sourcehook/test/main.cpp
branchsourcemm-1.6.0
changeset 347 e82968c21606
child 361 f34718303c8f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sourcehook/test/main.cpp	Tue Sep 18 20:03:47 2007 +0000
     1.3 @@ -0,0 +1,131 @@
     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 +#include "sh_tinyhash.h"
    1.17 +#include "sh_list.h"
    1.18 +#include "sourcehook_impl.h"
    1.19 +#include "sourcehook.h"
    1.20 +
    1.21 +using namespace std;
    1.22 +
    1.23 +bool g_Verbose;
    1.24 +
    1.25 +class Test
    1.26 +{
    1.27 +	typedef bool (*TestProto)(std::string&);
    1.28 +	TestProto m_Func;
    1.29 +	std::string m_Name;
    1.30 +
    1.31 +	static SourceHook::List<Test *> ms_Tests;
    1.32 +public:
    1.33 +	Test(TestProto func, const char *name) : m_Func(func), m_Name(name)
    1.34 +	{
    1.35 +		ms_Tests.push_back(this);
    1.36 +	}
    1.37 +
    1.38 +	bool operator()()
    1.39 +	{
    1.40 +		std::string error;
    1.41 +		if (!m_Func(error))
    1.42 +		{
    1.43 +			cout << "Test" << m_Name << " FAILED: " << error << endl;
    1.44 +			return false;
    1.45 +		}
    1.46 +		else
    1.47 +		{
    1.48 +			cout << "Test" << m_Name << " passed" << endl;
    1.49 +			return true;
    1.50 +		}
    1.51 +	}
    1.52 +
    1.53 +	static void DoTests()
    1.54 +	{
    1.55 +		int passed=0, failed=0;
    1.56 +		for (SourceHook::List<Test*>::iterator iter = ms_Tests.begin(); iter != ms_Tests.end(); ++iter)
    1.57 +		{
    1.58 +			if ((**iter)())
    1.59 +				++passed;
    1.60 +			else
    1.61 +				++failed;
    1.62 +		}
    1.63 +		cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
    1.64 +		cout << "Total: " << passed + failed << endl;
    1.65 +	}
    1.66 +};
    1.67 +
    1.68 +SourceHook::List<Test *> Test::ms_Tests;
    1.69 +
    1.70 +#define DO_TEST(x) \
    1.71 +	bool Test##x(std::string &error); \
    1.72 +	Test g_Test##x(Test##x, #x);
    1.73 +
    1.74 +DO_TEST(List);
    1.75 +DO_TEST(Basic);
    1.76 +DO_TEST(VafmtAndOverload);
    1.77 +DO_TEST(ThisPtrOffs);
    1.78 +DO_TEST(PlugSys);
    1.79 +DO_TEST(Bail);
    1.80 +DO_TEST(Reentr);
    1.81 +DO_TEST(Manual);
    1.82 +DO_TEST(Recall);
    1.83 +DO_TEST(Multi);
    1.84 +DO_TEST(Ref);
    1.85 +DO_TEST(RefRet);
    1.86 +
    1.87 +int main(int argc, char *argv[])
    1.88 +{
    1.89 +	std::string error;
    1.90 +
    1.91 +	g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
    1.92 +
    1.93 +	Test::DoTests();
    1.94 +
    1.95 +	cout << "Press enter to continue" << endl;
    1.96 +
    1.97 +	char x;
    1.98 +	cin.read(&x, 1);
    1.99 +}
   1.100 +
   1.101 +SourceHook::ISourceHook *Test_Factory()
   1.102 +{
   1.103 +	return new SourceHook::CSourceHookImpl();
   1.104 +}
   1.105 +
   1.106 +void Test_Delete(SourceHook::ISourceHook *shptr)
   1.107 +{
   1.108 +	delete static_cast<SourceHook::CSourceHookImpl *>(shptr);
   1.109 +}
   1.110 +
   1.111 +void Test_CompleteShutdown(SourceHook::ISourceHook *shptr)
   1.112 +{
   1.113 +	static_cast<SourceHook::CSourceHookImpl *>(shptr)->CompleteShutdown();
   1.114 +}
   1.115 +
   1.116 +bool Test_IsPluginInUse(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   1.117 +{
   1.118 +	return static_cast<SourceHook::CSourceHookImpl *>(shptr)->IsPluginInUse(plug);
   1.119 +}
   1.120 +
   1.121 +void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   1.122 +{
   1.123 +	static_cast<SourceHook::CSourceHookImpl *>(shptr)->UnloadPlugin(plug);
   1.124 +}
   1.125 +
   1.126 +void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   1.127 +{
   1.128 +	static_cast<SourceHook::CSourceHookImpl *>(shptr)->PausePlugin(plug);
   1.129 +}
   1.130 +
   1.131 +void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   1.132 +{
   1.133 +	static_cast<SourceHook::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
   1.134 +}