Skip to content

Commit

Permalink
Add map view test
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Jul 14, 2024
1 parent e6bb178 commit c0443c8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ target_sources(tactile-core-test
"src/debug/validation_test.cpp"
"src/debug/validation_test.cpp"
"src/document/layer_view_impl_test.cpp"
"src/document/map_view_impl_test.cpp"
"src/document/meta_view_impl_test.cpp"
"src/document/tile_view_impl_test.cpp"
"src/document/tileset_view_impl_test.cpp"
Expand Down
64 changes: 64 additions & 0 deletions source/core/test/src/document/map_view_impl_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0)

#include "tactile/core/document/map_view_impl.hpp"

#include <gtest/gtest.h>

#include "tactile/core/document/map_document.hpp"
#include "tactile/core/entity/registry.hpp"
#include "tactile/core/layer/group_layer.hpp"
#include "tactile/core/layer/object_layer.hpp"
#include "tactile/core/map/map.hpp"
#include "tactile/core/map/map_spec.hpp"
#include "test/document_testing.hpp"

namespace tactile::test {

class MapViewImplTest : public testing::Test
{
public:
MapViewImplTest()
: mMapSpec {kOrthogonalMapSpec},
mDocument {mMapSpec}
{}

protected:
MapSpec mMapSpec;
MapDocument mDocument;
};

// tactile::MapViewImpl::get_tile_size
// tactile::MapViewImpl::get_extent
// tactile::MapViewImpl::get_next_layer_id
// tactile::MapViewImpl::get_next_object_id
// tactile::MapViewImpl::layer_count
// tactile::MapViewImpl::tileset_count
TEST_F(MapViewImplTest, Getters)
{
const auto map_id = mDocument.get_root_entity();
auto& registry = mDocument.get_registry();

auto& map = registry.get<CMap>(map_id);
map.attached_tilesets.push_back(registry.make_entity());

auto& id_cache = registry.get<CMapIdCache>(map_id);
id_cache.next_layer_id = LayerID {7};
id_cache.next_object_id = ObjectID {42};

auto& root_layer = registry.get<CGroupLayer>(map.root_layer);
root_layer.layers.push_back(make_object_layer(registry));
root_layer.layers.push_back(make_object_layer(registry));
root_layer.layers.push_back(make_object_layer(registry));

const MapViewImpl map_view {&mDocument};

EXPECT_EQ(map_view.get_tile_size(), map.tile_size);
EXPECT_EQ(map_view.get_extent(), map.extent);
EXPECT_EQ(map_view.get_next_layer_id(), id_cache.next_layer_id);
EXPECT_EQ(map_view.get_next_object_id(), id_cache.next_object_id);
EXPECT_EQ(map_view.layer_count(), count_layers(registry, map.root_layer));
EXPECT_EQ(map_view.tileset_count(), map.attached_tilesets.size());
// TODO component_count
}

} // namespace tactile::test

0 comments on commit c0443c8

Please sign in to comment.