| 1 |
/* |
| 2 |
* Copyright (c) 2022 The Khronos Group Inc. |
| 3 |
* Copyright (c) 2022 Valve Corporation |
| 4 |
* Copyright (c) 2022 LunarG, Inc. |
| 5 |
* |
| 6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
* of this software and/or associated documentation files (the "Materials"), to |
| 8 |
* deal in the Materials without restriction, including without limitation the |
| 9 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 |
* sell copies of the Materials, and to permit persons to whom the Materials are |
| 11 |
* furnished to do so, subject to the following conditions: |
| 12 |
* |
| 13 |
* The above copyright notice(s) and this permission notice shall be included in |
| 14 |
* all copies or substantial portions of the Materials. |
| 15 |
* |
| 16 |
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 19 |
* |
| 20 |
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 21 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 22 |
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 23 |
* USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 |
* |
| 25 |
* Author: Charles Giessen <[email protected]> |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "dynamic_library.h" |
| 29 |
|
| 30 |
int main() { |
| 31 |
{ |
| 32 |
LibraryWrapper dynamic_library_a{std::string("./libdynamic_library_a.") + LIB_EXT}; |
| 33 |
LibraryWrapper dynamic_library_b{std::string("./libdynamic_library_b.") + LIB_EXT}; |
| 34 |
|
| 35 |
DoLogicFunction do_logic = nullptr; |
| 36 |
do_logic = dynamic_library_a.get_symbol(DO_LOGIC_FUNCTION_NAME); |
| 37 |
if (do_logic == nullptr || do_logic() != 'A') return 1; |
| 38 |
do_logic = dynamic_library_b.get_symbol(DO_LOGIC_FUNCTION_NAME); |
| 39 |
if (do_logic == nullptr || do_logic() != 'B') return 2; |
| 40 |
} |
| 41 |
{ |
| 42 |
LibraryWrapper dynamic_library_c{std::string("./libdynamic_library_c.") + LIB_EXT}; |
| 43 |
InitFunction init = dynamic_library_c.get_symbol(INIT_FUNCTION_NAME); |
| 44 |
if (init == nullptr) return 3; |
| 45 |
init(); |
| 46 |
DoLogicFunction do_logic = dynamic_library_c.get_symbol(DO_LOGIC_FUNCTION_NAME); |
| 47 |
if (do_logic == nullptr || do_logic() != 'C') return 4; |
| 48 |
// should fail because RTLD_NEXT on linux only is for dynamically *linked* libraries |
| 49 |
do_logic = reinterpret_cast<DoLogicFunction>(dlsym(RTLD_NEXT, DO_LOGIC_FUNCTION_NAME)); |
| 50 |
if (do_logic != nullptr) return 5; |
| 51 |
} |
| 52 |
std::cout << "Success\n"; |
| 53 |
return 0; |
| 54 |
} |