feat(editor): unify component registration pipeline

This commit is contained in:
2026-03-26 02:24:11 +08:00
parent 1ef3048da1
commit d018a4c82c
17 changed files with 268 additions and 116 deletions

View File

@@ -0,0 +1,36 @@
#include <gtest/gtest.h>
#include <XCEngine/Components/AudioListenerComponent.h>
#include <XCEngine/Components/AudioSourceComponent.h>
#include <XCEngine/Components/CameraComponent.h>
#include <XCEngine/Components/ComponentFactoryRegistry.h>
#include <XCEngine/Components/GameObject.h>
#include <XCEngine/Components/LightComponent.h>
using namespace XCEngine::Components;
namespace {
TEST(ComponentFactoryRegistry_Test, BuiltInTypesAreRegistered) {
auto& registry = ComponentFactoryRegistry::Get();
EXPECT_TRUE(registry.IsRegistered("Camera"));
EXPECT_TRUE(registry.IsRegistered("Light"));
EXPECT_TRUE(registry.IsRegistered("AudioSource"));
EXPECT_TRUE(registry.IsRegistered("AudioListener"));
EXPECT_FALSE(registry.IsRegistered("Transform"));
EXPECT_FALSE(registry.IsRegistered("MissingComponent"));
}
TEST(ComponentFactoryRegistry_Test, CreateBuiltInComponentsByTypeName) {
GameObject gameObject("FactoryTarget");
auto& registry = ComponentFactoryRegistry::Get();
EXPECT_NE(dynamic_cast<CameraComponent*>(registry.CreateComponent(&gameObject, "Camera")), nullptr);
EXPECT_NE(dynamic_cast<LightComponent*>(registry.CreateComponent(&gameObject, "Light")), nullptr);
EXPECT_NE(dynamic_cast<AudioSourceComponent*>(registry.CreateComponent(&gameObject, "AudioSource")), nullptr);
EXPECT_NE(dynamic_cast<AudioListenerComponent*>(registry.CreateComponent(&gameObject, "AudioListener")), nullptr);
EXPECT_EQ(registry.CreateComponent(&gameObject, "MissingComponent"), nullptr);
}
} // namespace