From bb6ed86ea700ac4aa79b99aeae04c418ad79a772 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 24 Jun 2016 18:41:52 +0300 Subject: Add dye unit tests based on real dyed images. --- data/test/CMakeLists.txt | 4 ++ data/test/Makefile.am | 4 ++ data/test/arrow_up.png | Bin 0 -> 234 bytes data/test/arrow_up_A.png | Bin 0 -> 199 bytes data/test/arrow_up_B.png | Bin 0 -> 209 bytes data/test/arrow_up_S.png | Bin 0 -> 196 bytes src/resources/dye/dye_unittest.cc | 93 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 101 insertions(+) create mode 100644 data/test/arrow_up.png create mode 100644 data/test/arrow_up_A.png create mode 100644 data/test/arrow_up_B.png create mode 100644 data/test/arrow_up_S.png 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 Binary files /dev/null and b/data/test/arrow_up.png differ diff --git a/data/test/arrow_up_A.png b/data/test/arrow_up_A.png new file mode 100644 index 000000000..e156f4c9c Binary files /dev/null and b/data/test/arrow_up_A.png differ diff --git a/data/test/arrow_up_B.png b/data/test/arrow_up_B.png new file mode 100644 index 000000000..e034b13d0 Binary files /dev/null and b/data/test/arrow_up_B.png differ diff --git a/data/test/arrow_up_S.png b/data/test/arrow_up_S.png new file mode 100644 index 000000000..56beae480 Binary files /dev/null and b/data/test/arrow_up_S.png 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 +#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( + surface1->pixels); + const uint32_t *const ptr2 = static_cast( + 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"); + } +} -- cgit v1.2.3-60-g2f50