mirror of
https://git.recroomarchive.org/Radium/libradhook.git
synced 2026-08-07 09:10:59 +00:00
initial commit
This commit is contained in:
30
tests/test_execution_flow.cpp
Normal file
30
tests/test_execution_flow.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <cassert>
|
||||
#include "radhook/radhook.h"
|
||||
|
||||
static int fn() { return 42; }
|
||||
static int detour() { return 1337; }
|
||||
|
||||
using Fn = int(*)();
|
||||
|
||||
int main() {
|
||||
RadHookHandle h = nullptr;
|
||||
|
||||
RadHookCreate((void*)fn, (void*)detour, &h);
|
||||
|
||||
// must trigger detour
|
||||
assert(fn() == 1337);
|
||||
|
||||
// disable restores original
|
||||
RadHookDisable(h);
|
||||
assert(fn() == 42);
|
||||
|
||||
// re-enable restores hook
|
||||
RadHookEnable(h);
|
||||
assert(fn() == 1337);
|
||||
|
||||
// trampoline correctness
|
||||
auto orig = RadHookGetOriginalAs<Fn>(h);
|
||||
assert(orig() == 42);
|
||||
|
||||
RadHookDestroy(h);
|
||||
}
|
||||
Reference in New Issue
Block a user