Line data Source code
1 :
2 : /* Copyright (c) 2014, Stefan.Eilemann@epfl.ch
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #include "test.h"
19 :
20 : #include <lunchbox/dso.h>
21 : #include <boost/filesystem.hpp>
22 : #ifdef __linux__
23 : # include <gnu/lib-names.h>
24 : #endif
25 :
26 : #ifdef _WIN32
27 : # include <lunchbox/os.h>
28 : # define fork CreateThread
29 : const std::string forkFun( "CreateThread" );
30 : #else
31 1 : const std::string forkFun( "fork" );
32 : #endif
33 :
34 : namespace fs = boost::filesystem;
35 :
36 1 : int main( int, char** )
37 : {
38 1 : lunchbox::Strings libraries;
39 : #ifdef _WIN32
40 : libraries.push_back( "Kernel32.dll" );
41 : libraries.push_back( "Ws2_32.dll" );
42 : #elif defined (Darwin)
43 : libraries.push_back( "/usr/lib/libc.dylib" );
44 : libraries.push_back( "/usr/lib/libtermcap.dylib" );
45 : #else
46 1 : libraries.push_back( LIBPTHREAD_SO );
47 1 : libraries.push_back( LIBM_SO );
48 : #endif
49 :
50 2 : lunchbox::DSO one( libraries[0] );
51 2 : lunchbox::DSO two( libraries[1] );
52 2 : lunchbox::DSO three;
53 :
54 1 : TEST( one.isOpen( ));
55 1 : TEST( two.isOpen( ));
56 1 : TEST( !three.isOpen( ));
57 :
58 1 : TEST( one != two );
59 1 : TEST( one != three );
60 1 : TEST( three.open( libraries[0] ));
61 1 : TEST( one == three );
62 1 : TEST( !three.open( libraries[0] ));
63 1 : TEST( one == three );
64 :
65 1 : TEST( one.getFunctionPointer( forkFun ));
66 1 : TEST( one.getFunctionPointer( forkFun ) == &fork );
67 1 : TEST( !one.getFunctionPointer( "fooBar" ));
68 :
69 1 : one.close();
70 1 : TEST( one != two );
71 1 : TEST( one != three );
72 1 : TEST( !one.getFunctionPointer( forkFun ));
73 :
74 1 : two.close();
75 1 : TEST( one == two );
76 1 : TEST( one != three );
77 :
78 2 : return EXIT_SUCCESS;
79 3 : }
|