From 6c65b90a95bde4e5cee673f86efc135b92fce624 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 29 Aug 2017 17:25:20 +0300 Subject: Remove _unittest from unit tests file names. --- src/unittests/resources/dye/dye.cc | 2020 ++++++++++++++++++++ src/unittests/resources/dye/dye_unittest.cc | 2020 -------------------- src/unittests/resources/dye/dyepalette.cc | 422 ++++ src/unittests/resources/dye/dyepalette_unittest.cc | 422 ---- src/unittests/resources/map/speciallayer.cc | 291 +++ .../resources/map/speciallayer_unittest.cc | 291 --- src/unittests/resources/mstack.cc | 165 ++ src/unittests/resources/mstack_unittest.cc | 165 -- .../resources/resourcemanager/resourcemanager.cc | 701 +++++++ .../resourcemanager/resourcemanager_unittest.cc | 701 ------- src/unittests/resources/sdlimagehelper.cc | 541 ++++++ src/unittests/resources/sdlimagehelper_unittest.cc | 541 ------ src/unittests/resources/sprite/animatedsprite.cc | 220 +++ .../resources/sprite/animatedsprite_unittest.cc | 220 --- 14 files changed, 4360 insertions(+), 4360 deletions(-) create mode 100644 src/unittests/resources/dye/dye.cc delete mode 100644 src/unittests/resources/dye/dye_unittest.cc create mode 100644 src/unittests/resources/dye/dyepalette.cc delete mode 100644 src/unittests/resources/dye/dyepalette_unittest.cc create mode 100644 src/unittests/resources/map/speciallayer.cc delete mode 100644 src/unittests/resources/map/speciallayer_unittest.cc create mode 100644 src/unittests/resources/mstack.cc delete mode 100644 src/unittests/resources/mstack_unittest.cc create mode 100644 src/unittests/resources/resourcemanager/resourcemanager.cc delete mode 100644 src/unittests/resources/resourcemanager/resourcemanager_unittest.cc create mode 100644 src/unittests/resources/sdlimagehelper.cc delete mode 100644 src/unittests/resources/sdlimagehelper_unittest.cc create mode 100644 src/unittests/resources/sprite/animatedsprite.cc delete mode 100644 src/unittests/resources/sprite/animatedsprite_unittest.cc (limited to 'src/unittests/resources') diff --git a/src/unittests/resources/dye/dye.cc b/src/unittests/resources/dye/dye.cc new file mode 100644 index 000000000..fcdeb7b17 --- /dev/null +++ b/src/unittests/resources/dye/dye.cc @@ -0,0 +1,2020 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013-2017 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 . + */ + +#include "unittests/unittests.h" + +#include "client.h" +#include "graphicsmanager.h" +#include "logger.h" + +#include "being/actorsprite.h" + +#include "fs/virtfs/fs.h" + +#include "gui/gui.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/delete2.h" +#include "utils/env.h" + +PRAGMA48(GCC diagnostic push) +PRAGMA48(GCC diagnostic ignored "-Wshadow") +#ifndef USE_SDL2 +#include +#endif // USE_SDL2 +PRAGMA48(GCC diagnostic pop) + +#include "debug.h" + +#ifdef USE_OPENGL + +TEST_CASE("Dye leak test1", "") +{ + logger = new Logger(); + REQUIRE(gui == nullptr); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); + delete2(logger); +} + +TEST_CASE("Dye replaceSOGLColor 1 1", "") +{ + DyePalette palette("#00ff00,000011", 6); + uint32_t data[1]; + data[0] = buildHex(0x01, 0x02, 0x03, 0x10); + DYEPALETTE(palette, SOGLColor)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x01, 0x02, 0x03, 0x10)); +} + +TEST_CASE("Dye replaceSOGLColor 1 2", "") +{ + DyePalette palette("#01ff02,030411", 6); + uint32_t data[1]; + data[0] = buildHex(0x20, 0x02, 0xff, 0x01); + DYEPALETTE(palette, SOGLColor)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); +} + +TEST_CASE("Dye replaceSOGLColor 1 3", "") +{ + DyePalette palette("#404040,200000,0100ee,102030", 6); + uint32_t data[1]; + data[0] = buildHex(0x40, 0xee, 0x00, 0x01); + DYEPALETTE(palette, SOGLColor)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x40, 0x30, 0x20, 0x10)); +} + +TEST_CASE("Dye replaceSOGLColor 2 1", "") +{ + DyePalette palette("#01ff02,030411", 6); + uint32_t data[2]; + data[0] = buildHex(0x20, 0x02, 0xff, 0x01); + data[1] = buildHex(0x30, 0x02, 0xff, 0x01); + DYEPALETTE(palette, SOGLColor)(&data[0], 2); + REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); + REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); +} + +TEST_CASE("Dye replaceSOGLColor 4 1", "") +{ + DyePalette palette("#01ff02,030411", 6); + uint32_t data[4]; + data[0] = buildHex(0x20, 0x02, 0xff, 0x01); + data[1] = buildHex(0x30, 0x02, 0xff, 0x01); + data[2] = buildHex(0x40, 0x02, 0xff, 0x01); + data[3] = buildHex(0x50, 0x02, 0xff, 0x02); + DYEPALETTE(palette, SOGLColor)(&data[0], 4); + REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); + REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); + REQUIRE(data[2] == buildHex(0x40, 0x11, 0x04, 0x03)); + REQUIRE(data[3] == buildHex(0x50, 0x02, 0xff, 0x02)); +} + +TEST_CASE("Dye replaceSOGLColor 8 1", "") +{ + DyePalette palette("#01ff02,030411,01ee02,010203", 6); + uint32_t data[8]; + data[0] = buildHex(0x20, 0x02, 0xff, 0x01); + data[1] = buildHex(0x30, 0x02, 0xff, 0x01); + data[2] = buildHex(0x40, 0x02, 0xff, 0x01); + data[3] = buildHex(0x50, 0x02, 0xff, 0x02); + data[4] = buildHex(0x20, 0x02, 0xff, 0x01); + data[5] = buildHex(0x30, 0x02, 0xff, 0x01); + data[6] = buildHex(0x40, 0x02, 0xff, 0x01); + data[7] = buildHex(0x60, 0x02, 0xff, 0x02); + DYEPALETTE(palette, SOGLColor)(&data[0], 8); + REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); + REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); + REQUIRE(data[2] == buildHex(0x40, 0x11, 0x04, 0x03)); + REQUIRE(data[3] == buildHex(0x50, 0x02, 0xff, 0x02)); + REQUIRE(data[4] == buildHex(0x20, 0x11, 0x04, 0x03)); + REQUIRE(data[5] == buildHex(0x30, 0x11, 0x04, 0x03)); + REQUIRE(data[6] == buildHex(0x40, 0x11, 0x04, 0x03)); + REQUIRE(data[7] == buildHex(0x60, 0x02, 0xff, 0x02)); +} + +TEST_CASE("Dye replaceSOGLColor 1 1 default", "") +{ + DyePalette palette("#00ff00,000011", 6); + uint32_t data[1]; + data[0] = buildHex(0x01, 0x02, 0x03, 0x10); + palette.replaceSOGLColorDefault(&data[0], 1); + REQUIRE(data[0] == buildHex(0x01, 0x02, 0x03, 0x10)); +} + +TEST_CASE("Dye replaceSOGLColor 1 2 default", "") +{ + DyePalette palette("#01ff02,030411", 6); + uint32_t data[1]; + data[0] = buildHex(0x20, 0x02, 0xff, 0x01); + palette.replaceSOGLColorDefault(&data[0], 1); + REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); +} + +TEST_CASE("Dye replaceSOGLColor 1 3 default", "") +{ + DyePalette palette("#404040,200000,0100ee,102030", 6); + uint32_t data[1]; + data[0] = buildHex(0x40, 0xee, 0x00, 0x01); + palette.replaceSOGLColorDefault(&data[0], 1); + REQUIRE(data[0] == buildHex(0x40, 0x30, 0x20, 0x10)); +} + +TEST_CASE("Dye replaceSOGLColor 2 1 default", "") +{ + DyePalette palette("#01ff02,030411", 6); + uint32_t data[2]; + data[0] = buildHex(0x20, 0x02, 0xff, 0x01); + data[1] = buildHex(0x30, 0x02, 0xff, 0x01); + palette.replaceSOGLColorDefault(&data[0], 2); + REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); + REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); +} + +TEST_CASE("Dye replaceSOGLColor 4 1 default", "") +{ + DyePalette palette("#01ff02,030411", 6); + uint32_t data[4]; + data[0] = buildHex(0x20, 0x02, 0xff, 0x01); + data[1] = buildHex(0x30, 0x02, 0xff, 0x01); + data[2] = buildHex(0x40, 0x02, 0xff, 0x01); + data[3] = buildHex(0x50, 0x02, 0xff, 0x02); + palette.replaceSOGLColorDefault(&data[0], 4); + REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); + REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); + REQUIRE(data[2] == buildHex(0x40, 0x11, 0x04, 0x03)); + REQUIRE(data[3] == buildHex(0x50, 0x02, 0xff, 0x02)); +} + +TEST_CASE("Dye replaceSOGLColor 8 1 default", "") +{ + DyePalette palette("#01ff02,030411,01ee02,010203", 6); + uint32_t data[8]; + data[0] = buildHex(0x20, 0x02, 0xff, 0x01); + data[1] = buildHex(0x30, 0x02, 0xff, 0x01); + data[2] = buildHex(0x40, 0x02, 0xff, 0x01); + data[3] = buildHex(0x50, 0x02, 0xff, 0x02); + data[4] = buildHex(0x20, 0x02, 0xff, 0x01); + data[5] = buildHex(0x30, 0x02, 0xff, 0x01); + data[6] = buildHex(0x40, 0x02, 0xff, 0x01); + data[7] = buildHex(0x60, 0x02, 0xff, 0x02); + palette.replaceSOGLColorDefault(&data[0], 8); + REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); + REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); + REQUIRE(data[2] == buildHex(0x40, 0x11, 0x04, 0x03)); + REQUIRE(data[3] == buildHex(0x50, 0x02, 0xff, 0x02)); + REQUIRE(data[4] == buildHex(0x20, 0x11, 0x04, 0x03)); + REQUIRE(data[5] == buildHex(0x30, 0x11, 0x04, 0x03)); + REQUIRE(data[6] == buildHex(0x40, 0x11, 0x04, 0x03)); + REQUIRE(data[7] == buildHex(0x60, 0x02, 0xff, 0x02)); +} + +TEST_CASE("Dye replaceSOGLColor 8 1 sse2", "") +{ + DyePalette palette("#01ff02,030411,01ee02,010203", 6); + uint32_t data[8]; + data[0] = buildHex(0x20, 0x02, 0xff, 0x01); + data[1] = buildHex(0x30, 0x02, 0xff, 0x01); + data[2] = buildHex(0x40, 0x02, 0xff, 0x01); + data[3] = buildHex(0x50, 0x02, 0xff, 0x02); + data[4] = buildHex(0x20, 0x02, 0xff, 0x01); + data[5] = buildHex(0x30, 0x02, 0xff, 0x01); + data[6] = buildHex(0x40, 0x02, 0xff, 0x01); + data[7] = buildHex(0x60, 0x02, 0xff, 0x02); + DYEPALETTE(palette, SOGLColorSse2)(&data[0], 8); + REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); + REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); + REQUIRE(data[2] == buildHex(0x40, 0x11, 0x04, 0x03)); + REQUIRE(data[3] == buildHex(0x50, 0x02, 0xff, 0x02)); + REQUIRE(data[4] == buildHex(0x20, 0x11, 0x04, 0x03)); + REQUIRE(data[5] == buildHex(0x30, 0x11, 0x04, 0x03)); + REQUIRE(data[6] == buildHex(0x40, 0x11, 0x04, 0x03)); + REQUIRE(data[7] == buildHex(0x60, 0x02, 0xff, 0x02)); +} + +TEST_CASE("Dye replaceSOGLColor 8 1 avx2", "") +{ + DyePalette palette("#01ff02,030411,01ee02,010203", 6); + uint32_t data[8]; + data[0] = buildHex(0x20, 0x02, 0xff, 0x01); + data[1] = buildHex(0x30, 0x02, 0xff, 0x01); + data[2] = buildHex(0x40, 0x02, 0xff, 0x01); + data[3] = buildHex(0x50, 0x02, 0xff, 0x02); + data[4] = buildHex(0x20, 0x02, 0xff, 0x01); + data[5] = buildHex(0x30, 0x02, 0xff, 0x01); + data[6] = buildHex(0x40, 0x02, 0xff, 0x01); + data[7] = buildHex(0x60, 0x02, 0xff, 0x02); + DYEPALETTE(palette, SOGLColorAvx2)(&data[0], 8); + REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); + REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); + REQUIRE(data[2] == buildHex(0x40, 0x11, 0x04, 0x03)); + REQUIRE(data[3] == buildHex(0x50, 0x02, 0xff, 0x02)); + REQUIRE(data[4] == buildHex(0x20, 0x11, 0x04, 0x03)); + REQUIRE(data[5] == buildHex(0x30, 0x11, 0x04, 0x03)); + REQUIRE(data[6] == buildHex(0x40, 0x11, 0x04, 0x03)); + REQUIRE(data[7] == buildHex(0x60, 0x02, 0xff, 0x02)); +} + + +TEST_CASE("Dye replaceAOGLColor 1 1", "") +{ + DyePalette palette("#00ff0010,00001120", 8); + uint32_t data[1]; + data[0] = buildHex(0x10, 0x03, 0x02, 0x01); + DYEPALETTE(palette, AOGLColor)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); +} + +TEST_CASE("Dye replaceAOGLColor 1 2", "") +{ + DyePalette palette("#00ff0120,020311ff", 8); + uint32_t data[1]; + data[0] = buildHex(0x20, 0x01, 0xff, 0x00); + DYEPALETTE(palette, AOGLColor)(&data[0], 1); + REQUIRE(data[0] == buildHex(0xff, 0x11, 0x03, 0x02)); +} + +TEST_CASE("Dye replaceAOGLColor 1 3", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[1]; + data[0] = buildHex(0x40, 0xee, 0x00, 0x01); + DYEPALETTE(palette, AOGLColor)(&data[0], 1); + REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); +} + +TEST_CASE("Dye replaceAOGLColor 2 1", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[2]; + data[0] = buildHex(0x40, 0xee, 0x00, 0x01); + data[1] = buildHex(0x40, 0xee, 0x00, 0x01); + DYEPALETTE(palette, AOGLColor)(&data[0], 2); + REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); +} + +TEST_CASE("Dye replaceAOGLColor 4 1", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[4]; + data[0] = buildHex(0x40, 0xee, 0x00, 0x01); + data[1] = buildHex(0x40, 0xee, 0x00, 0x01); + data[2] = buildHex(0x41, 0xee, 0x00, 0x01); + data[3] = buildHex(0x40, 0xee, 0x00, 0x01); + DYEPALETTE(palette, AOGLColor)(&data[0], 4); + REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[2] == buildHex(0x41, 0xee, 0x00, 0x01)); + REQUIRE(data[3] == buildHex(0xff, 0x30, 0x20, 0x10)); +} + +TEST_CASE("Dye replaceAOGLColor 8 1", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[8]; + data[0] = buildHex(0x40, 0xee, 0x00, 0x01); + data[1] = buildHex(0x40, 0xee, 0x00, 0x01); + data[2] = buildHex(0x41, 0xee, 0x00, 0x01); + data[3] = buildHex(0x40, 0xee, 0x00, 0x01); + data[4] = buildHex(0x40, 0xee, 0x00, 0x01); + data[5] = buildHex(0x40, 0x40, 0x40, 0x40); + data[6] = buildHex(0x41, 0xe0, 0x00, 0x01); + data[7] = buildHex(0x40, 0xee, 0x00, 0x01); + DYEPALETTE(palette, AOGLColor)(&data[0], 8); + REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[2] == buildHex(0x41, 0xee, 0x00, 0x01)); + REQUIRE(data[3] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[4] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[5] == buildHex(0x00, 0x00, 0x00, 0x20)); + REQUIRE(data[6] == buildHex(0x41, 0xe0, 0x00, 0x01)); + REQUIRE(data[7] == buildHex(0xff, 0x30, 0x20, 0x10)); +} + +TEST_CASE("Dye replaceAOGLColor 1 1 default", "") +{ + DyePalette palette("#00ff0010,00001120", 8); + uint32_t data[1]; + data[0] = buildHex(0x10, 0x03, 0x02, 0x01); + palette.replaceAOGLColorDefault(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); +} + +TEST_CASE("Dye replaceAOGLColor 1 2 default", "") +{ + DyePalette palette("#00ff0120,020311ff", 8); + uint32_t data[1]; + data[0] = buildHex(0x20, 0x01, 0xff, 0x00); + palette.replaceAOGLColorDefault(&data[0], 1); + REQUIRE(data[0] == buildHex(0xff, 0x11, 0x03, 0x02)); +} + +TEST_CASE("Dye replaceAOGLColor 1 3 default", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[1]; + data[0] = buildHex(0x40, 0xee, 0x00, 0x01); + palette.replaceAOGLColorDefault(&data[0], 1); + REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); +} + +TEST_CASE("Dye replaceAOGLColor 2 1 default", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[2]; + data[0] = buildHex(0x40, 0xee, 0x00, 0x01); + data[1] = buildHex(0x40, 0xee, 0x00, 0x01); + palette.replaceAOGLColorDefault(&data[0], 2); + REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); +} + +TEST_CASE("Dye replaceAOGLColor 4 1 default", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[4]; + data[0] = buildHex(0x40, 0xee, 0x00, 0x01); + data[1] = buildHex(0x40, 0xee, 0x00, 0x01); + data[2] = buildHex(0x41, 0xee, 0x00, 0x01); + data[3] = buildHex(0x40, 0xee, 0x00, 0x01); + palette.replaceAOGLColorDefault(&data[0], 4); + REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[2] == buildHex(0x41, 0xee, 0x00, 0x01)); + REQUIRE(data[3] == buildHex(0xff, 0x30, 0x20, 0x10)); +} + +TEST_CASE("Dye replaceAOGLColor 8 1 default", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[8]; + data[0] = buildHex(0x40, 0xee, 0x00, 0x01); + data[1] = buildHex(0x40, 0xee, 0x00, 0x01); + data[2] = buildHex(0x41, 0xee, 0x00, 0x01); + data[3] = buildHex(0x40, 0xee, 0x00, 0x01); + data[4] = buildHex(0x40, 0xee, 0x00, 0x01); + data[5] = buildHex(0x40, 0x40, 0x40, 0x40); + data[6] = buildHex(0x41, 0xe0, 0x00, 0x01); + data[7] = buildHex(0x40, 0xee, 0x00, 0x01); + palette.replaceAOGLColorDefault(&data[0], 8); + REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[2] == buildHex(0x41, 0xee, 0x00, 0x01)); + REQUIRE(data[3] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[4] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[5] == buildHex(0x00, 0x00, 0x00, 0x20)); + REQUIRE(data[6] == buildHex(0x41, 0xe0, 0x00, 0x01)); + REQUIRE(data[7] == buildHex(0xff, 0x30, 0x20, 0x10)); +} + +TEST_CASE("Dye replaceAOGLColor 8 1 sse2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[8]; + data[0] = buildHex(0x40, 0xee, 0x00, 0x01); + data[1] = buildHex(0x40, 0xee, 0x00, 0x01); + data[2] = buildHex(0x41, 0xee, 0x00, 0x01); + data[3] = buildHex(0x40, 0xee, 0x00, 0x01); + data[4] = buildHex(0x40, 0xee, 0x00, 0x01); + data[5] = buildHex(0x40, 0x40, 0x40, 0x40); + data[6] = buildHex(0x41, 0xe0, 0x00, 0x01); + data[7] = buildHex(0x40, 0xee, 0x00, 0x01); + DYEPALETTE(palette, AOGLColorSse2)(&data[0], 8); + REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[2] == buildHex(0x41, 0xee, 0x00, 0x01)); + REQUIRE(data[3] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[4] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[5] == buildHex(0x00, 0x00, 0x00, 0x20)); + REQUIRE(data[6] == buildHex(0x41, 0xe0, 0x00, 0x01)); + REQUIRE(data[7] == buildHex(0xff, 0x30, 0x20, 0x10)); +} + +TEST_CASE("Dye replaceAOGLColor 8 1 avx2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[8]; + data[0] = buildHex(0x40, 0xee, 0x00, 0x01); + data[1] = buildHex(0x40, 0xee, 0x00, 0x01); + data[2] = buildHex(0x41, 0xee, 0x00, 0x01); + data[3] = buildHex(0x40, 0xee, 0x00, 0x01); + data[4] = buildHex(0x40, 0xee, 0x00, 0x01); + data[5] = buildHex(0x40, 0x40, 0x40, 0x40); + data[6] = buildHex(0x41, 0xe0, 0x00, 0x01); + data[7] = buildHex(0x40, 0xee, 0x00, 0x01); + DYEPALETTE(palette, AOGLColorAvx2)(&data[0], 8); + REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[2] == buildHex(0x41, 0xee, 0x00, 0x01)); + REQUIRE(data[3] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[4] == buildHex(0xff, 0x30, 0x20, 0x10)); + REQUIRE(data[5] == buildHex(0x00, 0x00, 0x00, 0x20)); + REQUIRE(data[6] == buildHex(0x41, 0xe0, 0x00, 0x01)); + REQUIRE(data[7] == buildHex(0xff, 0x30, 0x20, 0x10)); +} +#endif // USE_OPENGL + + +TEST_CASE("Dye replaceSColor 1 1", "") +{ + DyePalette palette("#00ff00,000011", 6); + uint32_t data[1]; + data[0] = buildHex(0x10, 0x03, 0x02, 0x01); + DYEPALETTE(palette, SColor)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); +} + +TEST_CASE("Dye replaceSColor 1 2", "") +{ + DyePalette palette("#403020,706050", 6); + uint32_t data[1]; + data[0] = buildHex(0x40, 0x30, 0x20, 0x10); + DYEPALETTE(palette, SColor)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); +} + +TEST_CASE("Dye replaceSColor 1 3", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[1]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + DYEPALETTE(palette, SColor)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); +} + +TEST_CASE("Dye replaceSColor 2 1", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[2]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + DYEPALETTE(palette, SColor)(&data[0], 2); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); +} + +TEST_CASE("Dye replaceSColor 3 1", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[3]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x30, 0x20, 0x30); + DYEPALETTE(palette, SColor)(&data[0], 3); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0x70, 0x60, 0x50, 0x30)); +} + +TEST_CASE("Dye replaceSColor 4 1", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[4]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + DYEPALETTE(palette, SColor)(&data[0], 4); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); +} + +TEST_CASE("Dye replaceSColor 5 1", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[5]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x30); + data[4] = buildHex(0xff, 0x30, 0x20, 0x20); + DYEPALETTE(palette, SColor)(&data[0], 5); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x30)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x20)); +} + +TEST_CASE("Dye replaceSColor 7 1", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[7]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + DYEPALETTE(palette, SColor)(&data[0], 7); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); +} + +TEST_CASE("Dye replaceSColor 8 1", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[8]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + data[7] = buildHex(0xff, 0x30, 0x20, 0x60); + DYEPALETTE(palette, SColor)(&data[0], 8); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); + REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); +} + +TEST_CASE("Dye replaceSColor 9 1", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[9]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + data[7] = buildHex(0xff, 0x30, 0x20, 0x60); + data[8] = buildHex(0xff, 0x30, 0x20, 0x70); + DYEPALETTE(palette, SColor)(&data[0], 9); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); + REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); + REQUIRE(data[8] == buildHex(0x70, 0x60, 0x50, 0x70)); +} + +TEST_CASE("Dye replaceSColor 10 1", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[10]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + data[7] = buildHex(0xff, 0x30, 0x20, 0x60); + data[8] = buildHex(0x12, 0x34, 0x56, 0x70); + data[9] = buildHex(0xff, 0x30, 0x20, 0x80); + DYEPALETTE(palette, SColor)(&data[0], 10); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); + REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); + REQUIRE(data[8] == buildHex(0x00, 0x00, 0x00, 0x70)); + REQUIRE(data[9] == buildHex(0x70, 0x60, 0x50, 0x80)); +} + +TEST_CASE("Dye replaceSColor 1 1 default", "") +{ + DyePalette palette("#00ff00,000011", 6); + uint32_t data[1]; + data[0] = buildHex(0x10, 0x03, 0x02, 0x01); + palette.replaceSColorDefault(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); +} + +TEST_CASE("Dye replaceSColor 1 2 default", "") +{ + DyePalette palette("#403020,706050", 6); + uint32_t data[1]; + data[0] = buildHex(0x40, 0x30, 0x20, 0x10); + palette.replaceSColorDefault(&data[0], 1); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); +} + +TEST_CASE("Dye replaceSColor 1 3 default", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[1]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + palette.replaceSColorDefault(&data[0], 1); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); +} + +TEST_CASE("Dye replaceSColor 2 1 default", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[2]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + palette.replaceSColorDefault(&data[0], 2); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); +} + +TEST_CASE("Dye replaceSColor 3 1 default", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[3]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x30, 0x20, 0x30); + palette.replaceSColorDefault(&data[0], 3); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0x70, 0x60, 0x50, 0x30)); +} + +TEST_CASE("Dye replaceSColor 4 1 default", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[4]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + palette.replaceSColorDefault(&data[0], 4); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); +} + +TEST_CASE("Dye replaceSColor 5 1 default", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[5]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x30); + data[4] = buildHex(0xff, 0x30, 0x20, 0x20); + palette.replaceSColorDefault(&data[0], 5); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x30)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x20)); +} + +TEST_CASE("Dye replaceSColor 7 1 default", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[7]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + palette.replaceSColorDefault(&data[0], 7); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); +} + +TEST_CASE("Dye replaceSColor 8 1 default", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[8]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + data[7] = buildHex(0xff, 0x30, 0x20, 0x60); + palette.replaceSColorDefault(&data[0], 8); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); + REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); +} + +TEST_CASE("Dye replaceSColor 9 1 default", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[9]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + data[7] = buildHex(0xff, 0x30, 0x20, 0x60); + data[8] = buildHex(0xff, 0x30, 0x20, 0x70); + palette.replaceSColorDefault(&data[0], 9); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); + REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); + REQUIRE(data[8] == buildHex(0x70, 0x60, 0x50, 0x70)); +} + +TEST_CASE("Dye replaceSColor 10 1 default", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[10]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + data[7] = buildHex(0xff, 0x30, 0x20, 0x60); + data[8] = buildHex(0x12, 0x34, 0x56, 0x70); + data[9] = buildHex(0xff, 0x30, 0x20, 0x80); + palette.replaceSColorDefault(&data[0], 10); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); + REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); + REQUIRE(data[8] == buildHex(0x00, 0x00, 0x00, 0x70)); + REQUIRE(data[9] == buildHex(0x70, 0x60, 0x50, 0x80)); +} + +TEST_CASE("Dye replaceSColor 1 1 sse2", "") +{ + DyePalette palette("#00ff00,000011", 6); + uint32_t data[1]; + data[0] = buildHex(0x10, 0x03, 0x02, 0x01); + DYEPALETTE(palette, SColorSse2)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); +} + +TEST_CASE("Dye replaceSColor 1 2 sse2", "") +{ + DyePalette palette("#403020,706050", 6); + uint32_t data[1]; + data[0] = buildHex(0x40, 0x30, 0x20, 0x10); + DYEPALETTE(palette, SColorSse2)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); +} + +TEST_CASE("Dye replaceSColor 1 3 sse2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[1]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + DYEPALETTE(palette, SColorSse2)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); +} + +TEST_CASE("Dye replaceSColor 2 1 sse2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[2]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + DYEPALETTE(palette, SColorSse2)(&data[0], 2); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); +} + +TEST_CASE("Dye replaceSColor 3 1 sse2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[3]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x30, 0x20, 0x30); + DYEPALETTE(palette, SColorSse2)(&data[0], 3); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0x70, 0x60, 0x50, 0x30)); +} + +TEST_CASE("Dye replaceSColor 4 1 sse2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[4]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + DYEPALETTE(palette, SColorSse2)(&data[0], 4); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); +} + +TEST_CASE("Dye replaceSColor 5 1 sse2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[5]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x30); + data[4] = buildHex(0xff, 0x30, 0x20, 0x20); + DYEPALETTE(palette, SColorSse2)(&data[0], 5); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x30)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x20)); +} + +TEST_CASE("Dye replaceSColor 7 1 sse2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[7]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + DYEPALETTE(palette, SColorSse2)(&data[0], 7); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); +} + +TEST_CASE("Dye replaceSColor 8 1 sse2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[8]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + data[7] = buildHex(0xff, 0x30, 0x20, 0x60); + DYEPALETTE(palette, SColorSse2)(&data[0], 8); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); + REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); +} + +TEST_CASE("Dye replaceSColor 9 1 sse2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[9]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + data[7] = buildHex(0xff, 0x30, 0x20, 0x60); + data[8] = buildHex(0xff, 0x30, 0x20, 0x70); + DYEPALETTE(palette, SColorSse2)(&data[0], 9); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); + REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); + REQUIRE(data[8] == buildHex(0x70, 0x60, 0x50, 0x70)); +} + +TEST_CASE("Dye replaceSColor 10 1 sse2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[10]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + data[7] = buildHex(0xff, 0x30, 0x20, 0x60); + data[8] = buildHex(0x12, 0x34, 0x56, 0x70); + data[9] = buildHex(0xff, 0x30, 0x20, 0x80); + DYEPALETTE(palette, SColorSse2)(&data[0], 10); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); + REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); + REQUIRE(data[8] == buildHex(0x00, 0x00, 0x00, 0x70)); + REQUIRE(data[9] == buildHex(0x70, 0x60, 0x50, 0x80)); +} + +TEST_CASE("Dye replaceSColor 1 1 avx2", "") +{ + DyePalette palette("#00ff00,000011", 6); + uint32_t data[1]; + data[0] = buildHex(0x10, 0x03, 0x02, 0x01); + DYEPALETTE(palette, SColorAvx2)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); +} + +TEST_CASE("Dye replaceSColor 1 2 avx2", "") +{ + DyePalette palette("#403020,706050", 6); + uint32_t data[1]; + data[0] = buildHex(0x40, 0x30, 0x20, 0x10); + DYEPALETTE(palette, SColorAvx2)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); +} + +TEST_CASE("Dye replaceSColor 1 3 avx2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[1]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + DYEPALETTE(palette, SColorAvx2)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); +} + +TEST_CASE("Dye replaceSColor 2 1 avx2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[2]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + DYEPALETTE(palette, SColorAvx2)(&data[0], 2); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); +} + +TEST_CASE("Dye replaceSColor 3 1 avx2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[3]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x30, 0x20, 0x30); + DYEPALETTE(palette, SColorAvx2)(&data[0], 3); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0x70, 0x60, 0x50, 0x30)); +} + +TEST_CASE("Dye replaceSColor 4 1 avx2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[4]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + DYEPALETTE(palette, SColorAvx2)(&data[0], 4); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); +} + +TEST_CASE("Dye replaceSColor 5 1 avx2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[5]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x30); + data[4] = buildHex(0xff, 0x30, 0x20, 0x20); + DYEPALETTE(palette, SColorAvx2)(&data[0], 5); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x30)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x20)); +} + +TEST_CASE("Dye replaceSColor 7 1 avx2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[7]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + DYEPALETTE(palette, SColorAvx2)(&data[0], 7); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); +} + +TEST_CASE("Dye replaceSColor 8 1 avx2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[8]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + data[7] = buildHex(0xff, 0x30, 0x20, 0x60); + DYEPALETTE(palette, SColorAvx2)(&data[0], 8); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); + REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); +} + +TEST_CASE("Dye replaceSColor 9 1 avx2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[9]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + data[7] = buildHex(0xff, 0x30, 0x20, 0x60); + data[8] = buildHex(0xff, 0x30, 0x20, 0x70); + DYEPALETTE(palette, SColorAvx2)(&data[0], 9); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); + REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); + REQUIRE(data[8] == buildHex(0x70, 0x60, 0x50, 0x70)); +} + +TEST_CASE("Dye replaceSColor 10 1 avx2", "") +{ + DyePalette palette("#123456,000000,ff3020,706050", 6); + uint32_t data[10]; + data[0] = buildHex(0xff, 0x30, 0x20, 0x10); + data[1] = buildHex(0xff, 0x30, 0x20, 0x20); + data[2] = buildHex(0xff, 0x40, 0x20, 0x10); + data[3] = buildHex(0xff, 0x30, 0x20, 0x20); + data[4] = buildHex(0xff, 0x30, 0x20, 0x10); + data[5] = buildHex(0xff, 0x30, 0x20, 0x40); + data[6] = buildHex(0xff, 0x40, 0x20, 0x50); + data[7] = buildHex(0xff, 0x30, 0x20, 0x60); + data[8] = buildHex(0x12, 0x34, 0x56, 0x70); + data[9] = buildHex(0xff, 0x30, 0x20, 0x80); + DYEPALETTE(palette, SColorAvx2)(&data[0], 10); + REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); + REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); + REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); + REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); + REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); + REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); + REQUIRE(data[8] == buildHex(0x00, 0x00, 0x00, 0x70)); + REQUIRE(data[9] == buildHex(0x70, 0x60, 0x50, 0x80)); +} + + +TEST_CASE("Dye replaceAColor 1 1", "") +{ + DyePalette palette("#00ff0010,00001120", 8); + uint32_t data[1]; + data[0] = buildHex(0x10, 0x03, 0x02, 0x01); + DYEPALETTE(palette, AColor)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); +} + +TEST_CASE("Dye replaceAColor 1 2", "") +{ + DyePalette palette("#02ff0120,040311ff", 8); + uint32_t data[1]; + data[0] = buildHex(0x02, 0xff, 0x01, 0x20); + DYEPALETTE(palette, AColor)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x04, 0x03, 0x11, 0xff)); +} + +TEST_CASE("Dye replaceAColor 1 3", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[1]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + DYEPALETTE(palette, AColor)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); +} + +TEST_CASE("Dye replaceAColor 2 1", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[2]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColor)(&data[0], 2); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 3 1", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[3]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x50, 0x40, 0x40, 0x30); + data[2] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColor)(&data[0], 3); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x50, 0x40, 0x40, 0x30)); + REQUIRE(data[2] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 4 1", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[4]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColor)(&data[0], 4); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 5 1", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[5]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x50, 0x40, 0x40, 0x60); + data[4] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColor)(&data[0], 5); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x50, 0x40, 0x40, 0x60)); + REQUIRE(data[4] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 7 1", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[7]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + DYEPALETTE(palette, AColor)(&data[0], 7); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); +} + +TEST_CASE("Dye replaceAColor 8 1", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[8]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + data[7] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColor)(&data[0], 8); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[7] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 9 1", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[9]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + data[7] = buildHex(0x02, 0x40, 0x40, 0x40); + data[8] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColor)(&data[0], 9); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); + REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 10 1", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[10]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + data[7] = buildHex(0x02, 0x40, 0x40, 0x40); + data[8] = buildHex(0x40, 0x40, 0x40, 0x40); + data[9] = buildHex(0x01, 0x00, 0xee, 0x40); + DYEPALETTE(palette, AColor)(&data[0], 10); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); + REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[9] == buildHex(0x10, 0x20, 0x30, 0xff)); +} + +TEST_CASE("Dye replaceAColor 1 1 default", "") +{ + DyePalette palette("#00ff0010,00001120", 8); + uint32_t data[1]; + data[0] = buildHex(0x10, 0x03, 0x02, 0x01); + palette.replaceAColorDefault(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); +} + +TEST_CASE("Dye replaceAColor 1 2 default", "") +{ + DyePalette palette("#02ff0120,040311ff", 8); + uint32_t data[1]; + data[0] = buildHex(0x02, 0xff, 0x01, 0x20); + palette.replaceAColorDefault(&data[0], 1); + REQUIRE(data[0] == buildHex(0x04, 0x03, 0x11, 0xff)); +} + +TEST_CASE("Dye replaceAColor 1 3 default", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[1]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + palette.replaceAColorDefault(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); +} + +TEST_CASE("Dye replaceAColor 2 1 default", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[2]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + palette.replaceAColorDefault(&data[0], 2); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 3 1 default", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[3]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x50, 0x40, 0x40, 0x30); + data[2] = buildHex(0x40, 0x40, 0x40, 0x40); + palette.replaceAColorDefault(&data[0], 3); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x50, 0x40, 0x40, 0x30)); + REQUIRE(data[2] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 4 1 default", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[4]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + palette.replaceAColorDefault(&data[0], 4); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 5 1 default", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[5]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x50, 0x40, 0x40, 0x60); + data[4] = buildHex(0x40, 0x40, 0x40, 0x40); + palette.replaceAColorDefault(&data[0], 5); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x50, 0x40, 0x40, 0x60)); + REQUIRE(data[4] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 7 1 default", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[7]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + palette.replaceAColorDefault(&data[0], 7); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); +} + +TEST_CASE("Dye replaceAColor 8 1 default", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[8]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + data[7] = buildHex(0x40, 0x40, 0x40, 0x40); + palette.replaceAColorDefault(&data[0], 8); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[7] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 9 1 default", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[9]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + data[7] = buildHex(0x02, 0x40, 0x40, 0x40); + data[8] = buildHex(0x40, 0x40, 0x40, 0x40); + palette.replaceAColorDefault(&data[0], 9); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); + REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 10 1 default", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[10]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + data[7] = buildHex(0x02, 0x40, 0x40, 0x40); + data[8] = buildHex(0x40, 0x40, 0x40, 0x40); + data[9] = buildHex(0x01, 0x00, 0xee, 0x40); + palette.replaceAColorDefault(&data[0], 10); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); + REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[9] == buildHex(0x10, 0x20, 0x30, 0xff)); +} + +TEST_CASE("Dye replaceAColor 1 1 sse2", "") +{ + DyePalette palette("#00ff0010,00001120", 8); + uint32_t data[1]; + data[0] = buildHex(0x10, 0x03, 0x02, 0x01); + DYEPALETTE(palette, AColorSse2)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); +} + +TEST_CASE("Dye replaceAColor 1 2 sse2", "") +{ + DyePalette palette("#02ff0120,040311ff", 8); + uint32_t data[1]; + data[0] = buildHex(0x02, 0xff, 0x01, 0x20); + DYEPALETTE(palette, AColorSse2)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x04, 0x03, 0x11, 0xff)); +} + +TEST_CASE("Dye replaceAColor 1 3 sse2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[1]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + DYEPALETTE(palette, AColorSse2)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); +} + +TEST_CASE("Dye replaceAColor 2 1 sse2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[2]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColorSse2)(&data[0], 2); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 3 1 sse2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[3]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x50, 0x40, 0x40, 0x30); + data[2] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColorSse2)(&data[0], 3); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x50, 0x40, 0x40, 0x30)); + REQUIRE(data[2] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 4 1 sse2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[4]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColorSse2)(&data[0], 4); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 5 1 sse2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[5]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x50, 0x40, 0x40, 0x60); + data[4] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColorSse2)(&data[0], 5); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x50, 0x40, 0x40, 0x60)); + REQUIRE(data[4] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 7 1 sse2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[7]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + DYEPALETTE(palette, AColorSse2)(&data[0], 7); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); +} + +TEST_CASE("Dye replaceAColor 8 1 sse2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[8]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + data[7] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColorSse2)(&data[0], 8); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[7] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 9 1 sse2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[9]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + data[7] = buildHex(0x02, 0x40, 0x40, 0x40); + data[8] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColorSse2)(&data[0], 9); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); + REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 10 1 sse2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[10]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + data[7] = buildHex(0x02, 0x40, 0x40, 0x40); + data[8] = buildHex(0x40, 0x40, 0x40, 0x40); + data[9] = buildHex(0x01, 0x00, 0xee, 0x40); + DYEPALETTE(palette, AColorSse2)(&data[0], 10); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); + REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[9] == buildHex(0x10, 0x20, 0x30, 0xff)); +} + +TEST_CASE("Dye replaceAColor 1 1 avx2", "") +{ + DyePalette palette("#00ff0010,00001120", 8); + uint32_t data[1]; + data[0] = buildHex(0x10, 0x03, 0x02, 0x01); + DYEPALETTE(palette, AColorAvx2)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); +} + +TEST_CASE("Dye replaceAColor 1 2 avx2", "") +{ + DyePalette palette("#02ff0120,040311ff", 8); + uint32_t data[1]; + data[0] = buildHex(0x02, 0xff, 0x01, 0x20); + DYEPALETTE(palette, AColorAvx2)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x04, 0x03, 0x11, 0xff)); +} + +TEST_CASE("Dye replaceAColor 1 3 avx2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[1]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + DYEPALETTE(palette, AColorAvx2)(&data[0], 1); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); +} + +TEST_CASE("Dye replaceAColor 2 1 avx2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[2]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColorAvx2)(&data[0], 2); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 3 1 avx2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[3]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x50, 0x40, 0x40, 0x30); + data[2] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColorAvx2)(&data[0], 3); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x50, 0x40, 0x40, 0x30)); + REQUIRE(data[2] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 4 1 avx2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[4]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColorAvx2)(&data[0], 4); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 5 1 avx2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[5]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x50, 0x40, 0x40, 0x60); + data[4] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColorAvx2)(&data[0], 5); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x50, 0x40, 0x40, 0x60)); + REQUIRE(data[4] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 7 1 avx2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[7]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + DYEPALETTE(palette, AColorAvx2)(&data[0], 7); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); +} + +TEST_CASE("Dye replaceAColor 8 1 avx2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[8]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + data[7] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColorAvx2)(&data[0], 8); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[7] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 9 1 avx2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[9]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + data[7] = buildHex(0x02, 0x40, 0x40, 0x40); + data[8] = buildHex(0x40, 0x40, 0x40, 0x40); + DYEPALETTE(palette, AColorAvx2)(&data[0], 9); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); + REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); +} + +TEST_CASE("Dye replaceAColor 10 1 avx2", "") +{ + DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); + uint32_t data[10]; + data[0] = buildHex(0x01, 0x00, 0xee, 0x40); + data[1] = buildHex(0x40, 0x40, 0x40, 0x40); + data[2] = buildHex(0x01, 0x00, 0xee, 0x50); + data[3] = buildHex(0x40, 0x40, 0x40, 0x40); + data[4] = buildHex(0x01, 0x00, 0xee, 0x40); + data[5] = buildHex(0x40, 0x40, 0x41, 0x40); + data[6] = buildHex(0x01, 0x00, 0xee, 0x50); + data[7] = buildHex(0x02, 0x40, 0x40, 0x40); + data[8] = buildHex(0x40, 0x40, 0x40, 0x40); + data[9] = buildHex(0x01, 0x00, 0xee, 0x40); + DYEPALETTE(palette, AColorAvx2)(&data[0], 10); + REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); + REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); + REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); + REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); + REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); + REQUIRE(data[9] == buildHex(0x10, 0x20, 0x30, 0xff)); +} + + +TEST_CASE("Dye normalDye 1", "") +{ + Dye dye("R:#203040,506070"); + uint32_t data[1]; + data[0] = buildHex(0x50, 0x00, 0x00, 0x55); + dye.normalDye(&data[0], 1); + REQUIRE(data[0] == buildHex(0x14, 0x1e, 0x28, 0x55)); +} + +TEST_CASE("Dye normalDye 2", "") +{ + Dye dye("G:#203040,506070"); + uint32_t data[1]; + data[0] = buildHex(0x00, 0x50, 0x00, 0x60); + dye.normalDye(&data[0], 1); + REQUIRE(data[0] == buildHex(0x14, 0x1e, 0x28, 0x60)); +} + + +#ifdef USE_OPENGL +TEST_CASE("Dye normalOGLDye 1", "") +{ + Dye dye("R:#203040,506070"); + uint32_t data[1]; + data[0] = buildHex(0x50, 0x00, 0x00, 0x55); + dye.normalOGLDye(&data[0], 1); + REQUIRE(data[0] == buildHex(0x50, 0x2a, 0x20, 0x15)); +} +#endif // USE_OPENGL + +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]); + } + image2->decRef(); + image1->decRef(); +} + +TEST_CASE("Dye real dye", "") +{ + setEnv("SDL_VIDEODRIVER", "dummy"); + + client = new Client; + SDL_Init(SDL_INIT_VIDEO); + logger = new Logger(); + VirtFs::mountDirSilent("data", Append_false); + VirtFs::mountDirSilent("../data", Append_false); + VirtFs::mountDirSilent("data/test", Append_false); + VirtFs::mountDirSilent("../data/test", Append_false); + +#ifdef USE_SDL2 + imageHelper = new SurfaceImageHelper; + + SDLImageHelper::setRenderer(graphicsManager.createRenderer( + graphicsManager.createWindow(640, 480, 0, + SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE)); +#else // USE_SDL2 + + imageHelper = new SDLImageHelper; + + graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE); +#endif // USE_SDL2 + + ActorSprite::load(); + + 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"); + } + delete2(client); + VirtFs::unmountDirSilent("data"); + VirtFs::unmountDirSilent("../data"); + VirtFs::unmountDirSilent("data/test"); + VirtFs::unmountDirSilent("../data/test"); + delete2(logger); +// VirtFs::deinit(); +} + +TEST_CASE("Dye leak test2", "") +{ + logger = new Logger(); + REQUIRE(gui == nullptr); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); + delete2(logger); +} diff --git a/src/unittests/resources/dye/dye_unittest.cc b/src/unittests/resources/dye/dye_unittest.cc deleted file mode 100644 index fcdeb7b17..000000000 --- a/src/unittests/resources/dye/dye_unittest.cc +++ /dev/null @@ -1,2020 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2013-2017 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 . - */ - -#include "unittests/unittests.h" - -#include "client.h" -#include "graphicsmanager.h" -#include "logger.h" - -#include "being/actorsprite.h" - -#include "fs/virtfs/fs.h" - -#include "gui/gui.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/delete2.h" -#include "utils/env.h" - -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#ifndef USE_SDL2 -#include -#endif // USE_SDL2 -PRAGMA48(GCC diagnostic pop) - -#include "debug.h" - -#ifdef USE_OPENGL - -TEST_CASE("Dye leak test1", "") -{ - logger = new Logger(); - REQUIRE(gui == nullptr); - ResourceManager::cleanOrphans(true); - ResourceManager::deleteInstance(); - delete2(logger); -} - -TEST_CASE("Dye replaceSOGLColor 1 1", "") -{ - DyePalette palette("#00ff00,000011", 6); - uint32_t data[1]; - data[0] = buildHex(0x01, 0x02, 0x03, 0x10); - DYEPALETTE(palette, SOGLColor)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x01, 0x02, 0x03, 0x10)); -} - -TEST_CASE("Dye replaceSOGLColor 1 2", "") -{ - DyePalette palette("#01ff02,030411", 6); - uint32_t data[1]; - data[0] = buildHex(0x20, 0x02, 0xff, 0x01); - DYEPALETTE(palette, SOGLColor)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); -} - -TEST_CASE("Dye replaceSOGLColor 1 3", "") -{ - DyePalette palette("#404040,200000,0100ee,102030", 6); - uint32_t data[1]; - data[0] = buildHex(0x40, 0xee, 0x00, 0x01); - DYEPALETTE(palette, SOGLColor)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x40, 0x30, 0x20, 0x10)); -} - -TEST_CASE("Dye replaceSOGLColor 2 1", "") -{ - DyePalette palette("#01ff02,030411", 6); - uint32_t data[2]; - data[0] = buildHex(0x20, 0x02, 0xff, 0x01); - data[1] = buildHex(0x30, 0x02, 0xff, 0x01); - DYEPALETTE(palette, SOGLColor)(&data[0], 2); - REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); - REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); -} - -TEST_CASE("Dye replaceSOGLColor 4 1", "") -{ - DyePalette palette("#01ff02,030411", 6); - uint32_t data[4]; - data[0] = buildHex(0x20, 0x02, 0xff, 0x01); - data[1] = buildHex(0x30, 0x02, 0xff, 0x01); - data[2] = buildHex(0x40, 0x02, 0xff, 0x01); - data[3] = buildHex(0x50, 0x02, 0xff, 0x02); - DYEPALETTE(palette, SOGLColor)(&data[0], 4); - REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); - REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); - REQUIRE(data[2] == buildHex(0x40, 0x11, 0x04, 0x03)); - REQUIRE(data[3] == buildHex(0x50, 0x02, 0xff, 0x02)); -} - -TEST_CASE("Dye replaceSOGLColor 8 1", "") -{ - DyePalette palette("#01ff02,030411,01ee02,010203", 6); - uint32_t data[8]; - data[0] = buildHex(0x20, 0x02, 0xff, 0x01); - data[1] = buildHex(0x30, 0x02, 0xff, 0x01); - data[2] = buildHex(0x40, 0x02, 0xff, 0x01); - data[3] = buildHex(0x50, 0x02, 0xff, 0x02); - data[4] = buildHex(0x20, 0x02, 0xff, 0x01); - data[5] = buildHex(0x30, 0x02, 0xff, 0x01); - data[6] = buildHex(0x40, 0x02, 0xff, 0x01); - data[7] = buildHex(0x60, 0x02, 0xff, 0x02); - DYEPALETTE(palette, SOGLColor)(&data[0], 8); - REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); - REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); - REQUIRE(data[2] == buildHex(0x40, 0x11, 0x04, 0x03)); - REQUIRE(data[3] == buildHex(0x50, 0x02, 0xff, 0x02)); - REQUIRE(data[4] == buildHex(0x20, 0x11, 0x04, 0x03)); - REQUIRE(data[5] == buildHex(0x30, 0x11, 0x04, 0x03)); - REQUIRE(data[6] == buildHex(0x40, 0x11, 0x04, 0x03)); - REQUIRE(data[7] == buildHex(0x60, 0x02, 0xff, 0x02)); -} - -TEST_CASE("Dye replaceSOGLColor 1 1 default", "") -{ - DyePalette palette("#00ff00,000011", 6); - uint32_t data[1]; - data[0] = buildHex(0x01, 0x02, 0x03, 0x10); - palette.replaceSOGLColorDefault(&data[0], 1); - REQUIRE(data[0] == buildHex(0x01, 0x02, 0x03, 0x10)); -} - -TEST_CASE("Dye replaceSOGLColor 1 2 default", "") -{ - DyePalette palette("#01ff02,030411", 6); - uint32_t data[1]; - data[0] = buildHex(0x20, 0x02, 0xff, 0x01); - palette.replaceSOGLColorDefault(&data[0], 1); - REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); -} - -TEST_CASE("Dye replaceSOGLColor 1 3 default", "") -{ - DyePalette palette("#404040,200000,0100ee,102030", 6); - uint32_t data[1]; - data[0] = buildHex(0x40, 0xee, 0x00, 0x01); - palette.replaceSOGLColorDefault(&data[0], 1); - REQUIRE(data[0] == buildHex(0x40, 0x30, 0x20, 0x10)); -} - -TEST_CASE("Dye replaceSOGLColor 2 1 default", "") -{ - DyePalette palette("#01ff02,030411", 6); - uint32_t data[2]; - data[0] = buildHex(0x20, 0x02, 0xff, 0x01); - data[1] = buildHex(0x30, 0x02, 0xff, 0x01); - palette.replaceSOGLColorDefault(&data[0], 2); - REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); - REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); -} - -TEST_CASE("Dye replaceSOGLColor 4 1 default", "") -{ - DyePalette palette("#01ff02,030411", 6); - uint32_t data[4]; - data[0] = buildHex(0x20, 0x02, 0xff, 0x01); - data[1] = buildHex(0x30, 0x02, 0xff, 0x01); - data[2] = buildHex(0x40, 0x02, 0xff, 0x01); - data[3] = buildHex(0x50, 0x02, 0xff, 0x02); - palette.replaceSOGLColorDefault(&data[0], 4); - REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); - REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); - REQUIRE(data[2] == buildHex(0x40, 0x11, 0x04, 0x03)); - REQUIRE(data[3] == buildHex(0x50, 0x02, 0xff, 0x02)); -} - -TEST_CASE("Dye replaceSOGLColor 8 1 default", "") -{ - DyePalette palette("#01ff02,030411,01ee02,010203", 6); - uint32_t data[8]; - data[0] = buildHex(0x20, 0x02, 0xff, 0x01); - data[1] = buildHex(0x30, 0x02, 0xff, 0x01); - data[2] = buildHex(0x40, 0x02, 0xff, 0x01); - data[3] = buildHex(0x50, 0x02, 0xff, 0x02); - data[4] = buildHex(0x20, 0x02, 0xff, 0x01); - data[5] = buildHex(0x30, 0x02, 0xff, 0x01); - data[6] = buildHex(0x40, 0x02, 0xff, 0x01); - data[7] = buildHex(0x60, 0x02, 0xff, 0x02); - palette.replaceSOGLColorDefault(&data[0], 8); - REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); - REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); - REQUIRE(data[2] == buildHex(0x40, 0x11, 0x04, 0x03)); - REQUIRE(data[3] == buildHex(0x50, 0x02, 0xff, 0x02)); - REQUIRE(data[4] == buildHex(0x20, 0x11, 0x04, 0x03)); - REQUIRE(data[5] == buildHex(0x30, 0x11, 0x04, 0x03)); - REQUIRE(data[6] == buildHex(0x40, 0x11, 0x04, 0x03)); - REQUIRE(data[7] == buildHex(0x60, 0x02, 0xff, 0x02)); -} - -TEST_CASE("Dye replaceSOGLColor 8 1 sse2", "") -{ - DyePalette palette("#01ff02,030411,01ee02,010203", 6); - uint32_t data[8]; - data[0] = buildHex(0x20, 0x02, 0xff, 0x01); - data[1] = buildHex(0x30, 0x02, 0xff, 0x01); - data[2] = buildHex(0x40, 0x02, 0xff, 0x01); - data[3] = buildHex(0x50, 0x02, 0xff, 0x02); - data[4] = buildHex(0x20, 0x02, 0xff, 0x01); - data[5] = buildHex(0x30, 0x02, 0xff, 0x01); - data[6] = buildHex(0x40, 0x02, 0xff, 0x01); - data[7] = buildHex(0x60, 0x02, 0xff, 0x02); - DYEPALETTE(palette, SOGLColorSse2)(&data[0], 8); - REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); - REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); - REQUIRE(data[2] == buildHex(0x40, 0x11, 0x04, 0x03)); - REQUIRE(data[3] == buildHex(0x50, 0x02, 0xff, 0x02)); - REQUIRE(data[4] == buildHex(0x20, 0x11, 0x04, 0x03)); - REQUIRE(data[5] == buildHex(0x30, 0x11, 0x04, 0x03)); - REQUIRE(data[6] == buildHex(0x40, 0x11, 0x04, 0x03)); - REQUIRE(data[7] == buildHex(0x60, 0x02, 0xff, 0x02)); -} - -TEST_CASE("Dye replaceSOGLColor 8 1 avx2", "") -{ - DyePalette palette("#01ff02,030411,01ee02,010203", 6); - uint32_t data[8]; - data[0] = buildHex(0x20, 0x02, 0xff, 0x01); - data[1] = buildHex(0x30, 0x02, 0xff, 0x01); - data[2] = buildHex(0x40, 0x02, 0xff, 0x01); - data[3] = buildHex(0x50, 0x02, 0xff, 0x02); - data[4] = buildHex(0x20, 0x02, 0xff, 0x01); - data[5] = buildHex(0x30, 0x02, 0xff, 0x01); - data[6] = buildHex(0x40, 0x02, 0xff, 0x01); - data[7] = buildHex(0x60, 0x02, 0xff, 0x02); - DYEPALETTE(palette, SOGLColorAvx2)(&data[0], 8); - REQUIRE(data[0] == buildHex(0x20, 0x11, 0x04, 0x03)); - REQUIRE(data[1] == buildHex(0x30, 0x11, 0x04, 0x03)); - REQUIRE(data[2] == buildHex(0x40, 0x11, 0x04, 0x03)); - REQUIRE(data[3] == buildHex(0x50, 0x02, 0xff, 0x02)); - REQUIRE(data[4] == buildHex(0x20, 0x11, 0x04, 0x03)); - REQUIRE(data[5] == buildHex(0x30, 0x11, 0x04, 0x03)); - REQUIRE(data[6] == buildHex(0x40, 0x11, 0x04, 0x03)); - REQUIRE(data[7] == buildHex(0x60, 0x02, 0xff, 0x02)); -} - - -TEST_CASE("Dye replaceAOGLColor 1 1", "") -{ - DyePalette palette("#00ff0010,00001120", 8); - uint32_t data[1]; - data[0] = buildHex(0x10, 0x03, 0x02, 0x01); - DYEPALETTE(palette, AOGLColor)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); -} - -TEST_CASE("Dye replaceAOGLColor 1 2", "") -{ - DyePalette palette("#00ff0120,020311ff", 8); - uint32_t data[1]; - data[0] = buildHex(0x20, 0x01, 0xff, 0x00); - DYEPALETTE(palette, AOGLColor)(&data[0], 1); - REQUIRE(data[0] == buildHex(0xff, 0x11, 0x03, 0x02)); -} - -TEST_CASE("Dye replaceAOGLColor 1 3", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[1]; - data[0] = buildHex(0x40, 0xee, 0x00, 0x01); - DYEPALETTE(palette, AOGLColor)(&data[0], 1); - REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); -} - -TEST_CASE("Dye replaceAOGLColor 2 1", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[2]; - data[0] = buildHex(0x40, 0xee, 0x00, 0x01); - data[1] = buildHex(0x40, 0xee, 0x00, 0x01); - DYEPALETTE(palette, AOGLColor)(&data[0], 2); - REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); -} - -TEST_CASE("Dye replaceAOGLColor 4 1", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[4]; - data[0] = buildHex(0x40, 0xee, 0x00, 0x01); - data[1] = buildHex(0x40, 0xee, 0x00, 0x01); - data[2] = buildHex(0x41, 0xee, 0x00, 0x01); - data[3] = buildHex(0x40, 0xee, 0x00, 0x01); - DYEPALETTE(palette, AOGLColor)(&data[0], 4); - REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[2] == buildHex(0x41, 0xee, 0x00, 0x01)); - REQUIRE(data[3] == buildHex(0xff, 0x30, 0x20, 0x10)); -} - -TEST_CASE("Dye replaceAOGLColor 8 1", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[8]; - data[0] = buildHex(0x40, 0xee, 0x00, 0x01); - data[1] = buildHex(0x40, 0xee, 0x00, 0x01); - data[2] = buildHex(0x41, 0xee, 0x00, 0x01); - data[3] = buildHex(0x40, 0xee, 0x00, 0x01); - data[4] = buildHex(0x40, 0xee, 0x00, 0x01); - data[5] = buildHex(0x40, 0x40, 0x40, 0x40); - data[6] = buildHex(0x41, 0xe0, 0x00, 0x01); - data[7] = buildHex(0x40, 0xee, 0x00, 0x01); - DYEPALETTE(palette, AOGLColor)(&data[0], 8); - REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[2] == buildHex(0x41, 0xee, 0x00, 0x01)); - REQUIRE(data[3] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[4] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[5] == buildHex(0x00, 0x00, 0x00, 0x20)); - REQUIRE(data[6] == buildHex(0x41, 0xe0, 0x00, 0x01)); - REQUIRE(data[7] == buildHex(0xff, 0x30, 0x20, 0x10)); -} - -TEST_CASE("Dye replaceAOGLColor 1 1 default", "") -{ - DyePalette palette("#00ff0010,00001120", 8); - uint32_t data[1]; - data[0] = buildHex(0x10, 0x03, 0x02, 0x01); - palette.replaceAOGLColorDefault(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); -} - -TEST_CASE("Dye replaceAOGLColor 1 2 default", "") -{ - DyePalette palette("#00ff0120,020311ff", 8); - uint32_t data[1]; - data[0] = buildHex(0x20, 0x01, 0xff, 0x00); - palette.replaceAOGLColorDefault(&data[0], 1); - REQUIRE(data[0] == buildHex(0xff, 0x11, 0x03, 0x02)); -} - -TEST_CASE("Dye replaceAOGLColor 1 3 default", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[1]; - data[0] = buildHex(0x40, 0xee, 0x00, 0x01); - palette.replaceAOGLColorDefault(&data[0], 1); - REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); -} - -TEST_CASE("Dye replaceAOGLColor 2 1 default", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[2]; - data[0] = buildHex(0x40, 0xee, 0x00, 0x01); - data[1] = buildHex(0x40, 0xee, 0x00, 0x01); - palette.replaceAOGLColorDefault(&data[0], 2); - REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); -} - -TEST_CASE("Dye replaceAOGLColor 4 1 default", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[4]; - data[0] = buildHex(0x40, 0xee, 0x00, 0x01); - data[1] = buildHex(0x40, 0xee, 0x00, 0x01); - data[2] = buildHex(0x41, 0xee, 0x00, 0x01); - data[3] = buildHex(0x40, 0xee, 0x00, 0x01); - palette.replaceAOGLColorDefault(&data[0], 4); - REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[2] == buildHex(0x41, 0xee, 0x00, 0x01)); - REQUIRE(data[3] == buildHex(0xff, 0x30, 0x20, 0x10)); -} - -TEST_CASE("Dye replaceAOGLColor 8 1 default", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[8]; - data[0] = buildHex(0x40, 0xee, 0x00, 0x01); - data[1] = buildHex(0x40, 0xee, 0x00, 0x01); - data[2] = buildHex(0x41, 0xee, 0x00, 0x01); - data[3] = buildHex(0x40, 0xee, 0x00, 0x01); - data[4] = buildHex(0x40, 0xee, 0x00, 0x01); - data[5] = buildHex(0x40, 0x40, 0x40, 0x40); - data[6] = buildHex(0x41, 0xe0, 0x00, 0x01); - data[7] = buildHex(0x40, 0xee, 0x00, 0x01); - palette.replaceAOGLColorDefault(&data[0], 8); - REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[2] == buildHex(0x41, 0xee, 0x00, 0x01)); - REQUIRE(data[3] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[4] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[5] == buildHex(0x00, 0x00, 0x00, 0x20)); - REQUIRE(data[6] == buildHex(0x41, 0xe0, 0x00, 0x01)); - REQUIRE(data[7] == buildHex(0xff, 0x30, 0x20, 0x10)); -} - -TEST_CASE("Dye replaceAOGLColor 8 1 sse2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[8]; - data[0] = buildHex(0x40, 0xee, 0x00, 0x01); - data[1] = buildHex(0x40, 0xee, 0x00, 0x01); - data[2] = buildHex(0x41, 0xee, 0x00, 0x01); - data[3] = buildHex(0x40, 0xee, 0x00, 0x01); - data[4] = buildHex(0x40, 0xee, 0x00, 0x01); - data[5] = buildHex(0x40, 0x40, 0x40, 0x40); - data[6] = buildHex(0x41, 0xe0, 0x00, 0x01); - data[7] = buildHex(0x40, 0xee, 0x00, 0x01); - DYEPALETTE(palette, AOGLColorSse2)(&data[0], 8); - REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[2] == buildHex(0x41, 0xee, 0x00, 0x01)); - REQUIRE(data[3] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[4] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[5] == buildHex(0x00, 0x00, 0x00, 0x20)); - REQUIRE(data[6] == buildHex(0x41, 0xe0, 0x00, 0x01)); - REQUIRE(data[7] == buildHex(0xff, 0x30, 0x20, 0x10)); -} - -TEST_CASE("Dye replaceAOGLColor 8 1 avx2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[8]; - data[0] = buildHex(0x40, 0xee, 0x00, 0x01); - data[1] = buildHex(0x40, 0xee, 0x00, 0x01); - data[2] = buildHex(0x41, 0xee, 0x00, 0x01); - data[3] = buildHex(0x40, 0xee, 0x00, 0x01); - data[4] = buildHex(0x40, 0xee, 0x00, 0x01); - data[5] = buildHex(0x40, 0x40, 0x40, 0x40); - data[6] = buildHex(0x41, 0xe0, 0x00, 0x01); - data[7] = buildHex(0x40, 0xee, 0x00, 0x01); - DYEPALETTE(palette, AOGLColorAvx2)(&data[0], 8); - REQUIRE(data[0] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[1] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[2] == buildHex(0x41, 0xee, 0x00, 0x01)); - REQUIRE(data[3] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[4] == buildHex(0xff, 0x30, 0x20, 0x10)); - REQUIRE(data[5] == buildHex(0x00, 0x00, 0x00, 0x20)); - REQUIRE(data[6] == buildHex(0x41, 0xe0, 0x00, 0x01)); - REQUIRE(data[7] == buildHex(0xff, 0x30, 0x20, 0x10)); -} -#endif // USE_OPENGL - - -TEST_CASE("Dye replaceSColor 1 1", "") -{ - DyePalette palette("#00ff00,000011", 6); - uint32_t data[1]; - data[0] = buildHex(0x10, 0x03, 0x02, 0x01); - DYEPALETTE(palette, SColor)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); -} - -TEST_CASE("Dye replaceSColor 1 2", "") -{ - DyePalette palette("#403020,706050", 6); - uint32_t data[1]; - data[0] = buildHex(0x40, 0x30, 0x20, 0x10); - DYEPALETTE(palette, SColor)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); -} - -TEST_CASE("Dye replaceSColor 1 3", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[1]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - DYEPALETTE(palette, SColor)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); -} - -TEST_CASE("Dye replaceSColor 2 1", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[2]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - DYEPALETTE(palette, SColor)(&data[0], 2); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); -} - -TEST_CASE("Dye replaceSColor 3 1", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[3]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x30, 0x20, 0x30); - DYEPALETTE(palette, SColor)(&data[0], 3); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0x70, 0x60, 0x50, 0x30)); -} - -TEST_CASE("Dye replaceSColor 4 1", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[4]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - DYEPALETTE(palette, SColor)(&data[0], 4); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); -} - -TEST_CASE("Dye replaceSColor 5 1", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[5]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x30); - data[4] = buildHex(0xff, 0x30, 0x20, 0x20); - DYEPALETTE(palette, SColor)(&data[0], 5); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x30)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x20)); -} - -TEST_CASE("Dye replaceSColor 7 1", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[7]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - DYEPALETTE(palette, SColor)(&data[0], 7); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); -} - -TEST_CASE("Dye replaceSColor 8 1", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[8]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - data[7] = buildHex(0xff, 0x30, 0x20, 0x60); - DYEPALETTE(palette, SColor)(&data[0], 8); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); - REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); -} - -TEST_CASE("Dye replaceSColor 9 1", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[9]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - data[7] = buildHex(0xff, 0x30, 0x20, 0x60); - data[8] = buildHex(0xff, 0x30, 0x20, 0x70); - DYEPALETTE(palette, SColor)(&data[0], 9); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); - REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); - REQUIRE(data[8] == buildHex(0x70, 0x60, 0x50, 0x70)); -} - -TEST_CASE("Dye replaceSColor 10 1", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[10]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - data[7] = buildHex(0xff, 0x30, 0x20, 0x60); - data[8] = buildHex(0x12, 0x34, 0x56, 0x70); - data[9] = buildHex(0xff, 0x30, 0x20, 0x80); - DYEPALETTE(palette, SColor)(&data[0], 10); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); - REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); - REQUIRE(data[8] == buildHex(0x00, 0x00, 0x00, 0x70)); - REQUIRE(data[9] == buildHex(0x70, 0x60, 0x50, 0x80)); -} - -TEST_CASE("Dye replaceSColor 1 1 default", "") -{ - DyePalette palette("#00ff00,000011", 6); - uint32_t data[1]; - data[0] = buildHex(0x10, 0x03, 0x02, 0x01); - palette.replaceSColorDefault(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); -} - -TEST_CASE("Dye replaceSColor 1 2 default", "") -{ - DyePalette palette("#403020,706050", 6); - uint32_t data[1]; - data[0] = buildHex(0x40, 0x30, 0x20, 0x10); - palette.replaceSColorDefault(&data[0], 1); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); -} - -TEST_CASE("Dye replaceSColor 1 3 default", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[1]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - palette.replaceSColorDefault(&data[0], 1); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); -} - -TEST_CASE("Dye replaceSColor 2 1 default", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[2]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - palette.replaceSColorDefault(&data[0], 2); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); -} - -TEST_CASE("Dye replaceSColor 3 1 default", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[3]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x30, 0x20, 0x30); - palette.replaceSColorDefault(&data[0], 3); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0x70, 0x60, 0x50, 0x30)); -} - -TEST_CASE("Dye replaceSColor 4 1 default", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[4]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - palette.replaceSColorDefault(&data[0], 4); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); -} - -TEST_CASE("Dye replaceSColor 5 1 default", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[5]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x30); - data[4] = buildHex(0xff, 0x30, 0x20, 0x20); - palette.replaceSColorDefault(&data[0], 5); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x30)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x20)); -} - -TEST_CASE("Dye replaceSColor 7 1 default", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[7]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - palette.replaceSColorDefault(&data[0], 7); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); -} - -TEST_CASE("Dye replaceSColor 8 1 default", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[8]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - data[7] = buildHex(0xff, 0x30, 0x20, 0x60); - palette.replaceSColorDefault(&data[0], 8); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); - REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); -} - -TEST_CASE("Dye replaceSColor 9 1 default", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[9]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - data[7] = buildHex(0xff, 0x30, 0x20, 0x60); - data[8] = buildHex(0xff, 0x30, 0x20, 0x70); - palette.replaceSColorDefault(&data[0], 9); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); - REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); - REQUIRE(data[8] == buildHex(0x70, 0x60, 0x50, 0x70)); -} - -TEST_CASE("Dye replaceSColor 10 1 default", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[10]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - data[7] = buildHex(0xff, 0x30, 0x20, 0x60); - data[8] = buildHex(0x12, 0x34, 0x56, 0x70); - data[9] = buildHex(0xff, 0x30, 0x20, 0x80); - palette.replaceSColorDefault(&data[0], 10); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); - REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); - REQUIRE(data[8] == buildHex(0x00, 0x00, 0x00, 0x70)); - REQUIRE(data[9] == buildHex(0x70, 0x60, 0x50, 0x80)); -} - -TEST_CASE("Dye replaceSColor 1 1 sse2", "") -{ - DyePalette palette("#00ff00,000011", 6); - uint32_t data[1]; - data[0] = buildHex(0x10, 0x03, 0x02, 0x01); - DYEPALETTE(palette, SColorSse2)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); -} - -TEST_CASE("Dye replaceSColor 1 2 sse2", "") -{ - DyePalette palette("#403020,706050", 6); - uint32_t data[1]; - data[0] = buildHex(0x40, 0x30, 0x20, 0x10); - DYEPALETTE(palette, SColorSse2)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); -} - -TEST_CASE("Dye replaceSColor 1 3 sse2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[1]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - DYEPALETTE(palette, SColorSse2)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); -} - -TEST_CASE("Dye replaceSColor 2 1 sse2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[2]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - DYEPALETTE(palette, SColorSse2)(&data[0], 2); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); -} - -TEST_CASE("Dye replaceSColor 3 1 sse2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[3]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x30, 0x20, 0x30); - DYEPALETTE(palette, SColorSse2)(&data[0], 3); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0x70, 0x60, 0x50, 0x30)); -} - -TEST_CASE("Dye replaceSColor 4 1 sse2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[4]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - DYEPALETTE(palette, SColorSse2)(&data[0], 4); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); -} - -TEST_CASE("Dye replaceSColor 5 1 sse2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[5]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x30); - data[4] = buildHex(0xff, 0x30, 0x20, 0x20); - DYEPALETTE(palette, SColorSse2)(&data[0], 5); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x30)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x20)); -} - -TEST_CASE("Dye replaceSColor 7 1 sse2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[7]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - DYEPALETTE(palette, SColorSse2)(&data[0], 7); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); -} - -TEST_CASE("Dye replaceSColor 8 1 sse2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[8]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - data[7] = buildHex(0xff, 0x30, 0x20, 0x60); - DYEPALETTE(palette, SColorSse2)(&data[0], 8); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); - REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); -} - -TEST_CASE("Dye replaceSColor 9 1 sse2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[9]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - data[7] = buildHex(0xff, 0x30, 0x20, 0x60); - data[8] = buildHex(0xff, 0x30, 0x20, 0x70); - DYEPALETTE(palette, SColorSse2)(&data[0], 9); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); - REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); - REQUIRE(data[8] == buildHex(0x70, 0x60, 0x50, 0x70)); -} - -TEST_CASE("Dye replaceSColor 10 1 sse2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[10]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - data[7] = buildHex(0xff, 0x30, 0x20, 0x60); - data[8] = buildHex(0x12, 0x34, 0x56, 0x70); - data[9] = buildHex(0xff, 0x30, 0x20, 0x80); - DYEPALETTE(palette, SColorSse2)(&data[0], 10); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); - REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); - REQUIRE(data[8] == buildHex(0x00, 0x00, 0x00, 0x70)); - REQUIRE(data[9] == buildHex(0x70, 0x60, 0x50, 0x80)); -} - -TEST_CASE("Dye replaceSColor 1 1 avx2", "") -{ - DyePalette palette("#00ff00,000011", 6); - uint32_t data[1]; - data[0] = buildHex(0x10, 0x03, 0x02, 0x01); - DYEPALETTE(palette, SColorAvx2)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); -} - -TEST_CASE("Dye replaceSColor 1 2 avx2", "") -{ - DyePalette palette("#403020,706050", 6); - uint32_t data[1]; - data[0] = buildHex(0x40, 0x30, 0x20, 0x10); - DYEPALETTE(palette, SColorAvx2)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); -} - -TEST_CASE("Dye replaceSColor 1 3 avx2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[1]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - DYEPALETTE(palette, SColorAvx2)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); -} - -TEST_CASE("Dye replaceSColor 2 1 avx2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[2]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - DYEPALETTE(palette, SColorAvx2)(&data[0], 2); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); -} - -TEST_CASE("Dye replaceSColor 3 1 avx2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[3]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x30, 0x20, 0x30); - DYEPALETTE(palette, SColorAvx2)(&data[0], 3); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0x70, 0x60, 0x50, 0x30)); -} - -TEST_CASE("Dye replaceSColor 4 1 avx2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[4]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - DYEPALETTE(palette, SColorAvx2)(&data[0], 4); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); -} - -TEST_CASE("Dye replaceSColor 5 1 avx2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[5]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x30); - data[4] = buildHex(0xff, 0x30, 0x20, 0x20); - DYEPALETTE(palette, SColorAvx2)(&data[0], 5); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x30)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x20)); -} - -TEST_CASE("Dye replaceSColor 7 1 avx2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[7]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - DYEPALETTE(palette, SColorAvx2)(&data[0], 7); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); -} - -TEST_CASE("Dye replaceSColor 8 1 avx2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[8]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - data[7] = buildHex(0xff, 0x30, 0x20, 0x60); - DYEPALETTE(palette, SColorAvx2)(&data[0], 8); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); - REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); -} - -TEST_CASE("Dye replaceSColor 9 1 avx2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[9]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - data[7] = buildHex(0xff, 0x30, 0x20, 0x60); - data[8] = buildHex(0xff, 0x30, 0x20, 0x70); - DYEPALETTE(palette, SColorAvx2)(&data[0], 9); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); - REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); - REQUIRE(data[8] == buildHex(0x70, 0x60, 0x50, 0x70)); -} - -TEST_CASE("Dye replaceSColor 10 1 avx2", "") -{ - DyePalette palette("#123456,000000,ff3020,706050", 6); - uint32_t data[10]; - data[0] = buildHex(0xff, 0x30, 0x20, 0x10); - data[1] = buildHex(0xff, 0x30, 0x20, 0x20); - data[2] = buildHex(0xff, 0x40, 0x20, 0x10); - data[3] = buildHex(0xff, 0x30, 0x20, 0x20); - data[4] = buildHex(0xff, 0x30, 0x20, 0x10); - data[5] = buildHex(0xff, 0x30, 0x20, 0x40); - data[6] = buildHex(0xff, 0x40, 0x20, 0x50); - data[7] = buildHex(0xff, 0x30, 0x20, 0x60); - data[8] = buildHex(0x12, 0x34, 0x56, 0x70); - data[9] = buildHex(0xff, 0x30, 0x20, 0x80); - DYEPALETTE(palette, SColorAvx2)(&data[0], 10); - REQUIRE(data[0] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[1] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[2] == buildHex(0xff, 0x40, 0x20, 0x10)); - REQUIRE(data[3] == buildHex(0x70, 0x60, 0x50, 0x20)); - REQUIRE(data[4] == buildHex(0x70, 0x60, 0x50, 0x10)); - REQUIRE(data[5] == buildHex(0x70, 0x60, 0x50, 0x40)); - REQUIRE(data[6] == buildHex(0xff, 0x40, 0x20, 0x50)); - REQUIRE(data[7] == buildHex(0x70, 0x60, 0x50, 0x60)); - REQUIRE(data[8] == buildHex(0x00, 0x00, 0x00, 0x70)); - REQUIRE(data[9] == buildHex(0x70, 0x60, 0x50, 0x80)); -} - - -TEST_CASE("Dye replaceAColor 1 1", "") -{ - DyePalette palette("#00ff0010,00001120", 8); - uint32_t data[1]; - data[0] = buildHex(0x10, 0x03, 0x02, 0x01); - DYEPALETTE(palette, AColor)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); -} - -TEST_CASE("Dye replaceAColor 1 2", "") -{ - DyePalette palette("#02ff0120,040311ff", 8); - uint32_t data[1]; - data[0] = buildHex(0x02, 0xff, 0x01, 0x20); - DYEPALETTE(palette, AColor)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x04, 0x03, 0x11, 0xff)); -} - -TEST_CASE("Dye replaceAColor 1 3", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[1]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - DYEPALETTE(palette, AColor)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); -} - -TEST_CASE("Dye replaceAColor 2 1", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[2]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColor)(&data[0], 2); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 3 1", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[3]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x50, 0x40, 0x40, 0x30); - data[2] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColor)(&data[0], 3); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x50, 0x40, 0x40, 0x30)); - REQUIRE(data[2] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 4 1", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[4]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColor)(&data[0], 4); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 5 1", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[5]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x50, 0x40, 0x40, 0x60); - data[4] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColor)(&data[0], 5); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x50, 0x40, 0x40, 0x60)); - REQUIRE(data[4] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 7 1", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[7]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - DYEPALETTE(palette, AColor)(&data[0], 7); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); -} - -TEST_CASE("Dye replaceAColor 8 1", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[8]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - data[7] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColor)(&data[0], 8); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[7] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 9 1", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[9]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - data[7] = buildHex(0x02, 0x40, 0x40, 0x40); - data[8] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColor)(&data[0], 9); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); - REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 10 1", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[10]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - data[7] = buildHex(0x02, 0x40, 0x40, 0x40); - data[8] = buildHex(0x40, 0x40, 0x40, 0x40); - data[9] = buildHex(0x01, 0x00, 0xee, 0x40); - DYEPALETTE(palette, AColor)(&data[0], 10); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); - REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[9] == buildHex(0x10, 0x20, 0x30, 0xff)); -} - -TEST_CASE("Dye replaceAColor 1 1 default", "") -{ - DyePalette palette("#00ff0010,00001120", 8); - uint32_t data[1]; - data[0] = buildHex(0x10, 0x03, 0x02, 0x01); - palette.replaceAColorDefault(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); -} - -TEST_CASE("Dye replaceAColor 1 2 default", "") -{ - DyePalette palette("#02ff0120,040311ff", 8); - uint32_t data[1]; - data[0] = buildHex(0x02, 0xff, 0x01, 0x20); - palette.replaceAColorDefault(&data[0], 1); - REQUIRE(data[0] == buildHex(0x04, 0x03, 0x11, 0xff)); -} - -TEST_CASE("Dye replaceAColor 1 3 default", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[1]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - palette.replaceAColorDefault(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); -} - -TEST_CASE("Dye replaceAColor 2 1 default", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[2]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - palette.replaceAColorDefault(&data[0], 2); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 3 1 default", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[3]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x50, 0x40, 0x40, 0x30); - data[2] = buildHex(0x40, 0x40, 0x40, 0x40); - palette.replaceAColorDefault(&data[0], 3); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x50, 0x40, 0x40, 0x30)); - REQUIRE(data[2] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 4 1 default", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[4]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - palette.replaceAColorDefault(&data[0], 4); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 5 1 default", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[5]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x50, 0x40, 0x40, 0x60); - data[4] = buildHex(0x40, 0x40, 0x40, 0x40); - palette.replaceAColorDefault(&data[0], 5); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x50, 0x40, 0x40, 0x60)); - REQUIRE(data[4] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 7 1 default", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[7]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - palette.replaceAColorDefault(&data[0], 7); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); -} - -TEST_CASE("Dye replaceAColor 8 1 default", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[8]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - data[7] = buildHex(0x40, 0x40, 0x40, 0x40); - palette.replaceAColorDefault(&data[0], 8); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[7] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 9 1 default", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[9]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - data[7] = buildHex(0x02, 0x40, 0x40, 0x40); - data[8] = buildHex(0x40, 0x40, 0x40, 0x40); - palette.replaceAColorDefault(&data[0], 9); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); - REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 10 1 default", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[10]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - data[7] = buildHex(0x02, 0x40, 0x40, 0x40); - data[8] = buildHex(0x40, 0x40, 0x40, 0x40); - data[9] = buildHex(0x01, 0x00, 0xee, 0x40); - palette.replaceAColorDefault(&data[0], 10); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); - REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[9] == buildHex(0x10, 0x20, 0x30, 0xff)); -} - -TEST_CASE("Dye replaceAColor 1 1 sse2", "") -{ - DyePalette palette("#00ff0010,00001120", 8); - uint32_t data[1]; - data[0] = buildHex(0x10, 0x03, 0x02, 0x01); - DYEPALETTE(palette, AColorSse2)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); -} - -TEST_CASE("Dye replaceAColor 1 2 sse2", "") -{ - DyePalette palette("#02ff0120,040311ff", 8); - uint32_t data[1]; - data[0] = buildHex(0x02, 0xff, 0x01, 0x20); - DYEPALETTE(palette, AColorSse2)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x04, 0x03, 0x11, 0xff)); -} - -TEST_CASE("Dye replaceAColor 1 3 sse2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[1]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - DYEPALETTE(palette, AColorSse2)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); -} - -TEST_CASE("Dye replaceAColor 2 1 sse2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[2]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColorSse2)(&data[0], 2); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 3 1 sse2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[3]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x50, 0x40, 0x40, 0x30); - data[2] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColorSse2)(&data[0], 3); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x50, 0x40, 0x40, 0x30)); - REQUIRE(data[2] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 4 1 sse2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[4]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColorSse2)(&data[0], 4); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 5 1 sse2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[5]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x50, 0x40, 0x40, 0x60); - data[4] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColorSse2)(&data[0], 5); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x50, 0x40, 0x40, 0x60)); - REQUIRE(data[4] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 7 1 sse2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[7]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - DYEPALETTE(palette, AColorSse2)(&data[0], 7); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); -} - -TEST_CASE("Dye replaceAColor 8 1 sse2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[8]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - data[7] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColorSse2)(&data[0], 8); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[7] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 9 1 sse2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[9]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - data[7] = buildHex(0x02, 0x40, 0x40, 0x40); - data[8] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColorSse2)(&data[0], 9); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); - REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 10 1 sse2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[10]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - data[7] = buildHex(0x02, 0x40, 0x40, 0x40); - data[8] = buildHex(0x40, 0x40, 0x40, 0x40); - data[9] = buildHex(0x01, 0x00, 0xee, 0x40); - DYEPALETTE(palette, AColorSse2)(&data[0], 10); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); - REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[9] == buildHex(0x10, 0x20, 0x30, 0xff)); -} - -TEST_CASE("Dye replaceAColor 1 1 avx2", "") -{ - DyePalette palette("#00ff0010,00001120", 8); - uint32_t data[1]; - data[0] = buildHex(0x10, 0x03, 0x02, 0x01); - DYEPALETTE(palette, AColorAvx2)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x03, 0x02, 0x01)); -} - -TEST_CASE("Dye replaceAColor 1 2 avx2", "") -{ - DyePalette palette("#02ff0120,040311ff", 8); - uint32_t data[1]; - data[0] = buildHex(0x02, 0xff, 0x01, 0x20); - DYEPALETTE(palette, AColorAvx2)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x04, 0x03, 0x11, 0xff)); -} - -TEST_CASE("Dye replaceAColor 1 3 avx2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[1]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - DYEPALETTE(palette, AColorAvx2)(&data[0], 1); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); -} - -TEST_CASE("Dye replaceAColor 2 1 avx2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[2]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColorAvx2)(&data[0], 2); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 3 1 avx2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[3]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x50, 0x40, 0x40, 0x30); - data[2] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColorAvx2)(&data[0], 3); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x50, 0x40, 0x40, 0x30)); - REQUIRE(data[2] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 4 1 avx2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[4]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColorAvx2)(&data[0], 4); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 5 1 avx2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[5]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x50, 0x40, 0x40, 0x60); - data[4] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColorAvx2)(&data[0], 5); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x50, 0x40, 0x40, 0x60)); - REQUIRE(data[4] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 7 1 avx2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[7]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - DYEPALETTE(palette, AColorAvx2)(&data[0], 7); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); -} - -TEST_CASE("Dye replaceAColor 8 1 avx2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[8]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - data[7] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColorAvx2)(&data[0], 8); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[7] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 9 1 avx2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[9]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - data[7] = buildHex(0x02, 0x40, 0x40, 0x40); - data[8] = buildHex(0x40, 0x40, 0x40, 0x40); - DYEPALETTE(palette, AColorAvx2)(&data[0], 9); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); - REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); -} - -TEST_CASE("Dye replaceAColor 10 1 avx2", "") -{ - DyePalette palette("#40404040,20000000,0100ee40,102030ff", 8); - uint32_t data[10]; - data[0] = buildHex(0x01, 0x00, 0xee, 0x40); - data[1] = buildHex(0x40, 0x40, 0x40, 0x40); - data[2] = buildHex(0x01, 0x00, 0xee, 0x50); - data[3] = buildHex(0x40, 0x40, 0x40, 0x40); - data[4] = buildHex(0x01, 0x00, 0xee, 0x40); - data[5] = buildHex(0x40, 0x40, 0x41, 0x40); - data[6] = buildHex(0x01, 0x00, 0xee, 0x50); - data[7] = buildHex(0x02, 0x40, 0x40, 0x40); - data[8] = buildHex(0x40, 0x40, 0x40, 0x40); - data[9] = buildHex(0x01, 0x00, 0xee, 0x40); - DYEPALETTE(palette, AColorAvx2)(&data[0], 10); - REQUIRE(data[0] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[1] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[2] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[3] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[4] == buildHex(0x10, 0x20, 0x30, 0xff)); - REQUIRE(data[5] == buildHex(0x40, 0x40, 0x41, 0x40)); - REQUIRE(data[6] == buildHex(0x01, 0x00, 0xee, 0x50)); - REQUIRE(data[7] == buildHex(0x02, 0x40, 0x40, 0x40)); - REQUIRE(data[8] == buildHex(0x20, 0x00, 0x00, 0x00)); - REQUIRE(data[9] == buildHex(0x10, 0x20, 0x30, 0xff)); -} - - -TEST_CASE("Dye normalDye 1", "") -{ - Dye dye("R:#203040,506070"); - uint32_t data[1]; - data[0] = buildHex(0x50, 0x00, 0x00, 0x55); - dye.normalDye(&data[0], 1); - REQUIRE(data[0] == buildHex(0x14, 0x1e, 0x28, 0x55)); -} - -TEST_CASE("Dye normalDye 2", "") -{ - Dye dye("G:#203040,506070"); - uint32_t data[1]; - data[0] = buildHex(0x00, 0x50, 0x00, 0x60); - dye.normalDye(&data[0], 1); - REQUIRE(data[0] == buildHex(0x14, 0x1e, 0x28, 0x60)); -} - - -#ifdef USE_OPENGL -TEST_CASE("Dye normalOGLDye 1", "") -{ - Dye dye("R:#203040,506070"); - uint32_t data[1]; - data[0] = buildHex(0x50, 0x00, 0x00, 0x55); - dye.normalOGLDye(&data[0], 1); - REQUIRE(data[0] == buildHex(0x50, 0x2a, 0x20, 0x15)); -} -#endif // USE_OPENGL - -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]); - } - image2->decRef(); - image1->decRef(); -} - -TEST_CASE("Dye real dye", "") -{ - setEnv("SDL_VIDEODRIVER", "dummy"); - - client = new Client; - SDL_Init(SDL_INIT_VIDEO); - logger = new Logger(); - VirtFs::mountDirSilent("data", Append_false); - VirtFs::mountDirSilent("../data", Append_false); - VirtFs::mountDirSilent("data/test", Append_false); - VirtFs::mountDirSilent("../data/test", Append_false); - -#ifdef USE_SDL2 - imageHelper = new SurfaceImageHelper; - - SDLImageHelper::setRenderer(graphicsManager.createRenderer( - graphicsManager.createWindow(640, 480, 0, - SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE)); -#else // USE_SDL2 - - imageHelper = new SDLImageHelper; - - graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE); -#endif // USE_SDL2 - - ActorSprite::load(); - - 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"); - } - delete2(client); - VirtFs::unmountDirSilent("data"); - VirtFs::unmountDirSilent("../data"); - VirtFs::unmountDirSilent("data/test"); - VirtFs::unmountDirSilent("../data/test"); - delete2(logger); -// VirtFs::deinit(); -} - -TEST_CASE("Dye leak test2", "") -{ - logger = new Logger(); - REQUIRE(gui == nullptr); - ResourceManager::cleanOrphans(true); - ResourceManager::deleteInstance(); - delete2(logger); -} diff --git a/src/unittests/resources/dye/dyepalette.cc b/src/unittests/resources/dye/dyepalette.cc new file mode 100644 index 000000000..0e99e9871 --- /dev/null +++ b/src/unittests/resources/dye/dyepalette.cc @@ -0,0 +1,422 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013-2017 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 . + */ + +#include "unittests/unittests.h" + +#include "client.h" +#include "configuration.h" +#include "configmanager.h" +#include "dirs.h" +#include "graphicsmanager.h" + +#include "being/actorsprite.h" + +#include "fs/virtfs/fs.h" + +#include "gui/gui.h" +#include "gui/theme.h" + +#include "render/sdlgraphics.h" + +#include "resources/sdlimagehelper.h" + +#include "resources/db/palettedb.h" + +#include "resources/dye/dyepalette.h" + +#include "resources/resourcemanager/resourcemanager.h" + +#include "utils/delete2.h" +#include "utils/env.h" + +PRAGMA48(GCC diagnostic push) +PRAGMA48(GCC diagnostic ignored "-Wshadow") +#ifndef USE_SDL2 +#include +#endif // USE_SDL2 +PRAGMA48(GCC diagnostic pop) + +#include "debug.h" + +TEST_CASE("DyePalette leak test1", "") +{ + logger = new Logger(); + REQUIRE(gui == nullptr); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); + delete2(logger); +} + +TEST_CASE("DyePalette tests", "") +{ + setEnv("SDL_VIDEODRIVER", "dummy"); + + client = new Client; + XML::initXML(); + SDL_Init(SDL_INIT_VIDEO); + logger = new Logger(); + VirtFs::mountDirSilent("data", Append_false); + VirtFs::mountDirSilent("../data", Append_false); + VirtFs::mountDirSilent("data/test", Append_false); + VirtFs::mountDirSilent("../data/test", Append_false); + + mainGraphics = new SDLGraphics; + imageHelper = new SDLImageHelper(); +#ifdef USE_SDL2 + SDLImageHelper::setRenderer(graphicsManager.createRenderer( + graphicsManager.createWindow(640, 480, 0, + SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE)); +#else // USE_SDL2 + + graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE); +#endif // USE_SDL2 + + theme = new Theme; + Theme::selectSkin(); + + Dirs::initRootDir(); + Dirs::initHomeDir(); + + ConfigManager::initConfiguration(); + getConfigDefaults2(config.getDefaultValues()); + branding.setDefaultValues(getBrandingDefaults()); + + ActorSprite::load(); + gui = new Gui(); + gui->postInit(mainGraphics); + paths.setDefaultValues(getPathsDefaults()); + 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); + } + + SECTION("palette 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("palette 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("palette test 7") + { + 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("palette test 8") + { + 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 9") + { + 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("palette test 10") + { + 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("palette test 11") + { + 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 12") + { + DyePalette palette("@Untitled1,334455", 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] == 0x33); + REQUIRE(palette.mColors[1].value[1] == 0x44); + REQUIRE(palette.mColors[1].value[2] == 0x55); + REQUIRE(palette.mColors[1].value[3] == 0x00); + } + + SECTION("palette test 13") + { + DyePalette palette("@Untitled1,33445566", 8); + 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] == 0x33); + REQUIRE(palette.mColors[1].value[1] == 0x44); + REQUIRE(palette.mColors[1].value[2] == 0x55); + REQUIRE(palette.mColors[1].value[3] == 0x66); + } + + SECTION("palette test 14") + { + DyePalette palette("@+77,Untitled1", 8); + 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] == 0x77); + } + + SECTION("palette test 15") + { + DyePalette palette("@+87,Untitled1,Untitled8", 8); + 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] == 0x87); + + 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] == 0x87); + } + + SECTION("palette test 16") + { + DyePalette palette("@+87,Untitled1,+34,Untitled8", 8); + 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] == 0x87); + + 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] == 0x34); + } + + SECTION("palette test 17") + { + DyePalette palette("@+12,+23,+77,Untitled1", 8); + 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] == 0x77); + } + delete2(client); + VirtFs::unmountDirSilent("data"); + VirtFs::unmountDirSilent("../data"); + VirtFs::unmountDirSilent("data/test"); + VirtFs::unmountDirSilent("../data/test"); + delete2(logger); +// VirtFs::deinit(); +} + +TEST_CASE("DyePalette leak test2", "") +{ + logger = new Logger(); + REQUIRE(gui == nullptr); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); + delete2(logger); +} diff --git a/src/unittests/resources/dye/dyepalette_unittest.cc b/src/unittests/resources/dye/dyepalette_unittest.cc deleted file mode 100644 index 0e99e9871..000000000 --- a/src/unittests/resources/dye/dyepalette_unittest.cc +++ /dev/null @@ -1,422 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2013-2017 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 . - */ - -#include "unittests/unittests.h" - -#include "client.h" -#include "configuration.h" -#include "configmanager.h" -#include "dirs.h" -#include "graphicsmanager.h" - -#include "being/actorsprite.h" - -#include "fs/virtfs/fs.h" - -#include "gui/gui.h" -#include "gui/theme.h" - -#include "render/sdlgraphics.h" - -#include "resources/sdlimagehelper.h" - -#include "resources/db/palettedb.h" - -#include "resources/dye/dyepalette.h" - -#include "resources/resourcemanager/resourcemanager.h" - -#include "utils/delete2.h" -#include "utils/env.h" - -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#ifndef USE_SDL2 -#include -#endif // USE_SDL2 -PRAGMA48(GCC diagnostic pop) - -#include "debug.h" - -TEST_CASE("DyePalette leak test1", "") -{ - logger = new Logger(); - REQUIRE(gui == nullptr); - ResourceManager::cleanOrphans(true); - ResourceManager::deleteInstance(); - delete2(logger); -} - -TEST_CASE("DyePalette tests", "") -{ - setEnv("SDL_VIDEODRIVER", "dummy"); - - client = new Client; - XML::initXML(); - SDL_Init(SDL_INIT_VIDEO); - logger = new Logger(); - VirtFs::mountDirSilent("data", Append_false); - VirtFs::mountDirSilent("../data", Append_false); - VirtFs::mountDirSilent("data/test", Append_false); - VirtFs::mountDirSilent("../data/test", Append_false); - - mainGraphics = new SDLGraphics; - imageHelper = new SDLImageHelper(); -#ifdef USE_SDL2 - SDLImageHelper::setRenderer(graphicsManager.createRenderer( - graphicsManager.createWindow(640, 480, 0, - SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE)); -#else // USE_SDL2 - - graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE); -#endif // USE_SDL2 - - theme = new Theme; - Theme::selectSkin(); - - Dirs::initRootDir(); - Dirs::initHomeDir(); - - ConfigManager::initConfiguration(); - getConfigDefaults2(config.getDefaultValues()); - branding.setDefaultValues(getBrandingDefaults()); - - ActorSprite::load(); - gui = new Gui(); - gui->postInit(mainGraphics); - paths.setDefaultValues(getPathsDefaults()); - 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); - } - - SECTION("palette 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("palette 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("palette test 7") - { - 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("palette test 8") - { - 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 9") - { - 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("palette test 10") - { - 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("palette test 11") - { - 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 12") - { - DyePalette palette("@Untitled1,334455", 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] == 0x33); - REQUIRE(palette.mColors[1].value[1] == 0x44); - REQUIRE(palette.mColors[1].value[2] == 0x55); - REQUIRE(palette.mColors[1].value[3] == 0x00); - } - - SECTION("palette test 13") - { - DyePalette palette("@Untitled1,33445566", 8); - 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] == 0x33); - REQUIRE(palette.mColors[1].value[1] == 0x44); - REQUIRE(palette.mColors[1].value[2] == 0x55); - REQUIRE(palette.mColors[1].value[3] == 0x66); - } - - SECTION("palette test 14") - { - DyePalette palette("@+77,Untitled1", 8); - 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] == 0x77); - } - - SECTION("palette test 15") - { - DyePalette palette("@+87,Untitled1,Untitled8", 8); - 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] == 0x87); - - 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] == 0x87); - } - - SECTION("palette test 16") - { - DyePalette palette("@+87,Untitled1,+34,Untitled8", 8); - 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] == 0x87); - - 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] == 0x34); - } - - SECTION("palette test 17") - { - DyePalette palette("@+12,+23,+77,Untitled1", 8); - 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] == 0x77); - } - delete2(client); - VirtFs::unmountDirSilent("data"); - VirtFs::unmountDirSilent("../data"); - VirtFs::unmountDirSilent("data/test"); - VirtFs::unmountDirSilent("../data/test"); - delete2(logger); -// VirtFs::deinit(); -} - -TEST_CASE("DyePalette leak test2", "") -{ - logger = new Logger(); - REQUIRE(gui == nullptr); - ResourceManager::cleanOrphans(true); - ResourceManager::deleteInstance(); - delete2(logger); -} diff --git a/src/unittests/resources/map/speciallayer.cc b/src/unittests/resources/map/speciallayer.cc new file mode 100644 index 000000000..0461a98c4 --- /dev/null +++ b/src/unittests/resources/map/speciallayer.cc @@ -0,0 +1,291 @@ +/* + * The ManaPlus Client + * Copyright (C) 2016-2017 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 . + */ + +#include "unittests/unittests.h" + +#include "client.h" +#include "logger.h" + +#include "graphicsmanager.h" + +#include "being/actorsprite.h" + +#include "enums/resources/map/mapitemtype.h" + +#include "fs/virtfs/fs.h" + +#include "gui/gui.h" + +#include "utils/delete2.h" +#include "utils/env.h" + +#include "resources/sdlimagehelper.h" + +#include "resources/map/speciallayer.h" + +#include "resources/resourcemanager/resourcemanager.h" + +#include "debug.h" + +TEST_CASE("SpecialLayer leak test1", "") +{ + logger = new Logger(); + REQUIRE(gui == nullptr); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); + delete2(logger); +} + +TEST_CASE("SpecialLayer updateCache", "") +{ + setEnv("SDL_VIDEODRIVER", "dummy"); + + logger = new Logger; + client = new Client; + VirtFs::mountDirSilent("data", Append_false); + VirtFs::mountDirSilent("../data", Append_false); + + imageHelper = new SDLImageHelper; +#ifdef USE_SDL2 + SDLImageHelper::setRenderer(graphicsManager.createRenderer( + graphicsManager.createWindow(640, 480, 0, + SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE)); +#else // USE_SDL2 + + graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE); +#endif // USE_SDL2 + + ActorSprite::load(); + + SpecialLayer *layer = nullptr; + + SECTION("simple 1") + { + layer = new SpecialLayer("test", + 1, 1); + const int *const cache = layer->getCache(); + REQUIRE(cache[0] == 10000); + layer->setTile(0, 0, MapItemType::ARROW_UP); + layer->updateCache(); + REQUIRE(cache[0] == 10000); + } + + SECTION("simple 2") + { + layer = new SpecialLayer("test", + 2, 1); + const int *const cache = layer->getCache(); + REQUIRE(cache[0] == 10000); + REQUIRE(cache[1] == 10000); + layer->setTile(0, 0, MapItemType::ARROW_UP); + layer->updateCache(); + REQUIRE(cache[0] == 10000); + REQUIRE(cache[1] == 10000); + } + + SECTION("simple 3") + { + layer = new SpecialLayer("test", + 2, 1); + layer->setTile(0, 0, MapItemType::ARROW_UP); + layer->setTile(1, 0, MapItemType::ARROW_DOWN); + const int *const cache = layer->getCache(); + layer->updateCache(); + REQUIRE(cache[0] == 0); + REQUIRE(cache[1] == 10000); + } + + SECTION("simple 4") + { + layer = new SpecialLayer("test", + 2, 1); + layer->setTile(0, 0, MapItemType::ARROW_UP); + layer->setTile(1, 0, MapItemType::ARROW_UP); + const int *const cache = layer->getCache(); + layer->updateCache(); + REQUIRE(cache[0] == 0); + REQUIRE(cache[1] == 10000); + } + + SECTION("simple 4.2") + { + layer = new SpecialLayer("test", + 3, 1); + layer->setTile(0, 0, MapItemType::ARROW_UP); + layer->setTile(2, 0, MapItemType::ARROW_UP); + const int *const cache = layer->getCache(); + layer->updateCache(); + REQUIRE(cache[0] == 1); + REQUIRE(cache[1] == 0); + REQUIRE(cache[2] == 10000); + } + + SECTION("simple 5") + { + layer = new SpecialLayer("test", + 3, 1); + layer->setTile(0, 0, MapItemType::ARROW_UP); + layer->setTile(1, 0, MapItemType::ARROW_UP); + const int *const cache = layer->getCache(); + layer->updateCache(); + REQUIRE(cache[0] == 0); + REQUIRE(cache[1] == 10000); + REQUIRE(cache[2] == 10000); + } + + SECTION("simple 6") + { + layer = new SpecialLayer("test", + 3, 1); + layer->setTile(0, 0, MapItemType::ARROW_UP); + layer->setTile(1, 0, MapItemType::ARROW_UP); + layer->setTile(2, 0, MapItemType::ARROW_DOWN); + const int *const cache = layer->getCache(); + layer->updateCache(); + REQUIRE(cache[0] == 0); + REQUIRE(cache[1] == 0); + REQUIRE(cache[2] == 10000); + } + + SECTION("simple 7") + { + layer = new SpecialLayer("test", + 3, 1); + const int *const cache = layer->getCache(); + layer->updateCache(); + REQUIRE(cache[0] == 10000); + REQUIRE(cache[1] == 10000); + REQUIRE(cache[2] == 10000); + } + + SECTION("simple 8") + { + layer = new SpecialLayer("test", + 3, 1); + layer->setTile(0, 0, MapItemType::EMPTY); + layer->setTile(1, 0, MapItemType::EMPTY); + layer->setTile(2, 0, MapItemType::EMPTY); + const int *const cache = layer->getCache(); + layer->updateCache(); + REQUIRE(cache[0] == 10000); + REQUIRE(cache[1] == 10000); + REQUIRE(cache[2] == 10000); + } + + SECTION("simple 9") + { + layer = new SpecialLayer("test", + 2, 1); + const int *const cache = layer->getCache(); + REQUIRE(cache[0] == 10000); + REQUIRE(cache[1] == 10000); + layer->setTile(1, 0, MapItemType::ARROW_UP); + layer->updateCache(); + REQUIRE(cache[0] == 0); + REQUIRE(cache[1] == 10000); + } + + SECTION("normal 1") + { + layer = new SpecialLayer("test", + 100, 100); + layer->setTile(1, 10, MapItemType::ARROW_UP); + layer->setTile(2, 10, MapItemType::ARROW_UP); + layer->setTile(3, 10, MapItemType::ARROW_UP); + layer->setTile(4, 10, MapItemType::ARROW_DOWN); + layer->setTile(5, 10, MapItemType::EMPTY); + layer->setTile(6, 10, MapItemType::ARROW_DOWN); + layer->setTile(7, 10, MapItemType::EMPTY); + layer->setTile(8, 10, MapItemType::EMPTY); + layer->setTile(9, 10, MapItemType::ARROW_DOWN); + layer->setTile(10, 10, MapItemType::ARROW_DOWN); + layer->setTile(11, 10, MapItemType::ARROW_LEFT); + layer->setTile(12, 10, MapItemType::EMPTY); + layer->setTile(13, 10, MapItemType::EMPTY); + layer->setTile(14, 10, MapItemType::EMPTY); + layer->setTile(15, 10, MapItemType::ARROW_UP); + layer->setTile(16, 10, MapItemType::ARROW_UP); + layer->setTile(17, 10, MapItemType::ARROW_UP); + const int *const cache = layer->getCache(); + layer->updateCache(); + + REQUIRE(cache[10 * 100 + 0] == 0); + REQUIRE(cache[10 * 100 + 1] == 0); + REQUIRE(cache[10 * 100 + 2] == 0); + REQUIRE(cache[10 * 100 + 3] == 0); + REQUIRE(cache[10 * 100 + 4] == 1); + REQUIRE(cache[10 * 100 + 5] == 0); + REQUIRE(cache[10 * 100 + 6] == 2); + REQUIRE(cache[10 * 100 + 7] == 1); + REQUIRE(cache[10 * 100 + 8] == 0); + REQUIRE(cache[10 * 100 + 9] == 0); + REQUIRE(cache[10 * 100 + 10] == 0); + REQUIRE(cache[10 * 100 + 11] == 3); + REQUIRE(cache[10 * 100 + 12] == 2); + REQUIRE(cache[10 * 100 + 13] == 1); + REQUIRE(cache[10 * 100 + 14] == 0); + REQUIRE(cache[10 * 100 + 15] == 0); + REQUIRE(cache[10 * 100 + 16] == 0); + REQUIRE(cache[10 * 100 + 17] == 10000); + } + + SECTION("normal2") + { + const int maxX = 100; + const int maxY = 100; + layer = new SpecialLayer("test", + maxX, maxY); + const int *const cache = layer->getCache(); + for (int x = 0; x < maxX; x ++) + { + for (int y = 0; y < maxY; y ++) + { + layer->setTile(x, y, MapItemType::ARROW_UP); + REQUIRE(layer->getTiles()[x + y * maxX] != nullptr); + } + } + layer->updateCache(); + + for (int y = 0; y < maxY; y ++) + { + for (int x = 0; x < maxX - 1; x ++) + { + REQUIRE(cache[y * maxX + x] == 0); + } + REQUIRE(cache[y * maxX + maxX - 1] == 10000); + } + } + + delete layer; + ResourceManager::cleanOrphans(); + delete2(client); + VirtFs::unmountDirSilent("data"); + VirtFs::unmountDirSilent("../data"); + delete2(logger); +} + +TEST_CASE("SpecialLayer leak test2", "") +{ + logger = new Logger(); + REQUIRE(gui == nullptr); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); + delete2(logger); +} diff --git a/src/unittests/resources/map/speciallayer_unittest.cc b/src/unittests/resources/map/speciallayer_unittest.cc deleted file mode 100644 index 0461a98c4..000000000 --- a/src/unittests/resources/map/speciallayer_unittest.cc +++ /dev/null @@ -1,291 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2016-2017 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 . - */ - -#include "unittests/unittests.h" - -#include "client.h" -#include "logger.h" - -#include "graphicsmanager.h" - -#include "being/actorsprite.h" - -#include "enums/resources/map/mapitemtype.h" - -#include "fs/virtfs/fs.h" - -#include "gui/gui.h" - -#include "utils/delete2.h" -#include "utils/env.h" - -#include "resources/sdlimagehelper.h" - -#include "resources/map/speciallayer.h" - -#include "resources/resourcemanager/resourcemanager.h" - -#include "debug.h" - -TEST_CASE("SpecialLayer leak test1", "") -{ - logger = new Logger(); - REQUIRE(gui == nullptr); - ResourceManager::cleanOrphans(true); - ResourceManager::deleteInstance(); - delete2(logger); -} - -TEST_CASE("SpecialLayer updateCache", "") -{ - setEnv("SDL_VIDEODRIVER", "dummy"); - - logger = new Logger; - client = new Client; - VirtFs::mountDirSilent("data", Append_false); - VirtFs::mountDirSilent("../data", Append_false); - - imageHelper = new SDLImageHelper; -#ifdef USE_SDL2 - SDLImageHelper::setRenderer(graphicsManager.createRenderer( - graphicsManager.createWindow(640, 480, 0, - SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE)); -#else // USE_SDL2 - - graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE); -#endif // USE_SDL2 - - ActorSprite::load(); - - SpecialLayer *layer = nullptr; - - SECTION("simple 1") - { - layer = new SpecialLayer("test", - 1, 1); - const int *const cache = layer->getCache(); - REQUIRE(cache[0] == 10000); - layer->setTile(0, 0, MapItemType::ARROW_UP); - layer->updateCache(); - REQUIRE(cache[0] == 10000); - } - - SECTION("simple 2") - { - layer = new SpecialLayer("test", - 2, 1); - const int *const cache = layer->getCache(); - REQUIRE(cache[0] == 10000); - REQUIRE(cache[1] == 10000); - layer->setTile(0, 0, MapItemType::ARROW_UP); - layer->updateCache(); - REQUIRE(cache[0] == 10000); - REQUIRE(cache[1] == 10000); - } - - SECTION("simple 3") - { - layer = new SpecialLayer("test", - 2, 1); - layer->setTile(0, 0, MapItemType::ARROW_UP); - layer->setTile(1, 0, MapItemType::ARROW_DOWN); - const int *const cache = layer->getCache(); - layer->updateCache(); - REQUIRE(cache[0] == 0); - REQUIRE(cache[1] == 10000); - } - - SECTION("simple 4") - { - layer = new SpecialLayer("test", - 2, 1); - layer->setTile(0, 0, MapItemType::ARROW_UP); - layer->setTile(1, 0, MapItemType::ARROW_UP); - const int *const cache = layer->getCache(); - layer->updateCache(); - REQUIRE(cache[0] == 0); - REQUIRE(cache[1] == 10000); - } - - SECTION("simple 4.2") - { - layer = new SpecialLayer("test", - 3, 1); - layer->setTile(0, 0, MapItemType::ARROW_UP); - layer->setTile(2, 0, MapItemType::ARROW_UP); - const int *const cache = layer->getCache(); - layer->updateCache(); - REQUIRE(cache[0] == 1); - REQUIRE(cache[1] == 0); - REQUIRE(cache[2] == 10000); - } - - SECTION("simple 5") - { - layer = new SpecialLayer("test", - 3, 1); - layer->setTile(0, 0, MapItemType::ARROW_UP); - layer->setTile(1, 0, MapItemType::ARROW_UP); - const int *const cache = layer->getCache(); - layer->updateCache(); - REQUIRE(cache[0] == 0); - REQUIRE(cache[1] == 10000); - REQUIRE(cache[2] == 10000); - } - - SECTION("simple 6") - { - layer = new SpecialLayer("test", - 3, 1); - layer->setTile(0, 0, MapItemType::ARROW_UP); - layer->setTile(1, 0, MapItemType::ARROW_UP); - layer->setTile(2, 0, MapItemType::ARROW_DOWN); - const int *const cache = layer->getCache(); - layer->updateCache(); - REQUIRE(cache[0] == 0); - REQUIRE(cache[1] == 0); - REQUIRE(cache[2] == 10000); - } - - SECTION("simple 7") - { - layer = new SpecialLayer("test", - 3, 1); - const int *const cache = layer->getCache(); - layer->updateCache(); - REQUIRE(cache[0] == 10000); - REQUIRE(cache[1] == 10000); - REQUIRE(cache[2] == 10000); - } - - SECTION("simple 8") - { - layer = new SpecialLayer("test", - 3, 1); - layer->setTile(0, 0, MapItemType::EMPTY); - layer->setTile(1, 0, MapItemType::EMPTY); - layer->setTile(2, 0, MapItemType::EMPTY); - const int *const cache = layer->getCache(); - layer->updateCache(); - REQUIRE(cache[0] == 10000); - REQUIRE(cache[1] == 10000); - REQUIRE(cache[2] == 10000); - } - - SECTION("simple 9") - { - layer = new SpecialLayer("test", - 2, 1); - const int *const cache = layer->getCache(); - REQUIRE(cache[0] == 10000); - REQUIRE(cache[1] == 10000); - layer->setTile(1, 0, MapItemType::ARROW_UP); - layer->updateCache(); - REQUIRE(cache[0] == 0); - REQUIRE(cache[1] == 10000); - } - - SECTION("normal 1") - { - layer = new SpecialLayer("test", - 100, 100); - layer->setTile(1, 10, MapItemType::ARROW_UP); - layer->setTile(2, 10, MapItemType::ARROW_UP); - layer->setTile(3, 10, MapItemType::ARROW_UP); - layer->setTile(4, 10, MapItemType::ARROW_DOWN); - layer->setTile(5, 10, MapItemType::EMPTY); - layer->setTile(6, 10, MapItemType::ARROW_DOWN); - layer->setTile(7, 10, MapItemType::EMPTY); - layer->setTile(8, 10, MapItemType::EMPTY); - layer->setTile(9, 10, MapItemType::ARROW_DOWN); - layer->setTile(10, 10, MapItemType::ARROW_DOWN); - layer->setTile(11, 10, MapItemType::ARROW_LEFT); - layer->setTile(12, 10, MapItemType::EMPTY); - layer->setTile(13, 10, MapItemType::EMPTY); - layer->setTile(14, 10, MapItemType::EMPTY); - layer->setTile(15, 10, MapItemType::ARROW_UP); - layer->setTile(16, 10, MapItemType::ARROW_UP); - layer->setTile(17, 10, MapItemType::ARROW_UP); - const int *const cache = layer->getCache(); - layer->updateCache(); - - REQUIRE(cache[10 * 100 + 0] == 0); - REQUIRE(cache[10 * 100 + 1] == 0); - REQUIRE(cache[10 * 100 + 2] == 0); - REQUIRE(cache[10 * 100 + 3] == 0); - REQUIRE(cache[10 * 100 + 4] == 1); - REQUIRE(cache[10 * 100 + 5] == 0); - REQUIRE(cache[10 * 100 + 6] == 2); - REQUIRE(cache[10 * 100 + 7] == 1); - REQUIRE(cache[10 * 100 + 8] == 0); - REQUIRE(cache[10 * 100 + 9] == 0); - REQUIRE(cache[10 * 100 + 10] == 0); - REQUIRE(cache[10 * 100 + 11] == 3); - REQUIRE(cache[10 * 100 + 12] == 2); - REQUIRE(cache[10 * 100 + 13] == 1); - REQUIRE(cache[10 * 100 + 14] == 0); - REQUIRE(cache[10 * 100 + 15] == 0); - REQUIRE(cache[10 * 100 + 16] == 0); - REQUIRE(cache[10 * 100 + 17] == 10000); - } - - SECTION("normal2") - { - const int maxX = 100; - const int maxY = 100; - layer = new SpecialLayer("test", - maxX, maxY); - const int *const cache = layer->getCache(); - for (int x = 0; x < maxX; x ++) - { - for (int y = 0; y < maxY; y ++) - { - layer->setTile(x, y, MapItemType::ARROW_UP); - REQUIRE(layer->getTiles()[x + y * maxX] != nullptr); - } - } - layer->updateCache(); - - for (int y = 0; y < maxY; y ++) - { - for (int x = 0; x < maxX - 1; x ++) - { - REQUIRE(cache[y * maxX + x] == 0); - } - REQUIRE(cache[y * maxX + maxX - 1] == 10000); - } - } - - delete layer; - ResourceManager::cleanOrphans(); - delete2(client); - VirtFs::unmountDirSilent("data"); - VirtFs::unmountDirSilent("../data"); - delete2(logger); -} - -TEST_CASE("SpecialLayer leak test2", "") -{ - logger = new Logger(); - REQUIRE(gui == nullptr); - ResourceManager::cleanOrphans(true); - ResourceManager::deleteInstance(); - delete2(logger); -} diff --git a/src/unittests/resources/mstack.cc b/src/unittests/resources/mstack.cc new file mode 100644 index 000000000..1d2233803 --- /dev/null +++ b/src/unittests/resources/mstack.cc @@ -0,0 +1,165 @@ +/* + * The ManaPlus Client + * Copyright (C) 2015-2017 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 . + */ + +#include "unittests/unittests.h" + +#include "gui/cliprect.h" + +#include "resources/mstack.h" + +#include "debug.h" + +TEST_CASE("mstack push 1", "") +{ + MStack stack(10); + REQUIRE(-1 == (stack.mPointer - stack.mStack)); + REQUIRE(0 == stack.mStack[0].xOffset); + + ClipRect &val1 = stack.push(); + val1.xOffset = 10; + ClipRect &val2 = stack.top(); + REQUIRE(0 == stack.mPointer - stack.mStack); + REQUIRE(10 == val2.xOffset); + REQUIRE(10 == stack.mStack[0].xOffset); + REQUIRE(0 == stack.mStack[1].xOffset); + + val2.yOffset = 2; + REQUIRE(2 == val1.yOffset); +} + +TEST_CASE("mstack push 2", "") +{ + MStack stack(10); + ClipRect &val1 = stack.push(); + val1.xOffset = 10; + const ClipRect &val2 = stack.top(); + REQUIRE(10 == val2.xOffset); + REQUIRE(10 == stack.mStack[0].xOffset); + + val1.yOffset = 2; + REQUIRE(2 == val2.yOffset); + REQUIRE(2 == stack.mStack[0].yOffset); +} + +TEST_CASE("mstack push 3", "") +{ + MStack stack(10); + ClipRect &val1 = stack.push(); + val1.xOffset = 10; + ClipRect &val2 = stack.top(); + REQUIRE(10 == val2.xOffset); + REQUIRE(10 == stack.mStack[0].xOffset); +} + +TEST_CASE("mstack push 4", "") +{ + MStack stack(10); + ClipRect &val1 = stack.push(); + val1.xOffset = 10; + REQUIRE(10 == val1.xOffset); + REQUIRE(10 == stack.mStack[0].xOffset); + REQUIRE(0 == stack.mStack[1].xOffset); + REQUIRE(0 == stack.mStack[2].xOffset); + + ClipRect &val2 = stack.push(); + val2.xOffset = 20; + REQUIRE(20 == val2.xOffset); + REQUIRE(10 == stack.mStack[0].xOffset); + REQUIRE(20 == stack.mStack[1].xOffset); + REQUIRE(0 == stack.mStack[2].xOffset); + + ClipRect &val3 = stack.push(); + val3.xOffset = 30; + REQUIRE(30 == val3.xOffset); + REQUIRE(10 == stack.mStack[0].xOffset); + REQUIRE(20 == stack.mStack[1].xOffset); + REQUIRE(30 == stack.mStack[2].xOffset); +} + +TEST_CASE("mstack pop 1", "") +{ + MStack stack(10); + ClipRect &val1 = stack.push(); + val1.xOffset = 10; + REQUIRE(10 == stack.mStack[0].xOffset); + + stack.pop(); + REQUIRE(-1 == stack.mPointer - stack.mStack); +} + +TEST_CASE("mstack pop 2", "") +{ + MStack stack(10); + ClipRect &val1 = stack.push(); + REQUIRE(0 == stack.mPointer - stack.mStack); + + val1.xOffset = 10; + REQUIRE(10 == stack.mStack[0].xOffset); + + ClipRect &val2 = stack.push(); + REQUIRE(1 == stack.mPointer - stack.mStack); + + val2.xOffset = 20; + REQUIRE(10 == stack.mStack[0].xOffset); + REQUIRE(20 == stack.mStack[1].xOffset); + + stack.pop(); + REQUIRE(0 == stack.mPointer - stack.mStack); + REQUIRE(10 == stack.mStack[0].xOffset); + REQUIRE(20 == stack.mStack[1].xOffset); + + ClipRect &val3 = stack.top(); + REQUIRE(0 == stack.mPointer - stack.mStack); + REQUIRE(10 == val1.xOffset); + REQUIRE(20 == val2.xOffset); + REQUIRE(10 == val3.xOffset); + REQUIRE(10 == stack.mStack[0].xOffset); + REQUIRE(20 == stack.mStack[1].xOffset); + REQUIRE(0 == stack.mStack[2].xOffset); +} + +TEST_CASE("mstack clear 1", "") +{ + MStack stack(10); + REQUIRE(-1 == stack.mPointer - stack.mStack); + REQUIRE(0 == stack.mStack[0].xOffset); + + ClipRect &val1 = stack.push(); + val1.xOffset = 10; + + stack.clear(); + REQUIRE(-1 == stack.mPointer - stack.mStack); + REQUIRE(10 == stack.mStack[0].xOffset); + REQUIRE(0 == stack.mStack[1].xOffset); +} + +TEST_CASE("mstack getpop 1", "") +{ + MStack stack(10); + ClipRect &val1 = stack.push(); + val1.xOffset = 10; + REQUIRE(10 == stack.mStack[0].xOffset); + REQUIRE(10 == val1.xOffset); + + ClipRect &val2 = stack.getPop(); + REQUIRE(-1 == stack.mPointer - stack.mStack); + REQUIRE(10 == stack.mStack[0].xOffset); + REQUIRE(10 == val2.xOffset); +} diff --git a/src/unittests/resources/mstack_unittest.cc b/src/unittests/resources/mstack_unittest.cc deleted file mode 100644 index 1d2233803..000000000 --- a/src/unittests/resources/mstack_unittest.cc +++ /dev/null @@ -1,165 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2015-2017 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 . - */ - -#include "unittests/unittests.h" - -#include "gui/cliprect.h" - -#include "resources/mstack.h" - -#include "debug.h" - -TEST_CASE("mstack push 1", "") -{ - MStack stack(10); - REQUIRE(-1 == (stack.mPointer - stack.mStack)); - REQUIRE(0 == stack.mStack[0].xOffset); - - ClipRect &val1 = stack.push(); - val1.xOffset = 10; - ClipRect &val2 = stack.top(); - REQUIRE(0 == stack.mPointer - stack.mStack); - REQUIRE(10 == val2.xOffset); - REQUIRE(10 == stack.mStack[0].xOffset); - REQUIRE(0 == stack.mStack[1].xOffset); - - val2.yOffset = 2; - REQUIRE(2 == val1.yOffset); -} - -TEST_CASE("mstack push 2", "") -{ - MStack stack(10); - ClipRect &val1 = stack.push(); - val1.xOffset = 10; - const ClipRect &val2 = stack.top(); - REQUIRE(10 == val2.xOffset); - REQUIRE(10 == stack.mStack[0].xOffset); - - val1.yOffset = 2; - REQUIRE(2 == val2.yOffset); - REQUIRE(2 == stack.mStack[0].yOffset); -} - -TEST_CASE("mstack push 3", "") -{ - MStack stack(10); - ClipRect &val1 = stack.push(); - val1.xOffset = 10; - ClipRect &val2 = stack.top(); - REQUIRE(10 == val2.xOffset); - REQUIRE(10 == stack.mStack[0].xOffset); -} - -TEST_CASE("mstack push 4", "") -{ - MStack stack(10); - ClipRect &val1 = stack.push(); - val1.xOffset = 10; - REQUIRE(10 == val1.xOffset); - REQUIRE(10 == stack.mStack[0].xOffset); - REQUIRE(0 == stack.mStack[1].xOffset); - REQUIRE(0 == stack.mStack[2].xOffset); - - ClipRect &val2 = stack.push(); - val2.xOffset = 20; - REQUIRE(20 == val2.xOffset); - REQUIRE(10 == stack.mStack[0].xOffset); - REQUIRE(20 == stack.mStack[1].xOffset); - REQUIRE(0 == stack.mStack[2].xOffset); - - ClipRect &val3 = stack.push(); - val3.xOffset = 30; - REQUIRE(30 == val3.xOffset); - REQUIRE(10 == stack.mStack[0].xOffset); - REQUIRE(20 == stack.mStack[1].xOffset); - REQUIRE(30 == stack.mStack[2].xOffset); -} - -TEST_CASE("mstack pop 1", "") -{ - MStack stack(10); - ClipRect &val1 = stack.push(); - val1.xOffset = 10; - REQUIRE(10 == stack.mStack[0].xOffset); - - stack.pop(); - REQUIRE(-1 == stack.mPointer - stack.mStack); -} - -TEST_CASE("mstack pop 2", "") -{ - MStack stack(10); - ClipRect &val1 = stack.push(); - REQUIRE(0 == stack.mPointer - stack.mStack); - - val1.xOffset = 10; - REQUIRE(10 == stack.mStack[0].xOffset); - - ClipRect &val2 = stack.push(); - REQUIRE(1 == stack.mPointer - stack.mStack); - - val2.xOffset = 20; - REQUIRE(10 == stack.mStack[0].xOffset); - REQUIRE(20 == stack.mStack[1].xOffset); - - stack.pop(); - REQUIRE(0 == stack.mPointer - stack.mStack); - REQUIRE(10 == stack.mStack[0].xOffset); - REQUIRE(20 == stack.mStack[1].xOffset); - - ClipRect &val3 = stack.top(); - REQUIRE(0 == stack.mPointer - stack.mStack); - REQUIRE(10 == val1.xOffset); - REQUIRE(20 == val2.xOffset); - REQUIRE(10 == val3.xOffset); - REQUIRE(10 == stack.mStack[0].xOffset); - REQUIRE(20 == stack.mStack[1].xOffset); - REQUIRE(0 == stack.mStack[2].xOffset); -} - -TEST_CASE("mstack clear 1", "") -{ - MStack stack(10); - REQUIRE(-1 == stack.mPointer - stack.mStack); - REQUIRE(0 == stack.mStack[0].xOffset); - - ClipRect &val1 = stack.push(); - val1.xOffset = 10; - - stack.clear(); - REQUIRE(-1 == stack.mPointer - stack.mStack); - REQUIRE(10 == stack.mStack[0].xOffset); - REQUIRE(0 == stack.mStack[1].xOffset); -} - -TEST_CASE("mstack getpop 1", "") -{ - MStack stack(10); - ClipRect &val1 = stack.push(); - val1.xOffset = 10; - REQUIRE(10 == stack.mStack[0].xOffset); - REQUIRE(10 == val1.xOffset); - - ClipRect &val2 = stack.getPop(); - REQUIRE(-1 == stack.mPointer - stack.mStack); - REQUIRE(10 == stack.mStack[0].xOffset); - REQUIRE(10 == val2.xOffset); -} diff --git a/src/unittests/resources/resourcemanager/resourcemanager.cc b/src/unittests/resources/resourcemanager/resourcemanager.cc new file mode 100644 index 000000000..90bc873ab --- /dev/null +++ b/src/unittests/resources/resourcemanager/resourcemanager.cc @@ -0,0 +1,701 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013-2017 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 . + */ + +#include "unittests/unittests.h" + +#include "client.h" +#include "dirs.h" +#include "logger.h" +#include "graphicsmanager.h" + +#include "being/actorsprite.h" + +#include "fs/virtfs/fs.h" + +#include "gui/gui.h" + +#include "resources/sdlimagehelper.h" + +#include "resources/resourcemanager/resourcemanager.h" + +#include "utils/env.h" +#include "utils/delete2.h" + +#include + +PRAGMA48(GCC diagnostic push) +PRAGMA48(GCC diagnostic ignored "-Wshadow") +#ifndef USE_SDL2 +#include +#endif // USE_SDL2 +PRAGMA48(GCC diagnostic pop) + +#include "debug.h" + +namespace +{ + int testResouceCounter = 0; + + class TestResource : public Resource + { + public: + TestResource() : + Resource() + { + testResouceCounter ++; + } + + ~TestResource() + { + testResouceCounter --; + } + }; + + struct TestLoader final + { + std::string path; + static Resource *load(const void *const v) + { + BLOCK_START("TestLoader::load") + if (v == nullptr) + { + BLOCK_END("TestLoader::load") + return nullptr; + } + + Resource *const res = new TestResource(); + BLOCK_END("TestLoader::load") + return res; + } + }; + +} // namespace + +TEST_CASE("resourcemanager leak test1", "") +{ + logger = new Logger(); + REQUIRE(gui == nullptr); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); + delete2(logger); +} + +TEST_CASE("resourcemanager", "resourcemanager") +{ + setEnv("SDL_VIDEODRIVER", "dummy"); + + client = new Client; + XML::initXML(); + SDL_Init(SDL_INIT_VIDEO); + logger = new Logger(); + VirtFs::mountDirSilent("data", Append_false); + VirtFs::mountDirSilent("../data", Append_false); + + imageHelper = new SDLImageHelper(); +#ifdef USE_SDL2 + SDLImageHelper::setRenderer(graphicsManager.createRenderer( + graphicsManager.createWindow(640, 480, 0, + SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE)); +#else // USE_SDL2 + + graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE); +#endif // USE_SDL2 + + ActorSprite::load(); + + Dirs::initRootDir(); + Dirs::initHomeDir(); + +// ConfigManager::initConfiguration(); +// getConfigDefaults2(config.getDefaultValues()); + + while (ResourceManager::cleanOrphans(true)) + continue; + + testResouceCounter = 0; + const size_t resSize = ResourceManager::getResources().size(); + + SECTION("resourcemanager get 0") + { + REQUIRE(testResouceCounter == 0); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + } + + SECTION("resourcemanager get 1") + { + REQUIRE(testResouceCounter == 0); + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(testResouceCounter == 1); + REQUIRE(res != nullptr); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->decRef(); + REQUIRE(res->mRefCount == 0); + } + + SECTION("resourcemanager get 2") + { + TestLoader rl = { "test1" }; + Resource *const res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(res != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 1); + res->mSource = "source 1"; + REQUIRE(res->mSource == "source 1"); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + Resource *const res2 = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(res2 != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 2); + REQUIRE(res2->mRefCount == 2); + REQUIRE(res->mIdPath == res2->mIdPath); + REQUIRE(res2->mSource == "source 1"); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res2); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->decRef(); + res2->decRef(); + REQUIRE(res->mRefCount == 0); + } + + SECTION("resourcemanager get 3") + { + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(res != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->mSource = "source 1"; + res->decRef(); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + REQUIRE(res->mRefCount == 0); + } + + SECTION("resourcemanager get 4") + { + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(res != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->mSource = "source 1"; + res->decRef(); + REQUIRE(res->mRefCount == 0); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + + Resource *const res2 = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(res2 != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res2->mRefCount == 1); + REQUIRE(res->mIdPath == res2->mIdPath); + REQUIRE(res2->mSource == "source 1"); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res2); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res2->decRef(); + REQUIRE(res->mRefCount == 0); + } + + SECTION("resourcemanager get 5") + { + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(ResourceManager::isInCache("test1") == true); + REQUIRE(res != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->mSource = "source 1"; + res->decRef(); + REQUIRE(res->mRefCount == 0); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().size() == 1); + REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + + sleep(33); + ResourceManager::cleanOrphans(); + REQUIRE(ResourceManager::isInCache("test1") == false); + REQUIRE(testResouceCounter == 0); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + + Resource *const res2 = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(ResourceManager::isInCache("test1") == true); + REQUIRE(res2 != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res2->mRefCount == 1); + REQUIRE(res2->mSource.empty()); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res2); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res2->decRef(); + REQUIRE(res2->mRefCount == 0); + } + + SECTION("resourcemanager get 6") + { + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(res != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 1); + res->mSource = "source 1"; + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + + Resource *const res2 = ResourceManager::get("test2", + TestLoader::load, &rl); + REQUIRE(res2 != nullptr); + REQUIRE(testResouceCounter == 2); + REQUIRE(res2->mRefCount == 1); + REQUIRE(res2->mSource.empty()); + REQUIRE(ResourceManager::getResources().size() == 2 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getResources()["test2"] == res2); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->decRef(); + res2->decRef(); + REQUIRE(res->mRefCount == 0); + REQUIRE(res2->mRefCount == 0); + } + + SECTION("resourcemanager getFromCache 1") + { + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(res != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + Resource *const res2 = ResourceManager::getFromCache("test1"); + REQUIRE(res2 != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res2->mRefCount == 2); + REQUIRE(res == res2); + REQUIRE(res2->mSource.empty()); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res2); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->decRef(); + res->decRef(); + REQUIRE(res->mRefCount == 0); + } + + SECTION("resourcemanager getFromCache 2") + { + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(res != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->decRef(); + REQUIRE(res->mRefCount == 0); + Resource *const res2 = ResourceManager::getFromCache("test1"); + REQUIRE(res2 != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res2->mRefCount == 1); + REQUIRE(res == res2); + REQUIRE(res2->mSource.empty()); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res2); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->decRef(); + REQUIRE(res->mRefCount == 0); + } + + SECTION("resourcemanager getFromCache 3") + { + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(res != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 1); + res->mSource = "source 1"; + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + + Resource *const res2 = ResourceManager::get("test2", + TestLoader::load, &rl); + REQUIRE(res2 != nullptr); + REQUIRE(testResouceCounter == 2); + REQUIRE(res2->mRefCount == 1); + REQUIRE(res2->mSource.empty()); + REQUIRE(ResourceManager::getResources().size() == 2 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getResources()["test2"] == res2); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + + Resource *const resC = ResourceManager::getFromCache("test1"); + Resource *const res2C = ResourceManager::getFromCache("test2"); + REQUIRE(resC != nullptr); + REQUIRE(res2C != nullptr); + REQUIRE(testResouceCounter == 2); + REQUIRE(res == resC); + REQUIRE(res2 == res2C); + REQUIRE(resC->mRefCount == 2); + REQUIRE(res2C->mRefCount == 2); + REQUIRE(ResourceManager::getResources().size() == 2 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == resC); + REQUIRE(ResourceManager::getResources()["test2"] == res2C); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + + res->decRef(); + res->decRef(); + res2->decRef(); + res2->decRef(); + REQUIRE(res->mRefCount == 0); + REQUIRE(res2->mRefCount == 0); + } + + SECTION("resourcemanager addResource 1") + { + REQUIRE(testResouceCounter == 0); + Resource *res = new TestResource(); + REQUIRE(testResouceCounter == 1); + ResourceManager::addResource("test1", res); + REQUIRE(res != nullptr); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->decRef(); + REQUIRE(res->mRefCount == 0); + } + + SECTION("resourcemanager isInCache 1") + { + REQUIRE(testResouceCounter == 0); + TestLoader rl = { "test1" }; + REQUIRE(ResourceManager::isInCache("test1") == false); + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(ResourceManager::isInCache("test1") == true); + REQUIRE(ResourceManager::isInCache("test2") == false); + REQUIRE(testResouceCounter == 1); + REQUIRE(res != nullptr); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->decRef(); + REQUIRE(res->mRefCount == 0); + } + + SECTION("resourcemanager getTempResource 1") + { + TestLoader rl = { "test1" }; + REQUIRE(ResourceManager::getTempResource("test1") == nullptr); + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(res != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + Resource *const res2 = ResourceManager::getTempResource("test1"); + REQUIRE(ResourceManager::getTempResource("test2") == nullptr); + REQUIRE(res2 != nullptr); + REQUIRE(testResouceCounter == 1); + REQUIRE(res2->mRefCount == 1); + REQUIRE(res == res2); + REQUIRE(res2->mSource.empty()); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res2); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->decRef(); + REQUIRE(res->mRefCount == 0); + } + + SECTION("resourcemanager moveToDeleted 1") + { + REQUIRE(testResouceCounter == 0); + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(testResouceCounter == 1); + REQUIRE(res != nullptr); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + ResourceManager::moveToDeleted(res); + REQUIRE(testResouceCounter == 0); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + } + + SECTION("resourcemanager moveToDeleted 2") + { + REQUIRE(testResouceCounter == 0); + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + res->incRef(); + REQUIRE(testResouceCounter == 1); + REQUIRE(res != nullptr); + REQUIRE(res->mRefCount == 2); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + ResourceManager::moveToDeleted(res); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().size() == 1); + res->decRef(); + } + + SECTION("resourcemanager moveToDeleted 3") + { + REQUIRE(testResouceCounter == 0); + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(testResouceCounter == 1); + REQUIRE(res != nullptr); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + + res->decRef(); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 0); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().size() == 1); + REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + + ResourceManager::moveToDeleted(res); + REQUIRE(testResouceCounter == 0); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + } + + SECTION("resourcemanager decRefDelete 1") + { + REQUIRE(testResouceCounter == 0); + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(testResouceCounter == 1); + REQUIRE(res != nullptr); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + + ResourceManager::decRefDelete(res); + REQUIRE(testResouceCounter == 0); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + } + + SECTION("resourcemanager cleanUp 1") + { + REQUIRE(testResouceCounter == 0); + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(testResouceCounter == 1); + REQUIRE(res != nullptr); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->decRef(); + + ResourceManager::cleanUp(res); + REQUIRE(testResouceCounter == 0); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().size() == 1); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + ResourceManager::getOrphanedResources().clear(); + } + + SECTION("resourcemanager cleanProtected 1") + { + REQUIRE(testResouceCounter == 0); + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + REQUIRE(testResouceCounter == 1); + REQUIRE(res != nullptr); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->mProtected = true; + ResourceManager::cleanProtected(); + + REQUIRE(testResouceCounter == 1); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().size() == 1); + REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + res->decRef(); + } + + SECTION("resourcemanager clearDeleted 1") + { + REQUIRE(testResouceCounter == 0); + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + res->incRef(); + REQUIRE(testResouceCounter == 1); + REQUIRE(res != nullptr); + REQUIRE(res->mRefCount == 2); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + ResourceManager::moveToDeleted(res); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().size() == 1); + + ResourceManager::clearDeleted(); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().size() == 1); + res->decRef(); + } + + SECTION("resourcemanager clearDeleted 2") + { + REQUIRE(testResouceCounter == 0); + TestLoader rl = { "test1" }; + Resource *res = ResourceManager::get("test1", + TestLoader::load, &rl); + res->incRef(); + REQUIRE(testResouceCounter == 1); + REQUIRE(res != nullptr); + REQUIRE(res->mRefCount == 2); + REQUIRE(ResourceManager::getResources().size() == 1 + resSize); + REQUIRE(ResourceManager::getResources()["test1"] == res); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + ResourceManager::moveToDeleted(res); + REQUIRE(testResouceCounter == 1); + REQUIRE(res->mRefCount == 1); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().size() == 1); + + res->decRef(); + ResourceManager::clearDeleted(); + REQUIRE(testResouceCounter == 0); + REQUIRE(ResourceManager::getResources().size() == 0 + resSize); + REQUIRE(ResourceManager::getOrphanedResources().empty() == true); + REQUIRE(ResourceManager::getDeletedResources().empty() == true); + } + + delete2(client); + VirtFs::unmountDirSilent("data"); + VirtFs::unmountDirSilent("../data"); + delete2(logger); +// VirtFs::deinit(); +} + +TEST_CASE("resourcemanager leak test2", "") +{ + logger = new Logger(); + REQUIRE(gui == nullptr); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); + delete2(logger); +} diff --git a/src/unittests/resources/resourcemanager/resourcemanager_unittest.cc b/src/unittests/resources/resourcemanager/resourcemanager_unittest.cc deleted file mode 100644 index 90bc873ab..000000000 --- a/src/unittests/resources/resourcemanager/resourcemanager_unittest.cc +++ /dev/null @@ -1,701 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2013-2017 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 . - */ - -#include "unittests/unittests.h" - -#include "client.h" -#include "dirs.h" -#include "logger.h" -#include "graphicsmanager.h" - -#include "being/actorsprite.h" - -#include "fs/virtfs/fs.h" - -#include "gui/gui.h" - -#include "resources/sdlimagehelper.h" - -#include "resources/resourcemanager/resourcemanager.h" - -#include "utils/env.h" -#include "utils/delete2.h" - -#include - -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#ifndef USE_SDL2 -#include -#endif // USE_SDL2 -PRAGMA48(GCC diagnostic pop) - -#include "debug.h" - -namespace -{ - int testResouceCounter = 0; - - class TestResource : public Resource - { - public: - TestResource() : - Resource() - { - testResouceCounter ++; - } - - ~TestResource() - { - testResouceCounter --; - } - }; - - struct TestLoader final - { - std::string path; - static Resource *load(const void *const v) - { - BLOCK_START("TestLoader::load") - if (v == nullptr) - { - BLOCK_END("TestLoader::load") - return nullptr; - } - - Resource *const res = new TestResource(); - BLOCK_END("TestLoader::load") - return res; - } - }; - -} // namespace - -TEST_CASE("resourcemanager leak test1", "") -{ - logger = new Logger(); - REQUIRE(gui == nullptr); - ResourceManager::cleanOrphans(true); - ResourceManager::deleteInstance(); - delete2(logger); -} - -TEST_CASE("resourcemanager", "resourcemanager") -{ - setEnv("SDL_VIDEODRIVER", "dummy"); - - client = new Client; - XML::initXML(); - SDL_Init(SDL_INIT_VIDEO); - logger = new Logger(); - VirtFs::mountDirSilent("data", Append_false); - VirtFs::mountDirSilent("../data", Append_false); - - imageHelper = new SDLImageHelper(); -#ifdef USE_SDL2 - SDLImageHelper::setRenderer(graphicsManager.createRenderer( - graphicsManager.createWindow(640, 480, 0, - SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE)); -#else // USE_SDL2 - - graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE); -#endif // USE_SDL2 - - ActorSprite::load(); - - Dirs::initRootDir(); - Dirs::initHomeDir(); - -// ConfigManager::initConfiguration(); -// getConfigDefaults2(config.getDefaultValues()); - - while (ResourceManager::cleanOrphans(true)) - continue; - - testResouceCounter = 0; - const size_t resSize = ResourceManager::getResources().size(); - - SECTION("resourcemanager get 0") - { - REQUIRE(testResouceCounter == 0); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - } - - SECTION("resourcemanager get 1") - { - REQUIRE(testResouceCounter == 0); - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(testResouceCounter == 1); - REQUIRE(res != nullptr); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->decRef(); - REQUIRE(res->mRefCount == 0); - } - - SECTION("resourcemanager get 2") - { - TestLoader rl = { "test1" }; - Resource *const res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(res != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 1); - res->mSource = "source 1"; - REQUIRE(res->mSource == "source 1"); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - Resource *const res2 = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(res2 != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 2); - REQUIRE(res2->mRefCount == 2); - REQUIRE(res->mIdPath == res2->mIdPath); - REQUIRE(res2->mSource == "source 1"); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res2); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->decRef(); - res2->decRef(); - REQUIRE(res->mRefCount == 0); - } - - SECTION("resourcemanager get 3") - { - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(res != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->mSource = "source 1"; - res->decRef(); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - REQUIRE(res->mRefCount == 0); - } - - SECTION("resourcemanager get 4") - { - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(res != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->mSource = "source 1"; - res->decRef(); - REQUIRE(res->mRefCount == 0); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - - Resource *const res2 = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(res2 != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res2->mRefCount == 1); - REQUIRE(res->mIdPath == res2->mIdPath); - REQUIRE(res2->mSource == "source 1"); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res2); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res2->decRef(); - REQUIRE(res->mRefCount == 0); - } - - SECTION("resourcemanager get 5") - { - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(ResourceManager::isInCache("test1") == true); - REQUIRE(res != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->mSource = "source 1"; - res->decRef(); - REQUIRE(res->mRefCount == 0); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().size() == 1); - REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - - sleep(33); - ResourceManager::cleanOrphans(); - REQUIRE(ResourceManager::isInCache("test1") == false); - REQUIRE(testResouceCounter == 0); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - - Resource *const res2 = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(ResourceManager::isInCache("test1") == true); - REQUIRE(res2 != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res2->mRefCount == 1); - REQUIRE(res2->mSource.empty()); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res2); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res2->decRef(); - REQUIRE(res2->mRefCount == 0); - } - - SECTION("resourcemanager get 6") - { - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(res != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 1); - res->mSource = "source 1"; - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - - Resource *const res2 = ResourceManager::get("test2", - TestLoader::load, &rl); - REQUIRE(res2 != nullptr); - REQUIRE(testResouceCounter == 2); - REQUIRE(res2->mRefCount == 1); - REQUIRE(res2->mSource.empty()); - REQUIRE(ResourceManager::getResources().size() == 2 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getResources()["test2"] == res2); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->decRef(); - res2->decRef(); - REQUIRE(res->mRefCount == 0); - REQUIRE(res2->mRefCount == 0); - } - - SECTION("resourcemanager getFromCache 1") - { - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(res != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - Resource *const res2 = ResourceManager::getFromCache("test1"); - REQUIRE(res2 != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res2->mRefCount == 2); - REQUIRE(res == res2); - REQUIRE(res2->mSource.empty()); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res2); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->decRef(); - res->decRef(); - REQUIRE(res->mRefCount == 0); - } - - SECTION("resourcemanager getFromCache 2") - { - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(res != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->decRef(); - REQUIRE(res->mRefCount == 0); - Resource *const res2 = ResourceManager::getFromCache("test1"); - REQUIRE(res2 != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res2->mRefCount == 1); - REQUIRE(res == res2); - REQUIRE(res2->mSource.empty()); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res2); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->decRef(); - REQUIRE(res->mRefCount == 0); - } - - SECTION("resourcemanager getFromCache 3") - { - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(res != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 1); - res->mSource = "source 1"; - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - - Resource *const res2 = ResourceManager::get("test2", - TestLoader::load, &rl); - REQUIRE(res2 != nullptr); - REQUIRE(testResouceCounter == 2); - REQUIRE(res2->mRefCount == 1); - REQUIRE(res2->mSource.empty()); - REQUIRE(ResourceManager::getResources().size() == 2 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getResources()["test2"] == res2); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - - Resource *const resC = ResourceManager::getFromCache("test1"); - Resource *const res2C = ResourceManager::getFromCache("test2"); - REQUIRE(resC != nullptr); - REQUIRE(res2C != nullptr); - REQUIRE(testResouceCounter == 2); - REQUIRE(res == resC); - REQUIRE(res2 == res2C); - REQUIRE(resC->mRefCount == 2); - REQUIRE(res2C->mRefCount == 2); - REQUIRE(ResourceManager::getResources().size() == 2 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == resC); - REQUIRE(ResourceManager::getResources()["test2"] == res2C); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - - res->decRef(); - res->decRef(); - res2->decRef(); - res2->decRef(); - REQUIRE(res->mRefCount == 0); - REQUIRE(res2->mRefCount == 0); - } - - SECTION("resourcemanager addResource 1") - { - REQUIRE(testResouceCounter == 0); - Resource *res = new TestResource(); - REQUIRE(testResouceCounter == 1); - ResourceManager::addResource("test1", res); - REQUIRE(res != nullptr); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->decRef(); - REQUIRE(res->mRefCount == 0); - } - - SECTION("resourcemanager isInCache 1") - { - REQUIRE(testResouceCounter == 0); - TestLoader rl = { "test1" }; - REQUIRE(ResourceManager::isInCache("test1") == false); - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(ResourceManager::isInCache("test1") == true); - REQUIRE(ResourceManager::isInCache("test2") == false); - REQUIRE(testResouceCounter == 1); - REQUIRE(res != nullptr); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->decRef(); - REQUIRE(res->mRefCount == 0); - } - - SECTION("resourcemanager getTempResource 1") - { - TestLoader rl = { "test1" }; - REQUIRE(ResourceManager::getTempResource("test1") == nullptr); - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(res != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - Resource *const res2 = ResourceManager::getTempResource("test1"); - REQUIRE(ResourceManager::getTempResource("test2") == nullptr); - REQUIRE(res2 != nullptr); - REQUIRE(testResouceCounter == 1); - REQUIRE(res2->mRefCount == 1); - REQUIRE(res == res2); - REQUIRE(res2->mSource.empty()); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res2); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->decRef(); - REQUIRE(res->mRefCount == 0); - } - - SECTION("resourcemanager moveToDeleted 1") - { - REQUIRE(testResouceCounter == 0); - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(testResouceCounter == 1); - REQUIRE(res != nullptr); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - ResourceManager::moveToDeleted(res); - REQUIRE(testResouceCounter == 0); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - } - - SECTION("resourcemanager moveToDeleted 2") - { - REQUIRE(testResouceCounter == 0); - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - res->incRef(); - REQUIRE(testResouceCounter == 1); - REQUIRE(res != nullptr); - REQUIRE(res->mRefCount == 2); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - ResourceManager::moveToDeleted(res); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().size() == 1); - res->decRef(); - } - - SECTION("resourcemanager moveToDeleted 3") - { - REQUIRE(testResouceCounter == 0); - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(testResouceCounter == 1); - REQUIRE(res != nullptr); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - - res->decRef(); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 0); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().size() == 1); - REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - - ResourceManager::moveToDeleted(res); - REQUIRE(testResouceCounter == 0); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - } - - SECTION("resourcemanager decRefDelete 1") - { - REQUIRE(testResouceCounter == 0); - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(testResouceCounter == 1); - REQUIRE(res != nullptr); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - - ResourceManager::decRefDelete(res); - REQUIRE(testResouceCounter == 0); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - } - - SECTION("resourcemanager cleanUp 1") - { - REQUIRE(testResouceCounter == 0); - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(testResouceCounter == 1); - REQUIRE(res != nullptr); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->decRef(); - - ResourceManager::cleanUp(res); - REQUIRE(testResouceCounter == 0); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().size() == 1); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - ResourceManager::getOrphanedResources().clear(); - } - - SECTION("resourcemanager cleanProtected 1") - { - REQUIRE(testResouceCounter == 0); - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - REQUIRE(testResouceCounter == 1); - REQUIRE(res != nullptr); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->mProtected = true; - ResourceManager::cleanProtected(); - - REQUIRE(testResouceCounter == 1); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().size() == 1); - REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - res->decRef(); - } - - SECTION("resourcemanager clearDeleted 1") - { - REQUIRE(testResouceCounter == 0); - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - res->incRef(); - REQUIRE(testResouceCounter == 1); - REQUIRE(res != nullptr); - REQUIRE(res->mRefCount == 2); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - ResourceManager::moveToDeleted(res); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().size() == 1); - - ResourceManager::clearDeleted(); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().size() == 1); - res->decRef(); - } - - SECTION("resourcemanager clearDeleted 2") - { - REQUIRE(testResouceCounter == 0); - TestLoader rl = { "test1" }; - Resource *res = ResourceManager::get("test1", - TestLoader::load, &rl); - res->incRef(); - REQUIRE(testResouceCounter == 1); - REQUIRE(res != nullptr); - REQUIRE(res->mRefCount == 2); - REQUIRE(ResourceManager::getResources().size() == 1 + resSize); - REQUIRE(ResourceManager::getResources()["test1"] == res); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - ResourceManager::moveToDeleted(res); - REQUIRE(testResouceCounter == 1); - REQUIRE(res->mRefCount == 1); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().size() == 1); - - res->decRef(); - ResourceManager::clearDeleted(); - REQUIRE(testResouceCounter == 0); - REQUIRE(ResourceManager::getResources().size() == 0 + resSize); - REQUIRE(ResourceManager::getOrphanedResources().empty() == true); - REQUIRE(ResourceManager::getDeletedResources().empty() == true); - } - - delete2(client); - VirtFs::unmountDirSilent("data"); - VirtFs::unmountDirSilent("../data"); - delete2(logger); -// VirtFs::deinit(); -} - -TEST_CASE("resourcemanager leak test2", "") -{ - logger = new Logger(); - REQUIRE(gui == nullptr); - ResourceManager::cleanOrphans(true); - ResourceManager::deleteInstance(); - delete2(logger); -} diff --git a/src/unittests/resources/sdlimagehelper.cc b/src/unittests/resources/sdlimagehelper.cc new file mode 100644 index 000000000..2a3aec45b --- /dev/null +++ b/src/unittests/resources/sdlimagehelper.cc @@ -0,0 +1,541 @@ +/* + * The ManaPlus Client + * Copyright (C) 2014-2017 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 . + */ + +#ifndef USE_SDL2 +#include "localconsts.h" +PRAGMA48(GCC diagnostic push) +PRAGMA48(GCC diagnostic ignored "-Wshadow") +#include +PRAGMA48(GCC diagnostic pop) +#if SDL_BYTEORDER == SDL_LIL_ENDIAN + +#include "unittests/unittests.h" + +#include "client.h" +#include "graphicsmanager.h" + +#include "being/actorsprite.h" + +#include "fs/virtfs/fs.h" + +#include "utils/delete2.h" +#include "utils/env.h" + +#include "render/sdlgraphics.h" + +#include "resources/sdlimagehelper.h" + +#include "debug.h" + +static SDL_Surface *createSoftware32BitSurface(int width, + int height) +{ +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + const int rmask = 0xff000000; + const int gmask = 0x00ff0000; + const int bmask = 0x0000ff00; + const int amask = 0x000000ff; +#else // SDL_BYTEORDER == SDL_BIG_ENDIAN + + const int rmask = 0x000000ff; + const int gmask = 0x0000ff00; + const int bmask = 0x00ff0000; + const int amask = 0xff000000; +#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN + + return MSDL_CreateRGBSurface(SDL_SWSURFACE, + width, height, 32, rmask, gmask, bmask, amask); +} + +TEST_CASE("sdlimagehelper combineSurface", "") +{ + setEnv("SDL_VIDEODRIVER", "dummy"); + + client = new Client; + logger = new Logger(); + VirtFs::mountDirSilent("data", Append_false); + VirtFs::mountDirSilent("../data", Append_false); + + mainGraphics = new SDLGraphics; + imageHelper = new SDLImageHelper; +#ifdef USE_SDL2 + SDLImageHelper::setRenderer(graphicsManager.createRenderer( + graphicsManager.createWindow(640, 480, 0, + SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE)); +#else // USE_SDL2 + + graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE); +#endif // USE_SDL2 + + ActorSprite::load(); + + SECTION("empty copy1") + { + SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); + uint32_t *ptr1 = static_cast(surface1->pixels); + for (int f = 0; f < 2 * 2; f ++) + ptr1[f] = 0xff000000; + SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); + uint32_t *ptr2 = static_cast(surface2->pixels); + + ptr2[0] = 0xff000000; + ptr2[1] = 0x00ff0000; + ptr2[2] = 0x0000ff00; + ptr2[3] = 0x000000ff; + + SDLImageHelper::combineSurface(surface2, + nullptr, + surface1, + nullptr); + + // src image test + REQUIRE(ptr2[0] == 0xff000000); + REQUIRE(ptr2[1] == 0x00ff0000); + REQUIRE(ptr2[2] == 0x0000ff00); + REQUIRE(ptr2[3] == 0x000000ff); + + REQUIRE(ptr1[0] == 0xff000000); + REQUIRE(ptr1[1] == 0xff000000); + REQUIRE(ptr1[2] == 0xff000000); + REQUIRE(ptr1[3] == 0xff000000); + MSDL_FreeSurface(surface1); + MSDL_FreeSurface(surface2); + } + + SECTION("empty copy2") + { + SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); + uint32_t *ptr1 = static_cast(surface1->pixels); + for (int f = 0; f < 2 * 2; f ++) + ptr1[f] = 0xff000000; + SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); + uint32_t *ptr2 = static_cast(surface2->pixels); + + ptr2[0] = 0xff112233; + ptr2[1] = 0xff003344; + ptr2[2] = 0xff330055; + ptr2[3] = 0xff445500; + + SDLImageHelper::combineSurface(surface2, + nullptr, + surface1, + nullptr); + + REQUIRE(ptr1[0] == 0xff112233); + REQUIRE(ptr1[1] == 0xff003344); + REQUIRE(ptr1[2] == 0xff330055); + REQUIRE(ptr1[3] == 0xff445500); + MSDL_FreeSurface(surface1); + MSDL_FreeSurface(surface2); + } + + SECTION("empty copy3") + { + SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); + uint32_t *ptr1 = static_cast(surface1->pixels); + for (int f = 0; f < 2 * 2; f ++) + ptr1[f] = 0x00000000; + SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); + uint32_t *ptr2 = static_cast(surface2->pixels); + + ptr2[0] = 0xff112233; + ptr2[1] = 0xff003344; + ptr2[2] = 0xff330055; + ptr2[3] = 0xff445500; + + SDLImageHelper::combineSurface(surface2, + nullptr, + surface1, + nullptr); + + REQUIRE(ptr1[0] == 0xff112233); + REQUIRE(ptr1[1] == 0xff003344); + REQUIRE(ptr1[2] == 0xff330055); + REQUIRE(ptr1[3] == 0xff445500); + MSDL_FreeSurface(surface1); + MSDL_FreeSurface(surface2); + } + + SECTION("empty copy4") + { + SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); + uint32_t *ptr1 = static_cast(surface1->pixels); + for (int f = 0; f < 2 * 2; f ++) + ptr1[f] = 0xff000000; + SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); + uint32_t *ptr2 = static_cast(surface2->pixels); + + ptr2[0] = 0x50112233; + ptr2[1] = 0x50003344; + ptr2[2] = 0x50330055; + ptr2[3] = 0x50445500; + + SDLImageHelper::combineSurface(surface2, + nullptr, + surface1, + nullptr); + + REQUIRE(ptr1[0] == 0xff09121c); + REQUIRE(ptr1[1] == 0xff001c25); + REQUIRE(ptr1[2] == 0xff1c002f); + REQUIRE(ptr1[3] == 0xff252f00); + MSDL_FreeSurface(surface1); + MSDL_FreeSurface(surface2); + } + + SECTION("empty copy5") + { + SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); + uint32_t *ptr1 = static_cast(surface1->pixels); + for (int f = 0; f < 2 * 2; f ++) + ptr1[f] = 0x00000000; + SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); + uint32_t *ptr2 = static_cast(surface2->pixels); + + ptr2[0] = 0x50112233; + ptr2[1] = 0x50003344; + ptr2[2] = 0x50330055; + ptr2[3] = 0x50445500; + + SDLImageHelper::combineSurface(surface2, + nullptr, + surface1, + nullptr); + + REQUIRE(ptr1[0] == 0x8e09121c); + REQUIRE(ptr1[1] == 0x8e001c25); + REQUIRE(ptr1[2] == 0x8e1c002f); + REQUIRE(ptr1[3] == 0x8e252f00); + MSDL_FreeSurface(surface1); + MSDL_FreeSurface(surface2); + } + + SECTION("empty copy6") + { + SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); + uint32_t *ptr1 = static_cast(surface1->pixels); + ptr1[0] = 0x50112233; + ptr1[1] = 0x50003344; + ptr1[2] = 0x50330055; + ptr1[3] = 0x50445500; + SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); + uint32_t *ptr2 = static_cast(surface2->pixels); + + for (int f = 0; f < 2 * 2; f ++) + ptr2[f] = 0x00000000; + + SDLImageHelper::combineSurface(surface2, + nullptr, + surface1, + nullptr); + + REQUIRE(ptr1[0] == 0x50112233); + REQUIRE(ptr1[1] == 0x50003344); + REQUIRE(ptr1[2] == 0x50330055); + REQUIRE(ptr1[3] == 0x50445500); + MSDL_FreeSurface(surface1); + MSDL_FreeSurface(surface2); + } + + SECTION("mix 1") + { + SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); + uint32_t *ptr1 = static_cast(surface1->pixels); + ptr1[0] = 0x50112233; + ptr1[1] = 0x50003344; + ptr1[2] = 0x50330055; + ptr1[3] = 0x50445500; + SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); + uint32_t *ptr2 = static_cast(surface2->pixels); + + ptr2[0] = 0x50003344; + ptr2[1] = 0x50330055; + ptr2[2] = 0x50445500; + ptr2[3] = 0x50112233; + + SDLImageHelper::combineSurface(surface2, + nullptr, + surface1, + nullptr); + + REQUIRE(ptr1[0] == 0xdf082b3c); + REQUIRE(ptr1[1] == 0xdf1d174d); + REQUIRE(ptr1[2] == 0xdf3d2f26); + REQUIRE(ptr1[3] == 0xdf29391c); + MSDL_FreeSurface(surface1); + MSDL_FreeSurface(surface2); + } + + SECTION("mix 2") + { + SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); + uint32_t *ptr1 = static_cast(surface1->pixels); + ptr1[0] = 0x10112233; + ptr1[1] = 0x20003344; + ptr1[2] = 0x30330055; + ptr1[3] = 0x40445500; + SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); + uint32_t *ptr2 = static_cast(surface2->pixels); + + ptr2[0] = 0x50003344; + ptr2[1] = 0x60330055; + ptr2[2] = 0x70445500; + ptr2[3] = 0x80112233; + + SDLImageHelper::combineSurface(surface2, + nullptr, + surface1, + nullptr); + + REQUIRE(ptr1[0] == 0x9f082b3c); + REQUIRE(ptr1[1] == 0xbd1f144e); + REQUIRE(ptr1[2] == 0xb93f391e); + REQUIRE(ptr1[3] == 0xf5213224); + MSDL_FreeSurface(surface1); + MSDL_FreeSurface(surface2); + } + + SECTION("part mix 1") + { +// 11 11 00 00 +// 11 11 00 00 +// 00 00 00 00 +// 00 00 00 00 + + SDL_Surface *surface1 = createSoftware32BitSurface(4, 4); + uint32_t *ptr1 = static_cast(surface1->pixels); + ptr1[0] = 0x10112233; + ptr1[1] = 0x20003344; + ptr1[2] = 0x10203040; + ptr1[3] = 0x20304050; + ptr1[4] = 0x30330055; + ptr1[5] = 0x40445500; + ptr1[6] = 0x30405060; + ptr1[7] = 0x708090a0; + + ptr1[8] = 0x8090a0b0; + ptr1[9] = 0x90a0b0c0; + ptr1[10] = 0xa0b0c0d0; + ptr1[11] = 0xb0c0d0e0; + ptr1[12] = 0xc0d0e0f0; + ptr1[13] = 0xd0e0f000; + ptr1[14] = 0xe0f00010; + ptr1[15] = 0xf0001020; + + SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); + uint32_t *ptr2 = static_cast(surface2->pixels); + + ptr2[0] = 0x50003344; + ptr2[1] = 0x60330055; + ptr2[2] = 0x70445500; + ptr2[3] = 0x80112233; + + SDLImageHelper::combineSurface(surface2, + nullptr, + surface1, + nullptr); + + REQUIRE(ptr1[0] == 0x9f082b3c); + REQUIRE(ptr1[1] == 0xbd1f144e); + REQUIRE(ptr1[2] == 0x10203040); + REQUIRE(ptr1[3] == 0x20304050); + REQUIRE(ptr1[4] == 0xb93f391e); + REQUIRE(ptr1[5] == 0xf5213224); + REQUIRE(ptr1[6] == 0x30405060); + REQUIRE(ptr1[7] == 0x708090a0); + + REQUIRE(ptr1[8] == 0x8090a0b0); + REQUIRE(ptr1[9] == 0x90a0b0c0); + REQUIRE(ptr1[10] == 0xa0b0c0d0); + REQUIRE(ptr1[11] == 0xb0c0d0e0); + REQUIRE(ptr1[12] == 0xc0d0e0f0); + REQUIRE(ptr1[13] == 0xd0e0f000); + REQUIRE(ptr1[14] == 0xe0f00010); + REQUIRE(ptr1[15] == 0xf0001020); + + MSDL_FreeSurface(surface1); + MSDL_FreeSurface(surface2); + } + + SECTION("part mix 2") + { +// 00 00 00 00 +// 00 11 11 00 +// 00 11 11 00 +// 00 00 00 00 + + SDL_Surface *surface1 = createSoftware32BitSurface(4, 4); + uint32_t *ptr1 = static_cast(surface1->pixels); + + ptr1[0] = 0x10203040; + ptr1[1] = 0x20304050; + ptr1[2] = 0x30405060; + ptr1[3] = 0x708090a0; + ptr1[4] = 0x8090a0b0; + + ptr1[5] = 0x10112233; // + + ptr1[6] = 0x20003344; // + + + ptr1[7] = 0x90a0b0c0; + ptr1[8] = 0xa0b0c0d0; + + ptr1[9] = 0x30330055; // + + ptr1[10] = 0x40445500; // + + + ptr1[11] = 0xb0c0d0e0; + ptr1[12] = 0xc0d0e0f0; + ptr1[13] = 0xd0e0f000; + ptr1[14] = 0xe0f00010; + ptr1[15] = 0xf0001020; + + SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); + uint32_t *ptr2 = static_cast(surface2->pixels); + + ptr2[0] = 0x50003344; + ptr2[1] = 0x60330055; + ptr2[2] = 0x70445500; + ptr2[3] = 0x80112233; + + SDL_Rect rect1; + SDL_Rect rect2; + rect1.x = 1; + rect1.y = 1; + rect1.w = 2; + rect1.h = 2; + rect2.x = 0; + rect2.y = 0; + rect2.w = 2; + rect2.h = 2; + SDLImageHelper::combineSurface(surface2, + &rect2, + surface1, + &rect1); + + REQUIRE(ptr1[0] == 0x10203040); + REQUIRE(ptr1[1] == 0x20304050); + REQUIRE(ptr1[2] == 0x30405060); + REQUIRE(ptr1[3] == 0x708090a0); + REQUIRE(ptr1[4] == 0x8090a0b0); + + REQUIRE(ptr1[5] == 0x9f082b3c); // + + REQUIRE(ptr1[6] == 0xbd1f144e); // + + + REQUIRE(ptr1[7] == 0x90a0b0c0); + REQUIRE(ptr1[8] == 0xa0b0c0d0); + + REQUIRE(ptr1[9] == 0xb93f391e); // + + REQUIRE(ptr1[10] == 0xf5213224); // + + + REQUIRE(ptr1[11] == 0xb0c0d0e0); + REQUIRE(ptr1[12] == 0xc0d0e0f0); + REQUIRE(ptr1[13] == 0xd0e0f000); + REQUIRE(ptr1[14] == 0xe0f00010); + REQUIRE(ptr1[15] == 0xf0001020); + + MSDL_FreeSurface(surface1); + MSDL_FreeSurface(surface2); + } + + SECTION("part mix 3") + { + SDL_Surface *surface1 = createSoftware32BitSurface(4, 4); + uint32_t *ptr1 = static_cast(surface1->pixels); + + ptr1[0] = 0x10203040; + ptr1[1] = 0x20304050; + ptr1[2] = 0x30405060; + ptr1[3] = 0x708090a0; + ptr1[4] = 0x8090a0b0; + ptr1[5] = 0x10112233; + ptr1[6] = 0x20003344; + ptr1[7] = 0x90a0b0c0; + ptr1[8] = 0xa0b0c0d0; + ptr1[9] = 0x30330055; + ptr1[10] = 0x40445500; + ptr1[11] = 0xb0c0d0e0; + ptr1[12] = 0xc0d0e0f0; + ptr1[13] = 0xd0e0f000; + ptr1[14] = 0xe0f00010; + ptr1[15] = 0xf0001020; + + SDL_Surface *surface2 = createSoftware32BitSurface(4, 4); + uint32_t *ptr2 = static_cast(surface2->pixels); + + ptr2[0] = 0x50003344; + ptr2[1] = 0x60330055; + ptr2[2] = 0x70445500; + ptr2[3] = 0x80112233; + ptr2[4] = 0x90111111; + ptr2[5] = 0x90111111; + ptr2[6] = 0xff000000; + ptr2[7] = 0xff000000; + ptr2[8] = 0xff000000; + ptr2[9] = 0xff000000; + ptr2[10] = 0xff000000; + ptr2[11] = 0xff000000; + ptr2[12] = 0xff000000; + ptr2[13] = 0xff000000; + ptr2[14] = 0xff000000; + ptr2[15] = 0xff000000; + + SDL_Rect rect1; + SDL_Rect rect2; + rect1.x = 1; + rect1.y = 1; + rect1.w = 2; + rect1.h = 2; + rect2.x = 0; + rect2.y = 0; + rect2.w = 2; + rect2.h = 2; + SDLImageHelper::combineSurface(surface2, + &rect2, + surface1, + &rect1); + + REQUIRE(ptr1[0] == 0x10203040); + REQUIRE(ptr1[1] == 0x20304050); + REQUIRE(ptr1[2] == 0x30405060); + REQUIRE(ptr1[3] == 0x708090a0); + REQUIRE(ptr1[4] == 0x8090a0b0); + REQUIRE(ptr1[5] == 0x9f082b3c); + REQUIRE(ptr1[6] == 0xbd1f144e); + REQUIRE(ptr1[7] == 0x90a0b0c0); + REQUIRE(ptr1[8] == 0xa0b0c0d0); + REQUIRE(ptr1[9] == 0xbf1b0d23); + REQUIRE(ptr1[10] == 0xff1f230c); + REQUIRE(ptr1[11] == 0xb0c0d0e0); + REQUIRE(ptr1[12] == 0xc0d0e0f0); + REQUIRE(ptr1[13] == 0xd0e0f000); + REQUIRE(ptr1[14] == 0xe0f00010); + REQUIRE(ptr1[15] == 0xf0001020); + + MSDL_FreeSurface(surface1); + MSDL_FreeSurface(surface2); + } + + delete2(client); + VirtFs::unmountDirSilent("data"); + VirtFs::unmountDirSilent("../data"); + delete2(logger); +} + +#endif // SDL_BYTEORDER == SDL_LIL_ENDIAN +#endif // USE_SDL2 diff --git a/src/unittests/resources/sdlimagehelper_unittest.cc b/src/unittests/resources/sdlimagehelper_unittest.cc deleted file mode 100644 index 2a3aec45b..000000000 --- a/src/unittests/resources/sdlimagehelper_unittest.cc +++ /dev/null @@ -1,541 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2014-2017 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 . - */ - -#ifndef USE_SDL2 -#include "localconsts.h" -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#include -PRAGMA48(GCC diagnostic pop) -#if SDL_BYTEORDER == SDL_LIL_ENDIAN - -#include "unittests/unittests.h" - -#include "client.h" -#include "graphicsmanager.h" - -#include "being/actorsprite.h" - -#include "fs/virtfs/fs.h" - -#include "utils/delete2.h" -#include "utils/env.h" - -#include "render/sdlgraphics.h" - -#include "resources/sdlimagehelper.h" - -#include "debug.h" - -static SDL_Surface *createSoftware32BitSurface(int width, - int height) -{ -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const int rmask = 0xff000000; - const int gmask = 0x00ff0000; - const int bmask = 0x0000ff00; - const int amask = 0x000000ff; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const int rmask = 0x000000ff; - const int gmask = 0x0000ff00; - const int bmask = 0x00ff0000; - const int amask = 0xff000000; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - return MSDL_CreateRGBSurface(SDL_SWSURFACE, - width, height, 32, rmask, gmask, bmask, amask); -} - -TEST_CASE("sdlimagehelper combineSurface", "") -{ - setEnv("SDL_VIDEODRIVER", "dummy"); - - client = new Client; - logger = new Logger(); - VirtFs::mountDirSilent("data", Append_false); - VirtFs::mountDirSilent("../data", Append_false); - - mainGraphics = new SDLGraphics; - imageHelper = new SDLImageHelper; -#ifdef USE_SDL2 - SDLImageHelper::setRenderer(graphicsManager.createRenderer( - graphicsManager.createWindow(640, 480, 0, - SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE)); -#else // USE_SDL2 - - graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE); -#endif // USE_SDL2 - - ActorSprite::load(); - - SECTION("empty copy1") - { - SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); - uint32_t *ptr1 = static_cast(surface1->pixels); - for (int f = 0; f < 2 * 2; f ++) - ptr1[f] = 0xff000000; - SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); - uint32_t *ptr2 = static_cast(surface2->pixels); - - ptr2[0] = 0xff000000; - ptr2[1] = 0x00ff0000; - ptr2[2] = 0x0000ff00; - ptr2[3] = 0x000000ff; - - SDLImageHelper::combineSurface(surface2, - nullptr, - surface1, - nullptr); - - // src image test - REQUIRE(ptr2[0] == 0xff000000); - REQUIRE(ptr2[1] == 0x00ff0000); - REQUIRE(ptr2[2] == 0x0000ff00); - REQUIRE(ptr2[3] == 0x000000ff); - - REQUIRE(ptr1[0] == 0xff000000); - REQUIRE(ptr1[1] == 0xff000000); - REQUIRE(ptr1[2] == 0xff000000); - REQUIRE(ptr1[3] == 0xff000000); - MSDL_FreeSurface(surface1); - MSDL_FreeSurface(surface2); - } - - SECTION("empty copy2") - { - SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); - uint32_t *ptr1 = static_cast(surface1->pixels); - for (int f = 0; f < 2 * 2; f ++) - ptr1[f] = 0xff000000; - SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); - uint32_t *ptr2 = static_cast(surface2->pixels); - - ptr2[0] = 0xff112233; - ptr2[1] = 0xff003344; - ptr2[2] = 0xff330055; - ptr2[3] = 0xff445500; - - SDLImageHelper::combineSurface(surface2, - nullptr, - surface1, - nullptr); - - REQUIRE(ptr1[0] == 0xff112233); - REQUIRE(ptr1[1] == 0xff003344); - REQUIRE(ptr1[2] == 0xff330055); - REQUIRE(ptr1[3] == 0xff445500); - MSDL_FreeSurface(surface1); - MSDL_FreeSurface(surface2); - } - - SECTION("empty copy3") - { - SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); - uint32_t *ptr1 = static_cast(surface1->pixels); - for (int f = 0; f < 2 * 2; f ++) - ptr1[f] = 0x00000000; - SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); - uint32_t *ptr2 = static_cast(surface2->pixels); - - ptr2[0] = 0xff112233; - ptr2[1] = 0xff003344; - ptr2[2] = 0xff330055; - ptr2[3] = 0xff445500; - - SDLImageHelper::combineSurface(surface2, - nullptr, - surface1, - nullptr); - - REQUIRE(ptr1[0] == 0xff112233); - REQUIRE(ptr1[1] == 0xff003344); - REQUIRE(ptr1[2] == 0xff330055); - REQUIRE(ptr1[3] == 0xff445500); - MSDL_FreeSurface(surface1); - MSDL_FreeSurface(surface2); - } - - SECTION("empty copy4") - { - SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); - uint32_t *ptr1 = static_cast(surface1->pixels); - for (int f = 0; f < 2 * 2; f ++) - ptr1[f] = 0xff000000; - SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); - uint32_t *ptr2 = static_cast(surface2->pixels); - - ptr2[0] = 0x50112233; - ptr2[1] = 0x50003344; - ptr2[2] = 0x50330055; - ptr2[3] = 0x50445500; - - SDLImageHelper::combineSurface(surface2, - nullptr, - surface1, - nullptr); - - REQUIRE(ptr1[0] == 0xff09121c); - REQUIRE(ptr1[1] == 0xff001c25); - REQUIRE(ptr1[2] == 0xff1c002f); - REQUIRE(ptr1[3] == 0xff252f00); - MSDL_FreeSurface(surface1); - MSDL_FreeSurface(surface2); - } - - SECTION("empty copy5") - { - SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); - uint32_t *ptr1 = static_cast(surface1->pixels); - for (int f = 0; f < 2 * 2; f ++) - ptr1[f] = 0x00000000; - SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); - uint32_t *ptr2 = static_cast(surface2->pixels); - - ptr2[0] = 0x50112233; - ptr2[1] = 0x50003344; - ptr2[2] = 0x50330055; - ptr2[3] = 0x50445500; - - SDLImageHelper::combineSurface(surface2, - nullptr, - surface1, - nullptr); - - REQUIRE(ptr1[0] == 0x8e09121c); - REQUIRE(ptr1[1] == 0x8e001c25); - REQUIRE(ptr1[2] == 0x8e1c002f); - REQUIRE(ptr1[3] == 0x8e252f00); - MSDL_FreeSurface(surface1); - MSDL_FreeSurface(surface2); - } - - SECTION("empty copy6") - { - SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); - uint32_t *ptr1 = static_cast(surface1->pixels); - ptr1[0] = 0x50112233; - ptr1[1] = 0x50003344; - ptr1[2] = 0x50330055; - ptr1[3] = 0x50445500; - SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); - uint32_t *ptr2 = static_cast(surface2->pixels); - - for (int f = 0; f < 2 * 2; f ++) - ptr2[f] = 0x00000000; - - SDLImageHelper::combineSurface(surface2, - nullptr, - surface1, - nullptr); - - REQUIRE(ptr1[0] == 0x50112233); - REQUIRE(ptr1[1] == 0x50003344); - REQUIRE(ptr1[2] == 0x50330055); - REQUIRE(ptr1[3] == 0x50445500); - MSDL_FreeSurface(surface1); - MSDL_FreeSurface(surface2); - } - - SECTION("mix 1") - { - SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); - uint32_t *ptr1 = static_cast(surface1->pixels); - ptr1[0] = 0x50112233; - ptr1[1] = 0x50003344; - ptr1[2] = 0x50330055; - ptr1[3] = 0x50445500; - SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); - uint32_t *ptr2 = static_cast(surface2->pixels); - - ptr2[0] = 0x50003344; - ptr2[1] = 0x50330055; - ptr2[2] = 0x50445500; - ptr2[3] = 0x50112233; - - SDLImageHelper::combineSurface(surface2, - nullptr, - surface1, - nullptr); - - REQUIRE(ptr1[0] == 0xdf082b3c); - REQUIRE(ptr1[1] == 0xdf1d174d); - REQUIRE(ptr1[2] == 0xdf3d2f26); - REQUIRE(ptr1[3] == 0xdf29391c); - MSDL_FreeSurface(surface1); - MSDL_FreeSurface(surface2); - } - - SECTION("mix 2") - { - SDL_Surface *surface1 = createSoftware32BitSurface(2, 2); - uint32_t *ptr1 = static_cast(surface1->pixels); - ptr1[0] = 0x10112233; - ptr1[1] = 0x20003344; - ptr1[2] = 0x30330055; - ptr1[3] = 0x40445500; - SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); - uint32_t *ptr2 = static_cast(surface2->pixels); - - ptr2[0] = 0x50003344; - ptr2[1] = 0x60330055; - ptr2[2] = 0x70445500; - ptr2[3] = 0x80112233; - - SDLImageHelper::combineSurface(surface2, - nullptr, - surface1, - nullptr); - - REQUIRE(ptr1[0] == 0x9f082b3c); - REQUIRE(ptr1[1] == 0xbd1f144e); - REQUIRE(ptr1[2] == 0xb93f391e); - REQUIRE(ptr1[3] == 0xf5213224); - MSDL_FreeSurface(surface1); - MSDL_FreeSurface(surface2); - } - - SECTION("part mix 1") - { -// 11 11 00 00 -// 11 11 00 00 -// 00 00 00 00 -// 00 00 00 00 - - SDL_Surface *surface1 = createSoftware32BitSurface(4, 4); - uint32_t *ptr1 = static_cast(surface1->pixels); - ptr1[0] = 0x10112233; - ptr1[1] = 0x20003344; - ptr1[2] = 0x10203040; - ptr1[3] = 0x20304050; - ptr1[4] = 0x30330055; - ptr1[5] = 0x40445500; - ptr1[6] = 0x30405060; - ptr1[7] = 0x708090a0; - - ptr1[8] = 0x8090a0b0; - ptr1[9] = 0x90a0b0c0; - ptr1[10] = 0xa0b0c0d0; - ptr1[11] = 0xb0c0d0e0; - ptr1[12] = 0xc0d0e0f0; - ptr1[13] = 0xd0e0f000; - ptr1[14] = 0xe0f00010; - ptr1[15] = 0xf0001020; - - SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); - uint32_t *ptr2 = static_cast(surface2->pixels); - - ptr2[0] = 0x50003344; - ptr2[1] = 0x60330055; - ptr2[2] = 0x70445500; - ptr2[3] = 0x80112233; - - SDLImageHelper::combineSurface(surface2, - nullptr, - surface1, - nullptr); - - REQUIRE(ptr1[0] == 0x9f082b3c); - REQUIRE(ptr1[1] == 0xbd1f144e); - REQUIRE(ptr1[2] == 0x10203040); - REQUIRE(ptr1[3] == 0x20304050); - REQUIRE(ptr1[4] == 0xb93f391e); - REQUIRE(ptr1[5] == 0xf5213224); - REQUIRE(ptr1[6] == 0x30405060); - REQUIRE(ptr1[7] == 0x708090a0); - - REQUIRE(ptr1[8] == 0x8090a0b0); - REQUIRE(ptr1[9] == 0x90a0b0c0); - REQUIRE(ptr1[10] == 0xa0b0c0d0); - REQUIRE(ptr1[11] == 0xb0c0d0e0); - REQUIRE(ptr1[12] == 0xc0d0e0f0); - REQUIRE(ptr1[13] == 0xd0e0f000); - REQUIRE(ptr1[14] == 0xe0f00010); - REQUIRE(ptr1[15] == 0xf0001020); - - MSDL_FreeSurface(surface1); - MSDL_FreeSurface(surface2); - } - - SECTION("part mix 2") - { -// 00 00 00 00 -// 00 11 11 00 -// 00 11 11 00 -// 00 00 00 00 - - SDL_Surface *surface1 = createSoftware32BitSurface(4, 4); - uint32_t *ptr1 = static_cast(surface1->pixels); - - ptr1[0] = 0x10203040; - ptr1[1] = 0x20304050; - ptr1[2] = 0x30405060; - ptr1[3] = 0x708090a0; - ptr1[4] = 0x8090a0b0; - - ptr1[5] = 0x10112233; // + - ptr1[6] = 0x20003344; // + - - ptr1[7] = 0x90a0b0c0; - ptr1[8] = 0xa0b0c0d0; - - ptr1[9] = 0x30330055; // + - ptr1[10] = 0x40445500; // + - - ptr1[11] = 0xb0c0d0e0; - ptr1[12] = 0xc0d0e0f0; - ptr1[13] = 0xd0e0f000; - ptr1[14] = 0xe0f00010; - ptr1[15] = 0xf0001020; - - SDL_Surface *surface2 = createSoftware32BitSurface(2, 2); - uint32_t *ptr2 = static_cast(surface2->pixels); - - ptr2[0] = 0x50003344; - ptr2[1] = 0x60330055; - ptr2[2] = 0x70445500; - ptr2[3] = 0x80112233; - - SDL_Rect rect1; - SDL_Rect rect2; - rect1.x = 1; - rect1.y = 1; - rect1.w = 2; - rect1.h = 2; - rect2.x = 0; - rect2.y = 0; - rect2.w = 2; - rect2.h = 2; - SDLImageHelper::combineSurface(surface2, - &rect2, - surface1, - &rect1); - - REQUIRE(ptr1[0] == 0x10203040); - REQUIRE(ptr1[1] == 0x20304050); - REQUIRE(ptr1[2] == 0x30405060); - REQUIRE(ptr1[3] == 0x708090a0); - REQUIRE(ptr1[4] == 0x8090a0b0); - - REQUIRE(ptr1[5] == 0x9f082b3c); // + - REQUIRE(ptr1[6] == 0xbd1f144e); // + - - REQUIRE(ptr1[7] == 0x90a0b0c0); - REQUIRE(ptr1[8] == 0xa0b0c0d0); - - REQUIRE(ptr1[9] == 0xb93f391e); // + - REQUIRE(ptr1[10] == 0xf5213224); // + - - REQUIRE(ptr1[11] == 0xb0c0d0e0); - REQUIRE(ptr1[12] == 0xc0d0e0f0); - REQUIRE(ptr1[13] == 0xd0e0f000); - REQUIRE(ptr1[14] == 0xe0f00010); - REQUIRE(ptr1[15] == 0xf0001020); - - MSDL_FreeSurface(surface1); - MSDL_FreeSurface(surface2); - } - - SECTION("part mix 3") - { - SDL_Surface *surface1 = createSoftware32BitSurface(4, 4); - uint32_t *ptr1 = static_cast(surface1->pixels); - - ptr1[0] = 0x10203040; - ptr1[1] = 0x20304050; - ptr1[2] = 0x30405060; - ptr1[3] = 0x708090a0; - ptr1[4] = 0x8090a0b0; - ptr1[5] = 0x10112233; - ptr1[6] = 0x20003344; - ptr1[7] = 0x90a0b0c0; - ptr1[8] = 0xa0b0c0d0; - ptr1[9] = 0x30330055; - ptr1[10] = 0x40445500; - ptr1[11] = 0xb0c0d0e0; - ptr1[12] = 0xc0d0e0f0; - ptr1[13] = 0xd0e0f000; - ptr1[14] = 0xe0f00010; - ptr1[15] = 0xf0001020; - - SDL_Surface *surface2 = createSoftware32BitSurface(4, 4); - uint32_t *ptr2 = static_cast(surface2->pixels); - - ptr2[0] = 0x50003344; - ptr2[1] = 0x60330055; - ptr2[2] = 0x70445500; - ptr2[3] = 0x80112233; - ptr2[4] = 0x90111111; - ptr2[5] = 0x90111111; - ptr2[6] = 0xff000000; - ptr2[7] = 0xff000000; - ptr2[8] = 0xff000000; - ptr2[9] = 0xff000000; - ptr2[10] = 0xff000000; - ptr2[11] = 0xff000000; - ptr2[12] = 0xff000000; - ptr2[13] = 0xff000000; - ptr2[14] = 0xff000000; - ptr2[15] = 0xff000000; - - SDL_Rect rect1; - SDL_Rect rect2; - rect1.x = 1; - rect1.y = 1; - rect1.w = 2; - rect1.h = 2; - rect2.x = 0; - rect2.y = 0; - rect2.w = 2; - rect2.h = 2; - SDLImageHelper::combineSurface(surface2, - &rect2, - surface1, - &rect1); - - REQUIRE(ptr1[0] == 0x10203040); - REQUIRE(ptr1[1] == 0x20304050); - REQUIRE(ptr1[2] == 0x30405060); - REQUIRE(ptr1[3] == 0x708090a0); - REQUIRE(ptr1[4] == 0x8090a0b0); - REQUIRE(ptr1[5] == 0x9f082b3c); - REQUIRE(ptr1[6] == 0xbd1f144e); - REQUIRE(ptr1[7] == 0x90a0b0c0); - REQUIRE(ptr1[8] == 0xa0b0c0d0); - REQUIRE(ptr1[9] == 0xbf1b0d23); - REQUIRE(ptr1[10] == 0xff1f230c); - REQUIRE(ptr1[11] == 0xb0c0d0e0); - REQUIRE(ptr1[12] == 0xc0d0e0f0); - REQUIRE(ptr1[13] == 0xd0e0f000); - REQUIRE(ptr1[14] == 0xe0f00010); - REQUIRE(ptr1[15] == 0xf0001020); - - MSDL_FreeSurface(surface1); - MSDL_FreeSurface(surface2); - } - - delete2(client); - VirtFs::unmountDirSilent("data"); - VirtFs::unmountDirSilent("../data"); - delete2(logger); -} - -#endif // SDL_BYTEORDER == SDL_LIL_ENDIAN -#endif // USE_SDL2 diff --git a/src/unittests/resources/sprite/animatedsprite.cc b/src/unittests/resources/sprite/animatedsprite.cc new file mode 100644 index 000000000..3e4a1826c --- /dev/null +++ b/src/unittests/resources/sprite/animatedsprite.cc @@ -0,0 +1,220 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013-2017 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 . + */ + +#include "unittests/unittests.h" + +#include "configuration.h" +#include "configmanager.h" +#include "client.h" +#include "dirs.h" +#include "graphicsmanager.h" + +#include "const/resources/spriteaction.h" + +#include "being/actorsprite.h" + +#include "fs/virtfs/fs.h" + +#include "gui/gui.h" +#include "gui/theme.h" + +#include "render/sdlgraphics.h" + +#include "resources/sdlimagehelper.h" + +#include "resources/animation/animation.h" + +#include "resources/resourcemanager/resourcemanager.h" + +#include "resources/sprite/animatedsprite.h" + +#include "utils/env.h" +#include "utils/delete2.h" +#include "utils/mrand.h" + +PRAGMA48(GCC diagnostic push) +PRAGMA48(GCC diagnostic ignored "-Wshadow") +#ifndef USE_SDL2 +#include +#endif // USE_SDL2 +PRAGMA48(GCC diagnostic pop) + +#include "debug.h" + +TEST_CASE("AnimatedSprite leak test1", "") +{ + logger = new Logger(); + REQUIRE(gui == nullptr); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); + delete2(logger); +} + +TEST_CASE("AnimatedSprite tests", "animatedsprite") +{ + setEnv("SDL_VIDEODRIVER", "dummy"); + + initRand(); + client = new Client; + XML::initXML(); + SDL_Init(SDL_INIT_VIDEO); + logger = new Logger(); + VirtFs::mountDirSilent("data", Append_false); + VirtFs::mountDirSilent("../data", Append_false); + mainGraphics = new SDLGraphics; + imageHelper = new SDLImageHelper(); +#ifdef USE_SDL2 + SDLImageHelper::setRenderer(graphicsManager.createRenderer( + graphicsManager.createWindow(640, 480, 0, + SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE)); +#else // USE_SDL2 + + graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE); +#endif // USE_SDL2 + + theme = new Theme; + Theme::selectSkin(); + + Dirs::initRootDir(); + Dirs::initHomeDir(); + + ConfigManager::initConfiguration(); + getConfigDefaults2(config.getDefaultValues()); + branding.setDefaultValues(getBrandingDefaults()); + + ActorSprite::load(); + gui = new Gui(); + gui->postInit(mainGraphics); + + SECTION("basic test 1") + { + AnimatedSprite *sprite = AnimatedSprite::load( + "graphics/sprites/error.xml", 0); + sprite->play(SpriteAction::DEFAULT); + + REQUIRE_FALSE(sprite == nullptr); + REQUIRE_FALSE(sprite->getSprite() == nullptr); + REQUIRE_FALSE(sprite->getAnimation() == nullptr); + REQUIRE_FALSE(sprite->getFrame() == nullptr); + REQUIRE(0 == sprite->getFrameIndex()); + REQUIRE(0 == sprite->getFrameTime()); + REQUIRE(false == sprite->update(1)); + REQUIRE(0 == sprite->getFrameTime()); + REQUIRE(false == sprite->update(11)); + REQUIRE(10 == sprite->getFrameTime()); + REQUIRE(0 == sprite->getFrameIndex()); + delete sprite; + logger->log("test4"); + } + + SECTION("basic test 2") + { + AnimatedSprite *sprite = AnimatedSprite::load( + "graphics/sprites/test.xml", 0); + sprite->play(SpriteAction::STAND); + + REQUIRE(10 == const_cast(sprite->getAnimation()) + ->getFrames().size()); + + REQUIRE_FALSE(nullptr == sprite); + + REQUIRE(false == sprite->update(1)); + REQUIRE(0 == sprite->getFrameTime()); + REQUIRE(10 == sprite->getFrame()->delay); + + REQUIRE(false == sprite->update(1 + 10)); + REQUIRE(0 == sprite->getFrameIndex()); + REQUIRE(10 == sprite->getFrameTime()); + + REQUIRE(true == sprite->update(1 + 10 + 5)); + REQUIRE(1 == sprite->getFrameIndex()); + REQUIRE(5 == sprite->getFrameTime()); + + REQUIRE(false == sprite->update(1 + 10 + 5)); + REQUIRE(1 == sprite->getFrameIndex()); + REQUIRE(5 == sprite->getFrameTime()); + + REQUIRE(false == sprite->update(1 + 10 + 20)); + REQUIRE(1 == sprite->getFrameIndex()); + REQUIRE(20 == sprite->getFrameTime()); + + REQUIRE(true == sprite->update(1 + 10 + 20 + 1)); + REQUIRE(2 == sprite->getFrameIndex()); + REQUIRE(1 == sprite->getFrameTime()); + + REQUIRE(false == sprite->update(1 + 10 + 20 + 10)); + REQUIRE(2 == sprite->getFrameIndex()); + REQUIRE(10 == sprite->getFrameTime()); + + REQUIRE(true == sprite->update(1 + 10 + 20 + 10 + 1)); + REQUIRE(4 == sprite->getFrameIndex()); + REQUIRE(1 == sprite->getFrameTime()); + + REQUIRE(false == sprite->update(1 + 10 + 20 + 10 + 25)); + REQUIRE(4 == sprite->getFrameIndex()); + REQUIRE(25 == sprite->getFrameTime()); + + REQUIRE(true == sprite->update(1 + 10 + 20 + 10 + 25 + 1)); + REQUIRE(6 == sprite->getFrameIndex()); + REQUIRE(1 == sprite->getFrameTime()); + + REQUIRE(true == sprite->update(1 + 10 + 20 + 10 + 25 + 10 + 1)); + REQUIRE(8 == sprite->getFrameIndex()); + REQUIRE(1 == sprite->getFrameTime()); + + REQUIRE(true == sprite->update(1 + 10 + 20 + 10 + 25 + 10 + 10 + 1)); + REQUIRE(4 == sprite->getFrameIndex()); + REQUIRE(1 == sprite->getFrameTime()); + delete sprite; + } + + SECTION("basic test 3") + { + AnimatedSprite *sprite2 = AnimatedSprite::load( + "graphics/sprites/test.xml", 0); + sprite2->play(SpriteAction::SIT); + + REQUIRE(false == sprite2->update(1)); + REQUIRE(2 == const_cast(sprite2->getAnimation()) + ->getFrames().size()); + REQUIRE(0 == sprite2->getFrameTime()); + REQUIRE(85 == sprite2->getFrame()->delay); + + REQUIRE(true == sprite2->update(1 + 10 + 20 + 10 + 25 + 10 + 10 + 1)); + REQUIRE(1 == sprite2->getFrameIndex()); + REQUIRE(1 == sprite2->getFrameTime()); + delete sprite2; + } + + delete2(client); + VirtFs::unmountDirSilent("data"); + VirtFs::unmountDirSilent("../data"); + delete2(logger); +// VirtFs::deinit(); +} + +TEST_CASE("AnimatedSprite leak test2", "") +{ + logger = new Logger(); + REQUIRE(gui == nullptr); + ResourceManager::cleanOrphans(true); + ResourceManager::deleteInstance(); + delete2(logger); +} diff --git a/src/unittests/resources/sprite/animatedsprite_unittest.cc b/src/unittests/resources/sprite/animatedsprite_unittest.cc deleted file mode 100644 index 3e4a1826c..000000000 --- a/src/unittests/resources/sprite/animatedsprite_unittest.cc +++ /dev/null @@ -1,220 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2013-2017 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 . - */ - -#include "unittests/unittests.h" - -#include "configuration.h" -#include "configmanager.h" -#include "client.h" -#include "dirs.h" -#include "graphicsmanager.h" - -#include "const/resources/spriteaction.h" - -#include "being/actorsprite.h" - -#include "fs/virtfs/fs.h" - -#include "gui/gui.h" -#include "gui/theme.h" - -#include "render/sdlgraphics.h" - -#include "resources/sdlimagehelper.h" - -#include "resources/animation/animation.h" - -#include "resources/resourcemanager/resourcemanager.h" - -#include "resources/sprite/animatedsprite.h" - -#include "utils/env.h" -#include "utils/delete2.h" -#include "utils/mrand.h" - -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#ifndef USE_SDL2 -#include -#endif // USE_SDL2 -PRAGMA48(GCC diagnostic pop) - -#include "debug.h" - -TEST_CASE("AnimatedSprite leak test1", "") -{ - logger = new Logger(); - REQUIRE(gui == nullptr); - ResourceManager::cleanOrphans(true); - ResourceManager::deleteInstance(); - delete2(logger); -} - -TEST_CASE("AnimatedSprite tests", "animatedsprite") -{ - setEnv("SDL_VIDEODRIVER", "dummy"); - - initRand(); - client = new Client; - XML::initXML(); - SDL_Init(SDL_INIT_VIDEO); - logger = new Logger(); - VirtFs::mountDirSilent("data", Append_false); - VirtFs::mountDirSilent("../data", Append_false); - mainGraphics = new SDLGraphics; - imageHelper = new SDLImageHelper(); -#ifdef USE_SDL2 - SDLImageHelper::setRenderer(graphicsManager.createRenderer( - graphicsManager.createWindow(640, 480, 0, - SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE)); -#else // USE_SDL2 - - graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE); -#endif // USE_SDL2 - - theme = new Theme; - Theme::selectSkin(); - - Dirs::initRootDir(); - Dirs::initHomeDir(); - - ConfigManager::initConfiguration(); - getConfigDefaults2(config.getDefaultValues()); - branding.setDefaultValues(getBrandingDefaults()); - - ActorSprite::load(); - gui = new Gui(); - gui->postInit(mainGraphics); - - SECTION("basic test 1") - { - AnimatedSprite *sprite = AnimatedSprite::load( - "graphics/sprites/error.xml", 0); - sprite->play(SpriteAction::DEFAULT); - - REQUIRE_FALSE(sprite == nullptr); - REQUIRE_FALSE(sprite->getSprite() == nullptr); - REQUIRE_FALSE(sprite->getAnimation() == nullptr); - REQUIRE_FALSE(sprite->getFrame() == nullptr); - REQUIRE(0 == sprite->getFrameIndex()); - REQUIRE(0 == sprite->getFrameTime()); - REQUIRE(false == sprite->update(1)); - REQUIRE(0 == sprite->getFrameTime()); - REQUIRE(false == sprite->update(11)); - REQUIRE(10 == sprite->getFrameTime()); - REQUIRE(0 == sprite->getFrameIndex()); - delete sprite; - logger->log("test4"); - } - - SECTION("basic test 2") - { - AnimatedSprite *sprite = AnimatedSprite::load( - "graphics/sprites/test.xml", 0); - sprite->play(SpriteAction::STAND); - - REQUIRE(10 == const_cast(sprite->getAnimation()) - ->getFrames().size()); - - REQUIRE_FALSE(nullptr == sprite); - - REQUIRE(false == sprite->update(1)); - REQUIRE(0 == sprite->getFrameTime()); - REQUIRE(10 == sprite->getFrame()->delay); - - REQUIRE(false == sprite->update(1 + 10)); - REQUIRE(0 == sprite->getFrameIndex()); - REQUIRE(10 == sprite->getFrameTime()); - - REQUIRE(true == sprite->update(1 + 10 + 5)); - REQUIRE(1 == sprite->getFrameIndex()); - REQUIRE(5 == sprite->getFrameTime()); - - REQUIRE(false == sprite->update(1 + 10 + 5)); - REQUIRE(1 == sprite->getFrameIndex()); - REQUIRE(5 == sprite->getFrameTime()); - - REQUIRE(false == sprite->update(1 + 10 + 20)); - REQUIRE(1 == sprite->getFrameIndex()); - REQUIRE(20 == sprite->getFrameTime()); - - REQUIRE(true == sprite->update(1 + 10 + 20 + 1)); - REQUIRE(2 == sprite->getFrameIndex()); - REQUIRE(1 == sprite->getFrameTime()); - - REQUIRE(false == sprite->update(1 + 10 + 20 + 10)); - REQUIRE(2 == sprite->getFrameIndex()); - REQUIRE(10 == sprite->getFrameTime()); - - REQUIRE(true == sprite->update(1 + 10 + 20 + 10 + 1)); - REQUIRE(4 == sprite->getFrameIndex()); - REQUIRE(1 == sprite->getFrameTime()); - - REQUIRE(false == sprite->update(1 + 10 + 20 + 10 + 25)); - REQUIRE(4 == sprite->getFrameIndex()); - REQUIRE(25 == sprite->getFrameTime()); - - REQUIRE(true == sprite->update(1 + 10 + 20 + 10 + 25 + 1)); - REQUIRE(6 == sprite->getFrameIndex()); - REQUIRE(1 == sprite->getFrameTime()); - - REQUIRE(true == sprite->update(1 + 10 + 20 + 10 + 25 + 10 + 1)); - REQUIRE(8 == sprite->getFrameIndex()); - REQUIRE(1 == sprite->getFrameTime()); - - REQUIRE(true == sprite->update(1 + 10 + 20 + 10 + 25 + 10 + 10 + 1)); - REQUIRE(4 == sprite->getFrameIndex()); - REQUIRE(1 == sprite->getFrameTime()); - delete sprite; - } - - SECTION("basic test 3") - { - AnimatedSprite *sprite2 = AnimatedSprite::load( - "graphics/sprites/test.xml", 0); - sprite2->play(SpriteAction::SIT); - - REQUIRE(false == sprite2->update(1)); - REQUIRE(2 == const_cast(sprite2->getAnimation()) - ->getFrames().size()); - REQUIRE(0 == sprite2->getFrameTime()); - REQUIRE(85 == sprite2->getFrame()->delay); - - REQUIRE(true == sprite2->update(1 + 10 + 20 + 10 + 25 + 10 + 10 + 1)); - REQUIRE(1 == sprite2->getFrameIndex()); - REQUIRE(1 == sprite2->getFrameTime()); - delete sprite2; - } - - delete2(client); - VirtFs::unmountDirSilent("data"); - VirtFs::unmountDirSilent("../data"); - delete2(logger); -// VirtFs::deinit(); -} - -TEST_CASE("AnimatedSprite leak test2", "") -{ - logger = new Logger(); - REQUIRE(gui == nullptr); - ResourceManager::cleanOrphans(true); - ResourceManager::deleteInstance(); - delete2(logger); -} -- cgit v1.2.3-70-g09d2