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
|
|
|
|
2007-10-08 00:10:07 +02:00
|
|
|
static SourceHook::CVector<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;
|
2007-10-08 00:10:07 +02:00
|
|
|
for (SourceHook::CVector<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
|
|
|
|
2007-10-08 00:10:07 +02:00
|
|
|
SourceHook::CVector<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);
|
2006-05-13 20:23:25 +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);
|
2007-10-08 17:23:08 +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);
|
2006-05-13 19:57:35 +02:00
|
|
|
DO_TEST(Ref);
|
2006-08-09 08:46:11 +02:00
|
|
|
DO_TEST(RefRet);
|
2007-05-07 20:35:59 +02:00
|
|
|
DO_TEST(VPHooks);
|
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()
|
|
|
|
{
|
2007-10-08 00:10:07 +02:00
|
|
|
return new SourceHook::Impl::CSourceHookImpl();
|
2005-12-23 12:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Test_Delete(SourceHook::ISourceHook *shptr)
|
|
|
|
{
|
2007-10-08 00:10:07 +02:00
|
|
|
delete static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr);
|
2005-12-23 12:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Test_CompleteShutdown(SourceHook::ISourceHook *shptr)
|
|
|
|
{
|
2007-10-08 00:10:07 +02:00
|
|
|
static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->CompleteShutdown();
|
2005-12-23 12:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
|
|
|
|
{
|
2007-10-08 00:10:07 +02:00
|
|
|
static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnloadPlugin(plug);
|
2005-12-23 12:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
|
|
|
|
{
|
2007-10-08 00:10:07 +02:00
|
|
|
static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->PausePlugin(plug);
|
2005-12-23 12:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
|
|
|
|
{
|
2007-10-08 00:10:07 +02:00
|
|
|
static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
|
2005-12-24 00:15:18 +01:00
|
|
|
}
|