1.1 --- a/sourcehook/test/testbail.cpp Thu Oct 04 19:46:28 2007 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,115 +0,0 @@
1.4 -// TESTBAIL
1.5 -// This test used to be a test for a bug BAIL found.
1.6 -// That bug is now fixed so I've granted BAIL the pleasure of being a test for
1.7 -// the correct priority ordering of hook managers based on their version.
1.8 -
1.9 -/*
1.10 - THE PROBLEM:
1.11 - Old hook funcs don't work right when you combine override returns and recalls.
1.12 - THE SOLUTION:
1.13 - Always use a new hook func when possible. For this, hook funcs have to be able to say
1.14 - " HELLO I'M NEW! "
1.15 -
1.16 - This file tests that functionality.
1.17 -
1.18 - How it works:
1.19 - testbail.cpp compiles with old version of sourcehook.h.
1.20 - It sets everything up, adds a hook on a function
1.21 - Then testbail2.cpp which has the new version adds a hook on the same function and
1.22 - does a recall and overrides the value in it.
1.23 -*/
1.24 -#include "sourcehook_test.h"
1.25 -#include "testbail.h"
1.26 -
1.27 -namespace N_TestBail
1.28 -{
1.29 - StateList g_States;
1.30 - SourceHook::ISourceHook *g_SHPtr;
1.31 - IGaben *g_Gabgab;
1.32 -}
1.33 -
1.34 -namespace
1.35 -{
1.36 - int EatYams_Handler1(int a)
1.37 - {
1.38 - ADD_STATE(State_EatYams_Handler1_Called(a));
1.39 - RETURN_META_VALUE(MRES_IGNORED, 0);
1.40 - }
1.41 -}
1.42 -
1.43 -bool TestBail(std::string &error)
1.44 -{
1.45 - GET_SHPTR(g_SHPtr);
1.46 - g_PLID = 1;
1.47 -
1.48 - g_Gabgab = new IGaben;
1.49 -
1.50 - SH_ADD_HOOK(IGaben, EatYams, g_Gabgab, SH_STATIC(EatYams_Handler1), false);
1.51 -
1.52 - ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
1.53 -
1.54 - CHECK_STATES((&g_States,
1.55 - new State_EatYams_Handler1_Called(0xDEAD),
1.56 - new State_EatYams_Called(0xDEAD),
1.57 - new State_EatYams_Return(5),
1.58 - NULL), "Part 1");
1.59 -
1.60 - if (!TestBail2(error))
1.61 - return false;
1.62 -
1.63 - CHECK_STATES((&g_States,
1.64 - new State_EatYams_Handler1_Called(0xDEAD),
1.65 - new State_EatYams_Handler2_Called(0xDEAD),
1.66 - new State_EatYams_Handler3_Called(0xBEEF),
1.67 - new State_EatYams_Called(0xBEEF),
1.68 - NULL), "Part 2.1");
1.69 -
1.70 - // WHAT IF NOW SOMEONE UNLOADS PLUGIN 2 !?!?!?!?
1.71 - Test_UnloadPlugin(g_SHPtr, 2);
1.72 -
1.73 - ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
1.74 -
1.75 - CHECK_STATES((&g_States,
1.76 - new State_EatYams_Handler1_Called(0xDEAD),
1.77 - new State_EatYams_Called(0xDEAD),
1.78 - new State_EatYams_Return(5),
1.79 - NULL), "Part 3");
1.80 -
1.81 - SH_REMOVE_HOOK(IGaben, EatYams, g_Gabgab, SH_STATIC(EatYams_Handler1), false);
1.82 -
1.83 - ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
1.84 -
1.85 - CHECK_STATES((&g_States,
1.86 - new State_EatYams_Called(0xDEAD),
1.87 - new State_EatYams_Return(5),
1.88 - NULL), "Part 4");
1.89 -
1.90 - // Now, heh, try it the other way round.
1.91 -
1.92 - Test_CompleteShutdown(g_SHPtr);
1.93 -
1.94 - if (!TestBail2(error))
1.95 - return false;
1.96 -
1.97 - CHECK_STATES((&g_States,
1.98 - new State_EatYams_Handler2_Called(0xDEAD),
1.99 - new State_EatYams_Handler3_Called(0xBEEF),
1.100 - new State_EatYams_Called(0xBEEF),
1.101 - NULL), "Part 5");
1.102 -
1.103 - SH_ADD_HOOK(IGaben, EatYams, g_Gabgab, SH_STATIC(EatYams_Handler1), false);
1.104 -
1.105 - ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
1.106 -
1.107 - CHECK_STATES((&g_States,
1.108 - new State_EatYams_Handler2_Called(0xDEAD),
1.109 - new State_EatYams_Handler3_Called(0xBEEF),
1.110 - new State_EatYams_Handler1_Called(0xBEEF),
1.111 - new State_EatYams_Called(0xBEEF),
1.112 - new State_EatYams_Return(6),
1.113 - NULL), "Part 6");
1.114 -
1.115 - delete g_Gabgab;
1.116 -
1.117 - return true;
1.118 -}