Skip to content

Commit

Permalink
Merge pull request #80819 from sepTN/test-packed-scene-v3
Browse files Browse the repository at this point in the history
Improve PackedScene unit test by covering more methods
  • Loading branch information
akien-mga committed Jan 4, 2024
2 parents ea3e3b0 + a31120b commit 8ac6742
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/scene/test_packed_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,71 @@ TEST_CASE("[PackedScene] Instantiate Packed Scene With Children") {
memdelete(instance);
}

TEST_CASE("[PackedScene] Set Path") {
// Create a scene to pack.
Node *scene = memnew(Node);
scene->set_name("TestScene");

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

// Set a new path for the packed scene.
const String new_path = "NewTestPath";
packed_scene.set_path(new_path);

// Check if the path has been set correctly.
Ref<SceneState> state = packed_scene.get_state();
CHECK(state.is_valid());
CHECK(state->get_path() == new_path);

memdelete(scene);
}

TEST_CASE("[PackedScene] Replace State") {
// Create a scene to pack.
Node *scene = memnew(Node);
scene->set_name("TestScene");

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

// Create another scene state to replace with.
Ref<SceneState> new_state = memnew(SceneState);
new_state->set_path("NewPath");

// Replace the state.
packed_scene.replace_state(new_state);

// Check if the state has been replaced.
Ref<SceneState> state = packed_scene.get_state();
CHECK(state.is_valid());
CHECK(state == new_state);

memdelete(scene);
}

TEST_CASE("[PackedScene] Recreate State") {
// Create a scene to pack.
Node *scene = memnew(Node);
scene->set_name("TestScene");

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

// Recreate the state.
packed_scene.recreate_state();

// Check if the state has been recreated.
Ref<SceneState> state = packed_scene.get_state();
CHECK(state.is_valid());
CHECK(state->get_node_count() == 0); // Since the state was recreated, it should be empty.

memdelete(scene);
}

} // namespace TestPackedScene

#endif // TEST_PACKED_SCENE_H

0 comments on commit 8ac6742

Please sign in to comment.