sourcehook/test/main.cpp
author Pavol Marko <pavolmarko@gmail.com>
Sat May 13 17:57:35 2006 +0000 (2006-05-13)
changeset 196 25d98645f668
parent 177 114eaa11dca2
child 198 f6397777ba0e
permissions -rw-r--r--
rewritten sh's template files to use new shworker syntax, fixed sh_call. tbh, i'm good
     1 // Hello BAIL!
     2 //   hello pm how are you
     3 //    I'm fine, what about you?
     4 //     not bad, just looking for mem leaks
     5 //      mem leaks in my code!? never! I have to preserve binary compatibility :(
     6 // This is a test file
     7 
     8 #include <stdio.h>
     9 #include <iostream>
    10 #include <string>
    11 #include <stdlib.h>
    12 #include <time.h>
    13 #include "sh_tinyhash.h"
    14 #include "sh_list.h"
    15 #include "sourcehook_impl.h"
    16 #include "sourcehook.h"
    17 
    18 using namespace std;
    19 
    20 bool g_Verbose;
    21 
    22 class Test
    23 {
    24 	typedef bool (*TestProto)(std::string&);
    25 	TestProto m_Func;
    26 	std::string m_Name;
    27 
    28 	static SourceHook::List<Test *> ms_Tests;
    29 public:
    30 	Test(TestProto func, const char *name) : m_Func(func), m_Name(name)
    31 	{
    32 		ms_Tests.push_back(this);
    33 	}
    34 
    35 	bool operator()()
    36 	{
    37 		std::string error;
    38 		if (!m_Func(error))
    39 		{
    40 			cout << "Test" << m_Name << " FAILED: " << error << endl;
    41 			return false;
    42 		}
    43 		else
    44 		{
    45 			cout << "Test" << m_Name << " passed" << endl;
    46 			return true;
    47 		}
    48 	}
    49 
    50 	static void DoTests()
    51 	{
    52 		int passed=0, failed=0;
    53 		for (SourceHook::List<Test*>::iterator iter = ms_Tests.begin(); iter != ms_Tests.end(); ++iter)
    54 		{
    55 			if ((**iter)())
    56 				++passed;
    57 			else
    58 				++failed;
    59 		}
    60 		cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
    61 		cout << "Total: " << passed + failed << endl;
    62 	}
    63 };
    64 
    65 SourceHook::List<Test *> Test::ms_Tests;
    66 
    67 #define DO_TEST(x) \
    68 	bool Test##x(std::string &error); \
    69 	Test g_Test##x(Test##x, #x);
    70 
    71 DO_TEST(List);
    72 DO_TEST(Basic);
    73 //DO_TEST(VafmtAndOverload);
    74 DO_TEST(ThisPtrOffs);
    75 DO_TEST(PlugSys);
    76 DO_TEST(Bail);
    77 DO_TEST(Reentr);
    78 DO_TEST(Manual);
    79 DO_TEST(Recall);
    80 DO_TEST(Multi);
    81 DO_TEST(Ref);
    82 
    83 int main(int argc, char *argv[])
    84 {
    85 	std::string error;
    86 
    87 	g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
    88 
    89 	Test::DoTests();
    90 
    91 	cout << "Press enter to continue" << endl;
    92 
    93 	char x;
    94 	cin.read(&x, 1);
    95 }
    96 
    97 SourceHook::ISourceHook *Test_Factory()
    98 {
    99 	return new SourceHook::CSourceHookImpl();
   100 }
   101 
   102 void Test_Delete(SourceHook::ISourceHook *shptr)
   103 {
   104 	delete static_cast<SourceHook::CSourceHookImpl *>(shptr);
   105 }
   106 
   107 void Test_CompleteShutdown(SourceHook::ISourceHook *shptr)
   108 {
   109 	static_cast<SourceHook::CSourceHookImpl *>(shptr)->CompleteShutdown();
   110 }
   111 
   112 bool Test_IsPluginInUse(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   113 {
   114 	return static_cast<SourceHook::CSourceHookImpl *>(shptr)->IsPluginInUse(plug);
   115 }
   116 
   117 void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   118 {
   119 	static_cast<SourceHook::CSourceHookImpl *>(shptr)->UnloadPlugin(plug);
   120 }
   121 
   122 void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   123 {
   124 	static_cast<SourceHook::CSourceHookImpl *>(shptr)->PausePlugin(plug);
   125 }
   126 
   127 void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   128 {
   129 	static_cast<SourceHook::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
   130 }
   131