sourcehook/test/main.cpp
author David Anderson <dvander@alliedmods.net>
Fri Sep 28 21:40:58 2007 +0000 (2007-09-28)
branchsourcemm-1.6.0
changeset 361 f34718303c8f
parent 347 e82968c21606
permissions -rw-r--r--
removed old providers location
replaced sourcehook with v4.5
     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 DO_TEST(VPHooks);
    84 
    85 int main(int argc, char *argv[])
    86 {
    87 	std::string error;
    88 
    89 	g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
    90 
    91 	Test::DoTests();
    92 
    93 	cout << "Press enter to continue" << endl;
    94 
    95 	char x;
    96 	cin.read(&x, 1);
    97 }
    98 
    99 SourceHook::ISourceHook *Test_Factory()
   100 {
   101 	return new SourceHook::CSourceHookImpl();
   102 }
   103 
   104 void Test_Delete(SourceHook::ISourceHook *shptr)
   105 {
   106 	delete static_cast<SourceHook::CSourceHookImpl *>(shptr);
   107 }
   108 
   109 void Test_CompleteShutdown(SourceHook::ISourceHook *shptr)
   110 {
   111 	static_cast<SourceHook::CSourceHookImpl *>(shptr)->CompleteShutdown();
   112 }
   113 
   114 bool Test_IsPluginInUse(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   115 {
   116 	return static_cast<SourceHook::CSourceHookImpl *>(shptr)->IsPluginInUse(plug);
   117 }
   118 
   119 void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   120 {
   121 	static_cast<SourceHook::CSourceHookImpl *>(shptr)->UnloadPlugin(plug);
   122 }
   123 
   124 void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   125 {
   126 	static_cast<SourceHook::CSourceHookImpl *>(shptr)->PausePlugin(plug);
   127 }
   128 
   129 void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   130 {
   131 	static_cast<SourceHook::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
   132 }