added test

This commit is contained in:
Lysann Tranvouez 2025-09-30 00:09:10 +02:00
parent ade0920e54
commit aaad260259
4 changed files with 94 additions and 42 deletions

34
sample/main.cpp Normal file
View file

@ -0,0 +1,34 @@
// Copyright (c) Lysann Tranvouez. All rights reserved.
#include <cassert>
#include "mach_detours.h"
#include <cstring>
char* (*real_strerror)(int errno) = strerror;
static int counter = 0;
char* my_strerror(const int errno)
{
counter++;
return real_strerror(errno);
}
int main(int argc, const char* argv[])
{
counter = 0;
strerror(0);
assert(counter == 0);
detour_transaction_begin();
detour_attach(reinterpret_cast<detour_func_t*>(&real_strerror), reinterpret_cast<detour_func_t>(my_strerror));
detour_transaction_commit();
assert(counter == 0);
strerror(0);
assert(counter == 1);
return 0;
}