2005-04-14 18:19:07 +02:00
|
|
|
// Hello BAIL!
|
2005-09-12 01:24:18 +02:00
|
|
|
// hello pm how are you
|
2005-09-23 22:14:10 +02:00
|
|
|
// I'm fine, what about you?
|
2005-12-06 07:01:16 +01:00
|
|
|
// not bad, just looking for mem leaks
|
2005-12-23 12:58:11 +01:00
|
|
|
// mem leaks in my code!? never! I have to preserve binary compatibility :(
|
2005-04-14 18:19:07 +02:00
|
|
|
// This is a test file
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <iostream>
|
2005-04-30 17:48:46 +02:00
|
|
|
#include <string>
|
2005-09-13 18:47:42 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include "sh_tinyhash.h"
|
2005-09-23 22:14:10 +02:00
|
|
|
#include "sh_list.h"
|
2005-08-12 19:33:31 +02:00
|
|
|
#include "sourcehook_impl.h"
|
2005-12-06 07:01:16 +01:00
|
|
|
#include "sourcehook.h"
|
2005-04-14 18:19:07 +02:00
|
|
|
|
2005-04-30 17:48:46 +02:00
|
|
|
using namespace std;
|
2005-04-14 18:19:07 +02:00
|
|
|
|
2005-05-01 20:04:18 +02:00
|
|
|
bool g_Verbose;
|
|
|
|
|
2005-04-30 17:48:46 +02:00
|
|
|
class Test
|
2005-04-14 18:19:07 +02:00
|
|
|
{
|
2005-04-30 17:48:46 +02:00
|
|
|
typedef bool (*TestProto)(std::string&);
|
|
|
|
TestProto m_Func;
|
|
|
|
std::string m_Name;
|
2005-04-14 18:19:07 +02:00
|
|
|
|
2005-09-23 22:14:10 +02:00
|
|
|
static SourceHook::List<Test *> ms_Tests;
|
2005-04-14 18:19:07 +02:00
|
|
|
public:
|
2005-04-30 17:48:46 +02:00
|
|
|
Test(TestProto func, const char *name) : m_Func(func), m_Name(name)
|
2005-04-14 18:19:07 +02:00
|
|
|
{
|
2005-04-30 17:48:46 +02:00
|
|
|
ms_Tests.push_back(this);
|
2005-04-14 18:19:07 +02:00
|
|
|
}
|
|
|
|
|
2005-04-30 17:48:46 +02:00
|
|
|
bool operator()()
|
|
|
|
{
|
|
|
|
std::string error;
|
|
|
|
if (!m_Func(error))
|
|
|
|
{
|
|
|
|
cout << "Test" << m_Name << " FAILED: " << error << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cout << "Test" << m_Name << " passed" << endl;
|
|
|
|
return true;
|
|
|
|
}
|
2005-04-14 18:19:07 +02:00
|
|
|
}
|
|
|
|
|
2005-04-30 17:48:46 +02:00
|
|
|
static void DoTests()
|
|
|
|
{
|
|
|
|
int passed=0, failed=0;
|
2005-09-23 22:14:10 +02:00
|
|
|
for (SourceHook::List<Test*>::iterator iter = ms_Tests.begin(); iter != ms_Tests.end(); ++iter)
|
2005-04-30 17:48:46 +02:00
|
|
|
{
|
|
|
|
if ((**iter)())
|
|
|
|
++passed;
|
|
|
|
else
|
|
|
|
++failed;
|
|
|
|
}
|
2005-04-30 21:09:51 +02:00
|
|
|
cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
|
|
|
|
cout << "Total: " << passed + failed << endl;
|
2005-04-30 17:48:46 +02:00
|
|
|
}
|
|
|
|
};
|
2005-04-14 18:19:07 +02:00
|
|
|
|
2005-09-23 22:14:10 +02:00
|
|
|
SourceHook::List<Test *> Test::ms_Tests;
|
2005-04-14 18:19:07 +02:00
|
|
|
|
2005-04-30 17:48:46 +02:00
|
|
|
#define DO_TEST(x) \
|
|
|
|
bool Test##x(std::string &error); \
|
|
|
|
Test g_Test##x(Test##x, #x);
|
2005-04-14 18:19:07 +02:00
|
|
|
|
2005-09-23 22:14:10 +02:00
|
|
|
DO_TEST(List);
|
2005-04-30 17:48:46 +02:00
|
|
|
DO_TEST(Basic);
|
2005-04-30 21:09:51 +02:00
|
|
|
DO_TEST(VafmtAndOverload);
|
2005-05-05 12:40:47 +02:00
|
|
|
DO_TEST(ThisPtrOffs);
|
2005-05-05 16:00:08 +02:00
|
|
|
DO_TEST(PlugSys);
|
2005-05-27 23:39:30 +02:00
|
|
|
DO_TEST(Bail);
|
2005-10-14 19:45:36 +02:00
|
|
|
DO_TEST(Reentr);
|
2005-12-10 23:37:53 +01:00
|
|
|
DO_TEST(Manual);
|
2005-12-23 12:58:11 +01:00
|
|
|
DO_TEST(Recall);
|
2006-01-24 21:02:19 +01:00
|
|
|
DO_TEST(Multi);
|
2005-04-14 18:19:07 +02:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2005-04-30 17:48:46 +02:00
|
|
|
std::string error;
|
2005-04-14 18:19:07 +02:00
|
|
|
|
2005-05-05 16:00:08 +02:00
|
|
|
g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
|
2005-05-01 20:04:18 +02:00
|
|
|
|
2005-04-30 17:48:46 +02:00
|
|
|
Test::DoTests();
|
2005-04-14 18:19:07 +02:00
|
|
|
|
2005-04-30 17:48:46 +02:00
|
|
|
cout << "Press enter to continue" << endl;
|
2005-04-14 18:19:07 +02:00
|
|
|
|
2005-04-30 17:48:46 +02:00
|
|
|
char x;
|
|
|
|
cin.read(&x, 1);
|
2005-05-01 14:36:48 +02:00
|
|
|
}
|
|
|
|
|
2005-12-23 12:58:11 +01:00
|
|
|
SourceHook::ISourceHook *Test_Factory()
|
|
|
|
{
|
|
|
|
return new SourceHook::CSourceHookImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test_Delete(SourceHook::ISourceHook *shptr)
|
|
|
|
{
|
|
|
|
delete static_cast<SourceHook::CSourceHookImpl *>(shptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test_CompleteShutdown(SourceHook::ISourceHook *shptr)
|
|
|
|
{
|
|
|
|
static_cast<SourceHook::CSourceHookImpl *>(shptr)->CompleteShutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Test_IsPluginInUse(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
|
|
|
|
{
|
|
|
|
return static_cast<SourceHook::CSourceHookImpl *>(shptr)->IsPluginInUse(plug);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
|
|
|
|
{
|
|
|
|
static_cast<SourceHook::CSourceHookImpl *>(shptr)->UnloadPlugin(plug);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
|
|
|
|
{
|
|
|
|
static_cast<SourceHook::CSourceHookImpl *>(shptr)->PausePlugin(plug);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
|
|
|
|
{
|
|
|
|
static_cast<SourceHook::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
|
2005-12-24 00:15:18 +01:00
|
|
|
}
|
|
|
|
|