test: meta corner cases and re-registration
This commit is contained in:
@@ -547,10 +547,21 @@ TEST_F(MetaData, FromBase) {
|
||||
}
|
||||
|
||||
TEST_F(MetaData, ReRegistration) {
|
||||
using namespace entt::literals;
|
||||
|
||||
MetaData::StaticSetUp();
|
||||
|
||||
auto *node = entt::internal::meta_info<base_t>::resolve();
|
||||
auto type = entt::resolve<base_t>();
|
||||
|
||||
ASSERT_NE(node->data, nullptr);
|
||||
ASSERT_EQ(node->data->next, nullptr);
|
||||
ASSERT_TRUE(type.data("value"_hs));
|
||||
|
||||
entt::meta<base_t>().data<&base_t::value>("field"_hs);
|
||||
|
||||
ASSERT_NE(node->data, nullptr);
|
||||
ASSERT_EQ(node->data->next, nullptr);
|
||||
ASSERT_FALSE(type.data("value"_hs));
|
||||
ASSERT_TRUE(type.data("field"_hs));
|
||||
}
|
||||
|
||||
@@ -9,10 +9,14 @@ struct clazz_t {
|
||||
++counter;
|
||||
}
|
||||
|
||||
static void destroy(clazz_t &) {
|
||||
static void destroy_decr(clazz_t &) {
|
||||
--counter;
|
||||
}
|
||||
|
||||
static void destroy_incr(clazz_t &) {
|
||||
++counter;
|
||||
}
|
||||
|
||||
inline static int counter = 0;
|
||||
};
|
||||
|
||||
@@ -22,7 +26,9 @@ struct MetaDtor: ::testing::Test {
|
||||
|
||||
entt::meta<clazz_t>()
|
||||
.type("clazz"_hs)
|
||||
.dtor<&clazz_t::destroy>();
|
||||
.dtor<&clazz_t::destroy_decr>();
|
||||
|
||||
clazz_t::counter = 0;
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
@@ -54,4 +60,9 @@ TEST_F(MetaDtor, ReRegistration) {
|
||||
auto *node = entt::internal::meta_info<clazz_t>::resolve();
|
||||
|
||||
ASSERT_NE(node->dtor, nullptr);
|
||||
|
||||
entt::meta<clazz_t>().dtor<&clazz_t::destroy_incr>();
|
||||
entt::resolve<clazz_t>().construct().reset();
|
||||
|
||||
ASSERT_EQ(clazz_t::counter, 2);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ struct func_t {
|
||||
};
|
||||
|
||||
struct MetaFunc: ::testing::Test {
|
||||
void StaticSetUp() {
|
||||
static void StaticSetUp() {
|
||||
using namespace entt::literals;
|
||||
|
||||
entt::meta<double>()
|
||||
@@ -442,22 +442,47 @@ TEST_F(MetaFunc, ExternalMemberFunction) {
|
||||
}
|
||||
|
||||
TEST_F(MetaFunc, ReRegistration) {
|
||||
int count = 0;
|
||||
using namespace entt::literals;
|
||||
|
||||
for([[maybe_unnused]] auto func: entt::resolve<func_t>().func()) {
|
||||
++count;
|
||||
}
|
||||
auto reset_and_check = []() {
|
||||
int count = 0;
|
||||
|
||||
MetaFunc::StaticSetUp();
|
||||
for([[maybe_unnused]] auto func: entt::resolve<func_t>().func()) {
|
||||
++count;
|
||||
}
|
||||
|
||||
for([[maybe_unnused]] auto func: entt::resolve<func_t>().func()) {
|
||||
--count;
|
||||
}
|
||||
MetaFunc::StaticSetUp();
|
||||
|
||||
ASSERT_EQ(count, 0);
|
||||
for([[maybe_unnused]] auto func: entt::resolve<func_t>().func()) {
|
||||
--count;
|
||||
}
|
||||
|
||||
auto *node = entt::internal::meta_info<base_t>::resolve();
|
||||
ASSERT_EQ(count, 0);
|
||||
};
|
||||
|
||||
ASSERT_NE(node->func, nullptr);
|
||||
ASSERT_EQ(node->func->next, nullptr);
|
||||
reset_and_check();
|
||||
|
||||
func_t instance{};
|
||||
auto type = entt::resolve<func_t>();
|
||||
|
||||
ASSERT_TRUE(type.func("f2"_hs));
|
||||
ASSERT_FALSE(type.invoke("f2"_hs, instance, 0));
|
||||
ASSERT_TRUE(type.invoke("f2"_hs, instance, 0, 0));
|
||||
|
||||
ASSERT_TRUE(type.func("f1"_hs));
|
||||
ASSERT_TRUE(type.invoke("f1"_hs, instance, 0));
|
||||
ASSERT_FALSE(type.invoke("f1"_hs, instance, 0, 0));
|
||||
|
||||
entt::meta<func_t>()
|
||||
.func<entt::overload<int(int, int)>(&func_t::f)>("f"_hs)
|
||||
.func<entt::overload<int(int) const>(&func_t::f)>("f"_hs);
|
||||
|
||||
ASSERT_FALSE(type.func("f1"_hs));
|
||||
ASSERT_FALSE(type.func("f2"_hs));
|
||||
ASSERT_TRUE(type.func("f"_hs));
|
||||
|
||||
ASSERT_TRUE(type.invoke("f"_hs, instance, 0));
|
||||
ASSERT_TRUE(type.invoke("f"_hs, instance, 0, 0));
|
||||
|
||||
reset_and_check();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ struct base_2_t {};
|
||||
struct derived_t: base_1_t, base_2_t {};
|
||||
|
||||
struct MetaProp: ::testing::Test {
|
||||
void StaticSetUp() {
|
||||
static void StaticSetUp() {
|
||||
using namespace entt::literals;
|
||||
|
||||
entt::meta<base_1_t>()
|
||||
|
||||
@@ -92,7 +92,7 @@ union union_t {
|
||||
};
|
||||
|
||||
struct MetaType: ::testing::Test {
|
||||
void StaticSetUp() {
|
||||
static void StaticSetUp() {
|
||||
using namespace entt::literals;
|
||||
|
||||
entt::meta<double>()
|
||||
@@ -672,6 +672,8 @@ TEST_F(MetaType, ClassTemplate) {
|
||||
}
|
||||
|
||||
TEST_F(MetaType, ReRegistration) {
|
||||
using namespace entt::literals;
|
||||
|
||||
int count = 0;
|
||||
|
||||
for([[maybe_unnused]] auto type: entt::resolve()) {
|
||||
@@ -685,4 +687,11 @@ TEST_F(MetaType, ReRegistration) {
|
||||
}
|
||||
|
||||
ASSERT_EQ(count, 0);
|
||||
ASSERT_TRUE(entt::resolve("double"_hs));
|
||||
|
||||
entt::meta<double>().type("real"_hs);
|
||||
|
||||
ASSERT_FALSE(entt::resolve("double"_hs));
|
||||
ASSERT_TRUE(entt::resolve("real"_hs));
|
||||
ASSERT_TRUE(entt::resolve("real"_hs).data("var"_hs));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user