summaryrefslogtreecommitdiffstats
path: root/Source/kwsys
diff options
context:
space:
mode:
authorMathieu Malaterre <mathieu.malaterre@gmail.com>2006-03-09 21:40:34 (GMT)
committerMathieu Malaterre <mathieu.malaterre@gmail.com>2006-03-09 21:40:34 (GMT)
commit9b55f2579aa8909345b010eff7818f84948c244e (patch)
tree5625f7b9424e1275d175a78d264393a0abca1e69 /Source/kwsys
parent7ca1c6d2d8cf3eb22e5a8e2b78551db8b2e3c4dd (diff)
downloadCMake-9b55f2579aa8909345b010eff7818f84948c244e.zip
CMake-9b55f2579aa8909345b010eff7818f84948c244e.tar.gz
CMake-9b55f2579aa8909345b010eff7818f84948c244e.tar.bz2
ENH: Improve test coverage
Diffstat (limited to 'Source/kwsys')
-rw-r--r--Source/kwsys/testDynamicLoader.cxx34
1 files changed, 26 insertions, 8 deletions
diff --git a/Source/kwsys/testDynamicLoader.cxx b/Source/kwsys/testDynamicLoader.cxx
index b988767..08370d6 100644
--- a/Source/kwsys/testDynamicLoader.cxx
+++ b/Source/kwsys/testDynamicLoader.cxx
@@ -23,25 +23,33 @@
# include "kwsys_ios_iostream.h.in"
#endif
-int TestDynamicLoader(const char* libname, const char* symbol)
+#include "testSystemTools.h"
+
+/* libname = Library name
+ * System = symbol to lookup in libname
+ * r1: should OpenLibrary succeed ?
+ * r2: should GetSymbolAddress succeed ?
+ * r3: should CloseLibrary succeed ?
+ */
+int TestDynamicLoader(const char* libname, const char* symbol, int r1, int r2, int r3)
{
kwsys::LibHandle l = kwsys::DynamicLoader::OpenLibrary(libname);
- if( l )
+ // If result is incompatible with expectation just fails (xor):
+ if( (r1 && !l) || (!r1 && l) )
{
kwsys_ios::cerr
<< kwsys::DynamicLoader::LastError() << kwsys_ios::endl;
return 1;
}
- kwsys::DynamicLoaderFunction f =
- kwsys::DynamicLoader::GetSymbolAddress(l, symbol);
- if( f )
+ kwsys::DynamicLoaderFunction f = kwsys::DynamicLoader::GetSymbolAddress(l, symbol);
+ if( (r2 && !f) || (!r2 && f) )
{
kwsys_ios::cerr
<< kwsys::DynamicLoader::LastError() << kwsys_ios::endl;
return 1;
}
- int success = kwsys::DynamicLoader::CloseLibrary(l);
- if( success )
+ int s = kwsys::DynamicLoader::CloseLibrary(l);
+ if( (r3 && !s) || (!r3 && s) )
{
kwsys_ios::cerr
<< kwsys::DynamicLoader::LastError() << kwsys_ios::endl;
@@ -52,7 +60,17 @@ int TestDynamicLoader(const char* libname, const char* symbol)
int main(int , char *[])
{
- int res = TestDynamicLoader("foobar.lib", "foobar");
+ int res;
+ // Make sure that inexistant lib is giving correct result
+ res = TestDynamicLoader("foobar.lib", "foobar",0,0,0);
+ // Make sure that random binary file cannnot be assimilated as dylib
+ res += TestDynamicLoader(TEST_SYSTEMTOOLS_BIN_FILE, "wp",0,0,0);
+#ifdef __linux__
+ // This one is actually fun to test, since dlopen is by default loaded...wonder why :)
+ res += TestDynamicLoader("foobar.lib", "dlopen",0,1,0);
+ res += TestDynamicLoader("libdl.so", "dlopen",1,1,1);
+ res += TestDynamicLoader("libdl.so", "TestDynamicLoader",1,0,1);
+#endif
return res;
}