core-legacy/sourcehook/test/testbail2.cpp
author David Anderson <dvander@alliedmods.net>
Fri Nov 14 05:02:00 2008 -0600 (2008-11-14)
changeset 545 07e5df11f9fc
parent 541 core-1.4/sourcehook/test/testbail2.cpp@35a8cda28485
child 659 b35a5fdbc654
permissions -rw-r--r--
Renamed core-1.4 to core-legacy.
     1 // TESTBAIL
     2 //  Different compilation unit
     3 
     4 #include "sourcehook.h"
     5 #include "sourcehook_test.h"
     6 #include "testbail.h"
     7 
     8 static unsigned int n_calls = 0;
     9 
    10 int EatYams_Handler2(int a)
    11 {
    12 	ADD_STATE(State_EatYams_Handler2_Called(a));
    13 	RETURN_META_VALUE_NEWPARAMS(MRES_OVERRIDE, 6, &IGaben::EatYams, (0xBEEF));
    14 }
    15 
    16 int EatYams_Handler3(int a)
    17 {
    18 	ADD_STATE(State_EatYams_Handler3_Called(a));
    19 	RETURN_META_VALUE(MRES_IGNORED, 0);
    20 }
    21 
    22 namespace N_TestBail
    23 {
    24 	bool TestBail2(std::string &error)
    25 	{
    26 		g_PLID = 2;
    27 
    28 		SH_ADD_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams_Handler2, false);
    29 		SH_ADD_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams_Handler3, false);
    30 
    31 		int ret = g_Gabgab->EatYams(0xDEAD);
    32 
    33 		CHECK_COND(ret == 6, "Part 2.1");
    34 
    35 		n_calls++;
    36 
    37 		return true;
    38 	}
    39 
    40 	void UntestBail2()
    41 	{
    42 		while (n_calls)
    43 		{
    44 			SH_REMOVE_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams_Handler3, false);
    45 			SH_REMOVE_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams_Handler2, false);
    46 			n_calls--;
    47 		}
    48 	}
    49 }