core/sourcehook/test/main.cpp
changeset 539 db914129ae01
parent 480 d096210677d4
child 733 2365240861a2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/core/sourcehook/test/main.cpp	Fri Nov 14 04:04:02 2008 -0600
     1.3 @@ -0,0 +1,125 @@
     1.4 +// Hello BAIL!
     1.5 +//   hello pm how are you
     1.6 +//    I'm fine, what about you?
     1.7 +//     not bad, just looking for mem leaks
     1.8 +//      mem leaks in my code!? never! I have to preserve binary compatibility :(
     1.9 +// This is a test file
    1.10 +
    1.11 +#include <stdio.h>
    1.12 +#include <iostream>
    1.13 +#include <string>
    1.14 +#include <stdlib.h>
    1.15 +#include <time.h>
    1.16 +
    1.17 +#include "sourcehook_impl.h"
    1.18 +#include "sourcehook.h"
    1.19 +#include "sourcehook_hookmangen.h"
    1.20 +
    1.21 +using namespace std;
    1.22 +bool g_Verbose;
    1.23 +
    1.24 +#define DECL_TEST(x) bool Test##x(std::string &error);
    1.25 +
    1.26 +#define DO_TEST(x) \
    1.27 +	error.clear(); \
    1.28 +	if (Test##x(error)) \
    1.29 +	{ \
    1.30 +		++passed; \
    1.31 +		cout << "Test" << #x << " passed" << endl; \
    1.32 +	} \
    1.33 +	else \
    1.34 +	{ \
    1.35 +		++failed; \
    1.36 +		cout << "Test" << #x << " FAILED: " << error << endl; \
    1.37 +	} \
    1.38 +
    1.39 +
    1.40 +DECL_TEST(List);
    1.41 +DECL_TEST(Basic);
    1.42 +DECL_TEST(VafmtAndOverload);
    1.43 +DECL_TEST(ThisPtrOffs);
    1.44 +DECL_TEST(PlugSys);
    1.45 +DECL_TEST(Bail);
    1.46 +DECL_TEST(Reentr);
    1.47 +DECL_TEST(Manual);
    1.48 +DECL_TEST(Recall);
    1.49 +DECL_TEST(Multi);
    1.50 +DECL_TEST(Ref);
    1.51 +DECL_TEST(RefRet);
    1.52 +DECL_TEST(VPHooks);
    1.53 +DECL_TEST(CPageAlloc);					// in testhookmangen.cpp
    1.54 +DECL_TEST(HookManGen);
    1.55 +
    1.56 +int main(int argc, char *argv[])
    1.57 +{
    1.58 +	std::string error;
    1.59 +
    1.60 +	g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
    1.61 +
    1.62 +	int passed = 0, failed = 0;
    1.63 +
    1.64 +	DO_TEST(List);
    1.65 +	DO_TEST(Basic);
    1.66 +	DO_TEST(VafmtAndOverload);
    1.67 +	DO_TEST(ThisPtrOffs);
    1.68 +	DO_TEST(PlugSys);
    1.69 +	DO_TEST(Bail);
    1.70 +	DO_TEST(Reentr);
    1.71 +	DO_TEST(Manual);
    1.72 +	DO_TEST(Recall);
    1.73 +	DO_TEST(Multi);
    1.74 +	DO_TEST(Ref);
    1.75 +	DO_TEST(RefRet);
    1.76 +	DO_TEST(VPHooks);
    1.77 +	DO_TEST(CPageAlloc);
    1.78 +	DO_TEST(HookManGen);
    1.79 +
    1.80 +	cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
    1.81 +	cout << "Total: " << passed + failed << endl;
    1.82 +
    1.83 +	cout << "Press enter to continue" << endl;
    1.84 +
    1.85 +	char x;
    1.86 +	cin.read(&x, 1);
    1.87 +}
    1.88 +
    1.89 +SourceHook::ISourceHook *Test_Factory()
    1.90 +{
    1.91 +	return new SourceHook::Impl::CSourceHookImpl();
    1.92 +}
    1.93 +
    1.94 +void Test_Delete(SourceHook::ISourceHook *shptr)
    1.95 +{
    1.96 +	delete static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr);
    1.97 +}
    1.98 +
    1.99 +void Test_CompleteShutdown(SourceHook::ISourceHook *shptr)
   1.100 +{
   1.101 +	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->CompleteShutdown();
   1.102 +}
   1.103 +
   1.104 +void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   1.105 +{
   1.106 +	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnloadPlugin(plug);
   1.107 +}
   1.108 +
   1.109 +void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   1.110 +{
   1.111 +	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->PausePlugin(plug);
   1.112 +}
   1.113 +
   1.114 +void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   1.115 +{
   1.116 +	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
   1.117 +}
   1.118 +
   1.119 +SourceHook::IHookManagerAutoGen *Test_HMAG_Factory(SourceHook::ISourceHook *shptr)
   1.120 +{
   1.121 +	return new SourceHook::Impl::CHookManagerAutoGen(shptr);
   1.122 +}
   1.123 +
   1.124 +void Test_HMAG_Delete(SourceHook::IHookManagerAutoGen *ptr)
   1.125 +{
   1.126 +	delete static_cast<SourceHook::Impl::CHookManagerAutoGen*>(ptr);
   1.127 +}
   1.128 +