-
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
59a0d9e
commit e9c6d87
Showing
2 changed files
with
125 additions
and
0 deletions.
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
124 changes: 124 additions & 0 deletions
124
source/core/test/src/document/object_view_impl_test.cpp
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,124 @@ | ||
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0) | ||
|
||
#include "tactile/core/document/object_view_impl.hpp" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "tactile/core/document/layer_view_impl.hpp" | ||
#include "tactile/core/document/map_document.hpp" | ||
#include "tactile/core/document/tile_view_impl.hpp" | ||
#include "tactile/core/document/tileset_view_impl.hpp" | ||
#include "tactile/core/entity/registry.hpp" | ||
#include "tactile/core/layer/object.hpp" | ||
#include "tactile/core/layer/object_layer.hpp" | ||
#include "tactile/core/map/map_spec.hpp" | ||
#include "tactile/core/tile/tile.hpp" | ||
#include "tactile/core/tile/tileset.hpp" | ||
#include "tactile/core/tile/tileset_spec.hpp" | ||
#include "test/document_testing.hpp" | ||
|
||
namespace tactile::test { | ||
|
||
class ObjectViewImplTest : public testing::Test | ||
{ | ||
public: | ||
ObjectViewImplTest() | ||
: mMapSpec {kOrthogonalMapSpec}, | ||
mDocument {mMapSpec} | ||
{} | ||
|
||
protected: | ||
MapSpec mMapSpec; | ||
MapDocument mDocument; | ||
}; | ||
|
||
// tactile::ObjectViewImpl::ObjectViewImpl | ||
TEST_F(ObjectViewImplTest, Constructors) | ||
{ | ||
const ILayerView* layer_view = nullptr; | ||
const ITileView* tile_view = nullptr; | ||
|
||
EXPECT_ANY_THROW(ObjectViewImpl(nullptr, layer_view, kInvalidEntity)); | ||
EXPECT_ANY_THROW(ObjectViewImpl(nullptr, tile_view, kInvalidEntity)); | ||
|
||
EXPECT_ANY_THROW(ObjectViewImpl(&mDocument, layer_view, kInvalidEntity)); | ||
EXPECT_ANY_THROW(ObjectViewImpl(&mDocument, tile_view, kInvalidEntity)); | ||
} | ||
|
||
// tactile::ObjectViewImpl::get_parent_layer | ||
// tactile::ObjectViewImpl::get_parent_tile | ||
// tactile::ObjectViewImpl::get_type | ||
// tactile::ObjectViewImpl::get_id | ||
// tactile::ObjectViewImpl::get_position | ||
// tactile::ObjectViewImpl::get_size | ||
// tactile::ObjectViewImpl::get_tag | ||
// tactile::ObjectViewImpl::is_visible | ||
TEST_F(ObjectViewImplTest, ObjectInObjectLayer) | ||
{ | ||
auto& registry = mDocument.get_registry(); | ||
|
||
const auto layer_id = make_object_layer(registry); | ||
const auto object_id = make_object(registry, ObjectID {1}, ObjectType::kRect); | ||
|
||
auto& object_layer = registry.get<CObjectLayer>(layer_id); | ||
object_layer.objects.push_back(object_id); | ||
|
||
auto& object = registry.get<CObject>(object_id); | ||
object.position = Float2 {12, 34}; | ||
object.size = Float2 {56, 78}; | ||
object.tag = "tag"; | ||
|
||
const LayerViewImpl layer_view {&mDocument, nullptr, layer_id}; | ||
const ObjectViewImpl object_view {&mDocument, &layer_view, object_id}; | ||
|
||
EXPECT_EQ(object_view.get_parent_layer(), &layer_view); | ||
EXPECT_EQ(object_view.get_parent_tile(), nullptr); | ||
EXPECT_EQ(object_view.get_type(), object.type); | ||
EXPECT_EQ(object_view.get_id(), object.id); | ||
EXPECT_EQ(object_view.get_position(), object.position); | ||
EXPECT_EQ(object_view.get_size(), object.size); | ||
EXPECT_EQ(object_view.get_tag(), object.tag); | ||
EXPECT_EQ(object_view.is_visible(), object.is_visible); | ||
} | ||
|
||
// tactile::ObjectViewImpl::get_parent_layer | ||
// tactile::ObjectViewImpl::get_parent_tile | ||
// tactile::ObjectViewImpl::get_type | ||
// tactile::ObjectViewImpl::get_id | ||
// tactile::ObjectViewImpl::get_position | ||
// tactile::ObjectViewImpl::get_size | ||
// tactile::ObjectViewImpl::get_tag | ||
// tactile::ObjectViewImpl::is_visible | ||
TEST_F(ObjectViewImplTest, ObjectInTile) | ||
{ | ||
auto& registry = mDocument.get_registry(); | ||
|
||
const auto tileset_id = make_tileset(registry, kDummyTilesetSpec); | ||
const auto& tileset = registry.get<CTileset>(tileset_id); | ||
|
||
const auto tile_id = tileset.tiles.front(); | ||
const auto object_id = make_object(registry, ObjectID {1}, ObjectType::kRect); | ||
|
||
auto& tile = registry.get<CTile>(tile_id); | ||
tile.objects.push_back(object_id); | ||
|
||
auto& object = registry.get<CObject>(object_id); | ||
object.position = Float2 {-23, 15}; | ||
object.size = Float2 {10, 12}; | ||
object.tag = "foo"; | ||
|
||
const TilesetViewImpl tileset_view {&mDocument, tileset_id}; | ||
const TileViewImpl tile_view {&mDocument, &tileset_view, tile_id}; | ||
const ObjectViewImpl object_view {&mDocument, &tile_view, object_id}; | ||
|
||
EXPECT_EQ(object_view.get_parent_layer(), nullptr); | ||
EXPECT_EQ(object_view.get_parent_tile(), &tile_view); | ||
EXPECT_EQ(object_view.get_type(), object.type); | ||
EXPECT_EQ(object_view.get_id(), object.id); | ||
EXPECT_EQ(object_view.get_position(), object.position); | ||
EXPECT_EQ(object_view.get_size(), object.size); | ||
EXPECT_EQ(object_view.get_tag(), object.tag); | ||
EXPECT_EQ(object_view.is_visible(), object.is_visible); | ||
} | ||
|
||
} // namespace tactile::test |