sourcehook/test/testhookmangen.hxx
branchhookman_autogen
changeset 432 f26dd3e3030b
child 436 41f21d77c3c1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sourcehook/test/testhookmangen.hxx	Sun Oct 21 21:47:53 2007 +0000
     1.3 @@ -0,0 +1,578 @@
     1.4 +// Strip &
     1.5 +template <class T> struct StripRef
     1.6 +{
     1.7 +	typedef T type;
     1.8 +};
     1.9 +
    1.10 +template <class T> struct StripRef<T&>
    1.11 +{
    1.12 +	typedef T type;
    1.13 +};
    1.14 +
    1.15 +// Address of constructor/destructor
    1.16 +// (using wrappers)
    1.17 +template <class T>
    1.18 +class Ctor_Thunk
    1.19 +{
    1.20 +public:
    1.21 +	void NormalConstructor()
    1.22 +	{
    1.23 +		new(this) T;
    1.24 +	}
    1.25 +
    1.26 +	void CopyConstructor(const T &other)
    1.27 +	{
    1.28 +		new(this) T(other);
    1.29 +	}
    1.30 +
    1.31 +	void Destructor()
    1.32 +	{
    1.33 +		reinterpret_cast<T*>(this)->~T();
    1.34 +	}
    1.35 +};
    1.36 +
    1.37 +
    1.38 +template <class T>
    1.39 +void *FindFuncAddr(T mfp)
    1.40 +{
    1.41 +	if (sizeof(mfp) != sizeof(void*))
    1.42 +		return NULL;
    1.43 +	else
    1.44 +		return fastdelegate::detail::horrible_cast<void*>(mfp);
    1.45 +}
    1.46 +
    1.47 +// Reference carrier
    1.48 +template <class T> struct MyRefCarrier
    1.49 +{
    1.50 +	typedef T type;
    1.51 +};
    1.52 +
    1.53 +template <class T> struct MyRefCarrier<T&>
    1.54 +{
    1.55 +	class type
    1.56 +	{
    1.57 +		T *m_StoredRef;
    1.58 +	public:
    1.59 +		type() : m_StoredRef(NULL)
    1.60 +		{
    1.61 +		}
    1.62 +		type(T& ref) : m_StoredRef(&ref)
    1.63 +		{
    1.64 +		}
    1.65 +
    1.66 +		T& operator= (T& ref)
    1.67 +		{
    1.68 +			m_StoredRef = &ref;
    1.69 +			return ref;
    1.70 +		}
    1.71 +
    1.72 +		operator T& () const
    1.73 +		{
    1.74 +			return *m_StoredRef;
    1.75 +		}
    1.76 +		
    1.77 +		bool operator== (const typename MyRefCarrier<T&>::type &other)
    1.78 +		{
    1.79 +			return m_StoredRef == other.m_StoredRef;
    1.80 +		}
    1.81 +		
    1.82 +		friend std::ostream& operator <<(std::ostream &os,const typename MyRefCarrier<T&>::type &obj)
    1.83 +		{
    1.84 +			os << *obj.m_StoredRef;
    1.85 +			return os;
    1.86 +		}
    1.87 +	};
    1.88 +};
    1.89 +
    1.90 +// Stores parameter status
    1.91 +@[$1,0,$a:
    1.92 +
    1.93 +template<int dummy@[$2,1,$1:, class p$2@]>
    1.94 +struct ParamState$1
    1.95 +{
    1.96 +	@[$2,1,$1:typename MyRefCarrier<p$2>::type m_$2; @]
    1.97 +	
    1.98 +	bool operator==(const ParamState$1<dummy@[$2,1,$1:, p$2@]> &other)
    1.99 +	{
   1.100 +		return true
   1.101 +			@[$2,1,$1: && m_$1 == other.m_$1@]
   1.102 +			;
   1.103 +	}
   1.104 +	ParamState$1(@[$2,1,$1|, :p$2 a$2@]) @[$1!=0::@] @[$2,1,$1|, :m_$2(a$2)@]
   1.105 +	{
   1.106 +	}
   1.107 +	
   1.108 +	ParamState$1<dummy@[$2,1,$1:, p$2@]> & operator() (int incrsteps)
   1.109 +	{
   1.110 +		@[$1!=0:int i;@]
   1.111 +		@[$2,1,$1:
   1.112 +		for (i = 0; i < incrsteps; ++i)
   1.113 +			Increment<StripRef< p$2 >::type>::Incr(m_$2);
   1.114 +		@]
   1.115 +		
   1.116 +		return *this;
   1.117 +	}
   1.118 +};
   1.119 +
   1.120 +@[$1!=0:template<@[$2,1,$1|, :class p$2@]>@]
   1.121 +std::ostream& operator <<(std::ostream &os,const ParamState$1<0@[$2,1,$1:, p$2@]> &obj)
   1.122 +{
   1.123 +	@[$1!=0:os@] @[$2,1,$1:<< obj.m_$2@];
   1.124 +	return os;
   1.125 +}
   1.126 +	
   1.127 +@]
   1.128 +
   1.129 +#define CAT2(a, b) a##b
   1.130 +#define CAT3(a, b, c) a##b##c
   1.131 +#define CAT4(a, b, c, d) a##b##c##d
   1.132 +
   1.133 +// hook1: pre ignore
   1.134 +// hook2: pre supercede
   1.135 +// hook3: post ignore
   1.136 +// hook4: post supercede
   1.137 +
   1.138 +
   1.139 +@[$1,0,$a:
   1.140 +
   1.141 +#define THGM_MAKE_TEST$1_void(id@[$2,1,$1:, param$2@]) \
   1.142 +	struct TestClass##id; \
   1.143 +	typedef ParamState$1<0@[$2,1,$1:, param$2@] > ParamState_m##id; \
   1.144 +	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
   1.145 +	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   1.146 +	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   1.147 +	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   1.148 +	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   1.149 +	\
   1.150 +	struct TestClass##id \
   1.151 +	{ \
   1.152 +		static bool ms_DoRecall; \
   1.153 +		\
   1.154 +		virtual void Func(@[$2,1,$1|, :param$2 p$2@]) \
   1.155 +		{ \
   1.156 +			g_Inside_LeafFunc = true; \
   1.157 +			ADD_STATE(State_Func##id(this, ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
   1.158 +			g_Inside_LeafFunc = false; \
   1.159 +		} \
   1.160 +		\
   1.161 +		struct Delegate1 : public MyDelegate \
   1.162 +		{ \
   1.163 +			virtual void Call(@[$2,1,$1|, :param$2 p$2@]) \
   1.164 +			{ \
   1.165 +				g_Inside_LeafFunc = true; \
   1.166 +				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
   1.167 +				g_Inside_LeafFunc = false; \
   1.168 +				if (ms_DoRecall) \
   1.169 +				{ \
   1.170 +					@[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
   1.171 +					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (@[$2,1,$1|, :p$2@])); \
   1.172 +				} \
   1.173 +				else \
   1.174 +					RETURN_META(MRES_IGNORED); \
   1.175 +			} \
   1.176 +		}; \
   1.177 +		struct Delegate2 : public MyDelegate \
   1.178 +		{ \
   1.179 +			virtual void Call(@[$2,1,$1|, :param$2 p$2@]) \
   1.180 +			{ \
   1.181 +				g_Inside_LeafFunc = true; \
   1.182 +				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
   1.183 +				g_Inside_LeafFunc = false; \
   1.184 +				if (ms_DoRecall) \
   1.185 +				{ \
   1.186 +					@[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
   1.187 +					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (@[$2,1,$1|, :p$2@])); \
   1.188 +				} \
   1.189 +				else \
   1.190 +					RETURN_META(MRES_SUPERCEDE); \
   1.191 +			} \
   1.192 +		}; \
   1.193 +		struct Delegate3 : public MyDelegate \
   1.194 +		{ \
   1.195 +			virtual void Call(@[$2,1,$1|, :param$2 p$2@]) \
   1.196 +			{ \
   1.197 +				g_Inside_LeafFunc = true; \
   1.198 +				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
   1.199 +				g_Inside_LeafFunc = false; \
   1.200 +				if (ms_DoRecall) \
   1.201 +				{ \
   1.202 +					@[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
   1.203 +					RETURN_META_NEWPARAMS(MRES_IGNORED, &TestClass##id::Func, (@[$2,1,$1|, :p$2@])); \
   1.204 +				} \
   1.205 +				else \
   1.206 +					RETURN_META(MRES_IGNORED); \
   1.207 +			} \
   1.208 +		}; \
   1.209 +		struct Delegate4 : public MyDelegate \
   1.210 +		{ \
   1.211 +			virtual void Call(@[$2,1,$1|, :param$2 p$2@]) \
   1.212 +			{ \
   1.213 +				g_Inside_LeafFunc = true; \
   1.214 +				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
   1.215 +				g_Inside_LeafFunc = false; \
   1.216 +				if (ms_DoRecall) \
   1.217 +				{ \
   1.218 +					@[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
   1.219 +					RETURN_META_NEWPARAMS(MRES_SUPERCEDE, &TestClass##id::Func, (@[$2,1,$1|, :p$2@])); \
   1.220 +				} \
   1.221 +				else \
   1.222 +					RETURN_META(MRES_SUPERCEDE); \
   1.223 +			}; \
   1.224 +		}; \
   1.225 +	}; \
   1.226 +	\
   1.227 +	bool TestClass##id::ms_DoRecall = false; \
   1.228 +	\
   1.229 +	SourceHook::PassInfo paraminfos_##id[$1+1]; \
   1.230 +	SourceHook::PassInfo::V2Info paraminfos2_##id[$1+1]; \
   1.231 +	SourceHook::ProtoInfo protoinfo_##id = { $1, {0, 0, 0}, paraminfos_##id, \
   1.232 +		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
   1.233 +	\
   1.234 +	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
   1.235 +	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
   1.236 +
   1.237 +
   1.238 +#define THGM_MAKE_TEST$1(id, ret_type@[$2,1,$1:, param$2@]) \
   1.239 +	struct TestClass##id; \
   1.240 +	typedef ParamState$1<0@[$2,1,$1:, param$2@] > ParamState_m##id; \
   1.241 +	MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
   1.242 +	MAKE_STATE_3(State_Deleg1_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   1.243 +	MAKE_STATE_3(State_Deleg2_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   1.244 +	MAKE_STATE_3(State_Deleg3_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   1.245 +	MAKE_STATE_3(State_Deleg4_##id, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
   1.246 +	\
   1.247 +	struct TestClass##id \
   1.248 +	{ \
   1.249 +		static bool ms_DoRecall; \
   1.250 +		\
   1.251 +		virtual ret_type Func(@[$2,1,$1|, :param$2 p$2@]) \
   1.252 +		{ \
   1.253 +			g_Inside_LeafFunc = true; \
   1.254 +			ADD_STATE(State_Func##id(this, ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
   1.255 +			g_Inside_LeafFunc = false; \
   1.256 +			\
   1.257 +			return 0; \
   1.258 +		} \
   1.259 +		\
   1.260 +		struct Delegate1 : public MyDelegate \
   1.261 +		{ \
   1.262 +			virtual ret_type Call(@[$2,1,$1|, :param$2 p$2@]) \
   1.263 +			{ \
   1.264 +				g_Inside_LeafFunc = true; \
   1.265 +				ADD_STATE(State_Deleg1_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
   1.266 +				g_Inside_LeafFunc = false; \
   1.267 +				if (ms_DoRecall) \
   1.268 +				{ \
   1.269 +					@[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
   1.270 +					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, 1, &TestClass##id::Func, (@[$2,1,$1|, :p$2@])); \
   1.271 +				} \
   1.272 +				else \
   1.273 +					RETURN_META_VALUE(MRES_IGNORED, 1); \
   1.274 +			} \
   1.275 +		}; \
   1.276 +		struct Delegate2 : public MyDelegate \
   1.277 +		{ \
   1.278 +			virtual ret_type Call(@[$2,1,$1|, :param$2 p$2@]) \
   1.279 +			{ \
   1.280 +				g_Inside_LeafFunc = true; \
   1.281 +				ADD_STATE(State_Deleg2_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
   1.282 +				g_Inside_LeafFunc = false; \
   1.283 +				if (ms_DoRecall) \
   1.284 +				{ \
   1.285 +					@[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
   1.286 +					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, 2, &TestClass##id::Func, (@[$2,1,$1|, :p$2@])); \
   1.287 +				} \
   1.288 +				else \
   1.289 +					RETURN_META_VALUE(MRES_SUPERCEDE, 2); \
   1.290 +			} \
   1.291 +		}; \
   1.292 +		struct Delegate3 : public MyDelegate \
   1.293 +		{ \
   1.294 +			virtual ret_type Call(@[$2,1,$1|, :param$2 p$2@]) \
   1.295 +			{ \
   1.296 +				g_Inside_LeafFunc = true; \
   1.297 +				ADD_STATE(State_Deleg3_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
   1.298 +				g_Inside_LeafFunc = false; \
   1.299 +				if (ms_DoRecall) \
   1.300 +				{ \
   1.301 +					@[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
   1.302 +					RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, 3, &TestClass##id::Func, (@[$2,1,$1|, :p$2@])); \
   1.303 +				} \
   1.304 +				else \
   1.305 +					RETURN_META_VALUE(MRES_IGNORED, 3); \
   1.306 +			} \
   1.307 +		}; \
   1.308 +		struct Delegate4 : public MyDelegate \
   1.309 +		{ \
   1.310 +			virtual ret_type Call(@[$2,1,$1|, :param$2 p$2@]) \
   1.311 +			{ \
   1.312 +				g_Inside_LeafFunc = true; \
   1.313 +				ADD_STATE(State_Deleg4_##id(META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
   1.314 +				g_Inside_LeafFunc = false; \
   1.315 +				if (ms_DoRecall) \
   1.316 +				{ \
   1.317 +					@[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
   1.318 +					RETURN_META_VALUE_NEWPARAMS(MRES_SUPERCEDE, 4, &TestClass##id::Func, (@[$2,1,$1|, :p$2@])); \
   1.319 +				} \
   1.320 +				else \
   1.321 +					RETURN_META_VALUE(MRES_SUPERCEDE, 4); \
   1.322 +			}; \
   1.323 +		}; \
   1.324 +	}; \
   1.325 +	\
   1.326 +	bool TestClass##id::ms_DoRecall = false; \
   1.327 +	\
   1.328 +	SourceHook::PassInfo paraminfos_##id[$1+1]; \
   1.329 +	SourceHook::PassInfo::V2Info paraminfos2_##id[$1+1]; \
   1.330 +	SourceHook::ProtoInfo protoinfo_##id = { $1, {0, 0, 0}, paraminfos_##id, \
   1.331 +		SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
   1.332 +	\
   1.333 +	SourceHook::Impl::GenContext *g_Genc##id = NULL; \
   1.334 +	CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL); 
   1.335 +	
   1.336 +#define THGM_SETUP_PI$1(id@[$2,1,$1:, p$2_type, p$2_passtype, p$2_flags@]) \
   1.337 +	void setuppi_##id() \
   1.338 +	{ \
   1.339 +		paraminfos_##id[0].size = 1; paraminfos_##id[0].type = 0; paraminfos_##id[0].flags = 0; \
   1.340 +		\
   1.341 +		@[$2,1,$1: paraminfos_##id[$2].size = sizeof(p$2_type); paraminfos_##id[$2].type = p$2_passtype; paraminfos_##id[$2].flags = p$2_flags; @] \
   1.342 +		\
   1.343 +		@[$2,1,$1: paraminfos2_##id[$2].pNormalCtor = (paraminfos_##id[$2].flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p$2_type >::type>::NormalConstructor) : NULL; @] \
   1.344 +		@[$2,1,$1: paraminfos2_##id[$2].pCopyCtor = (paraminfos_##id[$2].flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p$2_type >::type>::CopyConstructor) : NULL; @] \
   1.345 +		@[$2,1,$1: paraminfos2_##id[$2].pDtor = (paraminfos_##id[$2].flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p$2_type >::type>::Destructor) : NULL; @] \
   1.346 +	}
   1.347 +	
   1.348 +@]
   1.349 +
   1.350 +#define THGM_SETUP_RI(id, ret_type, ret_passtype, ret_flags) \
   1.351 +	void setupri_##id() \
   1.352 +	{ \
   1.353 +		protoinfo_##id.retPassInfo.size = sizeof(ret_type); \
   1.354 +		protoinfo_##id.retPassInfo.type = ret_passtype; \
   1.355 +		protoinfo_##id.retPassInfo.flags = ret_flags; \
   1.356 +		\
   1.357 +		protoinfo_##id.retPassInfo2.pNormalCtor = (protoinfo_##id.retPassInfo.flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::NormalConstructor) : NULL; \
   1.358 +		protoinfo_##id.retPassInfo2.pCopyCtor = (protoinfo_##id.retPassInfo.flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::CopyConstructor) : NULL; \
   1.359 +		protoinfo_##id.retPassInfo2.pDtor = (protoinfo_##id.retPassInfo.flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::Destructor) : NULL; \
   1.360 +	}
   1.361 +	
   1.362 +#define THGM_ADD_HOOK(id, num) \
   1.363 +	CAT4(hook, num, _, id) = g_SHPtr->AddHook(g_PLID, SourceHook::ISourceHook::Hook_Normal, reinterpret_cast<void*>(pTest##id), \
   1.364 +		0, myhookman##id, PtrBufPtr(new TestClass##id::Delegate##num), num >= 3);
   1.365 +
   1.366 +#define THGM_REMOVE_HOOK(id, num) \
   1.367 +	g_SHPtr->RemoveHookByID(CAT4(hook, num, _, id));
   1.368 +
   1.369 +#define THGM_CALLS_void(id, call_params) \
   1.370 +	pTest##id->Func call_params; \
   1.371 +	SH_CALL(pTest##id, &TestClass##id::Func) call_params;
   1.372 +
   1.373 +#define THGM_DO_TEST_void(id, call_params) \
   1.374 +	setuppi_##id(); \
   1.375 +	g_Genc##id = new SourceHook::Impl::GenContext(&protoinfo_##id, 0, 0, g_SHPtr); \
   1.376 +	g_Genc_ad##id.set(g_Genc##id); \
   1.377 +	SourceHook::HookManagerPubFunc myhookman##id = g_Genc##id->Generate(); \
   1.378 +	int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
   1.379 +	\
   1.380 +	TestClass##id::ms_DoRecall = false; \
   1.381 +	TestClass##id *pTest##id = new TestClass##id; \
   1.382 +	CAutoPtrDestruction<TestClass##id> apd##id(pTest##id); \
   1.383 +	\
   1.384 +			/* no hooks - no hooks */ \
   1.385 +	PtrBuf_Clear(); \
   1.386 +	THGM_CALLS_void(id, call_params); \
   1.387 +	CHECK_STATES((&g_States, \
   1.388 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.389 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.390 +		NULL), "Test" #id " Part1"); \
   1.391 +	\
   1.392 +			/* hook1 - no hooks */ \
   1.393 +	PtrBuf_Clear(); \
   1.394 +	THGM_ADD_HOOK(id, 1); \
   1.395 +	THGM_CALLS_void(id, call_params); \
   1.396 +	CHECK_STATES((&g_States, \
   1.397 +		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
   1.398 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.399 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.400 +		NULL), "Test" #id " Part2"); \
   1.401 +	THGM_REMOVE_HOOK(id, 1); \
   1.402 +	\
   1.403 +			/* no hooks - hook3 */ \
   1.404 +	PtrBuf_Clear(); \
   1.405 +	THGM_ADD_HOOK(id, 3); \
   1.406 +	THGM_CALLS_void(id, call_params); \
   1.407 +	CHECK_STATES((&g_States, \
   1.408 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.409 +		new State_Deleg3_##id(pTest##id, 0, ParamState_m##id call_params), \
   1.410 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.411 +		NULL), "Test" #id " Part3"); \
   1.412 +	THGM_REMOVE_HOOK(id, 3); \
   1.413 +	\
   1.414 +			/* hook1 - hook3 */ \
   1.415 +	PtrBuf_Clear(); \
   1.416 +	THGM_ADD_HOOK(id, 1); \
   1.417 +	THGM_ADD_HOOK(id, 3); \
   1.418 +	THGM_CALLS_void(id, call_params); \
   1.419 +	CHECK_STATES((&g_States, \
   1.420 +		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
   1.421 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.422 +		new State_Deleg3_##id(pTest##id, 1, ParamState_m##id call_params), \
   1.423 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.424 +		NULL), "Test" #id " Part4"); \
   1.425 +	THGM_REMOVE_HOOK(id, 1); \
   1.426 +	THGM_REMOVE_HOOK(id, 3); \
   1.427 +	\
   1.428 +			/* hook1, hook2 - hook3 */ \
   1.429 +	PtrBuf_Clear(); \
   1.430 +	THGM_ADD_HOOK(id, 1); \
   1.431 +	THGM_ADD_HOOK(id, 2); \
   1.432 +	THGM_ADD_HOOK(id, 3); \
   1.433 +	THGM_CALLS_void(id, call_params); \
   1.434 +	CHECK_STATES((&g_States, \
   1.435 +		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
   1.436 +		new State_Deleg2_##id(pTest##id, 1, ParamState_m##id call_params), \
   1.437 +		new State_Deleg3_##id(pTest##id, 2, ParamState_m##id call_params), \
   1.438 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.439 +		NULL), "Test" #id " Part5"); \
   1.440 +	THGM_REMOVE_HOOK(id, 1); \
   1.441 +	THGM_REMOVE_HOOK(id, 2); \
   1.442 +	THGM_REMOVE_HOOK(id, 3); \
   1.443 +			/* hook1, hook2 - hook3, hook4 */ \
   1.444 +	PtrBuf_Clear(); \
   1.445 +	THGM_ADD_HOOK(id, 1); \
   1.446 +	THGM_ADD_HOOK(id, 2); \
   1.447 +	THGM_ADD_HOOK(id, 3); \
   1.448 +	THGM_ADD_HOOK(id, 4); \
   1.449 +	THGM_CALLS_void(id, call_params); \
   1.450 +	CHECK_STATES((&g_States, \
   1.451 +		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
   1.452 +		new State_Deleg2_##id(pTest##id, 1, ParamState_m##id call_params), \
   1.453 +		new State_Deleg3_##id(pTest##id, 2, ParamState_m##id call_params), \
   1.454 +		new State_Deleg4_##id(pTest##id, 3, ParamState_m##id call_params), \
   1.455 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.456 +		NULL), "Test" #id " Part6"); \
   1.457 +		\
   1.458 +			/* hook1 - hook3, hook4, with recalls! */ \
   1.459 +		\
   1.460 +	TestClass##id::ms_DoRecall = true; \
   1.461 +	THGM_REMOVE_HOOK(id, 2); \
   1.462 +	THGM_CALLS_void(id, call_params); \
   1.463 +	CHECK_STATES((&g_States, \
   1.464 +		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params(0)), \
   1.465 +		new State_Func##id(pTest##id, ParamState_m##id call_params(1)), \
   1.466 +		new State_Deleg3_##id(pTest##id, 2, ParamState_m##id call_params(1)), \
   1.467 +		new State_Deleg4_##id(pTest##id, 3, ParamState_m##id call_params(2)), \
   1.468 +		/* sh_call one */ \
   1.469 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.470 +		NULL), "Test" #id " Part7"); \
   1.471 +	THGM_REMOVE_HOOK(id, 1); \
   1.472 +	THGM_REMOVE_HOOK(id, 3); \
   1.473 +	THGM_REMOVE_HOOK(id, 4);
   1.474 +
   1.475 +
   1.476 +#define THGM_CALLS(id, call_params, exp_ret_norm, exp_ret_shcall, err) \
   1.477 +	CHECK_COND(pTest##id->Func call_params == exp_ret_norm, err " /retcallnorm"); \
   1.478 +	CHECK_COND(SH_CALL(pTest##id, &TestClass##id::Func) call_params == exp_ret_shcall, err " /retcallshcall");
   1.479 +
   1.480 +#define THGM_DO_TEST(id, call_params) \
   1.481 +	setuppi_##id(); \
   1.482 +	setupri_##id(); \
   1.483 +	g_Genc##id = new SourceHook::Impl::GenContext(&protoinfo_##id, 0, 0, g_SHPtr); \
   1.484 +	g_Genc_ad##id.set(g_Genc##id); \
   1.485 +	SourceHook::HookManagerPubFunc myhookman##id = g_Genc##id->Generate(); \
   1.486 +	int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
   1.487 +	\
   1.488 +	TestClass##id::ms_DoRecall = false; \
   1.489 +	TestClass##id *pTest##id = new TestClass##id; \
   1.490 +	CAutoPtrDestruction<TestClass##id> apd##id(pTest##id); \
   1.491 +	\
   1.492 +			/* no hooks - no hooks */ \
   1.493 +	PtrBuf_Clear(); \
   1.494 +	THGM_CALLS(id, call_params, 0, 0, "Part1"); \
   1.495 +	CHECK_STATES((&g_States, \
   1.496 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.497 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.498 +		NULL), "Test" #id " Part1"); \
   1.499 +	\
   1.500 +			/* hook1 - no hooks */ \
   1.501 +	PtrBuf_Clear(); \
   1.502 +	THGM_ADD_HOOK(id, 1); \
   1.503 +	THGM_CALLS(id, call_params, 0, 0, "Part2"); \
   1.504 +	CHECK_STATES((&g_States, \
   1.505 +		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
   1.506 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.507 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.508 +		NULL), "Test" #id " Part2"); \
   1.509 +	THGM_REMOVE_HOOK(id, 1); \
   1.510 +	\
   1.511 +			/* no hooks - hook3 */ \
   1.512 +	PtrBuf_Clear(); \
   1.513 +	THGM_ADD_HOOK(id, 3); \
   1.514 +	THGM_CALLS(id, call_params, 0, 0, "Part3"); \
   1.515 +	CHECK_STATES((&g_States, \
   1.516 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.517 +		new State_Deleg3_##id(pTest##id, 0, ParamState_m##id call_params), \
   1.518 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.519 +		NULL), "Test" #id " Part3"); \
   1.520 +	THGM_REMOVE_HOOK(id, 3); \
   1.521 +	\
   1.522 +			/* hook1 - hook3 */ \
   1.523 +	PtrBuf_Clear(); \
   1.524 +	THGM_ADD_HOOK(id, 1); \
   1.525 +	THGM_ADD_HOOK(id, 3); \
   1.526 +	THGM_CALLS(id, call_params, 0, 0, "Part4"); \
   1.527 +	CHECK_STATES((&g_States, \
   1.528 +		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
   1.529 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.530 +		new State_Deleg3_##id(pTest##id, 1, ParamState_m##id call_params), \
   1.531 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.532 +		NULL), "Test" #id " Part4"); \
   1.533 +	THGM_REMOVE_HOOK(id, 1); \
   1.534 +	THGM_REMOVE_HOOK(id, 3); \
   1.535 +	\
   1.536 +			/* hook1, hook2 - hook3 */ \
   1.537 +	PtrBuf_Clear(); \
   1.538 +	THGM_ADD_HOOK(id, 1); \
   1.539 +	THGM_ADD_HOOK(id, 2); \
   1.540 +	THGM_ADD_HOOK(id, 3); \
   1.541 +	THGM_CALLS(id, call_params, 2, 0, "Part5"); \
   1.542 +	CHECK_STATES((&g_States, \
   1.543 +		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
   1.544 +		new State_Deleg2_##id(pTest##id, 1, ParamState_m##id call_params), \
   1.545 +		new State_Deleg3_##id(pTest##id, 2, ParamState_m##id call_params), \
   1.546 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.547 +		NULL), "Test" #id " Part5"); \
   1.548 +	THGM_REMOVE_HOOK(id, 1); \
   1.549 +	THGM_REMOVE_HOOK(id, 2); \
   1.550 +	THGM_REMOVE_HOOK(id, 3); \
   1.551 +			/* hook1, hook2 - hook3, hook4 */ \
   1.552 +	PtrBuf_Clear(); \
   1.553 +	THGM_ADD_HOOK(id, 1); \
   1.554 +	THGM_ADD_HOOK(id, 2); \
   1.555 +	THGM_ADD_HOOK(id, 3); \
   1.556 +	THGM_ADD_HOOK(id, 4); \
   1.557 +	THGM_CALLS(id, call_params, 4, 0, "Part6"); \
   1.558 +	CHECK_STATES((&g_States, \
   1.559 +		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params), \
   1.560 +		new State_Deleg2_##id(pTest##id, 1, ParamState_m##id call_params), \
   1.561 +		new State_Deleg3_##id(pTest##id, 2, ParamState_m##id call_params), \
   1.562 +		new State_Deleg4_##id(pTest##id, 3, ParamState_m##id call_params), \
   1.563 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.564 +		NULL), "Test" #id " Part6"); \
   1.565 +		\
   1.566 +			/* hook1 - hook3, hook4, with recalls! */ \
   1.567 +		\
   1.568 +	TestClass##id::ms_DoRecall = true; \
   1.569 +	THGM_REMOVE_HOOK(id, 2); \
   1.570 +	THGM_CALLS(id, call_params, 4, 0, "Part7"); \
   1.571 +	CHECK_STATES((&g_States, \
   1.572 +		new State_Deleg1_##id(pTest##id, 0, ParamState_m##id call_params(0)), \
   1.573 +		new State_Func##id(pTest##id, ParamState_m##id call_params(1)), \
   1.574 +		new State_Deleg3_##id(pTest##id, 2, ParamState_m##id call_params(1)), \
   1.575 +		new State_Deleg4_##id(pTest##id, 3, ParamState_m##id call_params(2)), \
   1.576 +		/* sh_call one */ \
   1.577 +		new State_Func##id(pTest##id, ParamState_m##id call_params), \
   1.578 +		NULL), "Test" #id " Part7"); \
   1.579 +	THGM_REMOVE_HOOK(id, 1); \
   1.580 +	THGM_REMOVE_HOOK(id, 3); \
   1.581 +	THGM_REMOVE_HOOK(id, 4);