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);
22 MAKE_STATE_2(State_PluginInUse, int, bool);
29 ADD_STATE(State_Func1_Called);
34 ADD_STATE(State_Func2_Called);
39 ADD_STATE(State_Func3_Called);
43 // GCC's optimizer is too good. I had to add this in order to make it execute a virtual table lookup!
44 class Whatever : public Test
48 SH_DECL_HOOK0_void(Test, Func1, SH_NOATTRIB, 0);
49 SH_DECL_HOOK0_void(Test, Func2, SH_NOATTRIB, 0);
50 SH_DECL_HOOK0_void(Test, Func3, SH_NOATTRIB, 0);
54 ADD_STATE(State_Func1H_Called);
58 ADD_STATE(State_Func2H_Called);
62 ADD_STATE(State_Func3H_Called);
66 bool TestPlugSys(std::string &error)
75 // Add hooks, then issue a complete shutdown
76 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
77 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
78 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
84 CHECK_STATES((&g_States,
85 new State_Func1H_Called,
86 new State_Func1_Called,
87 new State_Func2_Called,
88 new State_Func2H_Called,
89 new State_Func3H_Called,
90 new State_Func3_Called,
93 Test_CompleteShutdown(g_SHPtr);
99 CHECK_STATES((&g_States,
100 new State_Func1_Called,
101 new State_Func2_Called,
102 new State_Func3_Called,
106 // Add hooks from "different plugins", then shutdown the plugins
109 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
111 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
113 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
116 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
117 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
120 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
121 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
124 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
125 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
131 CHECK_STATES((&g_States,
132 new State_Func1H_Called,
133 new State_Func1H_Called,
134 new State_Func1H_Called,
135 new State_Func1_Called,
136 new State_Func2_Called,
137 new State_Func2H_Called,
138 new State_Func2H_Called,
139 new State_Func2H_Called,
140 new State_Func3H_Called,
141 new State_Func3H_Called,
142 new State_Func3H_Called,
143 new State_Func3_Called,
146 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
147 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
148 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
149 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
151 CHECK_STATES((&g_States,
152 new State_PluginInUse(1, true),
153 new State_PluginInUse(2, true),
154 new State_PluginInUse(3, true),
155 new State_PluginInUse(4, false),
158 // Unload plugins one by one
159 Test_UnloadPlugin(g_SHPtr, 3);
165 CHECK_STATES((&g_States,
166 new State_Func1H_Called,
167 new State_Func1H_Called,
168 new State_Func1_Called,
169 new State_Func2_Called,
170 new State_Func2H_Called,
171 new State_Func2H_Called,
172 new State_Func3H_Called,
173 new State_Func3H_Called,
174 new State_Func3_Called,
175 NULL), "Part 2.3.1");
177 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
178 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
179 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
180 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
182 CHECK_STATES((&g_States,
183 new State_PluginInUse(1, true),
184 new State_PluginInUse(2, true),
185 new State_PluginInUse(3, false),
186 new State_PluginInUse(4, false),
187 NULL), "Part 2.3.2");
189 Test_UnloadPlugin(g_SHPtr, 2);
195 CHECK_STATES((&g_States,
196 new State_Func1H_Called,
197 new State_Func1_Called,
198 new State_Func2_Called,
199 new State_Func2H_Called,
200 new State_Func3H_Called,
201 new State_Func3_Called,
202 NULL), "Part 2.4.1");
204 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
205 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
206 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
207 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
209 CHECK_STATES((&g_States,
210 new State_PluginInUse(1, true),
211 new State_PluginInUse(2, false),
212 new State_PluginInUse(3, false),
213 new State_PluginInUse(4, false),
214 NULL), "Part 2.4.2");
216 Test_UnloadPlugin(g_SHPtr, 1);
222 CHECK_STATES((&g_States,
223 new State_Func1_Called,
224 new State_Func2_Called,
225 new State_Func3_Called,
226 NULL), "Part 2.5.1");
228 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
229 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
230 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
231 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
233 CHECK_STATES((&g_States,
234 new State_PluginInUse(1, false),
235 new State_PluginInUse(2, false),
236 new State_PluginInUse(3, false),
237 new State_PluginInUse(4, false),
238 NULL), "Part 2.5.2");
242 // Add hooks from "different plugins", then pause the plugins
245 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
247 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
249 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
252 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
253 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
256 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
257 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
260 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
261 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
267 CHECK_STATES((&g_States,
268 new State_Func1H_Called,
269 new State_Func1H_Called,
270 new State_Func1H_Called,
271 new State_Func1_Called,
272 new State_Func2_Called,
273 new State_Func2H_Called,
274 new State_Func2H_Called,
275 new State_Func2H_Called,
276 new State_Func3H_Called,
277 new State_Func3H_Called,
278 new State_Func3H_Called,
279 new State_Func3_Called,
282 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
283 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
284 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
285 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
287 CHECK_STATES((&g_States,
288 new State_PluginInUse(1, true),
289 new State_PluginInUse(2, true),
290 new State_PluginInUse(3, true),
291 new State_PluginInUse(4, false),
294 // Unload plugins one by one
295 Test_PausePlugin(g_SHPtr, 3);
301 CHECK_STATES((&g_States,
302 new State_Func1H_Called,
303 new State_Func1H_Called,
304 new State_Func1_Called,
305 new State_Func2_Called,
306 new State_Func2H_Called,
307 new State_Func2H_Called,
308 new State_Func3H_Called,
309 new State_Func3H_Called,
310 new State_Func3_Called,
311 NULL), "Part 3.3.1");
313 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
314 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
315 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
316 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
318 CHECK_STATES((&g_States,
319 new State_PluginInUse(1, true),
320 new State_PluginInUse(2, true),
321 new State_PluginInUse(3, true),
322 new State_PluginInUse(4, false),
323 NULL), "Part 3.3.2");
325 Test_PausePlugin(g_SHPtr, 2);
331 CHECK_STATES((&g_States,
332 new State_Func1H_Called,
333 new State_Func1_Called,
334 new State_Func2_Called,
335 new State_Func2H_Called,
336 new State_Func3H_Called,
337 new State_Func3_Called,
338 NULL), "Part 3.4.1");
340 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
341 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
342 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
343 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
345 CHECK_STATES((&g_States,
346 new State_PluginInUse(1, true),
347 new State_PluginInUse(2, true),
348 new State_PluginInUse(3, true),
349 new State_PluginInUse(4, false),
350 NULL), "Part 3.4.2");
352 Test_PausePlugin(g_SHPtr, 1);
358 CHECK_STATES((&g_States,
359 new State_Func1_Called,
360 new State_Func2_Called,
361 new State_Func3_Called,
362 NULL), "Part 3.5.1");
364 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
365 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
366 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
367 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
369 CHECK_STATES((&g_States,
370 new State_PluginInUse(1, true),
371 new State_PluginInUse(2, true),
372 new State_PluginInUse(3, true),
373 new State_PluginInUse(4, false),
374 NULL), "Part 3.5.2");
376 Test_UnpausePlugin(g_SHPtr, 1);
377 Test_UnpausePlugin(g_SHPtr, 2);
378 Test_UnpausePlugin(g_SHPtr, 3);
380 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
381 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
382 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
383 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
385 CHECK_STATES((&g_States,
386 new State_PluginInUse(1, true),
387 new State_PluginInUse(2, true),
388 new State_PluginInUse(3, true),
389 new State_PluginInUse(4, false),
396 CHECK_STATES((&g_States,
397 new State_Func1H_Called,
398 new State_Func1H_Called,
399 new State_Func1H_Called,
400 new State_Func1_Called,
401 new State_Func2_Called,
402 new State_Func2H_Called,
403 new State_Func2H_Called,
404 new State_Func2H_Called,
405 new State_Func3H_Called,
406 new State_Func3H_Called,
407 new State_Func3H_Called,
408 new State_Func3_Called,
412 Test_CompleteShutdown(g_SHPtr);
418 CHECK_STATES((&g_States,
419 new State_Func1_Called,
420 new State_Func2_Called,
421 new State_Func3_Called,