table.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <memory>
  2. #include <tuple>
  3. #include <type_traits>
  4. #include <utility>
  5. #include <gtest/gtest.h>
  6. #include <entt/core/iterator.hpp>
  7. #include <entt/entity/table.hpp>
  8. #include "../../common/linter.hpp"
  9. TEST(Table, Constructors) {
  10. entt::table<int, char> table;
  11. ASSERT_NO_THROW([[maybe_unused]] auto alloc = table.get_allocator());
  12. table = entt::table<int, char>{std::allocator<void>{}};
  13. ASSERT_NO_THROW([[maybe_unused]] auto alloc = table.get_allocator());
  14. }
  15. TEST(Table, Move) {
  16. entt::table<int, char> table;
  17. table.emplace(3, 'c');
  18. static_assert(std::is_move_constructible_v<decltype(table)>, "Move constructible type required");
  19. static_assert(std::is_move_assignable_v<decltype(table)>, "Move assignable type required");
  20. entt::table<int, char> other{std::move(table)};
  21. test::is_initialized(table);
  22. ASSERT_TRUE(table.empty());
  23. ASSERT_FALSE(other.empty());
  24. ASSERT_EQ(other[0u], std::make_tuple(3, 'c'));
  25. entt::table<int, char> extended{std::move(other), std::allocator<void>{}};
  26. test::is_initialized(other);
  27. ASSERT_TRUE(other.empty());
  28. ASSERT_FALSE(extended.empty());
  29. ASSERT_EQ(extended[0u], std::make_tuple(3, 'c'));
  30. table = std::move(extended);
  31. test::is_initialized(extended);
  32. ASSERT_FALSE(table.empty());
  33. ASSERT_TRUE(other.empty());
  34. ASSERT_TRUE(extended.empty());
  35. ASSERT_EQ(table[0u], std::make_tuple(3, 'c'));
  36. other = entt::table<int, char>{};
  37. other.emplace(1, 'a');
  38. other = std::move(table);
  39. test::is_initialized(table);
  40. ASSERT_TRUE(table.empty());
  41. ASSERT_FALSE(other.empty());
  42. ASSERT_EQ(other[0u], std::make_tuple(3, 'c'));
  43. }