Uh.
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 SH_DECL_HOOK0_void(Test, Func1, SH_NOATTRIB, 0);
44 SH_DECL_HOOK0_void(Test, Func2, SH_NOATTRIB, 0);
45 SH_DECL_HOOK0_void(Test, Func3, SH_NOATTRIB, 0);
49 ADD_STATE(State_Func1H_Called);
53 ADD_STATE(State_Func2H_Called);
57 ADD_STATE(State_Func3H_Called);
61 bool TestPlugSys(std::string &error)
70 // Add hooks, then issue a complete shutdown
71 SH_ADD_HOOK_STATICFUNC(Test, Func1, pInst, Handler_Func1, false);
72 SH_ADD_HOOK_STATICFUNC(Test, Func2, pInst, Handler_Func2, true);
73 SH_ADD_HOOK_STATICFUNC(Test, Func3, pInst, Handler_Func3, false);
79 CHECK_STATES((&g_States,
80 new State_Func1H_Called,
81 new State_Func1_Called,
82 new State_Func2_Called,
83 new State_Func2H_Called,
84 new State_Func3H_Called,
85 new State_Func3_Called,
88 Test_CompleteShutdown(g_SHPtr);
94 CHECK_STATES((&g_States,
95 new State_Func1_Called,
96 new State_Func2_Called,
97 new State_Func3_Called,
101 // Add hooks from "different plugins", then shutdown the plugins
104 SH_ADD_HOOK_STATICFUNC(Test, Func1, pInst, Handler_Func1, false);
106 SH_ADD_HOOK_STATICFUNC(Test, Func2, pInst, Handler_Func2, true);
108 SH_ADD_HOOK_STATICFUNC(Test, Func3, pInst, Handler_Func3, false);
111 SH_ADD_HOOK_STATICFUNC(Test, Func2, pInst, Handler_Func2, true);
112 SH_ADD_HOOK_STATICFUNC(Test, Func3, pInst, Handler_Func3, false);
115 SH_ADD_HOOK_STATICFUNC(Test, Func1, pInst, Handler_Func1, false);
116 SH_ADD_HOOK_STATICFUNC(Test, Func3, pInst, Handler_Func3, false);
119 SH_ADD_HOOK_STATICFUNC(Test, Func1, pInst, Handler_Func1, false);
120 SH_ADD_HOOK_STATICFUNC(Test, Func2, pInst, Handler_Func2, true);
126 CHECK_STATES((&g_States,
127 new State_Func1H_Called,
128 new State_Func1H_Called,
129 new State_Func1H_Called,
130 new State_Func1_Called,
131 new State_Func2_Called,
132 new State_Func2H_Called,
133 new State_Func2H_Called,
134 new State_Func2H_Called,
135 new State_Func3H_Called,
136 new State_Func3H_Called,
137 new State_Func3H_Called,
138 new State_Func3_Called,
141 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
142 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
143 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
144 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
146 CHECK_STATES((&g_States,
147 new State_PluginInUse(1, true),
148 new State_PluginInUse(2, true),
149 new State_PluginInUse(3, true),
150 new State_PluginInUse(4, false),
153 // Unload plugins one by one
154 Test_UnloadPlugin(g_SHPtr, 3);
160 CHECK_STATES((&g_States,
161 new State_Func1H_Called,
162 new State_Func1H_Called,
163 new State_Func1_Called,
164 new State_Func2_Called,
165 new State_Func2H_Called,
166 new State_Func2H_Called,
167 new State_Func3H_Called,
168 new State_Func3H_Called,
169 new State_Func3_Called,
170 NULL), "Part 2.3.1");
172 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
173 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
174 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
175 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
177 CHECK_STATES((&g_States,
178 new State_PluginInUse(1, true),
179 new State_PluginInUse(2, true),
180 new State_PluginInUse(3, false),
181 new State_PluginInUse(4, false),
182 NULL), "Part 2.3.2");
184 Test_UnloadPlugin(g_SHPtr, 2);
190 CHECK_STATES((&g_States,
191 new State_Func1H_Called,
192 new State_Func1_Called,
193 new State_Func2_Called,
194 new State_Func2H_Called,
195 new State_Func3H_Called,
196 new State_Func3_Called,
197 NULL), "Part 2.4.1");
199 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
200 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
201 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
202 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
204 CHECK_STATES((&g_States,
205 new State_PluginInUse(1, true),
206 new State_PluginInUse(2, false),
207 new State_PluginInUse(3, false),
208 new State_PluginInUse(4, false),
209 NULL), "Part 2.4.2");
211 Test_UnloadPlugin(g_SHPtr, 1);
217 CHECK_STATES((&g_States,
218 new State_Func1_Called,
219 new State_Func2_Called,
220 new State_Func3_Called,
221 NULL), "Part 2.5.1");
223 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
224 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
225 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
226 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
228 CHECK_STATES((&g_States,
229 new State_PluginInUse(1, false),
230 new State_PluginInUse(2, false),
231 new State_PluginInUse(3, false),
232 new State_PluginInUse(4, false),
233 NULL), "Part 2.5.2");
237 // Add hooks from "different plugins", then pause the plugins
240 SH_ADD_HOOK_STATICFUNC(Test, Func1, pInst, Handler_Func1, false);
242 SH_ADD_HOOK_STATICFUNC(Test, Func2, pInst, Handler_Func2, true);
244 SH_ADD_HOOK_STATICFUNC(Test, Func3, pInst, Handler_Func3, false);
247 SH_ADD_HOOK_STATICFUNC(Test, Func2, pInst, Handler_Func2, true);
248 SH_ADD_HOOK_STATICFUNC(Test, Func3, pInst, Handler_Func3, false);
251 SH_ADD_HOOK_STATICFUNC(Test, Func1, pInst, Handler_Func1, false);
252 SH_ADD_HOOK_STATICFUNC(Test, Func3, pInst, Handler_Func3, false);
255 SH_ADD_HOOK_STATICFUNC(Test, Func1, pInst, Handler_Func1, false);
256 SH_ADD_HOOK_STATICFUNC(Test, Func2, pInst, Handler_Func2, true);
262 CHECK_STATES((&g_States,
263 new State_Func1H_Called,
264 new State_Func1H_Called,
265 new State_Func1H_Called,
266 new State_Func1_Called,
267 new State_Func2_Called,
268 new State_Func2H_Called,
269 new State_Func2H_Called,
270 new State_Func2H_Called,
271 new State_Func3H_Called,
272 new State_Func3H_Called,
273 new State_Func3H_Called,
274 new State_Func3_Called,
277 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
278 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
279 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
280 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
282 CHECK_STATES((&g_States,
283 new State_PluginInUse(1, true),
284 new State_PluginInUse(2, true),
285 new State_PluginInUse(3, true),
286 new State_PluginInUse(4, false),
289 // Unload plugins one by one
290 Test_PausePlugin(g_SHPtr, 3);
296 CHECK_STATES((&g_States,
297 new State_Func1H_Called,
298 new State_Func1H_Called,
299 new State_Func1_Called,
300 new State_Func2_Called,
301 new State_Func2H_Called,
302 new State_Func2H_Called,
303 new State_Func3H_Called,
304 new State_Func3H_Called,
305 new State_Func3_Called,
306 NULL), "Part 3.3.1");
308 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
309 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
310 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
311 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
313 CHECK_STATES((&g_States,
314 new State_PluginInUse(1, true),
315 new State_PluginInUse(2, true),
316 new State_PluginInUse(3, true),
317 new State_PluginInUse(4, false),
318 NULL), "Part 3.3.2");
320 Test_PausePlugin(g_SHPtr, 2);
326 CHECK_STATES((&g_States,
327 new State_Func1H_Called,
328 new State_Func1_Called,
329 new State_Func2_Called,
330 new State_Func2H_Called,
331 new State_Func3H_Called,
332 new State_Func3_Called,
333 NULL), "Part 3.4.1");
335 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
336 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
337 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
338 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
340 CHECK_STATES((&g_States,
341 new State_PluginInUse(1, true),
342 new State_PluginInUse(2, true),
343 new State_PluginInUse(3, true),
344 new State_PluginInUse(4, false),
345 NULL), "Part 3.4.2");
347 Test_PausePlugin(g_SHPtr, 1);
353 CHECK_STATES((&g_States,
354 new State_Func1_Called,
355 new State_Func2_Called,
356 new State_Func3_Called,
357 NULL), "Part 3.5.1");
359 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
360 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
361 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
362 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
364 CHECK_STATES((&g_States,
365 new State_PluginInUse(1, true),
366 new State_PluginInUse(2, true),
367 new State_PluginInUse(3, true),
368 new State_PluginInUse(4, false),
369 NULL), "Part 3.5.2");
371 Test_UnpausePlugin(g_SHPtr, 1);
372 Test_UnpausePlugin(g_SHPtr, 2);
373 Test_UnpausePlugin(g_SHPtr, 3);
375 ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
376 ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
377 ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
378 ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
380 CHECK_STATES((&g_States,
381 new State_PluginInUse(1, true),
382 new State_PluginInUse(2, true),
383 new State_PluginInUse(3, true),
384 new State_PluginInUse(4, false),
391 CHECK_STATES((&g_States,
392 new State_Func1H_Called,
393 new State_Func1H_Called,
394 new State_Func1H_Called,
395 new State_Func1_Called,
396 new State_Func2_Called,
397 new State_Func2H_Called,
398 new State_Func2H_Called,
399 new State_Func2H_Called,
400 new State_Func3H_Called,
401 new State_Func3H_Called,
402 new State_Func3H_Called,
403 new State_Func3_Called,
407 Test_CompleteShutdown(g_SHPtr);
413 CHECK_STATES((&g_States,
414 new State_Func1_Called,
415 new State_Func2_Called,
416 new State_Func3_Called,