small test restructure again

This commit is contained in:
Lysann Tranvouez 2025-10-02 22:44:29 +02:00
parent 5d833e2928
commit 7257abce71

View file

@ -14,13 +14,11 @@ static int libFunctionDetour()
return 94; return 94;
} }
TEST_CASE( "Overriding custom function in dylib", "[attach][detach][dylib]" ) TEST_CASE( "Attaching custom function in dylib installs detour", "[attach][dylib]" )
{ {
libFunctionCounter = 0; libFunctionCounter = 0;
libFunctionDetourCounter = 0; libFunctionDetourCounter = 0;
SECTION( "attaching installs a detour" )
{
REQUIRE( realLibFunction == libFunction ); REQUIRE( realLibFunction == libFunction );
REQUIRE( libFunction() == 42 ); REQUIRE( libFunction() == 42 );
REQUIRE( libFunctionCounter == 1 ); REQUIRE( libFunctionCounter == 1 );
@ -48,14 +46,18 @@ TEST_CASE( "Overriding custom function in dylib", "[attach][detach][dylib]" )
// clean up // clean up
REQUIRE( detour_transaction_begin() == err_none ); REQUIRE( detour_transaction_begin() == err_none );
CHECK( detour_detach_and_commit(reinterpret_cast<detour_func_t*>(&realLibFunction), reinterpret_cast<detour_func_t>(libFunctionDetour)) == err_none ); CHECK( detour_detach_and_commit(reinterpret_cast<detour_func_t*>(&realLibFunction), reinterpret_cast<detour_func_t>(libFunctionDetour)) == err_none );
} }
TEST_CASE( "Detaching custom function in dylib removes detour", "[detach][dylib]" )
{
libFunctionCounter = 0;
libFunctionDetourCounter = 0;
SECTION( "detaching in separate transaction removes detour" )
{
REQUIRE( detour_transaction_begin() == err_none ); REQUIRE( detour_transaction_begin() == err_none );
REQUIRE( detour_attach_and_commit(reinterpret_cast<detour_func_t*>(&realLibFunction), reinterpret_cast<detour_func_t>(libFunctionDetour)) == err_none ); REQUIRE( detour_attach_and_commit(reinterpret_cast<detour_func_t*>(&realLibFunction), reinterpret_cast<detour_func_t>(libFunctionDetour)) == err_none );
REQUIRE( realLibFunction != libFunction ); REQUIRE( realLibFunction != libFunction );
// this must be a separate transaction because detach works only if the trampoline is actually in place already (committed)
REQUIRE( detour_transaction_begin() == err_none ); REQUIRE( detour_transaction_begin() == err_none );
SECTION( "detach + transaction_commit" ) SECTION( "detach + transaction_commit" )
@ -74,5 +76,4 @@ TEST_CASE( "Overriding custom function in dylib", "[attach][detach][dylib]" )
CHECK( libFunction() == 42 ); CHECK( libFunction() == 42 );
CHECK( libFunctionCounter == 1 ); CHECK( libFunctionCounter == 1 );
CHECK( libFunctionDetourCounter == 0 ); CHECK( libFunctionDetourCounter == 0 );
}
} }