Kaynağa Gözat

test: meta_factory::type

Michele Caini 1 yıl önce
ebeveyn
işleme
5a502466aa
1 değiştirilmiş dosya ile 28 ekleme ve 0 silme
  1. 28 0
      test/entt/meta/meta_factory.cpp

+ 28 - 0
test/entt/meta/meta_factory.cpp

@@ -4,6 +4,7 @@
 #include <entt/meta/factory.hpp>
 #include <entt/meta/meta.hpp>
 #include <entt/meta/resolve.hpp>
+#include "../../common/config.h"
 
 struct MetaFactory: ::testing::Test {
     void TearDown() override {
@@ -35,3 +36,30 @@ TEST_F(MetaFactory, Constructors) {
     // this is because of entt::meta, which should be deprecated nowadays
     ASSERT_FALSE(entt::resolve(ctx, entt::type_id<int>()).is_integral());
 }
+
+TEST_F(MetaFactory, Type) {
+    using namespace entt::literals;
+
+    entt::meta_factory<int> factory{};
+
+    ASSERT_EQ(entt::resolve<int>().id(), entt::id_type{});
+
+    factory.type("foo"_hs);
+
+    ASSERT_EQ(entt::resolve<int>().id(), "foo"_hs);
+
+    factory.type("bar"_hs);
+
+    ASSERT_EQ(entt::resolve<int>().id(), "bar"_hs);
+}
+
+ENTT_DEBUG_TEST_F(MetaFactoryDeathTest, Type) {
+    using namespace entt::literals;
+
+    entt::meta_factory<int> factory{};
+    entt::meta_factory<double> other{};
+
+    factory.type("foo"_hs);
+
+    ASSERT_DEATH(other.type("foo"_hs);, "");
+}