From ae1a595ce337ebcc292b317427e1b15e9f5df0db Mon Sep 17 00:00:00 2001 From: Karrz1 <127596890+Karrz1@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:21:46 +0000 Subject: [PATCH] test: add isolated real map fixture for spell lifecycle checks From KylRikul/TrinityCore, commit f5edcd618a, by KylRikul (GPL-2.0). Thank you! --- tests/DummyData.cpp | 35 +++++++++++++++++++++++++++++++++++ tests/DummyData.h | 20 ++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/tests/DummyData.cpp b/tests/DummyData.cpp index 4aa7cae0a8..a162b36b43 100644 --- a/tests/DummyData.cpp +++ b/tests/DummyData.cpp @@ -21,9 +21,44 @@ #include "ItemDefines.h" #include "ItemTemplate.h" #include "ObjectMgr.h" +#include "Map.h" +#include "MMapManager.h" #include "SpellInfo.h" +#include #include // std::memset +UnitTestDataLoader::MapFixture::MapFixture() + : _previousIndex(sMapStore._indexTable), _previousSize(sMapStore._indexTableSize) +{ + static bool const registered = [] + { + MMAP::MMapManager* manager = MMAP::MMapManager::instance(); + ASSERT(manager->getLoadedMapsCount() == 0, "MapFixture requires an isolated, uninitialized MMapManager"); + manager->InitializeThreadUnsafe({ { 0, {} } }); + return true; + }(); + (void)registered; + + _entry.ID = 0; + _entry.ParentMapID = _entry.CosmeticParentMapID = -1; + _entry.Directory = "unit-test"; + _entry.MapName.Str.fill("unit-test"); + sMapStore._indexTableSize = std::max(_previousSize, 1); + sMapStore._indexTable = new char*[sMapStore._indexTableSize]{}; + if (_previousSize) + std::copy_n(_previousIndex, _previousSize, sMapStore._indexTable); + sMapStore._indexTable[0] = reinterpret_cast(&_entry); + _map = std::make_unique(0, 1, 0, DIFFICULTY_NONE); +} + +UnitTestDataLoader::MapFixture::~MapFixture() +{ + _map.reset(); + delete[] sMapStore._indexTable; + sMapStore._indexTable = _previousIndex; + sMapStore._indexTableSize = _previousSize; +} + /*static*/ void UnitTestDataLoader::LoadSpellImmunities(SpellInfo& spellInfo) { spellInfo._LoadImmunityInfo(); diff --git a/tests/DummyData.h b/tests/DummyData.h index 1c954fdd4a..17830ca596 100644 --- a/tests/DummyData.h +++ b/tests/DummyData.h @@ -21,16 +21,36 @@ #include "Common.h" #include "Define.h" #include "DB2Store.h" +#include "DB2Structure.h" +#include #include class Item; struct ItemTemplate; class SpellInfo; +class Map; class UnitTestDataLoader { public: + // An empty real map for Spell lifecycle tests. No grids or world data + // are loaded, and the pre-existing map-store index is restored. + class MapFixture + { + public: + MapFixture(); + ~MapFixture(); + Map& Get() const { return *_map; } + MapFixture(MapFixture const&) = delete; + MapFixture& operator=(MapFixture const&) = delete; + private: + MapEntry _entry{}; + char** _previousIndex; + uint32 _previousSize; + std::unique_ptr _map; + }; + static uint16 ResolveItemVisual(Item const& item, uint32 visibleEnchantmentId); template