diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-07-07 17:15:53 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-07-07 19:18:09 +0300 |
commit | dea7c612d06b37ab6575d5441f0b52c5ccb2e92b (patch) | |
tree | 6deeb7d490dd751502a1378c0b7d1bd6695de9e4 /src/unittests/resources/map/maplayer/updateconditiontiles.cc | |
parent | 130f07fd84bfdf781eb42903b3fcbabc26199a3a (diff) | |
download | manaverse-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/updateconditiontiles.cc')
-rw-r--r-- | src/unittests/resources/map/maplayer/updateconditiontiles.cc | 240 |
1 files changed, 240 insertions, 0 deletions
diff --git a/src/unittests/resources/map/maplayer/updateconditiontiles.cc b/src/unittests/resources/map/maplayer/updateconditiontiles.cc new file mode 100644 index 000000000..b0711b3ee --- /dev/null +++ b/src/unittests/resources/map/maplayer/updateconditiontiles.cc @@ -0,0 +1,240 @@ +/* + * 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 updateConditionTiles", "") +{ + Image *const img1 = new Image(32, 32); + Map *map = nullptr; + MapLayer *layer = nullptr; + + SECTION("simple 1") + { + map = new Map("map", + 1, 1, + 32, 32); + layer = new MapLayer("test", + 0, 0, + 1, 1, + false, + 0, + 0); + layer->setTile(0, 0, img1); + map->addLayer(layer); + layer->setTileCondition(BlockMask::WATER); + TileInfo *const tiles = layer->getTiles(); + + map->addBlockMask(0, 0, BlockType::NONE); + layer->updateConditionTiles(map->getMetaTiles(), + 1, 1); + REQUIRE(tiles[0].isEnabled == false); + + map->addBlockMask(0, 0, BlockType::WATER); + layer->updateConditionTiles(map->getMetaTiles(), + 1, 1); + REQUIRE(tiles[0].isEnabled == true); + } + + SECTION("normal 1") + { + map = new Map("map", + 100, 200, + 32, 32); + layer = new MapLayer("test", + 0, 0, + 100, 200, + false, + 0, + 0); + layer->setTile(10, 10, img1); + layer->setTile(10, 20, img1); + layer->setTile(10, 30, img1); + map->addLayer(layer); + layer->setTileCondition(BlockMask::WATER); + TileInfo *const tiles = layer->getTiles(); + + map->addBlockMask(10, 10, BlockType::NONE); + map->addBlockMask(10, 20, BlockType::NONE); + map->addBlockMask(20, 20, BlockType::NONE); + layer->updateConditionTiles(map->getMetaTiles(), + 100, 200); + for (int x = 0; x < 100; x ++) + { + for (int y = 0; y < 200; y ++) + { + REQUIRE(tiles[y * 100 + x].isEnabled == false); + } + } + } + + SECTION("normal 2") + { + map = new Map("map", + 100, 200, + 32, 32); + layer = new MapLayer("test", + 0, 0, + 100, 200, + false, + 0, + 0); + layer->setTile(10, 10, img1); + layer->setTile(10, 20, img1); + layer->setTile(10, 30, img1); + map->addLayer(layer); + layer->setTileCondition(BlockMask::WATER); + TileInfo *const tiles = layer->getTiles(); + + map->addBlockMask(10, 10, BlockType::WATER); + map->addBlockMask(10, 20, BlockType::WATER); + map->addBlockMask(20, 20, BlockType::WATER); + layer->updateConditionTiles(map->getMetaTiles(), + 100, 200); + for (int x = 0; x < 100; x ++) + { + for (int y = 0; y < 200; y ++) + { + if ((x == 10 && y == 10) || (x == 10 && y == 20)) + { + REQUIRE(tiles[y * 100 + x].isEnabled == true); + } + else + { + REQUIRE(tiles[y * 100 + x].isEnabled == false); + } + } + } + } + + SECTION("normal 3") + { + map = new Map("map", + 100, 200, + 32, 32); + layer = new MapLayer("test", + 0, 0, + 100, 200, + false, + 0, + 0); + for (int x = 0; x < 100; x ++) + { + for (int y = 0; y < 200; y ++) + { + layer->setTile(x, y, img1); + } + } + map->addLayer(layer); + layer->setTileCondition(BlockMask::WATER); + TileInfo *const tiles = layer->getTiles(); + + map->addBlockMask(10, 10, BlockType::WATER); + map->addBlockMask(10, 20, BlockType::WATER); + layer->updateConditionTiles(map->getMetaTiles(), + 100, 200); + for (int x = 0; x < 100; x ++) + { + for (int y = 0; y < 200; y ++) + { + if ((x == 10 && y == 10) || (x == 10 && y == 20)) + { + REQUIRE(tiles[y * 100 + x].isEnabled == true); + } + else + { + REQUIRE(tiles[y * 100 + x].isEnabled == false); + } + } + } + } + + SECTION("normal 4") + { + map = new Map("map", + 100, 200, + 32, 32); + layer = new MapLayer("test", + 0, 0, + 100, 200, + false, + 0, + 0); + layer->setTile(10, 10, img1); + layer->setTile(10, 20, img1); + map->addLayer(layer); + layer->setTileCondition(BlockMask::WATER); + TileInfo *const tiles = layer->getTiles(); + + for (int x = 0; x < 100; x ++) + { + for (int y = 0; y < 200; y ++) + { + map->addBlockMask(x, y, BlockType::WATER); + } + } + + layer->updateConditionTiles(map->getMetaTiles(), + 100, 200); + for (int x = 0; x < 100; x ++) + { + for (int y = 0; y < 200; y ++) + { + if ((x == 10 && y == 10) || (x == 10 && y == 20)) + { + REQUIRE(tiles[y * 100 + x].isEnabled == true); + } + else + { + REQUIRE(tiles[y * 100 + x].isEnabled == false); + } + } + } + } + + delete map; + delete img1; +} |