diff --git a/sourcehook/test/main.cpp b/sourcehook/test/main.cpp index b4a791f..742d5c9 100644 --- a/sourcehook/test/main.cpp +++ b/sourcehook/test/main.cpp @@ -63,6 +63,7 @@ DO_TEST(Basic); DO_TEST(VafmtAndOverload); DO_TEST(ThisPtrOffs); DO_TEST(PlugSys); +DO_TEST(Bail); int main(int argc, char *argv[]) { diff --git a/sourcehook/test/testbail.cpp b/sourcehook/test/testbail.cpp new file mode 100644 index 0000000..ce6b1b1 --- /dev/null +++ b/sourcehook/test/testbail.cpp @@ -0,0 +1,37 @@ +// TESTBAIL +// Test for a bug Bail has found + +#include "testbail.h" + +void *___testbail_gabgab; + +bool TestBail(std::string &error) +{ + SourceHook::CSourceHookImpl g_SHImpl; + g_SHPtr = &g_SHImpl; + g_PLID = 1; + + g_Gabgab = new IGaben; + ___testbail_gabgab = (void*)g_Gabgab; + + g_Gabgab->EatYams(); + + SH_ADD_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams0_Handler, false); + + g_Gabgab->EatYams(); + + ___TestBail2(); + + g_Gabgab->EatYams(); + + SH_REMOVE_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams0_Handler, false); + + g_Gabgab->EatYams(); + + delete g_Gabgab; + + // If it didn't crash, it's ok + + return true; +} + diff --git a/sourcehook/test/testbail.h b/sourcehook/test/testbail.h new file mode 100644 index 0000000..0ed80fc --- /dev/null +++ b/sourcehook/test/testbail.h @@ -0,0 +1,40 @@ +////////////////////////////////////////////////////////////////////////// +// Shared data for testbail + +#include +#include "sourcehook_impl.h" +#include "testevents.h" +#include + +void ___TestBail2(); + +namespace +{ + StateList g_States; + SourceHook::ISourceHook *g_SHPtr; + SourceHook::Plugin g_PLID; + + MAKE_STATE(State_EatYams_Called); + MAKE_STATE(State_EatYams_Handler_Called); + + + class IGaben + { + public: + virtual void EatYams() + { + ADD_STATE(State_EatYams_Called); + } + }; + + SH_DECL_HOOK0_void(IGaben, EatYams, SH_NOATTRIB, 0); + + void EatYams0_Handler() + { + ADD_STATE(State_EatYams_Handler_Called); + } + + IGaben *g_Gabgab; +} + +extern void *___testbail_gabgab; \ No newline at end of file diff --git a/sourcehook/test/testbail2.cpp b/sourcehook/test/testbail2.cpp new file mode 100644 index 0000000..dbe278d --- /dev/null +++ b/sourcehook/test/testbail2.cpp @@ -0,0 +1,23 @@ +// TESTBAIL +// Different compilation unit + +#include "testbail.h" + +void ___TestBail2() +{ + SourceHook::CSourceHookImpl g_SHImpl; + g_SHPtr = &g_SHImpl; + g_PLID = 2; + + g_Gabgab = (IGaben*)___testbail_gabgab; + + g_Gabgab->EatYams(); + + SH_ADD_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams0_Handler, false); + + g_Gabgab->EatYams(); + + SH_REMOVE_HOOK_STATICFUNC(IGaben, EatYams, g_Gabgab, EatYams0_Handler, false); + + g_Gabgab->EatYams(); +} \ No newline at end of file