2005-04-30 21:10:07 +02:00
|
|
|
#include <string>
|
2005-12-23 12:58:11 +01:00
|
|
|
#include "sourcehook_test.h"
|
2005-04-30 21:10:07 +02:00
|
|
|
#include "testevents.h"
|
2005-05-01 16:30:52 +02:00
|
|
|
#include <stdarg.h>
|
2005-04-30 21:10:07 +02:00
|
|
|
|
2005-05-01 16:30:52 +02:00
|
|
|
// TEST2
|
|
|
|
// Vafmt and Overloaded functions
|
2005-04-30 21:10:07 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
StateList g_States;
|
|
|
|
SourceHook::ISourceHook *g_SHPtr;
|
|
|
|
SourceHook::Plugin g_PLID;
|
|
|
|
|
2005-05-01 16:30:52 +02:00
|
|
|
MAKE_STATE_1(State_EatYams_Called, int);
|
|
|
|
MAKE_STATE_1(State_EatYams_Handler_Called, int);
|
|
|
|
MAKE_STATE_2(State_Vafmt_Called, int, std::string);
|
|
|
|
MAKE_STATE_2(State_Vafmt_PreHandler_Called, int, std::string);
|
|
|
|
MAKE_STATE_2(State_Vafmt_PostHandler_Called, int, std::string);
|
2005-04-30 21:10:07 +02:00
|
|
|
|
|
|
|
class IGaben
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void EatYams()
|
|
|
|
{
|
|
|
|
ADD_STATE(State_EatYams_Called(0));
|
|
|
|
}
|
|
|
|
virtual bool EatYams(const char *location) const
|
|
|
|
{
|
|
|
|
ADD_STATE(State_EatYams_Called(1));
|
|
|
|
return true;
|
|
|
|
}
|
2005-05-01 16:30:52 +02:00
|
|
|
virtual void Vafmt1(bool param1, int x, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
char buffer[512];
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
ADD_STATE(State_Vafmt_Called(1, std::string(buffer)));
|
|
|
|
}
|
|
|
|
virtual float Vafmt2(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
char buffer[512];
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
ADD_STATE(State_Vafmt_Called(2, std::string(buffer)));
|
|
|
|
return 0.0f;
|
|
|
|
}
|
2005-04-30 21:10:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SH_DECL_HOOK0_void(IGaben, EatYams, SH_NOATTRIB, 0);
|
|
|
|
SH_DECL_HOOK1(IGaben, EatYams, const, 1, bool, const char *);
|
2005-05-01 16:30:52 +02:00
|
|
|
SH_DECL_HOOK2_void_vafmt(IGaben, Vafmt1, SH_NOATTRIB, 0, bool, int);
|
|
|
|
SH_DECL_HOOK0_vafmt(IGaben, Vafmt2, SH_NOATTRIB, 0, float);
|
2005-04-30 21:10:07 +02:00
|
|
|
|
2005-05-01 16:30:52 +02:00
|
|
|
void EatYams0_Handler()
|
|
|
|
{
|
|
|
|
ADD_STATE(State_EatYams_Handler_Called(0));
|
|
|
|
}
|
2005-04-30 21:10:07 +02:00
|
|
|
|
2005-05-01 16:30:52 +02:00
|
|
|
bool EatYams1_Handler(const char *loc)
|
|
|
|
{
|
|
|
|
ADD_STATE(State_EatYams_Handler_Called(1));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Vafmt1_PreHandler(bool param1, int x, const char *in)
|
|
|
|
{
|
|
|
|
ADD_STATE(State_Vafmt_PreHandler_Called(1, std::string(in)));
|
|
|
|
}
|
|
|
|
void Vafmt1_PostHandler(bool param1, int x, const char *in)
|
|
|
|
{
|
|
|
|
ADD_STATE(State_Vafmt_PostHandler_Called(1, std::string(in)));
|
|
|
|
}
|
|
|
|
float Vafmt2_PreHandler(const char *in)
|
|
|
|
{
|
|
|
|
ADD_STATE(State_Vafmt_PreHandler_Called(2, std::string(in)));
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
float Vafmt2_PostHandler(const char *in)
|
|
|
|
{
|
|
|
|
ADD_STATE(State_Vafmt_PostHandler_Called(2, std::string(in)));
|
|
|
|
return 0.0f;
|
|
|
|
}
|
2005-04-30 21:10:07 +02:00
|
|
|
}
|
|
|
|
|
2005-05-01 16:30:52 +02:00
|
|
|
|
2005-04-30 21:10:07 +02:00
|
|
|
bool TestVafmtAndOverload(std::string &error)
|
|
|
|
{
|
2007-10-08 00:10:07 +02:00
|
|
|
int h1, h2, h3, h4;
|
2005-12-23 12:58:11 +01:00
|
|
|
GET_SHPTR(g_SHPtr);
|
2005-04-30 21:10:07 +02:00
|
|
|
g_PLID = 1337;
|
|
|
|
|
2007-10-08 00:10:07 +02:00
|
|
|
IGaben gabgab;
|
2005-04-30 21:10:07 +02:00
|
|
|
IGaben *pGab = &gabgab;
|
|
|
|
|
2005-05-01 16:30:52 +02:00
|
|
|
// Part 1
|
2007-05-12 10:08:01 +02:00
|
|
|
SH_CALL(pGab, static_cast<void (IGaben::*)()>(&IGaben::EatYams))();
|
|
|
|
SH_CALL(pGab, static_cast<bool (IGaben::*)(const char *) const>(&IGaben::EatYams))("Here!");
|
2005-04-30 21:10:07 +02:00
|
|
|
|
2007-10-08 00:10:07 +02:00
|
|
|
h1 = SH_ADD_HOOK(IGaben, EatYams, pGab, EatYams0_Handler, false);
|
|
|
|
h2 = SH_ADD_HOOK(IGaben, EatYams, pGab, EatYams1_Handler, false);
|
2005-04-30 21:10:07 +02:00
|
|
|
|
|
|
|
pGab->EatYams();
|
|
|
|
pGab->EatYams("Here!");
|
|
|
|
|
2007-10-08 00:10:07 +02:00
|
|
|
SH_REMOVE_HOOK_ID(h1);
|
|
|
|
SH_REMOVE_HOOK_ID(h2);
|
2005-04-30 21:10:07 +02:00
|
|
|
|
|
|
|
CHECK_STATES((&g_States,
|
|
|
|
new State_EatYams_Called(0),
|
|
|
|
new State_EatYams_Called(1),
|
|
|
|
new State_EatYams_Handler_Called(0),
|
|
|
|
new State_EatYams_Called(0),
|
|
|
|
new State_EatYams_Handler_Called(1),
|
|
|
|
new State_EatYams_Called(1),
|
|
|
|
NULL),"Part 1");
|
|
|
|
|
2005-05-01 16:30:52 +02:00
|
|
|
// Part 2
|
|
|
|
pGab->Vafmt1(true, 55, "Hello %s%d%s", "BA", 1, "L");
|
2007-05-12 10:08:01 +02:00
|
|
|
SH_CALL(pGab, &IGaben::Vafmt1)(true, 55, "Hello %s%d%s", "BA", 1, "L");
|
2005-05-01 16:30:52 +02:00
|
|
|
pGab->Vafmt2("Hello %s%d%s", "BA", 1, "LOPAN");
|
2007-05-12 10:08:01 +02:00
|
|
|
SH_CALL(pGab, &IGaben::Vafmt2)("Hello %s%d%s", "BA", 1, "LOPAN");
|
2005-05-01 16:30:52 +02:00
|
|
|
|
|
|
|
CHECK_STATES((&g_States,
|
|
|
|
new State_Vafmt_Called(1, "Hello BA1L"),
|
|
|
|
new State_Vafmt_Called(1, "Hello BA1L"),
|
|
|
|
new State_Vafmt_Called(2, "Hello BA1LOPAN"),
|
|
|
|
new State_Vafmt_Called(2, "Hello BA1LOPAN"),
|
|
|
|
NULL), "Part 2");
|
|
|
|
|
|
|
|
// Part 3
|
2007-10-08 00:10:07 +02:00
|
|
|
h1 = SH_ADD_HOOK(IGaben, Vafmt1, pGab, Vafmt1_PreHandler, false);
|
|
|
|
h2 = SH_ADD_HOOK(IGaben, Vafmt1, pGab, Vafmt1_PostHandler, true);
|
|
|
|
h3 = SH_ADD_HOOK(IGaben, Vafmt2, pGab, Vafmt2_PreHandler, false);
|
|
|
|
h4 = SH_ADD_HOOK(IGaben, Vafmt2, pGab, Vafmt2_PostHandler, true);
|
2005-05-01 16:30:52 +02:00
|
|
|
|
|
|
|
pGab->Vafmt1(true, 55, "Hello %s%d%s", "BA", 1, "L");
|
|
|
|
pGab->Vafmt2("Hello %s%d%s", "BA", 1, "LOPAN");
|
|
|
|
|
|
|
|
CHECK_STATES((&g_States,
|
|
|
|
new State_Vafmt_PreHandler_Called(1, std::string("Hello BA1L")),
|
|
|
|
new State_Vafmt_Called(1, std::string("Hello BA1L")),
|
|
|
|
new State_Vafmt_PostHandler_Called(1, std::string("Hello BA1L")),
|
|
|
|
|
|
|
|
new State_Vafmt_PreHandler_Called(2, std::string("Hello BA1LOPAN")),
|
|
|
|
new State_Vafmt_Called(2, std::string("Hello BA1LOPAN")),
|
|
|
|
new State_Vafmt_PostHandler_Called(2, std::string("Hello BA1LOPAN")),
|
|
|
|
NULL), "Part 3");
|
|
|
|
|
|
|
|
// Part 4
|
2007-10-08 00:10:07 +02:00
|
|
|
SH_REMOVE_HOOK_ID(h1);
|
|
|
|
SH_REMOVE_HOOK_ID(h2);
|
|
|
|
SH_REMOVE_HOOK_ID(h3);
|
|
|
|
SH_REMOVE_HOOK_ID(h4);
|
2005-05-01 16:30:52 +02:00
|
|
|
|
|
|
|
pGab->Vafmt1(true, 55, "Hello %s%d%s", "BA", 1, "L");
|
|
|
|
pGab->Vafmt2("Hello %s%d%s", "BA", 1, "LOPAN");
|
|
|
|
|
|
|
|
CHECK_STATES((&g_States,
|
|
|
|
new State_Vafmt_Called(1, "Hello BA1L"),
|
|
|
|
new State_Vafmt_Called(2, "Hello BA1LOPAN"),
|
|
|
|
NULL), "Part 4");
|
|
|
|
|
2005-04-30 21:10:07 +02:00
|
|
|
return true;
|
2005-05-01 14:36:48 +02:00
|
|
|
}
|