Browse Source

test: put basic test allocator in its own file

Michele Caini 4 years ago
parent
commit
28e38321ee
2 changed files with 30 additions and 15 deletions
  1. 28 0
      test/entt/common/basic_test_allocator.hpp
  2. 2 15
      test/entt/core/memory.cpp

+ 28 - 0
test/entt/common/basic_test_allocator.hpp

@@ -0,0 +1,28 @@
+#ifndef ENTT_COMMON_BASIC_TEST_ALLOCATOR_HPP
+#define ENTT_COMMON_BASIC_TEST_ALLOCATOR_HPP
+
+#include <memory>
+#include <type_traits>
+
+namespace test {
+
+template<typename Type>
+struct basic_test_allocator: std::allocator<Type> {
+    // basic pocca/pocma/pocs allocator
+
+    using base = std::allocator<Type>;
+    using propagate_on_container_copy_assignment = std::true_type;
+    using propagate_on_container_swap = std::true_type;
+
+    using std::allocator<Type>::allocator;
+
+    basic_test_allocator &operator=(const basic_test_allocator &other) {
+        // necessary to avoid call suppression
+        base::operator=(other);
+        return *this;
+    }
+};
+
+} // namespace test
+
+#endif

+ 2 - 15
test/entt/core/memory.cpp

@@ -6,22 +6,9 @@
 #include <utility>
 #include <gtest/gtest.h>
 #include <entt/core/memory.hpp>
+#include "../common/basic_test_allocator.hpp"
 #include "../common/throwing_allocator.hpp"
 
-struct test_allocator: std::allocator<int> {
-    using base = std::allocator<int>;
-    using propagate_on_container_copy_assignment = std::true_type;
-    using propagate_on_container_swap = std::true_type;
-
-    using std::allocator<int>::allocator;
-
-    test_allocator &operator=(const test_allocator &other) {
-        // necessary to avoid call suppression
-        base::operator=(other);
-        return *this;
-    }
-};
-
 TEST(Memory, ToAddress) {
     std::shared_ptr<int> shared = std::make_shared<int>();
     auto *plain = std::addressof(*shared);
@@ -31,7 +18,7 @@ TEST(Memory, ToAddress) {
 }
 
 TEST(Memory, PoccaPocmaAndPocs) {
-    test_allocator lhs, rhs;
+    test::basic_test_allocator<int> lhs, rhs;
     // honestly, I don't even know how one is supposed to test such a thing :)
     entt::propagate_on_container_copy_assignment(lhs, rhs);
     entt::propagate_on_container_move_assignment(lhs, rhs);