|
|
@@ -3,76 +3,86 @@
|
|
|
#include <utility>
|
|
|
#include <gtest/gtest.h>
|
|
|
#include <entt/meta/adl_pointer.hpp>
|
|
|
+#include <entt/meta/factory.hpp>
|
|
|
#include <entt/meta/meta.hpp>
|
|
|
#include <entt/meta/pointer.hpp>
|
|
|
#include <entt/meta/resolve.hpp>
|
|
|
+#include <entt/meta/template.hpp>
|
|
|
#include <entt/meta/type_traits.hpp>
|
|
|
#include "../../common/config.h"
|
|
|
|
|
|
-template<typename Type>
|
|
|
-struct wrapped_shared_ptr {
|
|
|
- wrapped_shared_ptr(Type init)
|
|
|
- : ptr{new Type{init}} {}
|
|
|
+struct MetaPointer: ::testing::Test {
|
|
|
+ template<typename Type>
|
|
|
+ struct wrapped_shared_ptr {
|
|
|
+ wrapped_shared_ptr(Type init)
|
|
|
+ : ptr{new Type{init}} {}
|
|
|
|
|
|
- [[nodiscard]] Type &deref() const {
|
|
|
- return *ptr;
|
|
|
- }
|
|
|
+ [[nodiscard]] Type &deref() const {
|
|
|
+ return *ptr;
|
|
|
+ }
|
|
|
|
|
|
-private:
|
|
|
- std::shared_ptr<Type> ptr;
|
|
|
-};
|
|
|
+ private:
|
|
|
+ std::shared_ptr<Type> ptr;
|
|
|
+ };
|
|
|
|
|
|
-struct self_ptr {
|
|
|
- using element_type = self_ptr;
|
|
|
+ struct self_ptr {
|
|
|
+ using element_type = self_ptr;
|
|
|
|
|
|
- self_ptr(int val)
|
|
|
- : value{val} {}
|
|
|
+ self_ptr(int val)
|
|
|
+ : value{val} {}
|
|
|
|
|
|
- const self_ptr &operator*() const {
|
|
|
- return *this;
|
|
|
- }
|
|
|
+ const self_ptr &operator*() const {
|
|
|
+ return *this;
|
|
|
+ }
|
|
|
|
|
|
- int value;
|
|
|
-};
|
|
|
+ int value;
|
|
|
+ };
|
|
|
|
|
|
-struct proxy_ptr {
|
|
|
- using element_type = proxy_ptr;
|
|
|
+ struct proxy_ptr {
|
|
|
+ using element_type = proxy_ptr;
|
|
|
|
|
|
- proxy_ptr(int &val)
|
|
|
- : value{&val} {}
|
|
|
+ proxy_ptr(int &val)
|
|
|
+ : value{&val} {}
|
|
|
|
|
|
- proxy_ptr operator*() const {
|
|
|
- return *this;
|
|
|
- }
|
|
|
+ proxy_ptr operator*() const {
|
|
|
+ return *this;
|
|
|
+ }
|
|
|
|
|
|
- int *value;
|
|
|
-};
|
|
|
+ int *value;
|
|
|
+ };
|
|
|
|
|
|
-template<typename Type>
|
|
|
-struct adl_wrapped_shared_ptr: wrapped_shared_ptr<Type> {
|
|
|
- using is_meta_pointer_like = void;
|
|
|
-};
|
|
|
+ template<typename Type>
|
|
|
+ struct adl_wrapped_shared_ptr: wrapped_shared_ptr<Type> {
|
|
|
+ using is_meta_pointer_like = void;
|
|
|
+ };
|
|
|
|
|
|
-template<typename Type>
|
|
|
-struct spec_wrapped_shared_ptr: wrapped_shared_ptr<Type> {
|
|
|
- using is_meta_pointer_like = void;
|
|
|
+ template<typename Type>
|
|
|
+ struct spec_wrapped_shared_ptr: wrapped_shared_ptr<Type> {
|
|
|
+ using is_meta_pointer_like = void;
|
|
|
+ };
|
|
|
+
|
|
|
+ void TearDown() override {
|
|
|
+ entt::meta_reset();
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
+using MetaPointerDeathTest = MetaPointer;
|
|
|
+
|
|
|
template<>
|
|
|
-struct entt::is_meta_pointer_like<self_ptr>: std::true_type {};
|
|
|
+struct entt::is_meta_pointer_like<MetaPointer::self_ptr>: std::true_type {};
|
|
|
|
|
|
template<>
|
|
|
-struct entt::is_meta_pointer_like<proxy_ptr>: std::true_type {};
|
|
|
+struct entt::is_meta_pointer_like<MetaPointer::proxy_ptr>: std::true_type {};
|
|
|
|
|
|
template<typename Type>
|
|
|
-struct entt::adl_meta_pointer_like<spec_wrapped_shared_ptr<Type>> {
|
|
|
- static decltype(auto) dereference(const spec_wrapped_shared_ptr<Type> &ptr) {
|
|
|
+struct entt::adl_meta_pointer_like<MetaPointer::spec_wrapped_shared_ptr<Type>> {
|
|
|
+ static decltype(auto) dereference(const MetaPointer::spec_wrapped_shared_ptr<Type> &ptr) {
|
|
|
return ptr.deref();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
template<typename Type>
|
|
|
-Type &dereference_meta_pointer_like(const adl_wrapped_shared_ptr<Type> &ptr) {
|
|
|
+Type &dereference_meta_pointer_like(const MetaPointer::adl_wrapped_shared_ptr<Type> &ptr) {
|
|
|
return ptr.deref();
|
|
|
}
|
|
|
|
|
|
@@ -80,7 +90,7 @@ int test_function() {
|
|
|
return 3;
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceOperatorInvalidType) {
|
|
|
+TEST_F(MetaPointer, DereferenceOperatorInvalidType) {
|
|
|
const int value = 0;
|
|
|
const entt::meta_any any{value};
|
|
|
|
|
|
@@ -93,7 +103,7 @@ TEST(MetaPointerLike, DereferenceOperatorInvalidType) {
|
|
|
ASSERT_FALSE(deref);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceOperatorConstType) {
|
|
|
+TEST_F(MetaPointer, DereferenceOperatorConstType) {
|
|
|
const int value = 3;
|
|
|
const entt::meta_any any{&value};
|
|
|
|
|
|
@@ -113,7 +123,7 @@ TEST(MetaPointerLike, DereferenceOperatorConstType) {
|
|
|
ASSERT_EQ(deref.cast<const int &>(), 3);
|
|
|
}
|
|
|
|
|
|
-ENTT_DEBUG_TEST(MetaPointerLikeDeathTest, DereferenceOperatorConstType) {
|
|
|
+ENTT_DEBUG_TEST_F(MetaPointerDeathTest, DereferenceOperatorConstType) {
|
|
|
const int value = 3;
|
|
|
const entt::meta_any any{&value};
|
|
|
auto deref = *any;
|
|
|
@@ -122,7 +132,7 @@ ENTT_DEBUG_TEST(MetaPointerLikeDeathTest, DereferenceOperatorConstType) {
|
|
|
ASSERT_DEATH(deref.cast<int &>() = 0, "");
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceOperatorConstAnyNonConstType) {
|
|
|
+TEST_F(MetaPointer, DereferenceOperatorConstAnyNonConstType) {
|
|
|
int value = 3;
|
|
|
const entt::meta_any any{&value};
|
|
|
auto deref = *any;
|
|
|
@@ -138,7 +148,7 @@ TEST(MetaPointerLike, DereferenceOperatorConstAnyNonConstType) {
|
|
|
ASSERT_EQ(deref.cast<const int &>(), 3);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceOperatorConstAnyConstType) {
|
|
|
+TEST_F(MetaPointer, DereferenceOperatorConstAnyConstType) {
|
|
|
const int value = 3;
|
|
|
const entt::meta_any any{&value};
|
|
|
auto deref = *any;
|
|
|
@@ -153,7 +163,7 @@ TEST(MetaPointerLike, DereferenceOperatorConstAnyConstType) {
|
|
|
ASSERT_EQ(deref.cast<const int &>(), 3);
|
|
|
}
|
|
|
|
|
|
-ENTT_DEBUG_TEST(MetaPointerLikeDeathTest, DereferenceOperatorConstAnyConstType) {
|
|
|
+ENTT_DEBUG_TEST_F(MetaPointerDeathTest, DereferenceOperatorConstAnyConstType) {
|
|
|
const int value = 3;
|
|
|
const entt::meta_any any{&value};
|
|
|
auto deref = *any;
|
|
|
@@ -162,7 +172,7 @@ ENTT_DEBUG_TEST(MetaPointerLikeDeathTest, DereferenceOperatorConstAnyConstType)
|
|
|
ASSERT_DEATH(deref.cast<int &>() = 0, "");
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceOperatorRawPointer) {
|
|
|
+TEST_F(MetaPointer, DereferenceOperatorRawPointer) {
|
|
|
int value = 0;
|
|
|
entt::meta_any any{&value};
|
|
|
|
|
|
@@ -183,7 +193,7 @@ TEST(MetaPointerLike, DereferenceOperatorRawPointer) {
|
|
|
ASSERT_EQ(value, 3);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceOperatorSmartPointer) {
|
|
|
+TEST_F(MetaPointer, DereferenceOperatorSmartPointer) {
|
|
|
auto value = std::make_shared<int>(0);
|
|
|
entt::meta_any any{value};
|
|
|
|
|
|
@@ -204,7 +214,7 @@ TEST(MetaPointerLike, DereferenceOperatorSmartPointer) {
|
|
|
ASSERT_EQ(*value, 3);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, PointerToConstMoveOnlyType) {
|
|
|
+TEST_F(MetaPointer, PointerToConstMoveOnlyType) {
|
|
|
const std::unique_ptr<int> instance;
|
|
|
const entt::meta_any any{&instance};
|
|
|
auto deref = *any;
|
|
|
@@ -217,7 +227,7 @@ TEST(MetaPointerLike, PointerToConstMoveOnlyType) {
|
|
|
ASSERT_EQ(&deref.cast<const std::unique_ptr<int> &>(), &instance);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, AsRef) {
|
|
|
+TEST_F(MetaPointer, AsRef) {
|
|
|
int value = 0;
|
|
|
int *ptr = &value;
|
|
|
entt::meta_any any{entt::forward_as_meta(ptr)};
|
|
|
@@ -239,7 +249,7 @@ TEST(MetaPointerLike, AsRef) {
|
|
|
ASSERT_EQ(value, 3);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, AsConstRef) {
|
|
|
+TEST_F(MetaPointer, AsConstRef) {
|
|
|
int value = 3;
|
|
|
int *const ptr = &value;
|
|
|
entt::meta_any any{entt::forward_as_meta(ptr)};
|
|
|
@@ -261,7 +271,7 @@ TEST(MetaPointerLike, AsConstRef) {
|
|
|
ASSERT_EQ(value, 3);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceOverloadAdl) {
|
|
|
+TEST_F(MetaPointer, DereferenceOverloadAdl) {
|
|
|
const entt::meta_any any{adl_wrapped_shared_ptr<int>{3}};
|
|
|
|
|
|
ASSERT_FALSE(any.type().is_pointer());
|
|
|
@@ -278,7 +288,7 @@ TEST(MetaPointerLike, DereferenceOverloadAdl) {
|
|
|
ASSERT_EQ(deref.cast<const int &>(), 3);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceOverloadSpec) {
|
|
|
+TEST_F(MetaPointer, DereferenceOverloadSpec) {
|
|
|
const entt::meta_any any{spec_wrapped_shared_ptr<int>{3}};
|
|
|
|
|
|
ASSERT_FALSE(any.type().is_pointer());
|
|
|
@@ -295,7 +305,7 @@ TEST(MetaPointerLike, DereferenceOverloadSpec) {
|
|
|
ASSERT_EQ(deref.cast<const int &>(), 3);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferencePointerToConstOverloadAdl) {
|
|
|
+TEST_F(MetaPointer, DereferencePointerToConstOverloadAdl) {
|
|
|
const entt::meta_any any{adl_wrapped_shared_ptr<const int>{3}};
|
|
|
|
|
|
ASSERT_FALSE(any.type().is_pointer());
|
|
|
@@ -310,7 +320,7 @@ TEST(MetaPointerLike, DereferencePointerToConstOverloadAdl) {
|
|
|
ASSERT_EQ(deref.cast<const int &>(), 3);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferencePointerToConstOverloadSpec) {
|
|
|
+TEST_F(MetaPointer, DereferencePointerToConstOverloadSpec) {
|
|
|
const entt::meta_any any{spec_wrapped_shared_ptr<const int>{3}};
|
|
|
|
|
|
ASSERT_FALSE(any.type().is_pointer());
|
|
|
@@ -325,7 +335,7 @@ TEST(MetaPointerLike, DereferencePointerToConstOverloadSpec) {
|
|
|
ASSERT_EQ(deref.cast<const int &>(), 3);
|
|
|
}
|
|
|
|
|
|
-ENTT_DEBUG_TEST(MetaPointerLikeDeathTest, DereferencePointerToConstOverloadAdl) {
|
|
|
+ENTT_DEBUG_TEST_F(MetaPointerDeathTest, DereferencePointerToConstOverloadAdl) {
|
|
|
const entt::meta_any any{adl_wrapped_shared_ptr<const int>{3}};
|
|
|
|
|
|
auto deref = *any;
|
|
|
@@ -334,7 +344,7 @@ ENTT_DEBUG_TEST(MetaPointerLikeDeathTest, DereferencePointerToConstOverloadAdl)
|
|
|
ASSERT_DEATH(deref.cast<int &>() = 3, "");
|
|
|
}
|
|
|
|
|
|
-ENTT_DEBUG_TEST(MetaPointerLikeDeathTest, DereferencePointerToConstOverloadSpec) {
|
|
|
+ENTT_DEBUG_TEST_F(MetaPointerDeathTest, DereferencePointerToConstOverloadSpec) {
|
|
|
const entt::meta_any any{spec_wrapped_shared_ptr<const int>{3}};
|
|
|
|
|
|
auto deref = *any;
|
|
|
@@ -343,7 +353,7 @@ ENTT_DEBUG_TEST(MetaPointerLikeDeathTest, DereferencePointerToConstOverloadSpec)
|
|
|
ASSERT_DEATH(deref.cast<int &>() = 3, "");
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferencePointerToVoid) {
|
|
|
+TEST_F(MetaPointer, DereferencePointerToVoid) {
|
|
|
const entt::meta_any any{static_cast<void *>(nullptr)};
|
|
|
|
|
|
ASSERT_TRUE(any.type().is_pointer());
|
|
|
@@ -354,7 +364,7 @@ TEST(MetaPointerLike, DereferencePointerToVoid) {
|
|
|
ASSERT_FALSE(deref);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferencePointerToConstVoid) {
|
|
|
+TEST_F(MetaPointer, DereferencePointerToConstVoid) {
|
|
|
const entt::meta_any any{static_cast<const void *>(nullptr)};
|
|
|
|
|
|
ASSERT_TRUE(any.type().is_pointer());
|
|
|
@@ -365,7 +375,7 @@ TEST(MetaPointerLike, DereferencePointerToConstVoid) {
|
|
|
ASSERT_FALSE(deref);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceSharedPointerToVoid) {
|
|
|
+TEST_F(MetaPointer, DereferenceSharedPointerToVoid) {
|
|
|
const entt::meta_any any{std::shared_ptr<void>{}};
|
|
|
|
|
|
ASSERT_TRUE(any.type().is_class());
|
|
|
@@ -377,7 +387,7 @@ TEST(MetaPointerLike, DereferenceSharedPointerToVoid) {
|
|
|
ASSERT_FALSE(deref);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceUniquePointerToVoid) {
|
|
|
+TEST_F(MetaPointer, DereferenceUniquePointerToVoid) {
|
|
|
const entt::meta_any any{std::unique_ptr<void, void (*)(void *)>{nullptr, nullptr}};
|
|
|
|
|
|
ASSERT_TRUE(any.type().is_class());
|
|
|
@@ -389,7 +399,7 @@ TEST(MetaPointerLike, DereferenceUniquePointerToVoid) {
|
|
|
ASSERT_FALSE(deref);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferencePointerToFunction) {
|
|
|
+TEST_F(MetaPointer, DereferencePointerToFunction) {
|
|
|
entt::meta_any any{&test_function};
|
|
|
|
|
|
ASSERT_TRUE(any.type().is_pointer());
|
|
|
@@ -398,7 +408,7 @@ TEST(MetaPointerLike, DereferencePointerToFunction) {
|
|
|
ASSERT_EQ((***std::as_const(any)).cast<int (*)()>()(), 3);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceSelfPointer) {
|
|
|
+TEST_F(MetaPointer, DereferenceSelfPointer) {
|
|
|
self_ptr obj{3};
|
|
|
const entt::meta_any any{entt::forward_as_meta(obj)};
|
|
|
entt::meta_any deref = *any;
|
|
|
@@ -409,7 +419,7 @@ TEST(MetaPointerLike, DereferenceSelfPointer) {
|
|
|
ASSERT_FALSE(deref.try_cast<self_ptr>());
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceProxyPointer) {
|
|
|
+TEST_F(MetaPointer, DereferenceProxyPointer) {
|
|
|
int value = 3;
|
|
|
const proxy_ptr obj{value};
|
|
|
const entt::meta_any any{obj};
|
|
|
@@ -425,7 +435,7 @@ TEST(MetaPointerLike, DereferenceProxyPointer) {
|
|
|
ASSERT_EQ(value, 3);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceArray) {
|
|
|
+TEST_F(MetaPointer, DereferenceArray) {
|
|
|
// NOLINTBEGIN(*-avoid-c-arrays)
|
|
|
const entt::meta_any array{std::in_place_type<int[3]>};
|
|
|
const entt::meta_any array_of_array{std::in_place_type<int[3][3]>};
|
|
|
@@ -440,21 +450,21 @@ TEST(MetaPointerLike, DereferenceArray) {
|
|
|
ASSERT_FALSE(*array_of_array);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferencePlainNullPointer) {
|
|
|
+TEST_F(MetaPointer, DereferencePlainNullPointer) {
|
|
|
const entt::meta_any any{static_cast<int *>(nullptr)};
|
|
|
|
|
|
ASSERT_TRUE(any);
|
|
|
ASSERT_FALSE(*any);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceSharedNullPointer) {
|
|
|
+TEST_F(MetaPointer, DereferenceSharedNullPointer) {
|
|
|
const entt::meta_any any{std::shared_ptr<int>{}};
|
|
|
|
|
|
ASSERT_TRUE(any);
|
|
|
ASSERT_FALSE(*any);
|
|
|
}
|
|
|
|
|
|
-TEST(MetaPointerLike, DereferenceUniqueNullPointer) {
|
|
|
+TEST_F(MetaPointer, DereferenceUniqueNullPointer) {
|
|
|
const entt::meta_any any{std::unique_ptr<int>{}};
|
|
|
|
|
|
ASSERT_TRUE(any);
|