feat(editor): unify component registration pipeline
This commit is contained in:
@@ -4,6 +4,7 @@ project(XCEngine_ComponentsTests)
|
||||
|
||||
set(COMPONENTS_TEST_SOURCES
|
||||
test_component.cpp
|
||||
test_component_factory_registry.cpp
|
||||
test_transform_component.cpp
|
||||
test_game_object.cpp
|
||||
test_camera_light_component.cpp
|
||||
|
||||
36
tests/Components/test_component_factory_registry.cpp
Normal file
36
tests/Components/test_component_factory_registry.cpp
Normal 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
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <XCEngine/Components/AudioListenerComponent.h>
|
||||
#include <XCEngine/Components/AudioSourceComponent.h>
|
||||
#include <XCEngine/Scene/Scene.h>
|
||||
#include <XCEngine/Components/CameraComponent.h>
|
||||
#include <XCEngine/Components/GameObject.h>
|
||||
@@ -262,6 +264,30 @@ TEST_F(SceneTest, Save_ContainsGameObjectData) {
|
||||
std::filesystem::remove(scenePath);
|
||||
}
|
||||
|
||||
TEST_F(SceneTest, Save_And_Load_PreservesAudioComponents) {
|
||||
GameObject* listenerObject = testScene->CreateGameObject("Listener");
|
||||
GameObject* sourceObject = testScene->CreateGameObject("Source");
|
||||
|
||||
listenerObject->AddComponent<AudioListenerComponent>();
|
||||
sourceObject->AddComponent<AudioSourceComponent>();
|
||||
|
||||
const std::filesystem::path scenePath = GetTempScenePath("test_scene_audio_components.xc");
|
||||
testScene->Save(scenePath.string());
|
||||
|
||||
Scene loadedScene;
|
||||
loadedScene.Load(scenePath.string());
|
||||
|
||||
GameObject* loadedListenerObject = loadedScene.Find("Listener");
|
||||
GameObject* loadedSourceObject = loadedScene.Find("Source");
|
||||
ASSERT_NE(loadedListenerObject, nullptr);
|
||||
ASSERT_NE(loadedSourceObject, nullptr);
|
||||
|
||||
EXPECT_NE(loadedListenerObject->GetComponent<AudioListenerComponent>(), nullptr);
|
||||
EXPECT_NE(loadedSourceObject->GetComponent<AudioSourceComponent>(), nullptr);
|
||||
|
||||
std::filesystem::remove(scenePath);
|
||||
}
|
||||
|
||||
TEST_F(SceneTest, Save_And_Load_PreservesHierarchyAndComponents) {
|
||||
testScene->SetName("Serialized Scene");
|
||||
testScene->SetActive(false);
|
||||
|
||||
Reference in New Issue
Block a user