From 1c456e2cb669783f21b4f87c9efa6213737fb54b Mon Sep 17 00:00:00 2001 From: skypjack Date: Mon, 23 Feb 2026 08:36:47 +0100 Subject: [PATCH] test: refine common classes to cover both trivially destructible and non trivially destructible types in the storage tests - see #1311 --- test/common/non_trivially_destructible.h | 21 ------------ test/common/pointer_stable.h | 17 ---------- test/common/value_type.h | 42 ++++++++++++++++++++++++ test/entt/entity/helper.cpp | 2 +- test/entt/entity/registry.cpp | 2 +- test/entt/entity/runtime_view.cpp | 2 +- test/entt/entity/sigh_mixin.cpp | 2 +- test/entt/entity/snapshot.cpp | 2 +- test/entt/entity/storage.cpp | 5 ++- test/entt/entity/view.cpp | 2 +- 10 files changed, 50 insertions(+), 47 deletions(-) delete mode 100644 test/common/non_trivially_destructible.h delete mode 100644 test/common/pointer_stable.h create mode 100644 test/common/value_type.h diff --git a/test/common/non_trivially_destructible.h b/test/common/non_trivially_destructible.h deleted file mode 100644 index 04825c620..000000000 --- a/test/common/non_trivially_destructible.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef ENTT_COMMON_NON_TRIVIALLY_DESTRUCTIBLE_H -#define ENTT_COMMON_NON_TRIVIALLY_DESTRUCTIBLE_H - -#include -#include - -namespace test { - -struct non_trivially_destructible final { - ~non_trivially_destructible() {} - [[nodiscard]] constexpr bool operator==(const non_trivially_destructible &) const noexcept = default; - [[nodiscard]] constexpr auto operator<=>(const non_trivially_destructible &) const noexcept = default; - int value{}; -}; - -// ensure non trivially destructible-ness :) -static_assert(!std::is_trivially_destructible_v, "Not a trivially destructible type"); - -} // namespace test - -#endif diff --git a/test/common/pointer_stable.h b/test/common/pointer_stable.h deleted file mode 100644 index 625e9cf50..000000000 --- a/test/common/pointer_stable.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef ENTT_COMMON_POINTER_STABLE_H -#define ENTT_COMMON_POINTER_STABLE_H - -#include - -namespace test { - -struct pointer_stable { - static constexpr auto in_place_delete = true; - [[nodiscard]] constexpr bool operator==(const pointer_stable &other) const noexcept = default; - [[nodiscard]] constexpr auto operator<=>(const pointer_stable &other) const noexcept = default; - int value{}; -}; - -} // namespace test - -#endif diff --git a/test/common/value_type.h b/test/common/value_type.h new file mode 100644 index 000000000..ef072e6fe --- /dev/null +++ b/test/common/value_type.h @@ -0,0 +1,42 @@ +#ifndef ENTT_COMMON_VALUE_TYPE_H +#define ENTT_COMMON_VALUE_TYPE_H + +#include +#include + +namespace test { + +template +struct pointer_stable_mixin: Type... { + static constexpr auto in_place_delete = true; + [[nodiscard]] constexpr bool operator==(const pointer_stable_mixin &) const noexcept = default; + [[nodiscard]] constexpr auto operator<=>(const pointer_stable_mixin &) const noexcept = default; +}; + +template +struct non_trivially_destructible_mixin: Type... { + [[nodiscard]] constexpr bool operator==(const non_trivially_destructible_mixin &) const noexcept = default; + [[nodiscard]] constexpr auto operator<=>(const non_trivially_destructible_mixin &) const noexcept = default; + virtual ~non_trivially_destructible_mixin() = default; +}; + +template +struct value_type final: Type... { + constexpr value_type() = default; + constexpr value_type(int elem): value{elem} {} + [[nodiscard]] constexpr bool operator==(const value_type &) const noexcept = default; + [[nodiscard]] constexpr auto operator<=>(const value_type &) const noexcept = default; + int value{}; +}; + +using pointer_stable = value_type>; +using non_trivially_destructible = value_type>; +using pointer_stable_non_trivially_destructible = value_type>>; + +static_assert(std::is_trivially_destructible_v, "Not a trivially destructible type"); +static_assert(!std::is_trivially_destructible_v, "Trivially destructible type"); +static_assert(!std::is_trivially_destructible_v, "Trivially destructible type"); + +} // namespace test + +#endif diff --git a/test/entt/entity/helper.cpp b/test/entt/entity/helper.cpp index 4b56cf534..d0afbc1cc 100644 --- a/test/entt/entity/helper.cpp +++ b/test/entt/entity/helper.cpp @@ -9,7 +9,7 @@ #include #include #include -#include "../../common/pointer_stable.h" +#include "../../common/value_type.h" struct Invoke: testing::Test { struct clazz { diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index 62a047e5c..efe0054d6 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -24,7 +24,7 @@ #include "../../common/empty.h" #include "../../common/mixin.hpp" #include "../../common/non_default_constructible.h" -#include "../../common/pointer_stable.h" +#include "../../common/value_type.h" struct Registry: testing::Test { enum class my_entity : std::uint32_t {}; diff --git a/test/entt/entity/runtime_view.cpp b/test/entt/entity/runtime_view.cpp index 8e15186b1..e976a026b 100644 --- a/test/entt/entity/runtime_view.cpp +++ b/test/entt/entity/runtime_view.cpp @@ -9,7 +9,7 @@ #include #include #include "../../common/linter.hpp" -#include "../../common/pointer_stable.h" +#include "../../common/value_type.h" template struct RuntimeView: testing::Test { diff --git a/test/entt/entity/sigh_mixin.cpp b/test/entt/entity/sigh_mixin.cpp index 2c818c6db..161fcccc3 100644 --- a/test/entt/entity/sigh_mixin.cpp +++ b/test/entt/entity/sigh_mixin.cpp @@ -14,10 +14,10 @@ #include "../../common/config.h" #include "../../common/linter.hpp" #include "../../common/non_default_constructible.h" -#include "../../common/pointer_stable.h" #include "../../common/registry.h" #include "../../common/throwing_allocator.hpp" #include "../../common/throwing_type.hpp" +#include "../../common/value_type.h" struct SighMixinBase: testing::Test { enum class my_entity : std::uint32_t {}; diff --git a/test/entt/entity/snapshot.cpp b/test/entt/entity/snapshot.cpp index e499635cb..132e1dffe 100644 --- a/test/entt/entity/snapshot.cpp +++ b/test/entt/entity/snapshot.cpp @@ -13,7 +13,7 @@ #include #include "../../common/config.h" #include "../../common/empty.h" -#include "../../common/pointer_stable.h" +#include "../../common/value_type.h" struct SnapshotCommonBase: testing::Test { struct shadow { diff --git a/test/entt/entity/storage.cpp b/test/entt/entity/storage.cpp index 71db1c921..22ce4d9d8 100644 --- a/test/entt/entity/storage.cpp +++ b/test/entt/entity/storage.cpp @@ -16,11 +16,10 @@ #include "../../common/config.h" #include "../../common/linter.hpp" #include "../../common/new_delete.h" -#include "../../common/non_trivially_destructible.h" -#include "../../common/pointer_stable.h" #include "../../common/throwing_allocator.hpp" #include "../../common/throwing_type.hpp" #include "../../common/tracked_memory_resource.hpp" +#include "../../common/value_type.h" struct StorageBase: testing::Test { enum class my_entity : std::uint32_t {}; @@ -87,7 +86,7 @@ struct Storage: StorageBase { template using StorageDeathTest = Storage; -using StorageTypes = ::testing::Types; +using StorageTypes = ::testing::Types; TYPED_TEST_SUITE(Storage, StorageTypes, ); TYPED_TEST_SUITE(StorageDeathTest, StorageTypes, ); diff --git a/test/entt/entity/view.cpp b/test/entt/entity/view.cpp index 955a150ec..4857832be 100644 --- a/test/entt/entity/view.cpp +++ b/test/entt/entity/view.cpp @@ -10,7 +10,7 @@ #include #include "../../common/boxed_type.h" #include "../../common/empty.h" -#include "../../common/pointer_stable.h" +#include "../../common/value_type.h" TEST(ViewSingleStorage, Functionalities) { entt::storage storage{};