sourcehook/test/main.cpp
author David Anderson <dvander@alliedmods.net>
Sun Sep 11 23:24:18 2005 +0000 (2005-09-11)
changeset 99 bfbb04d6683f
parent 98 4c46acf7e76f
child 100 022428df37c9
permissions -rw-r--r--
std::vector -> SourceHook::CVector
     1 // Hello BAIL!
     2 //   hello pm how are you
     3 // This is a test file
     4 
     5 #include <stdio.h>
     6 #include <iostream>
     7 #include <string>
     8 #include <list>
     9 #include "sourcehook_impl.h"
    10 
    11 using namespace std;
    12 
    13 bool g_Verbose;
    14 
    15 class Test
    16 {
    17 	typedef bool (*TestProto)(std::string&);
    18 	TestProto m_Func;
    19 	std::string m_Name;
    20 
    21 	static std::list<Test *> ms_Tests;
    22 public:
    23 	Test(TestProto func, const char *name) : m_Func(func), m_Name(name)
    24 	{
    25 		ms_Tests.push_back(this);
    26 	}
    27 
    28 	bool operator()()
    29 	{
    30 		std::string error;
    31 		if (!m_Func(error))
    32 		{
    33 			cout << "Test" << m_Name << " FAILED: " << error << endl;
    34 			return false;
    35 		}
    36 		else
    37 		{
    38 			cout << "Test" << m_Name << " passed" << endl;
    39 			return true;
    40 		}
    41 	}
    42 
    43 	static void DoTests()
    44 	{
    45 		int passed=0, failed=0;
    46 		for (std::list<Test*>::iterator iter = ms_Tests.begin(); iter != ms_Tests.end(); ++iter)
    47 		{
    48 			if ((**iter)())
    49 				++passed;
    50 			else
    51 				++failed;
    52 		}
    53 		cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
    54 		cout << "Total: " << passed + failed << endl;
    55 	}
    56 };
    57 
    58 std::list<Test *> Test::ms_Tests;
    59 
    60 #define DO_TEST(x) \
    61 	bool Test##x(std::string &error); \
    62 	Test g_Test##x(Test##x, #x);
    63 
    64 DO_TEST(Basic);
    65 DO_TEST(VafmtAndOverload);
    66 DO_TEST(ThisPtrOffs);
    67 DO_TEST(PlugSys);
    68 DO_TEST(Bail);
    69 
    70 int main(int argc, char *argv[])
    71 {
    72 	std::string error;
    73 	int passed=0, failed=0;
    74 
    75 	g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
    76 
    77 	Test::DoTests();
    78 
    79 	cout << "Press enter to continue" << endl;
    80 
    81 	char x;
    82 	cin.read(&x, 1);
    83 }
    84