Bladeren bron

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

skypjack 1 week geleden
bovenliggende
commit
1c456e2cb6

+ 0 - 21
test/common/non_trivially_destructible.h

@@ -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

+ 0 - 17
test/common/pointer_stable.h

@@ -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 - 0
test/common/value_type.h

@@ -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

+ 1 - 1
test/entt/entity/helper.cpp

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

+ 1 - 1
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 {};

+ 1 - 1
test/entt/entity/runtime_view.cpp

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

+ 1 - 1
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 {};

+ 1 - 1
test/entt/entity/snapshot.cpp

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

+ 2 - 3
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<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, );

+ 1 - 1
test/entt/entity/view.cpp

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