|
|
@@ -4,291 +4,10 @@
|
|
|
#include <gtest/gtest.h>
|
|
|
#include <entt/core/hashed_string.hpp>
|
|
|
#include <entt/core/type_info.hpp>
|
|
|
-#include <entt/core/utility.hpp>
|
|
|
#include <entt/meta/factory.hpp>
|
|
|
#include <entt/meta/meta.hpp>
|
|
|
#include <entt/meta/resolve.hpp>
|
|
|
-
|
|
|
-template<typename Type>
|
|
|
-void set(Type &prop, Type value) {
|
|
|
- prop = value;
|
|
|
-}
|
|
|
-
|
|
|
-template<typename Type>
|
|
|
-Type get(Type &prop) {
|
|
|
- return prop;
|
|
|
-}
|
|
|
-
|
|
|
-enum class props {
|
|
|
- prop_int,
|
|
|
- prop_value,
|
|
|
- prop_bool,
|
|
|
- key_only,
|
|
|
- prop_list
|
|
|
-};
|
|
|
-
|
|
|
-struct empty_type {
|
|
|
- virtual ~empty_type() = default;
|
|
|
-
|
|
|
- static void destroy(empty_type &) {
|
|
|
- ++counter;
|
|
|
- }
|
|
|
-
|
|
|
- inline static int counter = 0;
|
|
|
-};
|
|
|
-
|
|
|
-struct fat_type: empty_type {
|
|
|
- fat_type() = default;
|
|
|
-
|
|
|
- fat_type(int *value)
|
|
|
- : foo{value}, bar{value}
|
|
|
- {}
|
|
|
-
|
|
|
- int *foo{nullptr};
|
|
|
- int *bar{nullptr};
|
|
|
-
|
|
|
- bool operator==(const fat_type &other) const {
|
|
|
- return foo == other.foo && bar == other.bar;
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-union union_type {
|
|
|
- int i;
|
|
|
- double d;
|
|
|
-};
|
|
|
-
|
|
|
-struct base_type {
|
|
|
- virtual ~base_type() = default;
|
|
|
-};
|
|
|
-
|
|
|
-struct derived_type: base_type {
|
|
|
- derived_type() = default;
|
|
|
-
|
|
|
- derived_type(const base_type &, int value, char character)
|
|
|
- : i{value}, c{character}
|
|
|
- {}
|
|
|
-
|
|
|
- int f() const { return i; }
|
|
|
- static char g(const derived_type &type) { return type.c; }
|
|
|
-
|
|
|
- const int i{};
|
|
|
- const char c{};
|
|
|
-};
|
|
|
-
|
|
|
-derived_type derived_factory(const base_type &, int value) {
|
|
|
- return {derived_type{}, value, 'c'};
|
|
|
-}
|
|
|
-
|
|
|
-struct data_type {
|
|
|
- int i{0};
|
|
|
- const int j{1};
|
|
|
- inline static int h{2};
|
|
|
- inline static const int k{3};
|
|
|
- empty_type empty{};
|
|
|
- int v{0};
|
|
|
-};
|
|
|
-
|
|
|
-struct array_type {
|
|
|
- static inline int global[3];
|
|
|
- int local[3];
|
|
|
-};
|
|
|
-
|
|
|
-struct func_type {
|
|
|
- int f(const base_type &, int a, int b) { return f(a, b); }
|
|
|
- int f(int a, int b) { value = a; return b*b; }
|
|
|
- int f(int v) const { return v*v; }
|
|
|
- void g(int v) { value = v*v; }
|
|
|
-
|
|
|
- static int h(int &v) { return (v *= value); }
|
|
|
- static void k(int v) { value = v; }
|
|
|
-
|
|
|
- int v(int v) const { return (value = v); }
|
|
|
- int & a() const { return value; }
|
|
|
-
|
|
|
- inline static int value = 0;
|
|
|
-};
|
|
|
-
|
|
|
-struct setter_getter_type {
|
|
|
- int value{};
|
|
|
-
|
|
|
- int setter(int val) { return value = val; }
|
|
|
- int getter() { return value; }
|
|
|
-
|
|
|
- int setter_with_ref(const int &val) { return value = val; }
|
|
|
- const int & getter_with_ref() { return value; }
|
|
|
-
|
|
|
- static int static_setter(setter_getter_type &type, int value) { return type.value = value; }
|
|
|
- static int static_getter(const setter_getter_type &type) { return type.value; }
|
|
|
-};
|
|
|
-
|
|
|
-struct not_comparable_type {
|
|
|
- bool operator==(const not_comparable_type &) const = delete;
|
|
|
-};
|
|
|
-
|
|
|
-struct unmanageable_type {
|
|
|
- unmanageable_type() = default;
|
|
|
- unmanageable_type(const unmanageable_type &) = delete;
|
|
|
- unmanageable_type(unmanageable_type &&) = delete;
|
|
|
- unmanageable_type & operator=(const unmanageable_type &) = delete;
|
|
|
- unmanageable_type & operator=(unmanageable_type &&) = delete;
|
|
|
-};
|
|
|
-
|
|
|
-bool operator!=(const not_comparable_type &, const not_comparable_type &) = delete;
|
|
|
-
|
|
|
-struct an_abstract_type {
|
|
|
- virtual ~an_abstract_type() = default;
|
|
|
- void f(int v) { i = v; }
|
|
|
- virtual void g(int) = 0;
|
|
|
- int i{};
|
|
|
-};
|
|
|
-
|
|
|
-struct another_abstract_type {
|
|
|
- virtual ~another_abstract_type() = default;
|
|
|
- virtual void h(char) = 0;
|
|
|
- char j{};
|
|
|
-};
|
|
|
-
|
|
|
-struct concrete_type: an_abstract_type, another_abstract_type {
|
|
|
- void f(int v) { i = v*v; } // hide, it's ok :-)
|
|
|
- void g(int v) override { i = -v; }
|
|
|
- void h(char c) override { j = c; }
|
|
|
-};
|
|
|
-
|
|
|
-struct Meta: ::testing::Test {
|
|
|
- static void SetUpTestCase() {
|
|
|
- entt::meta<double>().conv<int>();
|
|
|
-
|
|
|
- entt::meta<char>()
|
|
|
- .type("char"_hs)
|
|
|
- .prop(props::prop_int, 42)
|
|
|
- .data<&set<char>, &get<char>>("value"_hs);
|
|
|
-
|
|
|
- entt::meta<props>()
|
|
|
- .data<props::prop_bool>("prop_bool"_hs)
|
|
|
- .prop(props::prop_int, 0)
|
|
|
- .prop(props::prop_value, 3)
|
|
|
- .data<props::prop_int>("prop_int"_hs)
|
|
|
- .prop(std::make_tuple(std::make_pair(props::prop_bool, true), std::make_pair(props::prop_int, 0), std::make_pair(props::prop_value, 3)))
|
|
|
- .prop(props::key_only)
|
|
|
- .data<props::key_only>("key_only"_hs)
|
|
|
- .prop([]() { return props::key_only; })
|
|
|
- .data<&set<props>, &get<props>>("value"_hs)
|
|
|
- .data<props::prop_list>("prop_list"_hs)
|
|
|
- .props(std::make_pair(props::prop_bool, false), std::make_pair(props::prop_int, 0), std::make_pair(props::prop_value, 3), props::key_only);
|
|
|
-
|
|
|
- entt::meta<unsigned int>().data<0u>("min"_hs).data<100u>("max"_hs);
|
|
|
-
|
|
|
- entt::meta<base_type>()
|
|
|
- .type("base"_hs);
|
|
|
-
|
|
|
- entt::meta<derived_type>()
|
|
|
- .type("derived"_hs)
|
|
|
- .prop(props::prop_int, 99)
|
|
|
- .base<base_type>()
|
|
|
- .ctor<const base_type &, int, char>()
|
|
|
- .prop(props::prop_bool, false)
|
|
|
- .ctor<&derived_factory>()
|
|
|
- .prop(props::prop_int, 42)
|
|
|
- .conv<&derived_type::f>()
|
|
|
- .conv<&derived_type::g>();
|
|
|
-
|
|
|
- entt::meta<empty_type>()
|
|
|
- .ctor<>()
|
|
|
- .type("empty"_hs)
|
|
|
- .dtor<&empty_type::destroy>();
|
|
|
-
|
|
|
- entt::meta<fat_type>()
|
|
|
- .type("fat"_hs)
|
|
|
- .base<empty_type>()
|
|
|
- .dtor<&fat_type::destroy>();
|
|
|
-
|
|
|
- entt::meta<data_type>()
|
|
|
- .type("data"_hs)
|
|
|
- .data<&data_type::i, entt::as_ref_t>("i"_hs)
|
|
|
- .prop(props::prop_int, 0)
|
|
|
- .data<&data_type::j>("j"_hs)
|
|
|
- .prop(props::prop_int, 1)
|
|
|
- .data<&data_type::h>("h"_hs)
|
|
|
- .prop(props::prop_int, 2)
|
|
|
- .data<&data_type::k>("k"_hs)
|
|
|
- .prop(props::prop_int, 3)
|
|
|
- .data<&data_type::empty>("empty"_hs)
|
|
|
- .data<&data_type::v, entt::as_void_t>("v"_hs);
|
|
|
-
|
|
|
- entt::meta<array_type>()
|
|
|
- .type("array"_hs)
|
|
|
- .data<&array_type::global>("global"_hs)
|
|
|
- .data<&array_type::local>("local"_hs);
|
|
|
-
|
|
|
- entt::meta<func_type>()
|
|
|
- .type("func"_hs)
|
|
|
- .func<entt::overload<int(const base_type &, int, int)>(&func_type::f)>("f3"_hs)
|
|
|
- .func<entt::overload<int(int, int)>(&func_type::f)>("f2"_hs)
|
|
|
- .prop(props::prop_bool, false)
|
|
|
- .func<entt::overload<int(int) const>(&func_type::f)>("f1"_hs)
|
|
|
- .prop(props::prop_bool, false)
|
|
|
- .func<&func_type::g>("g"_hs)
|
|
|
- .prop(props::prop_bool, false)
|
|
|
- .func<&func_type::h>("h"_hs)
|
|
|
- .prop(props::prop_bool, false)
|
|
|
- .func<&func_type::k>("k"_hs)
|
|
|
- .prop(props::prop_bool, false)
|
|
|
- .func<&func_type::v, entt::as_void_t>("v"_hs)
|
|
|
- .func<&func_type::a, entt::as_ref_t>("a"_hs);
|
|
|
-
|
|
|
- entt::meta<setter_getter_type>()
|
|
|
- .type("setter_getter"_hs)
|
|
|
- .data<&setter_getter_type::static_setter, &setter_getter_type::static_getter>("x"_hs)
|
|
|
- .data<&setter_getter_type::setter, &setter_getter_type::getter>("y"_hs)
|
|
|
- .data<&setter_getter_type::static_setter, &setter_getter_type::getter>("z"_hs)
|
|
|
- .data<&setter_getter_type::setter_with_ref, &setter_getter_type::getter_with_ref>("w"_hs)
|
|
|
- .data<nullptr, &setter_getter_type::getter>("z_ro"_hs)
|
|
|
- .data<nullptr, &setter_getter_type::value>("value"_hs);
|
|
|
-
|
|
|
- entt::meta<an_abstract_type>()
|
|
|
- .type("an_abstract_type"_hs)
|
|
|
- .prop(props::prop_bool, false)
|
|
|
- .data<&an_abstract_type::i>("i"_hs)
|
|
|
- .func<&an_abstract_type::f>("f"_hs)
|
|
|
- .func<&an_abstract_type::g>("g"_hs);
|
|
|
-
|
|
|
- entt::meta<another_abstract_type>()
|
|
|
- .type("another_abstract_type"_hs)
|
|
|
- .prop(props::prop_int, 42)
|
|
|
- .data<&another_abstract_type::j>("j"_hs)
|
|
|
- .func<&another_abstract_type::h>("h"_hs);
|
|
|
-
|
|
|
- entt::meta<concrete_type>()
|
|
|
- .type("concrete"_hs)
|
|
|
- .base<an_abstract_type>()
|
|
|
- .base<another_abstract_type>()
|
|
|
- .func<&concrete_type::f>("f"_hs);
|
|
|
- }
|
|
|
-
|
|
|
- static void SetUpAfterUnregistration() {
|
|
|
- entt::meta<double>().conv<float>();
|
|
|
-
|
|
|
- entt::meta<props>()
|
|
|
- .data<props::prop_bool>("prop_bool"_hs)
|
|
|
- .prop(props::prop_int, 0)
|
|
|
- .prop(props::prop_value, 3);
|
|
|
-
|
|
|
- entt::meta<derived_type>()
|
|
|
- .type("my_type"_hs)
|
|
|
- .prop(props::prop_bool, false)
|
|
|
- .ctor<>();
|
|
|
-
|
|
|
- entt::meta<another_abstract_type>()
|
|
|
- .type("your_type"_hs)
|
|
|
- .data<&another_abstract_type::j>("a_data_member"_hs)
|
|
|
- .func<&another_abstract_type::h>("a_member_function"_hs);
|
|
|
- }
|
|
|
-
|
|
|
- void SetUp() override {
|
|
|
- empty_type::counter = 0;
|
|
|
- func_type::value = 0;
|
|
|
- }
|
|
|
-};
|
|
|
+#include "fixture.h"
|
|
|
|
|
|
TEST_F(Meta, Resolve) {
|
|
|
ASSERT_EQ(entt::resolve<derived_type>(), entt::resolve_id("derived"_hs));
|
|
|
@@ -1768,7 +1487,7 @@ TEST_F(Meta, MetaTypeDetach) {
|
|
|
ASSERT_EQ(entt::resolve<char>().prop(props::prop_int).value().cast<int>(), 42);
|
|
|
ASSERT_TRUE(entt::resolve<char>().data("value"_hs));
|
|
|
|
|
|
- entt::meta_factory<char>().type("char"_hs);
|
|
|
+ entt::meta<char>().type("char"_hs);
|
|
|
|
|
|
ASSERT_TRUE(entt::resolve_id("char"_hs));
|
|
|
}
|