Squashed 'external/entt/entt/' content from commit fef92113
git-subtree-dir: external/entt/entt git-subtree-split: fef921132cae7588213d0f9bcd2fb9c8ffd8b7fc
This commit is contained in:
38
test/lib/meta/lib.cpp
Normal file
38
test/lib/meta/lib.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <entt/core/attribute.h>
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
#include <entt/meta/factory.hpp>
|
||||
#include <entt/meta/meta.hpp>
|
||||
#include "types.h"
|
||||
|
||||
position create_position(int x, int y) {
|
||||
return position{x, y};
|
||||
}
|
||||
|
||||
ENTT_API void share(entt::locator<entt::meta_ctx>::node_type handle) {
|
||||
entt::locator<entt::meta_ctx>::reset(handle);
|
||||
}
|
||||
|
||||
ENTT_API void set_up() {
|
||||
using namespace entt::literals;
|
||||
|
||||
entt::meta<position>()
|
||||
.type("position"_hs)
|
||||
.ctor<&create_position>()
|
||||
.data<&position::x>("x"_hs)
|
||||
.data<&position::y>("y"_hs);
|
||||
|
||||
entt::meta<velocity>()
|
||||
.type("velocity"_hs)
|
||||
.ctor<>()
|
||||
.data<&velocity::dx>("dx"_hs)
|
||||
.data<&velocity::dy>("dy"_hs);
|
||||
}
|
||||
|
||||
ENTT_API void tear_down() {
|
||||
entt::meta_reset<position>();
|
||||
entt::meta_reset<velocity>();
|
||||
}
|
||||
|
||||
ENTT_API entt::meta_any wrap_int(int value) {
|
||||
return value;
|
||||
}
|
55
test/lib/meta/main.cpp
Normal file
55
test/lib/meta/main.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/core/attribute.h>
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
#include <entt/meta/factory.hpp>
|
||||
#include <entt/meta/meta.hpp>
|
||||
#include <entt/meta/resolve.hpp>
|
||||
#include "types.h"
|
||||
|
||||
ENTT_API void share(entt::locator<entt::meta_ctx>::node_type);
|
||||
ENTT_API void set_up();
|
||||
ENTT_API void tear_down();
|
||||
ENTT_API entt::meta_any wrap_int(int);
|
||||
|
||||
TEST(Lib, Meta) {
|
||||
using namespace entt::literals;
|
||||
|
||||
ASSERT_FALSE(entt::resolve("position"_hs));
|
||||
ASSERT_FALSE(entt::resolve("velocity"_hs));
|
||||
|
||||
share(entt::locator<entt::meta_ctx>::handle());
|
||||
set_up();
|
||||
entt::meta<double>().conv<int>();
|
||||
|
||||
ASSERT_TRUE(entt::resolve("position"_hs));
|
||||
ASSERT_TRUE(entt::resolve("velocity"_hs));
|
||||
|
||||
ASSERT_EQ(entt::resolve<position>(), entt::resolve("position"_hs));
|
||||
ASSERT_EQ(entt::resolve<velocity>(), entt::resolve("velocity"_hs));
|
||||
|
||||
auto pos = entt::resolve("position"_hs).construct(42., 3.);
|
||||
auto vel = entt::resolve("velocity"_hs).construct();
|
||||
|
||||
ASSERT_TRUE(pos && vel);
|
||||
|
||||
ASSERT_EQ(pos.type().data("x"_hs).type(), entt::resolve<int>());
|
||||
ASSERT_NE(pos.type().data("y"_hs).get(pos).try_cast<int>(), nullptr);
|
||||
ASSERT_EQ(pos.type().data("x"_hs).get(pos).cast<int>(), 42);
|
||||
ASSERT_EQ(pos.type().data("y"_hs).get(pos).cast<int>(), 3);
|
||||
|
||||
ASSERT_EQ(vel.type().data("dx"_hs).type(), entt::resolve<double>());
|
||||
ASSERT_TRUE(vel.type().data("dy"_hs).get(vel).allow_cast<double>());
|
||||
ASSERT_EQ(vel.type().data("dx"_hs).get(vel).cast<double>(), 0.);
|
||||
ASSERT_EQ(vel.type().data("dy"_hs).get(vel).cast<double>(), 0.);
|
||||
|
||||
pos.reset();
|
||||
vel.reset();
|
||||
|
||||
ASSERT_EQ(wrap_int(42).type(), entt::resolve<int>());
|
||||
ASSERT_EQ(wrap_int(42).cast<int>(), 42);
|
||||
|
||||
tear_down();
|
||||
|
||||
ASSERT_FALSE(entt::resolve("position"_hs));
|
||||
ASSERT_FALSE(entt::resolve("velocity"_hs));
|
||||
}
|
14
test/lib/meta/types.h
Normal file
14
test/lib/meta/types.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef ENTT_LIB_META_TYPES_H
|
||||
#define ENTT_LIB_META_TYPES_H
|
||||
|
||||
struct position {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
struct velocity {
|
||||
double dx;
|
||||
double dy;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user