diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9a8b57c58..9567a4bd2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -151,10 +151,14 @@ endif() # Test example if(ENTT_BUILD_EXAMPLE) - SETUP_BASIC_TEST_DEPRECATED(custom_identifier example/custom_identifier.cpp) - SETUP_BASIC_TEST_DEPRECATED(entity_copy example/entity_copy.cpp) - SETUP_BASIC_TEST_DEPRECATED(reserved_bits example/reserved_bits.cpp) - SETUP_BASIC_TEST_DEPRECATED(signal_less example/signal_less.cpp) + SETUP_BASIC_TEST( + NAME example + SOURCES + example/custom_identifier.cpp + example/entity_copy.cpp + example/reserved_bits.cpp + example/signal_less.cpp + ) endif() # Test lib diff --git a/test/example/custom_identifier.cpp b/test/example/custom_identifier.cpp index a9b1ebb43..5baaee6f3 100644 --- a/test/example/custom_identifier.cpp +++ b/test/example/custom_identifier.cpp @@ -3,30 +3,32 @@ #include #include -struct entity_id final { - using entity_type = std::uint32_t; - static constexpr auto null = entt::null; +struct CustomIdentifier: testing::Test { + struct entity_id final { + using entity_type = std::uint32_t; + static constexpr auto null = entt::null; - constexpr entity_id(entity_type value = null) noexcept - : entt{value} {} + constexpr entity_id(entity_type value = null) noexcept + : entt{value} {} - ~entity_id() = default; + ~entity_id() = default; - constexpr entity_id(const entity_id &other) = default; - constexpr entity_id(entity_id &&other) noexcept = default; + constexpr entity_id(const entity_id &other) = default; + constexpr entity_id(entity_id &&other) noexcept = default; - constexpr entity_id &operator=(const entity_id &other) = default; - constexpr entity_id &operator=(entity_id &&other) noexcept = default; + constexpr entity_id &operator=(const entity_id &other) = default; + constexpr entity_id &operator=(entity_id &&other) noexcept = default; - constexpr operator entity_type() const noexcept { - return entt; - } + constexpr operator entity_type() const noexcept { + return entt; + } -private: - entity_type entt; + private: + entity_type entt; + }; }; -TEST(Example, CustomIdentifier) { +TEST_F(CustomIdentifier, Example) { entt::basic_registry registry{}; entity_id entity{}; diff --git a/test/example/entity_copy.cpp b/test/example/entity_copy.cpp index 0874c66e3..457ce98c0 100644 --- a/test/example/entity_copy.cpp +++ b/test/example/entity_copy.cpp @@ -8,47 +8,50 @@ #include #include -enum class my_entity : entt::id_type {}; +struct EntityCopy: testing::Test { + enum class my_entity : entt::id_type {}; + enum class other_entity : entt::id_type {}; -template -// NOLINTNEXTLINE(*-exception-escape) -struct meta_mixin: Type { - using allocator_type = Type::allocator_type; - using element_type = Type::element_type; + template + // NOLINTNEXTLINE(*-exception-escape) + struct meta_mixin: Type { + using allocator_type = Type::allocator_type; + using element_type = Type::element_type; - explicit meta_mixin(const allocator_type &allocator); -}; + explicit meta_mixin(const allocator_type &allocator); + }; -template -struct entt::storage_type { - using type = meta_mixin>; + void TearDown() override { + entt::meta_reset(); + } }; template -meta_mixin::meta_mixin(const allocator_type &allocator) +struct entt::storage_type { + using type = EntityCopy::meta_mixin>; +}; + +template +struct entt::storage_type { + using type = EntityCopy::meta_mixin>; +}; + +template +EntityCopy::meta_mixin::meta_mixin(const allocator_type &allocator) : Type{allocator} { using namespace entt::literals; entt::meta_factory{} // cross registry, same type - .template func &(const entt::id_type)>(&entt::basic_registry::storage), entt::as_ref_t>("storage"_hs) + .template func &(const entt::id_type)>(&entt::basic_registry::storage), entt::as_ref_t>("storage"_hs) // cross registry, different types - .template func &(const entt::id_type)>(&entt::basic_registry::storage), entt::as_ref_t>("storage"_hs); + .template func &(const entt::id_type)>(&entt::basic_registry::storage), entt::as_ref_t>("storage"_hs); } -template -struct EntityCopy: testing::Test { - using type = Type; -}; - -using EntityCopyTypes = ::testing::Types, entt::basic_registry>; - -TYPED_TEST_SUITE(EntityCopy, EntityCopyTypes, ); - -TEST(EntityCopy, SameRegistry) { +TEST_F(EntityCopy, SameRegistry) { using namespace entt::literals; - entt::registry registry{}; + entt::basic_registry registry{}; auto &&custom = registry.storage("custom"_hs); const auto src = registry.create(); @@ -58,7 +61,7 @@ TEST(EntityCopy, SameRegistry) { registry.emplace(src, 2); registry.emplace(src, 'c'); - ASSERT_EQ(registry.storage().size(), 2u); + ASSERT_EQ(registry.storage().size(), 2u); ASSERT_TRUE(custom.contains(src)); ASSERT_FALSE(custom.contains(dst)); ASSERT_TRUE((registry.all_of(src))); @@ -71,7 +74,7 @@ TEST(EntityCopy, SameRegistry) { } } - ASSERT_EQ(registry.storage().size(), 2u); + ASSERT_EQ(registry.storage().size(), 2u); ASSERT_TRUE(custom.contains(src)); ASSERT_FALSE(custom.contains(dst)); ASSERT_TRUE((registry.all_of(src))); @@ -81,12 +84,11 @@ TEST(EntityCopy, SameRegistry) { ASSERT_EQ(registry.get(dst), 'c'); } -TYPED_TEST(EntityCopy, CrossRegistry) { +TEST_F(EntityCopy, CrossRegistry) { using namespace entt::literals; - entt::basic_registry src{}; - // other registry type, see typed test suite - typename TestFixture::type dst{}; + entt::basic_registry src{}; + entt::basic_registry dst{}; const auto entity = src.create(); const auto copy = dst.create(); @@ -94,8 +96,8 @@ TYPED_TEST(EntityCopy, CrossRegistry) { src.emplace(entity, 2); src.emplace(entity, 'c'); - ASSERT_EQ(src.storage().size(), 1u); - ASSERT_EQ(dst.template storage().size(), 1u); + ASSERT_EQ(src.storage().size(), 1u); + ASSERT_EQ(dst.storage().size(), 1u); ASSERT_TRUE((src.all_of(entity))); ASSERT_FALSE((dst.template all_of(copy))); @@ -114,8 +116,8 @@ TYPED_TEST(EntityCopy, CrossRegistry) { } } - ASSERT_EQ(src.storage().size(), 1u); - ASSERT_EQ(dst.template storage().size(), 1u); + ASSERT_EQ(src.storage().size(), 1u); + ASSERT_EQ(dst.storage().size(), 1u); ASSERT_TRUE((src.all_of(entity))); ASSERT_TRUE((dst.template all_of(copy))); diff --git a/test/example/reserved_bits.cpp b/test/example/reserved_bits.cpp index d50c4eef4..3b6eda792 100644 --- a/test/example/reserved_bits.cpp +++ b/test/example/reserved_bits.cpp @@ -10,33 +10,31 @@ #include #include -enum class my_entity : entt::id_type { - disabled = 0x10000000, - _entt_enum_as_bitmask -}; +struct ReservedBits: testing::Test { + enum class my_entity : entt::id_type { + disabled = 0x10000000, + _entt_enum_as_bitmask + }; -struct entity_traits { - using value_type = my_entity; - using entity_type = std::uint32_t; - using version_type = std::uint16_t; - static constexpr entity_type entity_mask = 0xFFFF; // 16b - static constexpr entity_type version_mask = 0x0FFF; // 12b + struct entity_traits { + using value_type = my_entity; + using entity_type = std::uint32_t; + using version_type = std::uint16_t; + static constexpr entity_type entity_mask = 0xFFFF; // 16b + static constexpr entity_type version_mask = 0x0FFF; // 12b + }; + + [[nodiscard]] static bool is_disabled(const my_entity entity) { + return ((entity & my_entity::disabled) == my_entity::disabled); + } }; template<> -struct entt::entt_traits: entt::basic_entt_traits { +struct entt::entt_traits: entt::basic_entt_traits { static constexpr std::size_t page_size = ENTT_SPARSE_PAGE; }; -namespace { - -[[nodiscard]] bool is_disabled(const my_entity entity) { - return ((entity & my_entity::disabled) == my_entity::disabled); -} - -} // namespace - -TEST(Example, DisabledEntity) { +TEST_F(ReservedBits, DisabledEntity) { entt::basic_registry registry{}; auto view = registry.view(); diff --git a/test/example/signal_less.cpp b/test/example/signal_less.cpp index b98e37a5f..c238bf8d5 100644 --- a/test/example/signal_less.cpp +++ b/test/example/signal_less.cpp @@ -4,33 +4,37 @@ #include #include -template -struct entt::storage_type { +struct SignalLess: testing::Test { + enum entity : std::uint32_t {}; + + template + struct has_on_construct: std::false_type {}; + + template + struct has_on_construct::on_construct)>>: std::true_type {}; + + template + static constexpr auto has_on_construct_v = has_on_construct::value; +}; + +template +struct entt::storage_type { // no signal regardless of element type ... - using type = basic_storage; + using type = basic_storage; }; -template -struct entt::storage_type { +template<> +struct entt::storage_type { // ... unless it's char, because yes. - using type = sigh_mixin>; + using type = sigh_mixin>; }; -template -struct has_on_construct: std::false_type {}; - -template -struct has_on_construct::on_construct)>>: std::true_type {}; - -template -inline constexpr auto has_on_construct_v = has_on_construct::value; - -TEST(Example, SignalLess) { +TEST_F(SignalLess, Example) { // invoking registry::on_construct is a compile-time error - ASSERT_FALSE((has_on_construct_v)); - ASSERT_TRUE((has_on_construct_v)); + ASSERT_FALSE((has_on_construct_v)); + ASSERT_TRUE((has_on_construct_v)); - entt::registry registry; + entt::basic_registry registry; const std::array entity{registry.create()}; // literally a test for storage_adapter_mixin