🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.1 KiB

  1. #include <gtest/gtest.h>
  2. #include <entt/core/hashed_string.hpp>
  3. #include <entt/entity/registry.hpp>
  4. enum class my_entity : entt::id_type {};
  5. TEST(Example, EntityCopy) {
  6. using namespace entt::literals;
  7. entt::registry registry{};
  8. auto &&custom = registry.storage<double>("custom"_hs);
  9. const auto src = registry.create();
  10. const auto dst = registry.create();
  11. const auto other = registry.create();
  12. custom.emplace(src, 1.);
  13. registry.emplace<int>(src, 42);
  14. registry.emplace<char>(src, 'c');
  15. registry.emplace<double>(other, 3.);
  16. ASSERT_TRUE(custom.contains(src));
  17. ASSERT_FALSE(registry.all_of<double>(src));
  18. ASSERT_TRUE((registry.all_of<int, char>(src)));
  19. ASSERT_FALSE((registry.any_of<int, char, double>(dst)));
  20. ASSERT_FALSE(custom.contains(dst));
  21. for(auto [id, storage]: registry.storage()) {
  22. // discard the custom storage because why not, this is just an example after all
  23. if(id != "custom"_hs && storage.contains(src)) {
  24. storage.emplace(dst, storage.get(src));
  25. }
  26. }
  27. ASSERT_TRUE((registry.all_of<int, char>(dst)));
  28. ASSERT_FALSE((registry.all_of<double>(dst)));
  29. ASSERT_FALSE(custom.contains(dst));
  30. ASSERT_EQ(registry.get<int>(dst), 42);
  31. ASSERT_EQ(registry.get<char>(dst), 'c');
  32. }
  33. TEST(Example, DifferentRegistryTypes) {
  34. using namespace entt::literals;
  35. entt::basic_registry<entt::entity> registry{};
  36. entt::basic_registry<my_entity> other{};
  37. static_cast<void>(registry.storage<double>());
  38. static_cast<void>(other.storage<int>());
  39. const auto src = registry.create();
  40. const auto dst = other.create();
  41. registry.emplace<int>(src, 42);
  42. registry.emplace<char>(src, 'c');
  43. for(auto [id, storage]: registry.storage()) {
  44. if(auto it = other.storage(id); it != other.storage().end() && storage.contains(src)) {
  45. it->second.emplace(dst, storage.get(src));
  46. }
  47. }
  48. ASSERT_TRUE((registry.all_of<int, char>(src)));
  49. ASSERT_FALSE(other.all_of<char>(dst));
  50. ASSERT_TRUE(other.all_of<int>(dst));
  51. ASSERT_EQ(other.get<int>(dst), 42);
  52. }