Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PackedScene unit test for complex scene #80423

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions tests/scene/test_packed_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,47 @@ TEST_CASE("[PackedScene] Instantiate Packed Scene") {
memdelete(instance);
}

TEST_CASE("[PackedScene] Instantiate Packed Scene With Children") {
// Create a scene to pack.
Node *scene = memnew(Node);
scene->set_name("TestScene");

// Add persisting child nodes to the scene.
Node *child1 = memnew(Node);
child1->set_name("Child1");
scene->add_child(child1);
child1->set_owner(scene);

Node *child2 = memnew(Node);
child2->set_name("Child2");
scene->add_child(child2);
child2->set_owner(scene);

// Add non persisting child node to the scene.
Node *child3 = memnew(Node);
child3->set_name("Child3");
scene->add_child(child3);

// Pack the scene.
PackedScene packed_scene;
packed_scene.pack(scene);

// Instantiate the packed scene.
Node *instance = packed_scene.instantiate();
CHECK(instance != nullptr);
CHECK(instance->get_name() == "TestScene");

// Validate the child nodes of the instantiated scene.
CHECK(instance->get_child_count() == 2);
CHECK(instance->get_child(0)->get_name() == "Child1");
CHECK(instance->get_child(1)->get_name() == "Child2");
CHECK(instance->get_child(0)->get_owner() == instance);
CHECK(instance->get_child(1)->get_owner() == instance);

memdelete(scene);
memdelete(instance);
}

} // namespace TestPackedScene

#endif // TEST_PACKED_SCENE_H
Loading