Initial commit - restart from existing code
This commit is contained in:
28
lib/All/entt/test/lib/dispatcher/plugin/main.cpp
Normal file
28
lib/All/entt/test/lib/dispatcher/plugin/main.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#define CR_HOST
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cr.h>
|
||||
#include <entt/signal/dispatcher.hpp>
|
||||
#include <entt/signal/sigh.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/listener.h"
|
||||
|
||||
TEST(Lib, Dispatcher) {
|
||||
entt::dispatcher dispatcher;
|
||||
test::listener<test::boxed_int> listener;
|
||||
|
||||
ASSERT_EQ(listener.value, 0);
|
||||
|
||||
dispatcher.sink<test::boxed_int>().connect<&test::listener<test::boxed_int>::on>(listener);
|
||||
|
||||
cr_plugin ctx;
|
||||
cr_plugin_load(ctx, PLUGIN);
|
||||
|
||||
ctx.userdata = &dispatcher;
|
||||
cr_plugin_update(ctx);
|
||||
|
||||
ASSERT_EQ(listener.value, 4);
|
||||
|
||||
dispatcher = {};
|
||||
cr_plugin_close(ctx);
|
||||
}
|
||||
20
lib/All/entt/test/lib/dispatcher/plugin/plugin.cpp
Normal file
20
lib/All/entt/test/lib/dispatcher/plugin/plugin.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <cr.h>
|
||||
#include <entt/signal/dispatcher.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/empty.h"
|
||||
|
||||
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
|
||||
switch(operation) {
|
||||
case CR_STEP:
|
||||
static_cast<entt::dispatcher *>(ctx->userdata)->trigger<test::empty>();
|
||||
static_cast<entt::dispatcher *>(ctx->userdata)->trigger(test::boxed_int{4});
|
||||
break;
|
||||
case CR_CLOSE:
|
||||
case CR_LOAD:
|
||||
case CR_UNLOAD:
|
||||
// nothing to do here, this is only a test.
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
9
lib/All/entt/test/lib/dispatcher/shared/lib.cpp
Normal file
9
lib/All/entt/test/lib/dispatcher/shared/lib.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <entt/core/attribute.h>
|
||||
#include <entt/signal/dispatcher.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/empty.h"
|
||||
|
||||
ENTT_API void trigger(entt::dispatcher &dispatcher) {
|
||||
dispatcher.trigger<test::empty>();
|
||||
dispatcher.trigger(test::boxed_int{2});
|
||||
}
|
||||
21
lib/All/entt/test/lib/dispatcher/shared/main.cpp
Normal file
21
lib/All/entt/test/lib/dispatcher/shared/main.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/core/attribute.h>
|
||||
#include <entt/core/utility.hpp>
|
||||
#include <entt/signal/dispatcher.hpp>
|
||||
#include <entt/signal/sigh.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/listener.h"
|
||||
|
||||
ENTT_API void trigger(entt::dispatcher &);
|
||||
|
||||
TEST(Lib, Dispatcher) {
|
||||
entt::dispatcher dispatcher;
|
||||
test::listener<test::boxed_int> listener;
|
||||
|
||||
ASSERT_EQ(listener.value, 0);
|
||||
|
||||
dispatcher.sink<test::boxed_int>().connect<entt::overload<void(test::boxed_int)>(&test::listener<test::boxed_int>::on)>(listener);
|
||||
trigger(dispatcher);
|
||||
|
||||
ASSERT_EQ(listener.value, 2);
|
||||
}
|
||||
30
lib/All/entt/test/lib/emitter/plugin/main.cpp
Normal file
30
lib/All/entt/test/lib/emitter/plugin/main.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#define CR_HOST
|
||||
|
||||
#include <functional>
|
||||
#include <gtest/gtest.h>
|
||||
#include <cr.h>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/emitter.h"
|
||||
|
||||
TEST(Lib, Emitter) {
|
||||
test::emitter emitter;
|
||||
int value{};
|
||||
|
||||
ASSERT_EQ(value, 0);
|
||||
|
||||
emitter.on<test::boxed_int>([&](test::boxed_int msg, test::emitter &owner) {
|
||||
value = msg.value;
|
||||
owner.erase<test::boxed_int>();
|
||||
});
|
||||
|
||||
cr_plugin ctx;
|
||||
cr_plugin_load(ctx, PLUGIN);
|
||||
|
||||
ctx.userdata = &emitter;
|
||||
cr_plugin_update(ctx);
|
||||
|
||||
ASSERT_EQ(value, 4);
|
||||
|
||||
emitter = {};
|
||||
cr_plugin_close(ctx);
|
||||
}
|
||||
21
lib/All/entt/test/lib/emitter/plugin/plugin.cpp
Normal file
21
lib/All/entt/test/lib/emitter/plugin/plugin.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <cr.h>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/emitter.h"
|
||||
#include "../../../common/empty.h"
|
||||
|
||||
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
|
||||
switch(operation) {
|
||||
case CR_STEP:
|
||||
static_cast<test::emitter *>(ctx->userdata)->publish(test::empty{});
|
||||
static_cast<test::emitter *>(ctx->userdata)->publish(test::boxed_int{4});
|
||||
static_cast<test::emitter *>(ctx->userdata)->publish(test::boxed_int{3});
|
||||
break;
|
||||
case CR_CLOSE:
|
||||
case CR_LOAD:
|
||||
case CR_UNLOAD:
|
||||
// nothing to do here, this is only a test.
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
lib/All/entt/test/lib/emitter/shared/lib.cpp
Normal file
10
lib/All/entt/test/lib/emitter/shared/lib.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <entt/core/attribute.h>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/emitter.h"
|
||||
#include "../../../common/empty.h"
|
||||
|
||||
ENTT_API void emit(test::emitter &emitter) {
|
||||
emitter.publish(test::empty{});
|
||||
emitter.publish(test::boxed_int{2});
|
||||
emitter.publish(test::boxed_int{3});
|
||||
}
|
||||
23
lib/All/entt/test/lib/emitter/shared/main.cpp
Normal file
23
lib/All/entt/test/lib/emitter/shared/main.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <functional>
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/core/attribute.h>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/emitter.h"
|
||||
|
||||
ENTT_API void emit(test::emitter &);
|
||||
|
||||
TEST(Lib, Emitter) {
|
||||
test::emitter emitter;
|
||||
int value{};
|
||||
|
||||
ASSERT_EQ(value, 0);
|
||||
|
||||
emitter.on<test::boxed_int>([&](test::boxed_int msg, test::emitter &owner) {
|
||||
value = msg.value;
|
||||
owner.erase<test::boxed_int>();
|
||||
});
|
||||
|
||||
emit(emitter);
|
||||
|
||||
ASSERT_EQ(value, 2);
|
||||
}
|
||||
31
lib/All/entt/test/lib/locator/plugin/main.cpp
Normal file
31
lib/All/entt/test/lib/locator/plugin/main.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#define CR_HOST
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cr.h>
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "userdata.h"
|
||||
|
||||
TEST(Lib, Locator) {
|
||||
entt::locator<test::boxed_int>::emplace().value = 4;
|
||||
|
||||
ASSERT_EQ(entt::locator<test::boxed_int>::value().value, 4);
|
||||
|
||||
userdata ud{entt::locator<test::boxed_int>::handle(), 3};
|
||||
|
||||
cr_plugin ctx;
|
||||
ctx.userdata = &ud;
|
||||
|
||||
cr_plugin_load(ctx, PLUGIN);
|
||||
cr_plugin_update(ctx);
|
||||
|
||||
ASSERT_EQ(entt::locator<test::boxed_int>::value().value, ud.value);
|
||||
|
||||
// service updates do not propagate across boundaries
|
||||
entt::locator<test::boxed_int>::emplace().value = 4;
|
||||
cr_plugin_update(ctx);
|
||||
|
||||
ASSERT_NE(entt::locator<test::boxed_int>::value().value, ud.value);
|
||||
|
||||
cr_plugin_close(ctx);
|
||||
}
|
||||
20
lib/All/entt/test/lib/locator/plugin/plugin.cpp
Normal file
20
lib/All/entt/test/lib/locator/plugin/plugin.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <cr.h>
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "userdata.h"
|
||||
|
||||
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
|
||||
switch(operation) {
|
||||
case CR_LOAD:
|
||||
entt::locator<test::boxed_int>::reset(static_cast<userdata *>(ctx->userdata)->handle);
|
||||
break;
|
||||
case CR_STEP:
|
||||
entt::locator<test::boxed_int>::value().value = static_cast<userdata *>(ctx->userdata)->value;
|
||||
break;
|
||||
case CR_UNLOAD:
|
||||
case CR_CLOSE:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
12
lib/All/entt/test/lib/locator/plugin/userdata.h
Normal file
12
lib/All/entt/test/lib/locator/plugin/userdata.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef ENTT_LIB_LOCATOR_PLUGIN_USERDATA_H
|
||||
#define ENTT_LIB_LOCATOR_PLUGIN_USERDATA_H
|
||||
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
|
||||
struct userdata {
|
||||
entt::locator<test::boxed_int>::node_type handle{};
|
||||
int value{};
|
||||
};
|
||||
|
||||
#endif
|
||||
11
lib/All/entt/test/lib/locator/shared/lib.cpp
Normal file
11
lib/All/entt/test/lib/locator/shared/lib.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <entt/core/attribute.h>
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
|
||||
ENTT_API void set_up(const entt::locator<test::boxed_int>::node_type &handle) {
|
||||
entt::locator<test::boxed_int>::reset(handle);
|
||||
}
|
||||
|
||||
ENTT_API void use_service(int value) {
|
||||
entt::locator<test::boxed_int>::value().value = value;
|
||||
}
|
||||
24
lib/All/entt/test/lib/locator/shared/main.cpp
Normal file
24
lib/All/entt/test/lib/locator/shared/main.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/core/attribute.h>
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
|
||||
ENTT_API void set_up(const entt::locator<test::boxed_int>::node_type &);
|
||||
ENTT_API void use_service(int);
|
||||
|
||||
TEST(Lib, Locator) {
|
||||
entt::locator<test::boxed_int>::emplace().value = 4;
|
||||
|
||||
ASSERT_EQ(entt::locator<test::boxed_int>::value().value, 4);
|
||||
|
||||
set_up(entt::locator<test::boxed_int>::handle());
|
||||
use_service(3);
|
||||
|
||||
ASSERT_EQ(entt::locator<test::boxed_int>::value().value, 3);
|
||||
|
||||
// service updates do not propagate across boundaries
|
||||
entt::locator<test::boxed_int>::emplace().value = 4;
|
||||
use_service(3);
|
||||
|
||||
ASSERT_EQ(entt::locator<test::boxed_int>::value().value, 4);
|
||||
}
|
||||
50
lib/All/entt/test/lib/meta/plugin/main.cpp
Normal file
50
lib/All/entt/test/lib/meta/plugin/main.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#define CR_HOST
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cr.h>
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include <entt/meta/context.hpp>
|
||||
#include <entt/meta/meta.hpp>
|
||||
#include <entt/meta/resolve.hpp>
|
||||
#include "userdata.h"
|
||||
|
||||
TEST(Lib, Meta) {
|
||||
using namespace entt::literals;
|
||||
|
||||
ASSERT_FALSE(entt::resolve("boxed_int"_hs));
|
||||
|
||||
userdata ud{entt::locator<entt::meta_ctx>::handle(), entt::meta_any{}};
|
||||
|
||||
cr_plugin ctx;
|
||||
ctx.userdata = &ud;
|
||||
|
||||
cr_plugin_load(ctx, PLUGIN);
|
||||
cr_plugin_update(ctx);
|
||||
|
||||
ASSERT_TRUE(entt::resolve("boxed_int"_hs));
|
||||
ASSERT_TRUE(entt::resolve("empty"_hs));
|
||||
|
||||
auto boxed_int = entt::resolve("boxed_int"_hs).construct(4.);
|
||||
auto empty = entt::resolve("empty"_hs).construct();
|
||||
|
||||
ASSERT_TRUE(boxed_int);
|
||||
ASSERT_TRUE(empty);
|
||||
|
||||
ASSERT_EQ(boxed_int.type().data("value"_hs).type(), entt::resolve<int>());
|
||||
ASSERT_NE(boxed_int.get("value"_hs).try_cast<int>(), nullptr);
|
||||
ASSERT_EQ(boxed_int.get("value"_hs).cast<int>(), 4);
|
||||
|
||||
ASSERT_EQ(ud.any.type(), entt::resolve<int>());
|
||||
ASSERT_EQ(ud.any.cast<int>(), 4);
|
||||
|
||||
// these objects have been initialized from a different context
|
||||
boxed_int.emplace<void>();
|
||||
empty.emplace<void>();
|
||||
ud.any.emplace<void>();
|
||||
|
||||
cr_plugin_close(ctx);
|
||||
|
||||
ASSERT_FALSE(entt::resolve("boxed_int"_hs));
|
||||
ASSERT_FALSE(entt::resolve("empty"_hs));
|
||||
}
|
||||
49
lib/All/entt/test/lib/meta/plugin/plugin.cpp
Normal file
49
lib/All/entt/test/lib/meta/plugin/plugin.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <cr.h>
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include <entt/meta/context.hpp>
|
||||
#include <entt/meta/factory.hpp>
|
||||
#include <entt/meta/meta.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/empty.h"
|
||||
#include "userdata.h"
|
||||
|
||||
test::boxed_int create_boxed_int(int value) {
|
||||
return test::boxed_int{value};
|
||||
}
|
||||
|
||||
void set_up() {
|
||||
using namespace entt::literals;
|
||||
|
||||
entt::meta_factory<test::boxed_int>{}
|
||||
.type("boxed_int"_hs)
|
||||
.ctor<&create_boxed_int>()
|
||||
.data<&test::boxed_int::value>("value"_hs);
|
||||
|
||||
entt::meta_factory<test::empty>{}
|
||||
.type("empty"_hs)
|
||||
.ctor<>();
|
||||
}
|
||||
|
||||
void tear_down() {
|
||||
entt::meta_reset<test::boxed_int>();
|
||||
entt::meta_reset<test::empty>();
|
||||
}
|
||||
|
||||
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
|
||||
switch(operation) {
|
||||
case CR_LOAD:
|
||||
entt::locator<entt::meta_ctx>::reset(static_cast<userdata *>(ctx->userdata)->ctx);
|
||||
set_up();
|
||||
break;
|
||||
case CR_STEP:
|
||||
static_cast<userdata *>(ctx->userdata)->any = 4;
|
||||
break;
|
||||
case CR_UNLOAD:
|
||||
case CR_CLOSE:
|
||||
tear_down();
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
13
lib/All/entt/test/lib/meta/plugin/userdata.h
Normal file
13
lib/All/entt/test/lib/meta/plugin/userdata.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef ENTT_LIB_META_PLUGIN_USERDATA_H
|
||||
#define ENTT_LIB_META_PLUGIN_USERDATA_H
|
||||
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include <entt/meta/context.hpp>
|
||||
#include <entt/meta/meta.hpp>
|
||||
|
||||
struct userdata {
|
||||
entt::locator<entt::meta_ctx>::node_type ctx{};
|
||||
entt::meta_any any{};
|
||||
};
|
||||
|
||||
#endif
|
||||
51
lib/All/entt/test/lib/meta/plugin_std/main.cpp
Normal file
51
lib/All/entt/test/lib/meta/plugin_std/main.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#define CR_HOST
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cr.h>
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include <entt/meta/context.hpp>
|
||||
#include <entt/meta/meta.hpp>
|
||||
#include <entt/meta/resolve.hpp>
|
||||
#include "userdata.h"
|
||||
|
||||
TEST(Lib, Meta) {
|
||||
using namespace entt::literals;
|
||||
|
||||
ASSERT_FALSE(entt::resolve("boxed_int"_hs));
|
||||
|
||||
userdata ud{};
|
||||
ud.ctx = entt::locator<entt::meta_ctx>::handle();
|
||||
|
||||
cr_plugin ctx;
|
||||
ctx.userdata = &ud;
|
||||
|
||||
cr_plugin_load(ctx, PLUGIN);
|
||||
cr_plugin_update(ctx);
|
||||
|
||||
ASSERT_TRUE(entt::resolve("boxed_int"_hs));
|
||||
ASSERT_TRUE(entt::resolve("empty"_hs));
|
||||
|
||||
auto boxed_int = entt::resolve("boxed_int"_hs).construct(4.);
|
||||
auto empty = entt::resolve("empty"_hs).construct();
|
||||
|
||||
ASSERT_TRUE(boxed_int);
|
||||
ASSERT_TRUE(empty);
|
||||
|
||||
ASSERT_EQ(boxed_int.type().data("value"_hs).type(), entt::resolve<int>());
|
||||
ASSERT_NE(boxed_int.get("value"_hs).try_cast<int>(), nullptr);
|
||||
ASSERT_EQ(boxed_int.get("value"_hs).cast<int>(), 4);
|
||||
|
||||
ASSERT_EQ(ud.any.type(), entt::resolve<int>());
|
||||
ASSERT_EQ(ud.any.cast<int>(), 4);
|
||||
|
||||
// these objects have been initialized from a different context
|
||||
boxed_int.emplace<void>();
|
||||
empty.emplace<void>();
|
||||
ud.any.emplace<void>();
|
||||
|
||||
cr_plugin_close(ctx);
|
||||
|
||||
ASSERT_FALSE(entt::resolve("boxed_int"_hs));
|
||||
ASSERT_FALSE(entt::resolve("empty"_hs));
|
||||
}
|
||||
49
lib/All/entt/test/lib/meta/plugin_std/plugin.cpp
Normal file
49
lib/All/entt/test/lib/meta/plugin_std/plugin.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <cr.h>
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include <entt/meta/context.hpp>
|
||||
#include <entt/meta/factory.hpp>
|
||||
#include <entt/meta/meta.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/empty.h"
|
||||
#include "userdata.h"
|
||||
|
||||
test::boxed_int create_boxed_int(int value) {
|
||||
return test::boxed_int{value};
|
||||
}
|
||||
|
||||
void set_up() {
|
||||
using namespace entt::literals;
|
||||
|
||||
entt::meta_factory<test::boxed_int>{}
|
||||
.type("boxed_int"_hs)
|
||||
.ctor<&create_boxed_int>()
|
||||
.data<&test::boxed_int::value>("value"_hs);
|
||||
|
||||
entt::meta_factory<test::empty>{}
|
||||
.type("empty"_hs)
|
||||
.ctor<>();
|
||||
}
|
||||
|
||||
void tear_down() {
|
||||
entt::meta_reset<test::boxed_int>();
|
||||
entt::meta_reset<test::empty>();
|
||||
}
|
||||
|
||||
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
|
||||
switch(operation) {
|
||||
case CR_LOAD:
|
||||
entt::locator<entt::meta_ctx>::reset(static_cast<userdata *>(ctx->userdata)->ctx);
|
||||
set_up();
|
||||
break;
|
||||
case CR_STEP:
|
||||
static_cast<userdata *>(ctx->userdata)->any = 4;
|
||||
break;
|
||||
case CR_UNLOAD:
|
||||
case CR_CLOSE:
|
||||
tear_down();
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
32
lib/All/entt/test/lib/meta/plugin_std/userdata.h
Normal file
32
lib/All/entt/test/lib/meta/plugin_std/userdata.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef ENTT_LIB_META_PLUGIN_STD_USERDATA_H
|
||||
#define ENTT_LIB_META_PLUGIN_STD_USERDATA_H
|
||||
|
||||
#include <type_traits>
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
#include <entt/core/type_info.hpp>
|
||||
#include <entt/meta/context.hpp>
|
||||
#include <entt/meta/meta.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/empty.h"
|
||||
|
||||
#define ASSIGN_TYPE_ID(clazz) \
|
||||
template<> \
|
||||
struct entt::type_hash<clazz> { \
|
||||
static constexpr entt::id_type value() noexcept { \
|
||||
return entt::basic_hashed_string<std::remove_const_t<std::remove_pointer_t<std::decay_t<decltype(#clazz)>>>>{#clazz}; \
|
||||
} \
|
||||
}
|
||||
|
||||
struct userdata {
|
||||
entt::locator<entt::meta_ctx>::node_type ctx{};
|
||||
entt::meta_any any{};
|
||||
};
|
||||
|
||||
ASSIGN_TYPE_ID(void);
|
||||
ASSIGN_TYPE_ID(std::size_t);
|
||||
ASSIGN_TYPE_ID(test::boxed_int);
|
||||
ASSIGN_TYPE_ID(test::empty);
|
||||
ASSIGN_TYPE_ID(double);
|
||||
ASSIGN_TYPE_ID(int);
|
||||
|
||||
#endif
|
||||
40
lib/All/entt/test/lib/meta/shared/lib.cpp
Normal file
40
lib/All/entt/test/lib/meta/shared/lib.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <entt/core/attribute.h>
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include <entt/meta/context.hpp>
|
||||
#include <entt/meta/factory.hpp>
|
||||
#include <entt/meta/meta.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/empty.h"
|
||||
|
||||
test::boxed_int create_boxed_int(int value) {
|
||||
return test::boxed_int{value};
|
||||
}
|
||||
|
||||
ENTT_API void share(const 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_factory<test::boxed_int>{}
|
||||
.type("boxed_int"_hs)
|
||||
.ctor<&create_boxed_int>()
|
||||
.data<&test::boxed_int::value>("value"_hs);
|
||||
|
||||
entt::meta_factory<test::empty>{}
|
||||
.type("empty"_hs)
|
||||
.ctor<>();
|
||||
|
||||
static_cast<void>(entt::meta_factory<double>{});
|
||||
}
|
||||
|
||||
ENTT_API void tear_down() {
|
||||
entt::meta_reset<test::boxed_int>();
|
||||
entt::meta_reset<test::empty>();
|
||||
}
|
||||
|
||||
ENTT_API entt::meta_any wrap_int(int value) {
|
||||
return value;
|
||||
}
|
||||
51
lib/All/entt/test/lib/meta/shared/main.cpp
Normal file
51
lib/All/entt/test/lib/meta/shared/main.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/core/attribute.h>
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include <entt/meta/context.hpp>
|
||||
#include <entt/meta/meta.hpp>
|
||||
#include <entt/meta/resolve.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/empty.h"
|
||||
|
||||
ENTT_API void share(const 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("boxed_int"_hs));
|
||||
ASSERT_FALSE(entt::resolve("empty"_hs));
|
||||
|
||||
share(entt::locator<entt::meta_ctx>::handle());
|
||||
set_up();
|
||||
|
||||
ASSERT_TRUE(entt::resolve("boxed_int"_hs));
|
||||
ASSERT_TRUE(entt::resolve("empty"_hs));
|
||||
|
||||
ASSERT_EQ(entt::resolve<test::boxed_int>(), entt::resolve("boxed_int"_hs));
|
||||
ASSERT_EQ(entt::resolve<test::empty>(), entt::resolve("empty"_hs));
|
||||
|
||||
auto boxed_int = entt::resolve("boxed_int"_hs).construct(4.);
|
||||
auto empty = entt::resolve("empty"_hs).construct();
|
||||
|
||||
ASSERT_TRUE(boxed_int);
|
||||
ASSERT_TRUE(empty);
|
||||
|
||||
ASSERT_EQ(boxed_int.type().data("value"_hs).type(), entt::resolve<int>());
|
||||
ASSERT_NE(boxed_int.get("value"_hs).try_cast<int>(), nullptr);
|
||||
ASSERT_EQ(boxed_int.get("value"_hs).cast<int>(), 4);
|
||||
|
||||
boxed_int.reset();
|
||||
empty.reset();
|
||||
|
||||
ASSERT_EQ(wrap_int(4).type(), entt::resolve<int>());
|
||||
ASSERT_EQ(wrap_int(4).cast<int>(), 4);
|
||||
|
||||
tear_down();
|
||||
|
||||
ASSERT_FALSE(entt::resolve("boxed_int"_hs));
|
||||
ASSERT_FALSE(entt::resolve("empty"_hs));
|
||||
}
|
||||
36
lib/All/entt/test/lib/registry/plugin/main.cpp
Normal file
36
lib/All/entt/test/lib/registry/plugin/main.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#define CR_HOST
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cr.h>
|
||||
#include <entt/entity/entity.hpp>
|
||||
#include <entt/entity/mixin.hpp>
|
||||
#include <entt/entity/registry.hpp>
|
||||
#include <entt/entity/view.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/empty.h"
|
||||
|
||||
TEST(Lib, Registry) {
|
||||
constexpr auto count = 3;
|
||||
entt::registry registry;
|
||||
|
||||
for(auto i = 0; i < count; ++i) {
|
||||
const auto entity = registry.create();
|
||||
registry.emplace<test::boxed_int>(entity, i);
|
||||
}
|
||||
|
||||
cr_plugin ctx;
|
||||
cr_plugin_load(ctx, PLUGIN);
|
||||
|
||||
ctx.userdata = ®istry;
|
||||
cr_plugin_update(ctx);
|
||||
|
||||
ASSERT_EQ(registry.storage<test::boxed_int>().size(), registry.storage<test::empty>().size());
|
||||
ASSERT_EQ(registry.storage<test::boxed_int>().size(), registry.storage<entt::entity>().size());
|
||||
|
||||
registry.view<test::boxed_int>().each([count](auto entity, auto &elem) {
|
||||
ASSERT_EQ(elem.value, entt::to_integral(entity) + count);
|
||||
});
|
||||
|
||||
registry = {};
|
||||
cr_plugin_close(ctx);
|
||||
}
|
||||
34
lib/All/entt/test/lib/registry/plugin/plugin.cpp
Normal file
34
lib/All/entt/test/lib/registry/plugin/plugin.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <cr.h>
|
||||
#include <entt/entity/mixin.hpp>
|
||||
#include <entt/entity/registry.hpp>
|
||||
#include <entt/entity/view.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/empty.h"
|
||||
|
||||
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
|
||||
constexpr auto count = 3;
|
||||
|
||||
switch(operation) {
|
||||
case CR_STEP: {
|
||||
// forces things to break
|
||||
auto ®istry = *static_cast<entt::registry *>(ctx->userdata);
|
||||
|
||||
// forces the creation of the pool for the empty type
|
||||
static_cast<void>(registry.storage<test::empty>());
|
||||
|
||||
const auto view = registry.view<test::boxed_int>();
|
||||
registry.insert(view.begin(), view.end(), test::empty{});
|
||||
|
||||
registry.view<test::boxed_int, test::empty>().each([cnt = count](test::boxed_int &elem) {
|
||||
elem.value += cnt;
|
||||
});
|
||||
} break;
|
||||
case CR_CLOSE:
|
||||
case CR_LOAD:
|
||||
case CR_UNLOAD:
|
||||
// nothing to do here, this is only a test.
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
22
lib/All/entt/test/lib/registry/shared/lib.cpp
Normal file
22
lib/All/entt/test/lib/registry/shared/lib.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <entt/core/attribute.h>
|
||||
#include <entt/entity/mixin.hpp>
|
||||
#include <entt/entity/registry.hpp>
|
||||
#include <entt/entity/view.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/empty.h"
|
||||
|
||||
template class entt::basic_registry<entt::entity>;
|
||||
|
||||
ENTT_API void update(entt::registry ®istry, int value) {
|
||||
registry.view<test::boxed_int, test::empty>().each([value](auto &elem) {
|
||||
elem.value += value;
|
||||
});
|
||||
}
|
||||
|
||||
ENTT_API void insert(entt::registry ®istry) {
|
||||
// forces the creation of the pool for the empty type
|
||||
static_cast<void>(registry.storage<test::empty>());
|
||||
|
||||
const auto view = registry.view<test::boxed_int>();
|
||||
registry.insert<test::empty>(view.begin(), view.end());
|
||||
}
|
||||
30
lib/All/entt/test/lib/registry/shared/main.cpp
Normal file
30
lib/All/entt/test/lib/registry/shared/main.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/core/attribute.h>
|
||||
#include <entt/entity/entity.hpp>
|
||||
#include <entt/entity/mixin.hpp>
|
||||
#include <entt/entity/registry.hpp>
|
||||
#include <entt/entity/view.hpp>
|
||||
#include "../../../common/boxed_type.h"
|
||||
#include "../../../common/empty.h"
|
||||
|
||||
ENTT_API void update(entt::registry &, int);
|
||||
ENTT_API void insert(entt::registry &);
|
||||
|
||||
TEST(Lib, Registry) {
|
||||
constexpr auto count = 3;
|
||||
entt::registry registry;
|
||||
|
||||
for(auto i = 0; i < count; ++i) {
|
||||
const auto entity = registry.create();
|
||||
registry.emplace<test::boxed_int>(entity, i);
|
||||
}
|
||||
|
||||
insert(registry);
|
||||
update(registry, count);
|
||||
|
||||
ASSERT_EQ(registry.storage<test::boxed_int>().size(), registry.storage<test::empty>().size());
|
||||
|
||||
registry.view<test::boxed_int>().each([count](auto entity, auto &elem) {
|
||||
ASSERT_EQ(elem.value, static_cast<int>(entt::to_integral(entity) + count));
|
||||
});
|
||||
}
|
||||
19
lib/All/entt/test/lib/view/plugin/main.cpp
Normal file
19
lib/All/entt/test/lib/view/plugin/main.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#define CR_HOST
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cr.h>
|
||||
#include "../types.h"
|
||||
|
||||
TEST(Lib, View) {
|
||||
view_type view{};
|
||||
|
||||
cr_plugin ctx;
|
||||
cr_plugin_load(ctx, PLUGIN);
|
||||
|
||||
ctx.userdata = &view;
|
||||
cr_plugin_update(ctx);
|
||||
|
||||
ASSERT_EQ(ctx.userdata, nullptr);
|
||||
|
||||
cr_plugin_close(ctx);
|
||||
}
|
||||
19
lib/All/entt/test/lib/view/plugin/plugin.cpp
Normal file
19
lib/All/entt/test/lib/view/plugin/plugin.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <cr.h>
|
||||
#include "../types.h"
|
||||
|
||||
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
|
||||
switch(operation) {
|
||||
case CR_STEP: {
|
||||
// unset filter fallback should not be accessible across boundaries
|
||||
auto &view = *static_cast<view_type *>(ctx->userdata);
|
||||
ctx->userdata = view.storage<1u>();
|
||||
} break;
|
||||
case CR_CLOSE:
|
||||
case CR_LOAD:
|
||||
case CR_UNLOAD:
|
||||
// nothing to do here, this is only a test.
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
lib/All/entt/test/lib/view/shared/lib.cpp
Normal file
10
lib/All/entt/test/lib/view/shared/lib.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <entt/core/attribute.h>
|
||||
#include "../types.h"
|
||||
|
||||
ENTT_API const void *filter(const view_type &view) {
|
||||
// forces the creation of all symbols for the view type
|
||||
[[maybe_unused]] const view_type other{};
|
||||
|
||||
// unset filter fallback should not be accessible across boundaries
|
||||
return view.storage<1u>();
|
||||
}
|
||||
12
lib/All/entt/test/lib/view/shared/main.cpp
Normal file
12
lib/All/entt/test/lib/view/shared/main.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/core/attribute.h>
|
||||
#include "../types.h"
|
||||
|
||||
ENTT_API const void *filter(const view_type &);
|
||||
|
||||
TEST(Lib, View) {
|
||||
view_type view{};
|
||||
const void *storage = filter(view);
|
||||
|
||||
ASSERT_EQ(storage, nullptr);
|
||||
}
|
||||
10
lib/All/entt/test/lib/view/types.h
Normal file
10
lib/All/entt/test/lib/view/types.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef ENTT_LIB_VIEW_TYPE_H
|
||||
#define ENTT_LIB_VIEW_TYPE_H
|
||||
|
||||
#include <entt/entity/storage.hpp>
|
||||
#include <entt/entity/view.hpp>
|
||||
#include "../../common/empty.h"
|
||||
|
||||
using view_type = entt::basic_view<entt::get_t<entt::storage<test::empty>>, entt::exclude_t<entt::storage<test::empty>>>;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user