sourcehook/test/main.cpp
author Pavol Marko <pavolmarko@gmail.com>
Sat Dec 10 22:37:53 2005 +0000 (2005-12-10)
changeset 157 064f77cac7ab
parent 151 1667580b0c91
child 162 a95db73792e5
permissions -rw-r--r--
Added manual hooks. I hope that I haven't broken binary compatibility - someone might want to test it.
     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 // This is a test file
     6 
     7 #include <stdio.h>
     8 #include <iostream>
     9 #include <string>
    10 #include <stdlib.h>
    11 #include <time.h>
    12 #include "sh_tinyhash.h"
    13 #include "sh_list.h"
    14 #include "sourcehook_impl.h"
    15 #include "sourcehook.h"
    16 
    17 using namespace std;
    18 
    19 bool g_Verbose;
    20 
    21 class Test
    22 {
    23 	typedef bool (*TestProto)(std::string&);
    24 	TestProto m_Func;
    25 	std::string m_Name;
    26 
    27 	static SourceHook::List<Test *> ms_Tests;
    28 public:
    29 	Test(TestProto func, const char *name) : m_Func(func), m_Name(name)
    30 	{
    31 		ms_Tests.push_back(this);
    32 	}
    33 
    34 	bool operator()()
    35 	{
    36 		std::string error;
    37 		if (!m_Func(error))
    38 		{
    39 			cout << "Test" << m_Name << " FAILED: " << error << endl;
    40 			return false;
    41 		}
    42 		else
    43 		{
    44 			cout << "Test" << m_Name << " passed" << endl;
    45 			return true;
    46 		}
    47 	}
    48 
    49 	static void DoTests()
    50 	{
    51 		int passed=0, failed=0;
    52 		for (SourceHook::List<Test*>::iterator iter = ms_Tests.begin(); iter != ms_Tests.end(); ++iter)
    53 		{
    54 			if ((**iter)())
    55 				++passed;
    56 			else
    57 				++failed;
    58 		}
    59 		cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
    60 		cout << "Total: " << passed + failed << endl;
    61 	}
    62 };
    63 
    64 SourceHook::List<Test *> Test::ms_Tests;
    65 
    66 #define DO_TEST(x) \
    67 	bool Test##x(std::string &error); \
    68 	Test g_Test##x(Test##x, #x);
    69 
    70 DO_TEST(List);
    71 DO_TEST(Basic);
    72 DO_TEST(VafmtAndOverload);
    73 DO_TEST(ThisPtrOffs);
    74 DO_TEST(PlugSys);
    75 DO_TEST(Bail);
    76 DO_TEST(Reentr);
    77 DO_TEST(Manual);
    78 
    79 int main(int argc, char *argv[])
    80 {
    81 	std::string error;
    82 
    83 	g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
    84 
    85 	Test::DoTests();
    86 
    87 	cout << "Press enter to continue" << endl;
    88 
    89 	char x;
    90 	cin.read(&x, 1);
    91 }
    92