sourcehook/test/main.cpp
author Pavol Marko <pavolmarko@gmail.com>
Fri Oct 14 17:45:36 2005 +0000 (2005-10-14)
changeset 133 ffe46578a1ae
parent 111 aec58c99dafc
child 151 1667580b0c91
permissions -rw-r--r--
sh_stack now works if assert is disabled (stupid me), simple reentrancy test, META_IFACEPTR takes a type argument
     1 // Hello BAIL!
     2 //   hello pm how are you
     3 //    I'm fine, what about you?
     4 // This is a test file
     5 
     6 #include <stdio.h>
     7 #include <iostream>
     8 #include <string>
     9 #include <stdlib.h>
    10 #include <time.h>
    11 #include "sh_tinyhash.h"
    12 #include "sh_list.h"
    13 #include "sourcehook_impl.h"
    14 
    15 using namespace std;
    16 
    17 bool g_Verbose;
    18 
    19 class Test
    20 {
    21 	typedef bool (*TestProto)(std::string&);
    22 	TestProto m_Func;
    23 	std::string m_Name;
    24 
    25 	static SourceHook::List<Test *> ms_Tests;
    26 public:
    27 	Test(TestProto func, const char *name) : m_Func(func), m_Name(name)
    28 	{
    29 		ms_Tests.push_back(this);
    30 	}
    31 
    32 	bool operator()()
    33 	{
    34 		std::string error;
    35 		if (!m_Func(error))
    36 		{
    37 			cout << "Test" << m_Name << " FAILED: " << error << endl;
    38 			return false;
    39 		}
    40 		else
    41 		{
    42 			cout << "Test" << m_Name << " passed" << endl;
    43 			return true;
    44 		}
    45 	}
    46 
    47 	static void DoTests()
    48 	{
    49 		int passed=0, failed=0;
    50 		for (SourceHook::List<Test*>::iterator iter = ms_Tests.begin(); iter != ms_Tests.end(); ++iter)
    51 		{
    52 			if ((**iter)())
    53 				++passed;
    54 			else
    55 				++failed;
    56 		}
    57 		cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
    58 		cout << "Total: " << passed + failed << endl;
    59 	}
    60 };
    61 
    62 SourceHook::List<Test *> Test::ms_Tests;
    63 
    64 #define DO_TEST(x) \
    65 	bool Test##x(std::string &error); \
    66 	Test g_Test##x(Test##x, #x);
    67 
    68 DO_TEST(List);
    69 DO_TEST(Basic);
    70 DO_TEST(VafmtAndOverload);
    71 DO_TEST(ThisPtrOffs);
    72 DO_TEST(PlugSys);
    73 DO_TEST(Bail);
    74 DO_TEST(Reentr);
    75 
    76 int main(int argc, char *argv[])
    77 {
    78 	std::string error;
    79 
    80 	g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
    81 
    82 	Test::DoTests();
    83 
    84 	cout << "Press enter to continue" << endl;
    85 
    86 	char x;
    87 	cin.read(&x, 1);
    88 }
    89