core-1.4/sourcehook/test/main.cpp
author David Anderson <dvander@alliedmods.net>
Fri Nov 14 04:25:40 2008 -0600 (2008-11-14)
changeset 541 35a8cda28485
permissions -rw-r--r--
Added MM:S 1.4 core to the central tree.
     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 DO_TEST(RefRet);
    83 
    84 int main(int argc, char *argv[])
    85 {
    86 	std::string error;
    87 
    88 	g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
    89 
    90 	Test::DoTests();
    91 
    92 	cout << "Press enter to continue" << endl;
    93 
    94 	char x;
    95 	cin.read(&x, 1);
    96 }
    97 
    98 SourceHook::ISourceHook *Test_Factory()
    99 {
   100 	return new SourceHook::CSourceHookImpl();
   101 }
   102 
   103 void Test_Delete(SourceHook::ISourceHook *shptr)
   104 {
   105 	delete static_cast<SourceHook::CSourceHookImpl *>(shptr);
   106 }
   107 
   108 void Test_CompleteShutdown(SourceHook::ISourceHook *shptr)
   109 {
   110 	static_cast<SourceHook::CSourceHookImpl *>(shptr)->CompleteShutdown();
   111 }
   112 
   113 bool Test_IsPluginInUse(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   114 {
   115 	return static_cast<SourceHook::CSourceHookImpl *>(shptr)->IsPluginInUse(plug);
   116 }
   117 
   118 void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   119 {
   120 	static_cast<SourceHook::CSourceHookImpl *>(shptr)->UnloadPlugin(plug);
   121 }
   122 
   123 void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   124 {
   125 	static_cast<SourceHook::CSourceHookImpl *>(shptr)->PausePlugin(plug);
   126 }
   127 
   128 void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   129 {
   130 	static_cast<SourceHook::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
   131 }