Skip to content

Commit

Permalink
Add layer view test
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Jul 14, 2024
1 parent e9c6d87 commit e6bb178
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/core/inc/tactile/core/layer/tile_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Registry;
/**
* Tag component for tile layers.
*/
struct CTileLayer final : CTag
struct CTileLayer final
{
/** The associated tile data. */
Variant<DenseTileMatrix, SparseTileMatrix> tiles;
Expand Down
1 change: 1 addition & 0 deletions source/core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ target_sources(tactile-core-test
"src/cmd/command_stack_test.cpp"
"src/debug/validation_test.cpp"
"src/debug/validation_test.cpp"
"src/document/layer_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
87 changes: 87 additions & 0 deletions source/core/test/src/document/layer_view_impl_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0)

#include "tactile/core/document/layer_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/layer.hpp"
#include "tactile/core/layer/object_layer.hpp"
#include "tactile/core/layer/tile_layer.hpp"
#include "tactile/core/map/map.hpp"
#include "tactile/core/map/map_spec.hpp"
#include "test/document_testing.hpp"

namespace tactile::test {

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

void SetUp() override
{
const auto map_id = mDocument.get_root_entity();
auto& registry = mDocument.get_registry();

auto& map = registry.get<CMap>(map_id);
auto& root_layer = registry.get<CGroupLayer>(map.root_layer);

mObjectLayerId = make_object_layer(registry);
mTileLayerId = make_tile_layer(registry, mMapSpec.extent);

root_layer.layers.push_back(mObjectLayerId);
root_layer.layers.push_back(mTileLayerId);
}

protected:
MapSpec mMapSpec;
MapDocument mDocument;
EntityID mTileLayerId {kInvalidEntity};
EntityID mObjectLayerId {kInvalidEntity};
};

// tactile::LayerViewImpl::LayerViewImpl
TEST_F(LayerViewImplTest, Constructor)
{
EXPECT_ANY_THROW(LayerViewImpl(nullptr, nullptr, kInvalidEntity));
}

// tactile::LayerViewImpl::get_parent_layer
// tactile::LayerViewImpl::get_type
// tactile::LayerViewImpl::get_opacity
// tactile::LayerViewImpl::is_visible
// tactile::LayerViewImpl::get_global_index
// tactile::LayerViewImpl::get_tile
// tactile::LayerViewImpl::get_extent
TEST_F(LayerViewImplTest, Getters)
{
auto& registry = mDocument.get_registry();

const auto& map = registry.get<CMap>(mDocument.get_root_entity());
const auto layer_id = mTileLayerId;

auto& layer = registry.get<CLayer>(layer_id);
layer.persistent_id = 42;
layer.opacity = 0.5f;
layer.visible = false;

const LayerViewImpl layer_view {&mDocument, nullptr, layer_id};

EXPECT_EQ(layer_view.get_parent_layer(), nullptr);
EXPECT_EQ(layer_view.get_type(), LayerType::kTileLayer);
EXPECT_EQ(layer_view.get_opacity(), layer.opacity);
EXPECT_EQ(layer_view.is_visible(), layer.visible);
EXPECT_EQ(layer_view.get_global_index(),
get_global_layer_index(registry, map.root_layer, layer_id));

EXPECT_EQ(layer_view.get_extent(), mMapSpec.extent);
EXPECT_EQ(layer_view.get_tile(MatrixIndex {0, 0}), kEmptyTile);
}

} // namespace tactile::test

0 comments on commit e6bb178

Please sign in to comment.