Parcourir la source

test: try to make lcov happy

Michele Caini il y a 3 ans
Parent
commit
3f2b15f9f7
1 fichiers modifiés avec 11 ajouts et 25 suppressions
  1. 11 25
      test/entt/core/any.cpp

+ 11 - 25
test/entt/core/any.cpp

@@ -2,6 +2,7 @@
 #include <cstdint>
 #include <cstring>
 #include <iterator>
+#include <memory>
 #include <type_traits>
 #include <unordered_map>
 #include <utility>
@@ -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<int &>(any), 42);
     ASSERT_EQ(entt::any_cast<const int &>(cany), 42);
 
-    not_copyable instance{};
-    instance.payload = 42.;
+    auto instance = std::make_unique<double>(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<not_copyable>(std::move(ref)).payload, 42.);
     ASSERT_EQ(entt::any_cast<double>(std::move(cref)), 42.);
+    ASSERT_EQ(*entt::any_cast<std::unique_ptr<double>>(std::move(ref)), 42.);
     ASSERT_EQ(entt::any_cast<int>(entt::any{42}), 42);
 }
 
@@ -1201,12 +1188,11 @@ ENTT_DEBUG_TEST_F(AnyDeathTest, AnyCast) {
     ASSERT_DEATH([[maybe_unused]] auto &elem = entt::any_cast<double &>(any), "");
     ASSERT_DEATH([[maybe_unused]] const auto &elem = entt::any_cast<const double &>(cany), "");
 
-    not_copyable instance{};
-    instance.payload = 42.;
+    auto instance = std::make_unique<double>(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<not_copyable>(std::as_const(ref).as_ref()), "");
+    ASSERT_DEATH([[maybe_unused]] auto elem = entt::any_cast<std::unique_ptr<double>>(std::as_const(ref).as_ref()), "");
     ASSERT_DEATH([[maybe_unused]] auto elem = entt::any_cast<double>(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<not_copyable>};
+    const std::unique_ptr<int> value{};
+    entt::any any{std::in_place_type<std::unique_ptr<int>>};
     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<entt::any> vec{};
-    vec.emplace_back(std::in_place_type<not_copyable>);
+    vec.emplace_back(std::in_place_type<std::unique_ptr<int>>);
     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<not_copyable>);
+    vec.emplace_back(std::in_place_type<std::unique_ptr<int>>);
 
     ASSERT_EQ(vec.size(), 2u);
     ASSERT_TRUE(vec[0u]);