diff --git a/source/base/test_util/.clang-tidy b/source/base/test_util/.clang-tidy new file mode 100644 index 0000000000..acce258686 --- /dev/null +++ b/source/base/test_util/.clang-tidy @@ -0,0 +1,5 @@ +InheritParentConfig: true +Checks: "-modernize-use-trailing-return-type, + -modernize-type-traits, + -readability-function-cognitive-complexity, + " \ No newline at end of file diff --git a/source/base/test_util/CMakeLists.txt b/source/base/test_util/CMakeLists.txt index a7a1f3e83b..0b1aed661c 100644 --- a/source/base/test_util/CMakeLists.txt +++ b/source/base/test_util/CMakeLists.txt @@ -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" ) @@ -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 ) diff --git a/source/base/test_util/inc/tactile/base/test_util/document_view_mocks.hpp b/source/base/test_util/inc/tactile/base/test_util/document_view_mocks.hpp new file mode 100644 index 0000000000..5948f64e5e --- /dev/null +++ b/source/base/test_util/inc/tactile/base/test_util/document_view_mocks.hpp @@ -0,0 +1,224 @@ +// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0) + +#pragma once + +#include + +#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), + 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 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), + 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 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 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, get_tile, (const MatrixIndex&), (const, override)); + + MOCK_METHOD(Optional, get_extent, (), (const, override)); + + MOCK_METHOD(const IMetaView&, get_meta, (), (const, override)); + + [[nodiscard]] + auto get_meta_view_mock() -> MetaViewMock& + { + return mMeta; + } + + private: + testing::NiceMock 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, get_tile_compression, (), (const, override)); + + MOCK_METHOD(Optional, 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 mMeta {}; +}; + +} // namespace tactile::test