2 #include "sourcehook_impl.h"
3 #include "testevents.h"
8 SourceHook::ISourceHook *g_SHPtr;
9 SourceHook::Plugin g_PLID;
11 struct State_EatYams_Called : State
14 State_EatYams_Called(int ovrld) : m_Overload(ovrld)
17 bool IsEqual(State *other)
19 State_EatYams_Called *other2 = dynamic_cast<State_EatYams_Called*>(other);
22 return other2->m_Overload == m_Overload;
26 struct State_EatYams_Handler_Called : State
29 State_EatYams_Handler_Called(int ovrld) : m_Overload(ovrld)
32 bool IsEqual(State *other)
34 State_EatYams_Handler_Called *other2 = dynamic_cast<State_EatYams_Handler_Called*>(other);
37 return other2->m_Overload == m_Overload;
44 // Hooking and callclass
48 virtual void EatYams()
50 ADD_STATE(State_EatYams_Called(0));
52 virtual bool EatYams(const char *location) const
54 ADD_STATE(State_EatYams_Called(1));
59 SH_DECL_HOOK0_void(IGaben, EatYams, SH_NOATTRIB, 0);
60 SH_DECL_HOOK1(IGaben, EatYams, const, 1, bool, const char *);
63 void EatYams0_Handler()
65 ADD_STATE(State_EatYams_Handler_Called(0));
68 bool EatYams1_Handler(const char *loc)
70 ADD_STATE(State_EatYams_Handler_Called(1));
74 bool TestVafmtAndOverload(std::string &error)
76 SourceHook::CSourceHookImpl g_SHImpl;
81 IGaben *pGab = &gabgab;
83 SourceHook::CallClass<IGaben> *cc = SH_GET_CALLCLASS(pGab);
85 SH_CALL(cc, static_cast<void (IGaben::*)()>(&IGaben::EatYams))();
86 SH_CALL(cc, static_cast<bool (IGaben::*)(const char *) const>(&IGaben::EatYams))("Here!");
88 SH_ADD_HOOK(IGaben, EatYams, pGab, EatYams0_Handler, false);
89 SH_ADD_HOOK(IGaben, EatYams, pGab, EatYams1_Handler, false);
92 pGab->EatYams("Here!");
94 SH_REMOVE_HOOK(IGaben, EatYams, pGab, EatYams0_Handler, false);
95 SH_REMOVE_HOOK(IGaben, EatYams, pGab, EatYams1_Handler, false);
97 CHECK_STATES((&g_States,
98 new State_EatYams_Called(0),
99 new State_EatYams_Called(1),
100 new State_EatYams_Handler_Called(0),
101 new State_EatYams_Called(0),
102 new State_EatYams_Handler_Called(1),
103 new State_EatYams_Called(1),
106 SH_RELEASE_CALLCLASS(cc);