summaryrefslogtreecommitdiff
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
parent7ba370f2311ab2e36aa00408e5cfae4c25aa0bca (diff)
downloadmv-a84d3ab5f4335ce610a29503e1709bc42faa0bc1.tar.gz
mv-a84d3ab5f4335ce610a29503e1709bc42faa0bc1.tar.bz2
mv-a84d3ab5f4335ce610a29503e1709bc42faa0bc1.tar.xz
mv-a84d3ab5f4335ce610a29503e1709bc42faa0bc1.zip
Add unit tests for dyepalette.
-rwxr-xr-xconfigure.ac1
-rw-r--r--data/test/CMakeLists.txt5
-rw-r--r--data/test/Makefile.am8
-rw-r--r--data/test/palette.gpl12
-rw-r--r--src/Makefile.am1
-rw-r--r--src/resources/dye/dyepalette.h3
-rw-r--r--src/resources/dye/dyepalette_unittest.cc192
7 files changed, 221 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index a27b69c19..5572ff9c5 100755
--- a/configure.ac
+++ b/configure.ac
@@ -442,6 +442,7 @@ data/graphics/shaders/Makefile
data/graphics/sprites/Makefile
data/sfx/Makefile
data/sfx/system/Makefile
+data/test/Makefile
data/themes/Makefile
data/themes/blacknblack/Makefile
data/themes/blackwood/Makefile
diff --git a/data/test/CMakeLists.txt b/data/test/CMakeLists.txt
new file mode 100644
index 000000000..83bbb8d5d
--- /dev/null
+++ b/data/test/CMakeLists.txt
@@ -0,0 +1,5 @@
+SET(FILES
+ palette.gpl
+ )
+
+INSTALL(FILES ${FILES} DESTINATION ${DATA_DIR}/test)
diff --git a/data/test/Makefile.am b/data/test/Makefile.am
new file mode 100644
index 000000000..904b30852
--- /dev/null
+++ b/data/test/Makefile.am
@@ -0,0 +1,8 @@
+testdir = $(pkgdatadir)/data/test
+
+test_DATA = \
+ palette.gpl
+
+EXTRA_DIST = \
+ $(test_DATA) \
+ CMakeLists.txt
diff --git a/data/test/palette.gpl b/data/test/palette.gpl
new file mode 100644
index 000000000..1e78d48e3
--- /dev/null
+++ b/data/test/palette.gpl
@@ -0,0 +1,12 @@
+GIMP Palette
+Name: Iron
+Columns: 5
+#
+ 47 56 46 Untitled1
+ 72 80 79 Untitled2
+ 91 108 107 Untitled3
+125 141 138 Untitled4
+146 157 157 Untitled5
+255 0 0 Untitled6
+0 255 0 Untitled7
+0 0 255 Untitled8
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);
+ }
+}