Skip to content

Commit

Permalink
Improve PackedScene unit test for complex scene
Browse files Browse the repository at this point in the history
  • Loading branch information
sepTN committed Aug 8, 2023
1 parent f2acfb1 commit 56d7ff6
Showing 1 changed file with 41 additions and 0 deletions.
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

0 comments on commit 56d7ff6

Please sign in to comment.