From 3f2b15f9f7e427b23c9e237e897c67abc77db6ec Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 17 Jan 2023 11:42:14 +0100 Subject: [PATCH] test: try to make lcov happy --- test/entt/core/any.cpp | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/test/entt/core/any.cpp b/test/entt/core/any.cpp index 2c091db5b..a896b9b51 100644 --- a/test/entt/core/any.cpp +++ b/test/entt/core/any.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -39,19 +40,6 @@ struct not_comparable { bool operator==(const not_comparable &) const = delete; }; -struct not_copyable { - not_copyable() - : payload{} {} - - not_copyable(const not_copyable &) = delete; - not_copyable(not_copyable &&) = default; - - not_copyable &operator=(const not_copyable &) = delete; - not_copyable &operator=(not_copyable &&) = default; - - double payload; -}; - struct not_movable { not_movable() = default; @@ -1184,13 +1172,12 @@ TEST_F(Any, AnyCast) { ASSERT_EQ(entt::any_cast(any), 42); ASSERT_EQ(entt::any_cast(cany), 42); - not_copyable instance{}; - instance.payload = 42.; + auto instance = std::make_unique(42.); entt::any ref{entt::forward_as_any(instance)}; - entt::any cref{entt::forward_as_any(std::as_const(instance).payload)}; + entt::any cref{entt::forward_as_any(std::as_const(*instance))}; - ASSERT_EQ(entt::any_cast(std::move(ref)).payload, 42.); ASSERT_EQ(entt::any_cast(std::move(cref)), 42.); + ASSERT_EQ(*entt::any_cast>(std::move(ref)), 42.); ASSERT_EQ(entt::any_cast(entt::any{42}), 42); } @@ -1201,12 +1188,11 @@ ENTT_DEBUG_TEST_F(AnyDeathTest, AnyCast) { ASSERT_DEATH([[maybe_unused]] auto &elem = entt::any_cast(any), ""); ASSERT_DEATH([[maybe_unused]] const auto &elem = entt::any_cast(cany), ""); - not_copyable instance{}; - instance.payload = 42.; + auto instance = std::make_unique(42.); entt::any ref{entt::forward_as_any(instance)}; - entt::any cref{entt::forward_as_any(std::as_const(instance).payload)}; + entt::any cref{entt::forward_as_any(std::as_const(*instance))}; - ASSERT_DEATH([[maybe_unused]] auto elem = entt::any_cast(std::as_const(ref).as_ref()), ""); + ASSERT_DEATH([[maybe_unused]] auto elem = entt::any_cast>(std::as_const(ref).as_ref()), ""); ASSERT_DEATH([[maybe_unused]] auto elem = entt::any_cast(entt::any{42}), ""); } @@ -1264,8 +1250,8 @@ TEST_F(Any, ForwardAsAny) { } TEST_F(Any, NotCopyableType) { - const not_copyable value{}; - entt::any any{std::in_place_type}; + const std::unique_ptr value{}; + entt::any any{std::in_place_type>}; entt::any other = entt::forward_as_any(value); ASSERT_TRUE(any); @@ -1297,7 +1283,7 @@ TEST_F(Any, NotCopyableType) { TEST_F(Any, NotCopyableValueType) { std::vector vec{}; - vec.emplace_back(std::in_place_type); + vec.emplace_back(std::in_place_type>); vec.shrink_to_fit(); ASSERT_EQ(vec.size(), 1u); @@ -1305,7 +1291,7 @@ TEST_F(Any, NotCopyableValueType) { ASSERT_TRUE(vec[0u]); // strong exception guarantee due to noexcept move ctor - vec.emplace_back(std::in_place_type); + vec.emplace_back(std::in_place_type>); ASSERT_EQ(vec.size(), 2u); ASSERT_TRUE(vec[0u]);