DoorKeeper/test/unit/asciimapsource.cpp

64 lines
2.2 KiB
C++

#include <gtest/gtest.h>
#include "doorkeeper/helpers/asciimapsource.hpp"
#include "doorkeeper/doorkeeper.hpp"
#include "doorkeeper/components/pixelconv.hpp"
#include "asciimapsource.hpp"
#include <sstream>
#include <memory>
const char asciimapsource::map_data[] =
"1101111001\n1101111001\n1110111100\n1110111000\n"
"1111011011\n1111010111\n1111101111\n1111111111\n";
const dk::CoordinateScalarType asciimapsource::tile_size = 64;
const dk::CoordinateScalarType asciimapsource::map_width = 10;
const dk::CoordinateScalarType asciimapsource::map_height = 8;
asciimapsource::asciimapsource() :
tiler(coords2(tile_size)),
layer(nullptr)
{
std::istringstream iss((std::string(map_data)));
loader.reset(new dkh::AsciiMapSource(iss, coords2(map_width, map_height), dk::MapType_Isometric, coords2(tile_size)));
layer = &tiler.push_layer<dkh::AsciiMapSource::MapTileType>(loader.get(), 0);
}
void asciimapsource::SetUp() {
ASSERT_NE(nullptr, layer);
}
TEST_F(asciimapsource, load) {
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);
}
TEST_F(asciimapsource, coordinates) {
const coords2 tile_size(32);
dk::Viewport<2> full_view(tiler, coords2(map_width, map_height), coords2(0));
full_view.setFrom(coords2(0));
for (auto itTile = full_view.begin(*layer), itTileEND = full_view.end(*layer); itTile != itTileEND; ++itTile) {
{
const coords2 expected_coords(tile_size * itTile.position());
const auto returned_coords(dk::get_square_coordinates<2>(itTile, tile_size));
EXPECT_EQ(expected_coords, returned_coords);
}
}
}