test: added meta_prop

This commit is contained in:
Michele Caini
2020-06-10 15:42:47 +02:00
parent 29832bb2c0
commit cedebf8145
5 changed files with 40 additions and 21 deletions

View File

@@ -794,7 +794,7 @@ public:
* @return A meta factory for the given type.
*/
template<typename Type>
[[nodiscard]] meta_factory<Type> meta() ENTT_NOEXCEPT {
[[nodiscard]] auto meta() ENTT_NOEXCEPT {
auto * const node = internal::meta_info<Type>::resolve();
// extended meta factory to allow assigning properties to opaque meta types
return meta_factory<Type, Type>{&node->prop};

View File

@@ -180,6 +180,7 @@ SETUP_BASIC_TEST(locator entt/locator/locator.cpp)
list(APPEND TEST_META_SOURCES entt/meta/meta.cpp entt/meta/fixture.cpp)
SETUP_BASIC_TEST(meta_any entt/meta/meta_any.cpp)
SETUP_BASIC_TEST(meta_basic entt/meta/meta_basic.cpp)
SETUP_BASIC_TEST(meta_prop entt/meta/meta_prop.cpp)
SETUP_BASIC_TEST(meta "${TEST_META_SOURCES}")
# Test process

View File

@@ -9,14 +9,6 @@
#include <entt/meta/resolve.hpp>
#include "fixture.h"
TEST_F(Meta, MetaProp) {
auto prop = entt::resolve<char>().prop(props::prop_int);
ASSERT_TRUE(prop);
ASSERT_EQ(prop.key(), props::prop_int);
ASSERT_EQ(prop.value(), 42);
}
TEST_F(Meta, MetaBase) {
auto base = entt::resolve<derived_type>().base("base"_hs);
derived_type derived{};
@@ -949,18 +941,6 @@ TEST_F(Meta, MetaFuncFromBase) {
ASSERT_EQ(instance.i, -3);
}
TEST_F(Meta, MetaPropFromBase) {
auto type = entt::resolve<concrete_type>();
auto prop_bool = type.prop(props::prop_bool);
auto prop_int = type.prop(props::prop_int);
ASSERT_TRUE(prop_bool);
ASSERT_TRUE(prop_int);
ASSERT_FALSE(prop_bool.value().cast<bool>());
ASSERT_EQ(prop_int.value().cast<int>(), 42);
}
TEST_F(Meta, AbstractClass) {
auto type = entt::resolve<an_abstract_type>();
concrete_type instance;

View File

@@ -1,6 +1,7 @@
#include <gtest/gtest.h>
#include <entt/core/hashed_string.hpp>
#include <entt/meta/factory.hpp>
#include <entt/meta/meta.hpp>
#include <entt/meta/resolve.hpp>
struct Meta: ::testing::Test {

View File

@@ -0,0 +1,37 @@
#include <gtest/gtest.h>
#include <entt/core/hashed_string.hpp>
#include <entt/meta/factory.hpp>
#include <entt/meta/meta.hpp>
#include <entt/meta/resolve.hpp>
struct base_1 {};
struct base_2 {};
struct derived: base_1, base_2 {};
struct Meta: ::testing::Test {
static void SetUpTestCase() {
entt::meta<base_1>().prop("int"_hs, 42);
entt::meta<base_2>().prop("bool"_hs, false);
entt::meta<derived>().base<base_1>().base<base_2>();
}
};
TEST_F(Meta, MetaProp) {
auto prop = entt::resolve<base_1>().prop("int"_hs);
ASSERT_TRUE(prop);
ASSERT_EQ(prop.key(), "int"_hs);
ASSERT_EQ(prop.value(), 42);
}
TEST_F(Meta, MetaPropFromBase) {
auto type = entt::resolve<derived>();
auto prop_bool = type.prop("bool"_hs);
auto prop_int = type.prop("int"_hs);
ASSERT_TRUE(prop_bool);
ASSERT_TRUE(prop_int);
ASSERT_FALSE(prop_bool.value().cast<bool>());
ASSERT_EQ(prop_int.value().cast<int>(), 42);
}