Skip to content

Commit

Permalink
Add document view mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Jul 19, 2024
1 parent c4ac2a7 commit 8f3e414
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 0 deletions.
5 changes: 5 additions & 0 deletions source/base/test_util/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
InheritParentConfig: true
Checks: "-modernize-use-trailing-return-type,
-modernize-type-traits,
-readability-function-cognitive-complexity,
"
3 changes: 3 additions & 0 deletions source/base/test_util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ target_sources(tactile-base-test-util
"src/ir_presets.cpp"

PUBLIC FILE_SET "HEADERS" BASE_DIRS "inc" FILES
"inc/tactile/base/test_util/document_view_mocks.hpp"
"inc/tactile/base/test_util/ir.hpp"
"inc/tactile/base/test_util/ir_presets.hpp"
)
Expand All @@ -18,4 +19,6 @@ tactile_prepare_target(tactile-base-test-util)
target_link_libraries(tactile-base-test-util
PUBLIC
tactile::base
GTest::gtest
GTest::gmock
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0)

#pragma once

#include <gmock/gmock.h>

#include "tactile/base/document/document_visitor.hpp"
#include "tactile/base/document/layer_view.hpp"
#include "tactile/base/document/map_view.hpp"
#include "tactile/base/document/meta_view.hpp"
#include "tactile/base/document/object_view.hpp"
#include "tactile/base/document/tile_view.hpp"
#include "tactile/base/document/tileset_view.hpp"
#include "tactile/base/prelude.hpp"

namespace tactile::test {

class MetaViewMock : public IMetaView
{
public:
MOCK_METHOD(StringView, get_name, (), (const, override));

MOCK_METHOD((Pair<const String&, const Attribute&>),
get_property,
(usize),
(const, override));

MOCK_METHOD(usize, property_count, (), (const, override));
};

class ObjectViewMock : public IObjectView
{
public:
ObjectViewMock()
{
ON_CALL(*this, accept).WillByDefault([this](IDocumentVisitor& visitor) {
visitor.visit(*this);
});

ON_CALL(*this, get_meta).WillByDefault(testing::ReturnRef(mMeta));
}

MOCK_METHOD(void, accept, (IDocumentVisitor&), (const, override));

MOCK_METHOD(const ILayerView*, get_parent_layer, (), (const, override));

MOCK_METHOD(const ITileView*, get_parent_tile, (), (const, override));

MOCK_METHOD(ObjectType, get_type, (), (const, override));

MOCK_METHOD(ObjectID, get_id, (), (const, override));

MOCK_METHOD(Float2, get_position, (), (const, override));

MOCK_METHOD(Float2, get_size, (), (const, override));

MOCK_METHOD(StringView, get_tag, (), (const, override));

MOCK_METHOD(bool, is_visible, (), (const, override));

MOCK_METHOD(const IMetaView&, get_meta, (), (const, override));

[[nodiscard]]
auto get_meta_view_mock() -> MetaViewMock&
{
return mMeta;
}

private:
testing::NiceMock<MetaViewMock> mMeta {};
};

class TileViewMock : public ITileView
{
public:
TileViewMock()
{
ON_CALL(*this, get_meta).WillByDefault(testing::ReturnRef(mMeta));
}

MOCK_METHOD(void, accept, (IDocumentVisitor&), (const, override));

MOCK_METHOD(const ITilesetView&, get_parent_tileset, (), (const, override));

MOCK_METHOD(TileIndex, get_index, (), (const, override));

MOCK_METHOD(usize, object_count, (), (const, override));

MOCK_METHOD(usize, animation_frame_count, (), (const, override));

MOCK_METHOD((Pair<TileIndex, Milliseconds>),
get_animation_frame,
(usize),
(const, override));

MOCK_METHOD(const IMetaView&, get_meta, (), (const, override));

[[nodiscard]]
auto get_meta_view_mock() -> MetaViewMock&
{
return mMeta;
}

private:
testing::NiceMock<MetaViewMock> mMeta {};
};

class TilesetViewMock : public ITilesetView
{
public:
TilesetViewMock()
{
ON_CALL(*this, get_meta).WillByDefault(testing::ReturnRef(mMeta));
}

MOCK_METHOD(void, accept, (IDocumentVisitor&), (const, override));

MOCK_METHOD(TileID, get_first_tile_id, (), (const, override));

MOCK_METHOD(usize, tile_count, (), (const, override));

MOCK_METHOD(usize, tile_definition_count, (), (const, override));

MOCK_METHOD(usize, column_count, (), (const, override));

MOCK_METHOD(Int2, get_tile_size, (), (const, override));

MOCK_METHOD(Int2, get_image_size, (), (const, override));

MOCK_METHOD(const Path&, get_image_path, (), (const, override));

MOCK_METHOD(const IMetaView&, get_meta, (), (const, override));

[[nodiscard]]
auto get_meta_view_mock() -> MetaViewMock&
{
return mMeta;
}

private:
testing::NiceMock<MetaViewMock> mMeta {};
};

class LayerViewMock : public ILayerView
{
public:
LayerViewMock()
{
ON_CALL(*this, get_meta).WillByDefault(testing::ReturnRef(mMeta));
}

MOCK_METHOD(void, accept, (IDocumentVisitor&), (const, override));

MOCK_METHOD(const ILayerView*, get_parent_layer, (), (const, override));

MOCK_METHOD(LayerID, get_id, (), (const, override));

MOCK_METHOD(LayerType, get_type, (), (const, override));

MOCK_METHOD(float, get_opacity, (), (const, override));

MOCK_METHOD(bool, is_visible, (), (const, override));

MOCK_METHOD(usize, get_global_index, (), (const, override));

MOCK_METHOD(Optional<TileID>, get_tile, (const MatrixIndex&), (const, override));

MOCK_METHOD(Optional<MatrixExtent>, get_extent, (), (const, override));

MOCK_METHOD(const IMetaView&, get_meta, (), (const, override));

[[nodiscard]]
auto get_meta_view_mock() -> MetaViewMock&
{
return mMeta;
}

private:
testing::NiceMock<MetaViewMock> mMeta {};
};

class MapViewMock : public IMapView
{
public:
MapViewMock()
{
ON_CALL(*this, get_meta).WillByDefault(testing::ReturnRef(mMeta));
}

MOCK_METHOD(void, accept, (IDocumentVisitor&), (const, override));

MOCK_METHOD(Int2, get_tile_size, (), (const, override));

MOCK_METHOD(MatrixExtent, get_extent, (), (const, override));

MOCK_METHOD(LayerID, get_next_layer_id, (), (const, override));

MOCK_METHOD(ObjectID, get_next_object_id, (), (const, override));

MOCK_METHOD(TileEncoding, get_tile_encoding, (), (const, override));

MOCK_METHOD(Optional<CompressionFormat>, get_tile_compression, (), (const, override));

MOCK_METHOD(Optional<int>, get_compression_level, (), (const, override));

MOCK_METHOD(usize, layer_count, (), (const, override));

MOCK_METHOD(usize, tileset_count, (), (const, override));

MOCK_METHOD(usize, component_count, (), (const, override));

MOCK_METHOD(const IMetaView&, get_meta, (), (const, override));

[[nodiscard]]
auto get_meta_view_mock() -> MetaViewMock&
{
return mMeta;
}

private:
testing::NiceMock<MetaViewMock> mMeta {};
};

} // namespace tactile::test

0 comments on commit 8f3e414

Please sign in to comment.