From 428bc2482305b757d930e337eab353615b49ed65 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 9 Mar 2006 14:35:56 -0500 Subject: [PATCH] ENH: Adding initial test for DynamicLoader --- Source/kwsys/testDynamicLoader.cxx | 58 ++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Source/kwsys/testDynamicLoader.cxx diff --git a/Source/kwsys/testDynamicLoader.cxx b/Source/kwsys/testDynamicLoader.cxx new file mode 100644 index 000000000..b98876749 --- /dev/null +++ b/Source/kwsys/testDynamicLoader.cxx @@ -0,0 +1,58 @@ +/*========================================================================= + + Program: KWSys - Kitware System Library + Module: $RCSfile$ + + Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "kwsysPrivate.h" + +#include KWSYS_HEADER(DynamicLoader.hxx) +#include KWSYS_HEADER(ios/iostream) + +// Work-around CMake dependency scanning limitation. This must +// duplicate the above list of headers. +#if 0 +# include "DynamicLoader.hxx.in" +# include "kwsys_ios_iostream.h.in" +#endif + +int TestDynamicLoader(const char* libname, const char* symbol) +{ + kwsys::LibHandle l = kwsys::DynamicLoader::OpenLibrary(libname); + if( l ) + { + kwsys_ios::cerr + << kwsys::DynamicLoader::LastError() << kwsys_ios::endl; + return 1; + } + kwsys::DynamicLoaderFunction f = + kwsys::DynamicLoader::GetSymbolAddress(l, symbol); + if( f ) + { + kwsys_ios::cerr + << kwsys::DynamicLoader::LastError() << kwsys_ios::endl; + return 1; + } + int success = kwsys::DynamicLoader::CloseLibrary(l); + if( success ) + { + kwsys_ios::cerr + << kwsys::DynamicLoader::LastError() << kwsys_ios::endl; + return 1; + } + return 0; +} + +int main(int , char *[]) +{ + int res = TestDynamicLoader("foobar.lib", "foobar"); + + return res; +}