sourcehook/test/test4.cpp
branchsourcemm-1.6.0
changeset 428 40a9d2f61121
parent 370 4dc28ab1c722
child 429 cadecde4b802
     1.1 --- a/sourcehook/test/test4.cpp	Thu Oct 04 19:46:28 2007 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,425 +0,0 @@
     1.4 -#include <string>
     1.5 -#include "sourcehook_test.h"
     1.6 -#include "testevents.h"
     1.7 -
     1.8 -// TEST4
     1.9 -// Tests of plugin management system
    1.10 -
    1.11 -namespace
    1.12 -{
    1.13 -	StateList g_States;
    1.14 -	SourceHook::ISourceHook *g_SHPtr;
    1.15 -	SourceHook::Plugin g_PLID;
    1.16 -
    1.17 -	MAKE_STATE(State_Func1_Called);
    1.18 -	MAKE_STATE(State_Func2_Called);
    1.19 -	MAKE_STATE(State_Func3_Called);
    1.20 -
    1.21 -	MAKE_STATE(State_Func1H_Called);
    1.22 -	MAKE_STATE(State_Func2H_Called);
    1.23 -	MAKE_STATE(State_Func3H_Called);
    1.24 -
    1.25 -	MAKE_STATE_2(State_PluginInUse, int, bool);
    1.26 -
    1.27 -	class Test
    1.28 -	{
    1.29 -	public:
    1.30 -		virtual void Func1()
    1.31 -		{
    1.32 -			ADD_STATE(State_Func1_Called);
    1.33 -		}
    1.34 -
    1.35 -		virtual void Func2()
    1.36 -		{
    1.37 -			ADD_STATE(State_Func2_Called);
    1.38 -		}
    1.39 -
    1.40 -		virtual void Func3()
    1.41 -		{
    1.42 -			ADD_STATE(State_Func3_Called);
    1.43 -		}
    1.44 -	};
    1.45 -
    1.46 -	// GCC's optimizer is too good. I had to add this in order to make it execute a virtual table lookup!
    1.47 -	class Whatever : public Test
    1.48 -	{
    1.49 -	};
    1.50 -
    1.51 -	SH_DECL_HOOK0_void(Test, Func1, SH_NOATTRIB, 0);
    1.52 -	SH_DECL_HOOK0_void(Test, Func2, SH_NOATTRIB, 0);
    1.53 -	SH_DECL_HOOK0_void(Test, Func3, SH_NOATTRIB, 0);
    1.54 -
    1.55 -	void Handler_Func1()
    1.56 -	{
    1.57 -		ADD_STATE(State_Func1H_Called);
    1.58 -	}
    1.59 -	void Handler_Func2()
    1.60 -	{
    1.61 -		ADD_STATE(State_Func2H_Called);
    1.62 -	}
    1.63 -	void Handler_Func3()
    1.64 -	{
    1.65 -		ADD_STATE(State_Func3H_Called);
    1.66 -	}
    1.67 -}
    1.68 -
    1.69 -bool TestPlugSys(std::string &error)
    1.70 -{
    1.71 -	GET_SHPTR(g_SHPtr);
    1.72 -	g_PLID = 1;
    1.73 -
    1.74 -	Whatever inst;
    1.75 -	Test *pInst = &inst;
    1.76 -
    1.77 -	// 1)
    1.78 -	//   Add hooks, then issue a complete shutdown
    1.79 -	SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
    1.80 -	SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
    1.81 -	SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
    1.82 -
    1.83 -	pInst->Func1();
    1.84 -	pInst->Func2();
    1.85 -	pInst->Func3();
    1.86 -
    1.87 -	CHECK_STATES((&g_States,
    1.88 -		new State_Func1H_Called,
    1.89 -		new State_Func1_Called,
    1.90 -		new State_Func2_Called,
    1.91 -		new State_Func2H_Called,
    1.92 -		new State_Func3H_Called,
    1.93 -		new State_Func3_Called,
    1.94 -		NULL), "Part 1.1");
    1.95 -
    1.96 -	Test_CompleteShutdown(g_SHPtr);
    1.97 -
    1.98 -	pInst->Func1();
    1.99 -	pInst->Func2();
   1.100 -	pInst->Func3();
   1.101 -
   1.102 -	CHECK_STATES((&g_States,
   1.103 -		new State_Func1_Called,
   1.104 -		new State_Func2_Called,
   1.105 -		new State_Func3_Called,
   1.106 -		NULL), "Part 1.2");
   1.107 -
   1.108 -	// 2)
   1.109 -	//   Add hooks from "different plugins", then shutdown the plugins
   1.110 -
   1.111 -	g_PLID = 1;
   1.112 -	SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
   1.113 -	g_PLID = 2;
   1.114 -	SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
   1.115 -	g_PLID = 3;
   1.116 -	SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
   1.117 -
   1.118 -	g_PLID = 1;
   1.119 -	SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
   1.120 -	SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
   1.121 -
   1.122 -	g_PLID = 2;
   1.123 -	SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
   1.124 -	SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
   1.125 -
   1.126 -	g_PLID = 3;
   1.127 -	SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
   1.128 -	SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
   1.129 -
   1.130 -	pInst->Func1();
   1.131 -	pInst->Func2();
   1.132 -	pInst->Func3();
   1.133 -
   1.134 -	CHECK_STATES((&g_States,
   1.135 -		new State_Func1H_Called,
   1.136 -		new State_Func1H_Called,
   1.137 -		new State_Func1H_Called,
   1.138 -		new State_Func1_Called,
   1.139 -		new State_Func2_Called,
   1.140 -		new State_Func2H_Called,
   1.141 -		new State_Func2H_Called,
   1.142 -		new State_Func2H_Called,
   1.143 -		new State_Func3H_Called,
   1.144 -		new State_Func3H_Called,
   1.145 -		new State_Func3H_Called,
   1.146 -		new State_Func3_Called,
   1.147 -		NULL), "Part 2.1");
   1.148 -
   1.149 -	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
   1.150 -	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
   1.151 -	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
   1.152 -	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
   1.153 -
   1.154 -	CHECK_STATES((&g_States,
   1.155 -		new State_PluginInUse(1, true),
   1.156 -		new State_PluginInUse(2, true),
   1.157 -		new State_PluginInUse(3, true),
   1.158 -		new State_PluginInUse(4, false),
   1.159 -		NULL), "Part 2.2");
   1.160 -
   1.161 -	// Unload plugins one by one
   1.162 -	Test_UnloadPlugin(g_SHPtr, 3);
   1.163 -
   1.164 -	pInst->Func1();
   1.165 -	pInst->Func2();
   1.166 -	pInst->Func3();
   1.167 -
   1.168 -	CHECK_STATES((&g_States,
   1.169 -		new State_Func1H_Called,
   1.170 -		new State_Func1H_Called,
   1.171 -		new State_Func1_Called,
   1.172 -		new State_Func2_Called,
   1.173 -		new State_Func2H_Called,
   1.174 -		new State_Func2H_Called,
   1.175 -		new State_Func3H_Called,
   1.176 -		new State_Func3H_Called,
   1.177 -		new State_Func3_Called,
   1.178 -		NULL), "Part 2.3.1");
   1.179 -
   1.180 -	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
   1.181 -	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
   1.182 -	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
   1.183 -	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
   1.184 -
   1.185 -	CHECK_STATES((&g_States,
   1.186 -		new State_PluginInUse(1, true),
   1.187 -		new State_PluginInUse(2, true),
   1.188 -		new State_PluginInUse(3, false),
   1.189 -		new State_PluginInUse(4, false),
   1.190 -		NULL), "Part 2.3.2");
   1.191 -
   1.192 -	Test_UnloadPlugin(g_SHPtr, 2);
   1.193 -
   1.194 -	pInst->Func1();
   1.195 -	pInst->Func2();
   1.196 -	pInst->Func3();
   1.197 -
   1.198 -	CHECK_STATES((&g_States,
   1.199 -		new State_Func1H_Called,
   1.200 -		new State_Func1_Called,
   1.201 -		new State_Func2_Called,
   1.202 -		new State_Func2H_Called,
   1.203 -		new State_Func3H_Called,
   1.204 -		new State_Func3_Called,
   1.205 -		NULL), "Part 2.4.1");
   1.206 -
   1.207 -	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
   1.208 -	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
   1.209 -	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
   1.210 -	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
   1.211 -
   1.212 -	CHECK_STATES((&g_States,
   1.213 -		new State_PluginInUse(1, true),
   1.214 -		new State_PluginInUse(2, false),
   1.215 -		new State_PluginInUse(3, false),
   1.216 -		new State_PluginInUse(4, false),
   1.217 -		NULL), "Part 2.4.2");
   1.218 -
   1.219 -	Test_UnloadPlugin(g_SHPtr, 1);
   1.220 -
   1.221 -	pInst->Func1();
   1.222 -	pInst->Func2();
   1.223 -	pInst->Func3();
   1.224 -
   1.225 -	CHECK_STATES((&g_States,
   1.226 -		new State_Func1_Called,
   1.227 -		new State_Func2_Called,
   1.228 -		new State_Func3_Called,
   1.229 -		NULL), "Part 2.5.1");
   1.230 -
   1.231 -	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
   1.232 -	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
   1.233 -	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
   1.234 -	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
   1.235 -
   1.236 -	CHECK_STATES((&g_States,
   1.237 -		new State_PluginInUse(1, false),
   1.238 -		new State_PluginInUse(2, false),
   1.239 -		new State_PluginInUse(3, false),
   1.240 -		new State_PluginInUse(4, false),
   1.241 -		NULL), "Part 2.5.2");
   1.242 -
   1.243 -
   1.244 -	// 3)
   1.245 -	//   Add hooks from "different plugins", then pause the plugins
   1.246 -
   1.247 -	g_PLID = 1;
   1.248 -	SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
   1.249 -	g_PLID = 2;
   1.250 -	SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
   1.251 -	g_PLID = 3;
   1.252 -	SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
   1.253 -
   1.254 -	g_PLID = 1;
   1.255 -	SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
   1.256 -	SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
   1.257 -
   1.258 -	g_PLID = 2;
   1.259 -	SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
   1.260 -	SH_ADD_HOOK(Test, Func3, pInst, SH_STATIC(Handler_Func3), false);
   1.261 -
   1.262 -	g_PLID = 3;
   1.263 -	SH_ADD_HOOK(Test, Func1, pInst, SH_STATIC(Handler_Func1), false);
   1.264 -	SH_ADD_HOOK(Test, Func2, pInst, SH_STATIC(Handler_Func2), true);
   1.265 -
   1.266 -	pInst->Func1();
   1.267 -	pInst->Func2();
   1.268 -	pInst->Func3();
   1.269 -
   1.270 -	CHECK_STATES((&g_States,
   1.271 -		new State_Func1H_Called,
   1.272 -		new State_Func1H_Called,
   1.273 -		new State_Func1H_Called,
   1.274 -		new State_Func1_Called,
   1.275 -		new State_Func2_Called,
   1.276 -		new State_Func2H_Called,
   1.277 -		new State_Func2H_Called,
   1.278 -		new State_Func2H_Called,
   1.279 -		new State_Func3H_Called,
   1.280 -		new State_Func3H_Called,
   1.281 -		new State_Func3H_Called,
   1.282 -		new State_Func3_Called,
   1.283 -		NULL), "Part 3.1");
   1.284 -
   1.285 -	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
   1.286 -	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
   1.287 -	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
   1.288 -	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
   1.289 -
   1.290 -	CHECK_STATES((&g_States,
   1.291 -		new State_PluginInUse(1, true),
   1.292 -		new State_PluginInUse(2, true),
   1.293 -		new State_PluginInUse(3, true),
   1.294 -		new State_PluginInUse(4, false),
   1.295 -		NULL), "Part 3.2");
   1.296 -
   1.297 -	// Unload plugins one by one
   1.298 -	Test_PausePlugin(g_SHPtr, 3);
   1.299 -
   1.300 -	pInst->Func1();
   1.301 -	pInst->Func2();
   1.302 -	pInst->Func3();
   1.303 -
   1.304 -	CHECK_STATES((&g_States,
   1.305 -		new State_Func1H_Called,
   1.306 -		new State_Func1H_Called,
   1.307 -		new State_Func1_Called,
   1.308 -		new State_Func2_Called,
   1.309 -		new State_Func2H_Called,
   1.310 -		new State_Func2H_Called,
   1.311 -		new State_Func3H_Called,
   1.312 -		new State_Func3H_Called,
   1.313 -		new State_Func3_Called,
   1.314 -		NULL), "Part 3.3.1");
   1.315 -
   1.316 -	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
   1.317 -	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
   1.318 -	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
   1.319 -	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
   1.320 -
   1.321 -	CHECK_STATES((&g_States,
   1.322 -		new State_PluginInUse(1, true),
   1.323 -		new State_PluginInUse(2, true),
   1.324 -		new State_PluginInUse(3, true),
   1.325 -		new State_PluginInUse(4, false),
   1.326 -		NULL), "Part 3.3.2");
   1.327 -
   1.328 -	Test_PausePlugin(g_SHPtr, 2);
   1.329 -
   1.330 -	pInst->Func1();
   1.331 -	pInst->Func2();
   1.332 -	pInst->Func3();
   1.333 -
   1.334 -	CHECK_STATES((&g_States,
   1.335 -		new State_Func1H_Called,
   1.336 -		new State_Func1_Called,
   1.337 -		new State_Func2_Called,
   1.338 -		new State_Func2H_Called,
   1.339 -		new State_Func3H_Called,
   1.340 -		new State_Func3_Called,
   1.341 -		NULL), "Part 3.4.1");
   1.342 -
   1.343 -	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
   1.344 -	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
   1.345 -	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
   1.346 -	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
   1.347 -
   1.348 -	CHECK_STATES((&g_States,
   1.349 -		new State_PluginInUse(1, true),
   1.350 -		new State_PluginInUse(2, true),
   1.351 -		new State_PluginInUse(3, true),
   1.352 -		new State_PluginInUse(4, false),
   1.353 -		NULL), "Part 3.4.2");
   1.354 -
   1.355 -	Test_PausePlugin(g_SHPtr, 1);
   1.356 -
   1.357 -	pInst->Func1();
   1.358 -	pInst->Func2();
   1.359 -	pInst->Func3();
   1.360 -
   1.361 -	CHECK_STATES((&g_States,
   1.362 -		new State_Func1_Called,
   1.363 -		new State_Func2_Called,
   1.364 -		new State_Func3_Called,
   1.365 -		NULL), "Part 3.5.1");
   1.366 -
   1.367 -	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
   1.368 -	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
   1.369 -	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
   1.370 -	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
   1.371 -
   1.372 -	CHECK_STATES((&g_States,
   1.373 -		new State_PluginInUse(1, true),
   1.374 -		new State_PluginInUse(2, true),
   1.375 -		new State_PluginInUse(3, true),
   1.376 -		new State_PluginInUse(4, false),
   1.377 -		NULL), "Part 3.5.2");
   1.378 -
   1.379 -	Test_UnpausePlugin(g_SHPtr, 1);
   1.380 -	Test_UnpausePlugin(g_SHPtr, 2);
   1.381 -	Test_UnpausePlugin(g_SHPtr, 3);
   1.382 -
   1.383 -	ADD_STATE(State_PluginInUse(1, Test_IsPluginInUse(g_SHPtr, 1)));
   1.384 -	ADD_STATE(State_PluginInUse(2, Test_IsPluginInUse(g_SHPtr, 2)));
   1.385 -	ADD_STATE(State_PluginInUse(3, Test_IsPluginInUse(g_SHPtr, 3)));
   1.386 -	ADD_STATE(State_PluginInUse(4, Test_IsPluginInUse(g_SHPtr, 4)));
   1.387 -
   1.388 -	CHECK_STATES((&g_States,
   1.389 -		new State_PluginInUse(1, true),
   1.390 -		new State_PluginInUse(2, true),
   1.391 -		new State_PluginInUse(3, true),
   1.392 -		new State_PluginInUse(4, false),
   1.393 -		NULL), "Part 3.6");
   1.394 -
   1.395 -	pInst->Func1();
   1.396 -	pInst->Func2();
   1.397 -	pInst->Func3();
   1.398 -
   1.399 -	CHECK_STATES((&g_States,
   1.400 -		new State_Func1H_Called,
   1.401 -		new State_Func1H_Called,
   1.402 -		new State_Func1H_Called,
   1.403 -		new State_Func1_Called,
   1.404 -		new State_Func2_Called,
   1.405 -		new State_Func2H_Called,
   1.406 -		new State_Func2H_Called,
   1.407 -		new State_Func2H_Called,
   1.408 -		new State_Func3H_Called,
   1.409 -		new State_Func3H_Called,
   1.410 -		new State_Func3H_Called,
   1.411 -		new State_Func3_Called,
   1.412 -		NULL), "Part 3.7");
   1.413 -
   1.414 -	// 4) Shutdown :)
   1.415 -	Test_CompleteShutdown(g_SHPtr);
   1.416 -
   1.417 -	pInst->Func1();
   1.418 -	pInst->Func2();
   1.419 -	pInst->Func3();
   1.420 -
   1.421 -	CHECK_STATES((&g_States,
   1.422 -		new State_Func1_Called,
   1.423 -		new State_Func2_Called,
   1.424 -		new State_Func3_Called,
   1.425 -		NULL), "Part 4");
   1.426 -
   1.427 -	return true;
   1.428 -}