sourcehook/test/testvphooks.cpp
changeset 420 9c0613cb6f50
parent 380 f9e21a2ac558
     1.1 --- a/sourcehook/test/testvphooks.cpp	Sun Oct 14 12:15:09 2007 +0000
     1.2 +++ b/sourcehook/test/testvphooks.cpp	Sun Oct 14 12:28:28 2007 +0000
     1.3 @@ -30,76 +30,76 @@
     1.4  	MAKE_STATE_2(State_Func3_Post, IBase *, int);
     1.5  
     1.6  	class IBase
     1.7 -	{
     1.8 -	public:
     1.9 -		virtual void Func1() = 0;
    1.10 -		virtual void Func2() = 0;
    1.11 -		virtual void Func3(int x) = 0;
    1.12 +	{
    1.13 +	public:
    1.14 +		virtual void Func1() = 0;
    1.15 +		virtual void Func2() = 0;
    1.16 +		virtual void Func3(int x) = 0;
    1.17  	};
    1.18  
    1.19  	class CDerived1 : public IBase
    1.20 -	{
    1.21 -	public:
    1.22 -		virtual void Func1()
    1.23 -		{
    1.24 -			ADD_STATE(State_D1_Func1(this));
    1.25 -		}
    1.26 -		virtual void Func2()
    1.27 -		{
    1.28 -			ADD_STATE(State_D1_Func2(this));
    1.29 -		}
    1.30 -		virtual void Func3(int x)
    1.31 -		{
    1.32 -			ADD_STATE(State_D1_Func3(this, x));
    1.33 -		}
    1.34 +	{
    1.35 +	public:
    1.36 +		virtual void Func1()
    1.37 +		{
    1.38 +			ADD_STATE(State_D1_Func1(this));
    1.39 +		}
    1.40 +		virtual void Func2()
    1.41 +		{
    1.42 +			ADD_STATE(State_D1_Func2(this));
    1.43 +		}
    1.44 +		virtual void Func3(int x)
    1.45 +		{
    1.46 +			ADD_STATE(State_D1_Func3(this, x));
    1.47 +		}
    1.48  	};
    1.49  
    1.50  	class CDerived2 : public IBase
    1.51 -	{
    1.52 -	public:
    1.53 -		virtual void Func1()
    1.54 -		{
    1.55 -			ADD_STATE(State_D2_Func1(this));
    1.56 -		}
    1.57 -		virtual void Func2()
    1.58 -		{
    1.59 -			ADD_STATE(State_D2_Func2(this));
    1.60 -		}
    1.61 -		virtual void Func3(int x)
    1.62 -		{
    1.63 -			ADD_STATE(State_D2_Func3(this, x));
    1.64 -		}
    1.65 +	{
    1.66 +	public:
    1.67 +		virtual void Func1()
    1.68 +		{
    1.69 +			ADD_STATE(State_D2_Func1(this));
    1.70 +		}
    1.71 +		virtual void Func2()
    1.72 +		{
    1.73 +			ADD_STATE(State_D2_Func2(this));
    1.74 +		}
    1.75 +		virtual void Func3(int x)
    1.76 +		{
    1.77 +			ADD_STATE(State_D2_Func3(this, x));
    1.78 +		}
    1.79  	};
    1.80  
    1.81  	void Handler_Func1_Pre()
    1.82 -	{
    1.83 -		ADD_STATE(State_Func1_Pre(META_IFACEPTR(IBase)));
    1.84 +	{
    1.85 +		ADD_STATE(State_Func1_Pre(META_IFACEPTR(IBase)));
    1.86  	}
    1.87  	void Handler_Func1_Post()
    1.88 -	{
    1.89 -		ADD_STATE(State_Func1_Post(META_IFACEPTR(IBase)));
    1.90 +	{
    1.91 +		ADD_STATE(State_Func1_Post(META_IFACEPTR(IBase)));
    1.92  	}
    1.93  	int g_F2_Pre_HookToRemove = 0;
    1.94  	void Handler_Func2_Pre()
    1.95 -	{
    1.96 -		ADD_STATE(State_Func2_Pre(META_IFACEPTR(IBase)));
    1.97 -		SH_REMOVE_HOOK_ID(g_F2_Pre_HookToRemove);
    1.98 +	{
    1.99 +		ADD_STATE(State_Func2_Pre(META_IFACEPTR(IBase)));
   1.100 +		SH_REMOVE_HOOK_ID(g_F2_Pre_HookToRemove);
   1.101  	}
   1.102  	void Handler_Func2_Post()
   1.103 -	{
   1.104 -		ADD_STATE(State_Func2_Post(META_IFACEPTR(IBase)));
   1.105 +	{
   1.106 +		ADD_STATE(State_Func2_Post(META_IFACEPTR(IBase)));
   1.107  	}
   1.108  
   1.109  
   1.110  	void Handler_Func3_Pre(int x)
   1.111 -	{
   1.112 -		ADD_STATE(State_Func3_Pre(META_IFACEPTR(IBase), x));
   1.113 -
   1.114 -		RETURN_META_NEWPARAMS(MRES_IGNORED, &IBase::Func3, (x+1));
   1.115 +	{
   1.116 +		ADD_STATE(State_Func3_Pre(META_IFACEPTR(IBase), x));
   1.117 +
   1.118 +		RETURN_META_NEWPARAMS(MRES_IGNORED, &IBase::Func3, (x+1));
   1.119  	}
   1.120  	void Handler_Func3_Post(int x)
   1.121 -	{
   1.122 -		ADD_STATE(State_Func3_Post(META_IFACEPTR(IBase), x));
   1.123 +	{
   1.124 +		ADD_STATE(State_Func3_Post(META_IFACEPTR(IBase), x));
   1.125  	}
   1.126  
   1.127  	SH_DECL_HOOK0_void(IBase, Func1, SH_NOATTRIB, 0);
   1.128 @@ -110,24 +110,24 @@
   1.129  }
   1.130  
   1.131  bool TestVPHooks(std::string &error)
   1.132 -{
   1.133 +{
   1.134  	GET_SHPTR(g_SHPtr);
   1.135 -	g_PLID = 1337;
   1.136 -
   1.137 -	CDerived1 d1i1;
   1.138 -	CDerived1 d1i2;
   1.139 -	CDerived2 d2i1;
   1.140 -
   1.141 -	IBase *p_d1i1 = &d1i1;
   1.142 -	IBase *p_d1i2 = &d1i2;
   1.143 -	IBase *p_d2i1 = &d2i1;
   1.144 -	
   1.145 -	int hook1 = SH_ADD_VPHOOK(IBase, Func1, p_d1i1, SH_STATIC(Handler_Func1_Pre), false);
   1.146 -
   1.147 -	p_d1i1->Func1();
   1.148 -	p_d1i2->Func1();
   1.149 -	p_d2i1->Func1();
   1.150 -
   1.151 +	g_PLID = 1337;
   1.152 +
   1.153 +	CDerived1 d1i1;
   1.154 +	CDerived1 d1i2;
   1.155 +	CDerived2 d2i1;
   1.156 +
   1.157 +	IBase *p_d1i1 = &d1i1;
   1.158 +	IBase *p_d1i2 = &d1i2;
   1.159 +	IBase *p_d2i1 = &d2i1;
   1.160 +	
   1.161 +	int hook1 = SH_ADD_VPHOOK(IBase, Func1, p_d1i1, SH_STATIC(Handler_Func1_Pre), false);
   1.162 +
   1.163 +	p_d1i1->Func1();
   1.164 +	p_d1i2->Func1();
   1.165 +	p_d2i1->Func1();
   1.166 +
   1.167  	CHECK_STATES((&g_States,
   1.168  		new State_Func1_Pre(p_d1i1),
   1.169  		new State_D1_Func1(p_d1i1),
   1.170 @@ -136,33 +136,32 @@
   1.171  		new State_D1_Func1(p_d1i2),
   1.172  
   1.173  		new State_D2_Func1(p_d2i1),
   1.174 -		NULL), "Part 1");
   1.175 -
   1.176 -	SH_REMOVE_HOOK_ID(hook1);
   1.177 -
   1.178 -	p_d1i1->Func1();
   1.179 -	p_d1i2->Func1();
   1.180 -	p_d2i1->Func1();
   1.181 -
   1.182 +		NULL), "Part 1");
   1.183 +
   1.184 +	SH_REMOVE_HOOK_ID(hook1);
   1.185 +
   1.186 +	p_d1i1->Func1();
   1.187 +	p_d1i2->Func1();
   1.188 +	p_d2i1->Func1();
   1.189 +
   1.190  	CHECK_STATES((&g_States,
   1.191  		new State_D1_Func1(p_d1i1),
   1.192  
   1.193  		new State_D1_Func1(p_d1i2),
   1.194  
   1.195  		new State_D2_Func1(p_d2i1),
   1.196 -		NULL), "Part 2");
   1.197 -
   1.198 -
   1.199 -
   1.200 -	// Normal hook, then vp hook
   1.201 -
   1.202 -	int hook2 = SH_ADD_HOOK(IBase, Func1, p_d1i1, SH_STATIC(Handler_Func1_Pre), false);
   1.203 -	hook1 = SH_ADD_VPHOOK(IBase, Func1, p_d1i1, SH_STATIC(Handler_Func1_Pre), false);
   1.204 -
   1.205 -	p_d1i1->Func1();
   1.206 -	p_d1i2->Func1();
   1.207 -	p_d2i1->Func1();
   1.208 -
   1.209 +		NULL), "Part 2");
   1.210 +
   1.211 +
   1.212 +	// Normal hook, then vp hook
   1.213 +
   1.214 +	int hook2 = SH_ADD_HOOK(IBase, Func1, p_d1i1, SH_STATIC(Handler_Func1_Pre), false);
   1.215 +	hook1 = SH_ADD_VPHOOK(IBase, Func1, p_d1i1, SH_STATIC(Handler_Func1_Pre), false);
   1.216 +
   1.217 +	p_d1i1->Func1();
   1.218 +	p_d1i2->Func1();
   1.219 +	p_d2i1->Func1();
   1.220 +
   1.221  	CHECK_STATES((&g_States,
   1.222  		new State_Func1_Pre(p_d1i1),
   1.223  		new State_Func1_Pre(p_d1i1),
   1.224 @@ -172,14 +171,14 @@
   1.225  		new State_D1_Func1(p_d1i2),
   1.226  
   1.227  		new State_D2_Func1(p_d2i1),
   1.228 -		NULL), "Part 3");
   1.229 -
   1.230 -	SH_REMOVE_HOOK_ID(hook1);
   1.231 -
   1.232 -	p_d1i1->Func1();
   1.233 -	p_d1i2->Func1();
   1.234 -	p_d2i1->Func1();
   1.235 -
   1.236 +		NULL), "Part 3");
   1.237 +
   1.238 +	SH_REMOVE_HOOK_ID(hook1);
   1.239 +
   1.240 +	p_d1i1->Func1();
   1.241 +	p_d1i2->Func1();
   1.242 +	p_d2i1->Func1();
   1.243 +
   1.244  	CHECK_STATES((&g_States,
   1.245  		new State_Func1_Pre(p_d1i1),
   1.246  		new State_D1_Func1(p_d1i1),
   1.247 @@ -187,33 +186,33 @@
   1.248  		new State_D1_Func1(p_d1i2),
   1.249  
   1.250  		new State_D2_Func1(p_d2i1),
   1.251 -		NULL), "Part 4");
   1.252 -
   1.253 -	SH_REMOVE_HOOK_ID(hook2);
   1.254 -
   1.255 -	p_d1i1->Func1();
   1.256 -	p_d1i2->Func1();
   1.257 -	p_d2i1->Func1();
   1.258 -
   1.259 +		NULL), "Part 4");
   1.260 +
   1.261 +	SH_REMOVE_HOOK_ID(hook2);
   1.262 +
   1.263 +	p_d1i1->Func1();
   1.264 +	p_d1i2->Func1();
   1.265 +	p_d2i1->Func1();
   1.266 +
   1.267  	CHECK_STATES((&g_States,
   1.268  		new State_D1_Func1(p_d1i1),
   1.269  
   1.270  		new State_D1_Func1(p_d1i2),
   1.271  
   1.272  		new State_D2_Func1(p_d2i1),
   1.273 -		NULL), "Part 5");
   1.274 -
   1.275 -	// Test this:
   1.276 -	// Normal hook AND vp hook on Func2
   1.277 -	// Func2's pre handler removes the VP hook.
   1.278 -
   1.279 -	hook1 = SH_ADD_VPHOOK(IBase, Func2, p_d1i1, SH_STATIC(Handler_Func2_Pre), false);
   1.280 -	hook2 = SH_ADD_HOOK(IBase, Func2, p_d1i1, SH_STATIC(Handler_Func2_Pre), false);
   1.281 -
   1.282 -	g_F2_Pre_HookToRemove = hook1;
   1.283 -	p_d1i1->Func2();
   1.284 -	p_d1i1->Func2();
   1.285 -
   1.286 +		NULL), "Part 5");
   1.287 +
   1.288 +	// Test this:
   1.289 +	// Normal hook AND vp hook on Func2
   1.290 +	// Func2's pre handler removes the VP hook.
   1.291 +
   1.292 +	hook1 = SH_ADD_VPHOOK(IBase, Func2, p_d1i1, SH_STATIC(Handler_Func2_Pre), false);
   1.293 +	hook2 = SH_ADD_HOOK(IBase, Func2, p_d1i1, SH_STATIC(Handler_Func2_Pre), false);
   1.294 +
   1.295 +	g_F2_Pre_HookToRemove = hook1;
   1.296 +	p_d1i1->Func2();
   1.297 +	p_d1i1->Func2();
   1.298 +
   1.299  	CHECK_STATES((&g_States,
   1.300  		new State_Func2_Pre(p_d1i1),
   1.301  		new State_D1_Func2(p_d1i1),
   1.302 @@ -221,22 +220,22 @@
   1.303  		new State_Func2_Pre(p_d1i1),
   1.304  		new State_D1_Func2(p_d1i1),
   1.305  
   1.306 -		NULL), "Part 6");
   1.307 -
   1.308 -	SH_REMOVE_HOOK_ID(hook1);
   1.309 -
   1.310 -	// Hook function 3:
   1.311 -	//  Using manualhook, VP
   1.312 -	hook1 = SH_ADD_MANUALVPHOOK(IBase_Func3_Manual, p_d1i1, SH_STATIC(Handler_Func3_Pre), false);
   1.313 -
   1.314 -	//  Normally, VP
   1.315 -	hook2 = SH_ADD_VPHOOK(IBase, Func3, p_d1i1, SH_STATIC(Handler_Func3_Pre), false);
   1.316 -
   1.317 -	// Normally, no VP
   1.318 -	int hook3 = SH_ADD_HOOK(IBase, Func3, p_d1i1, SH_STATIC(Handler_Func3_Pre), false);
   1.319 -
   1.320 -	p_d1i1->Func3(1);
   1.321 -
   1.322 +		NULL), "Part 6");
   1.323 +
   1.324 +	SH_REMOVE_HOOK_ID(hook1);
   1.325 +
   1.326 +	// Hook function 3:
   1.327 +	//  Using manualhook, VP
   1.328 +	hook1 = SH_ADD_MANUALVPHOOK(IBase_Func3_Manual, p_d1i1, SH_STATIC(Handler_Func3_Pre), false);
   1.329 +
   1.330 +	//  Normally, VP
   1.331 +	hook2 = SH_ADD_VPHOOK(IBase, Func3, p_d1i1, SH_STATIC(Handler_Func3_Pre), false);
   1.332 +
   1.333 +	// Normally, no VP
   1.334 +	int hook3 = SH_ADD_HOOK(IBase, Func3, p_d1i1, SH_STATIC(Handler_Func3_Pre), false);
   1.335 +
   1.336 +	p_d1i1->Func3(1);
   1.337 +
   1.338  	CHECK_STATES((&g_States,
   1.339  		new State_Func3_Pre(p_d1i1, 1),		// manual vp hook
   1.340  		new State_Func3_Pre(p_d1i1, 2),		// normal vp hook
   1.341 @@ -244,17 +243,18 @@
   1.342  
   1.343  		new State_D1_Func3(p_d1i1, 4),		// function
   1.344  
   1.345 -		NULL), "Part 7.1");
   1.346 -
   1.347 -	p_d1i2->Func3(1);
   1.348 -
   1.349 +		NULL), "Part 7.1");
   1.350 +
   1.351 +	p_d1i2->Func3(1);
   1.352 +
   1.353  	CHECK_STATES((&g_States,
   1.354  		new State_Func3_Pre(p_d1i2, 1),		// manual vp hook
   1.355  		new State_Func3_Pre(p_d1i2, 2),		// normal vp hook
   1.356  
   1.357  		new State_D1_Func3(p_d1i2, 3),		// function
   1.358  
   1.359 -		NULL), "Part 7.2");
   1.360 -
   1.361 -	return true;
   1.362 -}
   1.363 \ No newline at end of file
   1.364 +		NULL), "Part 7.2");
   1.365 +
   1.366 +	return true;
   1.367 +}
   1.368 +