Index: binaries/data/mods/public/gui/session/session.js
===================================================================
--- binaries/data/mods/public/gui/session/session.js
+++ binaries/data/mods/public/gui/session/session.js
@@ -1,5 +1,5 @@
const g_IsReplay = Engine.IsVisualReplay();
-
+warn(123);
const g_CivData = loadCivData(false, true);
const g_Ceasefire = prepareForDropdown(g_Settings && g_Settings.Ceasefire);
Index: binaries/data/mods/public/maps/random/rmgen/RandomMapLogger.js
===================================================================
--- binaries/data/mods/public/maps/random/rmgen/RandomMapLogger.js
+++ binaries/data/mods/public/maps/random/rmgen/RandomMapLogger.js
@@ -4,11 +4,13 @@
this.startTime = Engine.GetMicroseconds();
this.prefix = ""; // seems noisy
- this.printDirectly(
- this.prefix +
- "Generating " + g_MapSettings.Name +
- " of size " + g_MapSettings.Size +
- " and " + getNumPlayers() + " players.\n");
+ // Don't print in test cases
+ if (g_MapSettings.Name)
+ this.printDirectly(
+ this.prefix +
+ "Generating " + g_MapSettings.Name +
+ " of size " + g_MapSettings.Size +
+ " and " + (g_MapSettings.PlayerData.length - 1) + " players.\n");
}
RandomMapLogger.prototype.printDirectly = function(string)
Index: binaries/data/mods/public/maps/random/tests/test_TileClass.js
===================================================================
--- /dev/null
+++ binaries/data/mods/public/maps/random/tests/test_TileClass.js
@@ -0,0 +1,93 @@
+Engine.LoadLibrary("rmgen");
+Engine.GetMicroseconds = () => 0;
+
+var g_MapSettings = { "Size": 512 };
+var g_Map = new RandomMap(0, "blackness");
+
+// Test that that it checks by value, not by reference
+{
+ let tileClass = new TileClass(2);
+ let reference1 = new Vector2D(1, 1);
+ let reference2 = new Vector2D(1.000, 1.0);
+ tileClass.add(reference1);
+ TS_ASSERT(tileClass.has(reference2));
+}
+
+// Test out-of-bounds
+{
+ let tileClass = new TileClass(32);
+ let absentPoints = [
+ new Vector2D(0, 0),
+ new Vector2D(0, 1),
+ new Vector2D(1, 0),
+ new Vector2D(-1, -1),
+ new Vector2D(2048, 0),
+ new Vector2D(0, NaN),
+ new Vector2D(0, Infinity)
+ ];
+
+ absentPoints.forEach(point => {
+ TS_ASSERT(!tileClass.has(point));
+ });
+}
+
+// Test multi-insertion
+{
+ let tileClass = new TileClass(32);
+ let point = new Vector2D(1, 1);
+
+ tileClass.add(point);
+ tileClass.add(point);
+ TS_ASSERT_EQUALS(tileClass.countMembersInRadius(point, 0), 1);
+
+ // Still one point remaining
+ tileClass.remove(point);
+ tileClass.remove(point);
+ TS_ASSERT(!tileClass.has(point));
+}
+
+// Test Multi-insertion removal
+{
+ let tileClass = new TileClass(32);
+ let point = new Vector2D(2, 7);
+
+ tileClass.add(point);
+ tileClass.add(point);
+ tileClass.remove(point);
+ TS_ASSERT(tileClass.has(point));
+
+ tileClass.remove(point);
+ TS_ASSERT(!tileClass.has(point));
+}
+
+//Test Multi-insertion removal
+{
+ let tileClass = new TileClass(55);
+ let point = new Vector2D(5, 4);
+
+ for (let i = 0; i < 50; ++i)
+ tileClass.add(point);
+
+ tileClass.remove(point);
+ TS_ASSERT(tileClass.has(point));
+
+ tileClass.remove(point);
+ TS_ASSERT(tileClass.has(point));
+}
+
+// Test getters
+{
+ let tileClass = new TileClass(88);
+ let point = new Vector2D(5, 1);
+ tileClass.add(point);
+
+ let point2 = new Vector2D(4, 9);
+ tileClass.add(point2);
+
+ TS_ASSERT_EQUALS(tileClass.countMembersInRadius(point, 1), 1);
+ TS_ASSERT_EQUALS(tileClass.countMembersInRadius(point, 100), 2);
+
+ TS_ASSERT_EQUALS(tileClass.countNonMembersInRadius(point, 1), 4);
+ TS_ASSERT_EQUALS(tileClass.countNonMembersInRadius(point, 2), 12);
+ TS_ASSERT_EQUALS(tileClass.countNonMembersInRadius(point, 3), 28);
+}
Index: source/graphics/MapGenerator.cpp
===================================================================
--- source/graphics/MapGenerator.cpp
+++ source/graphics/MapGenerator.cpp
@@ -294,11 +294,11 @@
{
for (const VfsPath& p : pathnames)
{
- LOGMESSAGE("Loading map generator script '%s'", p.string8());
+ LOGMESSAGE("Loading map generator script '%s'", p.string8().c_str());
if (!m_ScriptInterface->LoadGlobalScriptFile(p))
{
- LOGERROR("CMapGeneratorWorker::LoadScripts: Failed to load script '%s'", p.string8());
+ LOGERROR("CMapGeneratorWorker::LoadScripts: Failed to load script '%s'", p.string8().c_str());
return false;
}
}
Index: source/graphics/tests/test_MapGenerator.h
===================================================================
--- /dev/null
+++ source/graphics/tests/test_MapGenerator.h
@@ -0,0 +1,84 @@
+/* Copyright (C) 2019 Wildfire Games.
+ * 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 .
+ */
+
+#include "simulation2/system/ComponentTest.h"
+
+#include "ps/Filesystem.h"
+#include "ps/scripting/JSInterface_VFS.h"
+
+class TestMapGenerator : public CxxTest::TestSuite
+{
+public:
+ void setUp()
+ {
+ g_VFS = CreateVfs();
+ g_VFS->Mount(L"", DataDir()/"mods"/"mod", VFS_MOUNT_MUST_EXIST);
+ g_VFS->Mount(L"", DataDir()/"mods"/"public", VFS_MOUNT_MUST_EXIST, 1); // ignore directory-not-found errors
+ CXeromyces::Startup();
+ }
+
+ void tearDown()
+ {
+ CXeromyces::Terminate();
+ g_VFS.reset();
+ }
+
+ static bool LoadScripts(ScriptInterface::CxPrivate* pCxPrivate, const VfsPath& libraryName)
+ {
+ VfsPath path = VfsPath(L"maps/random/") / libraryName / VfsPath();
+ VfsPaths pathnames;
+
+ Status ret = vfs::GetPathnames(g_VFS, path, L"*.js", pathnames);
+
+ if (ret != INFO::OK)
+ {
+ LOGERROR("TestMapGenerator::LoadScripts: Failed to load folder contents '%s'", path.string8());
+ return false;
+ }
+
+ for (const VfsPath& p : pathnames)
+ {
+ if (!pCxPrivate->pScriptInterface->LoadGlobalScriptFile(p))
+ {
+ LOGERROR("TestMapGenerator::LoadScripts: Failed to load script '%s'", p.string8());
+ return false;
+ }
+ }
+ return true;
+ }
+
+ void RegisterScriptFunctions(ScriptInterface& scriptInterface)
+ {
+ JSI_VFS::RegisterScriptFunctions_Maps(scriptInterface);
+ scriptInterface.LoadGlobalScripts();
+ scriptInterface.RegisterFunction("LoadLibrary");
+ }
+
+ void test_mapgen_scripts()
+ {
+ VfsPaths paths;
+ TS_ASSERT_OK(vfs::GetPathnames(g_VFS, L"maps/random/tests/", L"test_*.js", paths));
+
+ for (const VfsPath& path : paths)
+ {
+ ScriptInterface scriptInterface("Engine", "MapGenerator", g_ScriptRuntime);
+ ScriptTestSetup(scriptInterface);
+ RegisterScriptFunctions(scriptInterface);
+ scriptInterface.LoadGlobalScriptFile(path);
+ }
+ }
+};