Browse Source

*: code coverage, cleanup

Michele Caini 4 years ago
parent
commit
28b9f07b99
2 changed files with 48 additions and 4 deletions
  1. 0 4
      src/entt/meta/node.hpp
  2. 48 0
      test/entt/meta/meta_any.cpp

+ 0 - 4
src/entt/meta/node.hpp

@@ -198,10 +198,6 @@ template<typename... Args>
 
 
 template<auto Member, typename Type>
 template<auto Member, typename Type>
 [[nodiscard]] static std::decay_t<decltype(std::declval<internal::meta_type_node>().*Member)> find_by(const Type &info_or_id, const internal::meta_type_node *node) {
 [[nodiscard]] static std::decay_t<decltype(std::declval<internal::meta_type_node>().*Member)> find_by(const Type &info_or_id, const internal::meta_type_node *node) {
-    if(!node) {
-        return nullptr;
-    }
-
     for(auto *curr = node->*Member; curr; curr = curr->next) {
     for(auto *curr = node->*Member; curr; curr = curr->next) {
         if constexpr(std::is_same_v<Type, type_info>) {
         if constexpr(std::is_same_v<Type, type_info>) {
             if(*curr->type->info == info_or_id) {
             if(*curr->type->info == info_or_id) {

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

@@ -1134,6 +1134,54 @@ TEST_F(MetaAny, AllowCast) {
     ASSERT_EQ(as_cref.type(), entt::resolve<double>());
     ASSERT_EQ(as_cref.type(), entt::resolve<double>());
 }
 }
 
 
+TEST_F(MetaAny, OpaqueAllowCast) {
+    entt::meta_any clazz{clazz_t{}};
+    entt::meta_any fat{fat_t{}};
+    entt::meta_any arithmetic{42};
+    auto as_cref = entt::forward_as_meta(arithmetic.cast<const int &>());
+
+    ASSERT_TRUE(clazz);
+    ASSERT_TRUE(fat);
+    ASSERT_TRUE(arithmetic);
+    ASSERT_TRUE(as_cref);
+
+    ASSERT_TRUE(clazz.allow_cast(entt::resolve<clazz_t>()));
+    ASSERT_EQ(clazz.type(), entt::resolve<clazz_t>());
+
+    ASSERT_TRUE(clazz.allow_cast(entt::resolve<int>()));
+    ASSERT_EQ(clazz.type(), entt::resolve<int>());
+    ASSERT_TRUE(clazz.allow_cast(entt::resolve<int>()));
+
+    ASSERT_TRUE(fat.allow_cast(entt::resolve<fat_t>()));
+    ASSERT_TRUE(fat.allow_cast(entt::resolve<empty_t>()));
+    ASSERT_EQ(fat.type(), entt::resolve<fat_t>());
+    ASSERT_FALSE(fat.allow_cast(entt::resolve<int>()));
+
+    ASSERT_TRUE(std::as_const(fat).allow_cast(entt::resolve<fat_t>()));
+    ASSERT_TRUE(std::as_const(fat).allow_cast(entt::resolve<empty_t>()));
+    ASSERT_EQ(fat.type(), entt::resolve<fat_t>());
+    ASSERT_FALSE(fat.allow_cast(entt::resolve<int>()));
+
+    ASSERT_TRUE(arithmetic.allow_cast(entt::resolve<int>()));
+    ASSERT_EQ(arithmetic.type(), entt::resolve<int>());
+    ASSERT_FALSE(arithmetic.allow_cast(entt::resolve<fat_t>()));
+
+    ASSERT_TRUE(arithmetic.allow_cast(entt::resolve<double>()));
+    ASSERT_EQ(arithmetic.type(), entt::resolve<double>());
+    ASSERT_EQ(arithmetic.cast<double &>(), 42.);
+
+    ASSERT_TRUE(arithmetic.allow_cast(entt::resolve<float>()));
+    ASSERT_EQ(arithmetic.type(), entt::resolve<float>());
+    ASSERT_EQ(arithmetic.cast<float &>(), 42.f);
+
+    ASSERT_TRUE(as_cref.allow_cast(entt::resolve<int>()));
+    ASSERT_EQ(as_cref.type(), entt::resolve<int>());
+    ASSERT_FALSE(as_cref.allow_cast(entt::resolve<fat_t>()));
+
+    ASSERT_TRUE(as_cref.allow_cast(entt::resolve<double>()));
+    ASSERT_EQ(as_cref.type(), entt::resolve<double>());
+}
+
 TEST_F(MetaAny, Convert) {
 TEST_F(MetaAny, Convert) {
     entt::meta_any any{clazz_t{}};
     entt::meta_any any{clazz_t{}};
     any.cast<clazz_t &>().value = 42;
     any.cast<clazz_t &>().value = 42;