summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-03-29 17:10:58 +0300
committerAndrei Karas <akaras@inbox.ru>2016-03-29 19:24:47 +0300
commitf92c6c4807c44426b64747e047a3db9791810875 (patch)
treec48c64c8ea1e132fbce93d5a554d3bfe8e32b56b
parentc963418a6a073f4d69a818f5f763133b0c4d44d5 (diff)
downloadplus-f92c6c4807c44426b64747e047a3db9791810875.tar.gz
plus-f92c6c4807c44426b64747e047a3db9791810875.tar.bz2
plus-f92c6c4807c44426b64747e047a3db9791810875.tar.xz
plus-f92c6c4807c44426b64747e047a3db9791810875.zip
Add tests for chatutils.
-rw-r--r--src/Makefile.am1
-rw-r--r--src/actormanager.h2
-rw-r--r--src/utils/chatutils_unittest.cc209
3 files changed, 212 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2431c6b0f..5cd693930 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1762,6 +1762,7 @@ manaplustests_SOURCES = ${manaplus_SOURCES} \
resources/dye/dye_unittest.cc \
resources/dye/dyepalette_unittest.cc \
integrity_unittest.cc \
+ utils/chatutils_unittest.cc \
gui/windowmanager_unittest.cc
endif
diff --git a/src/actormanager.h b/src/actormanager.h
index 9c6672bbf..7ab4b1d67 100644
--- a/src/actormanager.h
+++ b/src/actormanager.h
@@ -385,7 +385,9 @@ class ActorManager final: public ConfigListener
const std::string &name);
#endif
+#ifndef UNITTESTS
protected:
+#endif
bool validateBeing(const Being *const aroundBeing,
Being *const being,
const ActorTypeT &type,
diff --git a/src/utils/chatutils_unittest.cc b/src/utils/chatutils_unittest.cc
new file mode 100644
index 000000000..31889b76c
--- /dev/null
+++ b/src/utils/chatutils_unittest.cc
@@ -0,0 +1,209 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2016 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * 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
+ * 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 "catch.hpp"
+
+#include "actormanager.h"
+#include "party.h"
+
+#include "being/localplayer.h"
+
+#include "utils/chatutils.h"
+#include "utils/delete2.h"
+
+#include "debug.h"
+
+TEST_CASE("chatutils replaceVars")
+{
+ localPlayer = new LocalPlayer(static_cast<BeingId>(1),
+ BeingTypeId_zero);
+ actorManager = new ActorManager;
+ std::string str;
+
+ SECTION("empty")
+ {
+ replaceVars(str);
+ REQUIRE(str == "");
+
+ str = "test line";
+ replaceVars(str);
+ REQUIRE(str == "test line");
+
+ str = "test <PLAYER>";
+ replaceVars(str);
+ REQUIRE(str == "test ");
+
+ str = "test <MONSTER>";
+ replaceVars(str);
+ REQUIRE(str == "test ");
+
+ str = "test <PEOPLE>";
+ replaceVars(str);
+ REQUIRE(str == "test ");
+
+ str = "test <PARTY>";
+ replaceVars(str);
+ REQUIRE(str == "test ");
+
+ str = "test <SOMETHING>";
+ replaceVars(str);
+ REQUIRE(str == "test <SOMETHING>");
+
+ delete2(localPlayer);
+ }
+
+ SECTION("player")
+ {
+ Being *player1 = new Being(static_cast<BeingId>(2),
+ ActorType::Player,
+ BeingTypeId_zero,
+ nullptr);
+ player1->setName("player1");
+ actorManager->mActors.insert(player1);
+
+ localPlayer->setTarget(player1);
+ str = "test <PLAYER>";
+ replaceVars(str);
+ REQUIRE(str == "test player1");
+
+ delete2(localPlayer);
+ }
+
+ SECTION("monster")
+ {
+ Being *monster = new Being(static_cast<BeingId>(3),
+ ActorType::Monster,
+ BeingTypeId_zero,
+ nullptr);
+ monster->setName("monster1");
+ actorManager->mActors.insert(monster);
+
+ localPlayer->setTarget(monster);
+ str = "test <MONSTER>";
+ replaceVars(str);
+ REQUIRE(str == "test monster1");
+
+ delete2(localPlayer);
+ }
+
+ SECTION("people")
+ {
+ actorManager->mActors.insert(localPlayer);
+ str = "test <PEOPLE>";
+ replaceVars(str);
+ REQUIRE(str == "test ");
+
+ Being *player1 = new Being(static_cast<BeingId>(2),
+ ActorType::Player,
+ BeingTypeId_zero,
+ nullptr);
+ player1->setName("player1");
+ actorManager->mActors.insert(player1);
+
+ str = "test <PEOPLE>";
+ replaceVars(str);
+ REQUIRE(str == "test player1");
+
+ Being *player2 = new Being(static_cast<BeingId>(4),
+ ActorType::Player,
+ BeingTypeId_zero,
+ nullptr);
+ player2->setName("player2");
+ actorManager->mActors.insert(player2);
+
+ str = "test <PEOPLE>";
+ replaceVars(str);
+ const bool correct = str == "test player1,player2" ||
+ str == "test player2,player1";
+ REQUIRE(correct == true);
+ }
+
+ SECTION("party")
+ {
+ actorManager->mActors.insert(localPlayer);
+
+ Party *party1 = Party::getParty(1);
+ localPlayer->setParty(party1);
+
+ str = "test <PARTY>";
+ replaceVars(str);
+ REQUIRE(str == "test ");
+
+ Being *player1 = new Being(static_cast<BeingId>(2),
+ ActorType::Player,
+ BeingTypeId_zero,
+ nullptr);
+ player1->setName("player1");
+ actorManager->mActors.insert(player1);
+ player1->setParty(party1);
+
+ str = "test <PARTY>";
+ replaceVars(str);
+ REQUIRE(str == "test player1");
+
+ Being *player2 = new Being(static_cast<BeingId>(4),
+ ActorType::Player,
+ BeingTypeId_zero,
+ nullptr);
+ player2->setName("player2");
+ actorManager->mActors.insert(player2);
+ player2->setParty(party1);
+
+ str = "test <PARTY>";
+ replaceVars(str);
+ REQUIRE(str == "test player1,player2");
+
+ Party *party2 = Party::getParty(2);
+
+ Being *player3 = new Being(static_cast<BeingId>(5),
+ ActorType::Player,
+ BeingTypeId_zero,
+ nullptr);
+ player3->setName("player3");
+ actorManager->mActors.insert(player3);
+ player3->setParty(party2);
+
+ str = "test <PARTY>";
+ replaceVars(str);
+ REQUIRE(str == "test player1,player2");
+
+ player3->setParty(party1);
+
+ str = "test <PARTY>";
+ replaceVars(str);
+ REQUIRE(str == "test player1,player2,player3");
+
+ player2->setParty(party2);
+
+ str = "test <PARTY>";
+ replaceVars(str);
+ REQUIRE(str == "test player1,player3");
+ }
+
+ delete2(actorManager);
+}
+
+TEST_CASE("chatutils textToMe")
+{
+ REQUIRE(textToMe("") == "**");
+ REQUIRE(textToMe("123") == "*123*");
+ REQUIRE(textToMe("*") == "***");
+ REQUIRE(textToMe("test line") == "*test line*");
+}