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);
64 bool TestPlugSys(std::string &error)
69 Test *pInst = MyTestFactory();
70 CAutoPtrDestruction<Test> apd(pInst);
73 // Add hooks, then issue a complete shutdown
74 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
75 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
76 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
82 CHECK_STATES((&g_States,
83 new State_Func1H_Called,
84 new State_Func1_Called,
85 new State_Func2_Called,
86 new State_Func2H_Called,
87 new State_Func3H_Called,
88 new State_Func3_Called,
91 Test_CompleteShutdown(g_SHPtr);
97 CHECK_STATES((&g_States,
98 new State_Func1_Called,
99 new State_Func2_Called,
100 new State_Func3_Called,
104 // Add hooks from "different plugins", then shutdown the plugins
107 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
109 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
111 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
114 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
115 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
118 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
119 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
122 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
123 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
129 CHECK_STATES((&g_States,
130 new State_Func1H_Called,
131 new State_Func1H_Called,
132 new State_Func1H_Called,
133 new State_Func1_Called,
134 new State_Func2_Called,
135 new State_Func2H_Called,
136 new State_Func2H_Called,
137 new State_Func2H_Called,
138 new State_Func3H_Called,
139 new State_Func3H_Called,
140 new State_Func3H_Called,
141 new State_Func3_Called,
144 // Unload plugins one by one
145 Test_UnloadPlugin(g_SHPtr, 3);
151 CHECK_STATES((&g_States,
152 new State_Func1H_Called,
153 new State_Func1H_Called,
154 new State_Func1_Called,
155 new State_Func2_Called,
156 new State_Func2H_Called,
157 new State_Func2H_Called,
158 new State_Func3H_Called,
159 new State_Func3H_Called,
160 new State_Func3_Called,
161 NULL), "Part 2.3.1");
163 Test_UnloadPlugin(g_SHPtr, 2);
169 CHECK_STATES((&g_States,
170 new State_Func1H_Called,
171 new State_Func1_Called,
172 new State_Func2_Called,
173 new State_Func2H_Called,
174 new State_Func3H_Called,
175 new State_Func3_Called,
176 NULL), "Part 2.4.1");
178 Test_UnloadPlugin(g_SHPtr, 1);
184 CHECK_STATES((&g_States,
185 new State_Func1_Called,
186 new State_Func2_Called,
187 new State_Func3_Called,
188 NULL), "Part 2.5.1");
192 // Add hooks from "different plugins", then pause the plugins
195 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
197 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
199 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
202 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
203 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
206 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
207 SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
210 SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
211 SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
217 CHECK_STATES((&g_States,
218 new State_Func1H_Called,
219 new State_Func1H_Called,
220 new State_Func1H_Called,
221 new State_Func1_Called,
222 new State_Func2_Called,
223 new State_Func2H_Called,
224 new State_Func2H_Called,
225 new State_Func2H_Called,
226 new State_Func3H_Called,
227 new State_Func3H_Called,
228 new State_Func3H_Called,
229 new State_Func3_Called,
232 // Unload plugins one by one
233 Test_PausePlugin(g_SHPtr, 3);
239 CHECK_STATES((&g_States,
240 new State_Func1H_Called,
241 new State_Func1H_Called,
242 new State_Func1_Called,
243 new State_Func2_Called,
244 new State_Func2H_Called,
245 new State_Func2H_Called,
246 new State_Func3H_Called,
247 new State_Func3H_Called,
248 new State_Func3_Called,
249 NULL), "Part 3.3.1");
251 Test_PausePlugin(g_SHPtr, 2);
257 CHECK_STATES((&g_States,
258 new State_Func1H_Called,
259 new State_Func1_Called,
260 new State_Func2_Called,
261 new State_Func2H_Called,
262 new State_Func3H_Called,
263 new State_Func3_Called,
264 NULL), "Part 3.4.1");
266 Test_PausePlugin(g_SHPtr, 1);
272 CHECK_STATES((&g_States,
273 new State_Func1_Called,
274 new State_Func2_Called,
275 new State_Func3_Called,
276 NULL), "Part 3.5.1");
278 Test_UnpausePlugin(g_SHPtr, 1);
279 Test_UnpausePlugin(g_SHPtr, 2);
280 Test_UnpausePlugin(g_SHPtr, 3);
286 CHECK_STATES((&g_States,
287 new State_Func1H_Called,
288 new State_Func1H_Called,
289 new State_Func1H_Called,
290 new State_Func1_Called,
291 new State_Func2_Called,
292 new State_Func2H_Called,
293 new State_Func2H_Called,
294 new State_Func2H_Called,
295 new State_Func3H_Called,
296 new State_Func3H_Called,
297 new State_Func3H_Called,
298 new State_Func3_Called,
302 Test_CompleteShutdown(g_SHPtr);
308 CHECK_STATES((&g_States,
309 new State_Func1_Called,
310 new State_Func2_Called,
311 new State_Func3_Called,