summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-06-24 18:41:52 +0300
committerAndrei Karas <akaras@inbox.ru>2016-06-24 19:07:50 +0300
commitbb6ed86ea700ac4aa79b99aeae04c418ad79a772 (patch)
tree9edd1f492f6a6565aaf55e5e537247948e427e81
parent26c14c26a425f0a4ddad526ebbddf4f3e3ff449d (diff)
downloadmv-bb6ed86ea700ac4aa79b99aeae04c418ad79a772.tar.gz
mv-bb6ed86ea700ac4aa79b99aeae04c418ad79a772.tar.bz2
mv-bb6ed86ea700ac4aa79b99aeae04c418ad79a772.tar.xz
mv-bb6ed86ea700ac4aa79b99aeae04c418ad79a772.zip
Add dye unit tests based on real dyed images.
-rw-r--r--data/test/CMakeLists.txt4
-rw-r--r--data/test/Makefile.am4
-rw-r--r--data/test/arrow_up.pngbin0 -> 234 bytes
-rw-r--r--data/test/arrow_up_A.pngbin0 -> 199 bytes
-rw-r--r--data/test/arrow_up_B.pngbin0 -> 209 bytes
-rw-r--r--data/test/arrow_up_S.pngbin0 -> 196 bytes
-rw-r--r--src/resources/dye/dye_unittest.cc93
7 files changed, 101 insertions, 0 deletions
diff --git a/data/test/CMakeLists.txt b/data/test/CMakeLists.txt
index 0cf52c800..1c98ea1d6 100644
--- a/data/test/CMakeLists.txt
+++ b/data/test/CMakeLists.txt
@@ -1,4 +1,8 @@
SET(FILES
+ arrow_up.png
+ arrow_up_A.png
+ arrow_up_B.png
+ arrow_up_S.png
palette.gpl
serverlistplus.xml
simplefile.txt
diff --git a/data/test/Makefile.am b/data/test/Makefile.am
index d019b948a..1f17ebca2 100644
--- a/data/test/Makefile.am
+++ b/data/test/Makefile.am
@@ -1,6 +1,10 @@
testdir = $(pkgdatadir)/data/test
test_DATA = \
+ arrow_up.png \
+ arrow_up_A.png \
+ arrow_up_B.png \
+ arrow_up_S.png \
palette.gpl \
serverlistplus.xml \
simplefile.txt
diff --git a/data/test/arrow_up.png b/data/test/arrow_up.png
new file mode 100644
index 000000000..f6158b2ae
--- /dev/null
+++ b/data/test/arrow_up.png
Binary files differ
diff --git a/data/test/arrow_up_A.png b/data/test/arrow_up_A.png
new file mode 100644
index 000000000..e156f4c9c
--- /dev/null
+++ b/data/test/arrow_up_A.png
Binary files differ
diff --git a/data/test/arrow_up_B.png b/data/test/arrow_up_B.png
new file mode 100644
index 000000000..e034b13d0
--- /dev/null
+++ b/data/test/arrow_up_B.png
Binary files differ
diff --git a/data/test/arrow_up_S.png b/data/test/arrow_up_S.png
new file mode 100644
index 000000000..56beae480
--- /dev/null
+++ b/data/test/arrow_up_S.png
Binary files differ
diff --git a/src/resources/dye/dye_unittest.cc b/src/resources/dye/dye_unittest.cc
index 4786141a6..074854d32 100644
--- a/src/resources/dye/dye_unittest.cc
+++ b/src/resources/dye/dye_unittest.cc
@@ -20,9 +20,31 @@
#include "catch.hpp"
+#include "client.h"
+#include "graphicsmanager.h"
+#include "logger.h"
+
+#include "resources/sdlimagehelper.h"
+#ifdef USE_SDL2
+#include "resources/surfaceimagehelper.h"
+#endif // USE_SDL2
+
#include "resources/dye/dye.h"
#include "resources/dye/dyepalette.h"
+#include "resources/image/image.h"
+
+#include "resources/loaders/imageloader.h"
+
+#include "resources/resourcemanager/resourcemanager.h"
+
+#include "utils/env.h"
+#include "utils/physfstools.h"
+
+#ifndef USE_SDL2
+#include <SDL.h>
+#endif // USE_SDL2
+
#include "debug.h"
TEST_CASE("Dye replaceSOGLColor 1")
@@ -252,3 +274,74 @@ TEST_CASE("Dye normalOGLDye 1")
REQUIRE(0x2a == data[2]);
REQUIRE(0x50 == data[3]);
}
+
+static void dyeCheck(const std::string &dyeString,
+ const std::string &dstName)
+{
+ const std::string srcName = "arrow_up.png";
+
+ Image *const image1 = Loader::getImage(srcName + dyeString);
+ Image *const image2 = Loader::getImage(dstName);
+ REQUIRE(image1 != nullptr);
+ REQUIRE(image2 != nullptr);
+ SDL_Surface *const surface1 = image1->getSDLSurface();
+ SDL_Surface *const surface2 = image2->getSDLSurface();
+ REQUIRE(surface1 != nullptr);
+ REQUIRE(surface2 != nullptr);
+ REQUIRE(surface1->w == surface2->w);
+ REQUIRE(surface1->h == surface2->h);
+ REQUIRE(surface1->pixels != nullptr);
+ REQUIRE(surface2->pixels != nullptr);
+ const uint32_t *const ptr1 = static_cast<const uint32_t *>(
+ surface1->pixels);
+ const uint32_t *const ptr2 = static_cast<const uint32_t *>(
+ surface2->pixels);
+ const size_t sz = surface1->w * surface1->h;
+ for (size_t idx = 0; idx < sz; idx ++)
+ {
+ REQUIRE(ptr1[idx] == ptr2[idx]);
+ }
+}
+
+TEST_CASE("Dye real dye")
+{
+ setEnv("SDL_VIDEODRIVER", "dummy");
+
+ client = new Client;
+ PHYSFS_init("manaplus");
+ dirSeparator = "/";
+ SDL_Init(SDL_INIT_VIDEO);
+ logger = new Logger();
+ ResourceManager::init();
+ resourceManager->addToSearchPath("data/test", Append_false);
+ resourceManager->addToSearchPath("../data/test", Append_false);
+
+#ifdef USE_SDL2
+ imageHelper = new SurfaceImageHelper;
+#else
+ imageHelper = new SDLImageHelper;
+#endif
+
+#ifdef USE_SDL2
+ SDLImageHelper::setRenderer(graphicsManager.createRenderer(
+ graphicsManager.createWindow(640, 480, 0,
+ SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
+#else
+ graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
+#endif
+
+ SECTION("B dye")
+ {
+ dyeCheck("|B:#FFC88A", "arrow_up_B.png");
+ }
+
+ SECTION("S dye")
+ {
+ dyeCheck("|S:#0000FF,FF0000", "arrow_up_S.png");
+ }
+
+ SECTION("A dye")
+ {
+ dyeCheck("|A:#0000FFFF,FF000050", "arrow_up_A.png");
+ }
+}