From ed7f09ab807e7bebf48fdd71f27f77d073c5da2a Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Sun, 5 Apr 2020 23:32:10 +0200 Subject: [PATCH] registry: updated tests (lib) --- test/CMakeLists.txt | 2 -- test/lib/registry/types.h | 6 ++-- test/lib/registry_plugin/main.cpp | 21 +++--------- test/lib/registry_plugin/plugin.cpp | 12 +++++-- test/lib/registry_plugin/proxy.h | 16 --------- test/lib/registry_plugin/types.h | 6 ---- test/lib/registry_plugin_std/main.cpp | 45 ------------------------- test/lib/registry_plugin_std/plugin.cpp | 26 -------------- test/lib/registry_plugin_std/proxy.h | 16 --------- test/lib/registry_plugin_std/types.h | 20 ----------- test/lib/registry_std/lib.cpp | 19 ----------- test/lib/registry_std/main.cpp | 27 --------------- test/lib/registry_std/types.h | 16 --------- 13 files changed, 18 insertions(+), 214 deletions(-) delete mode 100644 test/lib/registry_plugin/proxy.h delete mode 100644 test/lib/registry_plugin_std/main.cpp delete mode 100644 test/lib/registry_plugin_std/plugin.cpp delete mode 100644 test/lib/registry_plugin_std/proxy.h delete mode 100644 test/lib/registry_plugin_std/types.h delete mode 100644 test/lib/registry_std/lib.cpp delete mode 100644 test/lib/registry_std/main.cpp delete mode 100644 test/lib/registry_std/types.h diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b9be1fbf3..026763ed0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -116,7 +116,6 @@ if(BUILD_LIB) SETUP_LIB_TEST(registry) SETUP_LIB_TEST(meta_std ENTT_STANDARD_CPP) - SETUP_LIB_TEST(registry_std ENTT_STANDARD_CPP) SETUP_PLUGIN_TEST(dispatcher_plugin) SETUP_PLUGIN_TEST(emitter_plugin) @@ -124,7 +123,6 @@ if(BUILD_LIB) SETUP_PLUGIN_TEST(registry_plugin) SETUP_PLUGIN_TEST(meta_plugin_std ENTT_STANDARD_CPP) - SETUP_PLUGIN_TEST(registry_plugin_std ENTT_STANDARD_CPP) endif() # Test snapshot diff --git a/test/lib/registry/types.h b/test/lib/registry/types.h index 5fee0263d..6f126a84f 100644 --- a/test/lib/registry/types.h +++ b/test/lib/registry/types.h @@ -1,12 +1,14 @@ #ifndef ENTT_LIB_REGISTRY_TYPES_H #define ENTT_LIB_REGISTRY_TYPES_H -struct position { +#include + +struct ENTT_API position { int x; int y; }; -struct velocity { +struct ENTT_API velocity { double dx; double dy; }; diff --git a/test/lib/registry_plugin/main.cpp b/test/lib/registry_plugin/main.cpp index d59fb0211..d242c6342 100644 --- a/test/lib/registry_plugin/main.cpp +++ b/test/lib/registry_plugin/main.cpp @@ -2,27 +2,15 @@ #include #include +#include #include -#include "proxy.h" #include "types.h" -proxy::proxy(entt::registry &ref) - : registry{&ref} -{} - -void proxy::for_each(void(*cb)(position &, velocity &)) { - registry->view().each(cb); -} - -void proxy::assign(velocity vel) { - for(auto entity: registry->view()) { - registry->assign(entity, vel); - } -} +template +struct entt::type_index {}; TEST(Lib, Registry) { entt::registry registry; - proxy handler{registry}; for(auto i = 0; i < 3; ++i) { const auto entity = registry.create(); @@ -30,7 +18,7 @@ TEST(Lib, Registry) { } cr_plugin ctx; - ctx.userdata = &handler; + ctx.userdata = ®istry; cr_plugin_load(ctx, PLUGIN); cr_plugin_update(ctx); @@ -41,5 +29,6 @@ TEST(Lib, Registry) { ASSERT_EQ(position.y, entt::to_integral(entity) + 16); }); + registry = {}; cr_plugin_close(ctx); } diff --git a/test/lib/registry_plugin/plugin.cpp b/test/lib/registry_plugin/plugin.cpp index c6bab3102..902aded02 100644 --- a/test/lib/registry_plugin/plugin.cpp +++ b/test/lib/registry_plugin/plugin.cpp @@ -1,15 +1,21 @@ #include +#include +#include #include "types.h" +template +struct entt::type_index {}; + CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) { switch (operation) { case CR_STEP: [ctx]() { - auto *proxy = static_cast(ctx->userdata); + auto ®istry = *static_cast(ctx->userdata); - proxy->assign({1., 1.}); + const auto view = registry.view(); + registry.assign(view.begin(), view.end(), velocity{1., 1.}); - proxy->for_each([](auto &pos, auto &vel) { + registry.view().each([](auto &pos, auto &vel) { pos.x += static_cast(16 * vel.dx); pos.y += static_cast(16 * vel.dy); }); diff --git a/test/lib/registry_plugin/proxy.h b/test/lib/registry_plugin/proxy.h deleted file mode 100644 index 02532f232..000000000 --- a/test/lib/registry_plugin/proxy.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef ENTT_LIB_REGISTRY_PLUGIN_PROXY_H -#define ENTT_LIB_REGISTRY_PLUGIN_PROXY_H - -#include -#include "types.h" - -struct proxy: registry_proxy { - proxy(entt::registry &); - void for_each(void(*)(position &, velocity &)) override; - void assign(velocity) override; - -private: - entt::registry *registry; -}; - -#endif diff --git a/test/lib/registry_plugin/types.h b/test/lib/registry_plugin/types.h index 544106b06..2e0c14e42 100644 --- a/test/lib/registry_plugin/types.h +++ b/test/lib/registry_plugin/types.h @@ -11,10 +11,4 @@ struct velocity { double dy; }; -struct registry_proxy { - virtual ~registry_proxy() = default; - virtual void for_each(void(*)(position &, velocity &)) = 0; - virtual void assign(velocity) = 0; -}; - #endif diff --git a/test/lib/registry_plugin_std/main.cpp b/test/lib/registry_plugin_std/main.cpp deleted file mode 100644 index d59fb0211..000000000 --- a/test/lib/registry_plugin_std/main.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#define CR_HOST - -#include -#include -#include -#include "proxy.h" -#include "types.h" - -proxy::proxy(entt::registry &ref) - : registry{&ref} -{} - -void proxy::for_each(void(*cb)(position &, velocity &)) { - registry->view().each(cb); -} - -void proxy::assign(velocity vel) { - for(auto entity: registry->view()) { - registry->assign(entity, vel); - } -} - -TEST(Lib, Registry) { - entt::registry registry; - proxy handler{registry}; - - for(auto i = 0; i < 3; ++i) { - const auto entity = registry.create(); - registry.assign(entity, i, i); - } - - cr_plugin ctx; - ctx.userdata = &handler; - cr_plugin_load(ctx, PLUGIN); - cr_plugin_update(ctx); - - ASSERT_EQ(registry.size(), registry.size()); - - registry.view().each([](auto entity, auto &position) { - ASSERT_EQ(position.x, entt::to_integral(entity) + 16); - ASSERT_EQ(position.y, entt::to_integral(entity) + 16); - }); - - cr_plugin_close(ctx); -} diff --git a/test/lib/registry_plugin_std/plugin.cpp b/test/lib/registry_plugin_std/plugin.cpp deleted file mode 100644 index c6bab3102..000000000 --- a/test/lib/registry_plugin_std/plugin.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include "types.h" - -CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) { - switch (operation) { - case CR_STEP: - [ctx]() { - auto *proxy = static_cast(ctx->userdata); - - proxy->assign({1., 1.}); - - proxy->for_each([](auto &pos, auto &vel) { - pos.x += static_cast(16 * vel.dx); - pos.y += static_cast(16 * vel.dy); - }); - }(); - break; - case CR_CLOSE: - case CR_LOAD: - case CR_UNLOAD: - // nothing to do here, this is only a test. - break; - } - - return 0; -} diff --git a/test/lib/registry_plugin_std/proxy.h b/test/lib/registry_plugin_std/proxy.h deleted file mode 100644 index e7fca858f..000000000 --- a/test/lib/registry_plugin_std/proxy.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef ENTT_LIB_REGISTRY_PLUGIN_STD_PROXY_H -#define ENTT_LIB_REGISTRY_PLUGIN_STD_PROXY_H - -#include -#include "types.h" - -struct proxy: registry_proxy { - proxy(entt::registry &); - void for_each(void(*)(position &, velocity &)) override; - void assign(velocity) override; - -private: - entt::registry *registry; -}; - -#endif diff --git a/test/lib/registry_plugin_std/types.h b/test/lib/registry_plugin_std/types.h deleted file mode 100644 index 1bc7e1b8e..000000000 --- a/test/lib/registry_plugin_std/types.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef ENTT_LIB_REGISTRY_PLUGIN_STD_TYPES_H -#define ENTT_LIB_REGISTRY_PLUGIN_STD_TYPES_H - -struct position { - int x; - int y; -}; - -struct velocity { - double dx; - double dy; -}; - -struct registry_proxy { - virtual ~registry_proxy() = default; - virtual void for_each(void(*)(position &, velocity &)) = 0; - virtual void assign(velocity) = 0; -}; - -#endif diff --git a/test/lib/registry_std/lib.cpp b/test/lib/registry_std/lib.cpp deleted file mode 100644 index 581f34eec..000000000 --- a/test/lib/registry_std/lib.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include "types.h" - -ENTT_API void update_position(entt::registry ®istry) { - registry.view().each([](auto &pos, auto &vel) { - pos.x += static_cast(16 * vel.dx); - pos.y += static_cast(16 * vel.dy); - }); -} - -ENTT_API void assign_velocity(entt::registry ®istry) { - // forces the creation of the pool for the velocity component - registry.prepare(); - - for(auto entity: registry.view()) { - registry.assign(entity, 1., 1.); - } -} diff --git a/test/lib/registry_std/main.cpp b/test/lib/registry_std/main.cpp deleted file mode 100644 index 493a20551..000000000 --- a/test/lib/registry_std/main.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include -#include -#include "types.h" - -ENTT_API void update_position(entt::registry &); -ENTT_API void assign_velocity(entt::registry &); - -TEST(Lib, Registry) { - entt::registry registry; - - for(auto i = 0; i < 3; ++i) { - const auto entity = registry.create(); - registry.assign(entity, i, i); - } - - assign_velocity(registry); - update_position(registry); - - ASSERT_EQ(registry.size(), registry.size()); - - registry.view().each([](auto entity, auto &position) { - ASSERT_EQ(position.x, entt::to_integral(entity) + 16); - ASSERT_EQ(position.y, entt::to_integral(entity) + 16); - }); -} diff --git a/test/lib/registry_std/types.h b/test/lib/registry_std/types.h deleted file mode 100644 index 159c16fd9..000000000 --- a/test/lib/registry_std/types.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef ENTT_LIB_REGISTRY_STD_TYPES_H -#define ENTT_LIB_REGISTRY_STD_TYPES_H - -#include - -struct ENTT_API position { - int x; - int y; -}; - -struct ENTT_API velocity { - double dx; - double dy; -}; - -#endif