summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/scene/test_curve_2d.h36
-rw-r--r--tests/scene/test_packed_scene.h65
-rw-r--r--tests/test_main.cpp17
3 files changed, 109 insertions, 9 deletions
diff --git a/tests/scene/test_curve_2d.h b/tests/scene/test_curve_2d.h
index fc141f3d09..099f6fefa9 100644
--- a/tests/scene/test_curve_2d.h
+++ b/tests/scene/test_curve_2d.h
@@ -155,17 +155,37 @@ TEST_CASE("[Curve2D] Sampling") {
SUBCASE("sample_baked_with_rotation") {
const real_t pi = 3.14159;
- Transform2D t = curve->sample_baked_with_rotation(curve->get_closest_offset(Vector2(0, 0)));
- CHECK(t.get_origin() == Vector2(0, 0));
- CHECK(Math::is_equal_approx(t.get_rotation(), pi));
-
- t = curve->sample_baked_with_rotation(curve->get_closest_offset(Vector2(0, 25)));
+ const real_t half_pi = pi * 0.5;
+ Ref<Curve2D> rot_curve = memnew(Curve2D);
+ Transform2D t;
+
+ rot_curve->clear_points();
+ rot_curve->add_point(Vector2());
+ rot_curve->add_point(Vector2(50, 0));
+ t = rot_curve->sample_baked_with_rotation(25);
+ CHECK(t.get_origin() == Vector2(25, 0));
+ CHECK(Math::is_equal_approx(t.get_rotation(), 0));
+
+ rot_curve->clear_points();
+ rot_curve->add_point(Vector2());
+ rot_curve->add_point(Vector2(0, 50));
+ t = rot_curve->sample_baked_with_rotation(25);
CHECK(t.get_origin() == Vector2(0, 25));
- CHECK(Math::is_equal_approx(t.get_rotation(), pi));
+ CHECK(Math::is_equal_approx(t.get_rotation(), half_pi));
- t = curve->sample_baked_with_rotation(curve->get_closest_offset(Vector2(0, 50)));
- CHECK(t.get_origin() == Vector2(0, 50));
+ rot_curve->clear_points();
+ rot_curve->add_point(Vector2());
+ rot_curve->add_point(Vector2(-50, 0));
+ t = rot_curve->sample_baked_with_rotation(25);
+ CHECK(t.get_origin() == Vector2(-25, 0));
CHECK(Math::is_equal_approx(t.get_rotation(), pi));
+
+ rot_curve->clear_points();
+ rot_curve->add_point(Vector2());
+ rot_curve->add_point(Vector2(0, -50));
+ t = rot_curve->sample_baked_with_rotation(25);
+ CHECK(t.get_origin() == Vector2(0, -25));
+ CHECK(Math::is_equal_approx(t.get_rotation(), -half_pi));
}
SUBCASE("get_closest_point") {
diff --git a/tests/scene/test_packed_scene.h b/tests/scene/test_packed_scene.h
index 3517aba31f..1e784c199d 100644
--- a/tests/scene/test_packed_scene.h
+++ b/tests/scene/test_packed_scene.h
@@ -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
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 5187ebd00f..9e020b5d93 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -30,6 +30,8 @@
#include "test_main.h"
+#include "editor/editor_paths.h"
+#include "editor/editor_settings.h"
#include "tests/core/config/test_project_settings.h"
#include "tests/core/input/test_input_event.h"
#include "tests/core/input/test_input_event_key.h"
@@ -221,7 +223,7 @@ struct GodotTestCaseListener : public doctest::IReporter {
String name = String(p_in.m_name);
String suite_name = String(p_in.m_test_suite);
- if (name.find("[SceneTree]") != -1) {
+ if (name.find("[SceneTree]") != -1 || name.find("[Editor]") != -1) {
memnew(MessageQueue);
memnew(Input);
@@ -264,6 +266,13 @@ struct GodotTestCaseListener : public doctest::IReporter {
if (!DisplayServer::get_singleton()->has_feature(DisplayServer::Feature::FEATURE_SUBWINDOWS)) {
SceneTree::get_singleton()->get_root()->set_embedding_subwindows(true);
}
+
+ if (name.find("[Editor]") != -1) {
+ Engine::get_singleton()->set_editor_hint(true);
+ EditorPaths::create();
+ EditorSettings::create();
+ }
+
return;
}
@@ -286,6 +295,12 @@ struct GodotTestCaseListener : public doctest::IReporter {
}
void test_case_end(const doctest::CurrentTestCaseStats &) override {
+ if (EditorSettings::get_singleton()) {
+ EditorSettings::destroy();
+ }
+
+ Engine::get_singleton()->set_editor_hint(false);
+
if (SceneTree::get_singleton()) {
SceneTree::get_singleton()->finalize();
}