One bugfix, addition of META_RETURN_(VALUE_)NEWPARAMS (implemented using recalls), tests now support compiling against an older version of sourcehook.h (through the sourcehook_test.h file) while main.cpp which now also acts as a CSourceHookImpl factory compiles against the new version.
2 // This test used to be a test for a bug BAIL found.
3 // That bug is now fixed so I've granted BAIL the pleasure of being a test for
4 // the correct priority ordering of hook managers based on their version.
8 Old hook funcs don't work right when you combine override returns and recalls.
10 Always use a new hook func when possible. For this, hook funcs have to be able to say
13 This file tests that functionality.
16 testbail.cpp compiles with old version of sourcehook.h.
17 It sets everything up, adds a hook on a function
18 Then testbail2.cpp which has the new version adds a hook on the same function and
19 does a recall and overrides the value in it.
22 #include "sourcehook_test.h"
25 void *___testbail_gabgab;
26 SourceHook::ISourceHook *___testbail_shptr;
30 int EatYams_Handler1(int a)
32 ADD_STATE(State_EatYams_Handler1_Called(a));
33 RETURN_META_VALUE(MRES_IGNORED, 0);
37 // These are here so they can access this CU's g_States
38 int ___testbail_EatYams_Handler2(int a)
40 ADD_STATE(State_EatYams_Handler2_Called(a));
41 RETURN_META_VALUE_NEWPARAMS(MRES_OVERRIDE, 6, IGaben, EatYams, (0xBEEF));
44 int ___testbail_EatYams_Handler3(int a)
46 ADD_STATE(State_EatYams_Handler3_Called(a));
47 RETURN_META_VALUE(MRES_IGNORED, 0);
50 bool TestBail(std::string &error)
55 g_Gabgab = new IGaben;
56 ___testbail_gabgab = (void*)g_Gabgab;
57 ___testbail_shptr = g_SHPtr;
59 SH_ADD_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams_Handler1, false);
61 ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
63 CHECK_STATES((&g_States,
64 new State_EatYams_Handler1_Called(0xDEAD),
65 new State_EatYams_Called(0xDEAD),
66 new State_EatYams_Return(5),
69 if (!___TestBail2(error))
72 CHECK_STATES((&g_States,
73 new State_EatYams_Handler1_Called(0xDEAD),
74 new State_EatYams_Handler2_Called(0xDEAD),
75 new State_EatYams_Handler3_Called(0xBEEF),
76 new State_EatYams_Called(0xBEEF),
79 // WHAT IF NOW SOMEONE UNLOADS PLUGIN 2 !?!?!?!?
80 Test_UnloadPlugin(g_SHPtr, 2);
82 ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
84 CHECK_STATES((&g_States,
85 new State_EatYams_Handler1_Called(0xDEAD),
86 new State_EatYams_Called(0xDEAD),
87 new State_EatYams_Return(5),
90 SH_REMOVE_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams_Handler1, false);
92 ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
94 CHECK_STATES((&g_States,
95 new State_EatYams_Called(0xDEAD),
96 new State_EatYams_Return(5),