test: refine common classes to cover both trivially destructible and non trivially destructible types in the storage tests - see #1311

This commit is contained in:
skypjack
2026-02-23 08:36:47 +01:00
parent 17fc67de1f
commit 1c456e2cb6
10 changed files with 50 additions and 47 deletions

View File

@@ -1,21 +0,0 @@
#ifndef ENTT_COMMON_NON_TRIVIALLY_DESTRUCTIBLE_H
#define ENTT_COMMON_NON_TRIVIALLY_DESTRUCTIBLE_H
#include <compare>
#include <type_traits>
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<test::non_trivially_destructible>, "Not a trivially destructible type");
} // namespace test
#endif

View File

@@ -1,17 +0,0 @@
#ifndef ENTT_COMMON_POINTER_STABLE_H
#define ENTT_COMMON_POINTER_STABLE_H
#include <compare>
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

42
test/common/value_type.h Normal file
View File

@@ -0,0 +1,42 @@
#ifndef ENTT_COMMON_VALUE_TYPE_H
#define ENTT_COMMON_VALUE_TYPE_H
#include <compare>
#include <type_traits>
namespace test {
template<typename... Type>
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<typename... Type>
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<typename... Type>
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<pointer_stable_mixin<>>;
using non_trivially_destructible = value_type<non_trivially_destructible_mixin<>>;
using pointer_stable_non_trivially_destructible = value_type<pointer_stable_mixin<non_trivially_destructible_mixin<>>>;
static_assert(std::is_trivially_destructible_v<test::pointer_stable>, "Not a trivially destructible type");
static_assert(!std::is_trivially_destructible_v<test::non_trivially_destructible>, "Trivially destructible type");
static_assert(!std::is_trivially_destructible_v<test::pointer_stable_non_trivially_destructible>, "Trivially destructible type");
} // namespace test
#endif

View File

@@ -9,7 +9,7 @@
#include <entt/entity/storage.hpp>
#include <entt/entity/view.hpp>
#include <entt/signal/sigh.hpp>
#include "../../common/pointer_stable.h"
#include "../../common/value_type.h"
struct Invoke: testing::Test {
struct clazz {

View File

@@ -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 {};

View File

@@ -9,7 +9,7 @@
#include <entt/entity/runtime_view.hpp>
#include <entt/entity/storage.hpp>
#include "../../common/linter.hpp"
#include "../../common/pointer_stable.h"
#include "../../common/value_type.h"
template<typename Type>
struct RuntimeView: testing::Test {

View File

@@ -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 {};

View File

@@ -13,7 +13,7 @@
#include <entt/signal/sigh.hpp>
#include "../../common/config.h"
#include "../../common/empty.h"
#include "../../common/pointer_stable.h"
#include "../../common/value_type.h"
struct SnapshotCommonBase: testing::Test {
struct shadow {

View File

@@ -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<typename Type>
using StorageDeathTest = Storage<Type>;
using StorageTypes = ::testing::Types<int, test::pointer_stable, test::non_trivially_destructible>;
using StorageTypes = ::testing::Types<int, test::pointer_stable, test::non_trivially_destructible, test::pointer_stable_non_trivially_destructible>;
TYPED_TEST_SUITE(Storage, StorageTypes, );
TYPED_TEST_SUITE(StorageDeathTest, StorageTypes, );

View File

@@ -10,7 +10,7 @@
#include <entt/entity/view.hpp>
#include "../../common/boxed_type.h"
#include "../../common/empty.h"
#include "../../common/pointer_stable.h"
#include "../../common/value_type.h"
TEST(ViewSingleStorage, Functionalities) {
entt::storage<char> storage{};