sourcehook/test/main.cpp
author Pavol Marko <pavolmarko@gmail.com>
Sun Oct 21 21:47:53 2007 +0000 (2007-10-21)
branchhookman_autogen
changeset 432 f26dd3e3030b
parent 419 862e6dddd0ee
child 435 35296642e147
permissions -rw-r--r--
First version of automatic hookman/hookfunc generation functionality + test
Currently supports (msvc): all params, ret types: integeral, floating-point
Todo: other rettypes (pod/objects, ctors/dtors), gcc support, integration with ISourceHook::AddHook
     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 
    17 using namespace std;
    18 bool g_Verbose;
    19 
    20 #define DECL_TEST(x) bool Test##x(std::string &error);
    21 
    22 #define DO_TEST(x) \
    23 	error.clear(); \
    24 	if (Test##x(error)) \
    25 	{ \
    26 		++passed; \
    27 		cout << "Test" << #x << " passed" << endl; \
    28 	} \
    29 	else \
    30 	{ \
    31 		++failed; \
    32 		cout << "Test" << #x << " FAILED: " << error << endl; \
    33 	} \
    34 
    35 
    36 DECL_TEST(List);
    37 DECL_TEST(Basic);
    38 DECL_TEST(VafmtAndOverload);
    39 DECL_TEST(ThisPtrOffs);
    40 DECL_TEST(PlugSys);
    41 DECL_TEST(Bail);
    42 DECL_TEST(Reentr);
    43 DECL_TEST(Manual);
    44 DECL_TEST(Recall);
    45 DECL_TEST(Multi);
    46 DECL_TEST(Ref);
    47 DECL_TEST(RefRet);
    48 DECL_TEST(VPHooks);
    49 DECL_TEST(HookManGen);
    50 
    51 int main(int argc, char *argv[])
    52 {
    53 	std::string error;
    54 
    55 	g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
    56 
    57 	int passed = 0, failed = 0;
    58 
    59 	DO_TEST(List);
    60 	DO_TEST(Basic);
    61 	DO_TEST(VafmtAndOverload);
    62 	DO_TEST(ThisPtrOffs);
    63 	DO_TEST(PlugSys);
    64 	DO_TEST(Bail);
    65 	DO_TEST(Reentr);
    66 	DO_TEST(Manual);
    67 	DO_TEST(Recall);
    68 	DO_TEST(Multi);
    69 	DO_TEST(Ref);
    70 	DO_TEST(RefRet);
    71 	DO_TEST(VPHooks);
    72 	DO_TEST(HookManGen);
    73 
    74 	cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
    75 	cout << "Total: " << passed + failed << endl;
    76 
    77 	cout << "Press enter to continue" << endl;
    78 
    79 	char x;
    80 	cin.read(&x, 1);
    81 }
    82 
    83 SourceHook::ISourceHook *Test_Factory()
    84 {
    85 	return new SourceHook::Impl::CSourceHookImpl();
    86 }
    87 
    88 void Test_Delete(SourceHook::ISourceHook *shptr)
    89 {
    90 	delete static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr);
    91 }
    92 
    93 void Test_CompleteShutdown(SourceHook::ISourceHook *shptr)
    94 {
    95 	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->CompleteShutdown();
    96 }
    97 
    98 void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
    99 {
   100 	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnloadPlugin(plug);
   101 }
   102 
   103 void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   104 {
   105 	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->PausePlugin(plug);
   106 }
   107 
   108 void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   109 {
   110 	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
   111 }