diff options
author | KWSys Upstream <kwrobot@kitware.com> | 2016-11-09 14:12:29 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-11-09 14:22:56 (GMT) |
commit | 773b36e5d4af3ac040625e0ea16bcfd30fcdeb6d (patch) | |
tree | bd409d3f09f6714981a444e896e1bc08e22ee184 /testDynamicLoader.cxx | |
parent | 53862f04a0002894c0ef5aeb23d52495e5abe60d (diff) | |
download | CMake-773b36e5d4af3ac040625e0ea16bcfd30fcdeb6d.zip CMake-773b36e5d4af3ac040625e0ea16bcfd30fcdeb6d.tar.gz CMake-773b36e5d4af3ac040625e0ea16bcfd30fcdeb6d.tar.bz2 |
KWSys 2016-11-09 (18c65411)
Code extracted from:
http://public.kitware.com/KWSys.git
at commit 18c654114de3aa65429542f95308720bc68f9231 (master).
Upstream Shortlog
-----------------
Brad King (14):
37306a1c FStream: Quiet unused argument warning
15e90a3c Sort includes to stabilize include order w.r.t. clang-format
26509227 Copyright.txt: Add notice of copyright by contributors
fc42d3f2 Add temporary script to filter license notices
c41c1bc4 Simplify KWSys per-source license notices
1d4c0b4a Remove temporary script that filtered license notices
a4f5ef79 SystemInformation: Remove stray comment
8649a886 kwsysPrivate: Protect KWSYS_HEADER macro from clang-format
89b98af5 Configure clang-format for KWSys source tree
547dacad Add a script to run clang-format on the entire source tree
aa94be0c CONTRIBUTING: Add a section on coding style
6604c4b6 Empty commit at end of history preceding clang-format style transition
2b3e2b1c Tell Git to not export 'clang-format' infrastructure
18c65411 FStream: Include Configure.hxx before other headers
Kitware Robot (1):
6c973b46 Revise C++ coding style using clang-format
Diffstat (limited to 'testDynamicLoader.cxx')
-rw-r--r-- | testDynamicLoader.cxx | 89 |
1 files changed, 39 insertions, 50 deletions
diff --git a/testDynamicLoader.cxx b/testDynamicLoader.cxx index 7c58769..b52ddda 100644 --- a/testDynamicLoader.cxx +++ b/testDynamicLoader.cxx @@ -1,30 +1,21 @@ -/*============================================================================ - KWSys - Kitware System Library - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ #include "kwsysPrivate.h" #include KWSYS_HEADER(DynamicLoader.hxx) #if defined(__BEOS__) || defined(__HAIKU__) -#include <be/kernel/OS.h> /* disable_debugger() API. */ +#include <be/kernel/OS.h> /* disable_debugger() API. */ #endif // Work-around CMake dependency scanning limitation. This must // duplicate the above list of headers. #if 0 -# include "DynamicLoader.hxx.in" +#include "DynamicLoader.hxx.in" #endif -#include <string> #include <iostream> +#include <string> // Include with <> instead of "" to avoid getting any in-source copy // left on disk. @@ -53,41 +44,36 @@ static std::string GetLibName(const char* lname) * r2: should GetSymbolAddress succeed ? * r3: should CloseLibrary succeed ? */ -static int TestDynamicLoader(const char* libname, const char* symbol, int r1, int r2, int r3) +static int TestDynamicLoader(const char* libname, const char* symbol, int r1, + int r2, int r3) { std::cerr << "Testing: " << libname << std::endl; - kwsys::DynamicLoader::LibraryHandle l - = kwsys::DynamicLoader::OpenLibrary(libname); + kwsys::DynamicLoader::LibraryHandle l = + kwsys::DynamicLoader::OpenLibrary(libname); // If result is incompatible with expectation just fails (xor): - if( (r1 && !l) || (!r1 && l) ) - { - std::cerr - << kwsys::DynamicLoader::LastError() << std::endl; + if ((r1 && !l) || (!r1 && l)) { + std::cerr << kwsys::DynamicLoader::LastError() << std::endl; return 1; - } - kwsys::DynamicLoader::SymbolPointer f - = kwsys::DynamicLoader::GetSymbolAddress(l, symbol); - if( (r2 && !f) || (!r2 && f) ) - { - std::cerr - << kwsys::DynamicLoader::LastError() << std::endl; + } + kwsys::DynamicLoader::SymbolPointer f = + kwsys::DynamicLoader::GetSymbolAddress(l, symbol); + if ((r2 && !f) || (!r2 && f)) { + std::cerr << kwsys::DynamicLoader::LastError() << std::endl; return 1; - } + } #ifndef __APPLE__ int s = kwsys::DynamicLoader::CloseLibrary(l); - if( (r3 && !s) || (!r3 && s) ) - { - std::cerr - << kwsys::DynamicLoader::LastError() << std::endl; + if ((r3 && !s) || (!r3 && s)) { + std::cerr << kwsys::DynamicLoader::LastError() << std::endl; return 1; - } + } #else (void)r3; #endif return 0; } -int testDynamicLoader(int argc, char *argv[]) +int testDynamicLoader(int argc, char* argv[]) { #if defined(_WIN32) SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); @@ -95,34 +81,37 @@ int testDynamicLoader(int argc, char *argv[]) disable_debugger(1); #endif int res = 0; - if( argc == 3 ) - { + if (argc == 3) { // User specify a libname and symbol to check. - res = TestDynamicLoader(argv[1], argv[2],1,1,1); + res = TestDynamicLoader(argv[1], argv[2], 1, 1, 1); return res; - } + } // dlopen() on Syllable before 11/22/2007 doesn't return 0 on error #ifndef __SYLLABLE__ // Make sure that inexistent lib is giving correct result - res += TestDynamicLoader("azerty_", "foo_bar",0,0,0); + res += TestDynamicLoader("azerty_", "foo_bar", 0, 0, 0); // Make sure that random binary file cannot be assimilated as dylib - res += TestDynamicLoader(TEST_SYSTEMTOOLS_SOURCE_DIR "/testSystemTools.bin", "wp",0,0,0); + res += TestDynamicLoader(TEST_SYSTEMTOOLS_SOURCE_DIR "/testSystemTools.bin", + "wp", 0, 0, 0); #endif #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); + // 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 // Now try on the generated library std::string libname = GetLibName(KWSYS_NAMESPACE_STRING "TestDynload"); - res += TestDynamicLoader(libname.c_str(), "dummy",1,0,1); - res += TestDynamicLoader(libname.c_str(), "TestDynamicLoaderSymbolPointer",1,1,1); - res += TestDynamicLoader(libname.c_str(), "_TestDynamicLoaderSymbolPointer",1,0,1); - res += TestDynamicLoader(libname.c_str(), "TestDynamicLoaderData",1,1,1); - res += TestDynamicLoader(libname.c_str(), "_TestDynamicLoaderData",1,0,1); + res += TestDynamicLoader(libname.c_str(), "dummy", 1, 0, 1); + res += TestDynamicLoader(libname.c_str(), "TestDynamicLoaderSymbolPointer", + 1, 1, 1); + res += TestDynamicLoader(libname.c_str(), "_TestDynamicLoaderSymbolPointer", + 1, 0, 1); + res += TestDynamicLoader(libname.c_str(), "TestDynamicLoaderData", 1, 1, 1); + res += TestDynamicLoader(libname.c_str(), "_TestDynamicLoaderData", 1, 0, 1); return res; } |