core/sourcehook/test/main.cpp
author psychonic
Fri Dec 17 22:22:44 2010 -0500 (2010-12-17)
changeset 739 968e67c7780c
parent 733 2365240861a2
permissions -rw-r--r--
Merge.
     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 
    14 #include "sourcehook_impl.h"
    15 #include "sourcehook.h"
    16 #include "sourcehook_hookmangen.h"
    17 
    18 using namespace std;
    19 bool g_Verbose;
    20 
    21 #define DECL_TEST(x) bool Test##x(std::string &error);
    22 
    23 #define DO_TEST(x) \
    24 	error.clear(); \
    25 	if (Test##x(error)) \
    26 	{ \
    27 		++passed; \
    28 		cout << "Test" << #x << " passed" << endl; \
    29 	} \
    30 	else \
    31 	{ \
    32 		++failed; \
    33 		cout << "Test" << #x << " FAILED: " << error << endl; \
    34 	} \
    35 
    36 
    37 DECL_TEST(List);
    38 DECL_TEST(Basic);
    39 DECL_TEST(VafmtAndOverload);
    40 DECL_TEST(ThisPtrOffs);
    41 DECL_TEST(PlugSys);
    42 DECL_TEST(Bail);
    43 DECL_TEST(Reentr);
    44 DECL_TEST(Manual);
    45 DECL_TEST(Recall);
    46 DECL_TEST(Multi);
    47 DECL_TEST(Ref);
    48 DECL_TEST(RefRet);
    49 DECL_TEST(VPHooks);
    50 DECL_TEST(CPageAlloc);					// in testhookmangen.cpp
    51 DECL_TEST(HookManGen);
    52 DECL_TEST(OddThunks);
    53 
    54 int main(int argc, char *argv[])
    55 {
    56 	std::string error;
    57 
    58 	g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
    59 
    60 	int passed = 0, failed = 0;
    61 
    62 	DO_TEST(List);
    63 	DO_TEST(Basic);
    64 	DO_TEST(VafmtAndOverload);
    65 	DO_TEST(ThisPtrOffs);
    66 	DO_TEST(PlugSys);
    67 	DO_TEST(Bail);
    68 	DO_TEST(Reentr);
    69 	DO_TEST(Manual);
    70 	DO_TEST(Recall);
    71 	DO_TEST(Multi);
    72 	DO_TEST(Ref);
    73 	DO_TEST(RefRet);
    74 	DO_TEST(VPHooks);
    75 	DO_TEST(CPageAlloc);
    76 	DO_TEST(HookManGen);
    77 	DO_TEST(OddThunks);
    78 
    79 	cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
    80 	cout << "Total: " << passed + failed << endl;
    81 
    82 	cout << "Press enter to continue" << endl;
    83 
    84 	char x;
    85 	cin.read(&x, 1);
    86 }
    87 
    88 SourceHook::ISourceHook *Test_Factory()
    89 {
    90 	return new SourceHook::Impl::CSourceHookImpl();
    91 }
    92 
    93 void Test_Delete(SourceHook::ISourceHook *shptr)
    94 {
    95 	delete static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr);
    96 }
    97 
    98 void Test_CompleteShutdown(SourceHook::ISourceHook *shptr)
    99 {
   100 	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->CompleteShutdown();
   101 }
   102 
   103 void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   104 {
   105 	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnloadPlugin(plug);
   106 }
   107 
   108 void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   109 {
   110 	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->PausePlugin(plug);
   111 }
   112 
   113 void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   114 {
   115 	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
   116 }
   117 
   118 SourceHook::IHookManagerAutoGen *Test_HMAG_Factory(SourceHook::ISourceHook *shptr)
   119 {
   120 	return new SourceHook::Impl::CHookManagerAutoGen(shptr);
   121 }
   122 
   123 void Test_HMAG_Delete(SourceHook::IHookManagerAutoGen *ptr)
   124 {
   125 	delete static_cast<SourceHook::Impl::CHookManagerAutoGen*>(ptr);
   126 }
   127