-
Notifications
You must be signed in to change notification settings - Fork 2
/
hook.test.cpp
56 lines (43 loc) · 1.44 KB
/
hook.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
#include <lime/hooks/hook.hpp>
#include <boost/ut.hpp>
using namespace boost::ut;
using namespace boost::ut::literals;
int test_fn(int param)
{
return param;
}
std::unique_ptr<lime::hook<int(int)>> original_test;
int test_hook(int param)
{
return original_test->original()(param + 5);
}
suite webview_suite = []
{
expect(eq(test_fn(10), 10));
original_test = std::move(lime::hook<int(int)>::create(test_fn, test_hook).value());
expect(eq(test_fn(10), 15));
original_test.reset();
expect(eq(test_fn(10), 10));
original_test = std::move(lime::make_hook(test_fn, test_hook).value());
expect(eq(test_fn(10), 15));
original_test.reset();
expect(eq(test_fn(10), 10));
lime::hook<int(int)>::create(test_fn,
[](auto *hook, int param) -> int
{
auto rtn = hook->original()(param + 10);
delete hook;
return rtn;
});
expect(eq(test_fn(10), 20));
expect(eq(test_fn(10), 10));
lime::make_hook(test_fn,
[](auto *hook, int param) -> int
{
auto rtn = hook->original()(param + 10);
delete hook;
return rtn;
});
expect(eq(test_fn(10), 20));
expect(eq(test_fn(10), 10));
};