Core/Misc: DBC std::array refactors, and |Hachievement unit tests

(cherry picked from commit 3fbbe7cfbe)
This commit is contained in:
Treeston
2020-09-01 00:38:46 +02:00
committed by Shauren
parent f7e1b5338d
commit c4b287c7bf
13 changed files with 284 additions and 201 deletions

View File

@@ -17,6 +17,7 @@
#include "DummyData.h"
#include "DB2Stores.h"
#include "ItemDefines.h"
#include "ItemTemplate.h"
#include "ObjectMgr.h"
@@ -56,3 +57,23 @@
const_cast<ItemSparseEntry*>(t.ExtendedData)->OverallQualityID = ITEM_QUALITY_NORMAL;
SetItemLocale(6948, LOCALE_esMX, "Piedra de hogar");
}
static UnitTestDataLoader::DB2<AchievementEntry, &AchievementEntry::ID> achievements(sAchievementStore);
/*static*/ void UnitTestDataLoader::LoadAchievementTemplates()
{
auto loader = achievements.Loader();
AchievementEntry& toc5 = loader.Add();
toc5.ID = 4298;
toc5.Faction = 1;
toc5.InstanceID = 650;
toc5.Title.Str.fill("");
toc5.Title.Str[LOCALE_enUS] = "Heroic: Trial of the Champion";
toc5.Title.Str[LOCALE_esES] = "Heroico: Prueba del Campe\xc3\xb3n";
toc5.Title.Str[LOCALE_esMX] = "Heroico: Prueba del Campe\xc3\xb3n";
toc5.Category = 14921;
toc5.Points = 10;
toc5.Flags = 0;
toc5.MinimumCriteria = 0;
toc5.SharesCriteria = 0;
}

View File

@@ -20,6 +20,7 @@
#include "Common.h"
#include "Define.h"
#include "DB2Store.h"
#include <string_view>
@@ -28,6 +29,42 @@ struct ItemTemplate;
class UnitTestDataLoader
{
public:
template <typename T, uint32 T::*ID>
class DB2
{
class LoaderGuard
{
public:
LoaderGuard(DB2& d) : _d(d) {}
~LoaderGuard() { _d.Dump(); }
T& Add() { return _d._storage.emplace_back(); }
private:
DB2& _d;
};
public:
DB2(DB2Storage<T>& store) : _store(store) {}
LoaderGuard Loader() { return {*this}; }
void Dump()
{
delete[] _store._indexTable.AsT;
for (T const& entry : _storage)
if (entry.*ID >= _store._indexTableSize)
_store._indexTableSize = entry.*ID + 1;
_store._indexTable.AsT = new T*[_store._indexTableSize];
for (size_t i = 0; i < _store._indexTableSize; ++i)
_store._indexTable.AsT[i] = nullptr;
for (T& entry : _storage)
_store._indexTable.AsT[entry.*ID] = &entry;
}
private:
std::vector<T> _storage;
DB2Storage<T>& _store;
};
static void LoadAchievementTemplates();
static void LoadItemTemplates();
private:

View File

@@ -72,3 +72,21 @@ TEST_CASE("|Hitem validation", "[Hyperlinks]")
REQUIRE(false == CheckAllLinks("This is a |cffffffff|Hitem:6948:-1:::::::60:::::|h[Hearthstone]|h|r that is quite negative."));
}
}
TEST_CASE("|Hachievement validation", "[Hyperlinks]")
{
UnitTestDataLoader::LoadAchievementTemplates();
sWorld->setIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_SEVERITY, 1);
REQUIRE(true == CheckAllLinks("|cffffff00|Hachievement:4298:Player-0-000000FD:0:0:0:-1:0:0:0:0|h[Heroic: Trial of the Champion]|h|r"));
REQUIRE(false == CheckAllLinks("|cffffff00|Hachievement|h[Heroic: Trial of the Champion]|h|r"));
REQUIRE(false == CheckAllLinks("|cffffff00|Hachievement:1:Player-0-000000FD:0:0:0:-1:0:0:0:0|h[Heroic: Trial of the Champion]|h|r"));
REQUIRE(false == CheckAllLinks("|cffff0000|Hachievement:4298:Player-0-000000FD:0:0:0:-1:0:0:0:0|h[Heroic: Trial of the Champion]|h|r"));
REQUIRE(false == CheckAllLinks("|cffffff00|Hachievement:4298:00000000000000XY:0:0:0:-1:0:0:0:0|h[Heroic: Trial of the Champion]|h|r"));
REQUIRE(true == CheckAllLinks("|cffffff00|Hachievement:4298:Player-0-000000FD:1:12:20:12:0:0:0:0|h[Heroic: Trial of the Champion]|h|r"));
REQUIRE(false == CheckAllLinks("|cffffff00|Hachievement:4298:Player-0-000000FD:1:12:40:12:0:0:0:0|h[Heroic: Trial of the Champion]|h|r"));
REQUIRE(false == CheckAllLinks("|cffffff00|Hachievement:4298:Player-0-000000FD:1:14:20:12:0:0:0:0|h[Heroic: Trial of the Champion]|h|r"));
REQUIRE(false == CheckAllLinks("|cffffff00|Hachievement:4298:Player-0-000000FD:1:0:0:-1:0:0:0:0|h[Heroic: Trial of the Champion]|h|r"));
REQUIRE(true == CheckAllLinks("|cffffff00|Hachievement:4298:Player-0-000000FD:1:12:20:12:0:0:0:0|h[Heroico: Prueba del Campe\xc3\xb3n]|h|r"));
}