Просмотр исходного кода

test: bare minimum tests for meta types from different contexts

Michele Caini 3 лет назад
Родитель
Сommit
d2048c037a
2 измененных файлов с 15 добавлено и 3 удалено
  1. 2 2
      src/entt/meta/meta.hpp
  2. 13 1
      test/entt/meta/meta_context.cpp

+ 2 - 2
src/entt/meta/meta.hpp

@@ -567,7 +567,7 @@ public:
 
     /*! @copydoc any::operator== */
     [[nodiscard]] bool operator==(const meta_any &other) const noexcept {
-        return (!node.info && !other.node.info) || (node.info && other.node.info && *node.info == *other.node.info && storage == other.storage);
+        return (ctx == other.ctx) && ((!node.info && !other.node.info) || (node.info && other.node.info && *node.info == *other.node.info && storage == other.storage));
     }
 
     /*! @copydoc any::operator!= */
@@ -1495,7 +1495,7 @@ public:
      * @return True if the objects refer to the same type, false otherwise.
      */
     [[nodiscard]] bool operator==(const meta_type &other) const noexcept {
-        return (!node.info && !other.node.info) || (node.info && other.node.info && *node.info == *other.node.info);
+        return (ctx == other.ctx) && ((!node.info && !other.node.info) || (node.info && other.node.info && *node.info == *other.node.info));
     }
 
 private:

+ 13 - 1
test/entt/meta/meta_context.cpp

@@ -63,7 +63,19 @@ TEST_F(MetaContext, Resolve) {
 TEST_F(MetaContext, MetaType) {
     using namespace entt::literals;
 
-    // TODO
+    const auto global = entt::resolve<clazz>();
+    const auto local = entt::resolve<clazz>(context);
+
+    ASSERT_TRUE(global);
+    ASSERT_TRUE(local);
+
+    ASSERT_NE(global, local);
+
+    ASSERT_EQ(global, entt::resolve("foo"_hs));
+    ASSERT_EQ(local, entt::resolve(context, "bar"_hs));
+
+    ASSERT_EQ(global.id(), "foo"_hs);
+    ASSERT_EQ(local.id(), "bar"_hs);
 }
 
 TEST_F(MetaContext, MetaBase) {