DoorKeeper/test/unit/asciimapsource.cpp

44 lines
1.6 KiB
C++
Raw Normal View History

#include <gtest/gtest.h>
#include "doorkeeper/helpers/asciimapsource.hpp"
#include "doorkeeper/doorkeeper.hpp"
#include <sstream>
#include <memory>
TEST(load, asciimapsource) {
typedef dk::Tyler<2>::coords coords2;
typedef std::unique_ptr<dkh::AsciiMapSource> AsciiMapSourceUPtr;
const char map_data[] =
"1101111001\n1101111001\n1110111100\n1110111000\n"
"1111011011\n1111010111\n1111101111\n1111111111\n";
const dk::CoordinateScalarType tile_size = 64;
const dk::CoordinateScalarType map_width = 10;
const dk::CoordinateScalarType map_height = 8;
std::istringstream iss((std::string(map_data)));
dk::Tyler<2> tiler((coords2(tile_size)));
AsciiMapSourceUPtr loader(new dkh::AsciiMapSource(iss, coords2(map_width, map_height), dk::MapType_Isometric, coords2(tile_size)));
auto layer = &tiler.push_layer<dkh::AsciiMapSource::MapTileType>(loader.get(), 0);
dk::Viewport<2> full_view(tiler, coords2(map_width, map_height), coords2(0));
EXPECT_EQ(coords2(map_width, map_height), tiler.map_size());
dk::CoordinateDistType index = 0;
int data_index = 0;
full_view.setFrom(coords2(0));
for (auto itTile = full_view.begin(*layer), itTileEND = full_view.end(*layer); itTile != itTileEND; ++itTile) {
EXPECT_EQ(index, dk::to_index(itTile.raw_coords()));
EXPECT_LT(index, sizeof(map_data));
ASSERT_LT(data_index, sizeof(map_data));
const auto expected_value = static_cast<dk::CoordinateScalarType>(map_data[data_index] - '0');
EXPECT_EQ(expected_value, *itTile);
++index;
++data_index;
if (map_data[data_index] == '\n') {
++data_index;
}
}
EXPECT_EQ(map_width * map_height, index);
}