Remove materials from particle actors to prevent useless warnings.
[0ad.git] / source / test_setup.cpp
blobd94b46e5173fc3539f7d97e7ef3ebab5038b56fc
1 /* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 // Got to be consistent with what the rest of the source files do before
19 // including precompiled.h, so that the PCH works correctly
20 #ifndef CXXTEST_RUNNING
21 #define CXXTEST_RUNNING
22 #endif
23 #define _CXXTEST_HAVE_STD
25 #include "precompiled.h"
27 #include <fstream>
29 #include "lib/self_test.h"
30 #include <cxxtest/GlobalFixture.h>
32 #if OS_WIN
33 #include "lib/sysdep/os/win/wdbg_heap.h"
34 #endif
36 #include "lib/timer.h"
37 #include "lib/sysdep/sysdep.h"
38 #include "ps/Profiler2.h"
39 #include "ps/TaskManager.h"
40 #include "scriptinterface/FunctionWrapper.h"
41 #include "scriptinterface/ScriptEngine.h"
42 #include "scriptinterface/ScriptContext.h"
43 #include "scriptinterface/ScriptInterface.h"
45 class LeakReporter : public CxxTest::GlobalFixture
47 virtual bool tearDownWorld()
49 // Enable leak reporting on exit.
50 // (This is done in tearDownWorld so that it doesn't report 'leaks'
51 // if the program is aborted before finishing cleanly.)
52 #if OS_WIN
53 wdbg_heap_Enable(true);
54 #endif
55 return true;
58 virtual bool setUpWorld()
60 #if MSC_VERSION
61 // (Warning: the allocation numbers seem to differ by 3 when you
62 // run in the build process vs the debugger)
63 // _CrtSetBreakAlloc(1952);
64 #endif
65 return true;
70 class MiscSetup : public CxxTest::GlobalFixture
72 virtual bool setUpWorld()
74 // Timer must be initialised, else things will break when tests do IO
75 timer_Init();
77 #if OS_MACOSX || OS_BSD
78 // See comment in GameSetup.cpp FixLocales
79 setlocale(LC_CTYPE, "UTF-8");
80 #endif
82 Threading::SetMainThread();
84 g_Profiler2.Initialise();
85 m_ScriptEngine = new ScriptEngine;
86 g_ScriptContext = ScriptContext::CreateContext();
88 Threading::TaskManager::Initialise();
90 return true;
93 virtual bool tearDownWorld()
95 Threading::TaskManager::Instance().ClearQueue();
96 g_ScriptContext.reset();
97 SAFE_DELETE(m_ScriptEngine);
98 g_Profiler2.Shutdown();
100 return true;
103 virtual bool setUp()
105 // Clean up any JS leftover between tests.
106 g_ScriptContext->ShrinkingGC();
108 return true;
111 private:
113 // We're doing the initialization and shutdown of the ScriptEngine explicitly here
114 // to make sure it's only initialized when setUpWorld is called.
115 ScriptEngine* m_ScriptEngine;
118 static LeakReporter leakReporter;
119 static MiscSetup miscSetup;
121 // Definition of functions from lib/self_test.h
123 bool ts_str_contains(const std::string& str1, const std::string& str2)
125 return str1.find(str2) != str1.npos;
128 bool ts_str_contains(const std::wstring& str1, const std::wstring& str2)
130 return str1.find(str2) != str1.npos;
133 // we need the (version-controlled) binaries/data directory because it
134 // contains input files (it is assumed that developer's machines have
135 // write access to those directories). note that argv0 isn't
136 // available, so we use sys_ExecutablePathname.
137 OsPath DataDir()
139 return sys_ExecutablePathname().Parent()/".."/"data";
142 // Script-based testing setup:
144 namespace
146 void script_TS_FAIL(const std::wstring& msg)
148 TS_FAIL(utf8_from_wstring(msg).c_str());
152 void ScriptTestSetup(const ScriptInterface& scriptInterface)
154 ScriptRequest rq(scriptInterface);
155 ScriptFunction::Register<script_TS_FAIL>(rq, "TS_FAIL");
157 // Load the TS_* function definitions
158 // (We don't use VFS because tests might not have the normal VFS paths loaded)
159 OsPath path = DataDir()/"tests"/"test_setup.js";
160 std::ifstream ifs(OsString(path).c_str());
161 ENSURE(ifs.good());
162 std::string content((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
163 ENSURE(scriptInterface.LoadScript(L"test_setup.js", content));