2012-05-04 23:48:46 +02:00
|
|
|
/* Copyright (C) 2012 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2007-01-04 04:22:23 +01:00
|
|
|
// Got to be consistent with what the rest of the source files do before
|
|
|
|
// including precompiled.h, so that the PCH works correctly
|
|
|
|
#ifndef CXXTEST_RUNNING
|
|
|
|
#define CXXTEST_RUNNING
|
|
|
|
#endif
|
|
|
|
#define _CXXTEST_HAVE_STD
|
|
|
|
|
2006-12-20 04:09:21 +01:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
#include <fstream>
|
|
|
|
|
2010-01-10 12:31:31 +01:00
|
|
|
#include "lib/self_test.h"
|
2006-12-20 04:09:21 +01:00
|
|
|
#include <cxxtest/GlobalFixture.h>
|
|
|
|
|
2008-01-20 17:53:09 +01:00
|
|
|
#if OS_WIN
|
2008-06-30 19:34:18 +02:00
|
|
|
#include "lib/sysdep/os/win/wdbg_heap.h"
|
2008-01-20 17:53:09 +01:00
|
|
|
#endif
|
|
|
|
|
2011-02-24 01:32:38 +01:00
|
|
|
#include "lib/timer.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "lib/sysdep/sysdep.h"
|
2011-11-06 00:09:31 +01:00
|
|
|
#include "ps/Profiler2.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
|
|
|
|
2006-12-20 04:09:21 +01:00
|
|
|
class LeakReporter : public CxxTest::GlobalFixture
|
|
|
|
{
|
|
|
|
virtual bool tearDownWorld()
|
|
|
|
{
|
2010-01-09 20:20:14 +01:00
|
|
|
// Shut down JS to prevent leak reports from it
|
|
|
|
ScriptInterface::ShutDown();
|
|
|
|
|
2006-12-20 04:09:21 +01:00
|
|
|
// Enable leak reporting on exit.
|
|
|
|
// (This is done in tearDownWorld so that it doesn't report 'leaks'
|
|
|
|
// if the program is aborted before finishing cleanly.)
|
2008-01-20 17:53:09 +01:00
|
|
|
#if OS_WIN
|
|
|
|
wdbg_heap_Enable(true);
|
2006-12-20 04:09:21 +01:00
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool setUpWorld()
|
|
|
|
{
|
2008-01-08 01:09:52 +01:00
|
|
|
#if MSC_VERSION
|
2006-12-20 04:09:21 +01:00
|
|
|
// (Warning: the allocation numbers seem to differ by 3 when you
|
|
|
|
// run in the build process vs the debugger)
|
|
|
|
// _CrtSetBreakAlloc(1952);
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-07-06 23:19:59 +02:00
|
|
|
class MiscSetup : public CxxTest::GlobalFixture
|
2011-02-24 01:32:38 +01:00
|
|
|
{
|
|
|
|
virtual bool setUpWorld()
|
|
|
|
{
|
|
|
|
// Timer must be initialised, else things will break when tests do IO
|
|
|
|
timer_LatchStartTime();
|
|
|
|
|
2011-07-06 23:19:59 +02:00
|
|
|
#if OS_MACOSX
|
|
|
|
// See comment in GameSetup.cpp FixLocales
|
|
|
|
setlocale(LC_CTYPE, "UTF-8");
|
|
|
|
#endif
|
|
|
|
|
2012-04-03 20:44:46 +02:00
|
|
|
ThreadUtil::SetMainThread();
|
|
|
|
|
2011-11-06 00:09:31 +01:00
|
|
|
g_Profiler2.Initialise();
|
|
|
|
|
2011-02-24 01:32:38 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-06 00:09:31 +01:00
|
|
|
virtual bool tearDownWorld()
|
|
|
|
{
|
|
|
|
g_Profiler2.Shutdown();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-02-24 01:32:38 +01:00
|
|
|
};
|
|
|
|
|
2006-12-20 04:09:21 +01:00
|
|
|
static LeakReporter leakReporter;
|
2011-07-06 23:19:59 +02:00
|
|
|
static MiscSetup miscSetup;
|
2007-03-19 21:58:46 +01:00
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
// Definition of functions from lib/self_test.h
|
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
bool ts_str_contains(const std::wstring& str1, const std::wstring& str2)
|
2007-03-19 21:58:46 +01:00
|
|
|
{
|
|
|
|
return str1.find(str2) != str1.npos;
|
|
|
|
}
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
// we need the (version-controlled) binaries/data directory because it
|
|
|
|
// contains input files (it is assumed that developer's machines have
|
|
|
|
// write access to those directories). note that argv0 isn't
|
2011-03-23 17:14:47 +01:00
|
|
|
// available, so we use sys_ExecutablePathname.
|
2011-03-23 14:36:20 +01:00
|
|
|
OsPath DataDir()
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2011-05-06 20:45:30 +02:00
|
|
|
return sys_ExecutablePathname().Parent()/".."/"data";
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Script-based testing setup:
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
void script_TS_FAIL(void*, std::wstring msg)
|
|
|
|
{
|
|
|
|
TS_FAIL(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptTestSetup(ScriptInterface& ifc)
|
|
|
|
{
|
|
|
|
ifc.RegisterFunction<void, std::wstring, script_TS_FAIL>("TS_FAIL");
|
|
|
|
|
|
|
|
// Load the TS_* function definitions
|
|
|
|
// (We don't use VFS because tests might not have the normal VFS paths loaded)
|
2011-05-06 20:45:30 +02:00
|
|
|
OsPath path = DataDir()/"tests"/"test_setup.js";
|
2011-03-23 14:36:20 +01:00
|
|
|
std::ifstream ifs(OsString(path).c_str());
|
2011-04-30 15:01:45 +02:00
|
|
|
ENSURE(ifs.good());
|
2010-01-09 20:20:14 +01:00
|
|
|
std::string content((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
2012-05-04 23:48:46 +02:00
|
|
|
bool ok = ifc.LoadScript(L"test_setup.js", content);
|
2011-04-30 15:01:45 +02:00
|
|
|
ENSURE(ok);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|