aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/server/game/Chat/Hyperlinks.cpp14
-rw-r--r--src/server/game/Chat/Hyperlinks.h2
-rw-r--r--src/server/game/Globals/ObjectMgr.h14
-rw-r--r--tests/DummyData.cpp58
-rw-r--r--tests/DummyData.h38
-rw-r--r--tests/game/Hyperlinks.cpp59
6 files changed, 164 insertions, 21 deletions
diff --git a/src/server/game/Chat/Hyperlinks.cpp b/src/server/game/Chat/Hyperlinks.cpp
index 387e723ce11..448ad0a4ea7 100644
--- a/src/server/game/Chat/Hyperlinks.cpp
+++ b/src/server/game/Chat/Hyperlinks.cpp
@@ -372,7 +372,7 @@ struct LinkValidator<LinkTags::item>
{
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
{
- std::string name = itemTemplate->GetName(i);
+ std::string_view name = itemTemplate->GetName(i);
if (name.empty())
continue;
if (suffixStrings)
@@ -449,16 +449,20 @@ struct LinkValidator<LinkTags::quest>
{
static bool IsTextValid(QuestLinkData const& data, std::string_view text)
{
+ if (text == data.Quest->GetLogTitle())
+ return true;
+
QuestTemplateLocale const* locale = sObjectMgr->GetQuestLocale(data.Quest->GetQuestId());
if (!locale)
- return data.Quest->GetLogTitle().c_str() == text;
+ return false;
for (uint8 i = 0; i < TOTAL_LOCALES; ++i)
{
- std::string const& name = (i == DEFAULT_LOCALE) ? data.Quest->GetLogTitle() : locale->LogTitle[i];
- if (name.empty())
+ if (i == DEFAULT_LOCALE)
continue;
- if (text == name)
+
+ std::string_view name = ObjectMgr::GetLocaleString(locale->LogTitle, i);
+ if (!name.empty() && (text == name))
return true;
}
diff --git a/src/server/game/Chat/Hyperlinks.h b/src/server/game/Chat/Hyperlinks.h
index bbbe5eb9a7a..963262018d5 100644
--- a/src/server/game/Chat/Hyperlinks.h
+++ b/src/server/game/Chat/Hyperlinks.h
@@ -210,7 +210,7 @@ namespace Trinity::Hyperlinks
|* - this method SHOULD be constexpr *|
|* - returns identifier string for the link ("creature", "creature_entry", "item") *|
|* - MUST expose static ::StoreTo method, (storage&, std::string_view) *|
- |* - assign value_type& based on content of std::string_view *|
+ |* - assign storage& based on content of std::string_view *|
|* - return value indicates success/failure *|
|* - for integral/string types this can be achieved by extending base_tag *|
\****************************************************************************************/
diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h
index 65956b83e87..e157a84c539 100644
--- a/src/server/game/Globals/ObjectMgr.h
+++ b/src/server/game/Globals/ObjectMgr.h
@@ -1059,6 +1059,7 @@ class PlayerDumpReader;
class TC_GAME_API ObjectMgr
{
friend class PlayerDumpReader;
+ friend class UnitTestDataLoader;
private:
ObjectMgr();
@@ -1684,10 +1685,17 @@ class TC_GAME_API ObjectMgr
GraveyardContainer GraveyardStore;
static void AddLocaleString(std::string&& value, LocaleConstant localeConstant, std::vector<std::string>& data);
- static inline void GetLocaleString(std::vector<std::string> const& data, LocaleConstant localeConstant, std::string& value)
+ static std::string_view GetLocaleString(std::vector<std::string> const& data, size_t locale)
{
- if (data.size() > size_t(localeConstant) && !data[localeConstant].empty())
- value = data[localeConstant];
+ if (locale < data.size())
+ return data[locale];
+ else
+ return {};
+ }
+ static void GetLocaleString(std::vector<std::string> const& data, LocaleConstant localeConstant, std::string& value)
+ {
+ if (std::string_view str = GetLocaleString(data, static_cast<size_t>(localeConstant)); !str.empty())
+ value.assign(str);
}
CharacterConversionMap FactionChangeAchievements;
diff --git a/tests/DummyData.cpp b/tests/DummyData.cpp
new file mode 100644
index 00000000000..e5d0427e908
--- /dev/null
+++ b/tests/DummyData.cpp
@@ -0,0 +1,58 @@
+/*
+ * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "DummyData.h"
+
+#include "ItemDefines.h"
+#include "ItemTemplate.h"
+#include "ObjectMgr.h"
+
+/*static*/ ItemTemplate& UnitTestDataLoader::GetItemTemplate(uint32 itemId, std::string_view name)
+{
+ ItemTemplate& t = sObjectMgr->_itemTemplateStore[itemId];
+ ItemEntry* itemEntry = new ItemEntry();
+ memset(itemEntry, 0, sizeof(ItemEntry));
+ itemEntry->ID = itemId;
+ itemEntry->ClassID = ITEM_CLASS_MISCELLANEOUS;
+ t.BasicData = itemEntry;
+
+ ItemSparseEntry* itemSparse = new ItemSparseEntry();
+ itemSparse->ID = itemId;
+ for (char const*& display : itemSparse->Display.Str)
+ display = "";
+ itemSparse->Display.Str[LOCALE_enUS] = name.data();
+ itemSparse->OverallQualityID = ITEM_QUALITY_ARTIFACT;
+ t.ExtendedData = itemSparse;
+
+ return t;
+}
+
+/*static*/ void UnitTestDataLoader::SetItemLocale(uint32 id, LocaleConstant locale, std::string_view name)
+{
+ ItemTemplate& t = sObjectMgr->_itemTemplateStore[id];
+ const_cast<ItemSparseEntry*>(t.ExtendedData)->Display.Str[locale] = name.data();
+}
+
+/*static*/ void UnitTestDataLoader::LoadItemTemplates()
+{
+ if (!sObjectMgr->_itemTemplateStore.empty())
+ return;
+
+ ItemTemplate& t = GetItemTemplate(6948, "Hearthstone");
+ const_cast<ItemSparseEntry*>(t.ExtendedData)->OverallQualityID = ITEM_QUALITY_NORMAL;
+ SetItemLocale(6948, LOCALE_esMX, "Piedra de hogar");
+}
diff --git a/tests/DummyData.h b/tests/DummyData.h
new file mode 100644
index 00000000000..98812d3b6b8
--- /dev/null
+++ b/tests/DummyData.h
@@ -0,0 +1,38 @@
+/*
+ * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TRINITY_DUMMYDATA_H
+#define TRINITY_DUMMYDATA_H
+
+#include "Common.h"
+#include "Define.h"
+
+#include <string_view>
+
+struct ItemTemplate;
+
+class UnitTestDataLoader
+{
+ public:
+ static void LoadItemTemplates();
+
+ private:
+ static ItemTemplate& GetItemTemplate(uint32 id, std::string_view name);
+ static void SetItemLocale(uint32 id, LocaleConstant locale, std::string_view name);
+};
+
+#endif
diff --git a/tests/game/Hyperlinks.cpp b/tests/game/Hyperlinks.cpp
index ff9062af905..7a1c3821a2c 100644
--- a/tests/game/Hyperlinks.cpp
+++ b/tests/game/Hyperlinks.cpp
@@ -17,23 +17,58 @@
#include "tc_catch2.h"
+#include "DummyData.h"
#include "Hyperlinks.h"
-#include "ChatCommand.h"
+#include "World.h"
using namespace std::string_view_literals;
using namespace Trinity::Hyperlinks;
TEST_CASE("Basic link structure", "[Hyperlinks]")
{
- HyperlinkInfo info = ParseSingleHyperlink("|c12345678|Htag:data1:data2:data3:data4:data5|h[Text]|h|rtail");
- REQUIRE(info.ok);
- REQUIRE(info.color == 0x12345678);
- REQUIRE(info.color.a == 0x12);
- REQUIRE(info.color.r == 0x34);
- REQUIRE(info.color.g == 0x56);
- REQUIRE(info.color.b == 0x78);
- REQUIRE(info.tag == "tag");
- REQUIRE(info.data == "data1:data2:data3:data4:data5");
- REQUIRE(info.text == "Text");
- REQUIRE(info.tail == "tail");
+ SECTION("Link without data")
+ {
+ HyperlinkInfo info = ParseSingleHyperlink("|cabcdef01|HTag|h[text]|h|r");
+ REQUIRE(info.ok);
+ REQUIRE(info.color == 0xabcdef01);
+ REQUIRE(info.color.a == 0xab);
+ REQUIRE(info.color.r == 0xcd);
+ REQUIRE(info.color.g == 0xef);
+ REQUIRE(info.color.b == 0x01);
+ REQUIRE(info.tag == "Tag");
+ REQUIRE(info.data == "");
+ REQUIRE(info.text == "text");
+ REQUIRE(info.tail == "");
+ }
+ SECTION("Link with data")
+ {
+ HyperlinkInfo info = ParseSingleHyperlink("|c12345678|Htag:data1:data2:data3:data4:data5|h[Text]|h|rtail");
+ REQUIRE(info.ok);
+ REQUIRE(info.color == 0x12345678);
+ REQUIRE(info.color.a == 0x12);
+ REQUIRE(info.color.r == 0x34);
+ REQUIRE(info.color.g == 0x56);
+ REQUIRE(info.color.b == 0x78);
+ REQUIRE(info.tag == "tag");
+ REQUIRE(info.data == "data1:data2:data3:data4:data5");
+ REQUIRE(info.text == "Text");
+ REQUIRE(info.tail == "tail");
+ }
+}
+
+TEST_CASE("|Hitem validation", "[Hyperlinks]")
+{
+ UnitTestDataLoader::LoadItemTemplates();
+ sWorld->setIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_SEVERITY, 1);
+
+ SECTION("Basic item link")
+ {
+ REQUIRE(true == CheckAllLinks("This is my |cffffffff|Hitem:6948::::::::60:::::|h[Hearthstone]|h|r. There are many like it, but this one is mine."));
+ REQUIRE(true == CheckAllLinks("Some might call it their |cffffffff|Hitem:6948::::::::60:::::|h[Piedra de hogar]|h|r. They all still take you home."));
+ REQUIRE(false == CheckAllLinks("However, if you call it a |cffffffff|Hitem:6948::::::::60:::::|h|h[Doormat]|h|r, that's a step too far. Get it? Step?"));
+ REQUIRE(false == CheckAllLinks("Or if you try to pronounce |cffffffff|Hitem::::::::::::::|h|h[Cthulhu fhtagn]|h|r. Also too far."));
+ REQUIRE(false == CheckAllLinks("I'm out of witty one-liners. |cffffffff|Hitem|h[This]|h|r is just lacking data."));
+ REQUIRE(false == CheckAllLinks("This is a mis-colored |cffa335ee|Hitem:6948::::::::60:::::|h[Hearthstone]|h|r."));
+ REQUIRE(false == CheckAllLinks("This is a |cffffffff|Hitem:6948:-1:::::::60:::::|h[Hearthstone]|h|r that is quite negative."));
+ }
}