Michele Caini 3 лет назад
Родитель
Сommit
6650071d24
4 измененных файлов с 44 добавлено и 0 удалено
  1. 1 0
      test/CMakeLists.txt
  2. 11 0
      test/lib/locator/lib.cpp
  3. 24 0
      test/lib/locator/main.cpp
  4. 8 0
      test/lib/locator/types.h

+ 1 - 0
test/CMakeLists.txt

@@ -143,6 +143,7 @@ if(ENTT_BUILD_LIB)
 
     SETUP_LIB_TEST(dispatcher)
     SETUP_LIB_TEST(emitter)
+    SETUP_LIB_TEST(locator)
     SETUP_LIB_TEST(meta)
     SETUP_LIB_TEST(registry)
 

+ 11 - 0
test/lib/locator/lib.cpp

@@ -0,0 +1,11 @@
+#include <entt/core/attribute.h>
+#include <entt/locator/locator.hpp>
+#include "types.h"
+
+ENTT_API void set_up(const entt::locator<service>::node_type &handle) {
+    entt::locator<service>::reset(handle);
+}
+
+ENTT_API void use_service(int value) {
+    entt::locator<service>::value().value = value;
+}

+ 24 - 0
test/lib/locator/main.cpp

@@ -0,0 +1,24 @@
+#include <gtest/gtest.h>
+#include <entt/core/attribute.h>
+#include <entt/locator/locator.hpp>
+#include "types.h"
+
+ENTT_API void set_up(const entt::locator<service>::node_type &);
+ENTT_API void use_service(int);
+
+TEST(Lib, Locator) {
+    entt::locator<service>::emplace().value = 42;
+
+    ASSERT_EQ(entt::locator<service>::value().value, 42);
+
+    set_up(entt::locator<service>::handle());
+    use_service(3);
+
+    ASSERT_EQ(entt::locator<service>::value().value, 3);
+
+    // service updates do not propagate across boundaries
+    entt::locator<service>::emplace().value = 42;
+    use_service(3);
+
+    ASSERT_EQ(entt::locator<service>::value().value, 42);
+}

+ 8 - 0
test/lib/locator/types.h

@@ -0,0 +1,8 @@
+#ifndef ENTT_LIB_LOCATOR_TYPES_H
+#define ENTT_LIB_LOCATOR_TYPES_H
+
+struct service {
+    int value;
+};
+
+#endif