From 67d7b0080e7a18b36216cdc8d62bb51faa878ef6 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 31 Oct 2023 09:10:58 +0100 Subject: [PATCH] test: use shared pointer stable type --- test/entt/entity/view.cpp | 58 ++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/test/entt/entity/view.cpp b/test/entt/entity/view.cpp index 3603b11d2..2ff31d21d 100644 --- a/test/entt/entity/view.cpp +++ b/test/entt/entity/view.cpp @@ -5,14 +5,10 @@ #include #include #include +#include "../common/pointer_stable.h" struct empty_type {}; -struct pointer_stable { - static constexpr auto in_place_delete = true; - int value{}; -}; - TEST(SingleComponentView, Functionalities) { entt::registry registry; auto view = registry.view(); @@ -420,15 +416,15 @@ TEST(SingleComponentView, FrontBack) { TEST(SingleComponentView, DeductionGuide) { entt::registry registry; entt::storage_type_t istorage; - entt::storage_type_t sstorage; + entt::storage_type_t sstorage; testing::StaticAssertTypeEq>, entt::exclude_t<>>, decltype(entt::basic_view{istorage})>(); testing::StaticAssertTypeEq>, entt::exclude_t<>>, decltype(entt::basic_view{std::as_const(istorage)})>(); - testing::StaticAssertTypeEq>, entt::exclude_t<>>, decltype(entt::basic_view{sstorage})>(); + testing::StaticAssertTypeEq>, entt::exclude_t<>>, decltype(entt::basic_view{sstorage})>(); testing::StaticAssertTypeEq>, entt::exclude_t<>>, decltype(entt::basic_view{std::forward_as_tuple(istorage), std::make_tuple()})>(); testing::StaticAssertTypeEq>, entt::exclude_t<>>, decltype(entt::basic_view{std::forward_as_tuple(std::as_const(istorage))})>(); - testing::StaticAssertTypeEq>, entt::exclude_t<>>, decltype(entt::basic_view{std::forward_as_tuple(sstorage)})>(); + testing::StaticAssertTypeEq>, entt::exclude_t<>>, decltype(entt::basic_view{std::forward_as_tuple(sstorage)})>(); } TEST(SingleComponentView, IterableViewAlgorithmCompatibility) { @@ -446,13 +442,13 @@ TEST(SingleComponentView, IterableViewAlgorithmCompatibility) { TEST(SingleComponentView, StableType) { entt::registry registry; - auto view = registry.view(); + auto view = registry.view(); const auto entity = registry.create(); const auto other = registry.create(); - registry.emplace(entity); - registry.emplace(other); + registry.emplace(entity); + registry.emplace(other); registry.destroy(entity); ASSERT_EQ(view.size_hint(), 2u); @@ -465,18 +461,18 @@ TEST(SingleComponentView, StableType) { ASSERT_EQ(*view.begin(), other); ASSERT_EQ(++view.begin(), view.end()); - view.each([other](const auto entt, pointer_stable) { + view.each([other](const auto entt, test::pointer_stable) { ASSERT_EQ(other, entt); }); - view.each([check = true](pointer_stable) mutable { + view.each([check = true](test::pointer_stable) mutable { ASSERT_TRUE(check); check = false; }); for(auto [entt, st]: view.each()) { testing::StaticAssertTypeEq(); - testing::StaticAssertTypeEq(); + testing::StaticAssertTypeEq(); ASSERT_EQ(other, entt); } @@ -1256,25 +1252,25 @@ TEST(MultiComponentView, DeductionGuide) { entt::registry registry; entt::storage_type_t istorage; entt::storage_type_t dstorage; - entt::storage_type_t sstorage; + entt::storage_type_t sstorage; testing::StaticAssertTypeEq, entt::storage_type_t>, entt::exclude_t<>>, decltype(entt::basic_view{istorage, dstorage})>(); testing::StaticAssertTypeEq, entt::storage_type_t>, entt::exclude_t<>>, decltype(entt::basic_view{std::as_const(istorage), dstorage})>(); testing::StaticAssertTypeEq, const entt::storage_type_t>, entt::exclude_t<>>, decltype(entt::basic_view{istorage, std::as_const(dstorage)})>(); testing::StaticAssertTypeEq, const entt::storage_type_t>, entt::exclude_t<>>, decltype(entt::basic_view{std::as_const(istorage), std::as_const(dstorage)})>(); - testing::StaticAssertTypeEq, entt::storage_type_t>, entt::exclude_t<>>, decltype(entt::basic_view{istorage, sstorage})>(); + testing::StaticAssertTypeEq, entt::storage_type_t>, entt::exclude_t<>>, decltype(entt::basic_view{istorage, sstorage})>(); testing::StaticAssertTypeEq, entt::storage_type_t>, entt::exclude_t<>>, decltype(entt::basic_view{std::forward_as_tuple(istorage, dstorage), std::make_tuple()})>(); testing::StaticAssertTypeEq, entt::storage_type_t>, entt::exclude_t<>>, decltype(entt::basic_view{std::forward_as_tuple(std::as_const(istorage), dstorage)})>(); testing::StaticAssertTypeEq, const entt::storage_type_t>, entt::exclude_t<>>, decltype(entt::basic_view{std::forward_as_tuple(istorage, std::as_const(dstorage))})>(); testing::StaticAssertTypeEq, const entt::storage_type_t>, entt::exclude_t<>>, decltype(entt::basic_view{std::forward_as_tuple(std::as_const(istorage), std::as_const(dstorage))})>(); - testing::StaticAssertTypeEq, entt::storage_type_t>, entt::exclude_t<>>, decltype(entt::basic_view{std::forward_as_tuple(istorage, sstorage)})>(); + testing::StaticAssertTypeEq, entt::storage_type_t>, entt::exclude_t<>>, decltype(entt::basic_view{std::forward_as_tuple(istorage, sstorage)})>(); testing::StaticAssertTypeEq>, entt::exclude_t>>, decltype(entt::basic_view{std::forward_as_tuple(istorage), std::forward_as_tuple(dstorage)})>(); testing::StaticAssertTypeEq>, entt::exclude_t>>, decltype(entt::basic_view{std::forward_as_tuple(std::as_const(istorage)), std::forward_as_tuple(dstorage)})>(); testing::StaticAssertTypeEq>, entt::exclude_t>>, decltype(entt::basic_view{std::forward_as_tuple(istorage), std::forward_as_tuple(std::as_const(dstorage))})>(); testing::StaticAssertTypeEq>, entt::exclude_t>>, decltype(entt::basic_view{std::forward_as_tuple(std::as_const(istorage)), std::forward_as_tuple(std::as_const(dstorage))})>(); - testing::StaticAssertTypeEq>, entt::exclude_t>>, decltype(entt::basic_view{std::forward_as_tuple(istorage), std::forward_as_tuple(sstorage)})>(); + testing::StaticAssertTypeEq>, entt::exclude_t>>, decltype(entt::basic_view{std::forward_as_tuple(istorage), std::forward_as_tuple(sstorage)})>(); } TEST(MultiComponentView, IterableViewAlgorithmCompatibility) { @@ -1293,20 +1289,20 @@ TEST(MultiComponentView, IterableViewAlgorithmCompatibility) { TEST(MultiComponentView, StableType) { entt::registry registry; - auto view = registry.view(); + auto view = registry.view(); const auto entity = registry.create(); const auto other = registry.create(); registry.emplace(entity); registry.emplace(other); - registry.emplace(entity); - registry.emplace(other); + registry.emplace(entity); + registry.emplace(other); registry.destroy(entity); ASSERT_EQ(view.size_hint(), 1u); - view.use(); + view.use(); ASSERT_EQ(view.size_hint(), 2u); ASSERT_FALSE(view.contains(entity)); @@ -1318,11 +1314,11 @@ TEST(MultiComponentView, StableType) { ASSERT_EQ(*view.begin(), other); ASSERT_EQ(++view.begin(), view.end()); - view.each([other](const auto entt, int, pointer_stable) { + view.each([other](const auto entt, int, test::pointer_stable) { ASSERT_EQ(other, entt); }); - view.each([check = true](int, pointer_stable) mutable { + view.each([check = true](int, test::pointer_stable) mutable { ASSERT_TRUE(check); check = false; }); @@ -1330,7 +1326,7 @@ TEST(MultiComponentView, StableType) { for(auto [entt, iv, st]: view.each()) { testing::StaticAssertTypeEq(); testing::StaticAssertTypeEq(); - testing::StaticAssertTypeEq(); + testing::StaticAssertTypeEq(); ASSERT_EQ(other, entt); } @@ -1341,13 +1337,13 @@ TEST(MultiComponentView, StableType) { TEST(MultiComponentView, StableTypeWithExcludedComponent) { entt::registry registry; - auto view = registry.view(entt::exclude); + auto view = registry.view(entt::exclude); const auto entity = registry.create(); const auto other = registry.create(); - registry.emplace(entity, 0); - registry.emplace(other, 42); + registry.emplace(entity, 0); + registry.emplace(other, 42); registry.emplace(entity); ASSERT_EQ(view.size_hint(), 2u); @@ -1629,12 +1625,12 @@ TEST(View, Pipe) { registry.emplace(other); registry.emplace(other); - registry.emplace(other); + registry.emplace(other); auto view1 = registry.view(entt::exclude); auto view2 = registry.view(entt::exclude); auto view3 = registry.view(); - auto view4 = registry.view(); + auto view4 = registry.view(); testing::StaticAssertTypeEq, const entt::storage_type_t>, entt::exclude_t, entt::storage_type_t>>, decltype(view1 | view2)>(); testing::StaticAssertTypeEq, entt::storage_type_t>, entt::exclude_t, const entt::storage_type_t>>, decltype(view2 | view1)>(); @@ -1668,7 +1664,7 @@ TEST(View, Pipe) { ASSERT_EQ(pack14.storage(), nullptr); ASSERT_EQ(pack14.storage(), nullptr); - ASSERT_NE(pack14.storage(), nullptr); + ASSERT_NE(pack14.storage(), nullptr); ASSERT_EQ(pack32.storage(), nullptr); ASSERT_NE(pack32.storage(), nullptr);