ソースを参照

any: more tests (code coverage)

Michele Caini 5 年 前
コミット
18e16b09f2
1 ファイル変更34 行追加6 行削除
  1. 34 6
      test/entt/core/any.cpp

+ 34 - 6
test/entt/core/any.cpp

@@ -1,5 +1,4 @@
 #include <algorithm>
 #include <algorithm>
-#include <memory>
 #include <unordered_map>
 #include <unordered_map>
 #include <vector>
 #include <vector>
 #include <gtest/gtest.h>
 #include <gtest/gtest.h>
@@ -25,6 +24,14 @@ struct not_comparable {
     bool operator==(const not_comparable &) const = delete;
     bool operator==(const not_comparable &) const = delete;
 };
 };
 
 
+template<auto Sz>
+struct not_copyable {
+    not_copyable(): payload{} {}
+    not_copyable(const not_copyable &) = delete;
+    not_copyable & operator=(const not_copyable &) = delete;
+    double payload[Sz];
+};
+
 TEST(Any, SBO) {
 TEST(Any, SBO) {
     entt::any any{'c'};
     entt::any any{'c'};
 
 
@@ -784,14 +791,35 @@ TEST(Any, AnyCast) {
 }
 }
 
 
 TEST(Any, NonCopyableType) {
 TEST(Any, NonCopyableType) {
-    entt::any any{std::in_place_type<std::unique_ptr<int>>, new int{42}};
+    auto test = [](entt::any any) {
+        entt::any copy{any};
+
+        ASSERT_TRUE(any);
+        ASSERT_FALSE(copy);
+
+        copy = any;
+
+        ASSERT_TRUE(any);
+        ASSERT_FALSE(copy);
+    };
+
+    test(entt::any{std::in_place_type<not_copyable<1>>});
+    test(entt::any{std::in_place_type<not_copyable<4>>});
+}
+
+TEST(Any, Array) {
+    entt::any any{std::in_place_type<int[1]>};
     entt::any copy{any};
     entt::any copy{any};
 
 
     ASSERT_TRUE(any);
     ASSERT_TRUE(any);
     ASSERT_FALSE(copy);
     ASSERT_FALSE(copy);
 
 
-    copy = any;
+    ASSERT_EQ(any.type(), entt::type_id<int[1]>());
+    ASSERT_NE(entt::any_cast<int[1]>(&any), nullptr);
+    ASSERT_EQ(entt::any_cast<int[2]>(&any), nullptr);
+    ASSERT_EQ(entt::any_cast<int *>(&any), nullptr);
 
 
-    ASSERT_TRUE(any);
-    ASSERT_FALSE(copy);
-}
+    entt::any_cast<int(&)[1]>(any)[0] = 42;
+
+    ASSERT_EQ(entt::any_cast<const int(&)[1]>(std::as_const(any))[0], 42);
+}