diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5e08ba2d6..3257f557b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -149,6 +149,7 @@ if(ENTT_BUILD_LIB) SETUP_PLUGIN_TEST(dispatcher_plugin) SETUP_PLUGIN_TEST(emitter_plugin) + SETUP_PLUGIN_TEST(locator_plugin) SETUP_PLUGIN_TEST(meta_plugin) SETUP_PLUGIN_TEST(registry_plugin) diff --git a/test/lib/locator_plugin/main.cpp b/test/lib/locator_plugin/main.cpp new file mode 100644 index 000000000..bbad40187 --- /dev/null +++ b/test/lib/locator_plugin/main.cpp @@ -0,0 +1,32 @@ +#define CR_HOST + +#include +#include +#include +#include "types.h" + +TEST(Lib, Locator) { + entt::locator::emplace().value = 42; + + ASSERT_EQ(entt::locator::value().value, 42); + + userdata ud{}; + ud.handle = entt::locator::handle(); + ud.value = 3; + + cr_plugin ctx; + ctx.userdata = &ud; + + cr_plugin_load(ctx, PLUGIN); + cr_plugin_update(ctx); + + ASSERT_EQ(entt::locator::value().value, ud.value); + + // service updates do not propagate across boundaries + entt::locator::emplace().value = 42; + cr_plugin_update(ctx); + + ASSERT_NE(entt::locator::value().value, ud.value); + + cr_plugin_close(ctx); +} diff --git a/test/lib/locator_plugin/plugin.cpp b/test/lib/locator_plugin/plugin.cpp new file mode 100644 index 000000000..fcccdfaa8 --- /dev/null +++ b/test/lib/locator_plugin/plugin.cpp @@ -0,0 +1,19 @@ +#include +#include +#include "types.h" + +CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) { + switch(operation) { + case CR_LOAD: + entt::locator::reset(static_cast(ctx->userdata)->handle); + break; + case CR_STEP: + entt::locator::value().value = static_cast(ctx->userdata)->value; + break; + case CR_UNLOAD: + case CR_CLOSE: + break; + } + + return 0; +} diff --git a/test/lib/locator_plugin/types.h b/test/lib/locator_plugin/types.h new file mode 100644 index 000000000..d91a31c24 --- /dev/null +++ b/test/lib/locator_plugin/types.h @@ -0,0 +1,16 @@ +#ifndef ENTT_LIB_LOCATOR_PLUGIN_TYPES_H +#define ENTT_LIB_LOCATOR_PLUGIN_TYPES_H + +#include + +struct service { + int value; +}; + +struct userdata { + using node_type = typename entt::locator::node_type; + node_type handle; + int value; +}; + +#endif