-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9c6d87
commit e6bb178
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |