core-1.4/sourcehook/test/testbail2.cpp
changeset 541 35a8cda28485
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/core-1.4/sourcehook/test/testbail2.cpp	Fri Nov 14 04:25:40 2008 -0600
     1.3 @@ -0,0 +1,49 @@
     1.4 +// TESTBAIL
     1.5 +//  Different compilation unit
     1.6 +
     1.7 +#include "sourcehook.h"
     1.8 +#include "sourcehook_test.h"
     1.9 +#include "testbail.h"
    1.10 +
    1.11 +static unsigned int n_calls = 0;
    1.12 +
    1.13 +int EatYams_Handler2(int a)
    1.14 +{
    1.15 +	ADD_STATE(State_EatYams_Handler2_Called(a));
    1.16 +	RETURN_META_VALUE_NEWPARAMS(MRES_OVERRIDE, 6, &IGaben::EatYams, (0xBEEF));
    1.17 +}
    1.18 +
    1.19 +int EatYams_Handler3(int a)
    1.20 +{
    1.21 +	ADD_STATE(State_EatYams_Handler3_Called(a));
    1.22 +	RETURN_META_VALUE(MRES_IGNORED, 0);
    1.23 +}
    1.24 +
    1.25 +namespace N_TestBail
    1.26 +{
    1.27 +	bool TestBail2(std::string &error)
    1.28 +	{
    1.29 +		g_PLID = 2;
    1.30 +
    1.31 +		SH_ADD_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams_Handler2, false);
    1.32 +		SH_ADD_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams_Handler3, false);
    1.33 +
    1.34 +		int ret = g_Gabgab->EatYams(0xDEAD);
    1.35 +
    1.36 +		CHECK_COND(ret == 6, "Part 2.1");
    1.37 +
    1.38 +		n_calls++;
    1.39 +
    1.40 +		return true;
    1.41 +	}
    1.42 +
    1.43 +	void UntestBail2()
    1.44 +	{
    1.45 +		while (n_calls)
    1.46 +		{
    1.47 +			SH_REMOVE_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams_Handler3, false);
    1.48 +			SH_REMOVE_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams_Handler2, false);
    1.49 +			n_calls--;
    1.50 +		}
    1.51 +	}
    1.52 +}