From d7b382c508baca88a3408af7a0a669996791f3bb Mon Sep 17 00:00:00 2001 From: Anton Kashcheev Date: Tue, 17 Sep 2024 20:12:05 +0500 Subject: [PATCH] Add 'Common/TypeMapper' with tests --- include/FlameIDE/Common/Traits/Functional.hpp | 38 +++++++++++++++ src/Common/Tests/FunctionalTraitTest.cpp | 47 +++++++++++++++++++ src/Common/Tests/FunctionalTraitTest.hpp | 26 ++++++++++ src/Common/Tests/Sources.cmake | 2 + src/Common/Tests/TestAggregator.cpp | 2 + 5 files changed, 115 insertions(+) create mode 100644 src/Common/Tests/FunctionalTraitTest.cpp create mode 100644 src/Common/Tests/FunctionalTraitTest.hpp diff --git a/include/FlameIDE/Common/Traits/Functional.hpp b/include/FlameIDE/Common/Traits/Functional.hpp index 635df965..f81efc7b 100644 --- a/include/FlameIDE/Common/Traits/Functional.hpp +++ b/include/FlameIDE/Common/Traits/Functional.hpp @@ -342,6 +342,44 @@ struct DoSomeByIndex {} }; +/// +/// @brief The TypeMappingTrait class +/// @tparam T1 +/// @tparam T2 +/// +template +struct TypeMappingTrait +{ + using Type1 = T1; + using Type2 = T2; +}; + +/// +/// @brief The TypeMapper class +/// @tparam T +/// @tparam TypeMappingTrait +/// @tparam ENABLE_STATIC_ASSERT +/// +template +struct TypeMapper +{ + using Type = typename ChooseType< + ComparingTypes::VALUE + , typename TypeMappingTrait::Type2 + , typename ChooseType< + ComparingTypes::VALUE + , typename TypeMappingTrait::Type1 + , Empty + >::Type + >::Type; + + static_assert( + !ENABLE_STATIC_ASSERT + || ComparingTypes::VALUE == FalseType::VALUE + , "Type does not include in chosen TypeMatchingTrait" + ); +}; + } #endif // FLAMEIDE_COMMON_TRAITS_FUCTIONAL_HPP diff --git a/src/Common/Tests/FunctionalTraitTest.cpp b/src/Common/Tests/FunctionalTraitTest.cpp new file mode 100644 index 00000000..be993767 --- /dev/null +++ b/src/Common/Tests/FunctionalTraitTest.cpp @@ -0,0 +1,47 @@ +#include + +#include + +namespace flame_ide +{namespace common +{namespace tests +{ + +FunctionalTraitTest::FunctionalTraitTest() noexcept : ::AbstractTest{ "FunctionalTrait" } +{} + +FunctionalTraitTest::~FunctionalTraitTest() noexcept = default; + +int FunctionalTraitTest::vStart() +{ + CHECK_RESULT_SUCCESS(doTestCase( + "TypeMapper" + , [this] { return typeMapper(); } + )); + return ResultType::SUCCESS; +} + +int FunctionalTraitTest::typeMapper() +{ + using T1 = long long; + using T2 = unsigned long long; + using T3 = double; + using TestTypeMatchingTrait = TypeMappingTrait; + + using T2Result = TypeMapper::Type; + using T1Result = TypeMapper::Type; + // using T3Result = TypeMapper::Type; // static assert + using T3Result = TypeMapper::Type; + + const bool t1ComparationResult = ComparingTypes::VALUE; + const bool t2ComparationResult = ComparingTypes::VALUE; + const bool t3ComparationResult = ComparingTypes::VALUE; + + IN_CASE_CHECK(t1ComparationResult == true); + IN_CASE_CHECK(t2ComparationResult == true); + IN_CASE_CHECK(t3ComparationResult == true); + + return ResultType::SUCCESS; +} + +}}} // namespace flame_ide::common::tests diff --git a/src/Common/Tests/FunctionalTraitTest.hpp b/src/Common/Tests/FunctionalTraitTest.hpp new file mode 100644 index 00000000..02efde71 --- /dev/null +++ b/src/Common/Tests/FunctionalTraitTest.hpp @@ -0,0 +1,26 @@ +#ifndef FLAMEIDE_COMMON_TESTS_FUNCTIONALTRAITTEST_HPP +#define FLAMEIDE_COMMON_TESTS_FUNCTIONALTRAITTEST_HPP + +#include + +namespace flame_ide +{namespace common +{namespace tests +{ + +class FunctionalTraitTest: public ::AbstractTest +{ +public: + FunctionalTraitTest() noexcept; + ~FunctionalTraitTest() noexcept override; + +private: + int vStart() override; + +private: + int typeMapper(); +}; + +}}} // namespace flame_ide::common::tests + +#endif // FLAMEIDE_COMMON_TESTS_FUNCTIONALTRAITTEST_HPP diff --git a/src/Common/Tests/Sources.cmake b/src/Common/Tests/Sources.cmake index 3e585535..1c26f64a 100644 --- a/src/Common/Tests/Sources.cmake +++ b/src/Common/Tests/Sources.cmake @@ -1,6 +1,8 @@ set (SOURCE_LIST ${CMAKE_CURRENT_SOURCE_DIR}/ExpectedTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ExpectedTest.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/FunctionalTraitTest.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/FunctionalTraitTest.hpp ${CMAKE_CURRENT_SOURCE_DIR}/TestAggregator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TestAggregator.hpp ${CMAKE_CURRENT_SOURCE_DIR}/UtilsTest.cpp diff --git a/src/Common/Tests/TestAggregator.cpp b/src/Common/Tests/TestAggregator.cpp index eef69d18..6d36a9f9 100644 --- a/src/Common/Tests/TestAggregator.cpp +++ b/src/Common/Tests/TestAggregator.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include @@ -14,6 +15,7 @@ TestAggregator::TestAggregator() : ::TestAggregator("Common") pushBackTest(std::make_shared()); pushBackTest(std::make_shared()); pushBackTest(std::make_shared()); + pushBackTest(std::make_shared()); } }}} // namespace flame_ide::common::tests