97 lines
2.5 KiB
C++
97 lines
2.5 KiB
C++
#include <gtest/gtest.h>
|
|
#include <entt/core/hashed_string.hpp>
|
|
#include <entt/meta/meta.hpp>
|
|
#include <entt/meta/pointer.hpp>
|
|
#include <entt/meta/resolve.hpp>
|
|
|
|
struct not_copyable_t {
|
|
not_copyable_t() = default;
|
|
not_copyable_t(const not_copyable_t &) = delete;
|
|
not_copyable_t(not_copyable_t &&) = default;
|
|
not_copyable_t & operator=(const not_copyable_t &) = delete;
|
|
not_copyable_t & operator=(not_copyable_t &&) = default;
|
|
};
|
|
|
|
TEST(MetaPointerLike, DereferenceOperatorInvalidType) {
|
|
int value = 0;
|
|
entt::meta_any any{value};
|
|
|
|
ASSERT_FALSE(any.type().is_pointer());
|
|
ASSERT_FALSE(any.type().is_pointer_like());
|
|
ASSERT_EQ(any.type(), entt::resolve<int>());
|
|
|
|
auto deref = *any;
|
|
|
|
ASSERT_FALSE(deref);
|
|
}
|
|
|
|
TEST(MetaPointerLike, DereferenceOperatorConstType) {
|
|
const int value = 0;
|
|
entt::meta_any any{&value};
|
|
|
|
ASSERT_TRUE(any.type().is_pointer());
|
|
ASSERT_TRUE(any.type().is_pointer_like());
|
|
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_pointer_like());
|
|
ASSERT_EQ(deref.type(), entt::resolve<int>());
|
|
|
|
deref.cast<int>() = 42;
|
|
|
|
ASSERT_EQ(*any.cast<const int *>(), 0);
|
|
ASSERT_EQ(value, 0);
|
|
}
|
|
|
|
TEST(MetaPointerLike, DereferenceOperatorRawPointer) {
|
|
int value = 0;
|
|
entt::meta_any any{&value};
|
|
|
|
ASSERT_TRUE(any.type().is_pointer());
|
|
ASSERT_TRUE(any.type().is_pointer_like());
|
|
ASSERT_EQ(any.type(), entt::resolve<int *>());
|
|
|
|
auto deref = *any;
|
|
|
|
ASSERT_TRUE(deref);
|
|
ASSERT_FALSE(deref.type().is_pointer());
|
|
ASSERT_FALSE(deref.type().is_pointer_like());
|
|
ASSERT_EQ(deref.type(), entt::resolve<int>());
|
|
|
|
deref.cast<int>() = 42;
|
|
|
|
ASSERT_EQ(*any.cast<int *>(), 42);
|
|
ASSERT_EQ(value, 42);
|
|
}
|
|
|
|
TEST(MetaPointerLike, DereferenceOperatorSmartPointer) {
|
|
auto value = std::make_shared<int>(0);
|
|
entt::meta_any any{value};
|
|
|
|
ASSERT_FALSE(any.type().is_pointer());
|
|
ASSERT_TRUE(any.type().is_pointer_like());
|
|
ASSERT_EQ(any.type(), entt::resolve<std::shared_ptr<int>>());
|
|
|
|
auto deref = *any;
|
|
|
|
ASSERT_TRUE(deref);
|
|
ASSERT_FALSE(deref.type().is_pointer());
|
|
ASSERT_FALSE(deref.type().is_pointer_like());
|
|
ASSERT_EQ(deref.type(), entt::resolve<int>());
|
|
|
|
deref.cast<int>() = 42;
|
|
|
|
ASSERT_EQ(*any.cast<std::shared_ptr<int>>(), 42);
|
|
ASSERT_EQ(*value, 42);
|
|
}
|
|
|
|
TEST(MetaPointerLike, PointerToMoveOnlyType) {
|
|
const not_copyable_t instance;
|
|
entt::meta_any any{&instance};
|
|
|
|
ASSERT_TRUE(any);
|
|
ASSERT_FALSE(*any);
|
|
} |