summaryrefslogtreecommitdiff
path: root/src/unittests/resources/map/maplayer/gettiledrawwidth.cc
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-07-07 17:15:53 +0300
committerAndrei Karas <akaras@inbox.ru>2017-07-07 19:18:09 +0300
commitdea7c612d06b37ab6575d5441f0b52c5ccb2e92b (patch)
tree6deeb7d490dd751502a1378c0b7d1bd6695de9e4 /src/unittests/resources/map/maplayer/gettiledrawwidth.cc
parent130f07fd84bfdf781eb42903b3fcbabc26199a3a (diff)
downloadmanaverse-dea7c612d06b37ab6575d5441f0b52c5ccb2e92b.tar.gz
manaverse-dea7c612d06b37ab6575d5441f0b52c5ccb2e92b.tar.bz2
manaverse-dea7c612d06b37ab6575d5441f0b52c5ccb2e92b.tar.xz
manaverse-dea7c612d06b37ab6575d5441f0b52c5ccb2e92b.zip
Split maplayer unit tests into separate files.
Diffstat (limited to 'src/unittests/resources/map/maplayer/gettiledrawwidth.cc')
-rw-r--r--src/unittests/resources/map/maplayer/gettiledrawwidth.cc411
1 files changed, 411 insertions, 0 deletions
diff --git a/src/unittests/resources/map/maplayer/gettiledrawwidth.cc b/src/unittests/resources/map/maplayer/gettiledrawwidth.cc
new file mode 100644
index 000000000..0b72e310b
--- /dev/null
+++ b/src/unittests/resources/map/maplayer/gettiledrawwidth.cc
@@ -0,0 +1,411 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "unittests/unittests.h"
+
+#include "graphicsmanager.h"
+
+#include "being/localplayer.h"
+
+#include "enums/resources/map/blockmask.h"
+#include "enums/resources/map/mapitemtype.h"
+
+#include "fs/virtfs/fs.h"
+
+#include "gui/theme.h"
+
+#include "unittests/render/mockgraphics.h"
+
+#include "utils/delete2.h"
+#include "utils/env.h"
+
+#include "resources/sdlimagehelper.h"
+
+#include "resources/image/image.h"
+
+#include "resources/map/map.h"
+#include "resources/map/maplayer.h"
+#include "resources/map/speciallayer.h"
+
+#include "debug.h"
+
+TEST_CASE("MapLayer getTileDrawWidth", "")
+{
+ Image *const img1 = new Image(32, 32);
+ Image *const img2 = new Image(32, 32);
+ Image *const img3 = new Image(32, 32);
+ MapLayer *layer = nullptr;
+ int width;
+ int nextTile;
+
+ SECTION("simple 1")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 1, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ TileInfo *const tiles = layer->getTiles();
+ REQUIRE(layer->getTileDrawWidth(tiles,
+ 1,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+ }
+
+ SECTION("simple 2")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 2, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ TileInfo *const tiles = layer->getTiles();
+ REQUIRE(layer->getTileDrawWidth(tiles,
+ 2,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 1);
+ }
+
+ SECTION("simple 3")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 2, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(1, 0, img2);
+ TileInfo *const tiles = layer->getTiles();
+ REQUIRE(layer->getTileDrawWidth(tiles,
+ 1,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 1,
+ 1,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+ }
+
+ SECTION("simple 4")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 2, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(1, 0, img1);
+ TileInfo *const tiles = layer->getTiles();
+ REQUIRE(layer->getTileDrawWidth(tiles,
+ 2,
+ width,
+ nextTile) == 1);
+ REQUIRE(width == 64);
+ REQUIRE(nextTile == 1);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 1,
+ 1,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+ }
+
+ SECTION("simple 4.2")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 3, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(2, 0, img1);
+ TileInfo *const tiles = layer->getTiles();
+ REQUIRE(layer->getTileDrawWidth(tiles,
+ 3,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 1);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 2,
+ 1,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+ }
+
+ SECTION("simple 5")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 3, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(1, 0, img1);
+ TileInfo *const tiles = layer->getTiles();
+ REQUIRE(layer->getTileDrawWidth(tiles,
+ 3,
+ width,
+ nextTile) == 1);
+ REQUIRE(width == 64);
+ REQUIRE(nextTile == 2);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 1,
+ 2,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 1);
+ }
+
+ SECTION("simple 6")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 3, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(1, 0, img1);
+ layer->setTile(2, 0, img2);
+ TileInfo *const tiles = layer->getTiles();
+ REQUIRE(layer->getTileDrawWidth(tiles,
+ 3,
+ width,
+ nextTile) == 1);
+ REQUIRE(width == 64);
+ REQUIRE(nextTile == 1);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 1,
+ 2,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 2,
+ 1,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+ }
+
+ SECTION("simple 7")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 3, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(1, 0, img1);
+ layer->setTile(2, 0, img2);
+ TileInfo *const tiles = layer->getTiles();
+ tiles[1].isEnabled = false;
+ REQUIRE(layer->getTileDrawWidth(tiles,
+ 3,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 1);
+
+// REQUIRE(layer->getTileDrawWidth(tiles + 1,
+// 2,
+// width,
+// nextTile) == 0);
+// REQUIRE(width == 32);
+// REQUIRE(nextTile == 0);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 2,
+ 1,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+ }
+
+ SECTION("simple 8")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 3, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(1, 0, img1);
+ layer->setTile(2, 0, img2);
+ TileInfo *const tiles = layer->getTiles();
+ tiles[0].isEnabled = false;
+// REQUIRE(layer->getTileDrawWidth(tiles,
+// 3,
+// width,
+// nextTile) == 1);
+// REQUIRE(width == 0);
+// REQUIRE(nextTile == 1);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 1,
+ 2,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 2,
+ 1,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+ }
+
+ SECTION("normal 1")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 100, 100,
+ false,
+ 0,
+ 0);
+ layer->setTile(1, 10, img1);
+ layer->setTile(2, 10, img1);
+ layer->setTile(3, 10, img1);
+ layer->setTile(4, 10, img2);
+ layer->setTile(5, 10, nullptr);
+ layer->setTile(6, 10, img2);
+ layer->setTile(7, 10, nullptr);
+ layer->setTile(8, 10, nullptr);
+ layer->setTile(9, 10, img2);
+ layer->setTile(10, 10, img2);
+ layer->setTile(11, 10, img3);
+ layer->setTile(12, 10, nullptr);
+ layer->setTile(13, 10, nullptr);
+ layer->setTile(14, 10, nullptr);
+ layer->setTile(15, 10, img1);
+ layer->setTile(16, 10, img1);
+ layer->setTile(17, 10, img1);
+ TileInfo *const tiles = layer->getTiles();
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 1,
+ 100 - 1,
+ width,
+ nextTile) == 2);
+ REQUIRE(width == 96);
+ REQUIRE(nextTile == 2);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 2,
+ 100 - 2,
+ width,
+ nextTile) == 1);
+ REQUIRE(width == 64);
+ REQUIRE(nextTile == 1);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 3,
+ 100 - 3,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 4,
+ 100 - 4,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 1);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 6,
+ 100 - 6,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 2);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 9,
+ 100 - 9,
+ width,
+ nextTile) == 1);
+ REQUIRE(width == 64);
+ REQUIRE(nextTile == 1);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 10,
+ 100 - 10,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 11,
+ 100 - 11,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 3);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 15,
+ 100 - 15,
+ width,
+ nextTile) == 2);
+ REQUIRE(width == 96);
+ REQUIRE(nextTile == 84);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 16,
+ 100 - 16,
+ width,
+ nextTile) == 1);
+ REQUIRE(width == 64);
+ REQUIRE(nextTile == 83);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 10 * 100 + 17,
+ 100 - 17,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 82);
+ }
+
+ delete layer;
+ delete img1;
+ delete img2;
+ delete img3;
+}