From 9c4d14173e09297505d0bf6081acc215f231bd99 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Thu, 1 Oct 2026 06:17:06 -0500 Subject: [PATCH] test: write every LOT's component list from a real CDServer.sqlite (DLU_LOADER_SNAPSHOT), to compare loaders Co-Authored-By: Claude Opus 5.5 --- tests/dGameTests/CMakeLists.txt | 1 + tests/dGameTests/LoaderSnapshotTests.cpp | 52 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/dGameTests/LoaderSnapshotTests.cpp diff --git a/tests/dGameTests/CMakeLists.txt b/tests/dGameTests/CMakeLists.txt index 450cec427..0283b0422 100644 --- a/tests/dGameTests/CMakeLists.txt +++ b/tests/dGameTests/CMakeLists.txt @@ -1,5 +1,6 @@ set(DGAMETEST_SOURCES "GameDependencies.cpp" + "LoaderSnapshotTests.cpp" "GuildManagerTests.cpp" "LUBitStreamTests.cpp" "MailIdPinTests.cpp" diff --git a/tests/dGameTests/LoaderSnapshotTests.cpp b/tests/dGameTests/LoaderSnapshotTests.cpp new file mode 100644 index 000000000..e6ca77af4 --- /dev/null +++ b/tests/dGameTests/LoaderSnapshotTests.cpp @@ -0,0 +1,52 @@ +// Tool (task 51): writes every LOT's component list to $DLU_LOADER_SNAPSHOT, built from the real CDServer.sqlite in +// $DLU_LOADER_CDSERVER, so the loader rework can be compared with the old loader. Skipped without both. +#include "GameDependencies.h" +#include + +#include +#include +#include + +#include "CDClientDatabase.h" +#include "CDClientManager.h" +#include "DestroyableComponent.h" +#include "Entity.h" + +class LoaderSnapshotTest : public GameDependenciesTest { +protected: + void SetUp() override { SetUpDependencies(); } + void TearDown() override { TearDownDependencies(); } +}; + +TEST_F(LoaderSnapshotTest, EveryLot) { + const char* const out = std::getenv("DLU_LOADER_SNAPSHOT"); + const char* const db = std::getenv("DLU_LOADER_CDSERVER"); + if (!out || !db) GTEST_SKIP() << "DLU_LOADER_SNAPSHOT / DLU_LOADER_CDSERVER not set"; + CDClientDatabase::Connect(db); + CDClientManager::LoadValuesFromDatabase(); + + std::vector lots; + auto query = CDClientDatabase::ExecuteQuery("SELECT id FROM Objects ORDER BY id;"); + while (!query.eof()) { + lots.push_back(query.getIntField(0)); + query.nextRow(); + } + std::ofstream file(out); + LWOOBJID id = 288300744895990000; + for (const auto lot : lots) { + if (lot == 1) continue; + info.lot = lot; + Entity entity(id++, info); + entity.Initialize(); + std::vector types; + for (const auto& [type, component] : entity.GetComponents()) types.push_back(static_cast(type)); + std::sort(types.begin(), types.end()); + file << lot << ":"; + for (const auto type : types) file << " " << type; + if (auto* const destroyable = entity.GetComponent()) { + file << " | hp " << destroyable->GetMaxHealth() << " im " << destroyable->GetMaxImagination() << " sm " << destroyable->GetIsSmashable() << " f"; + for (const auto faction : destroyable->GetFactionIDs()) file << " " << faction; + } + file << "\n"; + } +}