Michele Caini 6 лет назад
Родитель
Сommit
46db75308c

+ 2 - 0
CMakeLists.txt

@@ -208,11 +208,13 @@ endif()
 #
 
 FILE(GLOB GH_WORKFLOWS .github/workflows/*.yml)
+FILE(GLOB_RECURSE BUILD_BAZEL test/BUILD.bazel)
 
 add_custom_target(
     entt_aob
     SOURCES
         ${GH_WORKFLOWS}
+        ${BUILD_BAZEL}
         .github/FUNDING.yml
         AUTHORS
         CONTRIBUTING.md

+ 13 - 17
test/CMakeLists.txt

@@ -11,8 +11,8 @@ macro(SETUP_TARGET TARGET_NAME)
 
     target_compile_options(
         ${TARGET_NAME}
-        PRIVATE $<$<AND:$<CONFIG:Debug>,$<NOT:$<PLATFORM_ID:Windows>>>:-O0 -g -pedantic -Wall -Wshadow>
-        PRIVATE $<$<AND:$<CONFIG:Release>,$<NOT:$<PLATFORM_ID:Windows>>>:-O2 -pedantic -Wall -Wshadow>
+        PRIVATE $<$<AND:$<CONFIG:Debug>,$<NOT:$<PLATFORM_ID:Windows>>>:-O0 -g -pedantic -Wall -Wshadow -fvisibility=hidden>
+        PRIVATE $<$<AND:$<CONFIG:Release>,$<NOT:$<PLATFORM_ID:Windows>>>:-O2 -pedantic -Wall -Wshadow -fvisibility=hidden>
         PRIVATE $<$<AND:$<CONFIG:Debug>,$<PLATFORM_ID:Windows>>:/EHsc /W1>
         PRIVATE $<$<AND:$<CONFIG:Release>,$<PLATFORM_ID:Windows>>:/EHsc /W1 /O2>
     )
@@ -28,6 +28,13 @@ macro(SETUP_AND_ADD_TEST TEST_NAME TEST_SOURCE)
     add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
 endmacro()
 
+macro(SETUP_AND_ADD_LIB_TEST TEST_NAME)
+    add_library(dyn_${TEST_NAME} SHARED lib/${TEST_NAME}/lib.cpp)
+    SETUP_TARGET(dyn_${TEST_NAME})
+    SETUP_AND_ADD_TEST(lib_${TEST_NAME} lib/${TEST_NAME}/main.cpp)
+    target_link_libraries(lib_${TEST_NAME} PRIVATE dyn_${TEST_NAME})
+endmacro()
+
 # Test benchmark
 
 if(BUILD_BENCHMARK)
@@ -37,21 +44,10 @@ endif()
 # Test lib
 
 if(BUILD_LIB)
-    add_library(a_module_shared SHARED lib/a_module.cpp)
-    add_library(a_module_static STATIC lib/a_module.cpp)
-    add_library(another_module_shared SHARED lib/another_module.cpp)
-    add_library(another_module_static STATIC lib/another_module.cpp)
-
-    SETUP_TARGET(a_module_shared)
-    SETUP_TARGET(a_module_static)
-    SETUP_TARGET(another_module_shared)
-    SETUP_TARGET(another_module_static)
-
-    SETUP_AND_ADD_TEST(lib_shared lib/lib.cpp)
-    target_link_libraries(lib_shared PRIVATE a_module_shared another_module_shared)
-
-    SETUP_AND_ADD_TEST(lib_static lib/lib.cpp)
-    target_link_libraries(lib_static PRIVATE a_module_static another_module_static)
+    SETUP_AND_ADD_LIB_TEST(dispatcher)
+    SETUP_AND_ADD_LIB_TEST(emitter)
+    SETUP_AND_ADD_LIB_TEST(meta)
+    SETUP_AND_ADD_LIB_TEST(registry)
 endif()
 
 # Test mod

+ 0 - 16
test/lib/BUILD.bazel

@@ -1,16 +0,0 @@
-load("//bazel:copts.bzl", "entt_copts")
-
-cc_test(
-    name = "lib",
-    srcs = [
-        "types.h",
-        "a_module.cpp",
-        "another_module.cpp",
-        "lib.cpp",
-    ],
-    copts = entt_copts,
-    deps = [
-        "//:entt",
-        "@com_google_googletest//:gtest_main",
-    ],
-)

+ 0 - 65
test/lib/another_module.cpp

@@ -1,65 +0,0 @@
-#include <entt/entity/registry.hpp>
-#include <entt/meta/factory.hpp>
-#include <entt/signal/dispatcher.hpp>
-#include <entt/signal/emitter.hpp>
-#include "types.h"
-
-#ifndef LIB_EXPORT
-#if defined _WIN32 || defined __CYGWIN__
-#define LIB_EXPORT __declspec(dllexport)
-#elif defined __GNUC__
-#define LIB_EXPORT __attribute__((visibility("default")))
-#else
-#define LIB_EXPORT
-#endif
-#endif
-
-LIB_EXPORT typename entt::component another_module_int_type() {
-    entt::registry registry;
-
-    (void)registry.type<char>();
-    (void)registry.type<double>();
-    (void)registry.type<const int>();
-    (void)registry.type<const char>();
-    (void)registry.type<float>();
-
-    return registry.type<int>();
-}
-
-LIB_EXPORT typename entt::component another_module_char_type() {
-    entt::registry registry;
-
-    (void)registry.type<int>();
-    (void)registry.type<float>();
-    (void)registry.type<const char>();
-    (void)registry.type<const int>();
-    (void)registry.type<double>();
-
-    return registry.type<char>();
-}
-
-LIB_EXPORT void assign_velocity(int vel, entt::registry &registry) {
-    for(auto entity: registry.view<position>()) {
-        registry.assign<velocity>(entity, vel, vel);
-    }
-}
-
-LIB_EXPORT void trigger_an_event(int payload, entt::dispatcher &dispatcher) {
-    dispatcher.trigger<an_event>(payload);
-}
-
-LIB_EXPORT void emit_an_event(int payload, test_emitter &emitter) {
-    emitter.publish<an_event>(payload);
-}
-
-LIB_EXPORT void another_module_bind_ctx(entt::meta_ctx context) {
-    entt::meta_ctx::bind(context);
-}
-
-LIB_EXPORT void another_module_meta_init() {
-    entt::meta<int>().type().data<0>("0"_hs);
-}
-
-LIB_EXPORT void another_module_meta_deinit() {
-    entt::meta<int>().reset();
-}

+ 15 - 0
test/lib/dispatcher/BUILD.bazel

@@ -0,0 +1,15 @@
+load("//bazel:copts.bzl", "entt_copts")
+
+cc_test(
+    name = "lib_dispatcher",
+    srcs = [
+        "types.h",
+        "lib.cpp",
+        "main.cpp",
+    ],
+    copts = entt_copts,
+    deps = [
+        "//:entt",
+        "@com_google_googletest//:gtest_main",
+    ],
+)

+ 16 - 0
test/lib/dispatcher/lib.cpp

@@ -0,0 +1,16 @@
+#include <entt/signal/dispatcher.hpp>
+#include "types.h"
+
+#ifndef LIB_EXPORT
+#if defined _WIN32 || defined __CYGWIN__
+#define LIB_EXPORT __declspec(dllexport)
+#elif defined __GNUC__
+#define LIB_EXPORT __attribute__((visibility("default")))
+#else
+#define LIB_EXPORT
+#endif
+#endif
+
+LIB_EXPORT void trigger_event(int value, entt::dispatcher &dispatcher) {
+    dispatcher.trigger<event>(value);
+}

+ 22 - 0
test/lib/dispatcher/main.cpp

@@ -0,0 +1,22 @@
+#include <gtest/gtest.h>
+#include <entt/signal/dispatcher.hpp>
+#include "types.h"
+
+extern void trigger_event(int, entt::dispatcher &);
+
+struct listener {
+    void on_int(int) { FAIL(); }
+    void on_event(event ev) { value = ev.payload; }
+    int value{};
+};
+
+TEST(Lib, Dispatcher) {
+    entt::dispatcher dispatcher;
+    listener listener;
+
+    dispatcher.sink<int>().connect<&listener::on_int>(listener);
+    dispatcher.sink<event>().connect<&listener::on_event>(listener);
+    trigger_event(42, dispatcher);
+
+    ASSERT_EQ(listener.value, 42);
+}

+ 5 - 0
test/lib/dispatcher/types.h

@@ -0,0 +1,5 @@
+#include <entt/core/type_traits.hpp>
+
+ENTT_NAMED_STRUCT(event, {
+    int payload;
+});

+ 15 - 0
test/lib/emitter/BUILD.bazel

@@ -0,0 +1,15 @@
+load("//bazel:copts.bzl", "entt_copts")
+
+cc_test(
+    name = "lib_emitter",
+    srcs = [
+        "types.h",
+        "lib.cpp",
+        "main.cpp",
+    ],
+    copts = entt_copts,
+    deps = [
+        "//:entt",
+        "@com_google_googletest//:gtest_main",
+    ],
+)

+ 16 - 0
test/lib/emitter/lib.cpp

@@ -0,0 +1,16 @@
+#include <entt/signal/emitter.hpp>
+#include "types.h"
+
+#ifndef LIB_EXPORT
+#if defined _WIN32 || defined __CYGWIN__
+#define LIB_EXPORT __declspec(dllexport)
+#elif defined __GNUC__
+#define LIB_EXPORT __attribute__((visibility("default")))
+#else
+#define LIB_EXPORT
+#endif
+#endif
+
+LIB_EXPORT void emit_event(int value, test_emitter &emitter) {
+    emitter.publish<event>(value);
+}

+ 21 - 0
test/lib/emitter/main.cpp

@@ -0,0 +1,21 @@
+#include <gtest/gtest.h>
+#include <entt/signal/emitter.hpp>
+#include "types.h"
+
+extern void emit_event(int, test_emitter &);
+
+TEST(Lib, Emitter) {
+    test_emitter emitter;
+    int value{};
+
+    emitter.once<int>([](int, test_emitter &) { FAIL(); });
+    emitter.once<event>([&](event event, test_emitter &) {
+        ASSERT_EQ(event.payload, 42);
+        value = event.payload;
+    });
+
+    emit_event(42, emitter);
+    emit_event(3, emitter);
+
+    ASSERT_EQ(value, 42);
+}

+ 10 - 0
test/lib/emitter/types.h

@@ -0,0 +1,10 @@
+#include <entt/core/type_traits.hpp>
+#include <entt/signal/emitter.hpp>
+
+struct test_emitter
+        : entt::emitter<test_emitter>
+{};
+
+ENTT_NAMED_STRUCT(event, {
+    int payload;
+});

+ 0 - 140
test/lib/lib.cpp

@@ -1,140 +0,0 @@
-#include <gtest/gtest.h>
-#include <entt/entity/entity.hpp>
-#include <entt/entity/registry.hpp>
-#include <entt/meta/factory.hpp>
-#include <entt/signal/dispatcher.hpp>
-#include <entt/signal/emitter.hpp>
-#include "types.h"
-
-extern typename entt::component a_module_int_type();
-extern typename entt::component a_module_char_type();
-extern typename entt::component another_module_int_type();
-extern typename entt::component another_module_char_type();
-
-extern void update_position(int delta, entt::registry &);
-extern void assign_velocity(int, entt::registry &);
-
-extern void trigger_an_event(int, entt::dispatcher &);
-extern void trigger_another_event(entt::dispatcher &);
-
-extern void emit_an_event(int, test_emitter &);
-extern void emit_another_event(test_emitter &);
-
-extern void a_module_bind_ctx(entt::meta_ctx);
-extern void another_module_bind_ctx(entt::meta_ctx);
-
-extern void a_module_meta_init();
-extern void another_module_meta_init();
-
-extern void a_module_meta_deinit();
-extern void another_module_meta_deinit();
-
-struct listener {
-    void on_an_event(an_event event) { value = event.payload; }
-    void on_another_event(another_event) {}
-
-    int value;
-};
-
-TEST(Lib, Types) {
-    entt::registry registry;
-
-    ASSERT_EQ(registry.type<int>(), registry.type<const int>());
-    ASSERT_EQ(registry.type<char>(), registry.type<const char>());
-
-    ASSERT_EQ(registry.type<int>(), a_module_int_type());
-    ASSERT_EQ(registry.type<char>(), a_module_char_type());
-    ASSERT_EQ(registry.type<const int>(), a_module_int_type());
-    ASSERT_EQ(registry.type<const char>(), a_module_char_type());
-
-    ASSERT_EQ(registry.type<const char>(), another_module_char_type());
-    ASSERT_EQ(registry.type<const int>(), another_module_int_type());
-    ASSERT_EQ(registry.type<char>(), another_module_char_type());
-    ASSERT_EQ(registry.type<int>(), another_module_int_type());
-}
-
-TEST(Lib, Registry) {
-    entt::registry registry;
-
-    for(auto i = 0; i < 3; ++i) {
-        const auto entity = registry.create();
-        registry.assign<position>(entity, i, i+1);
-    }
-
-    assign_velocity(2, registry);
-
-    ASSERT_EQ(registry.size<position>(), entt::registry::size_type{3});
-    ASSERT_EQ(registry.size<velocity>(), entt::registry::size_type{3});
-
-    update_position(1, registry);
-
-    registry.view<position>().each([](auto entity, auto &position) {
-        ASSERT_EQ(position.x, entt::to_integer(entity) + 2);
-        ASSERT_EQ(position.y, entt::to_integer(entity) + 3);
-    });
-}
-
-TEST(Lib, Dispatcher) {
-    entt::dispatcher dispatcher;
-    listener listener;
-
-    dispatcher.sink<an_event>().connect<&listener::on_an_event>(listener);
-    dispatcher.sink<another_event>().connect<&listener::on_another_event>(listener);
-
-    listener.value = 0;
-
-    trigger_an_event(3, dispatcher);
-    trigger_another_event(dispatcher);
-
-    ASSERT_EQ(listener.value, 3);
-}
-
-TEST(Lib, Emitter) {
-    test_emitter emitter;
-
-    emitter.once<another_event>([](another_event, test_emitter &) {});
-    emitter.once<an_event>([](an_event event, test_emitter &) {
-        ASSERT_EQ(event.payload, 3);
-    });
-
-    emit_an_event(3, emitter);
-    emit_another_event(emitter);
-
-    emitter.once<an_event>([](an_event event, test_emitter &) {
-        ASSERT_EQ(event.payload, 42);
-    });
-
-    emit_an_event(42, emitter);
-    emit_another_event(emitter);
-}
-
-TEST(Lib, Meta) {
-    ASSERT_FALSE(entt::resolve("double"_hs));
-    ASSERT_FALSE(entt::resolve("char"_hs));
-    ASSERT_FALSE(entt::resolve("int"_hs));
-    ASSERT_FALSE(entt::resolve<int>().data("0"_hs));
-    ASSERT_FALSE(entt::resolve<char>().data("c"_hs));
-
-    a_module_bind_ctx(entt::meta_ctx{});
-    another_module_bind_ctx(entt::meta_ctx{});
-
-    entt::meta<double>().type("double"_hs).conv<int>();
-    another_module_meta_init();
-    a_module_meta_init();
-
-    ASSERT_TRUE(entt::resolve("double"_hs));
-    ASSERT_TRUE(entt::resolve("char"_hs));
-    ASSERT_TRUE(entt::resolve("int"_hs));
-    ASSERT_TRUE(entt::resolve<int>().data("0"_hs));
-    ASSERT_TRUE(entt::resolve<char>().data("c"_hs));
-
-    a_module_meta_deinit();
-    entt::meta<double>().reset();
-    another_module_meta_deinit();
-
-    ASSERT_FALSE(entt::resolve("double"_hs));
-    ASSERT_FALSE(entt::resolve("char"_hs));
-    ASSERT_FALSE(entt::resolve("int"_hs));
-    ASSERT_FALSE(entt::resolve<int>().data("0"_hs));
-    ASSERT_FALSE(entt::resolve<char>().data("c"_hs));
-}

+ 15 - 0
test/lib/meta/BUILD.bazel

@@ -0,0 +1,15 @@
+load("//bazel:copts.bzl", "entt_copts")
+
+cc_test(
+    name = "lib_meta",
+    srcs = [
+        "types.h",
+        "lib.cpp",
+        "main.cpp",
+    ],
+    copts = entt_copts,
+    deps = [
+        "//:entt",
+        "@com_google_googletest//:gtest_main",
+    ],
+)

+ 26 - 0
test/lib/meta/lib.cpp

@@ -0,0 +1,26 @@
+#include <entt/meta/factory.hpp>
+#include "types.h"
+
+#ifndef LIB_EXPORT
+#if defined _WIN32 || defined __CYGWIN__
+#define LIB_EXPORT __declspec(dllexport)
+#elif defined __GNUC__
+#define LIB_EXPORT __attribute__((visibility("default")))
+#else
+#define LIB_EXPORT
+#endif
+#endif
+
+LIB_EXPORT void bind_ctx(entt::meta_ctx context) {
+    entt::meta_ctx::bind(context);
+}
+
+LIB_EXPORT void meta_init() {
+    entt::meta<char>().type().data<'c'>("c"_hs);
+    entt::meta<int>().type().data<0>("0"_hs);
+}
+
+LIB_EXPORT void meta_deinit() {
+    entt::meta<char>().reset();
+    entt::meta<int>().reset();
+}

+ 34 - 0
test/lib/meta/main.cpp

@@ -0,0 +1,34 @@
+#include <gtest/gtest.h>
+#include <entt/meta/factory.hpp>
+#include "types.h"
+
+extern void bind_ctx(entt::meta_ctx);
+extern void meta_init();
+extern void meta_deinit();
+
+TEST(Lib, Meta) {
+    ASSERT_FALSE(entt::resolve("double"_hs));
+    ASSERT_FALSE(entt::resolve("char"_hs));
+    ASSERT_FALSE(entt::resolve("int"_hs));
+    ASSERT_FALSE(entt::resolve<int>().data("0"_hs));
+    ASSERT_FALSE(entt::resolve<char>().data("c"_hs));
+
+    bind_ctx(entt::meta_ctx{});
+    entt::meta<double>().type("double"_hs).conv<int>();
+    meta_init();
+
+    ASSERT_TRUE(entt::resolve("double"_hs));
+    ASSERT_TRUE(entt::resolve("char"_hs));
+    ASSERT_TRUE(entt::resolve("int"_hs));
+    ASSERT_TRUE(entt::resolve<int>().data("0"_hs));
+    ASSERT_TRUE(entt::resolve<char>().data("c"_hs));
+
+    meta_deinit();
+    entt::meta<double>().reset();
+
+    ASSERT_FALSE(entt::resolve("double"_hs));
+    ASSERT_FALSE(entt::resolve("char"_hs));
+    ASSERT_FALSE(entt::resolve("int"_hs));
+    ASSERT_FALSE(entt::resolve<int>().data("0"_hs));
+    ASSERT_FALSE(entt::resolve<char>().data("c"_hs));
+}

+ 4 - 0
test/lib/meta/types.h

@@ -0,0 +1,4 @@
+#include <entt/core/type_traits.hpp>
+
+ENTT_NAMED_TYPE(int);
+ENTT_NAMED_TYPE(char);

+ 15 - 0
test/lib/registry/BUILD.bazel

@@ -0,0 +1,15 @@
+load("//bazel:copts.bzl", "entt_copts")
+
+cc_test(
+    name = "lib_registry",
+    srcs = [
+        "types.h",
+        "lib.cpp",
+        "main.cpp",
+    ],
+    copts = entt_copts,
+    deps = [
+        "//:entt",
+        "@com_google_googletest//:gtest_main",
+    ],
+)

+ 6 - 23
test/lib/a_module.cpp → test/lib/registry/lib.cpp

@@ -1,7 +1,4 @@
 #include <entt/entity/registry.hpp>
-#include <entt/meta/factory.hpp>
-#include <entt/signal/dispatcher.hpp>
-#include <entt/signal/emitter.hpp>
 #include "types.h"
 
 #ifndef LIB_EXPORT
@@ -14,7 +11,7 @@
 #endif
 #endif
 
-LIB_EXPORT typename entt::component a_module_int_type() {
+LIB_EXPORT typename entt::component int_type() {
     entt::registry registry;
 
     (void)registry.type<double>();
@@ -23,7 +20,7 @@ LIB_EXPORT typename entt::component a_module_int_type() {
     return registry.type<int>();
 }
 
-LIB_EXPORT typename entt::component a_module_char_type() {
+LIB_EXPORT typename entt::component char_type() {
     entt::registry registry;
 
     (void)registry.type<double>();
@@ -39,22 +36,8 @@ LIB_EXPORT void update_position(int delta, entt::registry &registry) {
     });
 }
 
-LIB_EXPORT void trigger_another_event(entt::dispatcher &dispatcher) {
-    dispatcher.trigger<another_event>();
-}
-
-LIB_EXPORT void emit_another_event(test_emitter &emitter) {
-    emitter.publish<another_event>();
-}
-
-LIB_EXPORT void a_module_bind_ctx(entt::meta_ctx context) {
-    entt::meta_ctx::bind(context);
-}
-
-LIB_EXPORT void a_module_meta_init() {
-    entt::meta<char>().type().data<'c'>("c"_hs);
-}
-
-LIB_EXPORT void a_module_meta_deinit() {
-    entt::meta<char>().reset();
+LIB_EXPORT void assign_velocity(int vel, entt::registry &registry) {
+    for(auto entity: registry.view<position>()) {
+        registry.assign<velocity>(entity, vel, vel);
+    }
 }

+ 44 - 0
test/lib/registry/main.cpp

@@ -0,0 +1,44 @@
+#include <gtest/gtest.h>
+#include <entt/entity/entity.hpp>
+#include <entt/entity/registry.hpp>
+#include "types.h"
+
+extern typename entt::component int_type();
+extern typename entt::component char_type();
+
+extern void update_position(int, entt::registry &);
+extern void assign_velocity(int, entt::registry &);
+
+TEST(Lib, Types) {
+    entt::registry registry;
+
+    ASSERT_EQ(registry.type<int>(), registry.type<const int>());
+    ASSERT_EQ(registry.type<char>(), registry.type<const char>());
+
+    ASSERT_EQ(registry.type<int>(), int_type());
+    ASSERT_EQ(registry.type<char>(), char_type());
+
+    ASSERT_EQ(registry.type<const char>(), char_type());
+    ASSERT_EQ(registry.type<const int>(), int_type());
+}
+
+TEST(Lib, Registry) {
+    entt::registry registry;
+
+    for(auto i = 0; i < 3; ++i) {
+        const auto entity = registry.create();
+        registry.assign<position>(entity, i, i+1);
+    }
+
+    assign_velocity(2, registry);
+
+    ASSERT_EQ(registry.size<position>(), entt::registry::size_type{3});
+    ASSERT_EQ(registry.size<velocity>(), entt::registry::size_type{3});
+
+    update_position(1, registry);
+
+    registry.view<position>().each([](auto entity, auto &position) {
+        ASSERT_EQ(position.x, entt::to_integer(entity) + 2);
+        ASSERT_EQ(position.y, entt::to_integer(entity) + 3);
+    });
+}

+ 0 - 11
test/lib/types.h → test/lib/registry/types.h

@@ -1,9 +1,4 @@
 #include <entt/core/type_traits.hpp>
-#include <entt/signal/emitter.hpp>
-
-struct test_emitter
-        : entt::emitter<test_emitter>
-{};
 
 ENTT_NAMED_STRUCT(position, {
     int x;
@@ -15,11 +10,5 @@ ENTT_NAMED_STRUCT(velocity, {
     int dy;
 });
 
-ENTT_NAMED_STRUCT(an_event, {
-    int payload;
-});
-
-ENTT_NAMED_STRUCT(another_event, {});
-
 ENTT_NAMED_TYPE(int);
 ENTT_NAMED_TYPE(char);