2005-05-27 23:39:30 +02:00
|
|
|
// TESTBAIL
|
2005-12-23 12:58:11 +01:00
|
|
|
// This test used to be a test for a bug BAIL found.
|
|
|
|
// That bug is now fixed so I've granted BAIL the pleasure of being a test for
|
|
|
|
// the correct priority ordering of hook managers based on their version.
|
|
|
|
|
|
|
|
/*
|
|
|
|
THE PROBLEM:
|
|
|
|
Old hook funcs don't work right when you combine override returns and recalls.
|
|
|
|
THE SOLUTION:
|
|
|
|
Always use a new hook func when possible. For this, hook funcs have to be able to say
|
|
|
|
" HELLO I'M NEW! "
|
|
|
|
|
|
|
|
This file tests that functionality.
|
|
|
|
|
|
|
|
How it works:
|
|
|
|
testbail.cpp compiles with old version of sourcehook.h.
|
|
|
|
It sets everything up, adds a hook on a function
|
|
|
|
Then testbail2.cpp which has the new version adds a hook on the same function and
|
|
|
|
does a recall and overrides the value in it.
|
|
|
|
*/
|
|
|
|
#include "sourcehook_test.h"
|
2005-05-27 23:39:30 +02:00
|
|
|
#include "testbail.h"
|
|
|
|
|
2005-12-24 00:00:55 +01:00
|
|
|
namespace N_TestBail
|
|
|
|
{
|
|
|
|
StateList g_States;
|
|
|
|
SourceHook::ISourceHook *g_SHPtr;
|
|
|
|
IGaben *g_Gabgab;
|
|
|
|
}
|
2005-05-27 23:39:30 +02:00
|
|
|
|
2005-10-05 23:51:02 +02:00
|
|
|
namespace
|
|
|
|
{
|
2005-12-23 12:58:11 +01:00
|
|
|
int EatYams_Handler1(int a)
|
2005-10-05 23:51:02 +02:00
|
|
|
{
|
2005-12-23 12:58:11 +01:00
|
|
|
ADD_STATE(State_EatYams_Handler1_Called(a));
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, 0);
|
2005-10-05 23:51:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-27 23:39:30 +02:00
|
|
|
bool TestBail(std::string &error)
|
|
|
|
{
|
2005-12-23 12:58:11 +01:00
|
|
|
GET_SHPTR(g_SHPtr);
|
2005-05-27 23:39:30 +02:00
|
|
|
g_PLID = 1;
|
|
|
|
|
|
|
|
g_Gabgab = new IGaben;
|
|
|
|
|
2007-05-07 20:35:59 +02:00
|
|
|
SH_ADD_HOOK(IGaben, EatYams, g_Gabgab, SH_STATIC(EatYams_Handler1), false);
|
2005-05-27 23:39:30 +02:00
|
|
|
|
2005-12-23 12:58:11 +01:00
|
|
|
ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
|
2005-05-27 23:39:30 +02:00
|
|
|
|
2005-12-23 12:58:11 +01:00
|
|
|
CHECK_STATES((&g_States,
|
|
|
|
new State_EatYams_Handler1_Called(0xDEAD),
|
|
|
|
new State_EatYams_Called(0xDEAD),
|
|
|
|
new State_EatYams_Return(5),
|
|
|
|
NULL), "Part 1");
|
2005-05-27 23:39:30 +02:00
|
|
|
|
2005-12-24 00:00:55 +01:00
|
|
|
if (!TestBail2(error))
|
2005-12-23 12:58:11 +01:00
|
|
|
return false;
|
2005-05-27 23:39:30 +02:00
|
|
|
|
2005-12-23 12:58:11 +01:00
|
|
|
CHECK_STATES((&g_States,
|
|
|
|
new State_EatYams_Handler1_Called(0xDEAD),
|
|
|
|
new State_EatYams_Handler2_Called(0xDEAD),
|
|
|
|
new State_EatYams_Handler3_Called(0xBEEF),
|
|
|
|
new State_EatYams_Called(0xBEEF),
|
|
|
|
NULL), "Part 2.1");
|
2005-05-27 23:39:30 +02:00
|
|
|
|
2005-12-23 12:58:11 +01:00
|
|
|
// WHAT IF NOW SOMEONE UNLOADS PLUGIN 2 !?!?!?!?
|
|
|
|
Test_UnloadPlugin(g_SHPtr, 2);
|
2005-05-27 23:39:30 +02:00
|
|
|
|
2005-12-23 12:58:11 +01:00
|
|
|
ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
|
2005-05-27 23:39:30 +02:00
|
|
|
|
2005-12-23 12:58:11 +01:00
|
|
|
CHECK_STATES((&g_States,
|
|
|
|
new State_EatYams_Handler1_Called(0xDEAD),
|
|
|
|
new State_EatYams_Called(0xDEAD),
|
|
|
|
new State_EatYams_Return(5),
|
|
|
|
NULL), "Part 3");
|
2005-10-05 23:51:02 +02:00
|
|
|
|
2007-05-07 20:35:59 +02:00
|
|
|
SH_REMOVE_HOOK(IGaben, EatYams, g_Gabgab, SH_STATIC(EatYams_Handler1), false);
|
2005-10-05 23:51:02 +02:00
|
|
|
|
2005-12-23 12:58:11 +01:00
|
|
|
ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
|
2005-10-05 23:51:02 +02:00
|
|
|
|
2005-12-23 12:58:11 +01:00
|
|
|
CHECK_STATES((&g_States,
|
|
|
|
new State_EatYams_Called(0xDEAD),
|
|
|
|
new State_EatYams_Return(5),
|
|
|
|
NULL), "Part 4");
|
2005-10-05 23:51:02 +02:00
|
|
|
|
2005-12-24 00:00:55 +01:00
|
|
|
// Now, heh, try it the other way round.
|
|
|
|
|
|
|
|
Test_CompleteShutdown(g_SHPtr);
|
|
|
|
|
|
|
|
if (!TestBail2(error))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
CHECK_STATES((&g_States,
|
|
|
|
new State_EatYams_Handler2_Called(0xDEAD),
|
|
|
|
new State_EatYams_Handler3_Called(0xBEEF),
|
|
|
|
new State_EatYams_Called(0xBEEF),
|
|
|
|
NULL), "Part 5");
|
|
|
|
|
2007-05-07 20:35:59 +02:00
|
|
|
SH_ADD_HOOK(IGaben, EatYams, g_Gabgab, SH_STATIC(EatYams_Handler1), false);
|
2005-12-24 00:00:55 +01:00
|
|
|
|
|
|
|
ADD_STATE(State_EatYams_Return(g_Gabgab->EatYams(0xDEAD)));
|
|
|
|
|
|
|
|
CHECK_STATES((&g_States,
|
|
|
|
new State_EatYams_Handler2_Called(0xDEAD),
|
|
|
|
new State_EatYams_Handler3_Called(0xBEEF),
|
|
|
|
new State_EatYams_Handler1_Called(0xBEEF),
|
|
|
|
new State_EatYams_Called(0xBEEF),
|
|
|
|
new State_EatYams_Return(6),
|
|
|
|
NULL), "Part 6");
|
|
|
|
|
2005-12-23 12:58:11 +01:00
|
|
|
delete g_Gabgab;
|
2005-10-05 23:51:02 +02:00
|
|
|
|
2005-05-27 23:39:30 +02:00
|
|
|
return true;
|
|
|
|
}
|