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