Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/tests/test_MapGenerator.h
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2023 Wildfire Games. | ||||
* This file is part of 0!A.D. | * This file is part of 0!A.D. | ||||
* | * | ||||
* 0!A.D. is free software: you can redistribute it and/or modify | * 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 | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0!A.D. is distributed in the hope that it will be useful, | * 0!A.D. is distributed in the hope that it will be useful, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * 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/>. | * along with 0!A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "graphics/MapGenerator.h" | #include "graphics/MapGenerator.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "simulation2/system/ComponentTest.h" | #include "simulation2/system/ComponentTest.h" | ||||
#include <atomic> | |||||
class TestMapGenerator : public CxxTest::TestSuite | class TestMapGenerator : public CxxTest::TestSuite | ||||
{ | { | ||||
public: | public: | ||||
void setUp() | void setUp() | ||||
{ | { | ||||
g_VFS = CreateVfs(); | g_VFS = CreateVfs(); | ||||
g_VFS->Mount(L"", DataDir() / "mods" / "mod" / "", VFS_MOUNT_MUST_EXIST); | 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 | g_VFS->Mount(L"", DataDir() / "mods" / "public" / "", VFS_MOUNT_MUST_EXIST, 1); // ignore directory-not-found errors | ||||
Show All 17 Lines | void test_mapgen_scripts() | ||||
VfsPaths paths; | VfsPaths paths; | ||||
TS_ASSERT_OK(vfs::GetPathnames(g_VFS, L"maps/random/tests/", L"test_*.js", paths)); | TS_ASSERT_OK(vfs::GetPathnames(g_VFS, L"maps/random/tests/", L"test_*.js", paths)); | ||||
for (const VfsPath& path : paths) | for (const VfsPath& path : paths) | ||||
{ | { | ||||
ScriptInterface scriptInterface("Engine", "MapGenerator", g_ScriptContext); | ScriptInterface scriptInterface("Engine", "MapGenerator", g_ScriptContext); | ||||
ScriptTestSetup(scriptInterface); | ScriptTestSetup(scriptInterface); | ||||
CMapGeneratorWorker worker(&scriptInterface); | // It's never read in the test so it doesn't matter to what value it's initialized. For | ||||
worker.InitScriptInterface(0); | // good practice it's initialized to 1. | ||||
scriptInterface.LoadGlobalScriptFile(path); | std::atomic<int> progress{1}; | ||||
const Script::StructuredClone result{RunMapGenerationScript(progress, scriptInterface, | |||||
path, "{\"Seed\": 0}", JSPROP_ENUMERATE | JSPROP_PERMANENT)}; | |||||
// The test scripts don't call `ExportMap` so `RunMapGenerationScript` allways returns | |||||
// `nullptr`. | |||||
TS_ASSERT_EQUALS(result, nullptr); | |||||
vladislavbelov: Shouldn't `progress` be checked? | |||||
Done Inline ActionsThe test scripts don't call ExportMap. So the result is INVALID_PROGRESS. Should that be checked? phosit: The test scripts don't call `ExportMap`. So the result is `INVALID_PROGRESS`. Should that be… | |||||
Done Inline ActionsIt'd be good to check. vladislavbelov: It'd be good to check. | |||||
} | } | ||||
Not Done Inline ActionsIt follows from the comment that GenerateMap reads the value. That doesn't seem true. Why we can't use INVALID_PROGRESS? vladislavbelov: It follows from the comment that `GenerateMap` reads the value. That doesn't seem true. Why we… | |||||
Done Inline ActionsAfter GenerateMap ran it can't be distinguished from complete or error. phosit: After `GenerateMap` ran it can't be distinguished from complete or error.
In the test it… | |||||
Not Done Inline ActionsI'd replace -1 by INVALID_PROGRESS in the comment. Also in case of "example" it'd be good to match the comments for the function usages. vladislavbelov: I'd replace `-1` by `INVALID_PROGRESS` in the comment. Also in case of "example" it'd be good… | |||||
} | } | ||||
}; | }; |
Wildfire Games · Phabricator
Shouldn't progress be checked?