sourcehook/test/testhookmangen.cpp
branchhookman_autogen
changeset 436 41f21d77c3c1
parent 435 35296642e147
child 437 89cf494f6088
     1.1 --- a/sourcehook/test/testhookmangen.cpp	Thu Nov 01 01:58:44 2007 +0000
     1.2 +++ b/sourcehook/test/testhookmangen.cpp	Thu Nov 01 17:29:39 2007 +0000
     1.3 @@ -18,53 +18,6 @@
     1.4  
     1.5  namespace
     1.6  {
     1.7 -	#include "testhookmangen.h"
     1.8 -
     1.9 -	StateList g_States;
    1.10 -	SourceHook::ISourceHook *g_SHPtr;
    1.11 -	SourceHook::Plugin g_PLID;
    1.12 -
    1.13 -	// PtrBuf(ptr) gives ptrs unique numbers
    1.14 -	// in the order they appear
    1.15 -	SourceHook::List<const void*> g_PtrHash;
    1.16 -
    1.17 -	bool g_Inside_LeafFunc = false;			// inside a hook or a func
    1.18 -
    1.19 -	template <class T>
    1.20 -	int PtrBuf(T ptr)
    1.21 -	{
    1.22 -		int a = 0;
    1.23 -
    1.24 -		const void *vptr = reinterpret_cast<const void*>(ptr);
    1.25 -		for (SourceHook::List<const void*>::iterator iter = g_PtrHash.begin(); iter != g_PtrHash.end(); ++iter)
    1.26 -		{
    1.27 -			if (*iter == vptr)
    1.28 -				return a;
    1.29 -			else
    1.30 -				++a;
    1.31 -		}
    1.32 -		g_PtrHash.push_back(vptr);
    1.33 -		return static_cast<int>(g_PtrHash.size()) - 1;
    1.34 -	}
    1.35 -
    1.36 -	template <class T>
    1.37 -	T PtrBufPtr(T ptr)
    1.38 -	{
    1.39 -		PtrBuf(ptr);
    1.40 -		return ptr;
    1.41 -	}
    1.42 -
    1.43 -	void PtrBuf_Clear(int leave_in = 0)
    1.44 -	{
    1.45 -		for (SourceHook::List<const void*>::iterator iter = g_PtrHash.begin(); iter != g_PtrHash.end();)
    1.46 -		{
    1.47 -			if (--leave_in < 0)
    1.48 -				iter = g_PtrHash.erase(iter);
    1.49 -			else
    1.50 -				++iter;
    1.51 -		}
    1.52 -	}
    1.53 -
    1.54  	// POD / Object types
    1.55  	template <int MYSIZE>
    1.56  	struct POD
    1.57 @@ -75,6 +28,16 @@
    1.58  		{
    1.59  			return memcmp(reinterpret_cast<void*>(x), reinterpret_cast<const void*>(other.x), MYSIZE) == 0;
    1.60  		}
    1.61 +
    1.62 +		bool operator==(char other)
    1.63 +		{
    1.64 +			for (int i = 0; i < MYSIZE; ++i)
    1.65 +			{
    1.66 +				if (x[i] != other)
    1.67 +					return false;
    1.68 +			}
    1.69 +			return true;
    1.70 +		}
    1.71  	};
    1.72  
    1.73  	template <int MYSIZE>
    1.74 @@ -132,6 +95,53 @@
    1.75  		return os;
    1.76  	}
    1.77  
    1.78 +	#include "testhookmangen.h"
    1.79 +
    1.80 +	StateList g_States;
    1.81 +	SourceHook::ISourceHook *g_SHPtr;
    1.82 +	SourceHook::Plugin g_PLID;
    1.83 +
    1.84 +	// PtrBuf(ptr) gives ptrs unique numbers
    1.85 +	// in the order they appear
    1.86 +	SourceHook::List<const void*> g_PtrHash;
    1.87 +
    1.88 +	bool g_Inside_LeafFunc = false;			// inside a hook or a func
    1.89 +
    1.90 +	template <class T>
    1.91 +	int PtrBuf(T ptr)
    1.92 +	{
    1.93 +		int a = 0;
    1.94 +
    1.95 +		const void *vptr = reinterpret_cast<const void*>(ptr);
    1.96 +		for (SourceHook::List<const void*>::iterator iter = g_PtrHash.begin(); iter != g_PtrHash.end(); ++iter)
    1.97 +		{
    1.98 +			if (*iter == vptr)
    1.99 +				return a;
   1.100 +			else
   1.101 +				++a;
   1.102 +		}
   1.103 +		g_PtrHash.push_back(vptr);
   1.104 +		return static_cast<int>(g_PtrHash.size()) - 1;
   1.105 +	}
   1.106 +
   1.107 +	template <class T>
   1.108 +	T PtrBufPtr(T ptr)
   1.109 +	{
   1.110 +		PtrBuf(ptr);
   1.111 +		return ptr;
   1.112 +	}
   1.113 +
   1.114 +	void PtrBuf_Clear(int leave_in = 0)
   1.115 +	{
   1.116 +		for (SourceHook::List<const void*>::iterator iter = g_PtrHash.begin(); iter != g_PtrHash.end();)
   1.117 +		{
   1.118 +			if (--leave_in < 0)
   1.119 +				iter = g_PtrHash.erase(iter);
   1.120 +			else
   1.121 +				++iter;
   1.122 +		}
   1.123 +	}
   1.124 +
   1.125  
   1.126  	// "Increment" something:  (reproducible change for recall tests)
   1.127  	//  integer: ++
   1.128 @@ -267,6 +277,31 @@
   1.129  	THGM_MAKE_TEST0(105, double);
   1.130  	THGM_SETUP_PI0(105);
   1.131  	THGM_SETUP_RI(105, double, SourceHook::PassInfo::PassType_Float, SourceHook::PassInfo::PassFlag_ByVal);
   1.132 +
   1.133 +	// pod 1-13
   1.134 +	THGM_MAKE_TEST1(106, POD<1>, int);
   1.135 +	THGM_SETUP_PI1(106,
   1.136 +		int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal
   1.137 +		);
   1.138 +	THGM_SETUP_RI(106, POD<1>, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByVal);
   1.139 +
   1.140 +	THGM_MAKE_TEST1(107, POD<4>, int);
   1.141 +	THGM_SETUP_PI1(107,
   1.142 +		int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal
   1.143 +		);
   1.144 +	THGM_SETUP_RI(107, POD<4>, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByVal);
   1.145 +
   1.146 +	THGM_MAKE_TEST1(108, POD<8>, int);
   1.147 +	THGM_SETUP_PI1(108,
   1.148 +		int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal
   1.149 +		);
   1.150 +	THGM_SETUP_RI(108, POD<8>, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByVal);
   1.151 +
   1.152 +	THGM_MAKE_TEST1(109, POD<13>, int);
   1.153 +	THGM_SETUP_PI1(109,
   1.154 +		int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal
   1.155 +		);
   1.156 +	THGM_SETUP_RI(109, POD<13>, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByVal);
   1.157  }
   1.158  
   1.159  bool TestHookManGen(std::string &error)
   1.160 @@ -292,10 +327,10 @@
   1.161  	double b = 233.33;
   1.162  	THGM_DO_TEST_void(7, (a, b));
   1.163  
   1.164 -	POD<7> pod7 = {78};
   1.165 +	POD<7> pod7 = MakeRet< POD<7> >::Do(78);
   1.166  	THGM_DO_TEST_void(8, (pod7));
   1.167  
   1.168 -	POD<600> pod600 = {34};
   1.169 +	POD<600> pod600 = MakeRet< POD<600> >::Do(34);
   1.170  	THGM_DO_TEST_void(9, (pod600));
   1.171  	
   1.172  	THGM_DO_TEST_void(10, (pod600));
   1.173 @@ -461,6 +496,12 @@
   1.174  
   1.175  	THGM_DO_TEST(105, ());
   1.176  
   1.177 +	// pod returns
   1.178 +	THGM_DO_TEST(106, (5));
   1.179 +	THGM_DO_TEST(107, (5));
   1.180 +	THGM_DO_TEST(108, (5));
   1.181 +	THGM_DO_TEST(109, (5));
   1.182 +
   1.183  	// Shutdown now!
   1.184  	// If we don't SH will auto-shutdown _after_ genc's destructor is called
   1.185  	//  -> crash