-
Notifications
You must be signed in to change notification settings - Fork 2
/
module.test.cpp
59 lines (43 loc) · 1.53 KB
/
module.test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <filesystem>
#include <boost/ut.hpp>
#include <lime/module.hpp>
#if defined(WIN32) || defined(_WIN32)
#include <windows.h>
#endif
using namespace boost::ut;
using namespace boost::ut::literals;
namespace fs = std::filesystem;
fs::path find_library()
{
#if defined(WIN32) || defined(_WIN32)
char path[MAX_PATH];
GetModuleFileNameA(nullptr, path, sizeof(path));
return fs::path{path}.parent_path() / "lime-shared-lib.dll";
#else
const auto self = fs::canonical("/proc/self/exe").parent_path();
return self / "lime-shared-lib.so";
#endif
}
suite<"Module"> module_suite = []
{
expect(eq(lime::module::find("lime-shared-lib").has_value(), false));
const auto path = find_library().string();
auto loaded = lime::module::load(path);
expect(eq(loaded.has_value(), true));
auto test = lime::module::find("lime-shared-lib");
expect(eq(test.has_value(), true));
#if defined(WIN32) || defined(_WIN32)
auto case_test = lime::module::find("LIME-SHARED-LIB");
expect(eq(case_test.has_value(), true));
#endif
expect(test->name().find("lime-shared") != std::string_view::npos);
expect(test->symbols().size() >= 1);
expect(test->size() > 0);
expect(eq(test->find_symbol("lime_demo").has_value(), true));
expect(test->symbol("lime_demo_export") > 0);
expect(test->start() > 0);
expect(test->end() > 0);
using demo_export_t = int (*)(int);
auto demo_export = reinterpret_cast<demo_export_t>(test->symbol("lime_demo_export"));
expect(eq(demo_export(10), 20));
};