Squashed 'external/entt/entt/' content from commit fef92113
git-subtree-dir: external/entt/entt git-subtree-split: fef921132cae7588213d0f9bcd2fb9c8ffd8b7fc
This commit is contained in:
32
test/lib/locator_plugin/main.cpp
Normal file
32
test/lib/locator_plugin/main.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#define CR_HOST
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cr.h>
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include "types.h"
|
||||
|
||||
TEST(Lib, Locator) {
|
||||
entt::locator<service>::emplace().value = 42;
|
||||
|
||||
ASSERT_EQ(entt::locator<service>::value().value, 42);
|
||||
|
||||
userdata ud{};
|
||||
ud.handle = entt::locator<service>::handle();
|
||||
ud.value = 3;
|
||||
|
||||
cr_plugin ctx;
|
||||
ctx.userdata = &ud;
|
||||
|
||||
cr_plugin_load(ctx, PLUGIN);
|
||||
cr_plugin_update(ctx);
|
||||
|
||||
ASSERT_EQ(entt::locator<service>::value().value, ud.value);
|
||||
|
||||
// service updates do not propagate across boundaries
|
||||
entt::locator<service>::emplace().value = 42;
|
||||
cr_plugin_update(ctx);
|
||||
|
||||
ASSERT_NE(entt::locator<service>::value().value, ud.value);
|
||||
|
||||
cr_plugin_close(ctx);
|
||||
}
|
19
test/lib/locator_plugin/plugin.cpp
Normal file
19
test/lib/locator_plugin/plugin.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include <cr.h>
|
||||
#include <entt/locator/locator.hpp>
|
||||
#include "types.h"
|
||||
|
||||
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
|
||||
switch(operation) {
|
||||
case CR_LOAD:
|
||||
entt::locator<service>::reset(static_cast<userdata *>(ctx->userdata)->handle);
|
||||
break;
|
||||
case CR_STEP:
|
||||
entt::locator<service>::value().value = static_cast<userdata *>(ctx->userdata)->value;
|
||||
break;
|
||||
case CR_UNLOAD:
|
||||
case CR_CLOSE:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
16
test/lib/locator_plugin/types.h
Normal file
16
test/lib/locator_plugin/types.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef ENTT_LIB_LOCATOR_PLUGIN_TYPES_H
|
||||
#define ENTT_LIB_LOCATOR_PLUGIN_TYPES_H
|
||||
|
||||
#include <entt/locator/locator.hpp>
|
||||
|
||||
struct service {
|
||||
int value;
|
||||
};
|
||||
|
||||
struct userdata {
|
||||
using node_type = typename entt::locator<service>::node_type;
|
||||
node_type handle;
|
||||
int value;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user