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:
56
tests/test_stability.cpp
Normal file
56
tests/test_stability.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include "radhook/radhook.h"
|
||||
|
||||
static int fn() { return 42; }
|
||||
static int detour() { return 1337; }
|
||||
|
||||
int main() {
|
||||
RadHookHandle handles[200];
|
||||
size_t count = 0;
|
||||
|
||||
// create many hooks
|
||||
for (int i = 0; i < 200; i++) {
|
||||
RadHookHandle h = nullptr;
|
||||
auto r = RadHookCreate(
|
||||
(void*)fn,
|
||||
(void*)detour,
|
||||
&h
|
||||
);
|
||||
|
||||
assert(r == RadHookResult::Success);
|
||||
assert(h != nullptr);
|
||||
|
||||
handles[count++] = h;
|
||||
}
|
||||
|
||||
// enumerate
|
||||
RadHookHandle listed[200];
|
||||
size_t listedCount = RadHookEnumerate(listed, 200);
|
||||
assert(listedCount == 200);
|
||||
|
||||
// every created handle must still be valid
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
assert(RadHookIsValid(handles[i]));
|
||||
}
|
||||
|
||||
// destroy half of them
|
||||
for (size_t i = 0; i < count; i += 2) {
|
||||
RadHookDestroy(handles[i]);
|
||||
}
|
||||
|
||||
// validate
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (i % 2 == 0) {
|
||||
assert(!RadHookIsValid(handles[i]));
|
||||
} else {
|
||||
assert(RadHookIsValid(handles[i]));
|
||||
}
|
||||
}
|
||||
|
||||
// final enumeration must not return destroyed hooks
|
||||
size_t finalCount = RadHookEnumerate(listed, 200);
|
||||
assert(finalCount == 100);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user