transaction tests
This commit is contained in:
parent
058069d1f3
commit
1fbdb703eb
3 changed files with 87 additions and 32 deletions
|
|
@ -5,10 +5,10 @@
|
|||
#include <mach_detours.h>
|
||||
|
||||
#include "lib_function.h"
|
||||
int (*realLibFunction)() = libFunction;
|
||||
static int (*realLibFunction)() = libFunction;
|
||||
|
||||
static int libFunctionDetourCounter = 0;
|
||||
int libFunctionDetour()
|
||||
static int libFunctionDetour()
|
||||
{
|
||||
libFunctionDetourCounter++;
|
||||
return 94;
|
||||
|
|
@ -75,34 +75,4 @@ TEST_CASE( "Overriding custom function in dylib", "[dylib]" )
|
|||
CHECK( libFunctionCounter == 1 );
|
||||
CHECK( libFunctionDetourCounter == 0 );
|
||||
}
|
||||
|
||||
SECTION( "aborting transaction means no detour" )
|
||||
{
|
||||
REQUIRE( detour_transaction_begin() == err_none );
|
||||
REQUIRE( detour_attach(reinterpret_cast<detour_func_t*>(&realLibFunction), reinterpret_cast<detour_func_t>(libFunctionDetour)) == err_none );
|
||||
CHECK( detour_transaction_abort() == err_none );
|
||||
|
||||
CHECK( realLibFunction == libFunction );
|
||||
CHECK( libFunctionCounter == 0 );
|
||||
CHECK( libFunctionDetourCounter == 0 );
|
||||
CHECK( libFunction() == 42 );
|
||||
CHECK( libFunctionCounter == 1 );
|
||||
CHECK( libFunctionDetourCounter == 0 );
|
||||
}
|
||||
|
||||
SECTION( "an error in a transaction means no detour" )
|
||||
{
|
||||
REQUIRE( detour_transaction_begin() == err_none );
|
||||
REQUIRE( detour_attach(reinterpret_cast<detour_func_t*>(&realLibFunction), reinterpret_cast<detour_func_t>(libFunctionDetour)) == err_none );
|
||||
// cannot detach because trampoline is not yet in place
|
||||
CHECK( detour_detach(reinterpret_cast<detour_func_t*>(&realLibFunction), reinterpret_cast<detour_func_t>(libFunctionDetour)) == KERN_FAILURE );
|
||||
CHECK( detour_transaction_commit() == KERN_FAILURE );
|
||||
|
||||
CHECK( realLibFunction == libFunction );
|
||||
CHECK( libFunctionCounter == 0 );
|
||||
CHECK( libFunctionDetourCounter == 0 );
|
||||
CHECK( libFunction() == 42 );
|
||||
CHECK( libFunctionCounter == 1 );
|
||||
CHECK( libFunctionDetourCounter == 0 );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue