| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "gate/tests.hpp" | ||
| 2 | #include "gate/libraries.hpp" | ||
| 3 | |||
| 4 | using namespace gate; | ||
| 5 | |||
| 6 | static StaticString const invlid_lib = "non-sense-lib-name"; | ||
| 7 | |||
| 8 | #if defined(GATE_SYS_WIN) | ||
| 9 | # define SYSLIB_NAME "kernel32" | ||
| 10 | # define SYSLIB_FUNC "OpenProcess" | ||
| 11 | |||
| 12 | #elif defined(GATE_SYS_DARWIN) | ||
| 13 | # define SYSLIB_NAME "libz.dylib" | ||
| 14 | # define SYSLIB_FUNC "deflate" | ||
| 15 | |||
| 16 | #elif defined(GATE_SYS_POSIX) | ||
| 17 | # define SYSLIB_NAME "libz.so" | ||
| 18 | # define SYSLIB_FUNC "deflate" | ||
| 19 | |||
| 20 | #endif | ||
| 21 | |||
| 22 | |||
| 23 | 5 | GATEXX_TEST_UNIT(Libraries) | |
| 24 | { | ||
| 25 | |||
| 26 | 2 | GATEXX_TEST_CHECK_THROW(Library(invlid_lib, 0)); | |
| 27 | |||
| 28 | 1 | if (!Library::isDynamicLoadingSupported()) | |
| 29 | { | ||
| 30 | /* is dyn loading is not support, further tests are meaningless */ | ||
| 31 | ✗ | return; | |
| 32 | } | ||
| 33 | |||
| 34 | #if defined(SYSLIB_NAME) | ||
| 35 | 1 | static StaticString const syslib_name = SYSLIB_NAME; | |
| 36 | 2 | Library syslib(syslib_name); | |
| 37 | |||
| 38 | 1 | static StaticString const unknown_data_name = "gate_test_some_thing_unknown"; | |
| 39 | 1 | static StaticString const known_func_name = SYSLIB_FUNC; | |
| 40 | |||
| 41 | 1 | GATEXX_TEST_CHECK(!syslib.hasData(unknown_data_name)); | |
| 42 | 2 | GATEXX_TEST_CHECK_THROW(syslib.getData(unknown_data_name)); | |
| 43 | |||
| 44 | 1 | Library::function_t myfunc = NULL; | |
| 45 | 1 | GATEXX_TEST_CHECK(syslib.hasFunction(unknown_data_name, NULL) == false); | |
| 46 | 1 | GATEXX_TEST_CHECK(syslib.hasFunction(known_func_name, &myfunc)); | |
| 47 | |||
| 48 | 2 | GATEXX_TEST_CHECK_THROW(myfunc = syslib.getFunction(unknown_data_name)); | |
| 49 | 1 | GATEXX_TEST_CHECK_NOTHROW(myfunc = syslib.getFunction(known_func_name)); | |
| 50 | 1 | GATEXX_TEST_CHECK_NOT_EQUAL(myfunc, NULL); | |
| 51 | #endif | ||
| 52 | } | ||
| 53 | |||
| 54 |