From 6e45126f53dc9e060eb0cb0bdfcf0b705873abc2 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 15 Jul 2020 15:38:13 +0200 Subject: [PATCH] test: added explicit test for ENTT_NO_ETO --- src/entt/config/config.h | 2 +- src/entt/entity/storage.hpp | 2 +- test/CMakeLists.txt | 17 +++++++---------- test/entt/entity/registry_no_eto.cpp | 25 +++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 test/entt/entity/registry_no_eto.cpp diff --git a/src/entt/config/config.h b/src/entt/config/config.h index aef92b78c..960c128e9 100644 --- a/src/entt/config/config.h +++ b/src/entt/config/config.h @@ -48,7 +48,7 @@ #else # include # // sfinae-friendly definition -# define ENTT_IS_EMPTY(Type) (false && std::is_empty_v) +# define ENTT_IS_EMPTY(Type) (std::is_empty_v, false) #endif diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index 750264a56..d1ff22240 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -478,7 +478,7 @@ private: /*! @copydoc storage */ template // the useless decltype(...) helps to get around a quite impressive issue of VS2017 -class storage())>: public sparse_set { +class storage()>: public sparse_set { using underlying_type = sparse_set; public: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 87a9b00aa..4a8568343 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -56,7 +56,7 @@ function(SETUP_TARGET TARGET_NAME) $<$,$>:/O2> ) - target_compile_definitions(${TARGET_NAME} PRIVATE ENTT_STANDALONE) + target_compile_definitions(${TARGET_NAME} PRIVATE ENTT_STANDALONE ${ARGN}) endfunction() add_library(odr OBJECT odr.cpp) @@ -65,27 +65,23 @@ SETUP_TARGET(odr) function(SETUP_BASIC_TEST TEST_NAME TEST_SOURCES) add_executable(${TEST_NAME} $ ${TEST_SOURCES}) target_link_libraries(${TEST_NAME} PRIVATE GTest::Main Threads::Threads) - SETUP_TARGET(${TEST_NAME}) + SETUP_TARGET(${TEST_NAME} ${ARGN}) add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) endfunction() function(SETUP_LIB_TEST TEST_NAME) add_library(_${TEST_NAME} SHARED $ lib/${TEST_NAME}/lib.cpp) - SETUP_TARGET(_${TEST_NAME}) - SETUP_BASIC_TEST(lib_${TEST_NAME} lib/${TEST_NAME}/main.cpp) - target_compile_definitions(_${TEST_NAME} PRIVATE ENTT_API_EXPORT ${ARGV1}) - target_compile_definitions(lib_${TEST_NAME} PRIVATE ENTT_API_IMPORT ${ARGV1}) + SETUP_TARGET(_${TEST_NAME} ENTT_API_EXPORT) + SETUP_BASIC_TEST(lib_${TEST_NAME} lib/${TEST_NAME}/main.cpp ENTT_API_IMPORT) target_link_libraries(lib_${TEST_NAME} PRIVATE _${TEST_NAME}) endfunction() function(SETUP_PLUGIN_TEST TEST_NAME) add_library(_${TEST_NAME} MODULE $ lib/${TEST_NAME}/plugin.cpp) - SETUP_TARGET(_${TEST_NAME}) - SETUP_BASIC_TEST(lib_${TEST_NAME} lib/${TEST_NAME}/main.cpp) + SETUP_TARGET(_${TEST_NAME} NOMINMAX ${ARGVN}) + SETUP_BASIC_TEST(lib_${TEST_NAME} lib/${TEST_NAME}/main.cpp NOMINMAX PLUGIN="$" ${ARGVN}) target_include_directories(_${TEST_NAME} PRIVATE ${cr_INCLUDE_DIR}) target_include_directories(lib_${TEST_NAME} PRIVATE ${cr_INCLUDE_DIR}) - target_compile_definitions(lib_${TEST_NAME} PRIVATE NOMINMAX PLUGIN="$" ${ARGV1}) - target_compile_definitions(_${TEST_NAME} PRIVATE NOMINMAX ${ARGV1}) target_link_libraries(lib_${TEST_NAME} PRIVATE ${CMAKE_DL_LIBS}) endfunction() @@ -172,6 +168,7 @@ SETUP_BASIC_TEST(handle entt/entity/handle.cpp) SETUP_BASIC_TEST(helper entt/entity/helper.cpp) SETUP_BASIC_TEST(observer entt/entity/observer.cpp) SETUP_BASIC_TEST(registry entt/entity/registry.cpp) +SETUP_BASIC_TEST(registry_no_eto entt/entity/registry_no_eto.cpp ENTT_NO_ETO) SETUP_BASIC_TEST(runtime_view entt/entity/runtime_view.cpp) SETUP_BASIC_TEST(snapshot entt/entity/snapshot.cpp) SETUP_BASIC_TEST(sparse_set entt/entity/sparse_set.cpp) diff --git a/test/entt/entity/registry_no_eto.cpp b/test/entt/entity/registry_no_eto.cpp new file mode 100644 index 000000000..dadf5ca77 --- /dev/null +++ b/test/entt/entity/registry_no_eto.cpp @@ -0,0 +1,25 @@ +#include +#include + +struct empty_type {}; + +bool operator==(const empty_type &lhs, const empty_type &rhs) { + return &lhs == &rhs; +} + +TEST(Registry, NoEto) { + entt::registry registry; + const auto entity = registry.create(); + + registry.emplace(entity); + registry.emplace(entity, 42); + + ASSERT_NE(registry.raw(), nullptr); + ASSERT_NE(registry.try_get(entity), nullptr); + ASSERT_EQ(registry.view().get(entity), std::as_const(registry).view().get(entity)); + + auto view = registry.view(); + auto cview = std::as_const(registry).view(); + + ASSERT_EQ((std::get<0>(view.get(entity))), (std::get<0>(cview.get(entity)))); +}