sourcehook/test/main.cpp
changeset 419 862e6dddd0ee
parent 388 498e769e86a4
child 432 f26dd3e3030b
child 480 d096210677d4
     1.1 --- a/sourcehook/test/main.cpp	Sun Oct 14 11:59:13 2007 +0000
     1.2 +++ b/sourcehook/test/main.cpp	Sun Oct 14 12:15:09 2007 +0000
     1.3 @@ -10,77 +10,42 @@
     1.4  #include <string>
     1.5  #include <stdlib.h>
     1.6  #include <time.h>
     1.7 -#include "sh_tinyhash.h"
     1.8 -#include "sh_list.h"
     1.9 +
    1.10  #include "sourcehook_impl.h"
    1.11  #include "sourcehook.h"
    1.12  
    1.13  using namespace std;
    1.14 -
    1.15  bool g_Verbose;
    1.16  
    1.17 -class Test
    1.18 -{
    1.19 -	typedef bool (*TestProto)(std::string&);
    1.20 -	TestProto m_Func;
    1.21 -	std::string m_Name;
    1.22 -
    1.23 -	static SourceHook::CVector<Test *> ms_Tests;
    1.24 -public:
    1.25 -	Test(TestProto func, const char *name) : m_Func(func), m_Name(name)
    1.26 -	{
    1.27 -		ms_Tests.push_back(this);
    1.28 -	}
    1.29 -
    1.30 -	bool operator()()
    1.31 -	{
    1.32 -		std::string error;
    1.33 -		if (!m_Func(error))
    1.34 -		{
    1.35 -			cout << "Test" << m_Name << " FAILED: " << error << endl;
    1.36 -			return false;
    1.37 -		}
    1.38 -		else
    1.39 -		{
    1.40 -			cout << "Test" << m_Name << " passed" << endl;
    1.41 -			return true;
    1.42 -		}
    1.43 -	}
    1.44 -
    1.45 -	static void DoTests()
    1.46 -	{
    1.47 -		int passed=0, failed=0;
    1.48 -		for (SourceHook::CVector<Test*>::iterator iter = ms_Tests.begin(); iter != ms_Tests.end(); ++iter)
    1.49 -		{
    1.50 -			if ((**iter)())
    1.51 -				++passed;
    1.52 -			else
    1.53 -				++failed;
    1.54 -		}
    1.55 -		cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
    1.56 -		cout << "Total: " << passed + failed << endl;
    1.57 -	}
    1.58 -};
    1.59 -
    1.60 -SourceHook::CVector<Test *> Test::ms_Tests;
    1.61 +#define DECL_TEST(x) bool Test##x(std::string &error);
    1.62  
    1.63  #define DO_TEST(x) \
    1.64 -	bool Test##x(std::string &error); \
    1.65 -	Test g_Test##x(Test##x, #x);
    1.66 +	error.clear(); \
    1.67 +	if (Test##x(error)) \
    1.68 +	{ \
    1.69 +		++passed; \
    1.70 +		cout << "Test" << #x << " passed" << endl; \
    1.71 +	} \
    1.72 +	else \
    1.73 +	{ \
    1.74 +		++failed; \
    1.75 +		cout << "Test" << #x << " FAILED: " << error << endl; \
    1.76 +	} \
    1.77 +
    1.78  
    1.79 -DO_TEST(List);
    1.80 -DO_TEST(Basic);
    1.81 -DO_TEST(VafmtAndOverload);
    1.82 -DO_TEST(ThisPtrOffs);
    1.83 -DO_TEST(PlugSys);
    1.84 -DO_TEST(Bail);
    1.85 -DO_TEST(Reentr);
    1.86 -DO_TEST(Manual);
    1.87 -DO_TEST(Recall);
    1.88 -DO_TEST(Multi);
    1.89 -DO_TEST(Ref);
    1.90 -DO_TEST(RefRet);
    1.91 -DO_TEST(VPHooks);
    1.92 +DECL_TEST(List);
    1.93 +DECL_TEST(Basic);
    1.94 +DECL_TEST(VafmtAndOverload);
    1.95 +DECL_TEST(ThisPtrOffs);
    1.96 +DECL_TEST(PlugSys);
    1.97 +DECL_TEST(Bail);
    1.98 +DECL_TEST(Reentr);
    1.99 +DECL_TEST(Manual);
   1.100 +DECL_TEST(Recall);
   1.101 +DECL_TEST(Multi);
   1.102 +DECL_TEST(Ref);
   1.103 +DECL_TEST(RefRet);
   1.104 +DECL_TEST(VPHooks);
   1.105  
   1.106  int main(int argc, char *argv[])
   1.107  {
   1.108 @@ -88,7 +53,24 @@
   1.109  
   1.110  	g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
   1.111  
   1.112 -	Test::DoTests();
   1.113 +	int passed = 0, failed = 0;
   1.114 +
   1.115 +	DO_TEST(List);
   1.116 +	DO_TEST(Basic);
   1.117 +	DO_TEST(VafmtAndOverload);
   1.118 +	DO_TEST(ThisPtrOffs);
   1.119 +	DO_TEST(PlugSys);
   1.120 +	DO_TEST(Bail);
   1.121 +	DO_TEST(Reentr);
   1.122 +	DO_TEST(Manual);
   1.123 +	DO_TEST(Recall);
   1.124 +	DO_TEST(Multi);
   1.125 +	DO_TEST(Ref);
   1.126 +	DO_TEST(RefRet);
   1.127 +	DO_TEST(VPHooks);
   1.128 +
   1.129 +	cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
   1.130 +	cout << "Total: " << passed + failed << endl;
   1.131  
   1.132  	cout << "Press enter to continue" << endl;
   1.133