diff --git a/sourcehook/test/sourcehook_test.h b/sourcehook/test/sourcehook_test.h index de8dbd0..ee5566e 100644 --- a/sourcehook/test/sourcehook_test.h +++ b/sourcehook/test/sourcehook_test.h @@ -15,7 +15,8 @@ struct CAutoPtrDestruction { T *m_Ptr; CAutoPtrDestruction(T *p) : m_Ptr(p) { } - ~CAutoPtrDestruction() { delete m_Ptr; } + ~CAutoPtrDestruction() { if (m_Ptr) delete m_Ptr; } + void clear() { m_Ptr = NULL; } }; struct CSHPtrAutoDestruction diff --git a/sourcehook/test/test1.cpp b/sourcehook/test/test1.cpp index d7fa002..9926a8e 100644 --- a/sourcehook/test/test1.cpp +++ b/sourcehook/test/test1.cpp @@ -707,7 +707,14 @@ bool TestBasic(std::string &error) NULL), "Part 11 1/2"); - // 12) Test? Test. + // 12) Try out one ref param + SH_ADD_HOOK(Test, F60, pTest, SH_STATIC(F60_Pre), false); + int a = 0; + pTest->F60(a); + CHECK_COND(a == 10, "Part12"); + SH_REMOVE_HOOK(Test, F60, pTest, SH_STATIC(F60_Pre), false); + + // 13) Remove hooks after the instance has been removed SH_ADD_HOOK(Test, F1, pTest, SH_MEMBER(&f1_handlers, &HandlersF1::Pre), true); SH_ADD_HOOK(Test, F2, pTest, SH_MEMBER(&f1_handlers, &HandlersF1::Pre), true); SH_ADD_HOOK(Test, F3, pTest, SH_MEMBER(&f1_handlers, &HandlersF1::Pre), false); @@ -719,6 +726,9 @@ bool TestBasic(std::string &error) SH_ADD_HOOK(Test, F9, pTest, SH_MEMBER(&f1_handlers, &HandlersF1::Pre), false); SH_ADD_HOOK(Test, F10, pTest, SH_MEMBER(&f1_handlers, &HandlersF1::Pre), false); + delete pTest; + apd.clear(); + SH_REMOVE_HOOK(Test, F1, pTest, SH_MEMBER(&f1_handlers, &HandlersF1::Pre), true); SH_REMOVE_HOOK(Test, F2, pTest, SH_MEMBER(&f1_handlers, &HandlersF1::Pre), true); SH_REMOVE_HOOK(Test, F3, pTest, SH_MEMBER(&f1_handlers, &HandlersF1::Pre), false); @@ -729,14 +739,9 @@ bool TestBasic(std::string &error) SH_REMOVE_HOOK(Test, F8, pTest, SH_MEMBER(&f1_handlers, &HandlersF1::Pre), false); SH_REMOVE_HOOK(Test, F9, pTest, SH_MEMBER(&f1_handlers, &HandlersF1::Pre), false); SH_REMOVE_HOOK(Test, F10, pTest, SH_MEMBER(&f1_handlers, &HandlersF1::Pre), false); + CHECK_COND(SH_REMOVE_HOOK(Test, F10, pTest, SH_MEMBER(&f1_handlers, &HandlersF1::Pre), false) == false, "Part 12.1"); - SH_ADD_HOOK(Test, F60, pTest, SH_STATIC(F60_Pre), false); - - int a = 0; - pTest->F60(a); Test_CompleteShutdown(g_SHPtr); - CHECK_COND(a == 10, "Part12.a"); - return true; }