summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-01-12 03:36:28 +0300
committerAndrei Karas <akaras@inbox.ru>2016-01-12 03:39:04 +0300
commita84d3ab5f4335ce610a29503e1709bc42faa0bc1 (patch)
tree17888b14d39750ac3c6546c536c48a804c391e2c /src
parent7ba370f2311ab2e36aa00408e5cfae4c25aa0bca (diff)
downloadmv-a84d3ab5f4335ce610a29503e1709bc42faa0bc1.tar.gz
mv-a84d3ab5f4335ce610a29503e1709bc42faa0bc1.tar.bz2
mv-a84d3ab5f4335ce610a29503e1709bc42faa0bc1.tar.xz
mv-a84d3ab5f4335ce610a29503e1709bc42faa0bc1.zip
Add unit tests for dyepalette.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/resources/dye/dyepalette.h3
-rw-r--r--src/resources/dye/dyepalette_unittest.cc192
3 files changed, 195 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 1076f577f..13aa6eb44 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1705,6 +1705,7 @@ manaplustests_SOURCES = ${manaplus_SOURCES} \
utils/xmlutils_unittest.cc \
utils/translation/poparser_unittest.cc \
resources/dye/dye_unittest.cc \
+ resources/dye/dyepalette_unittest.cc \
resources/mstack_unittest.cc
endif
diff --git a/src/resources/dye/dyepalette.h b/src/resources/dye/dyepalette.h
index 7c607bb8f..d27fba095 100644
--- a/src/resources/dye/dyepalette.h
+++ b/src/resources/dye/dyepalette.h
@@ -85,8 +85,9 @@ class DyePalette final
static unsigned int hexDecode(const signed char c)
A_CONST A_WARN_UNUSED;
-
+#ifndef UNITTESTS
private:
+#endif
std::vector<DyeColor> mColors;
};
diff --git a/src/resources/dye/dyepalette_unittest.cc b/src/resources/dye/dyepalette_unittest.cc
new file mode 100644
index 000000000..348f9124b
--- /dev/null
+++ b/src/resources/dye/dyepalette_unittest.cc
@@ -0,0 +1,192 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013-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 "client.h"
+#include "logger.h"
+
+#include "resources/resourcemanager.h"
+#include "resources/sdlimagehelper.h"
+
+#include "resources/db/palettedb.h"
+
+#include "resources/dye/dyepalette.h"
+
+#include "utils/env.h"
+#include "utils/physfstools.h"
+#include "utils/xml.h"
+
+#include "debug.h"
+
+TEST_CASE("DyePalette tests")
+{
+ setEnv("SDL_VIDEODRIVER", "dummy");
+
+ client = new Client;
+ PHYSFS_init("manaplus");
+ dirSeparator = "/";
+ XML::initXML();
+ SDL_Init(SDL_INIT_VIDEO);
+ logger = new Logger();
+ ResourceManager::init();
+ resourceManager->addToSearchPath("data/test", Append_false);
+ resourceManager->addToSearchPath("../data/test", Append_false);
+
+ imageHelper = new SDLImageHelper();
+ SDL_SetVideoMode(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
+
+ PaletteDB::load();
+
+ SECTION("simple test 1")
+ {
+ DyePalette palette("#12ff34", 6);
+ REQUIRE(palette.mColors.size() == 1);
+ REQUIRE(palette.mColors[0].value[0] == 0x12);
+ REQUIRE(palette.mColors[0].value[1] == 0xff);
+ REQUIRE(palette.mColors[0].value[2] == 0x34);
+ REQUIRE(palette.mColors[0].value[3] == 0x00);
+ }
+
+ SECTION("simple test 2")
+ {
+ DyePalette palette("#12ff3456", 8);
+ REQUIRE(palette.mColors.size() == 1);
+ REQUIRE(palette.mColors[0].value[0] == 0x12);
+ REQUIRE(palette.mColors[0].value[1] == 0xff);
+ REQUIRE(palette.mColors[0].value[2] == 0x34);
+ REQUIRE(palette.mColors[0].value[3] == 0x56);
+ }
+
+ SECTION("simple test 3")
+ {
+ DyePalette palette("#12ff34,002211", 6);
+ REQUIRE(palette.mColors.size() == 2);
+ REQUIRE(palette.mColors[0].value[0] == 0x12);
+ REQUIRE(palette.mColors[0].value[1] == 0xff);
+ REQUIRE(palette.mColors[0].value[2] == 0x34);
+ REQUIRE(palette.mColors[0].value[3] == 0x00);
+
+ REQUIRE(palette.mColors[1].value[0] == 0x00);
+ REQUIRE(palette.mColors[1].value[1] == 0x22);
+ REQUIRE(palette.mColors[1].value[2] == 0x11);
+ REQUIRE(palette.mColors[1].value[3] == 0x00);
+ }
+
+ SECTION("simple test 4")
+ {
+ DyePalette palette("#12ff3412,00221133", 8);
+ REQUIRE(palette.mColors.size() == 2);
+ REQUIRE(palette.mColors[0].value[0] == 0x12);
+ REQUIRE(palette.mColors[0].value[1] == 0xff);
+ REQUIRE(palette.mColors[0].value[2] == 0x34);
+ REQUIRE(palette.mColors[0].value[3] == 0x12);
+
+ REQUIRE(palette.mColors[1].value[0] == 0x00);
+ REQUIRE(palette.mColors[1].value[1] == 0x22);
+ REQUIRE(palette.mColors[1].value[2] == 0x11);
+ REQUIRE(palette.mColors[1].value[3] == 0x33);
+ }
+
+ SECTION("simple test 5")
+ {
+ DyePalette palette("#12ff34,", 6);
+ REQUIRE(palette.mColors.size() == 1);
+ REQUIRE(palette.mColors[0].value[0] == 0x12);
+ REQUIRE(palette.mColors[0].value[1] == 0xff);
+ REQUIRE(palette.mColors[0].value[2] == 0x34);
+ REQUIRE(palette.mColors[0].value[3] == 0x00);
+ }
+
+ SECTION("simple test 6")
+ {
+ DyePalette palette("#12ff3456,", 8);
+ REQUIRE(palette.mColors.size() == 1);
+ REQUIRE(palette.mColors[0].value[0] == 0x12);
+ REQUIRE(palette.mColors[0].value[1] == 0xff);
+ REQUIRE(palette.mColors[0].value[2] == 0x34);
+ REQUIRE(palette.mColors[0].value[3] == 0x56);
+ }
+
+ SECTION("simple test 7")
+ {
+ DyePalette palette("#,,,12ff3412,,00221133", 8);
+ REQUIRE(palette.mColors.size() == 2);
+ REQUIRE(palette.mColors[0].value[0] == 0x12);
+ REQUIRE(palette.mColors[0].value[1] == 0xff);
+ REQUIRE(palette.mColors[0].value[2] == 0x34);
+ REQUIRE(palette.mColors[0].value[3] == 0x12);
+
+ REQUIRE(palette.mColors[1].value[0] == 0x00);
+ REQUIRE(palette.mColors[1].value[1] == 0x22);
+ REQUIRE(palette.mColors[1].value[2] == 0x11);
+ REQUIRE(palette.mColors[1].value[3] == 0x33);
+ }
+
+ SECTION("palette test 1")
+ {
+ DyePalette palette("@Untitled1", 6);
+ REQUIRE(palette.mColors.size() == 1);
+ REQUIRE(palette.mColors[0].value[0] == 47);
+ REQUIRE(palette.mColors[0].value[1] == 56);
+ REQUIRE(palette.mColors[0].value[2] == 46);
+ REQUIRE(palette.mColors[0].value[3] == 255);
+ }
+
+ SECTION("palette test 2")
+ {
+ DyePalette palette("@Untitled1,Untitled8", 6);
+ REQUIRE(palette.mColors.size() == 2);
+ REQUIRE(palette.mColors[0].value[0] == 47);
+ REQUIRE(palette.mColors[0].value[1] == 56);
+ REQUIRE(palette.mColors[0].value[2] == 46);
+ REQUIRE(palette.mColors[0].value[3] == 255);
+
+ REQUIRE(palette.mColors[1].value[0] == 0);
+ REQUIRE(palette.mColors[1].value[1] == 0);
+ REQUIRE(palette.mColors[1].value[2] == 255);
+ REQUIRE(palette.mColors[1].value[3] == 255);
+ }
+
+ SECTION("palette test 3")
+ {
+ DyePalette palette("@Untitled1,", 6);
+ REQUIRE(palette.mColors.size() == 1);
+ REQUIRE(palette.mColors[0].value[0] == 47);
+ REQUIRE(palette.mColors[0].value[1] == 56);
+ REQUIRE(palette.mColors[0].value[2] == 46);
+ REQUIRE(palette.mColors[0].value[3] == 255);
+ }
+
+ SECTION("palette test 4")
+ {
+ DyePalette palette("@,,,Untitled1,,Untitled8", 6);
+ REQUIRE(palette.mColors.size() == 2);
+ REQUIRE(palette.mColors[0].value[0] == 47);
+ REQUIRE(palette.mColors[0].value[1] == 56);
+ REQUIRE(palette.mColors[0].value[2] == 46);
+ REQUIRE(palette.mColors[0].value[3] == 255);
+
+ REQUIRE(palette.mColors[1].value[0] == 0);
+ REQUIRE(palette.mColors[1].value[1] == 0);
+ REQUIRE(palette.mColors[1].value[2] == 255);
+ REQUIRE(palette.mColors[1].value[3] == 255);
+ }
+}