| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075 |
- #include <utility>
- #include <functional>
- #include <type_traits>
- #include <gtest/gtest.h>
- #include <entt/core/hashed_string.hpp>
- #include <entt/core/utility.hpp>
- #include <entt/meta/factory.hpp>
- #include <entt/meta/meta.hpp>
- template<typename Type>
- void set(Type &prop, Type value) {
- prop = value;
- }
- template<typename Type>
- Type get(Type &prop) {
- return prop;
- }
- enum class properties {
- prop_int,
- prop_bool
- };
- 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;
- };
- 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<entt::property<properties::prop_int, 42>>()
- .data<&set<char>, &get<char>>("value"_hs);
- entt::meta<properties>()
- .data<properties::prop_bool>("prop_bool"_hs)
- .prop<entt::property<properties::prop_int, 0>>()
- .data<properties::prop_int>("prop_int"_hs)
- .prop<entt::property<properties::prop_bool, true>>()
- .prop<entt::property<properties::prop_int, 0>>()
- .data<&set<properties>, &get<properties>>("value"_hs);
- 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<entt::property<properties::prop_int, 99>>()
- .base<base_type>()
- .ctor<const base_type &, int, char>()
- .prop<entt::property<properties::prop_bool, false>>()
- .ctor<&derived_factory>()
- .prop<entt::property<properties::prop_int, 42>>()
- .conv<&derived_type::f>()
- .conv<&derived_type::g>();
- entt::meta<empty_type>()
- .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_alias_t>("i"_hs)
- .prop<entt::property<properties::prop_int, 0>>()
- .data<&data_type::j>("j"_hs)
- .prop<entt::property<properties::prop_int, 1>>()
- .data<&data_type::h>("h"_hs)
- .prop<entt::property<properties::prop_int, 2>>()
- .data<&data_type::k>("k"_hs)
- .prop<entt::property<properties::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<entt::property<properties::prop_bool, false>>()
- .func<entt::overload<int(int) const>(&func_type::f)>("f1"_hs)
- .prop<entt::property<properties::prop_bool, false>>()
- .func<&func_type::g>("g"_hs)
- .prop<entt::property<properties::prop_bool, false>>()
- .func<&func_type::h>("h"_hs)
- .prop<entt::property<properties::prop_bool, false>>()
- .func<&func_type::k>("k"_hs)
- .prop<entt::property<properties::prop_bool, false>>()
- .func<&func_type::v, entt::as_void_t>("v"_hs)
- .func<&func_type::a, entt::as_alias_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);
- entt::meta<an_abstract_type>()
- .type("an_abstract_type"_hs)
- .prop<entt::property<properties::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<entt::property<properties::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<derived_type>()
- .type("my_type"_hs)
- .prop<entt::property<properties::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;
- }
- };
- TEST_F(Meta, Resolve) {
- ASSERT_EQ(entt::resolve<derived_type>(), entt::resolve("derived"_hs));
- bool found = false;
- entt::resolve([&found](auto type) {
- found = found || type == entt::resolve<derived_type>();
- });
- ASSERT_TRUE(found);
- }
- TEST_F(Meta, MetaAnyFromMetaHandle) {
- int value = 42;
- entt::meta_handle handle{value};
- entt::meta_any any{handle};
- any.cast<int>() = 3;
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<int>());
- ASSERT_EQ(any.try_cast<std::size_t>(), nullptr);
- ASSERT_EQ(any.try_cast<int>(), handle.data());
- ASSERT_EQ(std::as_const(any).try_cast<int>(), handle.data());
- ASSERT_EQ(any.data(), handle.data());
- ASSERT_EQ(std::as_const(any).data(), handle.data());
- ASSERT_EQ(value, 3);
- }
- TEST_F(Meta, MetaAnySBO) {
- entt::meta_any any{'c'};
- ASSERT_TRUE(any);
- ASSERT_FALSE(any.try_cast<std::size_t>());
- ASSERT_TRUE(any.try_cast<char>());
- ASSERT_EQ(any.cast<char>(), 'c');
- ASSERT_EQ(std::as_const(any).cast<char>(), 'c');
- ASSERT_NE(any.data(), nullptr);
- ASSERT_NE(std::as_const(any).data(), nullptr);
- ASSERT_EQ(any, entt::meta_any{'c'});
- ASSERT_NE(entt::meta_any{'h'}, any);
- }
- TEST_F(Meta, MetaAnyNoSBO) {
- int value = 42;
- fat_type instance{&value};
- entt::meta_any any{instance};
- ASSERT_TRUE(any);
- ASSERT_FALSE(any.try_cast<std::size_t>());
- ASSERT_TRUE(any.try_cast<fat_type>());
- ASSERT_EQ(any.cast<fat_type>(), instance);
- ASSERT_EQ(std::as_const(any).cast<fat_type>(), instance);
- ASSERT_NE(any.data(), nullptr);
- ASSERT_NE(std::as_const(any).data(), nullptr);
- ASSERT_EQ(any, entt::meta_any{instance});
- ASSERT_NE(fat_type{}, any);
- }
- TEST_F(Meta, MetaAnyEmpty) {
- entt::meta_any any{};
- ASSERT_FALSE(any);
- ASSERT_FALSE(any.type());
- ASSERT_FALSE(any.try_cast<std::size_t>());
- ASSERT_FALSE(any.try_cast<empty_type>());
- ASSERT_EQ(any.data(), nullptr);
- ASSERT_EQ(std::as_const(any).data(), nullptr);
- ASSERT_EQ(any, entt::meta_any{});
- ASSERT_NE(entt::meta_any{'c'}, any);
- }
- TEST_F(Meta, MetaAnySBOInPlaceTypeConstruction) {
- entt::meta_any any{std::in_place_type<int>, 42};
- ASSERT_TRUE(any);
- ASSERT_FALSE(any.try_cast<std::size_t>());
- ASSERT_TRUE(any.try_cast<int>());
- ASSERT_EQ(any.cast<int>(), 42);
- ASSERT_EQ(std::as_const(any).cast<int>(), 42);
- ASSERT_NE(any.data(), nullptr);
- ASSERT_NE(std::as_const(any).data(), nullptr);
- ASSERT_EQ(any, (entt::meta_any{std::in_place_type<int>, 42}));
- ASSERT_EQ(any, entt::meta_any{42});
- ASSERT_NE(entt::meta_any{3}, any);
- }
- TEST_F(Meta, MetaAnySBOAsAliasConstruction) {
- int value = 3;
- int other = 42;
- entt::meta_any any{std::ref(value)};
- ASSERT_TRUE(any);
- ASSERT_FALSE(any.try_cast<std::size_t>());
- ASSERT_TRUE(any.try_cast<int>());
- ASSERT_EQ(any.cast<int>(), 3);
- ASSERT_EQ(std::as_const(any).cast<int>(), 3);
- ASSERT_NE(any.data(), nullptr);
- ASSERT_NE(std::as_const(any).data(), nullptr);
- ASSERT_EQ(any, (entt::meta_any{std::ref(value)}));
- ASSERT_NE(any, (entt::meta_any{std::ref(other)}));
- ASSERT_NE(any, entt::meta_any{42});
- ASSERT_EQ(entt::meta_any{3}, any);
- }
- TEST_F(Meta, MetaAnySBOCopyConstruction) {
- entt::meta_any any{42};
- entt::meta_any other{any};
- ASSERT_TRUE(any);
- ASSERT_TRUE(other);
- ASSERT_FALSE(other.try_cast<std::size_t>());
- ASSERT_TRUE(other.try_cast<int>());
- ASSERT_EQ(other.cast<int>(), 42);
- ASSERT_EQ(std::as_const(other).cast<int>(), 42);
- ASSERT_EQ(other, entt::meta_any{42});
- ASSERT_NE(other, entt::meta_any{0});
- }
- TEST_F(Meta, MetaAnySBOCopyAssignment) {
- entt::meta_any any{42};
- entt::meta_any other{3};
- other = any;
- ASSERT_TRUE(any);
- ASSERT_TRUE(other);
- ASSERT_FALSE(other.try_cast<std::size_t>());
- ASSERT_TRUE(other.try_cast<int>());
- ASSERT_EQ(other.cast<int>(), 42);
- ASSERT_EQ(std::as_const(other).cast<int>(), 42);
- ASSERT_EQ(other, entt::meta_any{42});
- ASSERT_NE(other, entt::meta_any{0});
- }
- TEST_F(Meta, MetaAnySBOMoveConstruction) {
- entt::meta_any any{42};
- entt::meta_any other{std::move(any)};
- ASSERT_FALSE(any);
- ASSERT_TRUE(other);
- ASSERT_FALSE(other.try_cast<std::size_t>());
- ASSERT_TRUE(other.try_cast<int>());
- ASSERT_EQ(other.cast<int>(), 42);
- ASSERT_EQ(std::as_const(other).cast<int>(), 42);
- ASSERT_EQ(other, entt::meta_any{42});
- ASSERT_NE(other, entt::meta_any{0});
- }
- TEST_F(Meta, MetaAnySBOMoveAssignment) {
- entt::meta_any any{42};
- entt::meta_any other{3};
- other = std::move(any);
- ASSERT_FALSE(any);
- ASSERT_TRUE(other);
- ASSERT_FALSE(other.try_cast<std::size_t>());
- ASSERT_TRUE(other.try_cast<int>());
- ASSERT_EQ(other.cast<int>(), 42);
- ASSERT_EQ(std::as_const(other).cast<int>(), 42);
- ASSERT_EQ(other, entt::meta_any{42});
- ASSERT_NE(other, entt::meta_any{0});
- }
- TEST_F(Meta, MetaAnySBODirectAssignment) {
- entt::meta_any any{};
- any = 42;
- ASSERT_FALSE(any.try_cast<std::size_t>());
- ASSERT_TRUE(any.try_cast<int>());
- ASSERT_EQ(any.cast<int>(), 42);
- ASSERT_EQ(std::as_const(any).cast<int>(), 42);
- ASSERT_EQ(any, entt::meta_any{42});
- ASSERT_NE(entt::meta_any{0}, any);
- }
- TEST_F(Meta, MetaAnyNoSBOInPlaceTypeConstruction) {
- int value = 42;
- fat_type instance{&value};
- entt::meta_any any{std::in_place_type<fat_type>, instance};
- ASSERT_TRUE(any);
- ASSERT_FALSE(any.try_cast<std::size_t>());
- ASSERT_TRUE(any.try_cast<fat_type>());
- ASSERT_EQ(any.cast<fat_type>(), instance);
- ASSERT_EQ(std::as_const(any).cast<fat_type>(), instance);
- ASSERT_NE(any.data(), nullptr);
- ASSERT_NE(std::as_const(any).data(), nullptr);
- ASSERT_EQ(any, (entt::meta_any{std::in_place_type<fat_type>, instance}));
- ASSERT_EQ(any, entt::meta_any{instance});
- ASSERT_NE(entt::meta_any{fat_type{}}, any);
- }
- TEST_F(Meta, MetaAnyNoSBOAsAliasConstruction) {
- int value = 3;
- fat_type instance{&value};
- entt::meta_any any{std::ref(instance)};
- ASSERT_TRUE(any);
- ASSERT_FALSE(any.try_cast<std::size_t>());
- ASSERT_TRUE(any.try_cast<fat_type>());
- ASSERT_EQ(any.cast<fat_type>(), instance);
- ASSERT_EQ(std::as_const(any).cast<fat_type>(), instance);
- ASSERT_NE(any.data(), nullptr);
- ASSERT_NE(std::as_const(any).data(), nullptr);
- ASSERT_EQ(any, (entt::meta_any{std::ref(instance)}));
- ASSERT_EQ(any, entt::meta_any{instance});
- ASSERT_NE(entt::meta_any{fat_type{}}, any);
- }
- TEST_F(Meta, MetaAnyNoSBOCopyConstruction) {
- int value = 42;
- fat_type instance{&value};
- entt::meta_any any{instance};
- entt::meta_any other{any};
- ASSERT_TRUE(any);
- ASSERT_TRUE(other);
- ASSERT_FALSE(other.try_cast<std::size_t>());
- ASSERT_TRUE(other.try_cast<fat_type>());
- ASSERT_EQ(other.cast<fat_type>(), instance);
- ASSERT_EQ(std::as_const(other).cast<fat_type>(), instance);
- ASSERT_EQ(other, entt::meta_any{instance});
- ASSERT_NE(other, fat_type{});
- }
- TEST_F(Meta, MetaAnyNoSBOCopyAssignment) {
- int value = 42;
- fat_type instance{&value};
- entt::meta_any any{instance};
- entt::meta_any other{3};
- other = any;
- ASSERT_TRUE(any);
- ASSERT_TRUE(other);
- ASSERT_FALSE(other.try_cast<std::size_t>());
- ASSERT_TRUE(other.try_cast<fat_type>());
- ASSERT_EQ(other.cast<fat_type>(), instance);
- ASSERT_EQ(std::as_const(other).cast<fat_type>(), instance);
- ASSERT_EQ(other, entt::meta_any{instance});
- ASSERT_NE(other, fat_type{});
- }
- TEST_F(Meta, MetaAnyNoSBOMoveConstruction) {
- int value = 42;
- fat_type instance{&value};
- entt::meta_any any{instance};
- entt::meta_any other{std::move(any)};
- ASSERT_FALSE(any);
- ASSERT_TRUE(other);
- ASSERT_FALSE(other.try_cast<std::size_t>());
- ASSERT_TRUE(other.try_cast<fat_type>());
- ASSERT_EQ(other.cast<fat_type>(), instance);
- ASSERT_EQ(std::as_const(other).cast<fat_type>(), instance);
- ASSERT_EQ(other, entt::meta_any{instance});
- ASSERT_NE(other, fat_type{});
- }
- TEST_F(Meta, MetaAnyNoSBOMoveAssignment) {
- int value = 42;
- fat_type instance{&value};
- entt::meta_any any{instance};
- entt::meta_any other{3};
- other = std::move(any);
- ASSERT_FALSE(any);
- ASSERT_TRUE(other);
- ASSERT_FALSE(other.try_cast<std::size_t>());
- ASSERT_TRUE(other.try_cast<fat_type>());
- ASSERT_EQ(other.cast<fat_type>(), instance);
- ASSERT_EQ(std::as_const(other).cast<fat_type>(), instance);
- ASSERT_EQ(other, entt::meta_any{instance});
- ASSERT_NE(other, fat_type{});
- }
- TEST_F(Meta, MetaAnyNoSBODirectAssignment) {
- int value = 42;
- entt::meta_any any{};
- any = fat_type{&value};
- ASSERT_FALSE(any.try_cast<std::size_t>());
- ASSERT_TRUE(any.try_cast<fat_type>());
- ASSERT_EQ(any.cast<fat_type>(), fat_type{&value});
- ASSERT_EQ(std::as_const(any).cast<fat_type>(), fat_type{&value});
- ASSERT_EQ(any, entt::meta_any{fat_type{&value}});
- ASSERT_NE(fat_type{}, any);
- }
- TEST_F(Meta, MetaAnyVoidInPlaceTypeConstruction) {
- entt::meta_any any{std::in_place_type<void>};
- ASSERT_TRUE(any);
- ASSERT_FALSE(any.try_cast<char>());
- ASSERT_EQ(any.data(), nullptr);
- ASSERT_EQ(std::as_const(any).data(), nullptr);
- ASSERT_EQ(any.type(), entt::resolve<void>());
- ASSERT_EQ(any, entt::meta_any{std::in_place_type<void>});
- ASSERT_NE(entt::meta_any{3}, any);
- }
- TEST_F(Meta, MetaAnyVoidCopyConstruction) {
- entt::meta_any any{std::in_place_type<void>};
- entt::meta_any other{any};
- ASSERT_TRUE(any);
- ASSERT_TRUE(other);
- ASSERT_EQ(any.type(), entt::resolve<void>());
- ASSERT_EQ(other, entt::meta_any{std::in_place_type<void>});
- }
- TEST_F(Meta, MetaAnyVoidCopyAssignment) {
- entt::meta_any any{std::in_place_type<void>};
- entt::meta_any other{std::in_place_type<void>};
- other = any;
- ASSERT_TRUE(any);
- ASSERT_TRUE(other);
- ASSERT_EQ(any.type(), entt::resolve<void>());
- ASSERT_EQ(other, entt::meta_any{std::in_place_type<void>});
- }
- TEST_F(Meta, MetaAnyVoidMoveConstruction) {
- entt::meta_any any{std::in_place_type<void>};
- entt::meta_any other{std::move(any)};
- ASSERT_FALSE(any);
- ASSERT_TRUE(other);
- ASSERT_EQ(other.type(), entt::resolve<void>());
- ASSERT_EQ(other, entt::meta_any{std::in_place_type<void>});
- }
- TEST_F(Meta, MetaAnyVoidMoveAssignment) {
- entt::meta_any any{std::in_place_type<void>};
- entt::meta_any other{std::in_place_type<void>};
- other = std::move(any);
- ASSERT_FALSE(any);
- ASSERT_TRUE(other);
- ASSERT_EQ(other.type(), entt::resolve<void>());
- ASSERT_EQ(other, entt::meta_any{std::in_place_type<void>});
- }
- TEST_F(Meta, MetaAnySBOMoveInvalidate) {
- entt::meta_any any{42};
- entt::meta_any other{std::move(any)};
- entt::meta_any valid = std::move(other);
- ASSERT_FALSE(any);
- ASSERT_FALSE(other);
- ASSERT_TRUE(valid);
- }
- TEST_F(Meta, MetaAnyNoSBOMoveInvalidate) {
- int value = 42;
- fat_type instance{&value};
- entt::meta_any any{instance};
- entt::meta_any other{std::move(any)};
- entt::meta_any valid = std::move(other);
- ASSERT_FALSE(any);
- ASSERT_FALSE(other);
- ASSERT_TRUE(valid);
- }
- TEST_F(Meta, MetaAnyVoidMoveInvalidate) {
- entt::meta_any any{std::in_place_type<void>};
- entt::meta_any other{std::move(any)};
- entt::meta_any valid = std::move(other);
- ASSERT_FALSE(any);
- ASSERT_FALSE(other);
- ASSERT_TRUE(valid);
- }
- TEST_F(Meta, MetaAnySBODestruction) {
- ASSERT_EQ(empty_type::counter, 0);
- { entt::meta_any any{empty_type{}}; }
- ASSERT_EQ(empty_type::counter, 1);
- }
- TEST_F(Meta, MetaAnyNoSBODestruction) {
- ASSERT_EQ(fat_type::counter, 0);
- { entt::meta_any any{fat_type{}}; }
- ASSERT_EQ(fat_type::counter, 1);
- }
- TEST_F(Meta, MetaAnyVoidDestruction) {
- // just let asan tell us if everything is ok here
- [[maybe_unused]] entt::meta_any any{std::in_place_type<void>};
- }
- TEST_F(Meta, MetaAnyEmplace) {
- entt::meta_any any{};
- any.emplace<int>(42);
- ASSERT_TRUE(any);
- ASSERT_FALSE(any.try_cast<std::size_t>());
- ASSERT_TRUE(any.try_cast<int>());
- ASSERT_EQ(any.cast<int>(), 42);
- ASSERT_EQ(std::as_const(any).cast<int>(), 42);
- ASSERT_NE(any.data(), nullptr);
- ASSERT_NE(std::as_const(any).data(), nullptr);
- ASSERT_EQ(any, (entt::meta_any{std::in_place_type<int>, 42}));
- ASSERT_EQ(any, entt::meta_any{42});
- ASSERT_NE(entt::meta_any{3}, any);
- }
- TEST_F(Meta, MetaAnyEmplaceVoid) {
- entt::meta_any any{};
- any.emplace<void>();
- ASSERT_TRUE(any);
- ASSERT_EQ(any.data(), nullptr);
- ASSERT_EQ(std::as_const(any).data(), nullptr);
- ASSERT_EQ(any.type(), entt::resolve<void>());
- ASSERT_EQ(any, (entt::meta_any{std::in_place_type<void>}));
- }
- TEST_F(Meta, MetaAnySBOSwap) {
- entt::meta_any lhs{'c'};
- entt::meta_any rhs{42};
- std::swap(lhs, rhs);
- ASSERT_TRUE(lhs.try_cast<int>());
- ASSERT_EQ(lhs.cast<int>(), 42);
- ASSERT_TRUE(rhs.try_cast<char>());
- ASSERT_EQ(rhs.cast<char>(), 'c');
- }
- TEST_F(Meta, MetaAnyNoSBOSwap) {
- int i, j;
- entt::meta_any lhs{fat_type{&i}};
- entt::meta_any rhs{fat_type{&j}};
- std::swap(lhs, rhs);
- ASSERT_EQ(lhs.cast<fat_type>().foo, &j);
- ASSERT_EQ(rhs.cast<fat_type>().bar, &i);
- }
- TEST_F(Meta, MetaAnyVoidSwap) {
- entt::meta_any lhs{std::in_place_type<void>};
- entt::meta_any rhs{std::in_place_type<void>};
- const auto *pre = lhs.data();
- std::swap(lhs, rhs);
- ASSERT_EQ(pre, lhs.data());
- }
- TEST_F(Meta, MetaAnySBOWithNoSBOSwap) {
- int value = 42;
- entt::meta_any lhs{fat_type{&value}};
- entt::meta_any rhs{'c'};
- std::swap(lhs, rhs);
- ASSERT_TRUE(lhs.try_cast<char>());
- ASSERT_EQ(lhs.cast<char>(), 'c');
- ASSERT_TRUE(rhs.try_cast<fat_type>());
- ASSERT_EQ(rhs.cast<fat_type>().foo, &value);
- ASSERT_EQ(rhs.cast<fat_type>().bar, &value);
- }
- TEST_F(Meta, MetaAnySBOWithEmptySwap) {
- entt::meta_any lhs{'c'};
- entt::meta_any rhs{};
- std::swap(lhs, rhs);
- ASSERT_FALSE(lhs);
- ASSERT_TRUE(rhs.try_cast<char>());
- ASSERT_EQ(rhs.cast<char>(), 'c');
- std::swap(lhs, rhs);
- ASSERT_FALSE(rhs);
- ASSERT_TRUE(lhs.try_cast<char>());
- ASSERT_EQ(lhs.cast<char>(), 'c');
- }
- TEST_F(Meta, MetaAnySBOWithVoidSwap) {
- entt::meta_any lhs{'c'};
- entt::meta_any rhs{std::in_place_type<void>};
- std::swap(lhs, rhs);
- ASSERT_EQ(lhs.type(), entt::resolve<void>());
- ASSERT_TRUE(rhs.try_cast<char>());
- ASSERT_EQ(rhs.cast<char>(), 'c');
- }
- TEST_F(Meta, MetaAnyNoSBOWithEmptySwap) {
- int i;
- entt::meta_any lhs{fat_type{&i}};
- entt::meta_any rhs{};
- std::swap(lhs, rhs);
- ASSERT_EQ(rhs.cast<fat_type>().bar, &i);
- std::swap(lhs, rhs);
- ASSERT_EQ(lhs.cast<fat_type>().bar, &i);
- }
- TEST_F(Meta, MetaAnyNoSBOWithVoidSwap) {
- int i;
- entt::meta_any lhs{fat_type{&i}};
- entt::meta_any rhs{std::in_place_type<void>};
- std::swap(lhs, rhs);
- ASSERT_EQ(rhs.cast<fat_type>().bar, &i);
- std::swap(lhs, rhs);
- ASSERT_EQ(lhs.cast<fat_type>().bar, &i);
- }
- TEST_F(Meta, MetaAnyComparable) {
- entt::meta_any any{'c'};
- ASSERT_EQ(any, any);
- ASSERT_EQ(any, entt::meta_any{'c'});
- ASSERT_NE(entt::meta_any{'a'}, any);
- ASSERT_NE(any, entt::meta_any{});
- ASSERT_TRUE(any == any);
- ASSERT_TRUE(any == entt::meta_any{'c'});
- ASSERT_FALSE(any == entt::meta_any{'a'});
- ASSERT_TRUE(any != entt::meta_any{'a'});
- ASSERT_TRUE(any != entt::meta_any{});
- }
- TEST_F(Meta, MetaAnyNotComparable) {
- entt::meta_any any{not_comparable_type{}};
- ASSERT_EQ(any, any);
- ASSERT_NE(any, entt::meta_any{not_comparable_type{}});
- ASSERT_NE(entt::meta_any{}, any);
- ASSERT_TRUE(any == any);
- ASSERT_FALSE(any == entt::meta_any{not_comparable_type{}});
- ASSERT_TRUE(any != entt::meta_any{});
- }
- TEST_F(Meta, MetaAnyCompareVoid) {
- entt::meta_any any{std::in_place_type<void>};
- ASSERT_EQ(any, any);
- ASSERT_EQ(any, entt::meta_any{std::in_place_type<void>});
- ASSERT_NE(entt::meta_any{'a'}, any);
- ASSERT_NE(any, entt::meta_any{});
- ASSERT_TRUE(any == any);
- ASSERT_TRUE(any == entt::meta_any{std::in_place_type<void>});
- ASSERT_FALSE(any == entt::meta_any{'a'});
- ASSERT_TRUE(any != entt::meta_any{'a'});
- ASSERT_TRUE(any != entt::meta_any{});
- }
- TEST_F(Meta, MetaAnyTryCast) {
- entt::meta_any any{derived_type{}};
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<derived_type>());
- ASSERT_EQ(any.try_cast<void>(), nullptr);
- ASSERT_NE(any.try_cast<base_type>(), nullptr);
- ASSERT_EQ(any.try_cast<derived_type>(), any.data());
- ASSERT_EQ(std::as_const(any).try_cast<base_type>(), any.try_cast<base_type>());
- ASSERT_EQ(std::as_const(any).try_cast<derived_type>(), any.data());
- }
- TEST_F(Meta, MetaAnyCast) {
- entt::meta_any any{derived_type{}};
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<derived_type>());
- ASSERT_EQ(any.try_cast<std::size_t>(), nullptr);
- ASSERT_NE(any.try_cast<base_type>(), nullptr);
- ASSERT_EQ(any.try_cast<derived_type>(), any.data());
- ASSERT_EQ(std::as_const(any).try_cast<base_type>(), any.try_cast<base_type>());
- ASSERT_EQ(std::as_const(any).try_cast<derived_type>(), any.data());
- }
- TEST_F(Meta, MetaAnyConvert) {
- entt::meta_any any{42.};
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<double>());
- ASSERT_TRUE(any.convert<double>());
- ASSERT_FALSE(any.convert<char>());
- ASSERT_EQ(any.type(), entt::resolve<double>());
- ASSERT_EQ(any.cast<double>(), 42.);
- ASSERT_TRUE(any.convert<int>());
- ASSERT_EQ(any.type(), entt::resolve<int>());
- ASSERT_EQ(any.cast<int>(), 42);
- }
- TEST_F(Meta, MetaAnyConstConvert) {
- const entt::meta_any any{42.};
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<double>());
- ASSERT_TRUE(any.convert<double>());
- ASSERT_FALSE(any.convert<char>());
- ASSERT_EQ(any.type(), entt::resolve<double>());
- ASSERT_EQ(any.cast<double>(), 42.);
- auto other = any.convert<int>();
- ASSERT_EQ(any.type(), entt::resolve<double>());
- ASSERT_EQ(any.cast<double>(), 42.);
- ASSERT_EQ(other.type(), entt::resolve<int>());
- ASSERT_EQ(other.cast<int>(), 42);
- }
- TEST_F(Meta, MetaHandleFromObject) {
- empty_type empty{};
- entt::meta_handle handle{empty};
- ASSERT_TRUE(handle);
- ASSERT_EQ(handle.type(), entt::resolve<empty_type>());
- ASSERT_EQ(std::as_const(handle).data(), &empty);
- ASSERT_EQ(handle.data(), &empty);
- }
- TEST_F(Meta, MetaHandleFromMetaAny) {
- entt::meta_any any{42};
- entt::meta_handle handle{any};
- ASSERT_TRUE(handle);
- ASSERT_EQ(handle.type(), entt::resolve<int>());
- ASSERT_EQ(std::as_const(handle).data(), any.data());
- ASSERT_EQ(handle.data(), any.data());
- }
- TEST_F(Meta, MetaHandleEmpty) {
- entt::meta_handle handle{};
- ASSERT_FALSE(handle);
- ASSERT_FALSE(handle.type());
- ASSERT_EQ(std::as_const(handle).data(), nullptr);
- ASSERT_EQ(handle.data(), nullptr);
- }
- TEST_F(Meta, MetaProp) {
- auto prop = entt::resolve<char>().prop(properties::prop_int);
- ASSERT_TRUE(prop);
- ASSERT_NE(prop, entt::meta_prop{});
- ASSERT_EQ(prop.key(), properties::prop_int);
- ASSERT_EQ(prop.value(), 42);
- }
- TEST_F(Meta, MetaBase) {
- auto base = entt::resolve<derived_type>().base("base"_hs);
- derived_type derived{};
- ASSERT_TRUE(base);
- ASSERT_NE(base, entt::meta_base{});
- ASSERT_EQ(base.parent(), entt::resolve("derived"_hs));
- ASSERT_EQ(base.type(), entt::resolve<base_type>());
- ASSERT_EQ(base.cast(&derived), static_cast<base_type *>(&derived));
- }
- TEST_F(Meta, MetaConv) {
- auto conv = entt::resolve<double>().conv<int>();
- double value = 3.;
- ASSERT_TRUE(conv);
- ASSERT_NE(conv, entt::meta_conv{});
- ASSERT_EQ(conv.parent(), entt::resolve<double>());
- ASSERT_EQ(conv.type(), entt::resolve<int>());
- auto any = conv.convert(&value);
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<int>());
- ASSERT_EQ(any.cast<int>(), 3);
- }
- TEST_F(Meta, MetaConvAsFreeFunctions) {
- auto conv = entt::resolve<derived_type>().conv<int>();
- derived_type derived{derived_type{}, 42, 'c'};
- ASSERT_TRUE(conv);
- ASSERT_NE(conv, entt::meta_conv{});
- ASSERT_EQ(conv.parent(), entt::resolve<derived_type>());
- ASSERT_EQ(conv.type(), entt::resolve<int>());
- auto any = conv.convert(&derived);
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<int>());
- ASSERT_EQ(any.cast<int>(), 42);
- }
- TEST_F(Meta, MetaConvAsMemberFunctions) {
- auto conv = entt::resolve<derived_type>().conv<char>();
- derived_type derived{derived_type{}, 42, 'c'};
- ASSERT_TRUE(conv);
- ASSERT_NE(conv, entt::meta_conv{});
- ASSERT_EQ(conv.parent(), entt::resolve<derived_type>());
- ASSERT_EQ(conv.type(), entt::resolve<char>());
- auto any = conv.convert(&derived);
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<char>());
- ASSERT_EQ(any.cast<char>(), 'c');
- }
- TEST_F(Meta, MetaCtor) {
- auto ctor = entt::resolve<derived_type>().ctor<const base_type &, int, char>();
- ASSERT_TRUE(ctor);
- ASSERT_NE(ctor, entt::meta_ctor{});
- ASSERT_EQ(ctor.parent(), entt::resolve("derived"_hs));
- ASSERT_EQ(ctor.size(), entt::meta_ctor::size_type{3});
- ASSERT_EQ(ctor.arg(entt::meta_ctor::size_type{0}), entt::resolve<base_type>());
- ASSERT_EQ(ctor.arg(entt::meta_ctor::size_type{1}), entt::resolve<int>());
- ASSERT_EQ(ctor.arg(entt::meta_ctor::size_type{2}), entt::resolve<char>());
- ASSERT_FALSE(ctor.arg(entt::meta_ctor::size_type{3}));
- auto any = ctor.invoke(base_type{}, 42, 'c');
- auto empty = ctor.invoke();
- ASSERT_FALSE(empty);
- ASSERT_TRUE(any);
- ASSERT_TRUE(any.try_cast<derived_type>());
- ASSERT_EQ(any.cast<derived_type>().i, 42);
- ASSERT_EQ(any.cast<derived_type>().c, 'c');
- ctor.prop([](auto prop) {
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_bool);
- ASSERT_FALSE(prop.value().template cast<bool>());
- });
- ASSERT_FALSE(ctor.prop(properties::prop_int));
- auto prop = ctor.prop(properties::prop_bool);
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_bool);
- ASSERT_FALSE(prop.value().template cast<bool>());
- }
- TEST_F(Meta, MetaCtorFunc) {
- auto ctor = entt::resolve<derived_type>().ctor<const base_type &, int>();
- ASSERT_TRUE(ctor);
- ASSERT_EQ(ctor.parent(), entt::resolve("derived"_hs));
- ASSERT_EQ(ctor.size(), entt::meta_ctor::size_type{2});
- ASSERT_EQ(ctor.arg(entt::meta_ctor::size_type{0}), entt::resolve<base_type>());
- ASSERT_EQ(ctor.arg(entt::meta_ctor::size_type{1}), entt::resolve<int>());
- ASSERT_FALSE(ctor.arg(entt::meta_ctor::size_type{2}));
- auto any = ctor.invoke(derived_type{}, 42);
- auto empty = ctor.invoke(3, 'c');
- ASSERT_FALSE(empty);
- ASSERT_TRUE(any);
- ASSERT_TRUE(any.try_cast<derived_type>());
- ASSERT_EQ(any.cast<derived_type>().i, 42);
- ASSERT_EQ(any.cast<derived_type>().c, 'c');
- ctor.prop([](auto prop) {
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_int);
- ASSERT_EQ(prop.value(), 42);
- });
- ASSERT_FALSE(ctor.prop(properties::prop_bool));
- auto prop = ctor.prop(properties::prop_int);
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_int);
- ASSERT_EQ(prop.value(), 42);
- }
- TEST_F(Meta, MetaCtorMetaAnyArgs) {
- auto ctor = entt::resolve<derived_type>().ctor<const base_type &, int, char>();
- auto any = ctor.invoke(base_type{}, entt::meta_any{42}, entt::meta_any{'c'});
- ASSERT_TRUE(any);
- ASSERT_TRUE(any.try_cast<derived_type>());
- ASSERT_EQ(any.cast<derived_type>().i, 42);
- ASSERT_EQ(any.cast<derived_type>().c, 'c');
- }
- TEST_F(Meta, MetaCtorInvalidArgs) {
- auto ctor = entt::resolve<derived_type>().ctor<const base_type &, int, char>();
- ASSERT_FALSE(ctor.invoke(base_type{}, entt::meta_any{'c'}, entt::meta_any{42}));
- }
- TEST_F(Meta, MetaCtorCastAndConvert) {
- auto ctor = entt::resolve<derived_type>().ctor<const base_type &, int, char>();
- auto any = ctor.invoke(entt::meta_any{derived_type{}}, entt::meta_any{42.}, entt::meta_any{'c'});
- ASSERT_TRUE(any);
- ASSERT_TRUE(any.try_cast<derived_type>());
- ASSERT_EQ(any.cast<derived_type>().i, 42);
- ASSERT_EQ(any.cast<derived_type>().c, 'c');
- }
- TEST_F(Meta, MetaCtorFuncMetaAnyArgs) {
- auto ctor = entt::resolve<derived_type>().ctor<const base_type &, int>();
- auto any = ctor.invoke(base_type{}, entt::meta_any{42});
- ASSERT_TRUE(any);
- ASSERT_TRUE(any.try_cast<derived_type>());
- ASSERT_EQ(any.cast<derived_type>().i, 42);
- ASSERT_EQ(any.cast<derived_type>().c, 'c');
- }
- TEST_F(Meta, MetaCtorFuncInvalidArgs) {
- auto ctor = entt::resolve<derived_type>().ctor<const base_type &, int>();
- ASSERT_FALSE(ctor.invoke(base_type{}, entt::meta_any{'c'}));
- }
- TEST_F(Meta, MetaCtorFuncCastAndConvert) {
- auto ctor = entt::resolve<derived_type>().ctor<const base_type &, int>();
- auto any = ctor.invoke(entt::meta_any{derived_type{}}, entt::meta_any{42.});
- ASSERT_TRUE(any);
- ASSERT_TRUE(any.try_cast<derived_type>());
- ASSERT_EQ(any.cast<derived_type>().i, 42);
- ASSERT_EQ(any.cast<derived_type>().c, 'c');
- }
- TEST_F(Meta, MetaDtor) {
- auto dtor = entt::resolve<empty_type>().dtor();
- empty_type empty{};
- ASSERT_TRUE(dtor);
- ASSERT_NE(dtor, entt::meta_dtor{});
- ASSERT_EQ(dtor.parent(), entt::resolve("empty"_hs));
- ASSERT_EQ(empty_type::counter, 0);
- ASSERT_TRUE(dtor.invoke(empty));
- ASSERT_EQ(empty_type::counter, 1);
- }
- TEST_F(Meta, MetaDtorMetaAnyArg) {
- auto dtor = entt::resolve<empty_type>().dtor();
- entt::meta_any any{empty_type{}};
- ASSERT_EQ(empty_type::counter, 0);
- ASSERT_TRUE(dtor.invoke(any));
- ASSERT_EQ(empty_type::counter, 1);
- }
- TEST_F(Meta, MetaDtorMetaAnyInvalidArg) {
- auto instance = 0;
- ASSERT_FALSE(entt::resolve<empty_type>().dtor().invoke(instance));
- }
- TEST_F(Meta, MetaData) {
- auto data = entt::resolve<data_type>().data("i"_hs);
- data_type instance{};
- ASSERT_TRUE(data);
- ASSERT_NE(data, entt::meta_data{});
- ASSERT_EQ(data.parent(), entt::resolve("data"_hs));
- ASSERT_EQ(data.type(), entt::resolve<int>());
- ASSERT_EQ(data.identifier(), "i"_hs);
- ASSERT_FALSE(data.is_const());
- ASSERT_FALSE(data.is_static());
- ASSERT_EQ(data.get(instance).cast<int>(), 0);
- ASSERT_TRUE(data.set(instance, 42));
- ASSERT_EQ(data.get(instance).cast<int>(), 42);
- data.prop([](auto prop) {
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_int);
- ASSERT_EQ(prop.value(), 0);
- });
- ASSERT_FALSE(data.prop(properties::prop_bool));
- auto prop = data.prop(properties::prop_int);
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_int);
- ASSERT_EQ(prop.value(), 0);
- }
- TEST_F(Meta, MetaDataConst) {
- auto data = entt::resolve<data_type>().data("j"_hs);
- data_type instance{};
- ASSERT_TRUE(data);
- ASSERT_EQ(data.parent(), entt::resolve("data"_hs));
- ASSERT_EQ(data.type(), entt::resolve<int>());
- ASSERT_EQ(data.identifier(), "j"_hs);
- ASSERT_TRUE(data.is_const());
- ASSERT_FALSE(data.is_static());
- ASSERT_EQ(data.get(instance).cast<int>(), 1);
- ASSERT_FALSE(data.set(instance, 42));
- ASSERT_EQ(data.get(instance).cast<int>(), 1);
- data.prop([](auto prop) {
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_int);
- ASSERT_EQ(prop.value(), 1);
- });
- ASSERT_FALSE(data.prop(properties::prop_bool));
- auto prop = data.prop(properties::prop_int);
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_int);
- ASSERT_EQ(prop.value(), 1);
- }
- TEST_F(Meta, MetaDataStatic) {
- auto data = entt::resolve<data_type>().data("h"_hs);
- ASSERT_TRUE(data);
- ASSERT_EQ(data.parent(), entt::resolve("data"_hs));
- ASSERT_EQ(data.type(), entt::resolve<int>());
- ASSERT_EQ(data.identifier(), "h"_hs);
- ASSERT_FALSE(data.is_const());
- ASSERT_TRUE(data.is_static());
- ASSERT_EQ(data.get({}).cast<int>(), 2);
- ASSERT_TRUE(data.set({}, 42));
- ASSERT_EQ(data.get({}).cast<int>(), 42);
- data.prop([](auto prop) {
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_int);
- ASSERT_EQ(prop.value(), 2);
- });
- ASSERT_FALSE(data.prop(properties::prop_bool));
- auto prop = data.prop(properties::prop_int);
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_int);
- ASSERT_EQ(prop.value(), 2);
- }
- TEST_F(Meta, MetaDataConstStatic) {
- auto data = entt::resolve<data_type>().data("k"_hs);
- ASSERT_TRUE(data);
- ASSERT_EQ(data.parent(), entt::resolve("data"_hs));
- ASSERT_EQ(data.type(), entt::resolve<int>());
- ASSERT_EQ(data.identifier(), "k"_hs);
- ASSERT_TRUE(data.is_const());
- ASSERT_TRUE(data.is_static());
- ASSERT_EQ(data.get({}).cast<int>(), 3);
- ASSERT_FALSE(data.set({}, 42));
- ASSERT_EQ(data.get({}).cast<int>(), 3);
- data.prop([](auto prop) {
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_int);
- ASSERT_EQ(prop.value(), 3);
- });
- ASSERT_FALSE(data.prop(properties::prop_bool));
- auto prop = data.prop(properties::prop_int);
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_int);
- ASSERT_EQ(prop.value(), 3);
- }
- TEST_F(Meta, MetaDataGetMetaAnyArg) {
- auto data = entt::resolve<data_type>().data("i"_hs);
- entt::meta_any any{data_type{}};
- any.cast<data_type>().i = 99;
- const auto value = data.get(any);
- ASSERT_TRUE(value);
- ASSERT_TRUE(value.cast<int>());
- ASSERT_EQ(value.cast<int>(), 99);
- }
- TEST_F(Meta, MetaDataGetInvalidArg) {
- auto instance = 0;
- ASSERT_FALSE(entt::resolve<data_type>().data("i"_hs).get(instance));
- }
- TEST_F(Meta, MetaDataSetMetaAnyArg) {
- auto data = entt::resolve<data_type>().data("i"_hs);
- entt::meta_any any{data_type{}};
- entt::meta_any value{42};
- ASSERT_EQ(any.cast<data_type>().i, 0);
- ASSERT_TRUE(data.set(any, value));
- ASSERT_EQ(any.cast<data_type>().i, 42);
- }
- TEST_F(Meta, MetaDataSetInvalidArg) {
- ASSERT_FALSE(entt::resolve<data_type>().data("i"_hs).set({}, 'c'));
- }
- TEST_F(Meta, MetaDataSetCast) {
- auto data = entt::resolve<data_type>().data("empty"_hs);
- data_type instance{};
- ASSERT_EQ(empty_type::counter, 0);
- ASSERT_TRUE(data.set(instance, fat_type{}));
- ASSERT_EQ(empty_type::counter, 1);
- }
- TEST_F(Meta, MetaDataSetConvert) {
- auto data = entt::resolve<data_type>().data("i"_hs);
- data_type instance{};
- ASSERT_EQ(instance.i, 0);
- ASSERT_TRUE(data.set(instance, 3.));
- ASSERT_EQ(instance.i, 3);
- }
- TEST_F(Meta, MetaDataSetterGetterAsFreeFunctions) {
- auto data = entt::resolve<setter_getter_type>().data("x"_hs);
- setter_getter_type instance{};
- ASSERT_TRUE(data);
- ASSERT_NE(data, entt::meta_data{});
- ASSERT_EQ(data.parent(), entt::resolve("setter_getter"_hs));
- ASSERT_EQ(data.type(), entt::resolve<int>());
- ASSERT_EQ(data.identifier(), "x"_hs);
- ASSERT_FALSE(data.is_const());
- ASSERT_FALSE(data.is_static());
- ASSERT_EQ(data.get(instance).cast<int>(), 0);
- ASSERT_TRUE(data.set(instance, 42));
- ASSERT_EQ(data.get(instance).cast<int>(), 42);
- }
- TEST_F(Meta, MetaDataSetterGetterAsMemberFunctions) {
- auto data = entt::resolve<setter_getter_type>().data("y"_hs);
- setter_getter_type instance{};
- ASSERT_TRUE(data);
- ASSERT_NE(data, entt::meta_data{});
- ASSERT_EQ(data.parent(), entt::resolve("setter_getter"_hs));
- ASSERT_EQ(data.type(), entt::resolve<int>());
- ASSERT_EQ(data.identifier(), "y"_hs);
- ASSERT_FALSE(data.is_const());
- ASSERT_FALSE(data.is_static());
- ASSERT_EQ(data.get(instance).cast<int>(), 0);
- ASSERT_TRUE(data.set(instance, 42));
- ASSERT_EQ(data.get(instance).cast<int>(), 42);
- }
- TEST_F(Meta, MetaDataSetterGetterWithRefAsMemberFunctions) {
- auto data = entt::resolve<setter_getter_type>().data("w"_hs);
- setter_getter_type instance{};
- ASSERT_TRUE(data);
- ASSERT_NE(data, entt::meta_data{});
- ASSERT_EQ(data.parent(), entt::resolve("setter_getter"_hs));
- ASSERT_EQ(data.type(), entt::resolve<int>());
- ASSERT_EQ(data.identifier(), "w"_hs);
- ASSERT_FALSE(data.is_const());
- ASSERT_FALSE(data.is_static());
- ASSERT_EQ(data.get(instance).cast<int>(), 0);
- ASSERT_TRUE(data.set(instance, 42));
- ASSERT_EQ(data.get(instance).cast<int>(), 42);
- }
- TEST_F(Meta, MetaDataSetterGetterMixed) {
- auto data = entt::resolve<setter_getter_type>().data("z"_hs);
- setter_getter_type instance{};
- ASSERT_TRUE(data);
- ASSERT_NE(data, entt::meta_data{});
- ASSERT_EQ(data.parent(), entt::resolve("setter_getter"_hs));
- ASSERT_EQ(data.type(), entt::resolve<int>());
- ASSERT_EQ(data.identifier(), "z"_hs);
- ASSERT_FALSE(data.is_const());
- ASSERT_FALSE(data.is_static());
- ASSERT_EQ(data.get(instance).cast<int>(), 0);
- ASSERT_TRUE(data.set(instance, 42));
- ASSERT_EQ(data.get(instance).cast<int>(), 42);
- }
- TEST_F(Meta, MetaDataArrayStatic) {
- auto data = entt::resolve<array_type>().data("global"_hs);
- array_type::global[0] = 3;
- array_type::global[1] = 5;
- array_type::global[2] = 7;
- ASSERT_TRUE(data);
- ASSERT_NE(data, entt::meta_data{});
- ASSERT_EQ(data.parent(), entt::resolve("array"_hs));
- ASSERT_EQ(data.type(), entt::resolve<int[3]>());
- ASSERT_EQ(data.identifier(), "global"_hs);
- ASSERT_FALSE(data.is_const());
- ASSERT_TRUE(data.is_static());
- ASSERT_TRUE(data.type().is_array());
- ASSERT_EQ(data.type().extent(), 3);
- ASSERT_EQ(data.get({}, 0).cast<int>(), 3);
- ASSERT_EQ(data.get({}, 1).cast<int>(), 5);
- ASSERT_EQ(data.get({}, 2).cast<int>(), 7);
- ASSERT_FALSE(data.set({}, 0, 'c'));
- ASSERT_EQ(data.get({}, 0).cast<int>(), 3);
- ASSERT_TRUE(data.set({}, 0, data.get({}, 0).cast<int>()+2));
- ASSERT_TRUE(data.set({}, 1, data.get({}, 1).cast<int>()+2));
- ASSERT_TRUE(data.set({}, 2, data.get({}, 2).cast<int>()+2));
- ASSERT_EQ(data.get({}, 0).cast<int>(), 5);
- ASSERT_EQ(data.get({}, 1).cast<int>(), 7);
- ASSERT_EQ(data.get({}, 2).cast<int>(), 9);
- }
- TEST_F(Meta, MetaDataArray) {
- auto data = entt::resolve<array_type>().data("local"_hs);
- array_type instance;
- instance.local[0] = 3;
- instance.local[1] = 5;
- instance.local[2] = 7;
- ASSERT_TRUE(data);
- ASSERT_NE(data, entt::meta_data{});
- ASSERT_EQ(data.parent(), entt::resolve("array"_hs));
- ASSERT_EQ(data.type(), entt::resolve<int[3]>());
- ASSERT_EQ(data.identifier(), "local"_hs);
- ASSERT_FALSE(data.is_const());
- ASSERT_FALSE(data.is_static());
- ASSERT_TRUE(data.type().is_array());
- ASSERT_EQ(data.type().extent(), 3);
- ASSERT_EQ(data.get(instance, 0).cast<int>(), 3);
- ASSERT_EQ(data.get(instance, 1).cast<int>(), 5);
- ASSERT_EQ(data.get(instance, 2).cast<int>(), 7);
- ASSERT_FALSE(data.set(instance, 0, 'c'));
- ASSERT_EQ(data.get(instance, 0).cast<int>(), 3);
- ASSERT_TRUE(data.set(instance, 0, data.get(instance, 0).cast<int>()+2));
- ASSERT_TRUE(data.set(instance, 1, data.get(instance, 1).cast<int>()+2));
- ASSERT_TRUE(data.set(instance, 2, data.get(instance, 2).cast<int>()+2));
- ASSERT_EQ(data.get(instance, 0).cast<int>(), 5);
- ASSERT_EQ(data.get(instance, 1).cast<int>(), 7);
- ASSERT_EQ(data.get(instance, 2).cast<int>(), 9);
- }
- TEST_F(Meta, MetaDataAsVoid) {
- auto data = entt::resolve<data_type>().data("v"_hs);
- data_type instance{};
- ASSERT_TRUE(data.set(instance, 42));
- ASSERT_EQ(instance.v, 42);
- ASSERT_EQ(data.get(instance), entt::meta_any{std::in_place_type<void>});
- }
- TEST_F(Meta, MetaDataAsAlias) {
- data_type instance{};
- auto h_data = entt::resolve<data_type>().data("h"_hs);
- auto i_data = entt::resolve<data_type>().data("i"_hs);
- h_data.get(instance).cast<int>() = 3;
- i_data.get(instance).cast<int>() = 3;
- ASSERT_EQ(h_data.type(), entt::resolve<int>());
- ASSERT_EQ(i_data.type(), entt::resolve<int>());
- ASSERT_NE(instance.h, 3);
- ASSERT_EQ(instance.i, 3);
- }
- TEST_F(Meta, MetaFunc) {
- auto func = entt::resolve<func_type>().func("f2"_hs);
- func_type instance{};
- ASSERT_TRUE(func);
- ASSERT_NE(func, entt::meta_func{});
- ASSERT_EQ(func.parent(), entt::resolve("func"_hs));
- ASSERT_EQ(func.identifier(), "f2"_hs);
- ASSERT_EQ(func.size(), entt::meta_func::size_type{2});
- ASSERT_FALSE(func.is_const());
- ASSERT_FALSE(func.is_static());
- ASSERT_EQ(func.ret(), entt::resolve<int>());
- ASSERT_EQ(func.arg(entt::meta_func::size_type{0}), entt::resolve<int>());
- ASSERT_EQ(func.arg(entt::meta_func::size_type{1}), entt::resolve<int>());
- ASSERT_FALSE(func.arg(entt::meta_func::size_type{2}));
- auto any = func.invoke(instance, 3, 2);
- auto empty = func.invoke(instance);
- ASSERT_FALSE(empty);
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<int>());
- ASSERT_EQ(any.cast<int>(), 4);
- ASSERT_EQ(func_type::value, 3);
- func.prop([](auto prop) {
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_bool);
- ASSERT_FALSE(prop.value().template cast<bool>());
- });
- ASSERT_FALSE(func.prop(properties::prop_int));
- auto prop = func.prop(properties::prop_bool);
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_bool);
- ASSERT_FALSE(prop.value().cast<bool>());
- }
- TEST_F(Meta, MetaFuncConst) {
- auto func = entt::resolve<func_type>().func("f1"_hs);
- func_type instance{};
- ASSERT_TRUE(func);
- ASSERT_EQ(func.parent(), entt::resolve("func"_hs));
- ASSERT_EQ(func.identifier(), "f1"_hs);
- ASSERT_EQ(func.size(), entt::meta_func::size_type{1});
- ASSERT_TRUE(func.is_const());
- ASSERT_FALSE(func.is_static());
- ASSERT_EQ(func.ret(), entt::resolve<int>());
- ASSERT_EQ(func.arg(entt::meta_func::size_type{0}), entt::resolve<int>());
- ASSERT_FALSE(func.arg(entt::meta_func::size_type{1}));
- auto any = func.invoke(instance, 4);
- auto empty = func.invoke(instance, 'c');
- ASSERT_FALSE(empty);
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<int>());
- ASSERT_EQ(any.cast<int>(), 16);
- func.prop([](auto prop) {
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_bool);
- ASSERT_FALSE(prop.value().template cast<bool>());
- });
- ASSERT_FALSE(func.prop(properties::prop_int));
- auto prop = func.prop(properties::prop_bool);
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_bool);
- ASSERT_FALSE(prop.value().cast<bool>());
- }
- TEST_F(Meta, MetaFuncRetVoid) {
- auto func = entt::resolve<func_type>().func("g"_hs);
- func_type instance{};
- ASSERT_TRUE(func);
- ASSERT_EQ(func.parent(), entt::resolve("func"_hs));
- ASSERT_EQ(func.identifier(), "g"_hs);
- ASSERT_EQ(func.size(), entt::meta_func::size_type{1});
- ASSERT_FALSE(func.is_const());
- ASSERT_FALSE(func.is_static());
- ASSERT_EQ(func.ret(), entt::resolve<void>());
- ASSERT_EQ(func.arg(entt::meta_func::size_type{0}), entt::resolve<int>());
- ASSERT_FALSE(func.arg(entt::meta_func::size_type{1}));
- auto any = func.invoke(instance, 5);
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<void>());
- ASSERT_EQ(func_type::value, 25);
- func.prop([](auto prop) {
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_bool);
- ASSERT_FALSE(prop.value().template cast<bool>());
- });
- ASSERT_FALSE(func.prop(properties::prop_int));
- auto prop = func.prop(properties::prop_bool);
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_bool);
- ASSERT_FALSE(prop.value().cast<bool>());
- }
- TEST_F(Meta, MetaFuncStatic) {
- auto func = entt::resolve<func_type>().func("h"_hs);
- func_type::value = 2;
- ASSERT_TRUE(func);
- ASSERT_EQ(func.parent(), entt::resolve("func"_hs));
- ASSERT_EQ(func.identifier(), "h"_hs);
- ASSERT_EQ(func.size(), entt::meta_func::size_type{1});
- ASSERT_FALSE(func.is_const());
- ASSERT_TRUE(func.is_static());
- ASSERT_EQ(func.ret(), entt::resolve<int>());
- ASSERT_EQ(func.arg(entt::meta_func::size_type{0}), entt::resolve<int>());
- ASSERT_FALSE(func.arg(entt::meta_func::size_type{1}));
- auto any = func.invoke({}, 3);
- auto empty = func.invoke({}, 'c');
- ASSERT_FALSE(empty);
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<int>());
- ASSERT_EQ(any.cast<int>(), 6);
- func.prop([](auto prop) {
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_bool);
- ASSERT_FALSE(prop.value().template cast<bool>());
- });
- ASSERT_FALSE(func.prop(properties::prop_int));
- auto prop = func.prop(properties::prop_bool);
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_bool);
- ASSERT_FALSE(prop.value().cast<bool>());
- }
- TEST_F(Meta, MetaFuncStaticRetVoid) {
- auto func = entt::resolve<func_type>().func("k"_hs);
- ASSERT_TRUE(func);
- ASSERT_EQ(func.parent(), entt::resolve("func"_hs));
- ASSERT_EQ(func.identifier(), "k"_hs);
- ASSERT_EQ(func.size(), entt::meta_func::size_type{1});
- ASSERT_FALSE(func.is_const());
- ASSERT_TRUE(func.is_static());
- ASSERT_EQ(func.ret(), entt::resolve<void>());
- ASSERT_EQ(func.arg(entt::meta_func::size_type{0}), entt::resolve<int>());
- ASSERT_FALSE(func.arg(entt::meta_func::size_type{1}));
- auto any = func.invoke({}, 42);
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<void>());
- ASSERT_EQ(func_type::value, 42);
- func.prop([](auto *prop) {
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop->key(), properties::prop_bool);
- ASSERT_FALSE(prop->value().template cast<bool>());
- });
- ASSERT_FALSE(func.prop(properties::prop_int));
- auto prop = func.prop(properties::prop_bool);
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_bool);
- ASSERT_FALSE(prop.value().cast<bool>());
- }
- TEST_F(Meta, MetaFuncMetaAnyArgs) {
- auto func = entt::resolve<func_type>().func("f1"_hs);
- func_type instance;
- auto any = func.invoke(instance, entt::meta_any{3});
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<int>());
- ASSERT_EQ(any.cast<int>(), 9);
- }
- TEST_F(Meta, MetaFuncInvalidArgs) {
- auto func = entt::resolve<func_type>().func("f1"_hs);
- empty_type instance;
- ASSERT_FALSE(func.invoke(instance, entt::meta_any{'c'}));
- }
- TEST_F(Meta, MetaFuncCastAndConvert) {
- auto func = entt::resolve<func_type>().func("f3"_hs);
- func_type instance;
- auto any = func.invoke(instance, derived_type{}, 0, 3.);
- ASSERT_TRUE(any);
- ASSERT_EQ(any.type(), entt::resolve<int>());
- ASSERT_EQ(any.cast<int>(), 9);
- }
- TEST_F(Meta, MetaFuncAsVoid) {
- auto func = entt::resolve<func_type>().func("v"_hs);
- func_type instance{};
- ASSERT_EQ(func.invoke(instance, 42), entt::meta_any{std::in_place_type<void>});
- ASSERT_EQ(func.ret(), entt::resolve<void>());
- ASSERT_EQ(instance.value, 42);
- }
- TEST_F(Meta, MetaFuncAsAlias) {
- func_type instance{};
- auto func = entt::resolve<func_type>().func("a"_hs);
- func.invoke(instance).cast<int>() = 3;
- ASSERT_EQ(func.ret(), entt::resolve<int>());
- ASSERT_EQ(instance.value, 3);
- }
- TEST_F(Meta, MetaFuncByReference) {
- auto func = entt::resolve<func_type>().func("h"_hs);
- func_type::value = 2;
- entt::meta_any any{3};
- int value = 4;
- ASSERT_EQ(func.invoke({}, value).cast<int>(), 8);
- ASSERT_EQ(func.invoke({}, any).cast<int>(), 6);
- ASSERT_EQ(any.cast<int>(), 6);
- ASSERT_EQ(value, 8);
- }
- TEST_F(Meta, MetaType) {
- auto type = entt::resolve<derived_type>();
- ASSERT_TRUE(type);
- ASSERT_NE(type, entt::meta_type{});
- ASSERT_EQ(type.identifier(), "derived"_hs);
- type.prop([](auto prop) {
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_int);
- ASSERT_EQ(prop.value(), 99);
- });
- ASSERT_FALSE(type.prop(properties::prop_bool));
- auto prop = type.prop(properties::prop_int);
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_int);
- ASSERT_EQ(prop.value(), 99);
- }
- TEST_F(Meta, MetaTypeTraits) {
- ASSERT_TRUE(entt::resolve<void>().is_void());
- ASSERT_TRUE(entt::resolve<bool>().is_integral());
- ASSERT_TRUE(entt::resolve<double>().is_floating_point());
- ASSERT_TRUE(entt::resolve<properties>().is_enum());
- ASSERT_TRUE(entt::resolve<union_type>().is_union());
- ASSERT_TRUE(entt::resolve<derived_type>().is_class());
- ASSERT_TRUE(entt::resolve<int *>().is_pointer());
- ASSERT_TRUE(entt::resolve<decltype(&empty_type::destroy)>().is_function_pointer());
- ASSERT_TRUE(entt::resolve<decltype(&data_type::i)>().is_member_object_pointer());
- ASSERT_TRUE(entt::resolve<decltype(&func_type::g)>().is_member_function_pointer());
- }
- TEST_F(Meta, MetaTypeRemovePointer) {
- ASSERT_EQ(entt::resolve<void *>().remove_pointer(), entt::resolve<void>());
- ASSERT_EQ(entt::resolve<int(*)(char, double)>().remove_pointer(), entt::resolve<int(char, double)>());
- ASSERT_EQ(entt::resolve<derived_type>().remove_pointer(), entt::resolve<derived_type>());
- }
- TEST_F(Meta, MetaTypeBase) {
- auto type = entt::resolve<derived_type>();
- bool iterate = false;
- type.base([&iterate](auto base) {
- ASSERT_EQ(base.type(), entt::resolve<base_type>());
- iterate = true;
- });
- ASSERT_TRUE(iterate);
- ASSERT_EQ(type.base("base"_hs).type(), entt::resolve<base_type>());
- }
- TEST_F(Meta, MetaTypeConv) {
- auto type = entt::resolve<double>();
- bool iterate = false;
- type.conv([&iterate](auto conv) {
- ASSERT_EQ(conv.type(), entt::resolve<int>());
- iterate = true;
- });
- ASSERT_TRUE(iterate);
- auto conv = type.conv<int>();
- ASSERT_EQ(conv.type(), entt::resolve<int>());
- ASSERT_FALSE(type.conv<char>());
- }
- TEST_F(Meta, MetaTypeCtor) {
- auto type = entt::resolve<derived_type>();
- int counter{};
- type.ctor([&counter](auto) {
- ++counter;
- });
- ASSERT_EQ(counter, 2);
- ASSERT_TRUE((type.ctor<const base_type &, int>()));
- ASSERT_TRUE((type.ctor<const derived_type &, double>()));
- }
- TEST_F(Meta, MetaTypeDtor) {
- ASSERT_TRUE(entt::resolve<fat_type>().dtor());
- ASSERT_FALSE(entt::resolve<int>().dtor());
- }
- TEST_F(Meta, MetaTypeData) {
- auto type = entt::resolve<data_type>();
- int counter{};
- type.data([&counter](auto) {
- ++counter;
- });
- ASSERT_EQ(counter, 6);
- ASSERT_TRUE(type.data("i"_hs));
- }
- TEST_F(Meta, MetaTypeFunc) {
- auto type = entt::resolve<func_type>();
- int counter{};
- type.func([&counter](auto) {
- ++counter;
- });
- ASSERT_EQ(counter, 8);
- ASSERT_TRUE(type.func("f1"_hs));
- }
- TEST_F(Meta, MetaTypeConstruct) {
- auto type = entt::resolve<derived_type>();
- auto any = type.construct(base_type{}, 42, 'c');
- ASSERT_TRUE(any);
- ASSERT_TRUE(any.try_cast<derived_type>());
- ASSERT_EQ(any.cast<derived_type>().i, 42);
- ASSERT_EQ(any.cast<derived_type>().c, 'c');
- }
- TEST_F(Meta, MetaTypeConstructMetaAnyArgs) {
- auto type = entt::resolve<derived_type>();
- auto any = type.construct(entt::meta_any{base_type{}}, entt::meta_any{42}, entt::meta_any{'c'});
- ASSERT_TRUE(any);
- ASSERT_TRUE(any.try_cast<derived_type>());
- ASSERT_EQ(any.cast<derived_type>().i, 42);
- ASSERT_EQ(any.cast<derived_type>().c, 'c');
- }
- TEST_F(Meta, MetaTypeConstructInvalidArgs) {
- auto type = entt::resolve<derived_type>();
- auto any = type.construct(entt::meta_any{base_type{}}, entt::meta_any{'c'}, entt::meta_any{42});
- ASSERT_FALSE(any);
- }
- TEST_F(Meta, MetaTypeLessArgs) {
- auto type = entt::resolve<derived_type>();
- auto any = type.construct(base_type{});
- ASSERT_FALSE(any);
- }
- TEST_F(Meta, MetaTypeConstructCastAndConvert) {
- auto type = entt::resolve<derived_type>();
- auto any = type.construct(entt::meta_any{derived_type{}}, entt::meta_any{42.}, entt::meta_any{'c'});
- ASSERT_TRUE(any);
- ASSERT_TRUE(any.try_cast<derived_type>());
- ASSERT_EQ(any.cast<derived_type>().i, 42);
- ASSERT_EQ(any.cast<derived_type>().c, 'c');
- }
- TEST_F(Meta, MetaTypeDestroyDtor) {
- auto type = entt::resolve<empty_type>();
- empty_type instance;
- ASSERT_EQ(empty_type::counter, 0);
- ASSERT_TRUE(type.destroy(instance));
- ASSERT_EQ(empty_type::counter, 1);
- }
- TEST_F(Meta, MetaTypeDestroyDtorInvalidArg) {
- auto type = entt::resolve<empty_type>();
- auto instance = 'c';
- ASSERT_EQ(empty_type::counter, 0);
- ASSERT_FALSE(type.destroy(instance));
- ASSERT_EQ(empty_type::counter, 0);
- }
- TEST_F(Meta, MetaTypeDestroyDtorCastAndConvert) {
- auto type = entt::resolve<empty_type>();
- fat_type instance{};
- ASSERT_EQ(empty_type::counter, 0);
- ASSERT_FALSE(type.destroy(instance));
- ASSERT_EQ(empty_type::counter, 0);
- }
- TEST_F(Meta, MetaTypeDestroyNoDtor) {
- auto instance = 'c';
- ASSERT_TRUE(entt::resolve<char>().destroy(instance));
- }
- TEST_F(Meta, MetaTypeDestroyNoDtorInvalidArg) {
- auto instance = 42;
- ASSERT_FALSE(entt::resolve<char>().destroy(instance));
- }
- TEST_F(Meta, MetaTypeDestroyNoDtorVoid) {
- ASSERT_FALSE(entt::resolve<void>().destroy({}));
- }
- TEST_F(Meta, MetaTypeDestroyNoDtorCastAndConvert) {
- auto instance = 42.;
- ASSERT_FALSE(entt::resolve<int>().destroy(instance));
- }
- TEST_F(Meta, MetaDataFromBase) {
- auto type = entt::resolve<concrete_type>();
- concrete_type instance;
- ASSERT_TRUE(type.data("i"_hs));
- ASSERT_TRUE(type.data("j"_hs));
- ASSERT_EQ(instance.i, 0);
- ASSERT_EQ(instance.j, char{});
- ASSERT_TRUE(type.data("i"_hs).set(instance, 3));
- ASSERT_TRUE(type.data("j"_hs).set(instance, 'c'));
- ASSERT_EQ(instance.i, 3);
- ASSERT_EQ(instance.j, 'c');
- }
- TEST_F(Meta, MetaFuncFromBase) {
- auto type = entt::resolve<concrete_type>();
- auto base = entt::resolve<an_abstract_type>();
- concrete_type instance;
- ASSERT_TRUE(type.func("f"_hs));
- ASSERT_TRUE(type.func("g"_hs));
- ASSERT_TRUE(type.func("h"_hs));
- ASSERT_EQ(type.func("f"_hs).parent(), entt::resolve<concrete_type>());
- ASSERT_EQ(type.func("g"_hs).parent(), entt::resolve<an_abstract_type>());
- ASSERT_EQ(type.func("h"_hs).parent(), entt::resolve<another_abstract_type>());
- ASSERT_EQ(instance.i, 0);
- ASSERT_EQ(instance.j, char{});
- type.func("f"_hs).invoke(instance, 3);
- type.func("h"_hs).invoke(instance, 'c');
- ASSERT_EQ(instance.i, 9);
- ASSERT_EQ(instance.j, 'c');
- base.func("g"_hs).invoke(instance, 3);
- ASSERT_EQ(instance.i, -3);
- }
- TEST_F(Meta, MetaPropFromBase) {
- auto type = entt::resolve<concrete_type>();
- auto prop_bool = type.prop(properties::prop_bool);
- auto prop_int = type.prop(properties::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;
- ASSERT_EQ(instance.i, 0);
- type.func("f"_hs).invoke(instance, 3);
- ASSERT_EQ(instance.i, 3);
- type.func("g"_hs).invoke(instance, 3);
- ASSERT_EQ(instance.i, -3);
- }
- TEST_F(Meta, EnumAndNamedConstants) {
- auto type = entt::resolve<properties>();
- ASSERT_TRUE(type.data("prop_bool"_hs));
- ASSERT_TRUE(type.data("prop_int"_hs));
- ASSERT_EQ(type.data("prop_bool"_hs).type(), type);
- ASSERT_EQ(type.data("prop_int"_hs).type(), type);
- ASSERT_FALSE(type.data("prop_bool"_hs).set({}, properties::prop_int));
- ASSERT_FALSE(type.data("prop_int"_hs).set({}, properties::prop_bool));
- ASSERT_EQ(type.data("prop_bool"_hs).get({}).cast<properties>(), properties::prop_bool);
- ASSERT_EQ(type.data("prop_int"_hs).get({}).cast<properties>(), properties::prop_int);
- }
- TEST_F(Meta, ArithmeticTypeAndNamedConstants) {
- auto type = entt::resolve<unsigned int>();
- ASSERT_TRUE(type.data("min"_hs));
- ASSERT_TRUE(type.data("max"_hs));
- ASSERT_EQ(type.data("min"_hs).type(), type);
- ASSERT_EQ(type.data("max"_hs).type(), type);
- ASSERT_FALSE(type.data("min"_hs).set({}, 100u));
- ASSERT_FALSE(type.data("max"_hs).set({}, 0u));
- ASSERT_EQ(type.data("min"_hs).get({}).cast<unsigned int>(), 0u);
- ASSERT_EQ(type.data("max"_hs).get({}).cast<unsigned int>(), 100u);
- }
- TEST_F(Meta, Variables) {
- auto p_data = entt::resolve<properties>().data("value"_hs);
- auto c_data = entt::resolve("char"_hs).data("value"_hs);
- properties prop{properties::prop_int};
- char c = 'c';
- p_data.set(prop, properties::prop_bool);
- c_data.set(c, 'x');
- ASSERT_EQ(p_data.get(prop).cast<properties>(), properties::prop_bool);
- ASSERT_EQ(c_data.get(c).cast<char>(), 'x');
- ASSERT_EQ(prop, properties::prop_bool);
- ASSERT_EQ(c, 'x');
- }
- TEST_F(Meta, SharedProperties) {
- const auto type = entt::resolve<properties>();
- const auto prop_bool = type.data("prop_bool"_hs);
- const auto prop_int = type.data("prop_int"_hs);
- ASSERT_TRUE(prop_bool.prop(properties::prop_int));
- ASSERT_FALSE(prop_bool.prop(properties::prop_bool));
- ASSERT_TRUE(prop_int.prop(properties::prop_int));
- ASSERT_TRUE(prop_int.prop(properties::prop_bool));
- }
- TEST_F(Meta, Reset) {
- ASSERT_NE(*entt::internal::meta_info<>::ctx, nullptr);
- ASSERT_NE(entt::internal::meta_info<>::local, nullptr);
- entt::meta<char>().reset();
- entt::meta<concrete_type>().reset();
- entt::meta<setter_getter_type>().reset();
- entt::meta<fat_type>().reset();
- entt::meta<data_type>().reset();
- entt::meta<func_type>().reset();
- entt::meta<array_type>().reset();
- entt::meta<double>().reset();
- entt::meta<properties>().reset();
- entt::meta<base_type>().reset();
- entt::meta<derived_type>().reset();
- entt::meta<empty_type>().reset();
- entt::meta<an_abstract_type>().reset();
- entt::meta<another_abstract_type>().reset();
- entt::meta<unsigned int>().reset();
- ASSERT_EQ(*entt::internal::meta_info<>::ctx, nullptr);
- ASSERT_EQ(entt::internal::meta_info<>::local, nullptr);
- ASSERT_FALSE(entt::resolve("char"_hs));
- ASSERT_FALSE(entt::resolve("base"_hs));
- ASSERT_FALSE(entt::resolve("derived"_hs));
- ASSERT_FALSE(entt::resolve("empty"_hs));
- ASSERT_FALSE(entt::resolve("fat"_hs));
- ASSERT_FALSE(entt::resolve("data"_hs));
- ASSERT_FALSE(entt::resolve("func"_hs));
- ASSERT_FALSE(entt::resolve("setter_getter"_hs));
- ASSERT_FALSE(entt::resolve("an_abstract_type"_hs));
- ASSERT_FALSE(entt::resolve("another_abstract_type"_hs));
- ASSERT_FALSE(entt::resolve("concrete"_hs));
- Meta::SetUpAfterUnregistration();
- entt::meta_any any{42.};
- ASSERT_TRUE(any);
- ASSERT_FALSE(any.convert<int>());
- ASSERT_TRUE(any.convert<float>());
- ASSERT_FALSE(entt::resolve("derived"_hs));
- ASSERT_TRUE(entt::resolve("my_type"_hs));
- entt::resolve<derived_type>().prop([](auto prop) {
- ASSERT_TRUE(prop);
- ASSERT_EQ(prop.key(), properties::prop_bool);
- ASSERT_FALSE(prop.value().template cast<bool>());
- });
- ASSERT_FALSE((entt::resolve<derived_type>().ctor<const base_type &, int, char>()));
- ASSERT_TRUE((entt::resolve<derived_type>().ctor<>()));
- ASSERT_TRUE(entt::resolve("your_type"_hs).data("a_data_member"_hs));
- ASSERT_FALSE(entt::resolve("your_type"_hs).data("another_data_member"_hs));
- ASSERT_TRUE(entt::resolve("your_type"_hs).func("a_member_function"_hs));
- ASSERT_FALSE(entt::resolve("your_type"_hs).func("another_member_function"_hs));
- }
|