2015-08-16 22:41:21 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "doorkeeper/helpers/asciimapsource.hpp"
|
|
|
|
#include "doorkeeper/doorkeeper.hpp"
|
2015-08-17 13:39:28 +00:00
|
|
|
#include "doorkeeper/components/pixelconv.hpp"
|
2015-08-17 11:36:47 +00:00
|
|
|
#include "asciimapsource.hpp"
|
2015-08-16 22:41:21 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <memory>
|
|
|
|
|
2015-08-17 11:36:47 +00:00
|
|
|
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;
|
2015-08-16 22:41:21 +00:00
|
|
|
|
2015-08-17 11:36:47 +00:00
|
|
|
asciimapsource::asciimapsource() :
|
|
|
|
tiler(coords2(tile_size)),
|
|
|
|
layer(nullptr)
|
|
|
|
{
|
2015-08-16 22:41:21 +00:00
|
|
|
std::istringstream iss((std::string(map_data)));
|
2015-08-17 11:36:47 +00:00
|
|
|
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);
|
|
|
|
}
|
2015-08-16 22:41:21 +00:00
|
|
|
|
2015-08-17 11:36:47 +00:00
|
|
|
TEST_F(asciimapsource, load) {
|
2015-08-16 22:41:21 +00:00
|
|
|
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);
|
|
|
|
}
|
2015-08-17 11:36:47 +00:00
|
|
|
|
|
|
|
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) {
|
2015-08-17 13:39:28 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2015-08-17 11:36:47 +00:00
|
|
|
}
|
|
|
|
}
|