test: add isolated real map fixture for spell lifecycle checks

From KylRikul/TrinityCore, commit f5edcd618a, by KylRikul (GPL-2.0). Thank you!
This commit is contained in:
Karrz1
2026-11-14 08:07:57 +00:00
parent bbeaa54280
commit ae1a595ce3
2 changed files with 55 additions and 0 deletions
+35
View File
@@ -21,9 +21,44 @@
#include "ItemDefines.h"
#include "ItemTemplate.h"
#include "ObjectMgr.h"
#include "Map.h"
#include "MMapManager.h"
#include "SpellInfo.h"
#include <algorithm>
#include <cstring> // 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<uint32>(_previousSize, 1);
sMapStore._indexTable = new char*[sMapStore._indexTableSize]{};
if (_previousSize)
std::copy_n(_previousIndex, _previousSize, sMapStore._indexTable);
sMapStore._indexTable[0] = reinterpret_cast<char*>(&_entry);
_map = std::make_unique<Map>(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();
+20
View File
@@ -21,16 +21,36 @@
#include "Common.h"
#include "Define.h"
#include "DB2Store.h"
#include "DB2Structure.h"
#include <memory>
#include <string_view>
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> _map;
};
static uint16 ResolveItemVisual(Item const& item, uint32 visibleEnchantmentId);
template <typename T, uint32 T::*ID>