2 #include "sourcehook_test.h"
3 #include "testevents.h"
6 // Tests of plugin management system
11 SourceHook::ISourceHook *g_SHPtr;
12 SourceHook::Plugin g_PLID;
14 MAKE_STATE(State_Func1_Called);
15 MAKE_STATE(State_Func2_Called);
16 MAKE_STATE(State_Func3_Called);
18 MAKE_STATE(State_Func1H_Called);
19 MAKE_STATE(State_Func2H_Called);
20 MAKE_STATE(State_Func3H_Called);
27 ADD_STATE(State_Func1_Called);
32 ADD_STATE(State_Func2_Called);
37 ADD_STATE(State_Func3_Called);
41 SH_DECL_HOOK0_void(Test, Func1, SH_NOATTRIB, 1);
42 SH_DECL_HOOK0_void(Test, Func2, SH_NOATTRIB, 1);
43 SH_DECL_HOOK0_void(Test, Func3, SH_NOATTRIB, 1);
47 ADD_STATE(State_Func1H_Called);
51 ADD_STATE(State_Func2H_Called);
55 ADD_STATE(State_Func3H_Called);
59 bool TestPlugSys(std::string &error)
68 // Add hooks, then issue a complete shutdown
69 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
70 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
71 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
77 CHECK_STATES((&g_States,
78 new State_Func1H_Called,
79 new State_Func1_Called,
80 new State_Func2_Called,
81 new State_Func2H_Called,
82 new State_Func3H_Called,
83 new State_Func3_Called,
86 Test_CompleteShutdown(g_SHPtr);
92 CHECK_STATES((&g_States,
93 new State_Func1_Called,
94 new State_Func2_Called,
95 new State_Func3_Called,
99 // Add hooks from "different plugins", then shutdown the plugins
102 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
104 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
106 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
109 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
110 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
113 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
114 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
117 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
118 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
124 CHECK_STATES((&g_States,
125 new State_Func1H_Called,
126 new State_Func1H_Called,
127 new State_Func1H_Called,
128 new State_Func1_Called,
129 new State_Func2_Called,
130 new State_Func2H_Called,
131 new State_Func2H_Called,
132 new State_Func2H_Called,
133 new State_Func3H_Called,
134 new State_Func3H_Called,
135 new State_Func3H_Called,
136 new State_Func3_Called,
139 // Unload plugins one by one
140 Test_UnloadPlugin(g_SHPtr, 3);
146 CHECK_STATES((&g_States,
147 new State_Func1H_Called,
148 new State_Func1H_Called,
149 new State_Func1_Called,
150 new State_Func2_Called,
151 new State_Func2H_Called,
152 new State_Func2H_Called,
153 new State_Func3H_Called,
154 new State_Func3H_Called,
155 new State_Func3_Called,
156 NULL), "Part 2.3.1");
158 Test_UnloadPlugin(g_SHPtr, 2);
164 CHECK_STATES((&g_States,
165 new State_Func1H_Called,
166 new State_Func1_Called,
167 new State_Func2_Called,
168 new State_Func2H_Called,
169 new State_Func3H_Called,
170 new State_Func3_Called,
171 NULL), "Part 2.4.1");
173 Test_UnloadPlugin(g_SHPtr, 1);
179 CHECK_STATES((&g_States,
180 new State_Func1_Called,
181 new State_Func2_Called,
182 new State_Func3_Called,
183 NULL), "Part 2.5.1");
187 // Add hooks from "different plugins", then pause the plugins
190 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
192 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
194 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
197 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
198 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
201 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
202 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
205 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
206 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
212 CHECK_STATES((&g_States,
213 new State_Func1H_Called,
214 new State_Func1H_Called,
215 new State_Func1H_Called,
216 new State_Func1_Called,
217 new State_Func2_Called,
218 new State_Func2H_Called,
219 new State_Func2H_Called,
220 new State_Func2H_Called,
221 new State_Func3H_Called,
222 new State_Func3H_Called,
223 new State_Func3H_Called,
224 new State_Func3_Called,
227 // Unload plugins one by one
228 Test_PausePlugin(g_SHPtr, 3);
234 CHECK_STATES((&g_States,
235 new State_Func1H_Called,
236 new State_Func1H_Called,
237 new State_Func1_Called,
238 new State_Func2_Called,
239 new State_Func2H_Called,
240 new State_Func2H_Called,
241 new State_Func3H_Called,
242 new State_Func3H_Called,
243 new State_Func3_Called,
244 NULL), "Part 3.3.1");
246 Test_PausePlugin(g_SHPtr, 2);
252 CHECK_STATES((&g_States,
253 new State_Func1H_Called,
254 new State_Func1_Called,
255 new State_Func2_Called,
256 new State_Func2H_Called,
257 new State_Func3H_Called,
258 new State_Func3_Called,
259 NULL), "Part 3.4.1");
261 Test_PausePlugin(g_SHPtr, 1);
267 CHECK_STATES((&g_States,
268 new State_Func1_Called,
269 new State_Func2_Called,
270 new State_Func3_Called,
271 NULL), "Part 3.5.1");
273 Test_UnpausePlugin(g_SHPtr, 1);
274 Test_UnpausePlugin(g_SHPtr, 2);
275 Test_UnpausePlugin(g_SHPtr, 3);
281 CHECK_STATES((&g_States,
282 new State_Func1H_Called,
283 new State_Func1H_Called,
284 new State_Func1H_Called,
285 new State_Func1_Called,
286 new State_Func2_Called,
287 new State_Func2H_Called,
288 new State_Func2H_Called,
289 new State_Func2H_Called,
290 new State_Func3H_Called,
291 new State_Func3H_Called,
292 new State_Func3H_Called,
293 new State_Func3_Called,
297 Test_CompleteShutdown(g_SHPtr);
303 CHECK_STATES((&g_States,
304 new State_Func1_Called,
305 new State_Func2_Called,
306 new State_Func3_Called,