Add scene coverage for tag and layer round trip

This commit is contained in:
2026-04-03 15:15:56 +08:00
parent 19bd38ab15
commit 7cc4aa3b45

View File

@@ -292,11 +292,13 @@ TEST_F(SceneTest, FindObjectsOfType) {
}
TEST_F(SceneTest, FindGameObjectWithTag) {
GameObject* go = testScene->CreateGameObject("MyTag");
GameObject* go = testScene->CreateGameObject("TaggedObject");
go->SetTag("MyTag");
GameObject* found = testScene->FindGameObjectWithTag("MyTag");
EXPECT_NE(found, nullptr);
EXPECT_EQ(found, go);
}
TEST_F(SceneTest, OnGameObjectCreated_Event) {
@@ -456,6 +458,8 @@ TEST_F(SceneTest, SerializeToString_And_DeserializeFromString_PreservesHierarchy
testScene->SetActive(false);
GameObject* parent = testScene->CreateGameObject("Parent");
parent->SetTag("Environment");
parent->SetLayer(4);
parent->GetTransform()->SetLocalPosition(Vector3(2.0f, 4.0f, 6.0f));
parent->GetTransform()->SetLocalScale(Vector3(1.5f, 1.5f, 1.5f));
@@ -466,6 +470,8 @@ TEST_F(SceneTest, SerializeToString_And_DeserializeFromString_PreservesHierarchy
light->SetCastsShadows(true);
GameObject* child = testScene->CreateGameObject("Child Camera", parent);
child->SetTag("MainCamera");
child->SetLayer(9);
child->GetTransform()->SetLocalPosition(Vector3(1.0f, 0.0f, -3.0f));
auto* camera = child->AddComponent<CameraComponent>();
@@ -490,9 +496,14 @@ TEST_F(SceneTest, SerializeToString_And_DeserializeFromString_PreservesHierarchy
ASSERT_NE(loadedChild, nullptr);
EXPECT_EQ(loadedChild->GetParent(), loadedParent);
EXPECT_EQ(loadedParent->GetTag(), "Environment");
EXPECT_EQ(loadedParent->GetLayer(), 4u);
EXPECT_EQ(loadedParent->GetTransform()->GetLocalPosition(), Vector3(2.0f, 4.0f, 6.0f));
EXPECT_EQ(loadedParent->GetTransform()->GetLocalScale(), Vector3(1.5f, 1.5f, 1.5f));
EXPECT_EQ(loadedChild->GetTag(), "MainCamera");
EXPECT_EQ(loadedChild->GetLayer(), 9u);
EXPECT_EQ(loadedChild->GetTransform()->GetPosition(), Vector3(3.5f, 4.0f, 1.5f));
EXPECT_EQ(loadedScene.FindGameObjectWithTag("MainCamera"), loadedChild);
auto* loadedLight = loadedParent->GetComponent<LightComponent>();
ASSERT_NE(loadedLight, nullptr);