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.
21 #include "sourcehook_test.h"
27 SourceHook::ISourceHook *g_SHPtr;
33 int EatYams_Handler1(int a)
35 ADD_STATE(State_EatYams_Handler1_Called(a));
36 RETURN_META_VALUE(MRES_IGNORED, 0);
40 bool TestBail(std::string &error)
45 g_Gabgab = new IGaben;
47 SH_ADD_HOOK(IGaben, EatYams, g_Gabgab, SH_STATIC(EatYams_Handler1), false);
49 ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
51 CHECK_STATES((&g_States,
52 new State_EatYams_Handler1_Called(0xDEAD),
53 new State_EatYams_Called(0xDEAD),
54 new State_EatYams_Return(5),
57 if (!TestBail2(error))
60 CHECK_STATES((&g_States,
61 new State_EatYams_Handler1_Called(0xDEAD),
62 new State_EatYams_Handler2_Called(0xDEAD),
63 new State_EatYams_Handler3_Called(0xBEEF),
64 new State_EatYams_Called(0xBEEF),
67 // WHAT IF NOW SOMEONE UNLOADS PLUGIN 2 !?!?!?!?
68 Test_UnloadPlugin(g_SHPtr, 2);
70 ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
72 CHECK_STATES((&g_States,
73 new State_EatYams_Handler1_Called(0xDEAD),
74 new State_EatYams_Called(0xDEAD),
75 new State_EatYams_Return(5),
78 SH_REMOVE_HOOK(IGaben, EatYams, g_Gabgab, SH_STATIC(EatYams_Handler1), false);
80 ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
82 CHECK_STATES((&g_States,
83 new State_EatYams_Called(0xDEAD),
84 new State_EatYams_Return(5),
87 // Now, heh, try it the other way round.
89 Test_CompleteShutdown(g_SHPtr);
91 if (!TestBail2(error))
94 CHECK_STATES((&g_States,
95 new State_EatYams_Handler2_Called(0xDEAD),
96 new State_EatYams_Handler3_Called(0xBEEF),
97 new State_EatYams_Called(0xBEEF),
100 SH_ADD_HOOK(IGaben, EatYams, g_Gabgab, SH_STATIC(EatYams_Handler1), false);
102 ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
104 CHECK_STATES((&g_States,
105 new State_EatYams_Handler2_Called(0xDEAD),
106 new State_EatYams_Handler3_Called(0xBEEF),
107 new State_EatYams_Handler1_Called(0xBEEF),
108 new State_EatYams_Called(0xBEEF),
109 new State_EatYams_Return(6),