wibble
1.1
wibble
sys
mmap_v2.test.h
Go to the documentation of this file.
1
// -*- C++ -*- (c) 2013 Vladimír Štill <xstill@fi.muni.cz>
2
#if __cplusplus >= 201103L
3
#include <
wibble/sys/mmap_v2.h
>
4
using namespace
wibble::sys
;
5
#endif
6
7
#include <
wibble/test.h
>
8
#include <
string.h
>
9
10
using namespace
std;
11
using namespace
wibble
;
12
13
struct
TestMMapV2
{
14
Test
read
() {
15
#if defined POSIX && __cplusplus >= 201103L
16
MMap
map
;
17
assert_eq
(
map
.size(), 0U );
18
assert
( !
map
);
19
assert
( !
map
.valid() );
20
assert
( !
map
.mode() );
21
22
map
.map(
"/bin/sh"
);
23
assert_neq
(
map
.size(), 0U );
24
assert_eq
(
map
.mode(), MMap::ProtectMode::Read | MMap::ProtectMode::Shared );
25
assert
(
map
.valid() );
26
assert_eq
(
map
[ 1 ],
'E'
);
27
assert_eq
(
map
[ 2 ],
'L'
);
28
assert_eq
(
map
[ 3 ],
'F'
);
29
30
MMap
map1 =
map
;
// shared_ptr semantics
31
assert_eq
(
map
.size(),
map
.size() );
32
assert_eq
(
map
.asArrayOf<
char
>(), map1.asArrayOf<
char
>() );
33
assert_eq
(
map
.mode(), map1.mode() );
34
35
assert_eq
( map1.get<
char
>( 1 ),
'E'
);
36
assert_eq
( map1.get<
char
>( 2 ),
'L'
);
37
assert_eq
( map1.get<
char
>( 3 ),
'F'
);
38
39
map1.unmap();
40
assert_eq
( map1.size(), 0U );
41
assert
( !map1 );
42
assert_eq
(
map
.cget<
char
>( 1 ),
'E'
);
43
assert_eq
(
map
.cget<
char
>( 2 ),
'L'
);
44
assert_eq
(
map
.cget<
char
>( 3 ),
'F'
);
45
46
assert
(
map
.valid() );
47
48
map
.unmap();
49
assert_eq
(
map
.size(), 0U );
50
assert
( !
map
);
51
#endif
52
}
53
};
wibble::sys::MMap
Map a file into memory.
Definition:
mmap.h:44
TestMMapV2
Definition:
mmap_v2.test.h:13
string.h
wibble::sys
Definition:
buffer.cpp:28
mmap_v2.h
assert_neq
#define assert_neq(x, y)
Definition:
test.h:36
TestMMapV2::read
Test read()
Definition:
mmap_v2.test.h:14
wibble::list::map
Map< List, F > map(const List &l, const F &f)
Definition:
list.h:381
test.h
assert_eq
#define assert_eq(x, y)
Definition:
test.h:33
wibble
Definition:
amorph.h:17
Test
void Test
Definition:
test.h:178
assert
#define assert(x)
Definition:
test.h:30
Generated by
1.8.17