sourcehook/test/testrefret.cpp
changeset 387 093c72464b35
parent 380 f9e21a2ac558
     1.1 --- a/sourcehook/test/testrefret.cpp	Sun Oct 07 23:00:38 2007 +0000
     1.2 +++ b/sourcehook/test/testrefret.cpp	Mon Oct 08 14:20:51 2007 +0000
     1.3 @@ -91,6 +91,11 @@
     1.4  
     1.5  	SH_DECL_HOOK0(Test, Func1, SH_NOATTRIB, 0, int&);
     1.6  	SH_DECL_HOOK1(Test, Func2, SH_NOATTRIB, 0, const int&, int);
     1.7 +
     1.8 +	Test *MyTestFactory()
     1.9 +	{
    1.10 +		return new Test;
    1.11 +	}
    1.12  }
    1.13  
    1.14  bool TestRefRet(std::string &error)
    1.15 @@ -98,40 +103,40 @@
    1.16  	GET_SHPTR(g_SHPtr);
    1.17  	g_PLID = 1;
    1.18  
    1.19 -	Test test;
    1.20 -	Test *pTest = &test;
    1.21 +	Test *pTest = MyTestFactory();
    1.22 +	CAutoPtrDestruction<Test> apd(pTest);
    1.23  	CHook hook;
    1.24  
    1.25  	int &ret1 = pTest->Func1();
    1.26  	ADD_STATE(State_Func1_Ret(&ret1));
    1.27  
    1.28  	CHECK_STATES((&g_States,
    1.29 -		new State_Func1(&test.m_Var1),
    1.30 -		new State_Func1_Ret(&test.m_Var1),
    1.31 +		new State_Func1(&pTest->m_Var1),
    1.32 +		new State_Func1_Ret(&pTest->m_Var1),
    1.33  		NULL), "Part 1");
    1.34  
    1.35  	// Now add Func1_Pre1, which supercedes and returns hook.m_Var
    1.36 -	SH_ADD_HOOK(Test, Func1, &test, SH_MEMBER(&hook, &CHook::Func1_Pre1), false);
    1.37 +	SH_ADD_HOOK(Test, Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Pre1), false);
    1.38  
    1.39  	int &ret2 = pTest->Func1();
    1.40  	ADD_STATE(State_Func1_Ret(&ret2));
    1.41  	
    1.42  	CHECK_STATES((&g_States,
    1.43  		new State_Func1_Pre1(&hook.m_Var),		// Pre1 says that it's going to override with hook.m_Var
    1.44 -		new State_Func1(&test.m_Var1),			// Function says that it's going to return test.m_Var1
    1.45 +		new State_Func1(&pTest->m_Var1),			// Function says that it's going to return pTest->m_Var1
    1.46  		new State_Func1_Ret(&hook.m_Var),		// hook.m_Var is returned
    1.47  		NULL), "Part 2");
    1.48  
    1.49  	// Now add Func1_Post1, which only reports orig ret and override ret
    1.50 -	SH_ADD_HOOK(Test, Func1, &test, SH_MEMBER(&hook, &CHook::Func1_Post1), true);
    1.51 +	SH_ADD_HOOK(Test, Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Post1), true);
    1.52  
    1.53  	int &ret3 = pTest->Func1();
    1.54  	ADD_STATE(State_Func1_Ret(&ret3));
    1.55  	
    1.56  	CHECK_STATES((&g_States,
    1.57  		new State_Func1_Pre1(&hook.m_Var),		// Pre1 says that it's going to override with hook.m_Var
    1.58 -		new State_Func1(&test.m_Var1),			// Function says that it's going to return test.m_Var1
    1.59 -		new State_Func1_Post1(&test.m_Var1, &hook.m_Var),	// origret(=p1) is what it wanted to
    1.60 +		new State_Func1(&pTest->m_Var1),			// Function says that it's going to return pTest->m_Var1
    1.61 +		new State_Func1_Post1(&pTest->m_Var1, &hook.m_Var),	// origret(=p1) is what it wanted to
    1.62  															// return, overrideret(=p2) is pre1's var
    1.63  		new State_Func1_Ret(&hook.m_Var),		// hook.m_Var is returned
    1.64  		NULL), "Part 3");
    1.65 @@ -139,8 +144,8 @@
    1.66  	// Now add Func1_Pre2, which supercedes and returns g_Var (it also sets the override ret from pre1 to 1337)
    1.67  	// and add Func1_Post2, which overrides and returns hook.m_Var again.
    1.68  
    1.69 -	SH_ADD_HOOK(Test, Func1, &test, SH_MEMBER(&hook, &CHook::Func1_Pre2), false);
    1.70 -	SH_ADD_HOOK(Test, Func1, &test, SH_MEMBER(&hook, &CHook::Func1_Post2), true);
    1.71 +	SH_ADD_HOOK(Test, Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Pre2), false);
    1.72 +	SH_ADD_HOOK(Test, Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Post2), true);
    1.73  
    1.74  	int &ret4 = pTest->Func1();
    1.75  	ADD_STATE(State_Func1_Ret(&ret4));
    1.76 @@ -160,13 +165,13 @@
    1.77  	CHECK_COND(hook.m_Var == 1337, "Part 4.1");
    1.78  	
    1.79  	// Through a callclass
    1.80 -	SourceHook::CallClass<Test> *cc1 = SH_GET_CALLCLASS(&test);
    1.81 +	SourceHook::CallClass<Test> *cc1 = SH_GET_CALLCLASS(pTest);
    1.82  	int &ret5 = SH_CALL(cc1, &Test::Func1)();
    1.83  	ADD_STATE(State_Func1_Ret(&ret5));
    1.84  
    1.85  	CHECK_STATES((&g_States,
    1.86 -		new State_Func1(&test.m_Var1),
    1.87 -		new State_Func1_Ret(&test.m_Var1),
    1.88 +		new State_Func1(&pTest->m_Var1),
    1.89 +		new State_Func1_Ret(&pTest->m_Var1),
    1.90  		NULL), "Part 5");
    1.91  
    1.92  	SH_RELEASE_CALLCLASS(cc1);
    1.93 @@ -177,21 +182,21 @@
    1.94  	ADD_STATE(State_Func2_Ret(&ret21));
    1.95  
    1.96  	CHECK_STATES((&g_States,
    1.97 -		new State_Func2(500, &test.m_Var2),
    1.98 -		new State_Func2_Ret(&test.m_Var2),
    1.99 +		new State_Func2(500, &pTest->m_Var2),
   1.100 +		new State_Func2_Ret(&pTest->m_Var2),
   1.101  		NULL), "Part 6");
   1.102  
   1.103 -	SH_ADD_HOOK(Test, Func2, &test, SH_MEMBER(&hook, &CHook::Func2_Pre1), false);
   1.104 -	SH_ADD_HOOK(Test, Func2, &test, SH_MEMBER(&hook, &CHook::Func2_Post1), true);
   1.105 +	SH_ADD_HOOK(Test, Func2, pTest, SH_MEMBER(&hook, &CHook::Func2_Pre1), false);
   1.106 +	SH_ADD_HOOK(Test, Func2, pTest, SH_MEMBER(&hook, &CHook::Func2_Post1), true);
   1.107  
   1.108  	const int &ret22 = pTest->Func2(500);
   1.109  	ADD_STATE(State_Func2_Ret(&ret22));
   1.110  
   1.111  	CHECK_STATES((&g_States,
   1.112  		new State_Func2_Pre1(500, &hook.m_Var),		// p1 was 500; it's going to override with hook.m_Var; and also change p1 to 1337
   1.113 -		new State_Func2(1337, &test.m_Var2),		// p1 was 1337; it's going to ret test.m_Var2
   1.114 +		new State_Func2(1337, &pTest->m_Var2),		// p1 was 1337; it's going to ret pTest->m_Var2
   1.115  		new State_Func2_Post1(1337,					// p1 was 1337
   1.116 -			&test.m_Var2,							// orig ret was test.m_Var2
   1.117 +			&pTest->m_Var2,							// orig ret was pTest->m_Var2
   1.118  			&hook.m_Var),							// override ret was hook.m_Var
   1.119  		new State_Func2_Ret(&hook.m_Var),			// really returned hook.m_Var
   1.120  		NULL), "Part 7");