core/sourcehook/test/main.cpp
author Scott Ehlert <ds@alliedmods.net>
Thu Jul 01 02:43:22 2010 -0500 (2010-07-01)
changeset 722 78f730f91439
parent 539 db914129ae01
child 733 2365240861a2
permissions -rw-r--r--
Fixed problem on OBV where alternately loaded plugins (CreateInterface_MMS) could be incorrectly told they were on the OB engine (bug 4491, r=dvander).

This only happened when there was more than one plugin that loaded this way. And the first plugin to load had to fail on OBV first so that OB could be tried. It was being permanently set to OB for future plugin loads and this caused problems.
     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 
    53 int main(int argc, char *argv[])
    54 {
    55 	std::string error;
    56 
    57 	g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
    58 
    59 	int passed = 0, failed = 0;
    60 
    61 	DO_TEST(List);
    62 	DO_TEST(Basic);
    63 	DO_TEST(VafmtAndOverload);
    64 	DO_TEST(ThisPtrOffs);
    65 	DO_TEST(PlugSys);
    66 	DO_TEST(Bail);
    67 	DO_TEST(Reentr);
    68 	DO_TEST(Manual);
    69 	DO_TEST(Recall);
    70 	DO_TEST(Multi);
    71 	DO_TEST(Ref);
    72 	DO_TEST(RefRet);
    73 	DO_TEST(VPHooks);
    74 	DO_TEST(CPageAlloc);
    75 	DO_TEST(HookManGen);
    76 
    77 	cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
    78 	cout << "Total: " << passed + failed << endl;
    79 
    80 	cout << "Press enter to continue" << endl;
    81 
    82 	char x;
    83 	cin.read(&x, 1);
    84 }
    85 
    86 SourceHook::ISourceHook *Test_Factory()
    87 {
    88 	return new SourceHook::Impl::CSourceHookImpl();
    89 }
    90 
    91 void Test_Delete(SourceHook::ISourceHook *shptr)
    92 {
    93 	delete static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr);
    94 }
    95 
    96 void Test_CompleteShutdown(SourceHook::ISourceHook *shptr)
    97 {
    98 	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->CompleteShutdown();
    99 }
   100 
   101 void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   102 {
   103 	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnloadPlugin(plug);
   104 }
   105 
   106 void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   107 {
   108 	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->PausePlugin(plug);
   109 }
   110 
   111 void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
   112 {
   113 	static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
   114 }
   115 
   116 SourceHook::IHookManagerAutoGen *Test_HMAG_Factory(SourceHook::ISourceHook *shptr)
   117 {
   118 	return new SourceHook::Impl::CHookManagerAutoGen(shptr);
   119 }
   120 
   121 void Test_HMAG_Delete(SourceHook::IHookManagerAutoGen *ptr)
   122 {
   123 	delete static_cast<SourceHook::Impl::CHookManagerAutoGen*>(ptr);
   124 }
   125