sourcehook/test/test2.cpp
changeset 46 079c2393469e
child 48 a52dba4f8ed9
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sourcehook/test/test2.cpp	Sat Apr 30 19:10:07 2005 +0000
     1.3 @@ -0,0 +1,109 @@
     1.4 +#include <string>
     1.5 +#include "sourcehook_impl.h"
     1.6 +#include "testevents.h"
     1.7 +
     1.8 +namespace
     1.9 +{
    1.10 +	StateList g_States;
    1.11 +	SourceHook::ISourceHook *g_SHPtr;
    1.12 +	SourceHook::Plugin g_PLID;
    1.13 +
    1.14 +	struct State_EatYams_Called : State
    1.15 +	{
    1.16 +		int m_Overload;
    1.17 +		State_EatYams_Called(int ovrld) : m_Overload(ovrld)
    1.18 +		{
    1.19 +		}
    1.20 +		bool IsEqual(State *other)
    1.21 +		{
    1.22 +			State_EatYams_Called *other2 = dynamic_cast<State_EatYams_Called*>(other);
    1.23 +			if (!other2)
    1.24 +				return false;
    1.25 +			return other2->m_Overload == m_Overload;
    1.26 +		}
    1.27 +	};
    1.28 +
    1.29 +	struct State_EatYams_Handler_Called : State
    1.30 +	{
    1.31 +		int m_Overload;
    1.32 +		State_EatYams_Handler_Called(int ovrld) : m_Overload(ovrld)
    1.33 +		{
    1.34 +		}
    1.35 +		bool IsEqual(State *other)
    1.36 +		{
    1.37 +			State_EatYams_Handler_Called *other2 = dynamic_cast<State_EatYams_Handler_Called*>(other);
    1.38 +			if (!other2)
    1.39 +				return false;
    1.40 +			return other2->m_Overload == m_Overload;
    1.41 +		}
    1.42 +	};
    1.43 +
    1.44 +
    1.45 +	// TEST1
    1.46 +	// Basic tests
    1.47 +	// Hooking and callclass
    1.48 +	class IGaben
    1.49 +	{
    1.50 +	public:
    1.51 +		virtual void EatYams()
    1.52 +		{
    1.53 +			ADD_STATE(State_EatYams_Called(0));
    1.54 +		}
    1.55 +		virtual bool EatYams(const char *location) const
    1.56 +		{
    1.57 +			ADD_STATE(State_EatYams_Called(1));
    1.58 +			return true;
    1.59 +		}
    1.60 +	};
    1.61 +
    1.62 +	SH_DECL_HOOK0_void(IGaben, EatYams, SH_NOATTRIB, 0);
    1.63 +	SH_DECL_HOOK1(IGaben, EatYams, const, 1, bool, const char *);
    1.64 +}
    1.65 +
    1.66 +void EatYams0_Handler()
    1.67 +{
    1.68 +	ADD_STATE(State_EatYams_Handler_Called(0));
    1.69 +}
    1.70 +
    1.71 +bool EatYams1_Handler(const char *loc)
    1.72 +{
    1.73 +	ADD_STATE(State_EatYams_Handler_Called(1));
    1.74 +	return true;
    1.75 +}
    1.76 +
    1.77 +bool TestVafmtAndOverload(std::string &error)
    1.78 +{
    1.79 +	SourceHook::CSourceHookImpl g_SHImpl;
    1.80 +	g_SHPtr = &g_SHImpl;
    1.81 +	g_PLID = 1337;	
    1.82 +
    1.83 +	IGaben gabgab;
    1.84 +	IGaben *pGab = &gabgab;
    1.85 +
    1.86 +	SourceHook::CallClass<IGaben> *cc = SH_GET_CALLCLASS(pGab);
    1.87 +
    1.88 +	SH_CALL(cc, static_cast<void (IGaben::*)()>(&IGaben::EatYams))();
    1.89 +	SH_CALL(cc, static_cast<bool (IGaben::*)(const char *) const>(&IGaben::EatYams))("Here!");
    1.90 +
    1.91 +	SH_ADD_HOOK(IGaben, EatYams, pGab, EatYams0_Handler, false);
    1.92 +	SH_ADD_HOOK(IGaben, EatYams, pGab, EatYams1_Handler, false);
    1.93 +
    1.94 +	pGab->EatYams();
    1.95 +	pGab->EatYams("Here!");
    1.96 +
    1.97 +	SH_REMOVE_HOOK(IGaben, EatYams, pGab, EatYams0_Handler, false);
    1.98 +	SH_REMOVE_HOOK(IGaben, EatYams, pGab, EatYams1_Handler, false);
    1.99 +
   1.100 +	CHECK_STATES((&g_States, 
   1.101 +		new State_EatYams_Called(0),
   1.102 +		new State_EatYams_Called(1),
   1.103 +		new State_EatYams_Handler_Called(0),
   1.104 +		new State_EatYams_Called(0),
   1.105 +		new State_EatYams_Handler_Called(1),
   1.106 +		new State_EatYams_Called(1),
   1.107 +		NULL),"Part 1");
   1.108 +
   1.109 +	SH_RELEASE_CALLCLASS(cc);
   1.110 +
   1.111 +	return true;
   1.112 +}
   1.113 \ No newline at end of file