wibble 0.1.28
mmap.test.h
Go to the documentation of this file.
00001 /*
00002  * Simple mmap support
00003  *
00004  * Copyright (C) 2006--2008  Enrico Zini <enrico@debian.org>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 #include <wibble/sys/mmap.h>
00021 
00022 #ifdef POSIX
00023 #include <wibble/test.h>
00024 #include <string.h>
00025 
00026 using namespace std;
00027 using namespace wibble::sys;
00028 
00029 struct TestMMap {
00030     Test simple() {
00031         MMap map;
00032         assert_eq(map.filename, string());
00033         assert_eq(map.fd, -1);
00034         assert_eq(map.size, 0u);
00035         assert_eq(map.buf, (const char*)0);
00036 
00037         map.map("/bin/ls");
00038         assert_eq(map.filename, "/bin/ls");
00039         assert(map.fd != -1);
00040         assert(map.size != 0u);
00041         assert(map.buf != (const char*)0);
00042         assert_eq(map.buf[1], 'E');
00043         assert_eq(map.buf[2], 'L');
00044         assert_eq(map.buf[3], 'F');
00045 
00046     MMap map1 = map;
00047         assert_eq(map.filename, string());
00048         assert_eq(map.fd, -1);
00049         assert_eq(map.size, 0u);
00050         assert_eq(map.buf, (const char*)0);
00051 
00052         assert_eq(map1.filename, "/bin/ls");
00053         assert(map1.fd != -1);
00054         assert(map1.size != 0u);
00055         assert(map1.buf != (const char*)0);
00056         assert_eq(map1.buf[1], 'E');
00057         assert_eq(map1.buf[2], 'L');
00058         assert_eq(map1.buf[3], 'F');
00059 
00060     map1.unmap();
00061         assert_eq(map1.filename, string());
00062         assert_eq(map1.fd, -1);
00063         assert_eq(map1.size, 0u);
00064         assert_eq(map1.buf, (const char*)0);
00065     }
00066 };
00067 #endif
00068 // vim:set ts=4 sw=4: