Forráskód Böngészése

test: minor changes, code coverage

Michele Caini 5 éve
szülő
commit
4e66fb4589
4 módosított fájl, 33 hozzáadás és 10 törlés
  1. 1 2
      TODO
  2. 6 4
      src/entt/meta/internal.hpp
  3. 5 4
      src/entt/meta/meta.hpp
  4. 21 0
      test/entt/meta/meta_any.cpp

+ 1 - 2
TODO

@@ -28,7 +28,6 @@ Next:
  - meta: update doc
  - meta: update doc
  - static constexpr -> inline constexpr
  - static constexpr -> inline constexpr
  - remove internal::find_if
  - remove internal::find_if
- - add meta_handle::operator-> that returns a meta_any * (easier to use directly)
  - use a dedicate class template to specialize meta views for a better support to customizations
  - use a dedicate class template to specialize meta views for a better support to customizations
- - remove operator* from meta_any, meta_handle
  - add const meta container support to meta any
  - add const meta container support to meta any
+ - meta_any deref fails if operator* returns a temporary

+ 6 - 4
src/entt/meta/internal.hpp

@@ -164,6 +164,8 @@ public:
     }
     }
 
 
     friend void swap(meta_storage &lhs, meta_storage &rhs) {
     friend void swap(meta_storage &lhs, meta_storage &rhs) {
+        using std::swap;
+
         if(lhs.steal_fn && rhs.steal_fn) {
         if(lhs.steal_fn && rhs.steal_fn) {
             meta_storage buffer{};
             meta_storage buffer{};
             lhs.steal_fn(buffer, lhs);
             lhs.steal_fn(buffer, lhs);
@@ -174,12 +176,12 @@ public:
         } else if(rhs.steal_fn) {
         } else if(rhs.steal_fn) {
             rhs.steal_fn(lhs, rhs);
             rhs.steal_fn(lhs, rhs);
         } else {
         } else {
-            std::swap(lhs.instance, rhs.instance);
+            swap(lhs.instance, rhs.instance);
         }
         }
 
 
-        std::swap(lhs.destroy_fn, rhs.destroy_fn);
-        std::swap(lhs.copy_fn, rhs.copy_fn);
-        std::swap(lhs.steal_fn, rhs.steal_fn);
+        swap(lhs.destroy_fn, rhs.destroy_fn);
+        swap(lhs.copy_fn, rhs.copy_fn);
+        swap(lhs.steal_fn, rhs.steal_fn);
     }
     }
 
 
 private:
 private:

+ 5 - 4
src/entt/meta/meta.hpp

@@ -504,10 +504,11 @@ public:
      * @param rhs A valid meta any object.
      * @param rhs A valid meta any object.
      */
      */
     friend void swap(meta_any &lhs, meta_any &rhs) {
     friend void swap(meta_any &lhs, meta_any &rhs) {
-        std::swap(lhs.node, rhs.node);
-        std::swap(lhs.storage, rhs.storage);
-        std::swap(lhs.deref, rhs.deref);
-        std::swap(lhs.cview, rhs.cview);
+        using std::swap;
+        swap(lhs.node, rhs.node);
+        swap(lhs.storage, rhs.storage);
+        swap(lhs.deref, rhs.deref);
+        swap(lhs.cview, rhs.cview);
     }
     }
 
 
 private:
 private:

+ 21 - 0
test/entt/meta/meta_any.cpp

@@ -636,6 +636,27 @@ TEST_F(MetaAny, DereferenceOperatorInvalidType) {
     ASSERT_FALSE(deref);
     ASSERT_FALSE(deref);
 }
 }
 
 
+TEST_F(MetaAny, DereferenceOperatorConstType) {
+    const int value = 0;
+    entt::meta_any any{&value};
+
+    ASSERT_TRUE(any.type().is_pointer());
+    ASSERT_TRUE(any.type().is_dereferenceable());
+    ASSERT_EQ(any.type(), entt::resolve<const int *>());
+
+    auto deref = *any;
+
+    ASSERT_TRUE(deref);
+    ASSERT_FALSE(deref.type().is_pointer());
+    ASSERT_FALSE(deref.type().is_dereferenceable());
+    ASSERT_EQ(deref.type(), entt::resolve<int>());
+
+    deref.cast<int>() = 42;
+
+    ASSERT_EQ(*any.cast<const int *>(), 0);
+    ASSERT_EQ(value, 0);
+}
+
 TEST_F(MetaAny, DereferenceOperatorRawPointer) {
 TEST_F(MetaAny, DereferenceOperatorRawPointer) {
     int value = 0;
     int value = 0;
     entt::meta_any any{&value};
     entt::meta_any any{&value};