test: added explicit test for ENTT_NO_ETO
This commit is contained in:
@@ -48,7 +48,7 @@
|
||||
#else
|
||||
# include <type_traits>
|
||||
# // sfinae-friendly definition
|
||||
# define ENTT_IS_EMPTY(Type) (false && std::is_empty_v<Type>)
|
||||
# define ENTT_IS_EMPTY(Type) (std::is_empty_v<Type>, false)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -478,7 +478,7 @@ private:
|
||||
/*! @copydoc storage */
|
||||
template<typename Entity, typename Type>
|
||||
// the useless decltype(...) helps to get around a quite impressive issue of VS2017
|
||||
class storage<Entity, Type, decltype(std::enable_if_t<ENTT_IS_EMPTY(Type)>())>: public sparse_set<Entity> {
|
||||
class storage<Entity, Type, std::enable_if_t<ENTT_IS_EMPTY(Type)>()>: public sparse_set<Entity> {
|
||||
using underlying_type = sparse_set<Entity>;
|
||||
|
||||
public:
|
||||
|
||||
@@ -56,7 +56,7 @@ function(SETUP_TARGET TARGET_NAME)
|
||||
$<$<AND:$<CONFIG:Release>,$<PLATFORM_ID:Windows>>:/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} $<TARGET_OBJECTS:odr> ${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 $<TARGET_OBJECTS:odr> 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 $<TARGET_OBJECTS:odr> 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="$<TARGET_FILE:_${TEST_NAME}>" ${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="$<TARGET_FILE:_${TEST_NAME}>" ${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)
|
||||
|
||||
25
test/entt/entity/registry_no_eto.cpp
Normal file
25
test/entt/entity/registry_no_eto.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
||||
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<empty_type>(entity);
|
||||
registry.emplace<int>(entity, 42);
|
||||
|
||||
ASSERT_NE(registry.raw<empty_type>(), nullptr);
|
||||
ASSERT_NE(registry.try_get<empty_type>(entity), nullptr);
|
||||
ASSERT_EQ(registry.view<empty_type>().get(entity), std::as_const(registry).view<const empty_type>().get(entity));
|
||||
|
||||
auto view = registry.view<empty_type, int>();
|
||||
auto cview = std::as_const(registry).view<const empty_type, const int>();
|
||||
|
||||
ASSERT_EQ((std::get<0>(view.get<empty_type, int>(entity))), (std::get<0>(cview.get<const empty_type, const int>(entity))));
|
||||
}
|
||||
Reference in New Issue
Block a user