diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/io/test_http_client.h | 4 | ||||
-rw-r--r-- | tests/core/io/test_image.h | 22 | ||||
-rw-r--r-- | tests/core/math/test_basis.h | 18 | ||||
-rw-r--r-- | tests/core/object/test_class_db.h | 6 | ||||
-rw-r--r-- | tests/scene/test_graph_node.h | 2 | ||||
-rw-r--r-- | tests/scene/test_path_follow_2d.h | 128 | ||||
-rw-r--r-- | tests/scene/test_path_follow_3d.h | 197 | ||||
-rw-r--r-- | tests/test_main.cpp | 25 |
8 files changed, 273 insertions, 129 deletions
diff --git a/tests/core/io/test_http_client.h b/tests/core/io/test_http_client.h index 96a7735d03..961c653a0a 100644 --- a/tests/core/io/test_http_client.h +++ b/tests/core/io/test_http_client.h @@ -35,6 +35,8 @@ #include "tests/test_macros.h" +#include "modules/modules_enabled.gen.h" + namespace TestHTTPClient { TEST_CASE("[HTTPClient] Instantiation") { @@ -90,6 +92,7 @@ TEST_CASE("[HTTPClient] verify_headers") { ERR_PRINT_ON; } +#if defined(MODULE_MBEDTLS_ENABLED) || defined(WEB_ENABLED) TEST_CASE("[HTTPClient] connect_to_host") { Ref<HTTPClient> client = HTTPClient::create(); String host = "https://www.example.com"; @@ -100,6 +103,7 @@ TEST_CASE("[HTTPClient] connect_to_host") { Error err = client->connect_to_host(host, port, tls_options); CHECK_MESSAGE(err == OK, "Expected OK for successful connection"); } +#endif // MODULE_MBEDTLS_ENABLED || WEB_ENABLED } // namespace TestHTTPClient diff --git a/tests/core/io/test_image.h b/tests/core/io/test_image.h index 1b51286a9f..0698c60f2a 100644 --- a/tests/core/io/test_image.h +++ b/tests/core/io/test_image.h @@ -37,6 +37,8 @@ #include "tests/test_utils.h" #include "thirdparty/doctest/doctest.h" +#include "modules/modules_enabled.gen.h" + namespace TestImage { TEST_CASE("[Image] Instantiation") { @@ -107,6 +109,7 @@ TEST_CASE("[Image] Saving and loading") { image->get_data() == image_load->get_data(), "The loaded image should have the same data as the one that got saved."); +#ifdef MODULE_BMP_ENABLED // Load BMP Ref<Image> image_bmp = memnew(Image()); Ref<FileAccess> f_bmp = FileAccess::open(TestUtils::get_data_path("images/icon.bmp"), FileAccess::READ, &err); @@ -117,7 +120,9 @@ TEST_CASE("[Image] Saving and loading") { CHECK_MESSAGE( image_bmp->load_bmp_from_buffer(data_bmp) == OK, "The BMP image should load successfully."); +#endif // MODULE_BMP_ENABLED +#ifdef MODULE_JPG_ENABLED // Load JPG Ref<Image> image_jpg = memnew(Image()); Ref<FileAccess> f_jpg = FileAccess::open(TestUtils::get_data_path("images/icon.jpg"), FileAccess::READ, &err); @@ -128,7 +133,9 @@ TEST_CASE("[Image] Saving and loading") { CHECK_MESSAGE( image_jpg->load_jpg_from_buffer(data_jpg) == OK, "The JPG image should load successfully."); +#endif // MODULE_JPG_ENABLED +#ifdef MODULE_WEBP_ENABLED // Load WebP Ref<Image> image_webp = memnew(Image()); Ref<FileAccess> f_webp = FileAccess::open(TestUtils::get_data_path("images/icon.webp"), FileAccess::READ, &err); @@ -139,6 +146,7 @@ TEST_CASE("[Image] Saving and loading") { CHECK_MESSAGE( image_webp->load_webp_from_buffer(data_webp) == OK, "The WebP image should load successfully."); +#endif // MODULE_WEBP_ENABLED // Load PNG Ref<Image> image_png = memnew(Image()); @@ -151,6 +159,7 @@ TEST_CASE("[Image] Saving and loading") { image_png->load_png_from_buffer(data_png) == OK, "The PNG image should load successfully."); +#ifdef MODULE_TGA_ENABLED // Load TGA Ref<Image> image_tga = memnew(Image()); Ref<FileAccess> f_tga = FileAccess::open(TestUtils::get_data_path("images/icon.tga"), FileAccess::READ, &err); @@ -161,6 +170,7 @@ TEST_CASE("[Image] Saving and loading") { CHECK_MESSAGE( image_tga->load_tga_from_buffer(data_tga) == OK, "The TGA image should load successfully."); +#endif // MODULE_TGA_ENABLED } TEST_CASE("[Image] Basic getters") { @@ -345,8 +355,8 @@ TEST_CASE("[Image] Custom mipmaps") { uint8_t *data_ptr = data.ptrw(); for (int mip = 0; mip < mipmaps; mip++) { - int mip_offset = 0; - int mip_size = 0; + int64_t mip_offset = 0; + int64_t mip_size = 0; image->get_mipmap_offset_and_size(mip, mip_offset, mip_size); for (int i = 0; i < mip_size; i++) { @@ -368,8 +378,8 @@ TEST_CASE("[Image] Custom mipmaps") { const uint8_t *data_ptr = data.ptr(); for (int mip = 0; mip < mipmaps; mip++) { - int mip_offset = 0; - int mip_size = 0; + int64_t mip_offset = 0; + int64_t mip_size = 0; image_bytes->get_mipmap_offset_and_size(mip, mip_offset, mip_size); for (int i = 0; i < mip_size; i++) { @@ -392,8 +402,8 @@ TEST_CASE("[Image] Custom mipmaps") { const uint8_t *data_ptr = data.ptr(); for (int mip = 0; mip < mipmaps; mip++) { - int mip_offset = 0; - int mip_size = 0; + int64_t mip_offset = 0; + int64_t mip_size = 0; image_rgbaf->get_mipmap_offset_and_size(mip, mip_offset, mip_size); for (int i = 0; i < mip_size; i += 4) { diff --git a/tests/core/math/test_basis.h b/tests/core/math/test_basis.h index a9bc2e9b99..f8c5ef279d 100644 --- a/tests/core/math/test_basis.h +++ b/tests/core/math/test_basis.h @@ -93,9 +93,9 @@ void test_rotation(Vector3 deg_original_euler, EulerOrder rot_order) { Basis res = to_rotation.inverse() * rotation_from_computed_euler; - CHECK_MESSAGE((res.get_column(0) - Vector3(1.0, 0.0, 0.0)).length() <= 0.1, vformat("Fail due to X %s\n", String(res.get_column(0))).utf8().ptr()); - CHECK_MESSAGE((res.get_column(1) - Vector3(0.0, 1.0, 0.0)).length() <= 0.1, vformat("Fail due to Y %s\n", String(res.get_column(1))).utf8().ptr()); - CHECK_MESSAGE((res.get_column(2) - Vector3(0.0, 0.0, 1.0)).length() <= 0.1, vformat("Fail due to Z %s\n", String(res.get_column(2))).utf8().ptr()); + CHECK_MESSAGE((res.get_column(0) - Vector3(1.0, 0.0, 0.0)).length() <= 0.1, vformat("Fail due to X %s\n", String(res.get_column(0)))); + CHECK_MESSAGE((res.get_column(1) - Vector3(0.0, 1.0, 0.0)).length() <= 0.1, vformat("Fail due to Y %s\n", String(res.get_column(1)))); + CHECK_MESSAGE((res.get_column(2) - Vector3(0.0, 0.0, 1.0)).length() <= 0.1, vformat("Fail due to Z %s\n", String(res.get_column(2)))); // Double check `to_rotation` decomposing with XYZ rotation order. const Vector3 euler_xyz_from_rotation = to_rotation.get_euler(EulerOrder::XYZ); @@ -103,13 +103,13 @@ void test_rotation(Vector3 deg_original_euler, EulerOrder rot_order) { res = to_rotation.inverse() * rotation_from_xyz_computed_euler; - CHECK_MESSAGE((res.get_column(0) - Vector3(1.0, 0.0, 0.0)).length() <= 0.1, vformat("Double check with XYZ rot order failed, due to X %s\n", String(res.get_column(0))).utf8().ptr()); - CHECK_MESSAGE((res.get_column(1) - Vector3(0.0, 1.0, 0.0)).length() <= 0.1, vformat("Double check with XYZ rot order failed, due to Y %s\n", String(res.get_column(1))).utf8().ptr()); - CHECK_MESSAGE((res.get_column(2) - Vector3(0.0, 0.0, 1.0)).length() <= 0.1, vformat("Double check with XYZ rot order failed, due to Z %s\n", String(res.get_column(2))).utf8().ptr()); + CHECK_MESSAGE((res.get_column(0) - Vector3(1.0, 0.0, 0.0)).length() <= 0.1, vformat("Double check with XYZ rot order failed, due to X %s\n", String(res.get_column(0)))); + CHECK_MESSAGE((res.get_column(1) - Vector3(0.0, 1.0, 0.0)).length() <= 0.1, vformat("Double check with XYZ rot order failed, due to Y %s\n", String(res.get_column(1)))); + CHECK_MESSAGE((res.get_column(2) - Vector3(0.0, 0.0, 1.0)).length() <= 0.1, vformat("Double check with XYZ rot order failed, due to Z %s\n", String(res.get_column(2)))); - INFO(vformat("Rotation order: %s\n.", get_rot_order_name(rot_order)).utf8().ptr()); - INFO(vformat("Original Rotation: %s\n", String(deg_original_euler)).utf8().ptr()); - INFO(vformat("Quaternion to rotation order: %s\n", String(rad2deg(euler_from_rotation))).utf8().ptr()); + INFO(vformat("Rotation order: %s\n.", get_rot_order_name(rot_order))); + INFO(vformat("Original Rotation: %s\n", String(deg_original_euler))); + INFO(vformat("Quaternion to rotation order: %s\n", String(rad2deg(euler_from_rotation)))); } TEST_CASE("[Basis] Euler conversions") { diff --git a/tests/core/object/test_class_db.h b/tests/core/object/test_class_db.h index 358bbc08a3..c1aa39031d 100644 --- a/tests/core/object/test_class_db.h +++ b/tests/core/object/test_class_db.h @@ -405,7 +405,7 @@ void validate_argument(const Context &p_context, const ExposedClass &p_class, co err_msg += " " + type_error_msg; } - TEST_COND(!arg_defval_assignable_to_type, err_msg.utf8().get_data()); + TEST_COND(!arg_defval_assignable_to_type, err_msg); } } @@ -590,7 +590,7 @@ void add_exposed_classes(Context &r_context) { exposed_class.name, method.name); TEST_FAIL_COND_WARN( (exposed_class.name != r_context.names_cache.object_class || String(method.name) != "free"), - warn_msg.utf8().get_data()); + warn_msg); } else if (return_info.type == Variant::INT && return_info.usage & (PROPERTY_USAGE_CLASS_IS_ENUM | PROPERTY_USAGE_CLASS_IS_BITFIELD)) { method.return_type.name = return_info.class_name; @@ -720,7 +720,7 @@ void add_exposed_classes(Context &r_context) { "Signal name conflicts with %s: '%s.%s.", method_conflict ? "method" : "property", class_name, signal.name); TEST_FAIL_COND((method_conflict || exposed_class.find_method_by_name(signal.name)), - warn_msg.utf8().get_data()); + warn_msg); exposed_class.signals_.push_back(signal); } diff --git a/tests/scene/test_graph_node.h b/tests/scene/test_graph_node.h index 72b8b682c9..bf6cc9be09 100644 --- a/tests/scene/test_graph_node.h +++ b/tests/scene/test_graph_node.h @@ -42,7 +42,7 @@ TEST_CASE("[GraphNode][SceneTree]") { SUBCASE("[GraphNode] Graph Node only child on delete should not cause error.") { // Setup. GraphNode *test_node = memnew(GraphNode); - test_child->set_name("Graph Node"); + test_node->set_name("Graph Node"); Control *test_child = memnew(Control); test_child->set_name("child"); test_node->add_child(test_child); diff --git a/tests/scene/test_path_follow_2d.h b/tests/scene/test_path_follow_2d.h index 1958befa18..45ae0dff5d 100644 --- a/tests/scene/test_path_follow_2d.h +++ b/tests/scene/test_path_follow_2d.h @@ -32,205 +32,223 @@ #define TEST_PATH_FOLLOW_2D_H #include "scene/2d/path_2d.h" +#include "scene/main/window.h" #include "tests/test_macros.h" namespace TestPathFollow2D { -TEST_CASE("[PathFollow2D] Sampling with progress ratio") { - const Ref<Curve2D> &curve = memnew(Curve2D()); +bool is_equal_approx(const Vector2 &p_a, const Vector2 &p_b) { + const real_t tolerance = 0.001; + return Math::is_equal_approx(p_a.x, p_b.x, tolerance) && + Math::is_equal_approx(p_a.y, p_b.y, tolerance); +} + +TEST_CASE("[SceneTree][PathFollow2D] Sampling with progress ratio") { + Ref<Curve2D> curve = memnew(Curve2D); + curve->set_bake_interval(1); curve->add_point(Vector2(0, 0)); curve->add_point(Vector2(100, 0)); curve->add_point(Vector2(100, 100)); curve->add_point(Vector2(0, 100)); curve->add_point(Vector2(0, 0)); - const Path2D *path = memnew(Path2D); + Path2D *path = memnew(Path2D); path->set_curve(curve); - const PathFollow2D *path_follow_2d = memnew(PathFollow2D); + PathFollow2D *path_follow_2d = memnew(PathFollow2D); + path_follow_2d->set_loop(false); path->add_child(path_follow_2d); + SceneTree::get_singleton()->get_root()->add_child(path); path_follow_2d->set_progress_ratio(0); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(0, 0))); + CHECK(is_equal_approx(Vector2(0, 0), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress_ratio(0.125); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(50, 0))); + CHECK(is_equal_approx(Vector2(50, 0), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress_ratio(0.25); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(100, 0))); + CHECK(is_equal_approx(Vector2(100, 0), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress_ratio(0.375); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(100, 50))); + CHECK(is_equal_approx(Vector2(100, 50), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress_ratio(0.5); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(100, 100))); + CHECK(is_equal_approx(Vector2(100, 100), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress_ratio(0.625); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(50, 100))); + CHECK(is_equal_approx(Vector2(50, 100), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress_ratio(0.75); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(0, 100))); + CHECK(is_equal_approx(Vector2(0, 100), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress_ratio(0.875); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(0, 50))); + CHECK(is_equal_approx(Vector2(0, 50), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress_ratio(1); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(0, 0))); + CHECK(is_equal_approx(Vector2(0, 0), path_follow_2d->get_transform().get_origin())); memdelete(path); } -TEST_CASE("[PathFollow2D] Sampling with progress") { - const Ref<Curve2D> &curve = memnew(Curve2D()); +TEST_CASE("[SceneTree][PathFollow2D] Sampling with progress") { + Ref<Curve2D> curve = memnew(Curve2D); + curve->set_bake_interval(1); curve->add_point(Vector2(0, 0)); curve->add_point(Vector2(100, 0)); curve->add_point(Vector2(100, 100)); curve->add_point(Vector2(0, 100)); curve->add_point(Vector2(0, 0)); - const Path2D *path = memnew(Path2D); + Path2D *path = memnew(Path2D); path->set_curve(curve); - const PathFollow2D *path_follow_2d = memnew(PathFollow2D); + PathFollow2D *path_follow_2d = memnew(PathFollow2D); + path_follow_2d->set_loop(false); path->add_child(path_follow_2d); + SceneTree::get_singleton()->get_root()->add_child(path); path_follow_2d->set_progress(0); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(0, 0))); + CHECK(is_equal_approx(Vector2(0, 0), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress(50); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(50, 0))); + CHECK(is_equal_approx(Vector2(50, 0), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress(100); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(100, 0))); + CHECK(is_equal_approx(Vector2(100, 0), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress(150); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(100, 50))); + CHECK(is_equal_approx(Vector2(100, 50), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress(200); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(100, 100))); + CHECK(is_equal_approx(Vector2(100, 100), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress(250); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(50, 100))); + CHECK(is_equal_approx(Vector2(50, 100), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress(300); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(0, 100))); + CHECK(is_equal_approx(Vector2(0, 100), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress(350); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(0, 50))); + CHECK(is_equal_approx(Vector2(0, 50), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_progress(400); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(0, 0))); + CHECK(is_equal_approx(Vector2(0, 0), path_follow_2d->get_transform().get_origin())); memdelete(path); } -TEST_CASE("[PathFollow2D] Removal of a point in curve") { - const Ref<Curve2D> &curve = memnew(Curve2D()); +TEST_CASE("[SceneTree][PathFollow2D] Removal of a point in curve") { + Ref<Curve2D> curve = memnew(Curve2D); curve->add_point(Vector2(0, 0)); curve->add_point(Vector2(100, 0)); curve->add_point(Vector2(100, 100)); - const Path2D *path = memnew(Path2D); + Path2D *path = memnew(Path2D); path->set_curve(curve); - const PathFollow2D *path_follow_2d = memnew(PathFollow2D); + PathFollow2D *path_follow_2d = memnew(PathFollow2D); path->add_child(path_follow_2d); + SceneTree::get_singleton()->get_root()->add_child(path); path_follow_2d->set_progress_ratio(0.5); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(100, 0))); + CHECK(is_equal_approx(Vector2(100, 0), path_follow_2d->get_transform().get_origin())); curve->remove_point(1); + path_follow_2d->set_progress_ratio(0.5); CHECK_MESSAGE( - path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(50, 50)), + is_equal_approx(Vector2(50, 50), path_follow_2d->get_transform().get_origin()), "Path follow's position should be updated after removing a point from the curve"); memdelete(path); } -TEST_CASE("[PathFollow2D] Setting h_offset and v_offset") { - const Ref<Curve2D> &curve = memnew(Curve2D()); +TEST_CASE("[SceneTree][PathFollow2D] Setting h_offset and v_offset") { + Ref<Curve2D> curve = memnew(Curve2D); curve->add_point(Vector2(0, 0)); curve->add_point(Vector2(100, 0)); - const Path2D *path = memnew(Path2D); + Path2D *path = memnew(Path2D); path->set_curve(curve); - const PathFollow2D *path_follow_2d = memnew(PathFollow2D); + PathFollow2D *path_follow_2d = memnew(PathFollow2D); path->add_child(path_follow_2d); + SceneTree::get_singleton()->get_root()->add_child(path); path_follow_2d->set_progress_ratio(0.5); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(50, 0))); + CHECK(is_equal_approx(Vector2(50, 0), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_h_offset(25); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(75, 0))); + CHECK(is_equal_approx(Vector2(75, 0), path_follow_2d->get_transform().get_origin())); path_follow_2d->set_v_offset(25); - CHECK(path_follow_2d->get_transform().get_origin().is_equal_approx(Vector2(75, 25))); + CHECK(is_equal_approx(Vector2(75, 25), path_follow_2d->get_transform().get_origin())); memdelete(path); } -TEST_CASE("[PathFollow2D] Unit offset out of range") { - const Ref<Curve2D> &curve = memnew(Curve2D()); +TEST_CASE("[SceneTree][PathFollow2D] Progress ratio out of range") { + Ref<Curve2D> curve = memnew(Curve2D); curve->add_point(Vector2(0, 0)); curve->add_point(Vector2(100, 0)); - const Path2D *path = memnew(Path2D); + Path2D *path = memnew(Path2D); path->set_curve(curve); - const PathFollow2D *path_follow_2d = memnew(PathFollow2D); + PathFollow2D *path_follow_2d = memnew(PathFollow2D); path->add_child(path_follow_2d); + SceneTree::get_singleton()->get_root()->add_child(path); path_follow_2d->set_loop(true); path_follow_2d->set_progress_ratio(-0.3); CHECK_MESSAGE( - path_follow_2d->get_progress_ratio() == 0.7, + Math::is_equal_approx(path_follow_2d->get_progress_ratio(), (real_t)0.7), "Progress Ratio should loop back from the end in the opposite direction"); path_follow_2d->set_progress_ratio(1.3); CHECK_MESSAGE( - path_follow_2d->get_progress_ratio() == 0.3, + Math::is_equal_approx(path_follow_2d->get_progress_ratio(), (real_t)0.3), "Progress Ratio should loop back from the end in the opposite direction"); path_follow_2d->set_loop(false); path_follow_2d->set_progress_ratio(-0.3); CHECK_MESSAGE( - path_follow_2d->get_progress_ratio() == 0, + Math::is_equal_approx(path_follow_2d->get_progress_ratio(), 0), "Progress Ratio should be clamped at 0"); path_follow_2d->set_progress_ratio(1.3); CHECK_MESSAGE( - path_follow_2d->get_progress_ratio() == 1, + Math::is_equal_approx(path_follow_2d->get_progress_ratio(), 1), "Progress Ratio should be clamped at 1"); memdelete(path); } -TEST_CASE("[PathFollow2D] Progress out of range") { - const Ref<Curve2D> &curve = memnew(Curve2D()); +TEST_CASE("[SceneTree][PathFollow2D] Progress out of range") { + Ref<Curve2D> curve = memnew(Curve2D); curve->add_point(Vector2(0, 0)); curve->add_point(Vector2(100, 0)); - const Path2D *path = memnew(Path2D); + Path2D *path = memnew(Path2D); path->set_curve(curve); - const PathFollow2D *path_follow_2d = memnew(PathFollow2D); + PathFollow2D *path_follow_2d = memnew(PathFollow2D); path->add_child(path_follow_2d); + SceneTree::get_singleton()->get_root()->add_child(path); path_follow_2d->set_loop(true); path_follow_2d->set_progress(-50); CHECK_MESSAGE( - path_follow_2d->get_progress() == 50, + Math::is_equal_approx(path_follow_2d->get_progress(), 50), "Progress should loop back from the end in the opposite direction"); path_follow_2d->set_progress(150); CHECK_MESSAGE( - path_follow_2d->get_progress() == 50, + Math::is_equal_approx(path_follow_2d->get_progress(), 50), "Progress should loop back from the end in the opposite direction"); path_follow_2d->set_loop(false); path_follow_2d->set_progress(-50); CHECK_MESSAGE( - path_follow_2d->get_progress() == 0, + Math::is_equal_approx(path_follow_2d->get_progress(), 0), "Progress should be clamped at 0"); path_follow_2d->set_progress(150); CHECK_MESSAGE( - path_follow_2d->get_progress() == 100, + Math::is_equal_approx(path_follow_2d->get_progress(), 100), "Progress should be clamped at 1"); memdelete(path); diff --git a/tests/scene/test_path_follow_3d.h b/tests/scene/test_path_follow_3d.h index 7595fddd2f..d08af3a70c 100644 --- a/tests/scene/test_path_follow_3d.h +++ b/tests/scene/test_path_follow_3d.h @@ -32,188 +32,289 @@ #define TEST_PATH_FOLLOW_3D_H #include "scene/3d/path_3d.h" +#include "scene/main/window.h" #include "tests/test_macros.h" namespace TestPathFollow3D { -TEST_CASE("[PathFollow3D] Sampling with progress ratio") { - const Ref<Curve3D> &curve = memnew(Curve3D()); +bool is_equal_approx(const Vector3 &p_a, const Vector3 &p_b) { + const real_t tolerance = 0.001; + return Math::is_equal_approx(p_a.x, p_b.x, tolerance) && + Math::is_equal_approx(p_a.y, p_b.y, tolerance) && + Math::is_equal_approx(p_a.z, p_b.z, tolerance); +} + +TEST_CASE("[SceneTree][PathFollow3D] Sampling with progress ratio") { + Ref<Curve3D> curve = memnew(Curve3D); curve->add_point(Vector3(0, 0, 0)); curve->add_point(Vector3(100, 0, 0)); curve->add_point(Vector3(100, 100, 0)); curve->add_point(Vector3(100, 100, 100)); curve->add_point(Vector3(100, 0, 100)); - const Path3D *path = memnew(Path3D); + Path3D *path = memnew(Path3D); path->set_curve(curve); - const PathFollow3D *path_follow_3d = memnew(PathFollow3D); + PathFollow3D *path_follow_3d = memnew(PathFollow3D); + path_follow_3d->set_loop(false); path->add_child(path_follow_3d); + SceneTree::get_singleton()->get_root()->add_child(path); path_follow_3d->set_progress_ratio(0); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(0, 0, 0)); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(0, 0, 0), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress_ratio(0.125); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(50, 0, 0)); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(50, 0, 0), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress_ratio(0.25); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 0, 0); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 0, 0), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress_ratio(0.375); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 50, 0))); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 50, 0), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress_ratio(0.5); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 100, 0))); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 100, 0), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress_ratio(0.625); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 100, 50))); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 100, 50), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress_ratio(0.75); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 100, 100))); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 100, 100), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress_ratio(0.875); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 50, 100))); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 50, 100), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress_ratio(1); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 0, 100))); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 0, 100), path_follow_3d->get_transform().get_origin())); memdelete(path); } -TEST_CASE("[PathFollow3D] Sampling with progress") { - const Ref<Curve3D> &curve = memnew(Curve3D()); +TEST_CASE("[SceneTree][PathFollow3D] Sampling with progress") { + Ref<Curve3D> curve = memnew(Curve3D); curve->add_point(Vector3(0, 0, 0)); curve->add_point(Vector3(100, 0, 0)); curve->add_point(Vector3(100, 100, 0)); curve->add_point(Vector3(100, 100, 100)); curve->add_point(Vector3(100, 0, 100)); - const Path3D *path = memnew(Path3D); + Path3D *path = memnew(Path3D); path->set_curve(curve); - const PathFollow3D *path_follow_3d = memnew(PathFollow3D); + PathFollow3D *path_follow_3d = memnew(PathFollow3D); + path_follow_3d->set_loop(false); path->add_child(path_follow_3d); + SceneTree::get_singleton()->get_root()->add_child(path); path_follow_3d->set_progress(0); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(0, 0, 0)); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(0, 0, 0), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress(50); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(50, 0, 0)); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(50, 0, 0), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress(100); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 0, 0); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 0, 0), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress(150); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 50, 0))); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 50, 0), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress(200); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 100, 0))); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 100, 0), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress(250); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 100, 50))); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 100, 50), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress(300); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 100, 100))); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 100, 100), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress(350); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 50, 100))); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 50, 100), path_follow_3d->get_transform().get_origin())); path_follow_3d->set_progress(400); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector3(100, 0, 100))); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 0, 100), path_follow_3d->get_transform().get_origin())); memdelete(path); } -TEST_CASE("[PathFollow3D] Removal of a point in curve") { - const Ref<Curve3D> &curve = memnew(Curve3D()); +TEST_CASE("[SceneTree][PathFollow3D] Removal of a point in curve") { + Ref<Curve3D> curve = memnew(Curve3D); curve->add_point(Vector3(0, 0, 0)); curve->add_point(Vector3(100, 0, 0)); curve->add_point(Vector3(100, 100, 0)); - const Path3D *path = memnew(Path3D); + Path3D *path = memnew(Path3D); path->set_curve(curve); - const PathFollow3D *path_follow_3d = memnew(PathFollow3D); + PathFollow3D *path_follow_3d = memnew(PathFollow3D); path->add_child(path_follow_3d); + SceneTree::get_singleton()->get_root()->add_child(path); path_follow_3d->set_progress_ratio(0.5); - CHECK(path_follow_3d->get_transform().get_origin().is_equal_approx(Vector2(100, 0, 0))); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(100, 0, 0), path_follow_3d->get_transform().get_origin())); curve->remove_point(1); + path_follow_3d->set_progress_ratio(0.5); + path_follow_3d->update_transform(true); CHECK_MESSAGE( - path_follow_3d->get_transform().get_origin().is_equal_approx(Vector2(50, 50, 0)), + is_equal_approx(Vector3(50, 50, 0), path_follow_3d->get_transform().get_origin()), "Path follow's position should be updated after removing a point from the curve"); memdelete(path); } -TEST_CASE("[PathFollow3D] Progress ratio out of range") { - const Ref<Curve3D> &curve = memnew(Curve3D()); +TEST_CASE("[SceneTree][PathFollow3D] Progress ratio out of range") { + Ref<Curve3D> curve = memnew(Curve3D); curve->add_point(Vector3(0, 0, 0)); curve->add_point(Vector3(100, 0, 0)); - const Path3D *path = memnew(Path3D); + Path3D *path = memnew(Path3D); path->set_curve(curve); - const PathFollow3D *path_follow_3d = memnew(PathFollow3D); + PathFollow3D *path_follow_3d = memnew(PathFollow3D); path->add_child(path_follow_3d); + SceneTree::get_singleton()->get_root()->add_child(path); path_follow_3d->set_loop(true); path_follow_3d->set_progress_ratio(-0.3); CHECK_MESSAGE( - path_follow_3d->get_progress_ratio() == 0.7, + Math::is_equal_approx(path_follow_3d->get_progress_ratio(), (real_t)0.7), "Progress Ratio should loop back from the end in the opposite direction"); path_follow_3d->set_progress_ratio(1.3); CHECK_MESSAGE( - path_follow_3d->get_progress_ratio() == 0.3, + Math::is_equal_approx(path_follow_3d->get_progress_ratio(), (real_t)0.3), "Progress Ratio should loop back from the end in the opposite direction"); path_follow_3d->set_loop(false); path_follow_3d->set_progress_ratio(-0.3); CHECK_MESSAGE( - path_follow_3d->get_progress_ratio() == 0, + Math::is_equal_approx(path_follow_3d->get_progress_ratio(), 0), "Progress Ratio should be clamped at 0"); path_follow_3d->set_progress_ratio(1.3); CHECK_MESSAGE( - path_follow_3d->get_progress_ratio() == 1, + Math::is_equal_approx(path_follow_3d->get_progress_ratio(), 1), "Progress Ratio should be clamped at 1"); memdelete(path); } -TEST_CASE("[PathFollow3D] Progress out of range") { - const Ref<Curve3D> &curve = memnew(Curve3D()); +TEST_CASE("[SceneTree][PathFollow3D] Progress out of range") { + Ref<Curve3D> curve = memnew(Curve3D); curve->add_point(Vector3(0, 0, 0)); curve->add_point(Vector3(100, 0, 0)); - const Path3D *path = memnew(Path3D); + Path3D *path = memnew(Path3D); path->set_curve(curve); - const PathFollow3D *path_follow_3d = memnew(PathFollow3D); + PathFollow3D *path_follow_3d = memnew(PathFollow3D); path->add_child(path_follow_3d); + SceneTree::get_singleton()->get_root()->add_child(path); path_follow_3d->set_loop(true); path_follow_3d->set_progress(-50); CHECK_MESSAGE( - path_follow_3d->get_progress() == 50, + Math::is_equal_approx(path_follow_3d->get_progress(), 50), "Progress should loop back from the end in the opposite direction"); path_follow_3d->set_progress(150); CHECK_MESSAGE( - path_follow_3d->get_progress() == 50, + Math::is_equal_approx(path_follow_3d->get_progress(), 50), "Progress should loop back from the end in the opposite direction"); path_follow_3d->set_loop(false); path_follow_3d->set_progress(-50); CHECK_MESSAGE( - path_follow_3d->get_progress() == 0, + Math::is_equal_approx(path_follow_3d->get_progress(), 0), "Progress should be clamped at 0"); path_follow_3d->set_progress(150); CHECK_MESSAGE( - path_follow_3d->get_progress() == 100, + Math::is_equal_approx(path_follow_3d->get_progress(), 100), "Progress should be clamped at max value of curve"); memdelete(path); } + +TEST_CASE("[SceneTree][PathFollow3D] Calculate forward vector") { + const real_t dist_cube_100 = 100 * Math::sqrt(3.0); + Ref<Curve3D> curve = memnew(Curve3D); + curve->add_point(Vector3(0, 0, 0)); + curve->add_point(Vector3(100, 0, 0)); + curve->add_point(Vector3(200, 100, -100)); + curve->add_point(Vector3(200, 100, 200)); + curve->add_point(Vector3(100, 0, 100)); + curve->add_point(Vector3(0, 0, 100)); + Path3D *path = memnew(Path3D); + path->set_curve(curve); + PathFollow3D *path_follow_3d = memnew(PathFollow3D); + path->add_child(path_follow_3d); + SceneTree::get_singleton()->get_root()->add_child(path); + + path_follow_3d->set_loop(false); + path_follow_3d->set_rotation_mode(PathFollow3D::RotationMode::ROTATION_ORIENTED); + + path_follow_3d->set_progress(-50); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(-1, 0, 0), path_follow_3d->get_transform().get_basis().get_column(2))); + + path_follow_3d->set_progress(0); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(-1, 0, 0), path_follow_3d->get_transform().get_basis().get_column(2))); + + path_follow_3d->set_progress(50); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(-1, 0, 0), path_follow_3d->get_transform().get_basis().get_column(2))); + + path_follow_3d->set_progress(100); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(-1, 0, 0), path_follow_3d->get_transform().get_basis().get_column(2))); + + path_follow_3d->set_progress(100 + dist_cube_100 / 2); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(-0.577348, -0.577348, 0.577348), path_follow_3d->get_transform().get_basis().get_column(2))); + + path_follow_3d->set_progress(100 + dist_cube_100 - 0.01); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(-0.577348, -0.577348, 0.577348), path_follow_3d->get_transform().get_basis().get_column(2))); + + path_follow_3d->set_progress(250 + dist_cube_100); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(0, 0, -1), path_follow_3d->get_transform().get_basis().get_column(2))); + + path_follow_3d->set_progress(400 + dist_cube_100 - 0.01); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(0, 0, -1), path_follow_3d->get_transform().get_basis().get_column(2))); + + path_follow_3d->set_progress(400 + 1.5 * dist_cube_100); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(0.577348, 0.577348, 0.577348), path_follow_3d->get_transform().get_basis().get_column(2))); + + path_follow_3d->set_progress(400 + 2 * dist_cube_100 - 0.01); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(0.577348, 0.577348, 0.577348), path_follow_3d->get_transform().get_basis().get_column(2))); + + path_follow_3d->set_progress(500 + 2 * dist_cube_100); + path_follow_3d->update_transform(true); + CHECK(is_equal_approx(Vector3(1, 0, 0), path_follow_3d->get_transform().get_basis().get_column(2))); + + memdelete(path); +} } // namespace TestPathFollow3D #endif // TEST_PATH_FOLLOW_3D_H diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 3c875797a4..edadc52a16 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -30,6 +30,8 @@ #include "test_main.h" +#include "modules/modules_enabled.gen.h" + #ifdef TOOLS_ENABLED #include "editor/editor_paths.h" #include "editor/editor_settings.h" @@ -103,8 +105,6 @@ #include "tests/scene/test_audio_stream_wav.h" #include "tests/scene/test_bit_map.h" #include "tests/scene/test_camera_2d.h" -#include "tests/scene/test_code_edit.h" -#include "tests/scene/test_color_picker.h" #include "tests/scene/test_control.h" #include "tests/scene/test_curve.h" #include "tests/scene/test_curve_2d.h" @@ -117,8 +117,8 @@ #include "tests/scene/test_node_2d.h" #include "tests/scene/test_packed_scene.h" #include "tests/scene/test_path_2d.h" +#include "tests/scene/test_path_follow_2d.h" #include "tests/scene/test_sprite_frames.h" -#include "tests/scene/test_text_edit.h" #include "tests/scene/test_theme.h" #include "tests/scene/test_timer.h" #include "tests/scene/test_viewport.h" @@ -128,19 +128,30 @@ #include "tests/servers/test_text_server.h" #include "tests/test_validate_testing.h" +#ifndef ADVANCED_GUI_DISABLED +#include "tests/scene/test_code_edit.h" +#include "tests/scene/test_color_picker.h" +#include "tests/scene/test_graph_node.h" +#include "tests/scene/test_text_edit.h" +#endif // ADVANCED_GUI_DISABLED + #ifndef _3D_DISABLED -#include "tests/scene/test_arraymesh.h" -#include "tests/scene/test_camera_3d.h" +#ifdef MODULE_NAVIGATION_ENABLED #include "tests/scene/test_navigation_agent_2d.h" #include "tests/scene/test_navigation_agent_3d.h" #include "tests/scene/test_navigation_obstacle_2d.h" #include "tests/scene/test_navigation_obstacle_3d.h" #include "tests/scene/test_navigation_region_2d.h" #include "tests/scene/test_navigation_region_3d.h" -#include "tests/scene/test_path_3d.h" -#include "tests/scene/test_primitives.h" #include "tests/servers/test_navigation_server_2d.h" #include "tests/servers/test_navigation_server_3d.h" +#endif // MODULE_NAVIGATION_ENABLED + +#include "tests/scene/test_arraymesh.h" +#include "tests/scene/test_camera_3d.h" +#include "tests/scene/test_path_3d.h" +#include "tests/scene/test_path_follow_3d.h" +#include "tests/scene/test_primitives.h" #endif // _3D_DISABLED #include "modules/modules_tests.gen.h" |