Changeset View
Changeset View
Standalone View
Standalone View
source/test_setup.cpp
Show All 18 Lines | |||||
// including precompiled.h, so that the PCH works correctly | // including precompiled.h, so that the PCH works correctly | ||||
#ifndef CXXTEST_RUNNING | #ifndef CXXTEST_RUNNING | ||||
#define CXXTEST_RUNNING | #define CXXTEST_RUNNING | ||||
#endif | #endif | ||||
#define _CXXTEST_HAVE_STD | #define _CXXTEST_HAVE_STD | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include <fstream> | |||||
#include "lib/self_test.h" | #include "lib/self_test.h" | ||||
#include <cxxtest/GlobalFixture.h> | #include <cxxtest/GlobalFixture.h> | ||||
#if OS_WIN | #if OS_WIN | ||||
#include "lib/sysdep/os/win/wdbg_heap.h" | #include "lib/sysdep/os/win/wdbg_heap.h" | ||||
#endif | #endif | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "lib/sysdep/sysdep.h" | #include "lib/sysdep/sysdep.h" | ||||
#include "ps/Profiler2.h" | #include "ps/Profiler2.h" | ||||
#include "ps/TaskManager.h" | #include "ps/TaskManager.h" | ||||
#include "scriptinterface/FunctionWrapper.h" | #include "scriptinterface/FunctionWrapper.h" | ||||
#include "scriptinterface/ScriptEngine.h" | #include "scriptinterface/ScriptEngine.h" | ||||
#include "scriptinterface/ScriptContext.h" | #include "scriptinterface/ScriptContext.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include <fstream> | |||||
#include <memory> | |||||
class LeakReporter : public CxxTest::GlobalFixture | class LeakReporter : public CxxTest::GlobalFixture | ||||
{ | { | ||||
virtual bool tearDownWorld() | virtual bool tearDownWorld() | ||||
{ | { | ||||
// Enable leak reporting on exit. | // Enable leak reporting on exit. | ||||
// (This is done in tearDownWorld so that it doesn't report 'leaks' | // (This is done in tearDownWorld so that it doesn't report 'leaks' | ||||
// if the program is aborted before finishing cleanly.) | // if the program is aborted before finishing cleanly.) | ||||
#if OS_WIN | #if OS_WIN | ||||
Show All 23 Lines | |||||
#if OS_MACOSX || OS_BSD | #if OS_MACOSX || OS_BSD | ||||
// See comment in GameSetup.cpp FixLocales | // See comment in GameSetup.cpp FixLocales | ||||
setlocale(LC_CTYPE, "UTF-8"); | setlocale(LC_CTYPE, "UTF-8"); | ||||
#endif | #endif | ||||
Threading::SetMainThread(); | Threading::SetMainThread(); | ||||
g_Profiler2.Initialise(); | profiler = std::make_unique<CProfiler2>(); | ||||
m_ScriptEngine = new ScriptEngine; | m_ScriptEngine = new ScriptEngine; | ||||
g_ScriptContext = ScriptContext::CreateContext(); | g_ScriptContext = ScriptContext::CreateContext(); | ||||
Threading::TaskManager::Initialise(); | Threading::TaskManager::Initialise(); | ||||
return true; | return true; | ||||
} | } | ||||
virtual bool tearDownWorld() | virtual bool tearDownWorld() | ||||
{ | { | ||||
Threading::TaskManager::Instance().ClearQueue(); | Threading::TaskManager::Instance().ClearQueue(); | ||||
g_ScriptContext.reset(); | g_ScriptContext.reset(); | ||||
SAFE_DELETE(m_ScriptEngine); | SAFE_DELETE(m_ScriptEngine); | ||||
g_Profiler2.Shutdown(); | profiler.reset(); | ||||
return true; | return true; | ||||
} | } | ||||
virtual bool setUp() | virtual bool setUp() | ||||
{ | { | ||||
// Clean up any JS leftover between tests. | // Clean up any JS leftover between tests. | ||||
g_ScriptContext->ShrinkingGC(); | g_ScriptContext->ShrinkingGC(); | ||||
return true; | return true; | ||||
} | } | ||||
private: | private: | ||||
std::unique_ptr<CProfiler2> profiler; | |||||
// We're doing the initialization and shutdown of the ScriptEngine explicitly here | // We're doing the initialization and shutdown of the ScriptEngine explicitly here | ||||
// to make sure it's only initialized when setUpWorld is called. | // to make sure it's only initialized when setUpWorld is called. | ||||
ScriptEngine* m_ScriptEngine; | ScriptEngine* m_ScriptEngine; | ||||
}; | }; | ||||
phosit: We don't require support for optional yet. I'll change it to unique_ptr, performance doesn't… | |||||
static LeakReporter leakReporter; | static LeakReporter leakReporter; | ||||
static MiscSetup miscSetup; | static MiscSetup miscSetup; | ||||
// Definition of functions from lib/self_test.h | // Definition of functions from lib/self_test.h | ||||
bool ts_str_contains(const std::string& str1, const std::string& str2) | bool ts_str_contains(const std::string& str1, const std::string& str2) | ||||
{ | { | ||||
return str1.find(str2) != str1.npos; | return str1.find(str2) != str1.npos; | ||||
Show All 39 Lines |
Wildfire Games · Phabricator
We don't require support for optional yet. I'll change it to unique_ptr, performance doesn't mather in tests.