wibble  1.1
mmap.test.h
Go to the documentation of this file.
1 /*
2  * Simple mmap support
3  *
4  * Copyright (C) 2006--2008 Enrico Zini <enrico@debian.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 #include <wibble/sys/mmap.h>
21 
22 #include <wibble/test.h>
23 #include <string.h>
24 
25 using namespace std;
26 using namespace wibble::sys;
27 
28 struct TestMMap {
30 #ifdef POSIX
31  MMap map;
32  assert_eq(map.filename, string());
33  assert_eq(map.fd, -1);
34  assert_eq(map.size, 0u);
35  assert_eq(map.buf, static_cast<const char*>(0));
36 
37  map.map("/bin/sh");
38  assert_eq(map.filename, "/bin/sh");
39  assert(map.fd != -1);
40  assert(map.size != 0u);
41  assert(map.buf != static_cast<const char*>(0));
42  assert_eq(map.buf[1], 'E');
43  assert_eq(map.buf[2], 'L');
44  assert_eq(map.buf[3], 'F');
45 
46  MMap map1 = map;
47  assert_eq(map.filename, string());
48  assert_eq(map.fd, -1);
49  assert_eq(map.size, 0u);
50  assert_eq(map.buf, static_cast<const char*>(0));
51 
52  assert_eq(map1.filename, "/bin/sh");
53  assert(map1.fd != -1);
54  assert(map1.size != 0u);
55  assert(map1.buf != static_cast<const char*>(0));
56  assert_eq(map1.buf[1], 'E');
57  assert_eq(map1.buf[2], 'L');
58  assert_eq(map1.buf[3], 'F');
59 
60  map1.unmap();
61  assert_eq(map1.filename, string());
62  assert_eq(map1.fd, -1);
63  assert_eq(map1.size, 0u);
64  assert_eq(map1.buf, static_cast<const char*>(0));
65 #endif
66  }
67 };
68 // vim:set ts=4 sw=4:
Simple mmap support.
Map< List, F > map(const List &l, const F &f)
Definition: list.h:381
Definition: buffer.cpp:28
Definition: mmap.test.h:28
Test simple()
Definition: mmap.test.h:29
Map a file into memory.
Definition: mmap.h:45
size_t size
Definition: mmap.h:58
const char * buf
Definition: mmap.h:60
std::string filename
Definition: mmap.h:57
int fd
Definition: mmap.h:59
void Test
Definition: test.h:178
#define assert_eq(x, y)
Definition: test.h:33
#define assert(x)
Definition: test.h:30