summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core/input/test_input_event_key.h4
-rw-r--r--tests/core/io/test_image.h6
-rw-r--r--tests/core/io/test_json.h2
-rw-r--r--tests/core/math/test_aabb.h29
-rw-r--r--tests/core/math/test_basis.h225
-rw-r--r--tests/core/math/test_color.h6
-rw-r--r--tests/core/math/test_expression.h20
-rw-r--r--tests/core/math/test_geometry_2d.h26
-rw-r--r--tests/core/math/test_math_funcs.h556
-rw-r--r--tests/core/math/test_plane.h23
-rw-r--r--tests/core/math/test_quaternion.h124
-rw-r--r--tests/core/math/test_rect2.h29
-rw-r--r--tests/core/math/test_transform_2d.h34
-rw-r--r--tests/core/math/test_transform_3d.h23
-rw-r--r--tests/core/math/test_vector2.h129
-rw-r--r--tests/core/math/test_vector2i.h22
-rw-r--r--tests/core/math/test_vector3.h150
-rw-r--r--tests/core/math/test_vector3i.h20
-rw-r--r--tests/core/math/test_vector4.h104
-rw-r--r--tests/core/math/test_vector4i.h20
-rw-r--r--tests/core/object/test_class_db.h4
-rw-r--r--tests/core/string/test_string.h46
-rw-r--r--tests/core/templates/test_command_queue.h4
-rw-r--r--tests/scene/test_animation.h90
-rw-r--r--tests/scene/test_arraymesh.h321
-rw-r--r--tests/scene/test_audio_stream_wav.h2
-rw-r--r--tests/scene/test_bit_map.h24
-rw-r--r--tests/scene/test_curve.h54
-rw-r--r--tests/scene/test_path_2d.h109
-rw-r--r--tests/scene/test_primitives.h850
-rw-r--r--tests/scene/test_text_edit.h1206
-rw-r--r--tests/test_main.cpp9
-rw-r--r--tests/test_validate_testing.h2
33 files changed, 3715 insertions, 558 deletions
diff --git a/tests/core/input/test_input_event_key.h b/tests/core/input/test_input_event_key.h
index 4c9cd2002c..b852f3ccb9 100644
--- a/tests/core/input/test_input_event_key.h
+++ b/tests/core/input/test_input_event_key.h
@@ -102,7 +102,7 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") {
// as text. These cases are a bit weird, since None has no textual representation
// (find_keycode_name(Key::NONE) results in a nullptr). Thus, these tests look weird
// with only (Physical) or a lonely modifier with (Physical) but (as far as I
- // understand the code, that is intended behaviour.
+ // understand the code, that is intended behavior.
// Key is None without a physical key.
none_key.set_keycode(Key::NONE);
@@ -118,7 +118,7 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") {
InputEventKey none_key2;
- // Key is None without modifers with a physical key.
+ // Key is None without modifiers with a physical key.
none_key2.set_keycode(Key::NONE);
none_key2.set_physical_keycode(Key::ENTER);
diff --git a/tests/core/io/test_image.h b/tests/core/io/test_image.h
index 38b616cda0..1559c59b5c 100644
--- a/tests/core/io/test_image.h
+++ b/tests/core/io/test_image.h
@@ -124,7 +124,7 @@ TEST_CASE("[Image] Saving and loading") {
image_jpg->load_jpg_from_buffer(data_jpg) == OK,
"The JPG image should load successfully.");
- // Load WEBP
+ // Load WebP
Ref<Image> image_webp = memnew(Image());
Ref<FileAccess> f_webp = FileAccess::open(TestUtils::get_data_path("images/icon.webp"), FileAccess::READ, &err);
PackedByteArray data_webp;
@@ -132,7 +132,7 @@ TEST_CASE("[Image] Saving and loading") {
f_webp->get_buffer(data_webp.ptrw(), f_webp->get_length());
CHECK_MESSAGE(
image_webp->load_webp_from_buffer(data_webp) == OK,
- "The WEBP image should load successfully.");
+ "The WebP image should load successfully.");
// Load PNG
Ref<Image> image_png = memnew(Image());
@@ -162,7 +162,7 @@ TEST_CASE("[Image] Basic getters") {
CHECK(image->get_size() == Vector2(8, 4));
CHECK(image->get_format() == Image::FORMAT_LA8);
CHECK(image->get_used_rect() == Rect2i(0, 0, 0, 0));
- Ref<Image> image_get_rect = image->get_rect(Rect2i(0, 0, 2, 1));
+ Ref<Image> image_get_rect = image->get_region(Rect2i(0, 0, 2, 1));
CHECK(image_get_rect->get_size() == Vector2(2, 1));
}
diff --git a/tests/core/io/test_json.h b/tests/core/io/test_json.h
index 478cf1766e..af450da3b8 100644
--- a/tests/core/io/test_json.h
+++ b/tests/core/io/test_json.h
@@ -83,7 +83,7 @@ TEST_CASE("[JSON] Parsing single data types") {
json.get_error_line() == 0,
"Parsing a floating-point number as JSON should parse successfully.");
CHECK_MESSAGE(
- Math::is_equal_approx(double(json.get_data()), 0.123456),
+ double(json.get_data()) == doctest::Approx(0.123456),
"Parsing a floating-point number as JSON should return the expected value.");
json.parse("\"hello\"");
diff --git a/tests/core/math/test_aabb.h b/tests/core/math/test_aabb.h
index d5f54a139e..23969556be 100644
--- a/tests/core/math/test_aabb.h
+++ b/tests/core/math/test_aabb.h
@@ -91,7 +91,7 @@ TEST_CASE("[AABB] Basic setters") {
TEST_CASE("[AABB] Volume getters") {
AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
CHECK_MESSAGE(
- Math::is_equal_approx(aabb.get_volume(), 120),
+ aabb.get_volume() == doctest::Approx(120),
"get_volume() should return the expected value with positive size.");
CHECK_MESSAGE(
aabb.has_volume(),
@@ -99,17 +99,17 @@ TEST_CASE("[AABB] Volume getters") {
aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(-4, 5, 6));
CHECK_MESSAGE(
- Math::is_equal_approx(aabb.get_volume(), -120),
+ aabb.get_volume() == doctest::Approx(-120),
"get_volume() should return the expected value with negative size (1 component).");
aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(-4, -5, 6));
CHECK_MESSAGE(
- Math::is_equal_approx(aabb.get_volume(), 120),
+ aabb.get_volume() == doctest::Approx(120),
"get_volume() should return the expected value with negative size (2 components).");
aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(-4, -5, -6));
CHECK_MESSAGE(
- Math::is_equal_approx(aabb.get_volume(), -120),
+ aabb.get_volume() == doctest::Approx(-120),
"get_volume() should return the expected value with negative size (3 components).");
aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 0, 6));
@@ -389,6 +389,27 @@ TEST_CASE("[AABB] Expanding") {
aabb.expand(Vector3(-20, 0, 0)).is_equal_approx(AABB(Vector3(-20, 0, -2.5), Vector3(22.5, 7, 6))),
"expand() with non-contained point should return the expected AABB.");
}
+
+TEST_CASE("[AABB] Finite number checks") {
+ const Vector3 x(0, 1, 2);
+ const Vector3 infinite(NAN, NAN, NAN);
+
+ CHECK_MESSAGE(
+ AABB(x, x).is_finite(),
+ "AABB with all components finite should be finite");
+
+ CHECK_FALSE_MESSAGE(
+ AABB(infinite, x).is_finite(),
+ "AABB with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ AABB(x, infinite).is_finite(),
+ "AABB with one component infinite should not be finite.");
+
+ CHECK_FALSE_MESSAGE(
+ AABB(infinite, infinite).is_finite(),
+ "AABB with two components infinite should not be finite.");
+}
+
} // namespace TestAABB
#endif // TEST_AABB_H
diff --git a/tests/core/math/test_basis.h b/tests/core/math/test_basis.h
index ae8ca4acde..dce9d5cec3 100644
--- a/tests/core/math/test_basis.h
+++ b/tests/core/math/test_basis.h
@@ -38,16 +38,7 @@
namespace TestBasis {
-enum RotOrder {
- EulerXYZ,
- EulerXZY,
- EulerYZX,
- EulerYXZ,
- EulerZXY,
- EulerZYX
-};
-
-Vector3 deg2rad(const Vector3 &p_rotation) {
+Vector3 deg_to_rad(const Vector3 &p_rotation) {
return p_rotation / 180.0 * Math_PI;
}
@@ -55,88 +46,26 @@ Vector3 rad2deg(const Vector3 &p_rotation) {
return p_rotation / Math_PI * 180.0;
}
-Basis EulerToBasis(RotOrder mode, const Vector3 &p_rotation) {
- Basis ret;
- switch (mode) {
- case EulerXYZ:
- ret.set_euler(p_rotation, Basis::EULER_ORDER_XYZ);
- break;
-
- case EulerXZY:
- ret.set_euler(p_rotation, Basis::EULER_ORDER_XZY);
- break;
-
- case EulerYZX:
- ret.set_euler(p_rotation, Basis::EULER_ORDER_YZX);
- break;
-
- case EulerYXZ:
- ret.set_euler(p_rotation, Basis::EULER_ORDER_YXZ);
- break;
-
- case EulerZXY:
- ret.set_euler(p_rotation, Basis::EULER_ORDER_ZXY);
- break;
-
- case EulerZYX:
- ret.set_euler(p_rotation, Basis::EULER_ORDER_ZYX);
- break;
-
- default:
- // If you land here, Please integrate all rotation orders.
- FAIL("This is not unreachable.");
- }
-
- return ret;
-}
-
-Vector3 BasisToEuler(RotOrder mode, const Basis &p_rotation) {
- switch (mode) {
- case EulerXYZ:
- return p_rotation.get_euler(Basis::EULER_ORDER_XYZ);
-
- case EulerXZY:
- return p_rotation.get_euler(Basis::EULER_ORDER_XZY);
-
- case EulerYZX:
- return p_rotation.get_euler(Basis::EULER_ORDER_YZX);
-
- case EulerYXZ:
- return p_rotation.get_euler(Basis::EULER_ORDER_YXZ);
-
- case EulerZXY:
- return p_rotation.get_euler(Basis::EULER_ORDER_ZXY);
-
- case EulerZYX:
- return p_rotation.get_euler(Basis::EULER_ORDER_ZYX);
-
- default:
- // If you land here, Please integrate all rotation orders.
- FAIL("This is not unreachable.");
- return Vector3();
- }
-}
-
-String get_rot_order_name(RotOrder ro) {
+String get_rot_order_name(EulerOrder ro) {
switch (ro) {
- case EulerXYZ:
+ case EulerOrder::XYZ:
return "XYZ";
- case EulerXZY:
+ case EulerOrder::XZY:
return "XZY";
- case EulerYZX:
+ case EulerOrder::YZX:
return "YZX";
- case EulerYXZ:
+ case EulerOrder::YXZ:
return "YXZ";
- case EulerZXY:
+ case EulerOrder::ZXY:
return "ZXY";
- case EulerZYX:
+ case EulerOrder::ZYX:
return "ZYX";
default:
return "[Not supported]";
}
}
-void test_rotation(Vector3 deg_original_euler, RotOrder rot_order) {
+void test_rotation(Vector3 deg_original_euler, EulerOrder rot_order) {
// This test:
// 1. Converts the rotation vector from deg to rad.
// 2. Converts euler to basis.
@@ -155,12 +84,12 @@ void test_rotation(Vector3 deg_original_euler, RotOrder rot_order) {
// are correct.
// Euler to rotation
- const Vector3 original_euler = deg2rad(deg_original_euler);
- const Basis to_rotation = EulerToBasis(rot_order, original_euler);
+ const Vector3 original_euler = deg_to_rad(deg_original_euler);
+ const Basis to_rotation = Basis::from_euler(original_euler, rot_order);
// Euler from rotation
- const Vector3 euler_from_rotation = BasisToEuler(rot_order, to_rotation);
- const Basis rotation_from_computed_euler = EulerToBasis(rot_order, euler_from_rotation);
+ const Vector3 euler_from_rotation = to_rotation.get_euler(rot_order);
+ const Basis rotation_from_computed_euler = Basis::from_euler(euler_from_rotation, rot_order);
Basis res = to_rotation.inverse() * rotation_from_computed_euler;
@@ -169,9 +98,8 @@ void test_rotation(Vector3 deg_original_euler, RotOrder rot_order) {
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());
// Double check `to_rotation` decomposing with XYZ rotation order.
- const Vector3 euler_xyz_from_rotation = to_rotation.get_euler(Basis::EULER_ORDER_XYZ);
- Basis rotation_from_xyz_computed_euler;
- rotation_from_xyz_computed_euler.set_euler(euler_xyz_from_rotation, Basis::EULER_ORDER_XYZ);
+ const Vector3 euler_xyz_from_rotation = to_rotation.get_euler(EulerOrder::XYZ);
+ Basis rotation_from_xyz_computed_euler = Basis::from_euler(euler_xyz_from_rotation, EulerOrder::XYZ);
res = to_rotation.inverse() * rotation_from_xyz_computed_euler;
@@ -185,13 +113,13 @@ void test_rotation(Vector3 deg_original_euler, RotOrder rot_order) {
}
TEST_CASE("[Basis] Euler conversions") {
- Vector<RotOrder> rotorder_to_test;
- rotorder_to_test.push_back(EulerXYZ);
- rotorder_to_test.push_back(EulerXZY);
- rotorder_to_test.push_back(EulerYZX);
- rotorder_to_test.push_back(EulerYXZ);
- rotorder_to_test.push_back(EulerZXY);
- rotorder_to_test.push_back(EulerZYX);
+ Vector<EulerOrder> euler_order_to_test;
+ euler_order_to_test.push_back(EulerOrder::XYZ);
+ euler_order_to_test.push_back(EulerOrder::XZY);
+ euler_order_to_test.push_back(EulerOrder::YZX);
+ euler_order_to_test.push_back(EulerOrder::YXZ);
+ euler_order_to_test.push_back(EulerOrder::ZXY);
+ euler_order_to_test.push_back(EulerOrder::ZYX);
Vector<Vector3> vectors_to_test;
@@ -249,21 +177,21 @@ TEST_CASE("[Basis] Euler conversions") {
vectors_to_test.push_back(Vector3(120.0, 150.0, -130.0));
vectors_to_test.push_back(Vector3(120.0, 150.0, 130.0));
- for (int h = 0; h < rotorder_to_test.size(); h += 1) {
+ for (int h = 0; h < euler_order_to_test.size(); h += 1) {
for (int i = 0; i < vectors_to_test.size(); i += 1) {
- test_rotation(vectors_to_test[i], rotorder_to_test[h]);
+ test_rotation(vectors_to_test[i], euler_order_to_test[h]);
}
}
}
TEST_CASE("[Stress][Basis] Euler conversions") {
- Vector<RotOrder> rotorder_to_test;
- rotorder_to_test.push_back(EulerXYZ);
- rotorder_to_test.push_back(EulerXZY);
- rotorder_to_test.push_back(EulerYZX);
- rotorder_to_test.push_back(EulerYXZ);
- rotorder_to_test.push_back(EulerZXY);
- rotorder_to_test.push_back(EulerZYX);
+ Vector<EulerOrder> euler_order_to_test;
+ euler_order_to_test.push_back(EulerOrder::XYZ);
+ euler_order_to_test.push_back(EulerOrder::XZY);
+ euler_order_to_test.push_back(EulerOrder::YZX);
+ euler_order_to_test.push_back(EulerOrder::YXZ);
+ euler_order_to_test.push_back(EulerOrder::ZXY);
+ euler_order_to_test.push_back(EulerOrder::ZYX);
Vector<Vector3> vectors_to_test;
// Add 1000 random vectors with weirds numbers.
@@ -275,12 +203,99 @@ TEST_CASE("[Stress][Basis] Euler conversions") {
rng.randf_range(-1800, 1800)));
}
- for (int h = 0; h < rotorder_to_test.size(); h += 1) {
+ for (int h = 0; h < euler_order_to_test.size(); h += 1) {
for (int i = 0; i < vectors_to_test.size(); i += 1) {
- test_rotation(vectors_to_test[i], rotorder_to_test[h]);
+ test_rotation(vectors_to_test[i], euler_order_to_test[h]);
}
}
}
+
+TEST_CASE("[Basis] Set axis angle") {
+ Vector3 axis;
+ real_t angle;
+ real_t pi = (real_t)Math_PI;
+
+ // Testing the singularity when the angle is 0°.
+ Basis identity(1, 0, 0, 0, 1, 0, 0, 0, 1);
+ identity.get_axis_angle(axis, angle);
+ CHECK(angle == 0);
+
+ // Testing the singularity when the angle is 180°.
+ Basis singularityPi(-1, 0, 0, 0, 1, 0, 0, 0, -1);
+ singularityPi.get_axis_angle(axis, angle);
+ CHECK(angle == doctest::Approx(pi));
+
+ // Testing reversing the an axis (of an 30° angle).
+ float cos30deg = Math::cos(Math::deg_to_rad((real_t)30.0));
+ Basis z_positive(cos30deg, -0.5, 0, 0.5, cos30deg, 0, 0, 0, 1);
+ Basis z_negative(cos30deg, 0.5, 0, -0.5, cos30deg, 0, 0, 0, 1);
+
+ z_positive.get_axis_angle(axis, angle);
+ CHECK(angle == doctest::Approx(Math::deg_to_rad((real_t)30.0)));
+ CHECK(axis == Vector3(0, 0, 1));
+
+ z_negative.get_axis_angle(axis, angle);
+ CHECK(angle == doctest::Approx(Math::deg_to_rad((real_t)30.0)));
+ CHECK(axis == Vector3(0, 0, -1));
+
+ // Testing a rotation of 90° on x-y-z.
+ Basis x90deg(1, 0, 0, 0, 0, -1, 0, 1, 0);
+ x90deg.get_axis_angle(axis, angle);
+ CHECK(angle == doctest::Approx(pi / (real_t)2));
+ CHECK(axis == Vector3(1, 0, 0));
+
+ Basis y90deg(0, 0, 1, 0, 1, 0, -1, 0, 0);
+ y90deg.get_axis_angle(axis, angle);
+ CHECK(axis == Vector3(0, 1, 0));
+
+ Basis z90deg(0, -1, 0, 1, 0, 0, 0, 0, 1);
+ z90deg.get_axis_angle(axis, angle);
+ CHECK(axis == Vector3(0, 0, 1));
+
+ // Regression test: checks that the method returns a small angle (not 0).
+ Basis tiny(1, 0, 0, 0, 0.9999995, -0.001, 0, 001, 0.9999995); // The min angle possible with float is 0.001rad.
+ tiny.get_axis_angle(axis, angle);
+ CHECK(angle == doctest::Approx(0.001).epsilon(0.0001));
+
+ // Regression test: checks that the method returns an angle which is a number (not NaN)
+ Basis bugNan(1.00000024, 0, 0.000100001693, 0, 1, 0, -0.000100009143, 0, 1.00000024);
+ bugNan.get_axis_angle(axis, angle);
+ CHECK(!Math::is_nan(angle));
+}
+
+TEST_CASE("[Basis] Finite number checks") {
+ const Vector3 x(0, 1, 2);
+ const Vector3 infinite(NAN, NAN, NAN);
+
+ CHECK_MESSAGE(
+ Basis(x, x, x).is_finite(),
+ "Basis with all components finite should be finite");
+
+ CHECK_FALSE_MESSAGE(
+ Basis(infinite, x, x).is_finite(),
+ "Basis with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Basis(x, infinite, x).is_finite(),
+ "Basis with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Basis(x, x, infinite).is_finite(),
+ "Basis with one component infinite should not be finite.");
+
+ CHECK_FALSE_MESSAGE(
+ Basis(infinite, infinite, x).is_finite(),
+ "Basis with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Basis(infinite, x, infinite).is_finite(),
+ "Basis with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Basis(x, infinite, infinite).is_finite(),
+ "Basis with two components infinite should not be finite.");
+
+ CHECK_FALSE_MESSAGE(
+ Basis(infinite, infinite, infinite).is_finite(),
+ "Basis with three components infinite should not be finite.");
+}
+
} // namespace TestBasis
#endif // TEST_BASIS_H
diff --git a/tests/core/math/test_color.h b/tests/core/math/test_color.h
index 51c3bc8bdc..c6550778e8 100644
--- a/tests/core/math/test_color.h
+++ b/tests/core/math/test_color.h
@@ -101,13 +101,13 @@ TEST_CASE("[Color] Reading methods") {
const Color dark_blue = Color(0, 0, 0.5, 0.4);
CHECK_MESSAGE(
- Math::is_equal_approx(dark_blue.get_h(), 240.0f / 360.0f),
+ dark_blue.get_h() == doctest::Approx(240.0f / 360.0f),
"The returned HSV hue should match the expected value.");
CHECK_MESSAGE(
- Math::is_equal_approx(dark_blue.get_s(), 1.0f),
+ dark_blue.get_s() == doctest::Approx(1.0f),
"The returned HSV saturation should match the expected value.");
CHECK_MESSAGE(
- Math::is_equal_approx(dark_blue.get_v(), 0.5f),
+ dark_blue.get_v() == doctest::Approx(0.5f),
"The returned HSV value should match the expected value.");
}
diff --git a/tests/core/math/test_expression.h b/tests/core/math/test_expression.h
index 6e3be541b0..9734fd9f36 100644
--- a/tests/core/math/test_expression.h
+++ b/tests/core/math/test_expression.h
@@ -83,42 +83,42 @@ TEST_CASE("[Expression] Floating-point arithmetic") {
expression.parse("-123.456") == OK,
"Float identity should parse successfully.");
CHECK_MESSAGE(
- Math::is_equal_approx(double(expression.execute()), -123.456),
+ double(expression.execute()) == doctest::Approx(-123.456),
"Float identity should return the expected result.");
CHECK_MESSAGE(
expression.parse("2.0 + 3.0") == OK,
"Float addition should parse successfully.");
CHECK_MESSAGE(
- Math::is_equal_approx(double(expression.execute()), 5),
+ double(expression.execute()) == doctest::Approx(5),
"Float addition should return the expected result.");
CHECK_MESSAGE(
expression.parse("3.0 / 10") == OK,
"Float / integer division should parse successfully.");
CHECK_MESSAGE(
- Math::is_equal_approx(double(expression.execute()), 0.3),
+ double(expression.execute()) == doctest::Approx(0.3),
"Float / integer division should return the expected result.");
CHECK_MESSAGE(
expression.parse("3 / 10.0") == OK,
"Basic integer / float division should parse successfully.");
CHECK_MESSAGE(
- Math::is_equal_approx(double(expression.execute()), 0.3),
+ double(expression.execute()) == doctest::Approx(0.3),
"Basic integer / float division should return the expected result.");
CHECK_MESSAGE(
expression.parse("3.0 / 10.0") == OK,
"Float / float division should parse successfully.");
CHECK_MESSAGE(
- Math::is_equal_approx(double(expression.execute()), 0.3),
+ double(expression.execute()) == doctest::Approx(0.3),
"Float / float division should return the expected result.");
CHECK_MESSAGE(
expression.parse("2.5 * (6.0 + 14.25) / 2.0 - 5.12345") == OK,
"Float multiplication-addition-subtraction-division should parse successfully.");
CHECK_MESSAGE(
- Math::is_equal_approx(double(expression.execute()), 20.18905),
+ double(expression.execute()) == doctest::Approx(20.18905),
"Float multiplication-addition-subtraction-division should return the expected result.");
}
@@ -129,7 +129,7 @@ TEST_CASE("[Expression] Scientific notation") {
expression.parse("2.e5") == OK,
"The expression should parse successfully.");
CHECK_MESSAGE(
- Math::is_equal_approx(double(expression.execute()), 200'000),
+ double(expression.execute()) == doctest::Approx(200'000),
"The expression should return the expected result.");
// The middle "e" is ignored here.
@@ -137,14 +137,14 @@ TEST_CASE("[Expression] Scientific notation") {
expression.parse("2e5") == OK,
"The expression should parse successfully.");
CHECK_MESSAGE(
- Math::is_equal_approx(double(expression.execute()), 2e5),
+ double(expression.execute()) == doctest::Approx(2e5),
"The expression should return the expected result.");
CHECK_MESSAGE(
expression.parse("2e.5") == OK,
"The expression should parse successfully.");
CHECK_MESSAGE(
- Math::is_equal_approx(double(expression.execute()), 2),
+ double(expression.execute()) == doctest::Approx(2),
"The expression should return the expected result.");
}
@@ -176,7 +176,7 @@ TEST_CASE("[Expression] Built-in functions") {
expression.parse("snapped(sin(0.5), 0.01)") == OK,
"The expression should parse successfully.");
CHECK_MESSAGE(
- Math::is_equal_approx(double(expression.execute()), 0.48),
+ double(expression.execute()) == doctest::Approx(0.48),
"`snapped(sin(0.5), 0.01)` should return the expected result.");
CHECK_MESSAGE(
diff --git a/tests/core/math/test_geometry_2d.h b/tests/core/math/test_geometry_2d.h
index db4e6e2177..27c9e7f58b 100644
--- a/tests/core/math/test_geometry_2d.h
+++ b/tests/core/math/test_geometry_2d.h
@@ -64,7 +64,7 @@ TEST_CASE("[Geometry2D] Point in triangle") {
// This tests points on the edge of the triangle. They are treated as being outside the triangle.
// In `is_point_in_circle` and `is_point_in_polygon` they are treated as being inside, so in order the make
- // the behaviour consistent this may change in the future (see issue #44717 and PR #44274).
+ // the behavior consistent this may change in the future (see issue #44717 and PR #44274).
CHECK_FALSE(Geometry2D::is_point_in_triangle(Vector2(1, 1), Vector2(-1, 1), Vector2(0, -1), Vector2(1, 1)));
CHECK_FALSE(Geometry2D::is_point_in_triangle(Vector2(0, 1), Vector2(-1, 1), Vector2(0, -1), Vector2(1, 1)));
}
@@ -171,43 +171,43 @@ TEST_CASE("[Geometry2D] Segment intersection with circle") {
real_t one = 1.0;
CHECK_MESSAGE(
- Math::is_equal_approx(Geometry2D::segment_intersects_circle(Vector2(0, 0), Vector2(4, 0), Vector2(0, 0), 1.0), one_quarter),
+ Geometry2D::segment_intersects_circle(Vector2(0, 0), Vector2(4, 0), Vector2(0, 0), 1.0) == doctest::Approx(one_quarter),
"Segment from inside to outside of circle should intersect it.");
CHECK_MESSAGE(
- Math::is_equal_approx(Geometry2D::segment_intersects_circle(Vector2(4, 0), Vector2(0, 0), Vector2(0, 0), 1.0), three_quarters),
+ Geometry2D::segment_intersects_circle(Vector2(4, 0), Vector2(0, 0), Vector2(0, 0), 1.0) == doctest::Approx(three_quarters),
"Segment from outside to inside of circle should intersect it.");
CHECK_MESSAGE(
- Math::is_equal_approx(Geometry2D::segment_intersects_circle(Vector2(-2, 0), Vector2(2, 0), Vector2(0, 0), 1.0), one_quarter),
+ Geometry2D::segment_intersects_circle(Vector2(-2, 0), Vector2(2, 0), Vector2(0, 0), 1.0) == doctest::Approx(one_quarter),
"Segment running through circle should intersect it.");
CHECK_MESSAGE(
- Math::is_equal_approx(Geometry2D::segment_intersects_circle(Vector2(2, 0), Vector2(-2, 0), Vector2(0, 0), 1.0), one_quarter),
+ Geometry2D::segment_intersects_circle(Vector2(2, 0), Vector2(-2, 0), Vector2(0, 0), 1.0) == doctest::Approx(one_quarter),
"Segment running through circle should intersect it.");
CHECK_MESSAGE(
- Math::is_equal_approx(Geometry2D::segment_intersects_circle(Vector2(0, 0), Vector2(1, 0), Vector2(0, 0), 1.0), one),
+ Geometry2D::segment_intersects_circle(Vector2(0, 0), Vector2(1, 0), Vector2(0, 0), 1.0) == doctest::Approx(one),
"Segment starting inside the circle and ending on the circle should intersect it");
CHECK_MESSAGE(
- Math::is_equal_approx(Geometry2D::segment_intersects_circle(Vector2(1, 0), Vector2(0, 0), Vector2(0, 0), 1.0), zero),
+ Geometry2D::segment_intersects_circle(Vector2(1, 0), Vector2(0, 0), Vector2(0, 0), 1.0) == doctest::Approx(zero),
"Segment starting on the circle and going inwards should intersect it");
CHECK_MESSAGE(
- Math::is_equal_approx(Geometry2D::segment_intersects_circle(Vector2(1, 0), Vector2(2, 0), Vector2(0, 0), 1.0), zero),
+ Geometry2D::segment_intersects_circle(Vector2(1, 0), Vector2(2, 0), Vector2(0, 0), 1.0) == doctest::Approx(zero),
"Segment starting on the circle and going outwards should intersect it");
CHECK_MESSAGE(
- Math::is_equal_approx(Geometry2D::segment_intersects_circle(Vector2(2, 0), Vector2(1, 0), Vector2(0, 0), 1.0), one),
+ Geometry2D::segment_intersects_circle(Vector2(2, 0), Vector2(1, 0), Vector2(0, 0), 1.0) == doctest::Approx(one),
"Segment starting outside the circle and ending on the circle intersect it");
CHECK_MESSAGE(
- Math::is_equal_approx(Geometry2D::segment_intersects_circle(Vector2(-1, 0), Vector2(1, 0), Vector2(0, 0), 2.0), minus_one),
+ Geometry2D::segment_intersects_circle(Vector2(-1, 0), Vector2(1, 0), Vector2(0, 0), 2.0) == doctest::Approx(minus_one),
"Segment completely within the circle should not intersect it");
CHECK_MESSAGE(
- Math::is_equal_approx(Geometry2D::segment_intersects_circle(Vector2(1, 0), Vector2(-1, 0), Vector2(0, 0), 2.0), minus_one),
+ Geometry2D::segment_intersects_circle(Vector2(1, 0), Vector2(-1, 0), Vector2(0, 0), 2.0) == doctest::Approx(minus_one),
"Segment completely within the circle should not intersect it");
CHECK_MESSAGE(
- Math::is_equal_approx(Geometry2D::segment_intersects_circle(Vector2(2, 0), Vector2(3, 0), Vector2(0, 0), 1.0), minus_one),
+ Geometry2D::segment_intersects_circle(Vector2(2, 0), Vector2(3, 0), Vector2(0, 0), 1.0) == doctest::Approx(minus_one),
"Segment completely outside the circle should not intersect it");
CHECK_MESSAGE(
- Math::is_equal_approx(Geometry2D::segment_intersects_circle(Vector2(3, 0), Vector2(2, 0), Vector2(0, 0), 1.0), minus_one),
+ Geometry2D::segment_intersects_circle(Vector2(3, 0), Vector2(2, 0), Vector2(0, 0), 1.0) == doctest::Approx(minus_one),
"Segment completely outside the circle should not intersect it");
}
diff --git a/tests/core/math/test_math_funcs.h b/tests/core/math/test_math_funcs.h
new file mode 100644
index 0000000000..c468e73b74
--- /dev/null
+++ b/tests/core/math/test_math_funcs.h
@@ -0,0 +1,556 @@
+/*************************************************************************/
+/* test_math_funcs.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef TEST_MATH_FUNCS_H
+#define TEST_MATH_FUNCS_H
+
+#include "tests/test_macros.h"
+
+namespace TestMath {
+
+TEST_CASE("[Math] C++ macros") {
+ CHECK(MIN(-2, 2) == -2);
+ CHECK(MIN(600, 2) == 2);
+
+ CHECK(MAX(-2, 2) == 2);
+ CHECK(MAX(600, 2) == 600);
+
+ CHECK(CLAMP(600, -2, 2) == 2);
+ CHECK(CLAMP(620, 600, 650) == 620);
+ // `max` is lower than `min`.
+ CHECK(CLAMP(620, 600, 50) == 50);
+
+ CHECK(ABS(-5) == 5);
+ CHECK(ABS(0) == 0);
+ CHECK(ABS(5) == 5);
+
+ CHECK(SIGN(-5) == -1.0);
+ CHECK(SIGN(0) == 0.0);
+ CHECK(SIGN(5) == 1.0);
+}
+
+TEST_CASE("[Math] Power of two functions") {
+ CHECK(next_power_of_2(0) == 0);
+ CHECK(next_power_of_2(1) == 1);
+ CHECK(next_power_of_2(16) == 16);
+ CHECK(next_power_of_2(17) == 32);
+ CHECK(next_power_of_2(65535) == 65536);
+
+ CHECK(previous_power_of_2(0) == 0);
+ CHECK(previous_power_of_2(1) == 1);
+ CHECK(previous_power_of_2(16) == 16);
+ CHECK(previous_power_of_2(17) == 16);
+ CHECK(previous_power_of_2(65535) == 32768);
+
+ CHECK(closest_power_of_2(0) == 0);
+ CHECK(closest_power_of_2(1) == 1);
+ CHECK(closest_power_of_2(16) == 16);
+ CHECK(closest_power_of_2(17) == 16);
+ CHECK(closest_power_of_2(65535) == 65536);
+
+ CHECK(get_shift_from_power_of_2(0) == -1);
+ CHECK(get_shift_from_power_of_2(1) == 0);
+ CHECK(get_shift_from_power_of_2(16) == 4);
+ CHECK(get_shift_from_power_of_2(17) == -1);
+ CHECK(get_shift_from_power_of_2(65535) == -1);
+
+ CHECK(nearest_shift(0) == 0);
+ CHECK(nearest_shift(1) == 1);
+ CHECK(nearest_shift(16) == 5);
+ CHECK(nearest_shift(17) == 5);
+ CHECK(nearest_shift(65535) == 16);
+}
+
+TEST_CASE("[Math] abs") {
+ // int
+ CHECK(Math::abs(-1) == 1);
+ CHECK(Math::abs(0) == 0);
+ CHECK(Math::abs(1) == 1);
+
+ // double
+ CHECK(Math::abs(-0.1) == 0.1);
+ CHECK(Math::abs(0.0) == 0.0);
+ CHECK(Math::abs(0.1) == 0.1);
+
+ // float
+ CHECK(Math::abs(-0.1f) == 0.1f);
+ CHECK(Math::abs(0.0f) == 0.0f);
+ CHECK(Math::abs(0.1f) == 0.1f);
+}
+
+TEST_CASE("[Math] round/floor/ceil") {
+ CHECK(Math::round(1.5) == 2.0);
+ CHECK(Math::round(1.6) == 2.0);
+ CHECK(Math::round(-1.5) == -2.0);
+ CHECK(Math::round(-1.1) == -1.0);
+
+ CHECK(Math::floor(1.5) == 1.0);
+ CHECK(Math::floor(-1.5) == -2.0);
+
+ CHECK(Math::ceil(1.5) == 2.0);
+ CHECK(Math::ceil(-1.9) == -1.0);
+}
+
+TEST_CASE("[Math] sin/cos/tan") {
+ CHECK(Math::sin(-0.1) == doctest::Approx(-0.0998334166));
+ CHECK(Math::sin(0.1) == doctest::Approx(0.0998334166));
+ CHECK(Math::sin(0.5) == doctest::Approx(0.4794255386));
+ CHECK(Math::sin(1.0) == doctest::Approx(0.8414709848));
+ CHECK(Math::sin(1.5) == doctest::Approx(0.9974949866));
+ CHECK(Math::sin(450.0) == doctest::Approx(-0.683283725));
+
+ CHECK(Math::cos(-0.1) == doctest::Approx(0.99500416530));
+ CHECK(Math::cos(0.1) == doctest::Approx(0.9950041653));
+ CHECK(Math::cos(0.5) == doctest::Approx(0.8775825619));
+ CHECK(Math::cos(1.0) == doctest::Approx(0.5403023059));
+ CHECK(Math::cos(1.5) == doctest::Approx(0.0707372017));
+ CHECK(Math::cos(450.0) == doctest::Approx(-0.7301529642));
+
+ CHECK(Math::tan(-0.1) == doctest::Approx(-0.1003346721));
+ CHECK(Math::tan(0.1) == doctest::Approx(0.1003346721));
+ CHECK(Math::tan(0.5) == doctest::Approx(0.5463024898));
+ CHECK(Math::tan(1.0) == doctest::Approx(1.5574077247));
+ CHECK(Math::tan(1.5) == doctest::Approx(14.1014199472));
+ CHECK(Math::tan(450.0) == doctest::Approx(0.9358090134));
+}
+
+TEST_CASE("[Math] sinh/cosh/tanh") {
+ CHECK(Math::sinh(-0.1) == doctest::Approx(-0.10016675));
+ CHECK(Math::sinh(0.1) == doctest::Approx(0.10016675));
+ CHECK(Math::sinh(0.5) == doctest::Approx(0.5210953055));
+ CHECK(Math::sinh(1.0) == doctest::Approx(1.1752011936));
+ CHECK(Math::sinh(1.5) == doctest::Approx(2.1292794551));
+
+ CHECK(Math::cosh(-0.1) == doctest::Approx(1.0050041681));
+ CHECK(Math::cosh(0.1) == doctest::Approx(1.0050041681));
+ CHECK(Math::cosh(0.5) == doctest::Approx(1.1276259652));
+ CHECK(Math::cosh(1.0) == doctest::Approx(1.5430806348));
+ CHECK(Math::cosh(1.5) == doctest::Approx(2.3524096152));
+
+ CHECK(Math::tanh(-0.1) == doctest::Approx(-0.0996679946));
+ CHECK(Math::tanh(0.1) == doctest::Approx(0.0996679946));
+ CHECK(Math::tanh(0.5) == doctest::Approx(0.4621171573));
+ CHECK(Math::tanh(1.0) == doctest::Approx(0.761594156));
+ CHECK(Math::tanh(1.5) == doctest::Approx(0.9051482536));
+ CHECK(Math::tanh(450.0) == doctest::Approx(1.0));
+}
+
+TEST_CASE("[Math] asin/acos/atan") {
+ CHECK(Math::asin(-0.1) == doctest::Approx(-0.1001674212));
+ CHECK(Math::asin(0.1) == doctest::Approx(0.1001674212));
+ CHECK(Math::asin(0.5) == doctest::Approx(0.5235987756));
+ CHECK(Math::asin(1.0) == doctest::Approx(1.5707963268));
+ CHECK(Math::is_nan(Math::asin(1.5)));
+ CHECK(Math::is_nan(Math::asin(450.0)));
+
+ CHECK(Math::acos(-0.1) == doctest::Approx(1.670963748));
+ CHECK(Math::acos(0.1) == doctest::Approx(1.4706289056));
+ CHECK(Math::acos(0.5) == doctest::Approx(1.0471975512));
+ CHECK(Math::acos(1.0) == doctest::Approx(0.0));
+ CHECK(Math::is_nan(Math::acos(1.5)));
+ CHECK(Math::is_nan(Math::acos(450.0)));
+
+ CHECK(Math::atan(-0.1) == doctest::Approx(-0.0996686525));
+ CHECK(Math::atan(0.1) == doctest::Approx(0.0996686525));
+ CHECK(Math::atan(0.5) == doctest::Approx(0.463647609));
+ CHECK(Math::atan(1.0) == doctest::Approx(0.7853981634));
+ CHECK(Math::atan(1.5) == doctest::Approx(0.9827937232));
+ CHECK(Math::atan(450.0) == doctest::Approx(1.5685741082));
+}
+
+TEST_CASE("[Math] sinc/sincn/atan2") {
+ CHECK(Math::sinc(-0.1) == doctest::Approx(0.9983341665));
+ CHECK(Math::sinc(0.1) == doctest::Approx(0.9983341665));
+ CHECK(Math::sinc(0.5) == doctest::Approx(0.9588510772));
+ CHECK(Math::sinc(1.0) == doctest::Approx(0.8414709848));
+ CHECK(Math::sinc(1.5) == doctest::Approx(0.6649966577));
+ CHECK(Math::sinc(450.0) == doctest::Approx(-0.0015184083));
+
+ CHECK(Math::sincn(-0.1) == doctest::Approx(0.9836316431));
+ CHECK(Math::sincn(0.1) == doctest::Approx(0.9836316431));
+ CHECK(Math::sincn(0.5) == doctest::Approx(0.6366197724));
+ CHECK(Math::sincn(1.0) == doctest::Approx(0.0));
+ CHECK(Math::sincn(1.5) == doctest::Approx(-0.2122065908));
+ CHECK(Math::sincn(450.0) == doctest::Approx(0.0));
+
+ CHECK(Math::atan2(-0.1, 0.5) == doctest::Approx(-0.1973955598));
+ CHECK(Math::atan2(0.1, -0.5) == doctest::Approx(2.9441970937));
+ CHECK(Math::atan2(0.5, 1.5) == doctest::Approx(0.3217505544));
+ CHECK(Math::atan2(1.0, 2.5) == doctest::Approx(0.3805063771));
+ CHECK(Math::atan2(1.5, 1.0) == doctest::Approx(0.9827937232));
+ CHECK(Math::atan2(450.0, 1.0) == doctest::Approx(1.5685741082));
+}
+
+TEST_CASE("[Math] pow/log/log2/exp/sqrt") {
+ CHECK(Math::pow(-0.1, 2.0) == doctest::Approx(0.01));
+ CHECK(Math::pow(0.1, 2.5) == doctest::Approx(0.0031622777));
+ CHECK(Math::pow(0.5, 0.5) == doctest::Approx(0.7071067812));
+ CHECK(Math::pow(1.0, 1.0) == doctest::Approx(1.0));
+ CHECK(Math::pow(1.5, -1.0) == doctest::Approx(0.6666666667));
+ CHECK(Math::pow(450.0, -2.0) == doctest::Approx(0.0000049383));
+ CHECK(Math::pow(450.0, 0.0) == doctest::Approx(1.0));
+
+ CHECK(Math::is_nan(Math::log(-0.1)));
+ CHECK(Math::log(0.1) == doctest::Approx(-2.302585093));
+ CHECK(Math::log(0.5) == doctest::Approx(-0.6931471806));
+ CHECK(Math::log(1.0) == doctest::Approx(0.0));
+ CHECK(Math::log(1.5) == doctest::Approx(0.4054651081));
+ CHECK(Math::log(450.0) == doctest::Approx(6.1092475828));
+
+ CHECK(Math::is_nan(Math::log2(-0.1)));
+ CHECK(Math::log2(0.1) == doctest::Approx(-3.3219280949));
+ CHECK(Math::log2(0.5) == doctest::Approx(-1.0));
+ CHECK(Math::log2(1.0) == doctest::Approx(0.0));
+ CHECK(Math::log2(1.5) == doctest::Approx(0.5849625007));
+ CHECK(Math::log2(450.0) == doctest::Approx(8.8137811912));
+
+ CHECK(Math::exp(-0.1) == doctest::Approx(0.904837418));
+ CHECK(Math::exp(0.1) == doctest::Approx(1.1051709181));
+ CHECK(Math::exp(0.5) == doctest::Approx(1.6487212707));
+ CHECK(Math::exp(1.0) == doctest::Approx(2.7182818285));
+ CHECK(Math::exp(1.5) == doctest::Approx(4.4816890703));
+
+ CHECK(Math::is_nan(Math::sqrt(-0.1)));
+ CHECK(Math::sqrt(0.1) == doctest::Approx(0.316228));
+ CHECK(Math::sqrt(0.5) == doctest::Approx(0.707107));
+ CHECK(Math::sqrt(1.0) == doctest::Approx(1.0));
+ CHECK(Math::sqrt(1.5) == doctest::Approx(1.224745));
+}
+
+TEST_CASE("[Math] is_nan/is_inf") {
+ CHECK(!Math::is_nan(0.0));
+ CHECK(Math::is_nan(NAN));
+
+ CHECK(!Math::is_inf(0.0));
+ CHECK(Math::is_inf(INFINITY));
+}
+
+TEST_CASE("[Math] linear_to_db") {
+ CHECK(Math::linear_to_db(1.0) == doctest::Approx(0.0));
+ CHECK(Math::linear_to_db(20.0) == doctest::Approx(26.0206));
+ CHECK(Math::is_inf(Math::linear_to_db(0.0)));
+ CHECK(Math::is_nan(Math::linear_to_db(-20.0)));
+}
+
+TEST_CASE("[Math] db_to_linear") {
+ CHECK(Math::db_to_linear(0.0) == doctest::Approx(1.0));
+ CHECK(Math::db_to_linear(1.0) == doctest::Approx(1.122018));
+ CHECK(Math::db_to_linear(20.0) == doctest::Approx(10.0));
+ CHECK(Math::db_to_linear(-20.0) == doctest::Approx(0.1));
+}
+
+TEST_CASE("[Math] step_decimals") {
+ CHECK(Math::step_decimals(-0.5) == 1);
+ CHECK(Math::step_decimals(0) == 0);
+ CHECK(Math::step_decimals(1) == 0);
+ CHECK(Math::step_decimals(0.1) == 1);
+ CHECK(Math::step_decimals(0.01) == 2);
+ CHECK(Math::step_decimals(0.001) == 3);
+ CHECK(Math::step_decimals(0.0001) == 4);
+ CHECK(Math::step_decimals(0.00001) == 5);
+ CHECK(Math::step_decimals(0.000001) == 6);
+ CHECK(Math::step_decimals(0.0000001) == 7);
+ CHECK(Math::step_decimals(0.00000001) == 8);
+ CHECK(Math::step_decimals(0.000000001) == 9);
+ // Too many decimals to handle.
+ CHECK(Math::step_decimals(0.0000000001) == 0);
+}
+
+TEST_CASE("[Math] range_step_decimals") {
+ CHECK(Math::range_step_decimals(0.000000001) == 9);
+ // Too many decimals to handle.
+ CHECK(Math::range_step_decimals(0.0000000001) == 0);
+ // Should be treated as a step of 0 for use by the editor.
+ CHECK(Math::range_step_decimals(0.0) == 16);
+ CHECK(Math::range_step_decimals(-0.5) == 16);
+}
+
+TEST_CASE("[Math] lerp") {
+ CHECK(Math::lerp(2.0, 5.0, -0.1) == doctest::Approx(1.7));
+ CHECK(Math::lerp(2.0, 5.0, 0.0) == doctest::Approx(2.0));
+ CHECK(Math::lerp(2.0, 5.0, 0.1) == doctest::Approx(2.3));
+ CHECK(Math::lerp(2.0, 5.0, 1.0) == doctest::Approx(5.0));
+ CHECK(Math::lerp(2.0, 5.0, 2.0) == doctest::Approx(8.0));
+
+ CHECK(Math::lerp(-2.0, -5.0, -0.1) == doctest::Approx(-1.7));
+ CHECK(Math::lerp(-2.0, -5.0, 0.0) == doctest::Approx(-2.0));
+ CHECK(Math::lerp(-2.0, -5.0, 0.1) == doctest::Approx(-2.3));
+ CHECK(Math::lerp(-2.0, -5.0, 1.0) == doctest::Approx(-5.0));
+ CHECK(Math::lerp(-2.0, -5.0, 2.0) == doctest::Approx(-8.0));
+}
+
+TEST_CASE("[Math] inverse_lerp") {
+ CHECK(Math::inverse_lerp(2.0, 5.0, 1.7) == doctest::Approx(-0.1));
+ CHECK(Math::inverse_lerp(2.0, 5.0, 2.0) == doctest::Approx(0.0));
+ CHECK(Math::inverse_lerp(2.0, 5.0, 2.3) == doctest::Approx(0.1));
+ CHECK(Math::inverse_lerp(2.0, 5.0, 5.0) == doctest::Approx(1.0));
+ CHECK(Math::inverse_lerp(2.0, 5.0, 8.0) == doctest::Approx(2.0));
+
+ CHECK(Math::inverse_lerp(-2.0, -5.0, -1.7) == doctest::Approx(-0.1));
+ CHECK(Math::inverse_lerp(-2.0, -5.0, -2.0) == doctest::Approx(0.0));
+ CHECK(Math::inverse_lerp(-2.0, -5.0, -2.3) == doctest::Approx(0.1));
+ CHECK(Math::inverse_lerp(-2.0, -5.0, -5.0) == doctest::Approx(1.0));
+ CHECK(Math::inverse_lerp(-2.0, -5.0, -8.0) == doctest::Approx(2.0));
+}
+
+TEST_CASE("[Math] remap") {
+ CHECK(Math::remap(50.0, 100.0, 200.0, 0.0, 1000.0) == doctest::Approx(-500.0));
+ CHECK(Math::remap(100.0, 100.0, 200.0, 0.0, 1000.0) == doctest::Approx(0.0));
+ CHECK(Math::remap(200.0, 100.0, 200.0, 0.0, 1000.0) == doctest::Approx(1000.0));
+ CHECK(Math::remap(250.0, 100.0, 200.0, 0.0, 1000.0) == doctest::Approx(1500.0));
+
+ CHECK(Math::remap(-50.0, -100.0, -200.0, 0.0, 1000.0) == doctest::Approx(-500.0));
+ CHECK(Math::remap(-100.0, -100.0, -200.0, 0.0, 1000.0) == doctest::Approx(0.0));
+ CHECK(Math::remap(-200.0, -100.0, -200.0, 0.0, 1000.0) == doctest::Approx(1000.0));
+ CHECK(Math::remap(-250.0, -100.0, -200.0, 0.0, 1000.0) == doctest::Approx(1500.0));
+
+ CHECK(Math::remap(-50.0, -100.0, -200.0, 0.0, -1000.0) == doctest::Approx(500.0));
+ CHECK(Math::remap(-100.0, -100.0, -200.0, 0.0, -1000.0) == doctest::Approx(0.0));
+ CHECK(Math::remap(-200.0, -100.0, -200.0, 0.0, -1000.0) == doctest::Approx(-1000.0));
+ CHECK(Math::remap(-250.0, -100.0, -200.0, 0.0, -1000.0) == doctest::Approx(-1500.0));
+}
+
+TEST_CASE("[Math] lerp_angle") {
+ // Counter-clockwise rotation.
+ CHECK(Math::lerp_angle(0.24 * Math_TAU, 0.75 * Math_TAU, 0.5) == doctest::Approx(-0.005 * Math_TAU));
+ // Counter-clockwise rotation.
+ CHECK(Math::lerp_angle(0.25 * Math_TAU, 0.75 * Math_TAU, 0.5) == doctest::Approx(0.0));
+ // Clockwise rotation.
+ CHECK(Math::lerp_angle(0.26 * Math_TAU, 0.75 * Math_TAU, 0.5) == doctest::Approx(0.505 * Math_TAU));
+
+ CHECK(Math::lerp_angle(-0.25 * Math_TAU, 1.25 * Math_TAU, 0.5) == doctest::Approx(-0.5 * Math_TAU));
+ CHECK(Math::lerp_angle(0.72 * Math_TAU, 1.44 * Math_TAU, 0.96) == doctest::Approx(0.4512 * Math_TAU));
+ CHECK(Math::lerp_angle(0.72 * Math_TAU, 1.44 * Math_TAU, 1.04) == doctest::Approx(0.4288 * Math_TAU));
+
+ // Initial and final angles are effectively identical, so the value returned
+ // should always be the same regardless of the `weight` parameter.
+ CHECK(Math::lerp_angle(-4 * Math_TAU, 4 * Math_TAU, -1.0) == doctest::Approx(-4.0 * Math_TAU));
+ CHECK(Math::lerp_angle(-4 * Math_TAU, 4 * Math_TAU, 0.0) == doctest::Approx(-4.0 * Math_TAU));
+ CHECK(Math::lerp_angle(-4 * Math_TAU, 4 * Math_TAU, 0.5) == doctest::Approx(-4.0 * Math_TAU));
+ CHECK(Math::lerp_angle(-4 * Math_TAU, 4 * Math_TAU, 1.0) == doctest::Approx(-4.0 * Math_TAU));
+ CHECK(Math::lerp_angle(-4 * Math_TAU, 4 * Math_TAU, 500.0) == doctest::Approx(-4.0 * Math_TAU));
+}
+
+TEST_CASE("[Math] move_toward") {
+ CHECK(Math::move_toward(2.0, 5.0, -1.0) == doctest::Approx(1.0));
+ CHECK(Math::move_toward(2.0, 5.0, 2.5) == doctest::Approx(4.5));
+ CHECK(Math::move_toward(2.0, 5.0, 4.0) == doctest::Approx(5.0));
+ CHECK(Math::move_toward(-2.0, -5.0, -1.0) == doctest::Approx(-1.0));
+ CHECK(Math::move_toward(-2.0, -5.0, 2.5) == doctest::Approx(-4.5));
+ CHECK(Math::move_toward(-2.0, -5.0, 4.0) == doctest::Approx(-5.0));
+}
+
+TEST_CASE("[Math] smoothstep") {
+ CHECK(Math::smoothstep(0.0, 2.0, -5.0) == doctest::Approx(0.0));
+ CHECK(Math::smoothstep(0.0, 2.0, 0.5) == doctest::Approx(0.15625));
+ CHECK(Math::smoothstep(0.0, 2.0, 1.0) == doctest::Approx(0.5));
+ CHECK(Math::smoothstep(0.0, 2.0, 2.0) == doctest::Approx(1.0));
+}
+
+TEST_CASE("[Math] ease") {
+ CHECK(Math::ease(0.1, 1.0) == doctest::Approx(0.1));
+ CHECK(Math::ease(0.1, 2.0) == doctest::Approx(0.01));
+ CHECK(Math::ease(0.1, 0.5) == doctest::Approx(0.19));
+ CHECK(Math::ease(0.1, 0.0) == doctest::Approx(0));
+ CHECK(Math::ease(0.1, -0.5) == doctest::Approx(0.2236067977));
+ CHECK(Math::ease(0.1, -1.0) == doctest::Approx(0.1));
+ CHECK(Math::ease(0.1, -2.0) == doctest::Approx(0.02));
+
+ CHECK(Math::ease(-1.0, 1.0) == doctest::Approx(0));
+ CHECK(Math::ease(-1.0, 2.0) == doctest::Approx(0));
+ CHECK(Math::ease(-1.0, 0.5) == doctest::Approx(0));
+ CHECK(Math::ease(-1.0, 0.0) == doctest::Approx(0));
+ CHECK(Math::ease(-1.0, -0.5) == doctest::Approx(0));
+ CHECK(Math::ease(-1.0, -1.0) == doctest::Approx(0));
+ CHECK(Math::ease(-1.0, -2.0) == doctest::Approx(0));
+}
+
+TEST_CASE("[Math] snapped") {
+ CHECK(Math::snapped(0.5, 0.04) == doctest::Approx(0.52));
+ CHECK(Math::snapped(-0.5, 0.04) == doctest::Approx(-0.48));
+ CHECK(Math::snapped(0.0, 0.04) == doctest::Approx(0));
+ CHECK(Math::snapped(128'000.025, 0.04) == doctest::Approx(128'000.04));
+
+ CHECK(Math::snapped(0.5, 400) == doctest::Approx(0));
+ CHECK(Math::snapped(-0.5, 400) == doctest::Approx(0));
+ CHECK(Math::snapped(0.0, 400) == doctest::Approx(0));
+ CHECK(Math::snapped(128'000.025, 400) == doctest::Approx(128'000.0));
+
+ CHECK(Math::snapped(0.5, 0.0) == doctest::Approx(0.5));
+ CHECK(Math::snapped(-0.5, 0.0) == doctest::Approx(-0.5));
+ CHECK(Math::snapped(0.0, 0.0) == doctest::Approx(0.0));
+ CHECK(Math::snapped(128'000.025, 0.0) == doctest::Approx(128'000.0));
+
+ CHECK(Math::snapped(0.5, -1.0) == doctest::Approx(0));
+ CHECK(Math::snapped(-0.5, -1.0) == doctest::Approx(-1.0));
+ CHECK(Math::snapped(0.0, -1.0) == doctest::Approx(0));
+ CHECK(Math::snapped(128'000.025, -1.0) == doctest::Approx(128'000.0));
+}
+
+TEST_CASE("[Math] larger_prime") {
+ CHECK(Math::larger_prime(0) == 5);
+ CHECK(Math::larger_prime(1) == 5);
+ CHECK(Math::larger_prime(2) == 5);
+ CHECK(Math::larger_prime(5) == 13);
+ CHECK(Math::larger_prime(500) == 769);
+ CHECK(Math::larger_prime(1'000'000) == 1'572'869);
+ CHECK(Math::larger_prime(1'000'000'000) == 1'610'612'741);
+
+ // The next prime is larger than `INT32_MAX` and is not present in the built-in prime table.
+ ERR_PRINT_OFF;
+ CHECK(Math::larger_prime(2'000'000'000) == 0);
+ ERR_PRINT_ON;
+}
+
+TEST_CASE("[Math] fmod") {
+ CHECK(Math::fmod(-2.0, 0.3) == doctest::Approx(-0.2));
+ CHECK(Math::fmod(0.0, 0.3) == doctest::Approx(0.0));
+ CHECK(Math::fmod(2.0, 0.3) == doctest::Approx(0.2));
+
+ CHECK(Math::fmod(-2.0, -0.3) == doctest::Approx(-0.2));
+ CHECK(Math::fmod(0.0, -0.3) == doctest::Approx(0.0));
+ CHECK(Math::fmod(2.0, -0.3) == doctest::Approx(0.2));
+}
+
+TEST_CASE("[Math] fposmod") {
+ CHECK(Math::fposmod(-2.0, 0.3) == doctest::Approx(0.1));
+ CHECK(Math::fposmod(0.0, 0.3) == doctest::Approx(0.0));
+ CHECK(Math::fposmod(2.0, 0.3) == doctest::Approx(0.2));
+
+ CHECK(Math::fposmod(-2.0, -0.3) == doctest::Approx(-0.2));
+ CHECK(Math::fposmod(0.0, -0.3) == doctest::Approx(0.0));
+ CHECK(Math::fposmod(2.0, -0.3) == doctest::Approx(-0.1));
+}
+
+TEST_CASE("[Math] fposmodp") {
+ CHECK(Math::fposmodp(-2.0, 0.3) == doctest::Approx(0.1));
+ CHECK(Math::fposmodp(0.0, 0.3) == doctest::Approx(0.0));
+ CHECK(Math::fposmodp(2.0, 0.3) == doctest::Approx(0.2));
+
+ CHECK(Math::fposmodp(-2.0, -0.3) == doctest::Approx(-0.5));
+ CHECK(Math::fposmodp(0.0, -0.3) == doctest::Approx(0.0));
+ CHECK(Math::fposmodp(2.0, -0.3) == doctest::Approx(0.2));
+}
+
+TEST_CASE("[Math] posmod") {
+ CHECK(Math::posmod(-20, 3) == 1);
+ CHECK(Math::posmod(0, 3) == 0);
+ CHECK(Math::posmod(20, 3) == 2);
+ CHECK(Math::posmod(-20, -3) == -2);
+ CHECK(Math::posmod(0, -3) == 0);
+ CHECK(Math::posmod(20, -3) == -1);
+}
+
+TEST_CASE("[Math] wrapi") {
+ CHECK(Math::wrapi(-30, -20, 160) == 150);
+ CHECK(Math::wrapi(30, -20, 160) == 30);
+ CHECK(Math::wrapi(300, -20, 160) == 120);
+ CHECK(Math::wrapi(300'000'000'000, -20, 160) == 120);
+}
+
+TEST_CASE("[Math] wrapf") {
+ CHECK(Math::wrapf(-30.0, -20.0, 160.0) == doctest::Approx(150.0));
+ CHECK(Math::wrapf(30.0, -2.0, 160.0) == doctest::Approx(30.0));
+ CHECK(Math::wrapf(300.0, -20.0, 160.0) == doctest::Approx(120.0));
+ CHECK(Math::wrapf(300'000'000'000.0, -20.0, 160.0) == doctest::Approx(120.0));
+}
+
+TEST_CASE("[Math] fract") {
+ CHECK(Math::fract(1.0) == doctest::Approx(0.0));
+ CHECK(Math::fract(77.8) == doctest::Approx(0.8));
+ CHECK(Math::fract(-10.1) == doctest::Approx(0.9));
+}
+
+TEST_CASE("[Math] pingpong") {
+ CHECK(Math::pingpong(0.0, 0.0) == doctest::Approx(0.0));
+ CHECK(Math::pingpong(1.0, 1.0) == doctest::Approx(1.0));
+ CHECK(Math::pingpong(0.5, 2.0) == doctest::Approx(0.5));
+ CHECK(Math::pingpong(3.5, 2.0) == doctest::Approx(0.5));
+ CHECK(Math::pingpong(11.5, 2.0) == doctest::Approx(0.5));
+ CHECK(Math::pingpong(-2.5, 2.0) == doctest::Approx(1.5));
+}
+
+TEST_CASE("[Math] deg_to_rad/rad_to_deg") {
+ CHECK(Math::deg_to_rad(180.0) == doctest::Approx(Math_PI));
+ CHECK(Math::deg_to_rad(-27.0) == doctest::Approx(-0.471239));
+
+ CHECK(Math::rad_to_deg(Math_PI) == doctest::Approx(180.0));
+ CHECK(Math::rad_to_deg(-1.5) == doctest::Approx(-85.94366927));
+}
+
+TEST_CASE("[Math] cubic_interpolate") {
+ CHECK(Math::cubic_interpolate(0.2, 0.8, 0.0, 1.0, 0.0) == doctest::Approx(0.2));
+ CHECK(Math::cubic_interpolate(0.2, 0.8, 0.0, 1.0, 0.25) == doctest::Approx(0.33125));
+ CHECK(Math::cubic_interpolate(0.2, 0.8, 0.0, 1.0, 0.5) == doctest::Approx(0.5));
+ CHECK(Math::cubic_interpolate(0.2, 0.8, 0.0, 1.0, 0.75) == doctest::Approx(0.66875));
+ CHECK(Math::cubic_interpolate(0.2, 0.8, 0.0, 1.0, 1.0) == doctest::Approx(0.8));
+
+ CHECK(Math::cubic_interpolate(20.2, 30.1, -100.0, 32.0, -50.0) == doctest::Approx(-6662732.3));
+ CHECK(Math::cubic_interpolate(20.2, 30.1, -100.0, 32.0, -5.0) == doctest::Approx(-9356.3));
+ CHECK(Math::cubic_interpolate(20.2, 30.1, -100.0, 32.0, 0.0) == doctest::Approx(20.2));
+ CHECK(Math::cubic_interpolate(20.2, 30.1, -100.0, 32.0, 1.0) == doctest::Approx(30.1));
+ CHECK(Math::cubic_interpolate(20.2, 30.1, -100.0, 32.0, 4.0) == doctest::Approx(1853.2));
+}
+
+TEST_CASE("[Math] cubic_interpolate_angle") {
+ CHECK(Math::cubic_interpolate_angle(Math_PI * (1.0 / 6.0), Math_PI * (5.0 / 6.0), 0.0, Math_PI, 0.0) == doctest::Approx(Math_PI * (1.0 / 6.0)));
+ CHECK(Math::cubic_interpolate_angle(Math_PI * (1.0 / 6.0), Math_PI * (5.0 / 6.0), 0.0, Math_PI, 0.25) == doctest::Approx(0.973566));
+ CHECK(Math::cubic_interpolate_angle(Math_PI * (1.0 / 6.0), Math_PI * (5.0 / 6.0), 0.0, Math_PI, 0.5) == doctest::Approx(Math_PI / 2.0));
+ CHECK(Math::cubic_interpolate_angle(Math_PI * (1.0 / 6.0), Math_PI * (5.0 / 6.0), 0.0, Math_PI, 0.75) == doctest::Approx(2.16803));
+ CHECK(Math::cubic_interpolate_angle(Math_PI * (1.0 / 6.0), Math_PI * (5.0 / 6.0), 0.0, Math_PI, 1.0) == doctest::Approx(Math_PI * (5.0 / 6.0)));
+}
+
+TEST_CASE("[Math] cubic_interpolate_in_time") {
+ CHECK(Math::cubic_interpolate_in_time(0.2, 0.8, 0.0, 1.0, 0.0, 0.5, 0.0, 1.0) == doctest::Approx(0.0));
+ CHECK(Math::cubic_interpolate_in_time(0.2, 0.8, 0.0, 1.0, 0.25, 0.5, 0.0, 1.0) == doctest::Approx(0.1625));
+ CHECK(Math::cubic_interpolate_in_time(0.2, 0.8, 0.0, 1.0, 0.5, 0.5, 0.0, 1.0) == doctest::Approx(0.4));
+ CHECK(Math::cubic_interpolate_in_time(0.2, 0.8, 0.0, 1.0, 0.75, 0.5, 0.0, 1.0) == doctest::Approx(0.6375));
+ CHECK(Math::cubic_interpolate_in_time(0.2, 0.8, 0.0, 1.0, 1.0, 0.5, 0.0, 1.0) == doctest::Approx(0.8));
+}
+
+TEST_CASE("[Math] cubic_interpolate_angle_in_time") {
+ CHECK(Math::cubic_interpolate_angle_in_time(Math_PI * (1.0 / 6.0), Math_PI * (5.0 / 6.0), 0.0, Math_PI, 0.0, 0.5, 0.0, 1.0) == doctest::Approx(0.0));
+ CHECK(Math::cubic_interpolate_angle_in_time(Math_PI * (1.0 / 6.0), Math_PI * (5.0 / 6.0), 0.0, Math_PI, 0.25, 0.5, 0.0, 1.0) == doctest::Approx(0.494964));
+ CHECK(Math::cubic_interpolate_angle_in_time(Math_PI * (1.0 / 6.0), Math_PI * (5.0 / 6.0), 0.0, Math_PI, 0.5, 0.5, 0.0, 1.0) == doctest::Approx(1.27627));
+ CHECK(Math::cubic_interpolate_angle_in_time(Math_PI * (1.0 / 6.0), Math_PI * (5.0 / 6.0), 0.0, Math_PI, 0.75, 0.5, 0.0, 1.0) == doctest::Approx(2.07394));
+ CHECK(Math::cubic_interpolate_angle_in_time(Math_PI * (1.0 / 6.0), Math_PI * (5.0 / 6.0), 0.0, Math_PI, 1.0, 0.5, 0.0, 1.0) == doctest::Approx(Math_PI * (5.0 / 6.0)));
+}
+
+TEST_CASE("[Math] bezier_interpolate") {
+ CHECK(Math::bezier_interpolate(0.0, 0.2, 0.8, 1.0, 0.0) == doctest::Approx(0.0));
+ CHECK(Math::bezier_interpolate(0.0, 0.2, 0.8, 1.0, 0.25) == doctest::Approx(0.2125));
+ CHECK(Math::bezier_interpolate(0.0, 0.2, 0.8, 1.0, 0.5) == doctest::Approx(0.5));
+ CHECK(Math::bezier_interpolate(0.0, 0.2, 0.8, 1.0, 0.75) == doctest::Approx(0.7875));
+ CHECK(Math::bezier_interpolate(0.0, 0.2, 0.8, 1.0, 1.0) == doctest::Approx(1.0));
+}
+
+} // namespace TestMath
+
+#endif // TEST_MATH_FUNCS_H
diff --git a/tests/core/math/test_plane.h b/tests/core/math/test_plane.h
index d81a5af1ce..84d9a0ff7d 100644
--- a/tests/core/math/test_plane.h
+++ b/tests/core/math/test_plane.h
@@ -167,6 +167,29 @@ TEST_CASE("[Plane] Intersection") {
vec_out.is_equal_approx(Vector3(1, 1, 1)),
"intersects_segment() should modify vec_out to the expected result.");
}
+
+TEST_CASE("[Plane] Finite number checks") {
+ const Vector3 x(0, 1, 2);
+ const Vector3 infinite_vec(NAN, NAN, NAN);
+ const real_t y = 0;
+ const real_t infinite_y = NAN;
+
+ CHECK_MESSAGE(
+ Plane(x, y).is_finite(),
+ "Plane with all components finite should be finite");
+
+ CHECK_FALSE_MESSAGE(
+ Plane(x, infinite_y).is_finite(),
+ "Plane with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Plane(infinite_vec, y).is_finite(),
+ "Plane with one component infinite should not be finite.");
+
+ CHECK_FALSE_MESSAGE(
+ Plane(infinite_vec, infinite_y).is_finite(),
+ "Plane with two components infinite should not be finite.");
+}
+
} // namespace TestPlane
#endif // TEST_PLANE_H
diff --git a/tests/core/math/test_quaternion.h b/tests/core/math/test_quaternion.h
index 1b80ffba0b..c3ae322991 100644
--- a/tests/core/math/test_quaternion.h
+++ b/tests/core/math/test_quaternion.h
@@ -47,9 +47,9 @@ Quaternion quat_euler_yxz_deg(Vector3 angle) {
// Generate YXZ (Z-then-X-then-Y) Quaternion using single-axis Euler
// constructor and quaternion product, both tested separately.
- Quaternion q_y(Vector3(0.0, yaw, 0.0));
- Quaternion q_p(Vector3(pitch, 0.0, 0.0));
- Quaternion q_r(Vector3(0.0, 0.0, roll));
+ Quaternion q_y = Quaternion::from_euler(Vector3(0.0, yaw, 0.0));
+ Quaternion q_p = Quaternion::from_euler(Vector3(pitch, 0.0, 0.0));
+ Quaternion q_r = Quaternion::from_euler(Vector3(0.0, 0.0, roll));
// Roll-Z is followed by Pitch-X, then Yaw-Y.
Quaternion q_yxz = q_y * q_p * q_r;
@@ -134,21 +134,21 @@ TEST_CASE("[Quaternion] Construct Euler SingleAxis") {
double roll = Math::deg_to_rad(10.0);
Vector3 euler_y(0.0, yaw, 0.0);
- Quaternion q_y(euler_y);
+ Quaternion q_y = Quaternion::from_euler(euler_y);
CHECK(q_y[0] == doctest::Approx(0.0));
CHECK(q_y[1] == doctest::Approx(0.382684));
CHECK(q_y[2] == doctest::Approx(0.0));
CHECK(q_y[3] == doctest::Approx(0.923879));
Vector3 euler_p(pitch, 0.0, 0.0);
- Quaternion q_p(euler_p);
+ Quaternion q_p = Quaternion::from_euler(euler_p);
CHECK(q_p[0] == doctest::Approx(0.258819));
CHECK(q_p[1] == doctest::Approx(0.0));
CHECK(q_p[2] == doctest::Approx(0.0));
CHECK(q_p[3] == doctest::Approx(0.965926));
Vector3 euler_r(0.0, 0.0, roll);
- Quaternion q_r(euler_r);
+ Quaternion q_r = Quaternion::from_euler(euler_r);
CHECK(q_r[0] == doctest::Approx(0.0));
CHECK(q_r[1] == doctest::Approx(0.0));
CHECK(q_r[2] == doctest::Approx(0.0871558));
@@ -160,30 +160,30 @@ TEST_CASE("[Quaternion] Construct Euler YXZ dynamic axes") {
double pitch = Math::deg_to_rad(30.0);
double roll = Math::deg_to_rad(10.0);
- // Generate YXZ comparision data (Z-then-X-then-Y) using single-axis Euler
+ // Generate YXZ comparison data (Z-then-X-then-Y) using single-axis Euler
// constructor and quaternion product, both tested separately.
Vector3 euler_y(0.0, yaw, 0.0);
- Quaternion q_y(euler_y);
+ Quaternion q_y = Quaternion::from_euler(euler_y);
Vector3 euler_p(pitch, 0.0, 0.0);
- Quaternion q_p(euler_p);
+ Quaternion q_p = Quaternion::from_euler(euler_p);
Vector3 euler_r(0.0, 0.0, roll);
- Quaternion q_r(euler_r);
+ Quaternion q_r = Quaternion::from_euler(euler_r);
- // Roll-Z is followed by Pitch-X.
- Quaternion check_xz = q_p * q_r;
- // Then Yaw-Y follows both.
- Quaternion check_yxz = q_y * check_xz;
+ // Instrinsically, Yaw-Y then Pitch-X then Roll-Z.
+ // Extrinsically, Roll-Z is followed by Pitch-X, then Yaw-Y.
+ Quaternion check_yxz = q_y * q_p * q_r;
// Test construction from YXZ Euler angles.
Vector3 euler_yxz(pitch, yaw, roll);
- Quaternion q(euler_yxz);
+ Quaternion q = Quaternion::from_euler(euler_yxz);
CHECK(q[0] == doctest::Approx(check_yxz[0]));
CHECK(q[1] == doctest::Approx(check_yxz[1]));
CHECK(q[2] == doctest::Approx(check_yxz[2]));
CHECK(q[3] == doctest::Approx(check_yxz[3]));
- // Sneak in a test of is_equal_approx.
CHECK(q.is_equal_approx(check_yxz));
+ CHECK(q.get_euler().is_equal_approx(euler_yxz));
+ CHECK(check_yxz.get_euler().is_equal_approx(euler_yxz));
}
TEST_CASE("[Quaternion] Construct Basis Euler") {
@@ -191,8 +191,8 @@ TEST_CASE("[Quaternion] Construct Basis Euler") {
double pitch = Math::deg_to_rad(30.0);
double roll = Math::deg_to_rad(10.0);
Vector3 euler_yxz(pitch, yaw, roll);
- Quaternion q_yxz(euler_yxz);
- Basis basis_axes(euler_yxz);
+ Quaternion q_yxz = Quaternion::from_euler(euler_yxz);
+ Basis basis_axes = Basis::from_euler(euler_yxz);
Quaternion q(basis_axes);
CHECK(q.is_equal_approx(q_yxz));
}
@@ -209,7 +209,7 @@ TEST_CASE("[Quaternion] Construct Basis Axes") {
// Quaternion from local calculation.
Quaternion q_local = quat_euler_yxz_deg(Vector3(31.41, -49.16, 12.34));
// Quaternion from Euler angles constructor.
- Quaternion q_euler(euler_yxz);
+ Quaternion q_euler = Quaternion::from_euler(euler_yxz);
CHECK(q_calc.is_equal_approx(q_local));
CHECK(q_local.is_equal_approx(q_euler));
@@ -218,7 +218,7 @@ TEST_CASE("[Quaternion] Construct Basis Axes") {
// This is by design, but may be subject to change.
// Workaround by constructing Basis from Euler angles.
// basis_axes = Basis(i_unit, j_unit, k_unit);
- Basis basis_axes(euler_yxz);
+ Basis basis_axes = Basis::from_euler(euler_yxz);
Quaternion q(basis_axes);
CHECK(basis_axes.get_column(0).is_equal_approx(i_unit));
@@ -235,6 +235,23 @@ TEST_CASE("[Quaternion] Construct Basis Axes") {
CHECK(q[3] == doctest::Approx(0.8582598));
}
+TEST_CASE("[Quaternion] Get Euler Orders") {
+ double x = Math::deg_to_rad(30.0);
+ double y = Math::deg_to_rad(45.0);
+ double z = Math::deg_to_rad(10.0);
+ Vector3 euler(x, y, z);
+ for (int i = 0; i < 6; i++) {
+ EulerOrder order = (EulerOrder)i;
+ Basis basis = Basis::from_euler(euler, order);
+ Quaternion q = Quaternion(basis);
+ Vector3 check = q.get_euler(order);
+ CHECK_MESSAGE(check.is_equal_approx(euler),
+ "Quaternion get_euler method should return the original angles.");
+ CHECK_MESSAGE(check.is_equal_approx(basis.get_euler(order)),
+ "Quaternion get_euler method should behave the same as Basis get_euler.");
+ }
+}
+
TEST_CASE("[Quaternion] Product (book)") {
// Example from "Quaternions and Rotation Sequences" by Jack Kuipers, p. 108.
Quaternion p(1.0, -2.0, 1.0, 3.0);
@@ -253,21 +270,21 @@ TEST_CASE("[Quaternion] Product") {
double roll = Math::deg_to_rad(10.0);
Vector3 euler_y(0.0, yaw, 0.0);
- Quaternion q_y(euler_y);
+ Quaternion q_y = Quaternion::from_euler(euler_y);
CHECK(q_y[0] == doctest::Approx(0.0));
CHECK(q_y[1] == doctest::Approx(0.382684));
CHECK(q_y[2] == doctest::Approx(0.0));
CHECK(q_y[3] == doctest::Approx(0.923879));
Vector3 euler_p(pitch, 0.0, 0.0);
- Quaternion q_p(euler_p);
+ Quaternion q_p = Quaternion::from_euler(euler_p);
CHECK(q_p[0] == doctest::Approx(0.258819));
CHECK(q_p[1] == doctest::Approx(0.0));
CHECK(q_p[2] == doctest::Approx(0.0));
CHECK(q_p[3] == doctest::Approx(0.965926));
Vector3 euler_r(0.0, 0.0, roll);
- Quaternion q_r(euler_r);
+ Quaternion q_r = Quaternion::from_euler(euler_r);
CHECK(q_r[0] == doctest::Approx(0.0));
CHECK(q_r[1] == doctest::Approx(0.0));
CHECK(q_r[2] == doctest::Approx(0.0871558));
@@ -334,7 +351,7 @@ TEST_CASE("[Quaternion] xform unit vectors") {
TEST_CASE("[Quaternion] xform vector") {
// Arbitrary quaternion rotates an arbitrary vector.
Vector3 euler_yzx(Math::deg_to_rad(31.41), Math::deg_to_rad(-49.16), Math::deg_to_rad(12.34));
- Basis basis_axes(euler_yzx);
+ Basis basis_axes = Basis::from_euler(euler_yzx);
Quaternion q(basis_axes);
Vector3 v_arb(3.0, 4.0, 5.0);
@@ -347,7 +364,7 @@ TEST_CASE("[Quaternion] xform vector") {
// Test vector xform for a single combination of Quaternion and Vector.
void test_quat_vec_rotate(Vector3 euler_yzx, Vector3 v_in) {
- Basis basis_axes(euler_yzx);
+ Basis basis_axes = Basis::from_euler(euler_yzx);
Quaternion q(basis_axes);
Vector3 v_rot = q.xform(v_in);
@@ -384,6 +401,63 @@ TEST_CASE("[Stress][Quaternion] Many vector xforms") {
}
}
+TEST_CASE("[Quaternion] Finite number checks") {
+ const real_t x = NAN;
+
+ CHECK_MESSAGE(
+ Quaternion(0, 1, 2, 3).is_finite(),
+ "Quaternion with all components finite should be finite");
+
+ CHECK_FALSE_MESSAGE(
+ Quaternion(x, 1, 2, 3).is_finite(),
+ "Quaternion with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Quaternion(0, x, 2, 3).is_finite(),
+ "Quaternion with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Quaternion(0, 1, x, 3).is_finite(),
+ "Quaternion with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Quaternion(0, 1, 2, x).is_finite(),
+ "Quaternion with one component infinite should not be finite.");
+
+ CHECK_FALSE_MESSAGE(
+ Quaternion(x, x, 2, 3).is_finite(),
+ "Quaternion with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Quaternion(x, 1, x, 3).is_finite(),
+ "Quaternion with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Quaternion(x, 1, 2, x).is_finite(),
+ "Quaternion with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Quaternion(0, x, x, 3).is_finite(),
+ "Quaternion with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Quaternion(0, x, 2, x).is_finite(),
+ "Quaternion with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Quaternion(0, 1, x, x).is_finite(),
+ "Quaternion with two components infinite should not be finite.");
+
+ CHECK_FALSE_MESSAGE(
+ Quaternion(0, x, x, x).is_finite(),
+ "Quaternion with three components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Quaternion(x, 1, x, x).is_finite(),
+ "Quaternion with three components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Quaternion(x, x, 2, x).is_finite(),
+ "Quaternion with three components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Quaternion(x, x, x, 3).is_finite(),
+ "Quaternion with three components infinite should not be finite.");
+
+ CHECK_FALSE_MESSAGE(
+ Quaternion(x, x, x, x).is_finite(),
+ "Quaternion with four components infinite should not be finite.");
+}
+
} // namespace TestQuaternion
#endif // TEST_QUATERNION_H
diff --git a/tests/core/math/test_rect2.h b/tests/core/math/test_rect2.h
index 6323b214db..9984823331 100644
--- a/tests/core/math/test_rect2.h
+++ b/tests/core/math/test_rect2.h
@@ -102,16 +102,16 @@ TEST_CASE("[Rect2] Basic setters") {
TEST_CASE("[Rect2] Area getters") {
CHECK_MESSAGE(
- Math::is_equal_approx(Rect2(0, 100, 1280, 720).get_area(), 921'600),
+ Rect2(0, 100, 1280, 720).get_area() == doctest::Approx(921'600),
"get_area() should return the expected value.");
CHECK_MESSAGE(
- Math::is_equal_approx(Rect2(0, 100, -1280, -720).get_area(), 921'600),
+ Rect2(0, 100, -1280, -720).get_area() == doctest::Approx(921'600),
"get_area() should return the expected value.");
CHECK_MESSAGE(
- Math::is_equal_approx(Rect2(0, 100, 1280, -720).get_area(), -921'600),
+ Rect2(0, 100, 1280, -720).get_area() == doctest::Approx(-921'600),
"get_area() should return the expected value.");
CHECK_MESSAGE(
- Math::is_equal_approx(Rect2(0, 100, -1280, 720).get_area(), -921'600),
+ Rect2(0, 100, -1280, 720).get_area() == doctest::Approx(-921'600),
"get_area() should return the expected value.");
CHECK_MESSAGE(
Math::is_zero_approx(Rect2(0, 100, 0, 720).get_area()),
@@ -300,6 +300,27 @@ TEST_CASE("[Rect2] Merging") {
Rect2(0, 100, 1280, 720).merge(Rect2(-4000, -4000, 100, 100)).is_equal_approx(Rect2(-4000, -4000, 5280, 4820)),
"merge() with non-enclosed Rect2 should return the expected result.");
}
+
+TEST_CASE("[Rect2] Finite number checks") {
+ const Vector2 x(0, 1);
+ const Vector2 infinite(NAN, NAN);
+
+ CHECK_MESSAGE(
+ Rect2(x, x).is_finite(),
+ "Rect2 with all components finite should be finite");
+
+ CHECK_FALSE_MESSAGE(
+ Rect2(infinite, x).is_finite(),
+ "Rect2 with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Rect2(x, infinite).is_finite(),
+ "Rect2 with one component infinite should not be finite.");
+
+ CHECK_FALSE_MESSAGE(
+ Rect2(infinite, infinite).is_finite(),
+ "Rect2 with two components infinite should not be finite.");
+}
+
} // namespace TestRect2
#endif // TEST_RECT2_H
diff --git a/tests/core/math/test_transform_2d.h b/tests/core/math/test_transform_2d.h
index 697bf63fc5..ab51bcd7da 100644
--- a/tests/core/math/test_transform_2d.h
+++ b/tests/core/math/test_transform_2d.h
@@ -83,6 +83,40 @@ TEST_CASE("[Transform2D] rotation") {
CHECK(orig.rotated(phi) == R * orig);
CHECK(orig.rotated_local(phi) == orig * R);
}
+
+TEST_CASE("[Transform2D] Finite number checks") {
+ const Vector2 x(0, 1);
+ const Vector2 infinite(NAN, NAN);
+
+ CHECK_MESSAGE(
+ Transform2D(x, x, x).is_finite(),
+ "Transform2D with all components finite should be finite");
+
+ CHECK_FALSE_MESSAGE(
+ Transform2D(infinite, x, x).is_finite(),
+ "Transform2D with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Transform2D(x, infinite, x).is_finite(),
+ "Transform2D with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Transform2D(x, x, infinite).is_finite(),
+ "Transform2D with one component infinite should not be finite.");
+
+ CHECK_FALSE_MESSAGE(
+ Transform2D(infinite, infinite, x).is_finite(),
+ "Transform2D with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Transform2D(infinite, x, infinite).is_finite(),
+ "Transform2D with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Transform2D(x, infinite, infinite).is_finite(),
+ "Transform2D with two components infinite should not be finite.");
+
+ CHECK_FALSE_MESSAGE(
+ Transform2D(infinite, infinite, infinite).is_finite(),
+ "Transform2D with three components infinite should not be finite.");
+}
+
} // namespace TestTransform2D
#endif // TEST_TRANSFORM_2D_H
diff --git a/tests/core/math/test_transform_3d.h b/tests/core/math/test_transform_3d.h
index da166b43f7..d2730f3577 100644
--- a/tests/core/math/test_transform_3d.h
+++ b/tests/core/math/test_transform_3d.h
@@ -84,6 +84,29 @@ TEST_CASE("[Transform3D] rotation") {
CHECK(orig.rotated(axis, phi) == R * orig);
CHECK(orig.rotated_local(axis, phi) == orig * R);
}
+
+TEST_CASE("[Transform3D] Finite number checks") {
+ const Vector3 y(0, 1, 2);
+ const Vector3 infinite_vec(NAN, NAN, NAN);
+ const Basis x(y, y, y);
+ const Basis infinite_basis(infinite_vec, infinite_vec, infinite_vec);
+
+ CHECK_MESSAGE(
+ Transform3D(x, y).is_finite(),
+ "Transform3D with all components finite should be finite");
+
+ CHECK_FALSE_MESSAGE(
+ Transform3D(x, infinite_vec).is_finite(),
+ "Transform3D with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Transform3D(infinite_basis, y).is_finite(),
+ "Transform3D with one component infinite should not be finite.");
+
+ CHECK_FALSE_MESSAGE(
+ Transform3D(infinite_basis, infinite_vec).is_finite(),
+ "Transform3D with two components infinite should not be finite.");
+}
+
} // namespace TestTransform3D
#endif // TEST_TRANSFORM_3D_H
diff --git a/tests/core/math/test_vector2.h b/tests/core/math/test_vector2.h
index 9b7800164a..8f8fccd717 100644
--- a/tests/core/math/test_vector2.h
+++ b/tests/core/math/test_vector2.h
@@ -37,20 +37,28 @@
namespace TestVector2 {
+TEST_CASE("[Vector2] Constructor methods") {
+ const Vector2 vector_empty = Vector2();
+ const Vector2 vector_zero = Vector2(0.0, 0.0);
+ CHECK_MESSAGE(
+ vector_empty == vector_zero,
+ "Vector2 Constructor with no inputs should return a zero Vector2.");
+}
+
TEST_CASE("[Vector2] Angle methods") {
const Vector2 vector_x = Vector2(1, 0);
const Vector2 vector_y = Vector2(0, 1);
CHECK_MESSAGE(
- Math::is_equal_approx(vector_x.angle_to(vector_y), (real_t)Math_TAU / 4),
+ vector_x.angle_to(vector_y) == doctest::Approx((real_t)Math_TAU / 4),
"Vector2 angle_to should work as expected.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector_y.angle_to(vector_x), (real_t)-Math_TAU / 4),
+ vector_y.angle_to(vector_x) == doctest::Approx((real_t)-Math_TAU / 4),
"Vector2 angle_to should work as expected.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector_x.angle_to_point(vector_y), (real_t)Math_TAU * 3 / 8),
+ vector_x.angle_to_point(vector_y) == doctest::Approx((real_t)Math_TAU * 3 / 8),
"Vector2 angle_to_point should work as expected.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector_y.angle_to_point(vector_x), (real_t)-Math_TAU / 8),
+ vector_y.angle_to_point(vector_x) == doctest::Approx((real_t)-Math_TAU / 8),
"Vector2 angle_to_point should work as expected.");
}
@@ -102,10 +110,13 @@ TEST_CASE("[Vector2] Interpolation methods") {
Vector2(1, 1).slerp(Vector2(), 0.5) == Vector2(0.5, 0.5),
"Vector2 slerp with one input as zero should behave like a regular lerp.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.slerp(vector2, 0.5).length(), (real_t)4.31959610746631919),
+ Vector2(4, 6).slerp(Vector2(8, 10), 0.5).is_equal_approx(Vector2(5.9076470794008017626, 8.07918879020090480697)),
+ "Vector2 slerp should work as expected.");
+ CHECK_MESSAGE(
+ vector1.slerp(vector2, 0.5).length() == doctest::Approx((real_t)4.31959610746631919),
"Vector2 slerp with different length input should return a vector with an interpolated length.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.angle_to(vector1.slerp(vector2, 0.5)) * 2, vector1.angle_to(vector2)),
+ vector1.angle_to(vector1.slerp(vector2, 0.5)) * 2 == doctest::Approx(vector1.angle_to(vector2)),
"Vector2 slerp with different length input should return a vector with an interpolated angle.");
CHECK_MESSAGE(
vector1.cubic_interpolate(vector2, Vector2(), Vector2(7, 7), 0.5) == Vector2(2.375, 3.5),
@@ -125,19 +136,19 @@ TEST_CASE("[Vector2] Length methods") {
vector1.length_squared() == 200,
"Vector2 length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.length(), 10 * (real_t)Math_SQRT2),
+ vector1.length() == doctest::Approx(10 * (real_t)Math_SQRT2),
"Vector2 length should work as expected.");
CHECK_MESSAGE(
vector2.length_squared() == 1300,
"Vector2 length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector2.length(), (real_t)36.05551275463989293119),
+ vector2.length() == doctest::Approx((real_t)36.05551275463989293119),
"Vector2 length should work as expected.");
CHECK_MESSAGE(
vector1.distance_squared_to(vector2) == 500,
"Vector2 distance_squared_to should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.distance_to(vector2), (real_t)22.36067977499789696409),
+ vector1.distance_to(vector2) == doctest::Approx((real_t)22.36067977499789696409),
"Vector2 distance_to should work as expected.");
}
@@ -171,6 +182,15 @@ TEST_CASE("[Vector2] Normalization methods") {
CHECK_MESSAGE(
Vector2(1, 1).normalized().is_equal_approx(Vector2(Math_SQRT12, Math_SQRT12)),
"Vector2 normalized should work as expected.");
+
+ Vector2 vector = Vector2(3.2, -5.4);
+ vector.normalize();
+ CHECK_MESSAGE(
+ vector == Vector2(3.2, -5.4).normalized(),
+ "Vector2 normalize should convert same way as Vector2 normalized.");
+ CHECK_MESSAGE(
+ vector.is_equal_approx(Vector2(0.509802390301732898898, -0.860291533634174266891)),
+ "Vector2 normalize should work as expected.");
}
TEST_CASE("[Vector2] Operators") {
@@ -274,14 +294,16 @@ TEST_CASE("[Vector2] Operators") {
TEST_CASE("[Vector2] Other methods") {
const Vector2 vector = Vector2(1.2, 3.4);
CHECK_MESSAGE(
- Math::is_equal_approx(vector.aspect(), (real_t)1.2 / (real_t)3.4),
+ vector.aspect() == doctest::Approx((real_t)1.2 / (real_t)3.4),
"Vector2 aspect should work as expected.");
+
CHECK_MESSAGE(
vector.direction_to(Vector2()).is_equal_approx(-vector.normalized()),
"Vector2 direction_to should work as expected.");
CHECK_MESSAGE(
Vector2(1, 1).direction_to(Vector2(2, 2)).is_equal_approx(Vector2(Math_SQRT12, Math_SQRT12)),
"Vector2 direction_to should work as expected.");
+
CHECK_MESSAGE(
vector.posmod(2).is_equal_approx(Vector2(1.2, 1.4)),
"Vector2 posmod should work as expected.");
@@ -294,10 +316,21 @@ TEST_CASE("[Vector2] Other methods") {
CHECK_MESSAGE(
(-vector).posmodv(Vector2(2, 3)).is_equal_approx(Vector2(0.8, 2.6)),
"Vector2 posmodv should work as expected.");
+
+ CHECK_MESSAGE(
+ vector.rotated(Math_TAU).is_equal_approx(Vector2(1.2, 3.4)),
+ "Vector2 rotated should work as expected.");
CHECK_MESSAGE(
vector.rotated(Math_TAU / 4).is_equal_approx(Vector2(-3.4, 1.2)),
"Vector2 rotated should work as expected.");
CHECK_MESSAGE(
+ vector.rotated(Math_TAU / 3).is_equal_approx(Vector2(-3.544486372867091398996, -0.660769515458673623883)),
+ "Vector2 rotated should work as expected.");
+ CHECK_MESSAGE(
+ vector.rotated(Math_TAU / 2).is_equal_approx(vector.rotated(Math_TAU / -2)),
+ "Vector2 rotated should work as expected.");
+
+ CHECK_MESSAGE(
vector.snapped(Vector2(1, 1)) == Vector2(1, 3),
"Vector2 snapped to integers should be the same as rounding.");
CHECK_MESSAGE(
@@ -306,23 +339,57 @@ TEST_CASE("[Vector2] Other methods") {
CHECK_MESSAGE(
vector.snapped(Vector2(0.25, 0.25)) == Vector2(1.25, 3.5),
"Vector2 snapped to 0.25 should give exact results.");
+
+ CHECK_MESSAGE(
+ Vector2(1.2, 2.5).is_equal_approx(vector.min(Vector2(3.0, 2.5))),
+ "Vector2 min should return expected value.");
+
+ CHECK_MESSAGE(
+ Vector2(5.3, 3.4).is_equal_approx(vector.max(Vector2(5.3, 2.0))),
+ "Vector2 max should return expected value.");
}
TEST_CASE("[Vector2] Plane methods") {
const Vector2 vector = Vector2(1.2, 3.4);
const Vector2 vector_y = Vector2(0, 1);
+ const Vector2 vector_normal = Vector2(0.95879811270838721622267, 0.2840883296913739899919);
+ const Vector2 vector_non_normal = Vector2(5.4, 1.6);
CHECK_MESSAGE(
vector.bounce(vector_y) == Vector2(1.2, -3.4),
"Vector2 bounce on a plane with normal of the Y axis should.");
CHECK_MESSAGE(
+ vector.bounce(vector_normal).is_equal_approx(Vector2(-2.85851197982345523329, 2.197477931904161412358)),
+ "Vector2 bounce with normal should return expected value.");
+ CHECK_MESSAGE(
vector.reflect(vector_y) == Vector2(-1.2, 3.4),
"Vector2 reflect on a plane with normal of the Y axis should.");
CHECK_MESSAGE(
+ vector.reflect(vector_normal).is_equal_approx(Vector2(2.85851197982345523329, -2.197477931904161412358)),
+ "Vector2 reflect with normal should return expected value.");
+ CHECK_MESSAGE(
vector.project(vector_y) == Vector2(0, 3.4),
- "Vector2 projected on the X axis should only give the Y component.");
+ "Vector2 projected on the Y axis should only give the Y component.");
+ CHECK_MESSAGE(
+ vector.project(vector_normal).is_equal_approx(Vector2(2.0292559899117276166, 0.60126103404791929382)),
+ "Vector2 projected on a normal should return expected value.");
CHECK_MESSAGE(
vector.slide(vector_y) == Vector2(1.2, 0),
"Vector2 slide on a plane with normal of the Y axis should set the Y to zero.");
+ CHECK_MESSAGE(
+ vector.slide(vector_normal).is_equal_approx(Vector2(-0.8292559899117276166456, 2.798738965952080706179)),
+ "Vector2 slide with normal should return expected value.");
+ // There's probably a better way to test these ones?
+ ERR_PRINT_OFF;
+ CHECK_MESSAGE(
+ vector.bounce(vector_non_normal).is_equal_approx(Vector2()),
+ "Vector2 bounce should return empty Vector2 with non-normalized input.");
+ CHECK_MESSAGE(
+ vector.reflect(vector_non_normal).is_equal_approx(Vector2()),
+ "Vector2 reflect should return empty Vector2 with non-normalized input.");
+ CHECK_MESSAGE(
+ vector.slide(vector_non_normal).is_equal_approx(Vector2()),
+ "Vector2 slide should return empty Vector2 with non-normalized input.");
+ ERR_PRINT_ON;
}
TEST_CASE("[Vector2] Rounding methods") {
@@ -367,12 +434,20 @@ TEST_CASE("[Vector2] Rounding methods") {
TEST_CASE("[Vector2] Linear algebra methods") {
const Vector2 vector_x = Vector2(1, 0);
const Vector2 vector_y = Vector2(0, 1);
+ const Vector2 a = Vector2(3.5, 8.5);
+ const Vector2 b = Vector2(5.2, 4.6);
CHECK_MESSAGE(
vector_x.cross(vector_y) == 1,
"Vector2 cross product of X and Y should give 1.");
CHECK_MESSAGE(
vector_y.cross(vector_x) == -1,
"Vector2 cross product of Y and X should give negative 1.");
+ CHECK_MESSAGE(
+ a.cross(b) == doctest::Approx((real_t)-28.1),
+ "Vector2 cross should return expected value.");
+ CHECK_MESSAGE(
+ Vector2(-a.x, a.y).cross(Vector2(b.x, -b.y)) == doctest::Approx((real_t)-28.1),
+ "Vector2 cross should return expected value.");
CHECK_MESSAGE(
vector_x.dot(vector_y) == 0.0,
@@ -383,7 +458,39 @@ TEST_CASE("[Vector2] Linear algebra methods") {
CHECK_MESSAGE(
(vector_x * 10).dot(vector_x * 10) == 100.0,
"Vector2 dot product of same direction vectors should behave as expected.");
+ CHECK_MESSAGE(
+ a.dot(b) == doctest::Approx((real_t)57.3),
+ "Vector2 dot should return expected value.");
+ CHECK_MESSAGE(
+ Vector2(-a.x, a.y).dot(Vector2(b.x, -b.y)) == doctest::Approx((real_t)-57.3),
+ "Vector2 dot should return expected value.");
+}
+
+TEST_CASE("[Vector2] Finite number checks") {
+ const double infinite[] = { NAN, INFINITY, -INFINITY };
+
+ CHECK_MESSAGE(
+ Vector2(0, 1).is_finite(),
+ "Vector2(0, 1) should be finite");
+
+ for (double x : infinite) {
+ CHECK_FALSE_MESSAGE(
+ Vector2(x, 1).is_finite(),
+ "Vector2 with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector2(0, x).is_finite(),
+ "Vector2 with one component infinite should not be finite.");
+ }
+
+ for (double x : infinite) {
+ for (double y : infinite) {
+ CHECK_FALSE_MESSAGE(
+ Vector2(x, y).is_finite(),
+ "Vector2 with two components infinite should not be finite.");
+ }
+ }
}
+
} // namespace TestVector2
#endif // TEST_VECTOR2_H
diff --git a/tests/core/math/test_vector2i.h b/tests/core/math/test_vector2i.h
index 841bb793a4..c7a0dccdcc 100644
--- a/tests/core/math/test_vector2i.h
+++ b/tests/core/math/test_vector2i.h
@@ -37,6 +37,14 @@
namespace TestVector2i {
+TEST_CASE("[Vector2i] Constructor methods") {
+ const Vector2i vector_empty = Vector2i();
+ const Vector2i vector_zero = Vector2i(0, 0);
+ CHECK_MESSAGE(
+ vector_empty == vector_zero,
+ "Vector2i Constructor with no inputs should return a zero Vector2i.");
+}
+
TEST_CASE("[Vector2i] Axis methods") {
Vector2i vector = Vector2i(2, 3);
CHECK_MESSAGE(
@@ -71,13 +79,13 @@ TEST_CASE("[Vector2i] Length methods") {
vector1.length_squared() == 200,
"Vector2i length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.length(), 10 * Math_SQRT2),
+ vector1.length() == doctest::Approx(10 * Math_SQRT2),
"Vector2i length should work as expected.");
CHECK_MESSAGE(
vector2.length_squared() == 1300,
"Vector2i length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector2.length(), 36.05551275463989293119),
+ vector2.length() == doctest::Approx(36.05551275463989293119),
"Vector2i length should work as expected.");
}
@@ -119,8 +127,16 @@ TEST_CASE("[Vector2i] Operators") {
TEST_CASE("[Vector2i] Other methods") {
const Vector2i vector = Vector2i(1, 3);
CHECK_MESSAGE(
- Math::is_equal_approx(vector.aspect(), (real_t)1.0 / (real_t)3.0),
+ vector.aspect() == doctest::Approx((real_t)1.0 / (real_t)3.0),
"Vector2i aspect should work as expected.");
+
+ CHECK_MESSAGE(
+ Vector2i(1, 2) == vector.min(Vector2i(3, 2)),
+ "Vector2i min should return expected value.");
+
+ CHECK_MESSAGE(
+ Vector2i(5, 3) == vector.max(Vector2i(5, 2)),
+ "Vector2i max should return expected value.");
}
TEST_CASE("[Vector2i] Abs and sign methods") {
diff --git a/tests/core/math/test_vector3.h b/tests/core/math/test_vector3.h
index 6f99fada2b..89d73ee6de 100644
--- a/tests/core/math/test_vector3.h
+++ b/tests/core/math/test_vector3.h
@@ -39,31 +39,39 @@
namespace TestVector3 {
+TEST_CASE("[Vector3] Constructor methods") {
+ const Vector3 vector_empty = Vector3();
+ const Vector3 vector_zero = Vector3(0.0, 0.0, 0.0);
+ CHECK_MESSAGE(
+ vector_empty == vector_zero,
+ "Vector3 Constructor with no inputs should return a zero Vector3.");
+}
+
TEST_CASE("[Vector3] Angle methods") {
const Vector3 vector_x = Vector3(1, 0, 0);
const Vector3 vector_y = Vector3(0, 1, 0);
const Vector3 vector_yz = Vector3(0, 1, 1);
CHECK_MESSAGE(
- Math::is_equal_approx(vector_x.angle_to(vector_y), (real_t)Math_TAU / 4),
+ vector_x.angle_to(vector_y) == doctest::Approx((real_t)Math_TAU / 4),
"Vector3 angle_to should work as expected.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector_x.angle_to(vector_yz), (real_t)Math_TAU / 4),
+ vector_x.angle_to(vector_yz) == doctest::Approx((real_t)Math_TAU / 4),
"Vector3 angle_to should work as expected.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector_yz.angle_to(vector_x), (real_t)Math_TAU / 4),
+ vector_yz.angle_to(vector_x) == doctest::Approx((real_t)Math_TAU / 4),
"Vector3 angle_to should work as expected.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector_y.angle_to(vector_yz), (real_t)Math_TAU / 8),
+ vector_y.angle_to(vector_yz) == doctest::Approx((real_t)Math_TAU / 8),
"Vector3 angle_to should work as expected.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector_x.signed_angle_to(vector_y, vector_y), (real_t)Math_TAU / 4),
+ vector_x.signed_angle_to(vector_y, vector_y) == doctest::Approx((real_t)Math_TAU / 4),
"Vector3 signed_angle_to edge case should be positive.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector_x.signed_angle_to(vector_yz, vector_y), (real_t)Math_TAU / -4),
+ vector_x.signed_angle_to(vector_yz, vector_y) == doctest::Approx((real_t)Math_TAU / -4),
"Vector3 signed_angle_to should work as expected.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector_yz.signed_angle_to(vector_x, vector_y), (real_t)Math_TAU / 4),
+ vector_yz.signed_angle_to(vector_x, vector_y) == doctest::Approx((real_t)Math_TAU / 4),
"Vector3 signed_angle_to should work as expected.");
}
@@ -76,16 +84,12 @@ TEST_CASE("[Vector3] Axis methods") {
vector.min_axis_index() == Vector3::Axis::AXIS_X,
"Vector3 min_axis_index should work as expected.");
CHECK_MESSAGE(
- vector.get_axis(vector.max_axis_index()) == (real_t)5.6,
- "Vector3 get_axis should work as expected.");
+ vector[vector.max_axis_index()] == (real_t)5.6,
+ "Vector3 array operator should work as expected.");
CHECK_MESSAGE(
vector[vector.min_axis_index()] == (real_t)1.2,
"Vector3 array operator should work as expected.");
- vector.set_axis(Vector3::Axis::AXIS_Y, 4.7);
- CHECK_MESSAGE(
- vector.get_axis(Vector3::Axis::AXIS_Y) == (real_t)4.7,
- "Vector3 set_axis should work as expected.");
vector[Vector3::Axis::AXIS_Y] = 3.7;
CHECK_MESSAGE(
vector[Vector3::Axis::AXIS_Y] == (real_t)3.7,
@@ -123,10 +127,13 @@ TEST_CASE("[Vector3] Interpolation methods") {
Vector3(1, 1, 1).slerp(Vector3(), 0.5) == Vector3(0.5, 0.5, 0.5),
"Vector3 slerp with one input as zero should behave like a regular lerp.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.slerp(vector2, 0.5).length(), (real_t)6.25831088708303172),
+ Vector3(4, 6, 2).slerp(Vector3(8, 10, 3), 0.5).is_equal_approx(Vector3(5.90194219811429941053, 8.06758688849378394534, 2.558307894718317120038)),
+ "Vector3 slerp should work as expected.");
+ CHECK_MESSAGE(
+ vector1.slerp(vector2, 0.5).length() == doctest::Approx((real_t)6.25831088708303172),
"Vector3 slerp with different length input should return a vector with an interpolated length.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.angle_to(vector1.slerp(vector2, 0.5)) * 2, vector1.angle_to(vector2)),
+ vector1.angle_to(vector1.slerp(vector2, 0.5)) * 2 == doctest::Approx(vector1.angle_to(vector2)),
"Vector3 slerp with different length input should return a vector with an interpolated angle.");
CHECK_MESSAGE(
vector1.cubic_interpolate(vector2, Vector3(), Vector3(7, 7, 7), 0.5) == Vector3(2.375, 3.5, 4.625),
@@ -146,19 +153,19 @@ TEST_CASE("[Vector3] Length methods") {
vector1.length_squared() == 300,
"Vector3 length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.length(), 10 * (real_t)Math_SQRT3),
+ vector1.length() == doctest::Approx(10 * (real_t)Math_SQRT3),
"Vector3 length should work as expected.");
CHECK_MESSAGE(
vector2.length_squared() == 2900,
"Vector3 length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector2.length(), (real_t)53.8516480713450403125),
+ vector2.length() == doctest::Approx((real_t)53.8516480713450403125),
"Vector3 length should work as expected.");
CHECK_MESSAGE(
vector1.distance_squared_to(vector2) == 1400,
"Vector3 distance_squared_to should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.distance_to(vector2), (real_t)37.41657386773941385584),
+ vector1.distance_to(vector2) == doctest::Approx((real_t)37.41657386773941385584),
"Vector3 distance_to should work as expected.");
}
@@ -195,6 +202,15 @@ TEST_CASE("[Vector3] Normalization methods") {
CHECK_MESSAGE(
Vector3(1, 1, 1).normalized().is_equal_approx(Vector3(Math_SQRT13, Math_SQRT13, Math_SQRT13)),
"Vector3 normalized should work as expected.");
+
+ Vector3 vector = Vector3(3.2, -5.4, 6);
+ vector.normalize();
+ CHECK_MESSAGE(
+ vector == Vector3(3.2, -5.4, 6).normalized(),
+ "Vector3 normalize should convert same way as Vector3 normalized.");
+ CHECK_MESSAGE(
+ vector.is_equal_approx(Vector3(0.368522751763902980457, -0.621882143601586279522, 0.6909801595573180883585)),
+ "Vector3 normalize should work as expected.");
}
TEST_CASE("[Vector3] Operators") {
@@ -318,10 +334,21 @@ TEST_CASE("[Vector3] Other methods") {
CHECK_MESSAGE(
(-vector).posmodv(Vector3(2, 3, 4)).is_equal_approx(Vector3(0.8, 2.6, 2.4)),
"Vector3 posmodv should work as expected.");
+
+ CHECK_MESSAGE(
+ vector.rotated(Vector3(0, 1, 0), Math_TAU).is_equal_approx(vector),
+ "Vector3 rotated should work as expected.");
CHECK_MESSAGE(
vector.rotated(Vector3(0, 1, 0), Math_TAU / 4).is_equal_approx(Vector3(5.6, 3.4, -1.2)),
"Vector3 rotated should work as expected.");
CHECK_MESSAGE(
+ vector.rotated(Vector3(1, 0, 0), Math_TAU / 3).is_equal_approx(Vector3(1.2, -6.54974226119285642, 0.1444863728670914)),
+ "Vector3 rotated should work as expected.");
+ CHECK_MESSAGE(
+ vector.rotated(Vector3(0, 0, 1), Math_TAU / 2).is_equal_approx(vector.rotated(Vector3(0, 0, 1), Math_TAU / -2)),
+ "Vector3 rotated should work as expected.");
+
+ CHECK_MESSAGE(
vector.snapped(Vector3(1, 1, 1)) == Vector3(1, 3, 6),
"Vector3 snapped to integers should be the same as rounding.");
CHECK_MESSAGE(
@@ -332,18 +359,44 @@ TEST_CASE("[Vector3] Other methods") {
TEST_CASE("[Vector3] Plane methods") {
const Vector3 vector = Vector3(1.2, 3.4, 5.6);
const Vector3 vector_y = Vector3(0, 1, 0);
+ const Vector3 vector_normal = Vector3(0.88763458893247992491, 0.26300284116517923701, 0.37806658417494515320);
+ const Vector3 vector_non_normal = Vector3(5.4, 1.6, 2.3);
CHECK_MESSAGE(
vector.bounce(vector_y) == Vector3(1.2, -3.4, 5.6),
"Vector3 bounce on a plane with normal of the Y axis should.");
CHECK_MESSAGE(
+ vector.bounce(vector_normal).is_equal_approx(Vector3(-6.0369629829775736287, 1.25571467171034855444, 2.517589840583626047)),
+ "Vector3 bounce with normal should return expected value.");
+ CHECK_MESSAGE(
vector.reflect(vector_y) == Vector3(-1.2, 3.4, -5.6),
"Vector3 reflect on a plane with normal of the Y axis should.");
CHECK_MESSAGE(
+ vector.reflect(vector_normal).is_equal_approx(Vector3(6.0369629829775736287, -1.25571467171034855444, -2.517589840583626047)),
+ "Vector3 reflect with normal should return expected value.");
+ CHECK_MESSAGE(
vector.project(vector_y) == Vector3(0, 3.4, 0),
- "Vector3 projected on the X axis should only give the Y component.");
+ "Vector3 projected on the Y axis should only give the Y component.");
+ CHECK_MESSAGE(
+ vector.project(vector_normal).is_equal_approx(Vector3(3.61848149148878681437, 1.0721426641448257227776, 1.54120507970818697649)),
+ "Vector3 projected on a normal should return expected value.");
CHECK_MESSAGE(
vector.slide(vector_y) == Vector3(1.2, 0, 5.6),
"Vector3 slide on a plane with normal of the Y axis should set the Y to zero.");
+ CHECK_MESSAGE(
+ vector.slide(vector_normal).is_equal_approx(Vector3(-2.41848149148878681437, 2.32785733585517427722237, 4.0587949202918130235)),
+ "Vector3 slide with normal should return expected value.");
+ // There's probably a better way to test these ones?
+ ERR_PRINT_OFF;
+ CHECK_MESSAGE(
+ vector.bounce(vector_non_normal).is_equal_approx(Vector3()),
+ "Vector3 bounce should return empty Vector3 with non-normalized input.");
+ CHECK_MESSAGE(
+ vector.reflect(vector_non_normal).is_equal_approx(Vector3()),
+ "Vector3 reflect should return empty Vector3 with non-normalized input.");
+ CHECK_MESSAGE(
+ vector.slide(vector_non_normal).is_equal_approx(Vector3()),
+ "Vector3 slide should return empty Vector3 with non-normalized input.");
+ ERR_PRINT_ON;
}
TEST_CASE("[Vector3] Rounding methods") {
@@ -389,6 +442,8 @@ TEST_CASE("[Vector3] Linear algebra methods") {
const Vector3 vector_x = Vector3(1, 0, 0);
const Vector3 vector_y = Vector3(0, 1, 0);
const Vector3 vector_z = Vector3(0, 0, 1);
+ const Vector3 a = Vector3(3.5, 8.5, 2.3);
+ const Vector3 b = Vector3(5.2, 4.6, 7.8);
CHECK_MESSAGE(
vector_x.cross(vector_y) == vector_z,
"Vector3 cross product of X and Y should give Z.");
@@ -401,6 +456,12 @@ TEST_CASE("[Vector3] Linear algebra methods") {
CHECK_MESSAGE(
vector_z.cross(vector_x) == vector_y,
"Vector3 cross product of Z and X should give Y.");
+ CHECK_MESSAGE(
+ a.cross(b).is_equal_approx(Vector3(55.72, -15.34, -28.1)),
+ "Vector3 cross should return expected value.");
+ CHECK_MESSAGE(
+ Vector3(-a.x, a.y, -a.z).cross(Vector3(b.x, -b.y, b.z)).is_equal_approx(Vector3(55.72, 15.34, -28.1)),
+ "Vector2 cross should return expected value.");
CHECK_MESSAGE(
vector_x.dot(vector_y) == 0.0,
@@ -411,7 +472,58 @@ TEST_CASE("[Vector3] Linear algebra methods") {
CHECK_MESSAGE(
(vector_x * 10).dot(vector_x * 10) == 100.0,
"Vector3 dot product of same direction vectors should behave as expected.");
+ CHECK_MESSAGE(
+ a.dot(b) == doctest::Approx((real_t)75.24),
+ "Vector3 dot should return expected value.");
+ CHECK_MESSAGE(
+ Vector3(-a.x, a.y, -a.z).dot(Vector3(b.x, -b.y, b.z)) == doctest::Approx((real_t)-75.24),
+ "Vector3 dot should return expected value.");
+}
+
+TEST_CASE("[Vector3] Finite number checks") {
+ const double infinite[] = { NAN, INFINITY, -INFINITY };
+
+ CHECK_MESSAGE(
+ Vector3(0, 1, 2).is_finite(),
+ "Vector3(0, 1, 2) should be finite");
+
+ for (double x : infinite) {
+ CHECK_FALSE_MESSAGE(
+ Vector3(x, 1, 2).is_finite(),
+ "Vector3 with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector3(0, x, 2).is_finite(),
+ "Vector3 with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector3(0, 1, x).is_finite(),
+ "Vector3 with one component infinite should not be finite.");
+ }
+
+ for (double x : infinite) {
+ for (double y : infinite) {
+ CHECK_FALSE_MESSAGE(
+ Vector3(x, y, 2).is_finite(),
+ "Vector3 with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector3(x, 1, y).is_finite(),
+ "Vector3 with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector3(0, x, y).is_finite(),
+ "Vector3 with two components infinite should not be finite.");
+ }
+ }
+
+ for (double x : infinite) {
+ for (double y : infinite) {
+ for (double z : infinite) {
+ CHECK_FALSE_MESSAGE(
+ Vector3(x, y, z).is_finite(),
+ "Vector3 with three components infinite should not be finite.");
+ }
+ }
+ }
}
+
} // namespace TestVector3
#endif // TEST_VECTOR3_H
diff --git a/tests/core/math/test_vector3i.h b/tests/core/math/test_vector3i.h
index b1c6944eba..56578f99eb 100644
--- a/tests/core/math/test_vector3i.h
+++ b/tests/core/math/test_vector3i.h
@@ -36,6 +36,14 @@
namespace TestVector3i {
+TEST_CASE("[Vector3i] Constructor methods") {
+ const Vector3i vector_empty = Vector3i();
+ const Vector3i vector_zero = Vector3i(0, 0, 0);
+ CHECK_MESSAGE(
+ vector_empty == vector_zero,
+ "Vector3i Constructor with no inputs should return a zero Vector3i.");
+}
+
TEST_CASE("[Vector3i] Axis methods") {
Vector3i vector = Vector3i(1, 2, 3);
CHECK_MESSAGE(
@@ -45,16 +53,12 @@ TEST_CASE("[Vector3i] Axis methods") {
vector.min_axis_index() == Vector3i::Axis::AXIS_X,
"Vector3i min_axis_index should work as expected.");
CHECK_MESSAGE(
- vector.get_axis(vector.max_axis_index()) == 3,
- "Vector3i get_axis should work as expected.");
+ vector[vector.max_axis_index()] == 3,
+ "Vector3i array operator should work as expected.");
CHECK_MESSAGE(
vector[vector.min_axis_index()] == 1,
"Vector3i array operator should work as expected.");
- vector.set_axis(Vector3i::Axis::AXIS_Y, 4);
- CHECK_MESSAGE(
- vector.get_axis(Vector3i::Axis::AXIS_Y) == 4,
- "Vector3i set_axis should work as expected.");
vector[Vector3i::Axis::AXIS_Y] = 5;
CHECK_MESSAGE(
vector[Vector3i::Axis::AXIS_Y] == 5,
@@ -78,13 +82,13 @@ TEST_CASE("[Vector3i] Length methods") {
vector1.length_squared() == 300,
"Vector3i length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.length(), 10 * Math_SQRT3),
+ vector1.length() == doctest::Approx(10 * Math_SQRT3),
"Vector3i length should work as expected.");
CHECK_MESSAGE(
vector2.length_squared() == 2900,
"Vector3i length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector2.length(), 53.8516480713450403125),
+ vector2.length() == doctest::Approx(53.8516480713450403125),
"Vector3i length should work as expected.");
}
diff --git a/tests/core/math/test_vector4.h b/tests/core/math/test_vector4.h
index ccf991401b..6ed85661cb 100644
--- a/tests/core/math/test_vector4.h
+++ b/tests/core/math/test_vector4.h
@@ -38,6 +38,14 @@
namespace TestVector4 {
+TEST_CASE("[Vector4] Constructor methods") {
+ const Vector4 vector_empty = Vector4();
+ const Vector4 vector_zero = Vector4(0.0, 0.0, 0.0, 0.0);
+ CHECK_MESSAGE(
+ vector_empty == vector_zero,
+ "Vector4 Constructor with no inputs should return a zero Vector4.");
+}
+
TEST_CASE("[Vector4] Axis methods") {
Vector4 vector = Vector4(1.2, 3.4, 5.6, -0.9);
CHECK_MESSAGE(
@@ -47,16 +55,12 @@ TEST_CASE("[Vector4] Axis methods") {
vector.min_axis_index() == Vector4::Axis::AXIS_W,
"Vector4 min_axis_index should work as expected.");
CHECK_MESSAGE(
- vector.get_axis(vector.max_axis_index()) == (real_t)5.6,
- "Vector4 get_axis should work as expected.");
+ vector[vector.max_axis_index()] == (real_t)5.6,
+ "Vector4 array operator should work as expected.");
CHECK_MESSAGE(
vector[vector.min_axis_index()] == (real_t)-0.9,
"Vector4 array operator should work as expected.");
- vector.set_axis(Vector4::Axis::AXIS_Y, 4.7);
- CHECK_MESSAGE(
- vector.get_axis(Vector4::Axis::AXIS_Y) == (real_t)4.7,
- "Vector4 set_axis should work as expected.");
vector[Vector4::Axis::AXIS_Y] = 3.7;
CHECK_MESSAGE(
vector[Vector4::Axis::AXIS_Y] == (real_t)3.7,
@@ -87,19 +91,19 @@ TEST_CASE("[Vector4] Length methods") {
vector1.length_squared() == 400,
"Vector4 length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.length(), 20),
+ vector1.length() == doctest::Approx(20),
"Vector4 length should work as expected.");
CHECK_MESSAGE(
vector2.length_squared() == 5400,
"Vector4 length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector2.length(), (real_t)73.484692283495),
+ vector2.length() == doctest::Approx((real_t)73.484692283495),
"Vector4 length should work as expected.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.distance_to(vector2), (real_t)54.772255750517),
+ vector1.distance_to(vector2) == doctest::Approx((real_t)54.772255750517),
"Vector4 distance_to should work as expected.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.distance_squared_to(vector2), 3000),
+ vector1.distance_squared_to(vector2) == doctest::Approx(3000),
"Vector4 distance_squared_to should work as expected.");
}
@@ -307,9 +311,87 @@ TEST_CASE("[Vector4] Linear algebra methods") {
(vector_x * 10).dot(vector_x * 10) == 100.0,
"Vector4 dot product of same direction vectors should behave as expected.");
CHECK_MESSAGE(
- Math::is_equal_approx((vector1 * 2).dot(vector2 * 4), (real_t)-25.9 * 8),
+ (vector1 * 2).dot(vector2 * 4) == doctest::Approx((real_t)-25.9 * 8),
"Vector4 dot product should work as expected.");
}
+
+TEST_CASE("[Vector4] Finite number checks") {
+ const double infinite[] = { NAN, INFINITY, -INFINITY };
+
+ CHECK_MESSAGE(
+ Vector4(0, 1, 2, 3).is_finite(),
+ "Vector4(0, 1, 2, 3) should be finite");
+
+ for (double x : infinite) {
+ CHECK_FALSE_MESSAGE(
+ Vector4(x, 1, 2, 3).is_finite(),
+ "Vector4 with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector4(0, x, 2, 3).is_finite(),
+ "Vector4 with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector4(0, 1, x, 3).is_finite(),
+ "Vector4 with one component infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector4(0, 1, 2, x).is_finite(),
+ "Vector4 with one component infinite should not be finite.");
+ }
+
+ for (double x : infinite) {
+ for (double y : infinite) {
+ CHECK_FALSE_MESSAGE(
+ Vector4(x, y, 2, 3).is_finite(),
+ "Vector4 with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector4(x, 1, y, 3).is_finite(),
+ "Vector4 with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector4(x, 1, 2, y).is_finite(),
+ "Vector4 with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector4(0, x, y, 3).is_finite(),
+ "Vector4 with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector4(0, x, 2, y).is_finite(),
+ "Vector4 with two components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector4(0, 1, x, y).is_finite(),
+ "Vector4 with two components infinite should not be finite.");
+ }
+ }
+
+ for (double x : infinite) {
+ for (double y : infinite) {
+ for (double z : infinite) {
+ CHECK_FALSE_MESSAGE(
+ Vector4(0, x, y, z).is_finite(),
+ "Vector4 with three components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector4(x, 1, y, z).is_finite(),
+ "Vector4 with three components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector4(x, y, 2, z).is_finite(),
+ "Vector4 with three components infinite should not be finite.");
+ CHECK_FALSE_MESSAGE(
+ Vector4(x, y, z, 3).is_finite(),
+ "Vector4 with three components infinite should not be finite.");
+ }
+ }
+ }
+
+ for (double x : infinite) {
+ for (double y : infinite) {
+ for (double z : infinite) {
+ for (double w : infinite) {
+ CHECK_FALSE_MESSAGE(
+ Vector4(x, y, z, w).is_finite(),
+ "Vector4 with four components infinite should not be finite.");
+ }
+ }
+ }
+ }
+}
+
} // namespace TestVector4
#endif // TEST_VECTOR4_H
diff --git a/tests/core/math/test_vector4i.h b/tests/core/math/test_vector4i.h
index ac63001b24..30d38607dd 100644
--- a/tests/core/math/test_vector4i.h
+++ b/tests/core/math/test_vector4i.h
@@ -36,6 +36,14 @@
namespace TestVector4i {
+TEST_CASE("[Vector4i] Constructor methods") {
+ const Vector4i vector_empty = Vector4i();
+ const Vector4i vector_zero = Vector4i(0, 0, 0, 0);
+ CHECK_MESSAGE(
+ vector_empty == vector_zero,
+ "Vector4i Constructor with no inputs should return a zero Vector4i.");
+}
+
TEST_CASE("[Vector4i] Axis methods") {
Vector4i vector = Vector4i(1, 2, 3, 4);
CHECK_MESSAGE(
@@ -45,16 +53,12 @@ TEST_CASE("[Vector4i] Axis methods") {
vector.min_axis_index() == Vector4i::Axis::AXIS_X,
"Vector4i min_axis_index should work as expected.");
CHECK_MESSAGE(
- vector.get_axis(vector.max_axis_index()) == 4,
- "Vector4i get_axis should work as expected.");
+ vector[vector.max_axis_index()] == 4,
+ "Vector4i array operator should work as expected.");
CHECK_MESSAGE(
vector[vector.min_axis_index()] == 1,
"Vector4i array operator should work as expected.");
- vector.set_axis(Vector4i::Axis::AXIS_Y, 5);
- CHECK_MESSAGE(
- vector.get_axis(Vector4i::Axis::AXIS_Y) == 5,
- "Vector4i set_axis should work as expected.");
vector[Vector4i::Axis::AXIS_Y] = 5;
CHECK_MESSAGE(
vector[Vector4i::Axis::AXIS_Y] == 5,
@@ -78,13 +82,13 @@ TEST_CASE("[Vector4i] Length methods") {
vector1.length_squared() == 400,
"Vector4i length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector1.length(), 20),
+ vector1.length() == doctest::Approx(20),
"Vector4i length should work as expected.");
CHECK_MESSAGE(
vector2.length_squared() == 5400,
"Vector4i length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
- Math::is_equal_approx(vector2.length(), 73.4846922835),
+ vector2.length() == doctest::Approx(73.4846922835),
"Vector4i length should work as expected.");
}
diff --git a/tests/core/object/test_class_db.h b/tests/core/object/test_class_db.h
index 208923edb9..b0375c63b9 100644
--- a/tests/core/object/test_class_db.h
+++ b/tests/core/object/test_class_db.h
@@ -666,6 +666,10 @@ void add_exposed_classes(Context &r_context) {
} else {
exposed_class.methods.push_back(method);
}
+
+ if (method.is_virtual) {
+ TEST_COND(String(method.name)[0] != '_', "Virtual method ", String(method.name), " does not start with underscore.");
+ }
}
// Add signals
diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h
index d97da05c04..7e4e3aa9f0 100644
--- a/tests/core/string/test_string.h
+++ b/tests/core/string/test_string.h
@@ -411,9 +411,13 @@ TEST_CASE("[String] Number to string") {
CHECK(String::num_real(3.141593) == "3.141593");
CHECK(String::num_real(3.141) == "3.141"); // No trailing zeros.
#ifdef REAL_T_IS_DOUBLE
+ CHECK_MESSAGE(String::num_real(123.456789) == "123.456789", "Prints the appropriate amount of digits for real_t = double.");
+ CHECK_MESSAGE(String::num_real(-123.456789) == "-123.456789", "Prints the appropriate amount of digits for real_t = double.");
CHECK_MESSAGE(String::num_real(Math_PI) == "3.14159265358979", "Prints the appropriate amount of digits for real_t = double.");
CHECK_MESSAGE(String::num_real(3.1415f) == "3.1414999961853", "Prints more digits of 32-bit float when real_t = double (ones that would be reliable for double) and no trailing zero.");
#else
+ CHECK_MESSAGE(String::num_real(123.456789) == "123.4568", "Prints the appropriate amount of digits for real_t = float.");
+ CHECK_MESSAGE(String::num_real(-123.456789) == "-123.4568", "Prints the appropriate amount of digits for real_t = float.");
CHECK_MESSAGE(String::num_real(Math_PI) == "3.141593", "Prints the appropriate amount of digits for real_t = float.");
CHECK_MESSAGE(String::num_real(3.1415f) == "3.1415", "Prints only reliable digits of 32-bit float when real_t = float.");
#endif // REAL_T_IS_DOUBLE
@@ -481,6 +485,7 @@ TEST_CASE("[String] Splitting") {
const char *slices_l[3] = { "Mars", "Jupiter", "Saturn,Uranus" };
const char *slices_r[3] = { "Mars,Jupiter", "Saturn", "Uranus" };
+ const char *slices_3[4] = { "t", "e", "s", "t" };
l = s.split(",", true, 2);
CHECK(l.size() == 3);
@@ -494,6 +499,13 @@ TEST_CASE("[String] Splitting") {
CHECK(l[i] == slices_r[i]);
}
+ s = "test";
+ l = s.split();
+ CHECK(l.size() == 4);
+ for (int i = 0; i < l.size(); i++) {
+ CHECK(l[i] == slices_3[i]);
+ }
+
s = "Mars Jupiter Saturn Uranus";
const char *slices_s[4] = { "Mars", "Jupiter", "Saturn", "Uranus" };
l = s.split_spaces();
@@ -740,6 +752,14 @@ TEST_CASE("[String] sprintf") {
REQUIRE(error == false);
CHECK(output == String("fish 99.990000 frog"));
+ // Real (infinity) left-padded
+ format = "fish %11f frog";
+ args.clear();
+ args.push_back(INFINITY);
+ output = format.sprintf(args, &error);
+ REQUIRE(error == false);
+ CHECK(output == String("fish inf frog"));
+
// Real right-padded.
format = "fish %-11f frog";
args.clear();
@@ -840,6 +860,14 @@ TEST_CASE("[String] sprintf") {
REQUIRE(error == false);
CHECK(output == String("fish ( 19.990000, 1.000000, -2.050000) frog"));
+ // Vector left-padded with inf/nan
+ format = "fish %11v frog";
+ args.clear();
+ args.push_back(Variant(Vector2(INFINITY, NAN)));
+ output = format.sprintf(args, &error);
+ REQUIRE(error == false);
+ CHECK(output == String("fish ( inf, nan) frog"));
+
// Vector right-padded.
format = "fish %-11v frog";
args.clear();
@@ -1408,20 +1436,22 @@ TEST_CASE("[String] dedent") {
}
TEST_CASE("[String] Path functions") {
- static const char *path[7] = { "C:\\Godot\\project\\test.tscn", "/Godot/project/test.xscn", "../Godot/project/test.scn", "Godot\\test.doc", "C:\\test.", "res://test", "/.test" };
- static const char *base_dir[7] = { "C:\\Godot\\project", "/Godot/project", "../Godot/project", "Godot", "C:\\", "res://", "/" };
- static const char *base_name[7] = { "C:\\Godot\\project\\test", "/Godot/project/test", "../Godot/project/test", "Godot\\test", "C:\\test", "res://test", "/" };
- static const char *ext[7] = { "tscn", "xscn", "scn", "doc", "", "", "test" };
- static const char *file[7] = { "test.tscn", "test.xscn", "test.scn", "test.doc", "test.", "test", ".test" };
- static const bool abs[7] = { true, true, false, false, true, true, true };
-
- for (int i = 0; i < 7; i++) {
+ static const char *path[8] = { "C:\\Godot\\project\\test.tscn", "/Godot/project/test.xscn", "../Godot/project/test.scn", "Godot\\test.doc", "C:\\test.", "res://test", "user://test", "/.test" };
+ static const char *base_dir[8] = { "C:\\Godot\\project", "/Godot/project", "../Godot/project", "Godot", "C:\\", "res://", "user://", "/" };
+ static const char *base_name[8] = { "C:\\Godot\\project\\test", "/Godot/project/test", "../Godot/project/test", "Godot\\test", "C:\\test", "res://test", "user://test", "/" };
+ static const char *ext[8] = { "tscn", "xscn", "scn", "doc", "", "", "", "test" };
+ static const char *file[8] = { "test.tscn", "test.xscn", "test.scn", "test.doc", "test.", "test", "test", ".test" };
+ static const char *simplified[8] = { "C:/Godot/project/test.tscn", "/Godot/project/test.xscn", "Godot/project/test.scn", "Godot/test.doc", "C:/test.", "res://test", "user://test", "/.test" };
+ static const bool abs[8] = { true, true, false, false, true, true, true, true };
+
+ for (int i = 0; i < 8; i++) {
CHECK(String(path[i]).get_base_dir() == base_dir[i]);
CHECK(String(path[i]).get_basename() == base_name[i]);
CHECK(String(path[i]).get_extension() == ext[i]);
CHECK(String(path[i]).get_file() == file[i]);
CHECK(String(path[i]).is_absolute_path() == abs[i]);
CHECK(String(path[i]).is_relative_path() != abs[i]);
+ CHECK(String(path[i]).simplify_path() == String(simplified[i]));
CHECK(String(path[i]).simplify_path().get_base_dir().path_join(file[i]) == String(path[i]).simplify_path());
}
diff --git a/tests/core/templates/test_command_queue.h b/tests/core/templates/test_command_queue.h
index 0d016f5d06..db1e436ed9 100644
--- a/tests/core/templates/test_command_queue.h
+++ b/tests/core/templates/test_command_queue.h
@@ -38,8 +38,6 @@
#include "core/templates/command_queue_mt.h"
#include "tests/test_macros.h"
-#if !defined(NO_THREADS)
-
namespace TestCommandQueue {
class ThreadWork {
@@ -426,6 +424,4 @@ TEST_CASE("[Stress][CommandQueue] Stress test command queue") {
}
} // namespace TestCommandQueue
-#endif // !defined(NO_THREADS)
-
#endif // TEST_COMMAND_QUEUE_H
diff --git a/tests/scene/test_animation.h b/tests/scene/test_animation.h
index 9199713fd9..e921779c23 100644
--- a/tests/scene/test_animation.h
+++ b/tests/scene/test_animation.h
@@ -40,8 +40,8 @@ namespace TestAnimation {
TEST_CASE("[Animation] Empty animation getters") {
const Ref<Animation> animation = memnew(Animation);
- CHECK(Math::is_equal_approx(animation->get_length(), real_t(1.0)));
- CHECK(Math::is_equal_approx(animation->get_step(), real_t(0.1)));
+ CHECK(animation->get_length() == doctest::Approx(real_t(1.0)));
+ CHECK(animation->get_step() == doctest::Approx(real_t(0.1)));
}
TEST_CASE("[Animation] Create value track") {
@@ -59,33 +59,33 @@ TEST_CASE("[Animation] Create value track") {
CHECK(int(animation->track_get_key_value(0, 0)) == 0);
CHECK(int(animation->track_get_key_value(0, 1)) == 100);
- CHECK(Math::is_equal_approx(animation->value_track_interpolate(0, -0.2), 0.0));
- CHECK(Math::is_equal_approx(animation->value_track_interpolate(0, 0.0), 0.0));
- CHECK(Math::is_equal_approx(animation->value_track_interpolate(0, 0.2), 40.0));
- CHECK(Math::is_equal_approx(animation->value_track_interpolate(0, 0.4), 80.0));
- CHECK(Math::is_equal_approx(animation->value_track_interpolate(0, 0.5), 100.0));
- CHECK(Math::is_equal_approx(animation->value_track_interpolate(0, 0.6), 100.0));
+ CHECK(animation->value_track_interpolate(0, -0.2) == doctest::Approx(0.0));
+ CHECK(animation->value_track_interpolate(0, 0.0) == doctest::Approx(0.0));
+ CHECK(animation->value_track_interpolate(0, 0.2) == doctest::Approx(40.0));
+ CHECK(animation->value_track_interpolate(0, 0.4) == doctest::Approx(80.0));
+ CHECK(animation->value_track_interpolate(0, 0.5) == doctest::Approx(100.0));
+ CHECK(animation->value_track_interpolate(0, 0.6) == doctest::Approx(100.0));
- CHECK(Math::is_equal_approx(animation->track_get_key_transition(0, 0), real_t(1.0)));
- CHECK(Math::is_equal_approx(animation->track_get_key_transition(0, 1), real_t(1.0)));
+ CHECK(animation->track_get_key_transition(0, 0) == doctest::Approx(real_t(1.0)));
+ CHECK(animation->track_get_key_transition(0, 1) == doctest::Approx(real_t(1.0)));
ERR_PRINT_OFF;
// Nonexistent keys.
CHECK(animation->track_get_key_value(0, 2).is_null());
CHECK(animation->track_get_key_value(0, -1).is_null());
- CHECK(Math::is_equal_approx(animation->track_get_key_transition(0, 2), real_t(-1.0)));
+ CHECK(animation->track_get_key_transition(0, 2) == doctest::Approx(real_t(-1.0)));
// Nonexistent track (and keys).
CHECK(animation->track_get_key_value(1, 0).is_null());
CHECK(animation->track_get_key_value(1, 1).is_null());
CHECK(animation->track_get_key_value(1, 2).is_null());
CHECK(animation->track_get_key_value(1, -1).is_null());
- CHECK(Math::is_equal_approx(animation->track_get_key_transition(1, 0), real_t(-1.0)));
+ CHECK(animation->track_get_key_transition(1, 0) == doctest::Approx(real_t(-1.0)));
// This is a value track, so the methods below should return errors.
CHECK(animation->position_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
CHECK(animation->rotation_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
CHECK(animation->scale_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
- CHECK(Math::is_zero_approx(animation->bezier_track_interpolate(0, 0.0)));
+ CHECK(animation->bezier_track_interpolate(0, 0.0) == doctest::Approx(0.0));
CHECK(animation->blend_shape_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
ERR_PRINT_ON;
}
@@ -123,15 +123,15 @@ TEST_CASE("[Animation] Create 3D position track") {
CHECK(r_interpolation.is_equal_approx(Vector3(3.5, 4, 5)));
// 3D position tracks always use linear interpolation for performance reasons.
- CHECK(Math::is_equal_approx(animation->track_get_key_transition(0, 0), real_t(1.0)));
- CHECK(Math::is_equal_approx(animation->track_get_key_transition(0, 1), real_t(1.0)));
+ CHECK(animation->track_get_key_transition(0, 0) == doctest::Approx(real_t(1.0)));
+ CHECK(animation->track_get_key_transition(0, 1) == doctest::Approx(real_t(1.0)));
// This is a 3D position track, so the methods below should return errors.
ERR_PRINT_OFF;
CHECK(animation->value_track_interpolate(0, 0.0).is_null());
CHECK(animation->rotation_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
CHECK(animation->scale_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
- CHECK(Math::is_zero_approx(animation->bezier_track_interpolate(0, 0.0)));
+ CHECK(animation->bezier_track_interpolate(0, 0.0) == doctest::Approx(0.0));
CHECK(animation->blend_shape_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
ERR_PRINT_ON;
}
@@ -140,13 +140,13 @@ TEST_CASE("[Animation] Create 3D rotation track") {
Ref<Animation> animation = memnew(Animation);
const int track_index = animation->add_track(Animation::TYPE_ROTATION_3D);
animation->track_set_path(track_index, NodePath("Enemy:rotation"));
- animation->rotation_track_insert_key(track_index, 0.0, Quaternion(Vector3(0, 1, 2)));
- animation->rotation_track_insert_key(track_index, 0.5, Quaternion(Vector3(3.5, 4, 5)));
+ animation->rotation_track_insert_key(track_index, 0.0, Quaternion::from_euler(Vector3(0, 1, 2)));
+ animation->rotation_track_insert_key(track_index, 0.5, Quaternion::from_euler(Vector3(3.5, 4, 5)));
CHECK(animation->get_track_count() == 1);
CHECK(!animation->track_is_compressed(0));
- CHECK(Quaternion(animation->track_get_key_value(0, 0)).is_equal_approx(Quaternion(Vector3(0, 1, 2))));
- CHECK(Quaternion(animation->track_get_key_value(0, 1)).is_equal_approx(Quaternion(Vector3(3.5, 4, 5))));
+ CHECK(Quaternion(animation->track_get_key_value(0, 0)).is_equal_approx(Quaternion::from_euler(Vector3(0, 1, 2))));
+ CHECK(Quaternion(animation->track_get_key_value(0, 1)).is_equal_approx(Quaternion::from_euler(Vector3(3.5, 4, 5))));
Quaternion r_interpolation;
@@ -169,15 +169,15 @@ TEST_CASE("[Animation] Create 3D rotation track") {
CHECK(r_interpolation.is_equal_approx(Quaternion(0.231055, 0.374912, 0.761204, 0.476048)));
// 3D rotation tracks always use linear interpolation for performance reasons.
- CHECK(Math::is_equal_approx(animation->track_get_key_transition(0, 0), real_t(1.0)));
- CHECK(Math::is_equal_approx(animation->track_get_key_transition(0, 1), real_t(1.0)));
+ CHECK(animation->track_get_key_transition(0, 0) == doctest::Approx(real_t(1.0)));
+ CHECK(animation->track_get_key_transition(0, 1) == doctest::Approx(real_t(1.0)));
// This is a 3D rotation track, so the methods below should return errors.
ERR_PRINT_OFF;
CHECK(animation->value_track_interpolate(0, 0.0).is_null());
CHECK(animation->position_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
CHECK(animation->scale_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
- CHECK(Math::is_zero_approx(animation->bezier_track_interpolate(0, 0.0)));
+ CHECK(animation->bezier_track_interpolate(0, 0.0) == doctest::Approx(real_t(0.0)));
CHECK(animation->blend_shape_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
ERR_PRINT_ON;
}
@@ -215,15 +215,15 @@ TEST_CASE("[Animation] Create 3D scale track") {
CHECK(r_interpolation.is_equal_approx(Vector3(3.5, 4, 5)));
// 3D scale tracks always use linear interpolation for performance reasons.
- CHECK(Math::is_equal_approx(animation->track_get_key_transition(0, 0), real_t(1.0)));
- CHECK(Math::is_equal_approx(animation->track_get_key_transition(0, 1), real_t(1.0)));
+ CHECK(animation->track_get_key_transition(0, 0) == doctest::Approx(1.0));
+ CHECK(animation->track_get_key_transition(0, 1) == doctest::Approx(1.0));
// This is a 3D scale track, so the methods below should return errors.
ERR_PRINT_OFF;
CHECK(animation->value_track_interpolate(0, 0.0).is_null());
CHECK(animation->position_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
CHECK(animation->rotation_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
- CHECK(Math::is_zero_approx(animation->bezier_track_interpolate(0, 0.0)));
+ CHECK(animation->bezier_track_interpolate(0, 0.0) == doctest::Approx(0.0));
CHECK(animation->blend_shape_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
ERR_PRINT_ON;
}
@@ -242,32 +242,32 @@ TEST_CASE("[Animation] Create blend shape track") {
float r_blend = 0.0f;
CHECK(animation->blend_shape_track_get_key(0, 0, &r_blend) == OK);
- CHECK(Math::is_equal_approx(r_blend, -1.0f));
+ CHECK(r_blend == doctest::Approx(-1.0f));
CHECK(animation->blend_shape_track_get_key(0, 1, &r_blend) == OK);
- CHECK(Math::is_equal_approx(r_blend, 1.0f));
+ CHECK(r_blend == doctest::Approx(1.0f));
CHECK(animation->blend_shape_track_interpolate(0, -0.2, &r_blend) == OK);
- CHECK(Math::is_equal_approx(r_blend, -1.0f));
+ CHECK(r_blend == doctest::Approx(-1.0f));
CHECK(animation->blend_shape_track_interpolate(0, 0.0, &r_blend) == OK);
- CHECK(Math::is_equal_approx(r_blend, -1.0f));
+ CHECK(r_blend == doctest::Approx(-1.0f));
CHECK(animation->blend_shape_track_interpolate(0, 0.2, &r_blend) == OK);
- CHECK(Math::is_equal_approx(r_blend, -0.2f));
+ CHECK(r_blend == doctest::Approx(-0.2f));
CHECK(animation->blend_shape_track_interpolate(0, 0.4, &r_blend) == OK);
- CHECK(Math::is_equal_approx(r_blend, 0.6f));
+ CHECK(r_blend == doctest::Approx(0.6f));
CHECK(animation->blend_shape_track_interpolate(0, 0.5, &r_blend) == OK);
- CHECK(Math::is_equal_approx(r_blend, 1.0f));
+ CHECK(r_blend == doctest::Approx(1.0f));
CHECK(animation->blend_shape_track_interpolate(0, 0.6, &r_blend) == OK);
- CHECK(Math::is_equal_approx(r_blend, 1.0f));
+ CHECK(r_blend == doctest::Approx(1.0f));
// Blend shape tracks always use linear interpolation for performance reasons.
- CHECK(Math::is_equal_approx(animation->track_get_key_transition(0, 0), real_t(1.0)));
- CHECK(Math::is_equal_approx(animation->track_get_key_transition(0, 1), real_t(1.0)));
+ CHECK(animation->track_get_key_transition(0, 0) == doctest::Approx(real_t(1.0)));
+ CHECK(animation->track_get_key_transition(0, 1) == doctest::Approx(real_t(1.0)));
// This is a blend shape track, so the methods below should return errors.
ERR_PRINT_OFF;
@@ -275,7 +275,7 @@ TEST_CASE("[Animation] Create blend shape track") {
CHECK(animation->position_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
CHECK(animation->rotation_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
CHECK(animation->scale_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
- CHECK(Math::is_zero_approx(animation->bezier_track_interpolate(0, 0.0)));
+ CHECK(animation->bezier_track_interpolate(0, 0.0) == doctest::Approx(0.0));
ERR_PRINT_ON;
}
@@ -289,15 +289,15 @@ TEST_CASE("[Animation] Create Bezier track") {
CHECK(animation->get_track_count() == 1);
CHECK(!animation->track_is_compressed(0));
- CHECK(Math::is_equal_approx(animation->bezier_track_get_key_value(0, 0), real_t(-1.0)));
- CHECK(Math::is_equal_approx(animation->bezier_track_get_key_value(0, 1), real_t(1.0)));
+ CHECK(animation->bezier_track_get_key_value(0, 0) == doctest::Approx(real_t(-1.0)));
+ CHECK(animation->bezier_track_get_key_value(0, 1) == doctest::Approx(real_t(1.0)));
- CHECK(Math::is_equal_approx(animation->bezier_track_interpolate(0, -0.2), real_t(-1.0)));
- CHECK(Math::is_equal_approx(animation->bezier_track_interpolate(0, 0.0), real_t(-1.0)));
- CHECK(Math::is_equal_approx(animation->bezier_track_interpolate(0, 0.2), real_t(-0.76057207584381)));
- CHECK(Math::is_equal_approx(animation->bezier_track_interpolate(0, 0.4), real_t(-0.39975279569626)));
- CHECK(Math::is_equal_approx(animation->bezier_track_interpolate(0, 0.5), real_t(1.0)));
- CHECK(Math::is_equal_approx(animation->bezier_track_interpolate(0, 0.6), real_t(1.0)));
+ CHECK(animation->bezier_track_interpolate(0, -0.2) == doctest::Approx(real_t(-1.0)));
+ CHECK(animation->bezier_track_interpolate(0, 0.0) == doctest::Approx(real_t(-1.0)));
+ CHECK(animation->bezier_track_interpolate(0, 0.2) == doctest::Approx(real_t(-0.76057207584381)));
+ CHECK(animation->bezier_track_interpolate(0, 0.4) == doctest::Approx(real_t(-0.39975279569626)));
+ CHECK(animation->bezier_track_interpolate(0, 0.5) == doctest::Approx(real_t(1.0)));
+ CHECK(animation->bezier_track_interpolate(0, 0.6) == doctest::Approx(real_t(1.0)));
// This is a bezier track, so the methods below should return errors.
ERR_PRINT_OFF;
diff --git a/tests/scene/test_arraymesh.h b/tests/scene/test_arraymesh.h
new file mode 100644
index 0000000000..fc23adcd06
--- /dev/null
+++ b/tests/scene/test_arraymesh.h
@@ -0,0 +1,321 @@
+/*************************************************************************/
+/* test_arraymesh.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef TEST_ARRAYMESH_H
+#define TEST_ARRAYMESH_H
+
+#include "scene/resources/mesh.h"
+#include "scene/resources/primitive_meshes.h"
+
+#include "tests/test_macros.h"
+
+namespace TestArrayMesh {
+
+TEST_CASE("[SceneTree][ArrayMesh] Adding and modifying blendshapes.") {
+ Ref<ArrayMesh> mesh = memnew(ArrayMesh);
+ StringName name_a{ "ShapeA" };
+ StringName name_b{ "ShapeB" };
+
+ SUBCASE("Adding a blend shape to the mesh before a surface is added.") {
+ mesh->add_blend_shape(name_a);
+ mesh->add_blend_shape(name_b);
+
+ CHECK(mesh->get_blend_shape_name(0) == name_a);
+ CHECK(mesh->get_blend_shape_name(1) == name_b);
+ }
+
+ SUBCASE("Add same blend shape multiple times appends name with number.") {
+ mesh->add_blend_shape(name_a);
+ mesh->add_blend_shape(name_a);
+ mesh->add_blend_shape(name_a);
+
+ CHECK(mesh->get_blend_shape_name(0) == "ShapeA");
+ bool all_different = (static_cast<String>(mesh->get_blend_shape_name(0)) != static_cast<String>(mesh->get_blend_shape_name(1))) &&
+ (static_cast<String>(mesh->get_blend_shape_name(1)) != static_cast<String>(mesh->get_blend_shape_name(2))) &&
+ (static_cast<String>(mesh->get_blend_shape_name(0)) != static_cast<String>(mesh->get_blend_shape_name(2)));
+ bool all_have_name = static_cast<String>(mesh->get_blend_shape_name(1)).contains("ShapeA") &&
+ static_cast<String>(mesh->get_blend_shape_name(2)).contains("ShapeA");
+ CHECK((all_different && all_have_name));
+ }
+
+ SUBCASE("ArrayMesh keeps correct count of number of blend shapes") {
+ mesh->add_blend_shape(name_a);
+ mesh->add_blend_shape(name_a);
+ mesh->add_blend_shape(name_b);
+ mesh->add_blend_shape(name_b);
+ mesh->add_blend_shape(name_b);
+
+ REQUIRE(mesh->get_blend_shape_count() == 5);
+ }
+
+ SUBCASE("Adding blend shape after surface is added causes error") {
+ Ref<CylinderMesh> cylinder = memnew(CylinderMesh);
+ Array cylinder_array{};
+ cylinder_array.resize(Mesh::ARRAY_MAX);
+ cylinder->create_mesh_array(cylinder_array, 3.f, 3.f, 5.f);
+ mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array);
+
+ mesh->add_blend_shape(name_a);
+ CHECK(mesh->get_blend_shape_count() == 0);
+ }
+
+ SUBCASE("Change blend shape name after adding.") {
+ mesh->add_blend_shape(name_a);
+ mesh->set_blend_shape_name(0, name_b);
+
+ CHECK(mesh->get_blend_shape_name(0) == name_b);
+ }
+
+ SUBCASE("Change blend shape name to the name of one already there, should append number to end") {
+ mesh->add_blend_shape(name_a);
+ mesh->add_blend_shape(name_b);
+ mesh->set_blend_shape_name(0, name_b);
+
+ String name_string = mesh->get_blend_shape_name(0);
+ CHECK(name_string.contains("ShapeB"));
+ CHECK(name_string.length() > static_cast<String>(name_b).size());
+ }
+
+ SUBCASE("Clear all blend shapes before surface has been added.") {
+ mesh->add_blend_shape(name_a);
+ mesh->add_blend_shape(name_b);
+ CHECK(mesh->get_blend_shape_count() == 2);
+
+ mesh->clear_blend_shapes();
+ CHECK(mesh->get_blend_shape_count() == 0);
+ }
+
+ SUBCASE("Can't clear blend shapes after surface had been added.") {
+ mesh->add_blend_shape(name_a);
+ mesh->add_blend_shape(name_b);
+ Ref<CylinderMesh> cylinder = memnew(CylinderMesh);
+ Array cylinder_array{};
+ cylinder_array.resize(Mesh::ARRAY_MAX);
+ cylinder->create_mesh_array(cylinder_array, 3.f, 3.f, 5.f);
+ mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array);
+
+ mesh->clear_blend_shapes();
+ CHECK(mesh->get_blend_shape_count() == 2);
+ }
+
+ SUBCASE("Set the blend shape mode of ArrayMesh and underlying mesh RID.") {
+ mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_RELATIVE);
+ CHECK(mesh->get_blend_shape_mode() == Mesh::BLEND_SHAPE_MODE_RELATIVE);
+ }
+}
+
+TEST_CASE("[SceneTree][ArrayMesh] Surface meta data tests.") {
+ Ref<ArrayMesh> mesh = memnew(ArrayMesh);
+ Ref<CylinderMesh> cylinder = memnew(CylinderMesh);
+ Array cylinder_array{};
+ cylinder_array.resize(Mesh::ARRAY_MAX);
+ cylinder->create_mesh_array(cylinder_array, 3.f, 3.f, 5.f);
+ mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array);
+
+ Ref<BoxMesh> box = memnew(BoxMesh);
+ Array box_array{};
+ box_array.resize(Mesh::ARRAY_MAX);
+ box->create_mesh_array(box_array, Vector3(2.f, 1.2f, 1.6f));
+ mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, box_array);
+
+ SUBCASE("Add 2 surfaces and count the number of surfaces in the mesh.") {
+ REQUIRE(mesh->get_surface_count() == 2);
+ }
+
+ SUBCASE("Get the surface array from mesh.") {
+ REQUIRE(mesh->surface_get_arrays(0)[0] == cylinder_array[0]);
+ REQUIRE(mesh->surface_get_arrays(1)[0] == box_array[0]);
+ }
+
+ SUBCASE("Get the array length of a particular surface.") {
+ CHECK(mesh->surface_get_array_len(0) == static_cast<Vector<Vector3>>(cylinder_array[RenderingServer::ARRAY_VERTEX]).size());
+ CHECK(mesh->surface_get_array_len(1) == static_cast<Vector<Vector3>>(box_array[RenderingServer::ARRAY_VERTEX]).size());
+ }
+
+ SUBCASE("Get the index array length of a particular surface.") {
+ CHECK(mesh->surface_get_array_index_len(0) == static_cast<Vector<Vector3>>(cylinder_array[RenderingServer::ARRAY_INDEX]).size());
+ CHECK(mesh->surface_get_array_index_len(1) == static_cast<Vector<Vector3>>(box_array[RenderingServer::ARRAY_INDEX]).size());
+ }
+
+ SUBCASE("Get correct primitive type") {
+ CHECK(mesh->surface_get_primitive_type(0) == Mesh::PRIMITIVE_TRIANGLES);
+ CHECK(mesh->surface_get_primitive_type(1) == Mesh::PRIMITIVE_TRIANGLES);
+ mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLE_STRIP, box_array);
+ CHECK(mesh->surface_get_primitive_type(2) == Mesh::PRIMITIVE_TRIANGLE_STRIP);
+ }
+
+ SUBCASE("Returns correct format for the mesh") {
+ auto format = RS::ARRAY_FORMAT_BLEND_SHAPE_MASK | RS::ARRAY_FORMAT_TEX_UV | RS::ARRAY_FORMAT_INDEX;
+ CHECK((mesh->surface_get_format(0) & format) != 0);
+ CHECK((mesh->surface_get_format(1) & format) != 0);
+ }
+
+ SUBCASE("Set a surface name and retrieve it by name.") {
+ mesh->surface_set_name(0, "surf1");
+ CHECK(mesh->surface_find_by_name("surf1") == 0);
+ CHECK(mesh->surface_get_name(0) == "surf1");
+ }
+
+ SUBCASE("Set material to two different surfaces.") {
+ Ref<Material> mat = memnew(Material);
+ mesh->surface_set_material(0, mat);
+ CHECK(mesh->surface_get_material(0) == mat);
+ mesh->surface_set_material(1, mat);
+ CHECK(mesh->surface_get_material(1) == mat);
+ }
+
+ SUBCASE("Set same material multiple times doesn't change material of surface.") {
+ Ref<Material> mat = memnew(Material);
+ mesh->surface_set_material(0, mat);
+ mesh->surface_set_material(0, mat);
+ mesh->surface_set_material(0, mat);
+ CHECK(mesh->surface_get_material(0) == mat);
+ }
+
+ SUBCASE("Set material of surface then change to different material.") {
+ Ref<Material> mat1 = memnew(Material);
+ Ref<Material> mat2 = memnew(Material);
+ mesh->surface_set_material(1, mat1);
+ CHECK(mesh->surface_get_material(1) == mat1);
+ mesh->surface_set_material(1, mat2);
+ CHECK(mesh->surface_get_material(1) == mat2);
+ }
+
+ SUBCASE("Get the LOD of the mesh.") {
+ Dictionary lod{};
+ mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array, TypedArray<Array>{}, lod);
+ CHECK(mesh->surface_get_lods(2) == lod);
+ }
+
+ SUBCASE("Get the blend shape arrays from the mesh.") {
+ TypedArray<Array> blend{};
+ mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array, blend);
+ CHECK(mesh->surface_get_blend_shape_arrays(2) == blend);
+ }
+}
+
+TEST_CASE("[SceneTree][ArrayMesh] Get/Set mesh metadata and actions") {
+ Ref<ArrayMesh> mesh = memnew(ArrayMesh);
+ Ref<CylinderMesh> cylinder = memnew(CylinderMesh);
+ Array cylinder_array{};
+ cylinder_array.resize(Mesh::ARRAY_MAX);
+ cylinder->create_mesh_array(cylinder_array, 3.f, 3.f, 5.f);
+ mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array);
+
+ Ref<BoxMesh> box = memnew(BoxMesh);
+ Array box_array{};
+ box_array.resize(Mesh::ARRAY_MAX);
+ box->create_mesh_array(box_array, Vector3(2.f, 1.2f, 1.6f));
+ mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, box_array);
+
+ SUBCASE("Set the shadow mesh.") {
+ Ref<ArrayMesh> shadow = memnew(ArrayMesh);
+ mesh->set_shadow_mesh(shadow);
+ CHECK(mesh->get_shadow_mesh() == shadow);
+ }
+
+ SUBCASE("Set the shadow mesh multiple times.") {
+ Ref<ArrayMesh> shadow = memnew(ArrayMesh);
+ mesh->set_shadow_mesh(shadow);
+ mesh->set_shadow_mesh(shadow);
+ mesh->set_shadow_mesh(shadow);
+ mesh->set_shadow_mesh(shadow);
+ CHECK(mesh->get_shadow_mesh() == shadow);
+ }
+
+ SUBCASE("Set the same shadow mesh on multiple meshes.") {
+ Ref<ArrayMesh> shadow = memnew(ArrayMesh);
+ Ref<ArrayMesh> mesh2 = memnew(ArrayMesh);
+ mesh->set_shadow_mesh(shadow);
+ mesh2->set_shadow_mesh(shadow);
+
+ CHECK(mesh->get_shadow_mesh() == shadow);
+ CHECK(mesh2->get_shadow_mesh() == shadow);
+ }
+
+ SUBCASE("Set the shadow mesh and then change it.") {
+ Ref<ArrayMesh> shadow = memnew(ArrayMesh);
+ mesh->set_shadow_mesh(shadow);
+ CHECK(mesh->get_shadow_mesh() == shadow);
+ Ref<ArrayMesh> shadow2 = memnew(ArrayMesh);
+ mesh->set_shadow_mesh(shadow2);
+ CHECK(mesh->get_shadow_mesh() == shadow2);
+ }
+
+ SUBCASE("Set custom AABB.") {
+ AABB bound{};
+ mesh->set_custom_aabb(bound);
+ CHECK(mesh->get_custom_aabb() == bound);
+ }
+
+ SUBCASE("Set custom AABB multiple times.") {
+ AABB bound{};
+ mesh->set_custom_aabb(bound);
+ mesh->set_custom_aabb(bound);
+ mesh->set_custom_aabb(bound);
+ mesh->set_custom_aabb(bound);
+ CHECK(mesh->get_custom_aabb() == bound);
+ }
+
+ SUBCASE("Set custom AABB then change to another AABB.") {
+ AABB bound{};
+ AABB bound2{};
+ mesh->set_custom_aabb(bound);
+ CHECK(mesh->get_custom_aabb() == bound);
+ mesh->set_custom_aabb(bound2);
+ CHECK(mesh->get_custom_aabb() == bound2);
+ }
+
+ SUBCASE("Clear all surfaces should leave zero count.") {
+ mesh->clear_surfaces();
+ CHECK(mesh->get_surface_count() == 0);
+ }
+
+ SUBCASE("Able to get correct mesh RID.") {
+ RID rid = mesh->get_rid();
+ CHECK(RS::get_singleton()->mesh_get_surface_count(rid) == 2);
+ }
+
+ SUBCASE("Create surface from raw SurfaceData data.") {
+ RID mesh_rid = mesh->get_rid();
+ RS::SurfaceData surface_data = RS::get_singleton()->mesh_get_surface(mesh_rid, 0);
+ Ref<ArrayMesh> mesh2 = memnew(ArrayMesh);
+ mesh2->add_surface(surface_data.format, Mesh::PRIMITIVE_TRIANGLES, surface_data.vertex_data, surface_data.attribute_data,
+ surface_data.skin_data, surface_data.vertex_count, surface_data.index_data, surface_data.index_count, surface_data.aabb);
+ CHECK(mesh2->get_surface_count() == 1);
+ CHECK(mesh2->surface_get_primitive_type(0) == Mesh::PRIMITIVE_TRIANGLES);
+ CHECK((mesh2->surface_get_format(0) & surface_data.format) != 0);
+ CHECK(mesh2->get_aabb().is_equal_approx(surface_data.aabb));
+ }
+}
+
+} // namespace TestArrayMesh
+
+#endif // TEST_ARRAYMESH_H
diff --git a/tests/scene/test_audio_stream_wav.h b/tests/scene/test_audio_stream_wav.h
index cf369c115b..c84c66b0e6 100644
--- a/tests/scene/test_audio_stream_wav.h
+++ b/tests/scene/test_audio_stream_wav.h
@@ -138,7 +138,7 @@ void run_test(String file_name, AudioStreamWAV::Format data_format, bool stereo,
CHECK(stream->get_data() == test_data);
SUBCASE("Stream length is computed properly") {
- CHECK(Math::is_equal_approx(stream->get_length(), wav_count / wav_rate));
+ CHECK(stream->get_length() == doctest::Approx(double(wav_count / wav_rate)));
}
SUBCASE("Stream can be saved as .wav") {
diff --git a/tests/scene/test_bit_map.h b/tests/scene/test_bit_map.h
index 53afdc38f7..aca7e5fe22 100644
--- a/tests/scene/test_bit_map.h
+++ b/tests/scene/test_bit_map.h
@@ -76,15 +76,11 @@ TEST_CASE("[BitMap] Create bit map from image alpha") {
bit_map.create_from_image_alpha(empty_img);
CHECK_MESSAGE(bit_map.get_size() == Size2i(256, 256), "Bitmap should have its old values because bitmap creation from an empty image should fail.");
- Ref<Image> wrong_format_img;
- wrong_format_img.instantiate();
- wrong_format_img->create(3, 3, false, Image::Format::FORMAT_DXT1);
+ Ref<Image> wrong_format_img = Image::create_empty(3, 3, false, Image::Format::FORMAT_DXT1);
bit_map.create_from_image_alpha(wrong_format_img);
CHECK_MESSAGE(bit_map.get_size() == Size2i(256, 256), "Bitmap should have its old values because converting from a compressed image should fail.");
- Ref<Image> img;
- img.instantiate();
- img->create(3, 3, false, Image::Format::FORMAT_RGBA8);
+ Ref<Image> img = Image::create_empty(3, 3, false, Image::Format::FORMAT_RGBA8);
img->set_pixel(0, 0, Color(0, 0, 0, 0));
img->set_pixel(0, 1, Color(0, 0, 0, 0.09f));
img->set_pixel(0, 2, Color(0, 0, 0, 0.25f));
@@ -183,7 +179,7 @@ TEST_CASE("[BitMap] Get true bit count") {
CHECK(bit_map.get_true_bit_count() == 0);
bit_map.create(dim);
- CHECK_MESSAGE(bit_map.get_true_bit_count() == 0, "Unitialized bit map should have no true bits");
+ CHECK_MESSAGE(bit_map.get_true_bit_count() == 0, "Uninitialized bit map should have no true bits");
bit_map.set_bit_rect(Rect2i{ 0, 0, 256, 256 }, true);
CHECK(bit_map.get_true_bit_count() == 65536);
bit_map.set_bitv(Point2i{ 0, 0 }, false);
@@ -196,7 +192,7 @@ TEST_CASE("[BitMap] Get size") {
const Size2i dim{ 256, 256 };
BitMap bit_map{};
- CHECK_MESSAGE(bit_map.get_size() == Size2i(0, 0), "Unitialized bit map should have a size of 0x0");
+ CHECK_MESSAGE(bit_map.get_size() == Size2i(0, 0), "Uninitialized bit map should have a size of 0x0");
bit_map.create(dim);
CHECK(bit_map.get_size() == Size2i(256, 256));
@@ -238,7 +234,7 @@ TEST_CASE("[BitMap] Resize") {
TEST_CASE("[BitMap] Grow and shrink mask") {
const Size2i dim{ 256, 256 };
BitMap bit_map{};
- bit_map.grow_mask(100, Rect2i(0, 0, 128, 128)); // Check if method does not crash when working with an uninitialised bit map.
+ bit_map.grow_mask(100, Rect2i(0, 0, 128, 128)); // Check if method does not crash when working with an uninitialized bit map.
CHECK_MESSAGE(bit_map.get_size() == Size2i(0, 0), "Size should still be equal to 0x0");
bit_map.create(dim);
@@ -339,21 +335,21 @@ TEST_CASE("[BitMap] Blit") {
blit_bit_map.instantiate();
- // Testing if uninitialised blit bit map and uninitialised bit map does not crash
+ // Testing if uninitialized blit bit map and uninitialized bit map does not crash
bit_map.blit(blit_pos, blit_bit_map);
- // Testing if uninitialised bit map does not crash
+ // Testing if uninitialized bit map does not crash
blit_bit_map->create(blit_size);
bit_map.blit(blit_pos, blit_bit_map);
- // Testing if uninitialised bit map does not crash
+ // Testing if uninitialized bit map does not crash
blit_bit_map.unref();
blit_bit_map.instantiate();
CHECK_MESSAGE(blit_bit_map->get_size() == Point2i(0, 0), "Size should be cleared by unref and instance calls.");
bit_map.create(bit_map_size);
bit_map.blit(Point2i(128, 128), blit_bit_map);
- // Testing if both initialised does not crash.
+ // Testing if both initialized does not crash.
blit_bit_map->create(blit_size);
bit_map.blit(blit_pos, blit_bit_map);
@@ -390,7 +386,7 @@ TEST_CASE("[BitMap] Convert to image") {
bit_map.create(dim);
img = bit_map.convert_to_image();
CHECK_MESSAGE(img->get_size() == dim, "Image should have the same dimensions as the BitMap");
- CHECK_MESSAGE(img->get_pixel(0, 0).is_equal_approx(Color(0, 0, 0)), "BitMap is intialized to all 0's, so Image should be all black");
+ CHECK_MESSAGE(img->get_pixel(0, 0).is_equal_approx(Color(0, 0, 0)), "BitMap is initialized to all 0's, so Image should be all black");
reset_bit_map(bit_map);
bit_map.set_bit_rect(Rect2i(0, 0, 128, 128), true);
diff --git a/tests/scene/test_curve.h b/tests/scene/test_curve.h
index ad7625ddc5..36ec0c0a4d 100644
--- a/tests/scene/test_curve.h
+++ b/tests/scene/test_curve.h
@@ -83,54 +83,54 @@ TEST_CASE("[Curve] Custom curve with free tangents") {
Math::is_zero_approx(curve->sample(-0.1)),
"Custom free curve should return the expected value at offset 0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample(0.1), (real_t)0.352),
+ curve->sample(0.1) == doctest::Approx((real_t)0.352),
"Custom free curve should return the expected value at offset 0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample(0.4), (real_t)0.352),
+ curve->sample(0.4) == doctest::Approx((real_t)0.352),
"Custom free curve should return the expected value at offset 0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample(0.7), (real_t)0.896),
+ curve->sample(0.7) == doctest::Approx((real_t)0.896),
"Custom free curve should return the expected value at offset 0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample(1), 1),
+ curve->sample(1) == doctest::Approx(1),
"Custom free curve should return the expected value at offset 0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample(2), 1),
+ curve->sample(2) == doctest::Approx(1),
"Custom free curve should return the expected value at offset 0.1.");
CHECK_MESSAGE(
Math::is_zero_approx(curve->sample_baked(-0.1)),
"Custom free curve should return the expected baked value at offset 0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample_baked(0.1), (real_t)0.352),
+ curve->sample_baked(0.1) == doctest::Approx((real_t)0.352),
"Custom free curve should return the expected baked value at offset 0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample_baked(0.4), (real_t)0.352),
+ curve->sample_baked(0.4) == doctest::Approx((real_t)0.352),
"Custom free curve should return the expected baked value at offset 0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample_baked(0.7), (real_t)0.896),
+ curve->sample_baked(0.7) == doctest::Approx((real_t)0.896),
"Custom free curve should return the expected baked value at offset 0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample_baked(1), 1),
+ curve->sample_baked(1) == doctest::Approx(1),
"Custom free curve should return the expected baked value at offset 0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample_baked(2), 1),
+ curve->sample_baked(2) == doctest::Approx(1),
"Custom free curve should return the expected baked value at offset 0.1.");
curve->remove_point(1);
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample(0.1), 0),
+ curve->sample(0.1) == doctest::Approx(0),
"Custom free curve should return the expected value at offset 0.1 after removing point at index 1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample_baked(0.1), 0),
+ curve->sample_baked(0.1) == doctest::Approx(0),
"Custom free curve should return the expected baked value at offset 0.1 after removing point at index 1.");
curve->clear_points();
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample(0.6), 0),
+ curve->sample(0.6) == doctest::Approx(0),
"Custom free curve should return the expected value at offset 0.6 after clearing all points.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample_baked(0.6), 0),
+ curve->sample_baked(0.6) == doctest::Approx(0),
"Custom free curve should return the expected baked value at offset 0.6 after clearing all points.");
}
@@ -143,7 +143,7 @@ TEST_CASE("[Curve] Custom curve with linear tangents") {
curve->add_point(Vector2(0.75, 1), 0, 0, Curve::TangentMode::TANGENT_LINEAR, Curve::TangentMode::TANGENT_LINEAR);
CHECK_MESSAGE(
- Math::is_equal_approx(curve->get_point_left_tangent(3), 4),
+ curve->get_point_left_tangent(3) == doctest::Approx(4),
"get_point_left_tangent() should return the expected value for point index 3.");
CHECK_MESSAGE(
Math::is_zero_approx(curve->get_point_right_tangent(3)),
@@ -172,48 +172,48 @@ TEST_CASE("[Curve] Custom curve with linear tangents") {
Math::is_zero_approx(curve->sample(-0.1)),
"Custom linear curve should return the expected value at offset -0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample(0.1), (real_t)0.4),
+ curve->sample(0.1) == doctest::Approx((real_t)0.4),
"Custom linear curve should return the expected value at offset 0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample(0.4), (real_t)0.4),
+ curve->sample(0.4) == doctest::Approx((real_t)0.4),
"Custom linear curve should return the expected value at offset 0.4.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample(0.7), (real_t)0.8),
+ curve->sample(0.7) == doctest::Approx((real_t)0.8),
"Custom linear curve should return the expected value at offset 0.7.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample(1), 1),
+ curve->sample(1) == doctest::Approx(1),
"Custom linear curve should return the expected value at offset 1.0.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample(2), 1),
+ curve->sample(2) == doctest::Approx(1),
"Custom linear curve should return the expected value at offset 2.0.");
CHECK_MESSAGE(
Math::is_zero_approx(curve->sample_baked(-0.1)),
"Custom linear curve should return the expected baked value at offset -0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample_baked(0.1), (real_t)0.4),
+ curve->sample_baked(0.1) == doctest::Approx((real_t)0.4),
"Custom linear curve should return the expected baked value at offset 0.1.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample_baked(0.4), (real_t)0.4),
+ curve->sample_baked(0.4) == doctest::Approx((real_t)0.4),
"Custom linear curve should return the expected baked value at offset 0.4.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample_baked(0.7), (real_t)0.8),
+ curve->sample_baked(0.7) == doctest::Approx((real_t)0.8),
"Custom linear curve should return the expected baked value at offset 0.7.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample_baked(1), 1),
+ curve->sample_baked(1) == doctest::Approx(1),
"Custom linear curve should return the expected baked value at offset 1.0.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample_baked(2), 1),
+ curve->sample_baked(2) == doctest::Approx(1),
"Custom linear curve should return the expected baked value at offset 2.0.");
ERR_PRINT_OFF;
curve->remove_point(10);
ERR_PRINT_ON;
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample(0.7), (real_t)0.8),
+ curve->sample(0.7) == doctest::Approx((real_t)0.8),
"Custom free curve should return the expected value at offset 0.7 after removing point at invalid index 10.");
CHECK_MESSAGE(
- Math::is_equal_approx(curve->sample_baked(0.7), (real_t)0.8),
+ curve->sample_baked(0.7) == doctest::Approx((real_t)0.8),
"Custom free curve should return the expected baked value at offset 0.7 after removing point at invalid index 10.");
}
diff --git a/tests/scene/test_path_2d.h b/tests/scene/test_path_2d.h
new file mode 100644
index 0000000000..dc5eee4012
--- /dev/null
+++ b/tests/scene/test_path_2d.h
@@ -0,0 +1,109 @@
+/*************************************************************************/
+/* test_path_2d.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef TEST_PATH_2D_H
+#define TEST_PATH_2D_H
+
+#include "scene/2d/path_2d.h"
+
+#include "tests/test_macros.h"
+
+namespace TestPath2D {
+
+TEST_CASE("[SceneTree][Path2D] Initialization") {
+ SUBCASE("Path should be empty right after initialization") {
+ Path2D *test_path = memnew(Path2D);
+ CHECK(test_path->get_curve() == nullptr);
+ memdelete(test_path);
+ }
+}
+
+TEST_CASE("[SceneTree][Path2D] Curve setter and getter") {
+ Path2D *test_path = memnew(Path2D);
+ const Ref<Curve2D> &curve = memnew(Curve2D);
+
+ SUBCASE("Curve passed to the class should remain the same") {
+ test_path->set_curve(curve);
+ CHECK(test_path->get_curve() == curve);
+ }
+ SUBCASE("Curve passed many times to the class should remain the same") {
+ test_path->set_curve(curve);
+ test_path->set_curve(curve);
+ test_path->set_curve(curve);
+ CHECK(test_path->get_curve() == curve);
+ }
+ SUBCASE("Curve rewrite testing") {
+ const Ref<Curve2D> &curve1 = memnew(Curve2D);
+ const Ref<Curve2D> &curve2 = memnew(Curve2D);
+
+ test_path->set_curve(curve1);
+ test_path->set_curve(curve2);
+ CHECK_MESSAGE(test_path->get_curve() != curve1,
+ "After rewrite, second curve should be in class");
+ CHECK_MESSAGE(test_path->get_curve() == curve2,
+ "After rewrite, second curve should be in class");
+ }
+
+ SUBCASE("Assign same curve to two paths") {
+ Path2D *path2 = memnew(Path2D);
+
+ test_path->set_curve(curve);
+ path2->set_curve(curve);
+ CHECK_MESSAGE(test_path->get_curve() == path2->get_curve(),
+ "Both paths have the same curve.");
+ memdelete(path2);
+ }
+
+ SUBCASE("Swapping curves between two paths") {
+ Path2D *path2 = memnew(Path2D);
+ const Ref<Curve2D> &curve1 = memnew(Curve2D);
+ const Ref<Curve2D> &curve2 = memnew(Curve2D);
+
+ test_path->set_curve(curve1);
+ path2->set_curve(curve2);
+ CHECK(test_path->get_curve() == curve1);
+ CHECK(path2->get_curve() == curve2);
+
+ // Do the swap
+ Ref<Curve2D> temp = test_path->get_curve();
+ test_path->set_curve(path2->get_curve());
+ path2->set_curve(temp);
+
+ CHECK(test_path->get_curve() == curve2);
+ CHECK(path2->get_curve() == curve1);
+ memdelete(path2);
+ }
+
+ memdelete(test_path);
+}
+
+} // namespace TestPath2D
+
+#endif // TEST_PATH_2D_H
diff --git a/tests/scene/test_primitives.h b/tests/scene/test_primitives.h
new file mode 100644
index 0000000000..8bac903d93
--- /dev/null
+++ b/tests/scene/test_primitives.h
@@ -0,0 +1,850 @@
+/*************************************************************************/
+/* test_primitives.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef TEST_PRIMITIVES_H
+#define TEST_PRIMITIVES_H
+
+#include "scene/resources/primitive_meshes.h"
+
+#include "tests/test_macros.h"
+
+namespace TestPrimitives {
+
+TEST_CASE("[SceneTree][Primitive][Capsule] Capsule Primitive") {
+ Ref<CapsuleMesh> capsule = memnew(CapsuleMesh);
+
+ SUBCASE("[SceneTree][Primitive][Capsule] Default values should be valid") {
+ CHECK_MESSAGE(capsule->get_radius() > 0,
+ "Radius of default capsule positive.");
+ CHECK_MESSAGE(capsule->get_height() > 0,
+ "Height of default capsule positive.");
+ CHECK_MESSAGE(capsule->get_radial_segments() >= 0,
+ "Radius Segments of default capsule positive.");
+ CHECK_MESSAGE(capsule->get_rings() >= 0,
+ "Number of rings of default capsule positive.");
+ }
+
+ SUBCASE("[SceneTree][Primitive][Capsule] Set properties of the capsule and get them with accessor methods") {
+ capsule->set_height(7.1f);
+ capsule->set_radius(1.3f);
+ capsule->set_radial_segments(16);
+ capsule->set_rings(32);
+
+ CHECK_MESSAGE(capsule->get_radius() == doctest::Approx(1.3f),
+ "Get/Set radius work with one set.");
+ CHECK_MESSAGE(capsule->get_height() == doctest::Approx(7.1f),
+ "Get/Set radius work with one set.");
+ CHECK_MESSAGE(capsule->get_radial_segments() == 16,
+ "Get/Set radius work with one set.");
+ CHECK_MESSAGE(capsule->get_rings() == 32,
+ "Get/Set radius work with one set.");
+ }
+
+ SUBCASE("[SceneTree][Primitive][Capsule] If set segments negative, default to at least 0") {
+ capsule->set_radial_segments(-5);
+ capsule->set_rings(-17);
+
+ CHECK_MESSAGE(capsule->get_radial_segments() >= 0,
+ "Ensure number of radial segments is >= 0.");
+ CHECK_MESSAGE(capsule->get_rings() >= 0,
+ "Ensure number of rings is >= 0.");
+ }
+
+ SUBCASE("[SceneTree][Primitive][Capsule] If set height < 2*radius, adjust radius and height to radius=height*0.5") {
+ capsule->set_radius(1.f);
+ capsule->set_height(0.5f);
+
+ CHECK_MESSAGE(capsule->get_radius() >= capsule->get_height() * 0.5,
+ "Ensure radius >= height * 0.5 (needed for capsule to exist).");
+ }
+
+ SUBCASE("[Primitive][Capsule] Check mesh is correct") {
+ Array data{};
+ data.resize(RS::ARRAY_MAX);
+ float radius{ 0.5f };
+ float height{ 4.f };
+ int num_radial_segments{ 4 };
+ int num_rings{ 8 };
+ CapsuleMesh::create_mesh_array(data, radius, height, num_radial_segments, num_rings);
+ Vector<Vector3> points = data[RS::ARRAY_VERTEX];
+
+ SUBCASE("[Primitive][Capsule] Ensure all vertices positions are within bounding radius and height") {
+ // Get mesh data
+
+ // Check all points within radius of capsule
+ float dist_to_yaxis = 0.f;
+ for (Vector3 point : points) {
+ float new_dist_to_y = point.x * point.x + point.z * point.z;
+ if (new_dist_to_y > dist_to_yaxis)
+ dist_to_yaxis = new_dist_to_y;
+ }
+
+ CHECK(dist_to_yaxis <= radius * radius);
+
+ // Check highest point and lowest point are within height of each other
+ float max_y{ 0.f };
+ float min_y{ 0.f };
+ for (Vector3 point : points) {
+ if (point.y > max_y)
+ max_y = point.y;
+ if (point.y < min_y)
+ min_y = point.y;
+ }
+
+ CHECK(max_y - min_y <= height);
+ }
+
+ SUBCASE("[Primitive][Capsule] If normal.y == 0, then mesh makes a cylinder.") {
+ Vector<Vector3> normals = data[RS::ARRAY_NORMAL];
+ for (int ii = 0; ii < points.size(); ++ii) {
+ float point_dist_from_yaxis = Math::sqrt(points[ii].x * points[ii].x + points[ii].z * points[ii].z);
+ Vector3 yaxis_to_point{ points[ii].x / point_dist_from_yaxis, 0.f, points[ii].z / point_dist_from_yaxis };
+ if (normals[ii].y == 0.f) {
+ float mag_of_normal = Math::sqrt(normals[ii].x * normals[ii].x + normals[ii].z * normals[ii].z);
+ Vector3 normalized_normal = normals[ii] / mag_of_normal;
+ CHECK_MESSAGE(point_dist_from_yaxis == doctest::Approx(radius),
+ "Points on the tube of the capsule are radius away from y-axis.");
+ CHECK_MESSAGE(normalized_normal.is_equal_approx(yaxis_to_point),
+ "Normal points orthogonal from mid cylinder.");
+ }
+ }
+ }
+ }
+} // End capsule tests
+
+TEST_CASE("[SceneTree][Primitive][Box] Box Primitive") {
+ Ref<BoxMesh> box = memnew(BoxMesh);
+
+ SUBCASE("[SceneTree][Primitive][Box] Default values should be valid") {
+ CHECK(box->get_size().x > 0);
+ CHECK(box->get_size().y > 0);
+ CHECK(box->get_size().z > 0);
+ CHECK(box->get_subdivide_width() >= 0);
+ CHECK(box->get_subdivide_height() >= 0);
+ CHECK(box->get_subdivide_depth() >= 0);
+ }
+
+ SUBCASE("[SceneTree][Primitive][Box] Set properties and get them with accessor methods") {
+ Vector3 size{ 2.1, 3.3, 1.7 };
+ box->set_size(size);
+ box->set_subdivide_width(3);
+ box->set_subdivide_height(2);
+ box->set_subdivide_depth(4);
+
+ CHECK(box->get_size().is_equal_approx(size));
+ CHECK(box->get_subdivide_width() == 3);
+ CHECK(box->get_subdivide_height() == 2);
+ CHECK(box->get_subdivide_depth() == 4);
+ }
+
+ SUBCASE("[SceneTree][Primitive][Box] Set subdivides to negative and ensure they are >= 0") {
+ box->set_subdivide_width(-2);
+ box->set_subdivide_height(-2);
+ box->set_subdivide_depth(-2);
+
+ CHECK(box->get_subdivide_width() >= 0);
+ CHECK(box->get_subdivide_height() >= 0);
+ CHECK(box->get_subdivide_depth() >= 0);
+ }
+
+ SUBCASE("[Primitive][Box] Check mesh is correct.") {
+ Array data{};
+ data.resize(RS::ARRAY_MAX);
+ Vector3 size{ 0.5f, 1.2f, .9f };
+ int subdivide_width{ 3 };
+ int subdivide_height{ 2 };
+ int subdivide_depth{ 8 };
+ BoxMesh::create_mesh_array(data, size, subdivide_width, subdivide_height, subdivide_depth);
+ Vector<Vector3> points = data[RS::ARRAY_VERTEX];
+ Vector<Vector3> normals = data[RS::ARRAY_NORMAL];
+
+ SUBCASE("Only 6 distinct normals.") {
+ Vector<Vector3> distinct_normals{};
+ distinct_normals.push_back(normals[0]);
+
+ for (const Vector3 &normal : normals) {
+ bool add_normal{ true };
+ for (const Vector3 &vec : distinct_normals) {
+ if (vec.is_equal_approx(normal))
+ add_normal = false;
+ }
+
+ if (add_normal)
+ distinct_normals.push_back(normal);
+ }
+
+ CHECK_MESSAGE(distinct_normals.size() == 6,
+ "There are exactly 6 distinct normals in the mesh data.");
+
+ // All normals are orthogonal, or pointing in same direction.
+ bool normal_correct_direction{ true };
+ for (int rowIndex = 0; rowIndex < distinct_normals.size(); ++rowIndex) {
+ for (int colIndex = rowIndex + 1; colIndex < distinct_normals.size(); ++colIndex) {
+ if (!Math::is_equal_approx(distinct_normals[rowIndex].normalized().dot(distinct_normals[colIndex].normalized()), 0) &&
+ !Math::is_equal_approx(distinct_normals[rowIndex].normalized().dot(distinct_normals[colIndex].normalized()), 1) &&
+ !Math::is_equal_approx(distinct_normals[rowIndex].normalized().dot(distinct_normals[colIndex].normalized()), -1)) {
+ normal_correct_direction = false;
+ break;
+ }
+ }
+ if (!normal_correct_direction)
+ break;
+ }
+
+ CHECK_MESSAGE(normal_correct_direction,
+ "All normals are either orthogonal or colinear.");
+ }
+ }
+} // End box tests
+
+TEST_CASE("[SceneTree][Primitive][Cylinder] Cylinder Primitive") {
+ Ref<CylinderMesh> cylinder = memnew(CylinderMesh);
+
+ SUBCASE("[SceneTree][Primitive][Cylinder] Default values should be valid") {
+ CHECK(cylinder->get_top_radius() > 0);
+ CHECK(cylinder->get_bottom_radius() > 0);
+ CHECK(cylinder->get_height() > 0);
+ CHECK(cylinder->get_radial_segments() > 0);
+ CHECK(cylinder->get_rings() > 0);
+ }
+
+ SUBCASE("[SceneTree][Primitive][Cylinder] Set properties and get them") {
+ cylinder->set_top_radius(4.3f);
+ cylinder->set_bottom_radius(1.2f);
+ cylinder->set_height(9.77f);
+ cylinder->set_radial_segments(12);
+ cylinder->set_rings(16);
+ cylinder->set_cap_top(false);
+ cylinder->set_cap_bottom(false);
+
+ CHECK(cylinder->get_top_radius() == doctest::Approx(4.3f));
+ CHECK(cylinder->get_bottom_radius() == doctest::Approx(1.2f));
+ CHECK(cylinder->get_height() == doctest::Approx(9.77f));
+ CHECK(cylinder->get_radial_segments() == 12);
+ CHECK(cylinder->get_rings() == 16);
+ CHECK(!cylinder->is_cap_top());
+ CHECK(!cylinder->is_cap_bottom());
+ }
+
+ SUBCASE("[SceneTree][Primitive][Cylinder] Ensure num segments is >= 0") {
+ cylinder->set_radial_segments(-12);
+ cylinder->set_rings(-16);
+
+ CHECK(cylinder->get_radial_segments() >= 0);
+ CHECK(cylinder->get_rings() >= 0);
+ }
+
+ SUBCASE("[Primitive][Cylinder] Actual cylinder mesh tests (top and bottom radius the same).") {
+ Array data{};
+ data.resize(RS::ARRAY_MAX);
+ real_t radius = .9f;
+ real_t height = 3.2f;
+ int radial_segments = 8;
+ int rings = 5;
+ bool top_cap = true;
+ bool bottom_cap = true;
+ CylinderMesh::create_mesh_array(data, radius, radius, height, radial_segments, rings, top_cap, bottom_cap);
+ Vector<Vector3> points = data[RS::ARRAY_VERTEX];
+ Vector<Vector3> normals = data[RS::ARRAY_NORMAL];
+
+ SUBCASE("[Primitive][Cylinder] Side points are radius away from y-axis.") {
+ bool is_radius_correct{ true };
+ for (int index = 0; index < normals.size(); ++index) {
+ if (Math::is_equal_approx(normals[index].y, 0)) {
+ if (!Math::is_equal_approx((points[index] - Vector3(0, points[index].y, 0)).length_squared(), radius * radius)) {
+ is_radius_correct = false;
+ break;
+ }
+ }
+ }
+
+ CHECK(is_radius_correct);
+ }
+
+ SUBCASE("[Primitive][Cylinder] Only possible normals point in direction of point or in positive/negative y direction.") {
+ bool is_correct_normals{ true };
+ for (int index = 0; index < normals.size(); ++index) {
+ Vector3 yaxis_to_point = points[index] - Vector3(0.f, points[index].y, 0.f);
+ Vector3 point_to_normal = normals[index].normalized() - yaxis_to_point.normalized();
+ // std::cout << "<" << point_to_normal.x << ", " << point_to_normal.y << ", " << point_to_normal.z << ">\n";
+ if (!(point_to_normal.is_equal_approx(Vector3(0, 0, 0))) &&
+ (!Math::is_equal_approx(Math::abs(normals[index].normalized().y), 1))) {
+ is_correct_normals = false;
+ break;
+ }
+ }
+
+ CHECK(is_correct_normals);
+ }
+
+ SUBCASE("[Primitive][Cylinder] Points on top and bottom are height/2 away from origin.") {
+ bool is_height_correct{ true };
+ real_t half_height = 0.5 * height;
+ for (int index = 0; index < normals.size(); ++index) {
+ if (Math::is_equal_approx(normals[index].x, 0) &&
+ Math::is_equal_approx(normals[index].z, 0) &&
+ normals[index].y > 0) {
+ if (!Math::is_equal_approx(points[index].y, half_height)) {
+ is_height_correct = false;
+ break;
+ }
+ }
+ if (Math::is_equal_approx(normals[index].x, 0) &&
+ Math::is_equal_approx(normals[index].z, 0) &&
+ normals[index].y < 0) {
+ if (!Math::is_equal_approx(points[index].y, -half_height)) {
+ is_height_correct = false;
+ break;
+ }
+ }
+ }
+
+ CHECK(is_height_correct);
+ }
+
+ SUBCASE("[Primitive][Cylinder] Does mesh obey cap parameters?") {
+ CylinderMesh::create_mesh_array(data, radius, radius, height, radial_segments, rings, top_cap, false);
+ points = data[RS::ARRAY_VERTEX];
+ normals = data[RS::ARRAY_NORMAL];
+ bool no_bottom_cap{ true };
+
+ for (int index = 0; index < normals.size(); ++index) {
+ if (Math::is_equal_approx(normals[index].x, 0) &&
+ Math::is_equal_approx(normals[index].z, 0) &&
+ normals[index].y < 0) {
+ no_bottom_cap = false;
+ break;
+ }
+ }
+
+ CHECK_MESSAGE(no_bottom_cap,
+ "Check there is no bottom cap.");
+
+ CylinderMesh::create_mesh_array(data, radius, radius, height, radial_segments, rings, false, bottom_cap);
+ points = data[RS::ARRAY_VERTEX];
+ normals = data[RS::ARRAY_NORMAL];
+ bool no_top_cap{ true };
+
+ for (int index = 0; index < normals.size(); ++index) {
+ if (Math::is_equal_approx(normals[index].x, 0) &&
+ Math::is_equal_approx(normals[index].z, 0) &&
+ normals[index].y > 0) {
+ no_top_cap = false;
+ break;
+ }
+ }
+
+ CHECK_MESSAGE(no_top_cap,
+ "Check there is no top cap.");
+ }
+ }
+
+ SUBCASE("[Primitive][Cylinder] Slanted cylinder mesh (top and bottom radius different).") {
+ Array data{};
+ data.resize(RS::ARRAY_MAX);
+ real_t top_radius = 2.f;
+ real_t bottom_radius = 1.f;
+ real_t height = 1.f;
+ int radial_segments = 8;
+ int rings = 5;
+ CylinderMesh::create_mesh_array(data, top_radius, bottom_radius, height, radial_segments, rings, false, false);
+ Vector<Vector3> points = data[RS::ARRAY_VERTEX];
+ Vector<Vector3> normals = data[RS::ARRAY_NORMAL];
+
+ SUBCASE("[Primitive][Cylinder] Side points lie correct distance from y-axis") {
+ bool is_radius_correct{ true };
+ for (int index = 0; index < points.size(); ++index) {
+ real_t radius = ((top_radius - bottom_radius) / height) * (points[index].y - 0.5 * height) + top_radius;
+ Vector3 distance_to_yaxis = points[index] - Vector3(0.f, points[index].y, 0.f);
+ if (!Math::is_equal_approx(distance_to_yaxis.length_squared(), radius * radius)) {
+ is_radius_correct = false;
+ break;
+ }
+ }
+
+ CHECK(is_radius_correct);
+ }
+
+ SUBCASE("[Primitive][Cylinder] Normal on side is orthogonal to side tangent vector") {
+ bool is_normal_correct{ true };
+ for (int index = 0; index < points.size(); ++index) {
+ Vector3 yaxis_to_point = points[index] - Vector3(0.f, points[index].y, 0.f);
+ Vector3 yaxis_to_rb = yaxis_to_point.normalized() * bottom_radius;
+ Vector3 rb_to_point = yaxis_to_point - yaxis_to_rb;
+ Vector3 y_to_bottom = -Vector3(0.f, points[index].y + 0.5 * height, 0.f);
+ Vector3 side_tangent = rb_to_point - y_to_bottom;
+
+ if (!Math::is_equal_approx(normals[index].dot(side_tangent), 0)) {
+ is_normal_correct = false;
+ break;
+ }
+ }
+
+ CHECK(is_normal_correct);
+ }
+ }
+
+} // End cylinder tests
+
+TEST_CASE("[SceneTree][Primitive][Plane] Plane Primitive") {
+ Ref<PlaneMesh> plane = memnew(PlaneMesh);
+
+ SUBCASE("[SceneTree][Primitive][Plane] Default values should be valid") {
+ CHECK(plane->get_size().x > 0);
+ CHECK(plane->get_size().y > 0);
+ CHECK(plane->get_subdivide_width() >= 0);
+ CHECK(plane->get_subdivide_depth() >= 0);
+ CHECK((plane->get_orientation() == PlaneMesh::FACE_X || plane->get_orientation() == PlaneMesh::FACE_Y || plane->get_orientation() == PlaneMesh::FACE_Z));
+ }
+
+ SUBCASE("[SceneTree][Primitive][Plane] Set properties and get them.") {
+ Size2 size{ 3.2, 1.8 };
+ Vector3 offset{ -7.3, 0.4, -1.7 };
+ plane->set_size(size);
+ plane->set_subdivide_width(15);
+ plane->set_subdivide_depth(29);
+ plane->set_center_offset(offset);
+ plane->set_orientation(PlaneMesh::FACE_X);
+
+ CHECK(plane->get_size().is_equal_approx(size));
+ CHECK(plane->get_subdivide_width() == 15);
+ CHECK(plane->get_subdivide_depth() == 29);
+ CHECK(plane->get_center_offset().is_equal_approx(offset));
+ CHECK(plane->get_orientation() == PlaneMesh::FACE_X);
+ }
+
+ SUBCASE("[SceneTree][Primitive][Plane] Ensure number of segments is >= 0.") {
+ plane->set_subdivide_width(-15);
+ plane->set_subdivide_depth(-29);
+
+ CHECK(plane->get_subdivide_width() >= 0);
+ CHECK(plane->get_subdivide_depth() >= 0);
+ }
+}
+
+TEST_CASE("[SceneTree][Primitive][Quad] QuadMesh Primitive") {
+ Ref<QuadMesh> quad = memnew(QuadMesh);
+
+ SUBCASE("[Primitive][Quad] Orientation on initialization is in z direction") {
+ CHECK(quad->get_orientation() == PlaneMesh::FACE_Z);
+ }
+}
+
+TEST_CASE("[SceneTree][Primitive][Prism] Prism Primitive") {
+ Ref<PrismMesh> prism = memnew(PrismMesh);
+
+ SUBCASE("[Primitive][Prism] There are valid values of properties on initialization.") {
+ CHECK(prism->get_left_to_right() >= 0);
+ CHECK(prism->get_size().x >= 0);
+ CHECK(prism->get_size().y >= 0);
+ CHECK(prism->get_size().z >= 0);
+ CHECK(prism->get_subdivide_width() >= 0);
+ CHECK(prism->get_subdivide_height() >= 0);
+ CHECK(prism->get_subdivide_depth() >= 0);
+ }
+
+ SUBCASE("[Primitive][Prism] Are able to change prism properties.") {
+ Vector3 size{ 4.3, 9.1, 0.43 };
+ prism->set_left_to_right(3.4f);
+ prism->set_size(size);
+ prism->set_subdivide_width(36);
+ prism->set_subdivide_height(5);
+ prism->set_subdivide_depth(64);
+
+ CHECK(prism->get_left_to_right() == doctest::Approx(3.4f));
+ CHECK(prism->get_size().is_equal_approx(size));
+ CHECK(prism->get_subdivide_width() == 36);
+ CHECK(prism->get_subdivide_height() == 5);
+ CHECK(prism->get_subdivide_depth() == 64);
+ }
+
+ SUBCASE("[Primitive][Prism] Ensure number of segments always >= 0") {
+ prism->set_subdivide_width(-36);
+ prism->set_subdivide_height(-5);
+ prism->set_subdivide_depth(-64);
+
+ CHECK(prism->get_subdivide_width() >= 0);
+ CHECK(prism->get_subdivide_height() >= 0);
+ CHECK(prism->get_subdivide_depth() >= 0);
+ }
+}
+
+TEST_CASE("[SceneTree][Primitive][Sphere] Sphere Primitive") {
+ Ref<SphereMesh> sphere = memnew(SphereMesh);
+
+ SUBCASE("[Primitive][Sphere] There are valid values of properties on initialization.") {
+ CHECK(sphere->get_radius() >= 0);
+ CHECK(sphere->get_height() >= 0);
+ CHECK(sphere->get_radial_segments() >= 0);
+ CHECK(sphere->get_rings() >= 0);
+ }
+
+ SUBCASE("[Primitive][Sphere] Are able to change prism properties.") {
+ sphere->set_radius(3.4f);
+ sphere->set_height(2.2f);
+ sphere->set_radial_segments(36);
+ sphere->set_rings(5);
+ sphere->set_is_hemisphere(true);
+
+ CHECK(sphere->get_radius() == doctest::Approx(3.4f));
+ CHECK(sphere->get_height() == doctest::Approx(2.2f));
+ CHECK(sphere->get_radial_segments() == 36);
+ CHECK(sphere->get_rings() == 5);
+ CHECK(sphere->get_is_hemisphere());
+ }
+
+ SUBCASE("[Primitive][Sphere] Ensure number of segments always >= 0") {
+ sphere->set_radial_segments(-36);
+ sphere->set_rings(-5);
+
+ CHECK(sphere->get_radial_segments() >= 0);
+ CHECK(sphere->get_rings() >= 0);
+ }
+
+ SUBCASE("[Primitive][Sphere] Sphere mesh tests.") {
+ Array data{};
+ data.resize(RS::ARRAY_MAX);
+ real_t radius = 1.1f;
+ int radial_segments = 8;
+ int rings = 5;
+ SphereMesh::create_mesh_array(data, radius, 2 * radius, radial_segments, rings);
+ Vector<Vector3> points = data[RS::ARRAY_VERTEX];
+ Vector<Vector3> normals = data[RS::ARRAY_NORMAL];
+
+ SUBCASE("[Primitive][Sphere] All points lie radius away from origin.") {
+ bool is_radius_correct = true;
+ for (Vector3 point : points) {
+ if (!Math::is_equal_approx(point.length_squared(), radius * radius)) {
+ is_radius_correct = false;
+ break;
+ }
+ }
+
+ CHECK(is_radius_correct);
+ }
+
+ SUBCASE("[Primitive][Sphere] All normals lie in direction of corresponding point.") {
+ bool is_normals_correct = true;
+ for (int index = 0; index < points.size(); ++index) {
+ if (!Math::is_equal_approx(normals[index].normalized().dot(points[index].normalized()), 1)) {
+ is_normals_correct = false;
+ break;
+ }
+ }
+
+ CHECK(is_normals_correct);
+ }
+ }
+}
+
+TEST_CASE("[SceneTree][Primitive][Torus] Torus Primitive") {
+ Ref<TorusMesh> torus = memnew(TorusMesh);
+ Ref<PrimitiveMesh> prim = memnew(PrimitiveMesh);
+
+ SUBCASE("[Primitive][Torus] There are valid values of properties on initialization.") {
+ CHECK(torus->get_inner_radius() > 0);
+ CHECK(torus->get_outer_radius() > 0);
+ CHECK(torus->get_rings() >= 0);
+ CHECK(torus->get_ring_segments() >= 0);
+ }
+
+ SUBCASE("[Primitive][Torus] Are able to change properties.") {
+ torus->set_inner_radius(3.2f);
+ torus->set_outer_radius(9.5f);
+ torus->set_rings(19);
+ torus->set_ring_segments(43);
+
+ CHECK(torus->get_inner_radius() == doctest::Approx(3.2f));
+ CHECK(torus->get_outer_radius() == doctest::Approx(9.5f));
+ CHECK(torus->get_rings() == 19);
+ CHECK(torus->get_ring_segments() == 43);
+ }
+}
+
+TEST_CASE("[SceneTree][Primitive][TubeTrail] TubeTrail Primitive") {
+ Ref<TubeTrailMesh> tube = memnew(TubeTrailMesh);
+
+ SUBCASE("[Primitive][TubeTrail] There are valid values of properties on initialization.") {
+ CHECK(tube->get_radius() > 0);
+ CHECK(tube->get_radial_steps() >= 0);
+ CHECK(tube->get_sections() >= 0);
+ CHECK(tube->get_section_length() > 0);
+ CHECK(tube->get_section_rings() >= 0);
+ CHECK(tube->get_curve() == nullptr);
+ CHECK(tube->get_builtin_bind_pose_count() >= 0);
+ }
+
+ SUBCASE("[Primitive][TubeTrail] Are able to change properties.") {
+ tube->set_radius(7.2f);
+ tube->set_radial_steps(9);
+ tube->set_sections(33);
+ tube->set_section_length(5.5f);
+ tube->set_section_rings(12);
+ Ref<Curve> curve = memnew(Curve);
+ tube->set_curve(curve);
+
+ CHECK(tube->get_radius() == doctest::Approx(7.2f));
+ CHECK(tube->get_section_length() == doctest::Approx(5.5f));
+ CHECK(tube->get_radial_steps() == 9);
+ CHECK(tube->get_sections() == 33);
+ CHECK(tube->get_section_rings() == 12);
+ CHECK(tube->get_curve() == curve);
+ }
+
+ SUBCASE("[Primitive][TubeTrail] Setting same curve more than once, it remains the same.") {
+ Ref<Curve> curve = memnew(Curve);
+ tube->set_curve(curve);
+ tube->set_curve(curve);
+ tube->set_curve(curve);
+
+ CHECK(tube->get_curve() == curve);
+ }
+
+ SUBCASE("[Primitive][TubeTrail] Setting curve, then changing to different curve.") {
+ Ref<Curve> curve1 = memnew(Curve);
+ Ref<Curve> curve2 = memnew(Curve);
+ tube->set_curve(curve1);
+ CHECK(tube->get_curve() == curve1);
+
+ tube->set_curve(curve2);
+ CHECK(tube->get_curve() == curve2);
+ }
+
+ SUBCASE("[Primitive][TubeTrail] Assign same curve to two different tube trails") {
+ Ref<TubeTrailMesh> tube2 = memnew(TubeTrailMesh);
+ Ref<Curve> curve = memnew(Curve);
+ tube->set_curve(curve);
+ tube2->set_curve(curve);
+
+ CHECK(tube->get_curve() == curve);
+ CHECK(tube2->get_curve() == curve);
+ }
+}
+
+TEST_CASE("[SceneTree][Primitive][RibbonTrail] RibbonTrail Primitive") {
+ Ref<RibbonTrailMesh> ribbon = memnew(RibbonTrailMesh);
+
+ SUBCASE("[Primitive][RibbonTrail] There are valid values of properties on initialization.") {
+ CHECK(ribbon->get_size() > 0);
+ CHECK(ribbon->get_sections() >= 0);
+ CHECK(ribbon->get_section_length() > 0);
+ CHECK(ribbon->get_section_segments() >= 0);
+ CHECK(ribbon->get_builtin_bind_pose_count() >= 0);
+ CHECK(ribbon->get_curve() == nullptr);
+ CHECK((ribbon->get_shape() == RibbonTrailMesh::SHAPE_CROSS ||
+ ribbon->get_shape() == RibbonTrailMesh::SHAPE_FLAT));
+ }
+
+ SUBCASE("[Primitive][RibbonTrail] Able to change properties.") {
+ Ref<Curve> curve = memnew(Curve);
+ ribbon->set_size(4.3f);
+ ribbon->set_sections(16);
+ ribbon->set_section_length(1.3f);
+ ribbon->set_section_segments(9);
+ ribbon->set_curve(curve);
+
+ CHECK(ribbon->get_size() == doctest::Approx(4.3f));
+ CHECK(ribbon->get_section_length() == doctest::Approx(1.3f));
+ CHECK(ribbon->get_sections() == 16);
+ CHECK(ribbon->get_section_segments() == 9);
+ CHECK(ribbon->get_curve() == curve);
+ }
+
+ SUBCASE("[Primitive][RibbonTrail] Setting same curve more than once, it remains the same.") {
+ Ref<Curve> curve = memnew(Curve);
+ ribbon->set_curve(curve);
+ ribbon->set_curve(curve);
+ ribbon->set_curve(curve);
+
+ CHECK(ribbon->get_curve() == curve);
+ }
+
+ SUBCASE("[Primitive][RibbonTrail] Setting curve, then changing to different curve.") {
+ Ref<Curve> curve1 = memnew(Curve);
+ Ref<Curve> curve2 = memnew(Curve);
+ ribbon->set_curve(curve1);
+ CHECK(ribbon->get_curve() == curve1);
+
+ ribbon->set_curve(curve2);
+ CHECK(ribbon->get_curve() == curve2);
+ }
+
+ SUBCASE("[Primitive][RibbonTrail] Assign same curve to two different ribbon trails") {
+ Ref<RibbonTrailMesh> ribbon2 = memnew(RibbonTrailMesh);
+ Ref<Curve> curve = memnew(Curve);
+ ribbon->set_curve(curve);
+ ribbon2->set_curve(curve);
+
+ CHECK(ribbon->get_curve() == curve);
+ CHECK(ribbon2->get_curve() == curve);
+ }
+}
+
+TEST_CASE("[SceneTree][Primitive][Text] Text Primitive") {
+ Ref<TextMesh> text = memnew(TextMesh);
+
+ SUBCASE("[Primitive][Text] There are valid values of properties on initialization.") {
+ CHECK((text->get_horizontal_alignment() == HORIZONTAL_ALIGNMENT_CENTER ||
+ text->get_horizontal_alignment() == HORIZONTAL_ALIGNMENT_LEFT ||
+ text->get_horizontal_alignment() == HORIZONTAL_ALIGNMENT_RIGHT ||
+ text->get_horizontal_alignment() == HORIZONTAL_ALIGNMENT_FILL));
+ CHECK((text->get_vertical_alignment() == VERTICAL_ALIGNMENT_BOTTOM ||
+ text->get_vertical_alignment() == VERTICAL_ALIGNMENT_TOP ||
+ text->get_vertical_alignment() == VERTICAL_ALIGNMENT_CENTER ||
+ text->get_vertical_alignment() == VERTICAL_ALIGNMENT_FILL));
+ CHECK(text->get_font() == nullptr);
+ CHECK(text->get_font_size() > 0);
+ CHECK(text->get_line_spacing() >= 0);
+ CHECK((text->get_autowrap_mode() == TextServer::AUTOWRAP_OFF ||
+ text->get_autowrap_mode() == TextServer::AUTOWRAP_ARBITRARY ||
+ text->get_autowrap_mode() == TextServer::AUTOWRAP_WORD ||
+ text->get_autowrap_mode() == TextServer::AUTOWRAP_WORD_SMART));
+ CHECK((text->get_text_direction() == TextServer::DIRECTION_AUTO ||
+ text->get_text_direction() == TextServer::DIRECTION_LTR ||
+ text->get_text_direction() == TextServer::DIRECTION_RTL));
+ CHECK((text->get_structured_text_bidi_override() == TextServer::STRUCTURED_TEXT_DEFAULT ||
+ text->get_structured_text_bidi_override() == TextServer::STRUCTURED_TEXT_URI ||
+ text->get_structured_text_bidi_override() == TextServer::STRUCTURED_TEXT_FILE ||
+ text->get_structured_text_bidi_override() == TextServer::STRUCTURED_TEXT_EMAIL ||
+ text->get_structured_text_bidi_override() == TextServer::STRUCTURED_TEXT_LIST ||
+ text->get_structured_text_bidi_override() == TextServer::STRUCTURED_TEXT_NONE ||
+ text->get_structured_text_bidi_override() == TextServer::STRUCTURED_TEXT_CUSTOM));
+ CHECK(text->get_structured_text_bidi_override_options().size() >= 0);
+ CHECK(text->get_width() > 0);
+ CHECK(text->get_depth() > 0);
+ CHECK(text->get_curve_step() > 0);
+ CHECK(text->get_pixel_size() > 0);
+ }
+
+ SUBCASE("[Primitive][Text] Change the properties of the mesh.") {
+ Ref<Font> font = memnew(Font);
+ Array options{};
+ Point2 offset{ 30.8, 104.23 };
+ text->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
+ text->set_vertical_alignment(VERTICAL_ALIGNMENT_BOTTOM);
+ text->set_text("Hello");
+ text->set_font(font);
+ text->set_font_size(12);
+ text->set_line_spacing(1.7f);
+ text->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
+ text->set_text_direction(TextServer::DIRECTION_RTL);
+ text->set_language("French");
+ text->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_EMAIL);
+ text->set_structured_text_bidi_override_options(options);
+ text->set_uppercase(true);
+ real_t width{ 0.6 };
+ real_t depth{ 1.7 };
+ real_t pixel_size{ 2.8 };
+ real_t curve_step{ 4.8 };
+ text->set_width(width);
+ text->set_depth(depth);
+ text->set_curve_step(curve_step);
+ text->set_pixel_size(pixel_size);
+ text->set_offset(offset);
+
+ CHECK(text->get_horizontal_alignment() == HORIZONTAL_ALIGNMENT_RIGHT);
+ CHECK(text->get_vertical_alignment() == VERTICAL_ALIGNMENT_BOTTOM);
+ CHECK(text->get_text_direction() == TextServer::DIRECTION_RTL);
+ CHECK(text->get_text() == "Hello");
+ CHECK(text->get_font() == font);
+ CHECK(text->get_font_size() == 12);
+ CHECK(text->get_autowrap_mode() == TextServer::AUTOWRAP_WORD_SMART);
+ CHECK(text->get_language() == "French");
+ CHECK(text->get_structured_text_bidi_override() == TextServer::STRUCTURED_TEXT_EMAIL);
+ CHECK(text->get_structured_text_bidi_override_options() == options);
+ CHECK(text->is_uppercase() == true);
+ CHECK(text->get_offset() == offset);
+ CHECK(text->get_line_spacing() == doctest::Approx(1.7f));
+ CHECK(text->get_width() == doctest::Approx(width));
+ CHECK(text->get_depth() == doctest::Approx(depth));
+ CHECK(text->get_curve_step() == doctest::Approx(curve_step));
+ CHECK(text->get_pixel_size() == doctest::Approx(pixel_size));
+ }
+
+ SUBCASE("[Primitive][Text] Set objects multiple times.") {
+ Ref<Font> font = memnew(Font);
+ Array options{};
+ Point2 offset{ 30.8, 104.23 };
+
+ text->set_font(font);
+ text->set_font(font);
+ text->set_font(font);
+ text->set_structured_text_bidi_override_options(options);
+ text->set_structured_text_bidi_override_options(options);
+ text->set_structured_text_bidi_override_options(options);
+ text->set_offset(offset);
+ text->set_offset(offset);
+ text->set_offset(offset);
+
+ CHECK(text->get_font() == font);
+ CHECK(text->get_structured_text_bidi_override_options() == options);
+ CHECK(text->get_offset() == offset);
+ }
+
+ SUBCASE("[Primitive][Text] Set then change objects.") {
+ Ref<Font> font1 = memnew(Font);
+ Ref<Font> font2 = memnew(Font);
+ Array options1{};
+ Array options2{};
+ Point2 offset1{ 30.8, 104.23 };
+ Point2 offset2{ -30.8, -104.23 };
+
+ text->set_font(font1);
+ text->set_structured_text_bidi_override_options(options1);
+ text->set_offset(offset1);
+
+ CHECK(text->get_font() == font1);
+ CHECK(text->get_structured_text_bidi_override_options() == options1);
+ CHECK(text->get_offset() == offset1);
+
+ text->set_font(font2);
+ text->set_structured_text_bidi_override_options(options2);
+ text->set_offset(offset2);
+
+ CHECK(text->get_font() == font2);
+ CHECK(text->get_structured_text_bidi_override_options() == options2);
+ CHECK(text->get_offset() == offset2);
+ }
+
+ SUBCASE("[Primitive][Text] Assign same font to two Textmeshes.") {
+ Ref<TextMesh> text2 = memnew(TextMesh);
+ Ref<Font> font = memnew(Font);
+
+ text->set_font(font);
+ text2->set_font(font);
+
+ CHECK(text->get_font() == font);
+ CHECK(text2->get_font() == font);
+ }
+}
+
+} // namespace TestPrimitives
+
+#endif // TEST_PRIMITIVES_H
diff --git a/tests/scene/test_text_edit.h b/tests/scene/test_text_edit.h
index 225316b293..5dad7d06e1 100644
--- a/tests/scene/test_text_edit.h
+++ b/tests/scene/test_text_edit.h
@@ -93,10 +93,10 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->undo();
MessageQueue::get_singleton()->flush();
CHECK(text_edit->get_text() == "test text");
- CHECK(text_edit->get_caret_column() == 9);
+ CHECK(text_edit->get_caret_column() == 0);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_set");
text_edit->redo();
@@ -104,18 +104,18 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
CHECK(text_edit->get_text() == "");
CHECK(text_edit->get_caret_column() == 0);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_set");
// Cannot undo when not-editable but should still clear.
text_edit->undo();
MessageQueue::get_singleton()->flush();
CHECK(text_edit->get_text() == "test text");
- CHECK(text_edit->get_caret_column() == 9);
+ CHECK(text_edit->get_caret_column() == 0);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_set");
// Clear.
@@ -131,8 +131,8 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
CHECK(text_edit->get_text() == "");
CHECK(text_edit->get_caret_column() == 0);
SIGNAL_CHECK("text_set", empty_signal_args);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_clear_args);
+ SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
text_edit->set_editable(true);
@@ -252,6 +252,7 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
CHECK(text_edit->get_line(0) == "te");
CHECK(text_edit->has_selection());
CHECK(text_edit->get_selected_text() == "te");
+ CHECK(text_edit->get_caret_column() == 2);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
@@ -263,6 +264,8 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
MessageQueue::get_singleton()->flush();
CHECK(text_edit->get_line(0) == "test text");
CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "test");
+ CHECK(text_edit->get_caret_column() == 4);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
@@ -271,7 +274,8 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->redo();
MessageQueue::get_singleton()->flush();
CHECK(text_edit->get_line(0) == "te");
- CHECK_FALSE(text_edit->has_selection()); // Currently not handled.
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_caret_column() == 2);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
@@ -425,7 +429,7 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->undo();
MessageQueue::get_singleton()->flush();
CHECK(text_edit->get_text() == "testing\nswap");
- CHECK_FALSE(text_edit->has_selection()); // Not currently handled.
+ CHECK(text_edit->has_selection());
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
@@ -436,7 +440,7 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->redo();
MessageQueue::get_singleton()->flush();
CHECK(text_edit->get_text() == "new\ntesting\nswap");
- CHECK_FALSE(text_edit->has_selection()); // Not currently handled.
+ CHECK(text_edit->has_selection());
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
@@ -448,7 +452,7 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
CHECK(text_edit->has_selection());
CHECK(text_edit->get_selection_from_line() == 0);
CHECK(text_edit->get_selection_to_line() == 2);
- SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("caret_changed");
((Array)lines_edited_args[0])[0] = 2;
((Array)lines_edited_args[0])[1] = 3;
@@ -533,7 +537,7 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
MessageQueue::get_singleton()->flush();
CHECK(text_edit->get_text() == "temidsting\nswap");
CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 10);
+ CHECK(text_edit->get_caret_column() == 5);
CHECK(text_edit->has_selection());
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
@@ -633,17 +637,42 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
}
SUBCASE("[TextEdit] select word under caret") {
- text_edit->set_text("test test");
+ text_edit->set_text("\ntest test\ntest test");
+
text_edit->set_caret_column(0);
+ text_edit->set_caret_line(1);
+
+ text_edit->add_caret(2, 0);
+ text_edit->add_caret(2, 2);
+ CHECK(text_edit->get_caret_count() == 3);
+
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
text_edit->select_word_under_caret();
- CHECK(text_edit->get_selected_text() == "test");
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selection_from_line() == 0);
- CHECK(text_edit->get_selection_from_column() == 0);
- CHECK(text_edit->get_selection_to_line() == 0);
- CHECK(text_edit->get_selection_to_column() == 4);
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
+ CHECK(text_edit->has_selection(0));
+ CHECK(text_edit->get_selected_text(0) == "test");
+ CHECK(text_edit->get_selection_from_line(0) == 1);
+ CHECK(text_edit->get_selection_from_column(0) == 0);
+ CHECK(text_edit->get_selection_to_line(0) == 1);
+ CHECK(text_edit->get_selection_to_column(0) == 4);
+ CHECK(text_edit->get_caret_line(0) == 1);
+ CHECK(text_edit->get_caret_column(0) == 4);
+
+ CHECK(text_edit->has_selection(1));
+ CHECK(text_edit->get_selected_text(1) == "test");
+ CHECK(text_edit->get_selection_from_line(1) == 2);
+ CHECK(text_edit->get_selection_from_column(1) == 0);
+ CHECK(text_edit->get_selection_to_line(1) == 2);
+ CHECK(text_edit->get_selection_to_column(1) == 4);
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 4);
+
+ CHECK(text_edit->get_caret_count() == 2);
text_edit->select_word_under_caret();
CHECK_FALSE(text_edit->has_selection());
@@ -652,27 +681,44 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SEND_GUI_ACTION(text_edit, "ui_text_select_word_under_caret");
CHECK(text_edit->get_viewport()->is_input_handled());
MessageQueue::get_singleton()->flush();
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "test");
- CHECK(text_edit->get_selection_from_line() == 0);
- CHECK(text_edit->get_selection_from_column() == 0);
- CHECK(text_edit->get_selection_to_line() == 0);
- CHECK(text_edit->get_selection_to_column() == 4);
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
+ CHECK(text_edit->has_selection(0));
+ CHECK(text_edit->get_selected_text(0) == "test");
+ CHECK(text_edit->get_selection_from_line(0) == 1);
+ CHECK(text_edit->get_selection_from_column(0) == 0);
+ CHECK(text_edit->get_selection_to_line(0) == 1);
+ CHECK(text_edit->get_selection_to_column(0) == 4);
+ CHECK(text_edit->get_caret_line(0) == 1);
+ CHECK(text_edit->get_caret_column(0) == 4);
+
+ CHECK(text_edit->has_selection(1));
+ CHECK(text_edit->get_selected_text(1) == "test");
+ CHECK(text_edit->get_selection_from_line(1) == 2);
+ CHECK(text_edit->get_selection_from_column(1) == 0);
+ CHECK(text_edit->get_selection_to_line(1) == 2);
+ CHECK(text_edit->get_selection_to_column(1) == 4);
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 4);
+
+ CHECK(text_edit->get_selected_text() == "test\ntest");
SIGNAL_CHECK("caret_changed", empty_signal_args);
text_edit->set_selecting_enabled(false);
text_edit->select_word_under_caret();
CHECK_FALSE(text_edit->has_selection());
CHECK(text_edit->get_selected_text() == "");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 4);
+ CHECK(text_edit->get_caret_line(0) == 1);
+ CHECK(text_edit->get_caret_column(0) == 4);
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 4);
SIGNAL_CHECK_FALSE("caret_changed");
text_edit->set_selecting_enabled(true);
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(5);
+ text_edit->set_caret_line(1, false, true, 0, 0);
+ text_edit->set_caret_column(5, false, 0);
+
+ text_edit->set_caret_line(2, false, true, 0, 1);
+ text_edit->set_caret_column(5, false, 1);
+
text_edit->select_word_under_caret();
CHECK_FALSE(text_edit->has_selection());
CHECK(text_edit->get_selected_text() == "");
@@ -680,11 +726,81 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->select_word_under_caret();
CHECK_FALSE(text_edit->has_selection());
CHECK(text_edit->get_selected_text() == "");
- CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 5);
+ CHECK(text_edit->get_caret_line(0) == 1);
+ CHECK(text_edit->get_caret_column(0) == 5);
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 5);
SIGNAL_CHECK_FALSE("caret_changed");
}
+ SUBCASE("[TextEdit] add selection for next occurrence") {
+ text_edit->set_text("\ntest other_test\nrandom test\nword test word nonrandom");
+ text_edit->set_caret_column(0);
+ text_edit->set_caret_line(1);
+
+ // First selection made by the implicit select_word_under_caret call
+ text_edit->add_selection_for_next_occurrence();
+ CHECK(text_edit->get_caret_count() == 1);
+ CHECK(text_edit->get_selected_text(0) == "test");
+ CHECK(text_edit->get_selection_from_line(0) == 1);
+ CHECK(text_edit->get_selection_from_column(0) == 0);
+ CHECK(text_edit->get_selection_to_line(0) == 1);
+ CHECK(text_edit->get_selection_to_column(0) == 4);
+ CHECK(text_edit->get_caret_line(0) == 1);
+ CHECK(text_edit->get_caret_column(0) == 4);
+
+ text_edit->add_selection_for_next_occurrence();
+ CHECK(text_edit->get_caret_count() == 2);
+ CHECK(text_edit->get_selected_text(1) == "test");
+ CHECK(text_edit->get_selection_from_line(1) == 1);
+ CHECK(text_edit->get_selection_from_column(1) == 13);
+ CHECK(text_edit->get_selection_to_line(1) == 1);
+ CHECK(text_edit->get_selection_to_column(1) == 17);
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 17);
+
+ text_edit->add_selection_for_next_occurrence();
+ CHECK(text_edit->get_caret_count() == 3);
+ CHECK(text_edit->get_selected_text(2) == "test");
+ CHECK(text_edit->get_selection_from_line(2) == 2);
+ CHECK(text_edit->get_selection_from_column(2) == 9);
+ CHECK(text_edit->get_selection_to_line(2) == 2);
+ CHECK(text_edit->get_selection_to_column(2) == 13);
+ CHECK(text_edit->get_caret_line(2) == 2);
+ CHECK(text_edit->get_caret_column(2) == 13);
+
+ text_edit->add_selection_for_next_occurrence();
+ CHECK(text_edit->get_caret_count() == 4);
+ CHECK(text_edit->get_selected_text(3) == "test");
+ CHECK(text_edit->get_selection_from_line(3) == 3);
+ CHECK(text_edit->get_selection_from_column(3) == 5);
+ CHECK(text_edit->get_selection_to_line(3) == 3);
+ CHECK(text_edit->get_selection_to_column(3) == 9);
+ CHECK(text_edit->get_caret_line(3) == 3);
+ CHECK(text_edit->get_caret_column(3) == 9);
+
+ // A different word with a new manually added caret
+ text_edit->add_caret(2, 1);
+ text_edit->select(2, 0, 2, 4, 4);
+ CHECK(text_edit->get_selected_text(4) == "rand");
+
+ text_edit->add_selection_for_next_occurrence();
+ CHECK(text_edit->get_caret_count() == 6);
+ CHECK(text_edit->get_selected_text(5) == "rand");
+ CHECK(text_edit->get_selection_from_line(5) == 3);
+ CHECK(text_edit->get_selection_from_column(5) == 18);
+ CHECK(text_edit->get_selection_to_line(5) == 3);
+ CHECK(text_edit->get_selection_to_column(5) == 22);
+ CHECK(text_edit->get_caret_line(5) == 3);
+ CHECK(text_edit->get_caret_column(5) == 22);
+
+ // Make sure the previous selections are still active
+ CHECK(text_edit->get_selected_text(0) == "test");
+ CHECK(text_edit->get_selected_text(1) == "test");
+ CHECK(text_edit->get_selected_text(2) == "test");
+ CHECK(text_edit->get_selected_text(3) == "test");
+ }
+
SUBCASE("[TextEdit] deselect on focus loss") {
text_edit->set_text("test");
@@ -950,11 +1066,15 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->delete_selection();
CHECK(text_edit->get_text() == "this is some text\nfor selection");
+ CHECK(text_edit->get_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 8);
text_edit->select(0, 8, 0, 4);
CHECK(text_edit->has_selection());
SEND_GUI_ACTION(text_edit, "ui_text_backspace");
CHECK(text_edit->get_text() == "thissome text\nfor selection");
+ CHECK(text_edit->get_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 4);
text_edit->undo();
CHECK(text_edit->has_selection());
@@ -966,7 +1086,7 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
CHECK_FALSE(text_edit->has_selection());
CHECK(text_edit->get_text() == "thissome text\nfor selection");
CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 8);
+ CHECK(text_edit->get_caret_column() == 4);
text_edit->undo();
CHECK(text_edit->has_selection());
@@ -991,7 +1111,7 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
CHECK_FALSE(text_edit->has_selection());
CHECK(text_edit->get_text() == "thissome text\nfor selection");
CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == 8);
+ CHECK(text_edit->get_caret_column() == 4);
text_edit->undo();
CHECK(text_edit->has_selection());
@@ -1176,8 +1296,8 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->undo();
MessageQueue::get_singleton()->flush();
CHECK(text_edit->get_text() == "this is\nsome\n");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
+ CHECK(text_edit->get_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 6);
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
@@ -1187,9 +1307,9 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->redo();
MessageQueue::get_singleton()->flush();
CHECK(text_edit->get_text() == "some\n");
- CHECK(text_edit->get_caret_line() == 1);
- CHECK(text_edit->get_caret_column() == 0);
- SIGNAL_CHECK_FALSE("caret_changed");
+ CHECK(text_edit->get_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 4);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
@@ -1259,9 +1379,14 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
lines_edited_args.push_back(args1);
SUBCASE("[TextEdit] ui_text_newline_above") {
- text_edit->set_text("this is some test text.");
+ text_edit->set_text("this is some test text.\nthis is some test text.");
text_edit->select(0, 0, 0, 4);
text_edit->set_caret_column(4);
+
+ text_edit->add_caret(1, 4);
+ text_edit->select(1, 0, 1, 4, 1);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1269,50 +1394,78 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
- ((Array)lines_edited_args[0])[1] = 1;
+ // For the second caret.
+ Array args2;
+ args2.push_back(0);
+ args2.push_back(1);
+ lines_edited_args.push_front(args2);
+
+ ((Array)lines_edited_args[1])[1] = 1;
SEND_GUI_ACTION(text_edit, "ui_text_newline_above");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nthis is some test text.");
+ CHECK(text_edit->get_text() == "\nthis is some test text.\n\nthis is some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
text_edit->set_caret_line(1);
text_edit->set_caret_column(4);
- text_edit->select(0, 0, 0, 4);
+
+ text_edit->set_caret_line(3, false, true, 0, 1);
+ text_edit->set_caret_column(4, false, 1);
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("caret_changed");
text_edit->set_editable(false);
SEND_GUI_ACTION(text_edit, "ui_text_newline_above");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nthis is some test text.");
+ CHECK(text_edit->get_text() == "\nthis is some test text.\n\nthis is some test text.");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 4);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 3);
+ CHECK(text_edit->get_caret_column(1) == 4);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
text_edit->set_editable(true);
+ ((Array)lines_edited_args[0])[0] = 2;
+ ((Array)lines_edited_args[0])[1] = 3;
+
SEND_GUI_ACTION(text_edit, "ui_text_newline_above");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n\nthis is some test text.");
+ CHECK(text_edit->get_text() == "\n\nthis is some test text.\n\n\nthis is some test text.");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 4);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
}
SUBCASE("[TextEdit] ui_text_newline_blank") {
- text_edit->set_text("this is some test text.");
+ text_edit->set_text("this is some test text.\nthis is some test text.");
text_edit->select(0, 0, 0, 4);
text_edit->set_caret_column(4);
+
+ text_edit->add_caret(1, 4);
+ text_edit->select(1, 0, 1, 4, 1);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1320,13 +1473,23 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
- ((Array)lines_edited_args[0])[1] = 1;
+ // For the second caret.
+ Array args2;
+ args2.push_back(1);
+ args2.push_back(2);
+ lines_edited_args.push_front(args2);
+
+ ((Array)lines_edited_args[1])[1] = 1;
SEND_GUI_ACTION(text_edit, "ui_text_newline_blank");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some test text.\n");
+ CHECK(text_edit->get_text() == "this is some test text.\n\nthis is some test text.\n");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 3);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
@@ -1334,10 +1497,14 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_editable(false);
SEND_GUI_ACTION(text_edit, "ui_text_newline_blank");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some test text.\n");
+ CHECK(text_edit->get_text() == "this is some test text.\n\nthis is some test text.\n");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 3);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
@@ -1345,9 +1512,14 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
}
SUBCASE("[TextEdit] ui_text_newline") {
- text_edit->set_text("this is some test text.");
+ text_edit->set_text("this is some test text.\nthis is some test text.");
text_edit->select(0, 0, 0, 4);
text_edit->set_caret_column(4);
+
+ text_edit->add_caret(1, 4);
+ text_edit->select(1, 0, 1, 4, 1);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1355,14 +1527,27 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
- lines_edited_args.push_back(lines_edited_args[0].duplicate());
- ((Array)lines_edited_args[1])[1] = 1;
+ // For the second caret.
+ Array args2;
+ args2.push_back(1);
+ args2.push_back(1);
+ lines_edited_args.push_front(args2);
+ lines_edited_args.push_front(args2.duplicate());
+ ((Array)lines_edited_args[1])[1] = 2;
+
+ lines_edited_args.push_back(lines_edited_args[2].duplicate());
+ ((Array)lines_edited_args[3])[1] = 1;
+
SEND_GUI_ACTION(text_edit, "ui_text_newline");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n is some test text.");
+ CHECK(text_edit->get_text() == "\n is some test text.\n\n is some test text.");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 3);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
@@ -1370,10 +1555,14 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_editable(false);
SEND_GUI_ACTION(text_edit, "ui_text_newline");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n is some test text.");
+ CHECK(text_edit->get_text() == "\n is some test text.\n\n is some test text.");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 3);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
@@ -1381,10 +1570,15 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
}
SUBCASE("[TextEdit] ui_text_backspace_all_to_left") {
- text_edit->set_text("\nthis is some test text.");
+ text_edit->set_text("\nthis is some test text.\n\nthis is some test text.");
text_edit->select(1, 0, 1, 4);
text_edit->set_caret_line(1);
text_edit->set_caret_column(4);
+
+ text_edit->add_caret(3, 4);
+ text_edit->select(3, 0, 3, 4, 1);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
Ref<InputEvent> tmpevent = InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::ALT | KeyModifierMask::CMD_OR_CTRL);
@@ -1395,34 +1589,50 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
+ // For the second caret.
+ Array args2;
+ args2.push_back(3);
+ args2.push_back(3);
+ lines_edited_args.push_front(args2);
+
// With selection should be a normal backspace.
- ((Array)lines_edited_args[0])[0] = 1;
- ((Array)lines_edited_args[0])[1] = 1;
+ ((Array)lines_edited_args[1])[0] = 1;
+ ((Array)lines_edited_args[1])[1] = 1;
SEND_GUI_ACTION(text_edit, "ui_text_backspace_all_to_left");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n is some test text.");
+ CHECK(text_edit->get_text() == "\n is some test text.\n\n is some test text.");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 3);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- ((Array)lines_edited_args[0])[1] = 0;
+ ((Array)lines_edited_args[0])[1] = 2;
+ ((Array)lines_edited_args[1])[1] = 0;
// Start of line should also be a normal backspace.
SEND_GUI_ACTION(text_edit, "ui_text_backspace_all_to_left");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.");
+ CHECK(text_edit->get_text() == " is some test text.\n is some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
text_edit->set_caret_column(text_edit->get_line(0).length());
+ text_edit->set_caret_column(text_edit->get_line(1).length(), false, 1);
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1433,23 +1643,33 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_editable(false);
SEND_GUI_ACTION(text_edit, "ui_text_backspace_all_to_left");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.");
+ CHECK(text_edit->get_text() == " is some test text.\n is some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == text_edit->get_line(0).length());
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == text_edit->get_line(1).length());
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
text_edit->set_editable(true);
- ((Array)lines_edited_args[0])[0] = 0;
+ ((Array)lines_edited_args[0])[0] = 1;
+ ((Array)lines_edited_args[0])[1] = 1;
+ ((Array)lines_edited_args[1])[0] = 0;
SEND_GUI_ACTION(text_edit, "ui_text_backspace_all_to_left");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "");
+ CHECK(text_edit->get_text() == "\n");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
@@ -1458,10 +1678,14 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
}
SUBCASE("[TextEdit] ui_text_backspace_word") {
- text_edit->set_text("\nthis is some test text.");
+ text_edit->set_text("\nthis is some test text.\n\nthis is some test text.");
text_edit->select(1, 0, 1, 4);
text_edit->set_caret_line(1);
text_edit->set_caret_column(4);
+
+ text_edit->add_caret(3, 4);
+ text_edit->select(3, 0, 3, 4, 1);
+ CHECK(text_edit->get_caret_count() == 2);
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1469,30 +1693,45 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
+ // For the second caret.
+ Array args2;
+ args2.push_back(3);
+ args2.push_back(3);
+ lines_edited_args.push_front(args2);
+
// With selection should be a normal backspace.
- ((Array)lines_edited_args[0])[0] = 1;
- ((Array)lines_edited_args[0])[1] = 1;
+ ((Array)lines_edited_args[1])[0] = 1;
+ ((Array)lines_edited_args[1])[1] = 1;
SEND_GUI_ACTION(text_edit, "ui_text_backspace_word");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n is some test text.");
+ CHECK(text_edit->get_text() == "\n is some test text.\n\n is some test text.");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 3);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
text_edit->end_complex_operation();
- ((Array)lines_edited_args[0])[1] = 0;
+ ((Array)lines_edited_args[0])[1] = 2;
+ ((Array)lines_edited_args[1])[1] = 0;
// Start of line should also be a normal backspace.
SEND_GUI_ACTION(text_edit, "ui_text_backspace_word");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.");
+ CHECK(text_edit->get_text() == " is some test text.\n is some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
@@ -1500,16 +1739,21 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_editable(false);
SEND_GUI_ACTION(text_edit, "ui_text_backspace_word");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.");
+ CHECK(text_edit->get_text() == " is some test text.\n is some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
text_edit->set_editable(true);
text_edit->set_caret_column(text_edit->get_line(0).length());
+ text_edit->set_caret_column(text_edit->get_line(1).length(), false, 1);
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1517,24 +1761,35 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
- ((Array)lines_edited_args[0])[0] = 0;
+ ((Array)lines_edited_args[0])[0] = 1;
+ ((Array)lines_edited_args[0])[1] = 1;
+ ((Array)lines_edited_args[1])[0] = 0;
SEND_GUI_ACTION(text_edit, "ui_text_backspace_word");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test ");
+ CHECK(text_edit->get_text() == " is some test \n is some test ");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 14);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 14);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
}
SUBCASE("[TextEdit] ui_text_backspace") {
- text_edit->set_text("\nthis is some test text.");
+ text_edit->set_text("\nthis is some test text.\n\nthis is some test text.");
text_edit->select(1, 0, 1, 4);
text_edit->set_caret_line(1);
text_edit->set_caret_column(4);
+
+ text_edit->add_caret(3, 4);
+ text_edit->select(3, 0, 3, 4, 1);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1542,34 +1797,50 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
+ // For the second caret.
+ Array args2;
+ args2.push_back(3);
+ args2.push_back(3);
+ lines_edited_args.push_front(args2);
+
// With selection should be a normal backspace.
- ((Array)lines_edited_args[0])[0] = 1;
- ((Array)lines_edited_args[0])[1] = 1;
+ ((Array)lines_edited_args[1])[0] = 1;
+ ((Array)lines_edited_args[1])[1] = 1;
SEND_GUI_ACTION(text_edit, "ui_text_backspace");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n is some test text.");
+ CHECK(text_edit->get_text() == "\n is some test text.\n\n is some test text.");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 3);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- ((Array)lines_edited_args[0])[1] = 0;
+ ((Array)lines_edited_args[0])[1] = 2;
+ ((Array)lines_edited_args[1])[1] = 0;
// Start of line should also be a normal backspace.
SEND_GUI_ACTION(text_edit, "ui_text_backspace");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.");
+ CHECK(text_edit->get_text() == " is some test text.\n is some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
text_edit->set_caret_column(text_edit->get_line(0).length());
+ text_edit->set_caret_column(text_edit->get_line(1).length(), false, 1);
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1580,23 +1851,33 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_editable(false);
SEND_GUI_ACTION(text_edit, "ui_text_backspace");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.");
+ CHECK(text_edit->get_text() == " is some test text.\n is some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == text_edit->get_line(0).length());
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == text_edit->get_line(1).length());
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
text_edit->set_editable(true);
- ((Array)lines_edited_args[0])[0] = 0;
+ ((Array)lines_edited_args[0])[0] = 1;
+ ((Array)lines_edited_args[0])[1] = 1;
+ ((Array)lines_edited_args[1])[0] = 0;
SEND_GUI_ACTION(text_edit, "ui_text_backspace");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text");
+ CHECK(text_edit->get_text() == " is some test text\n is some test text");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 18);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 18);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
@@ -1605,6 +1886,10 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->select(0, 18, 0, 0);
text_edit->set_caret_line(0);
text_edit->set_caret_column(0);
+
+ text_edit->select(1, 18, 1, 0, 1);
+ text_edit->set_caret_line(1, false, true, 0, 1);
+ text_edit->set_caret_column(0, false, 1);
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1612,12 +1897,12 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
- ((Array)lines_edited_args[0])[0] = 0;
-
SEND_GUI_ACTION(text_edit, "ui_text_backspace");
- CHECK(text_edit->get_text() == "");
+ CHECK(text_edit->get_text() == "\n");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 0);
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
@@ -1627,10 +1912,15 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
Ref<InputEvent> tmpevent = InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::ALT | KeyModifierMask::CMD_OR_CTRL);
InputMap::get_singleton()->action_add_event("ui_text_delete_all_to_right", tmpevent);
- text_edit->set_text("this is some test text.\n");
+ text_edit->set_text("this is some test text.\nthis is some test text.\n");
text_edit->select(0, 0, 0, 4);
text_edit->set_caret_line(0);
text_edit->set_caret_column(4);
+
+ text_edit->add_caret(1, 4);
+ text_edit->select(1, 0, 1, 4, 1);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1638,19 +1928,30 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
+ // For the second caret.
+ Array args2;
+ args2.push_back(1);
+ args2.push_back(1);
+ lines_edited_args.push_front(args2);
+
// With selection should be a normal delete.
SEND_GUI_ACTION(text_edit, "ui_text_delete_all_to_right");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.\n");
+ CHECK(text_edit->get_text() == " is some test text.\n is some test text.\n");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
// End of line should not do anything.
text_edit->set_caret_column(text_edit->get_line(0).length());
+ text_edit->set_caret_column(text_edit->get_line(1).length(), false, 1);
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1660,15 +1961,20 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SEND_GUI_ACTION(text_edit, "ui_text_delete_all_to_right");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.\n");
+ CHECK(text_edit->get_text() == " is some test text.\n is some test text.\n");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == text_edit->get_line(0).length());
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == text_edit->get_line(1).length());
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
text_edit->set_caret_column(0);
+ text_edit->set_caret_column(0, false, 1);
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1679,10 +1985,14 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_editable(false);
SEND_GUI_ACTION(text_edit, "ui_text_delete_all_to_right");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " is some test text.\n");
+ CHECK(text_edit->get_text() == " is some test text.\n is some test text.\n");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
@@ -1690,10 +2000,14 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SEND_GUI_ACTION(text_edit, "ui_text_delete_all_to_right");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\n");
+ CHECK(text_edit->get_text() == "\n\n");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
@@ -1705,10 +2019,15 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_caret_mid_grapheme_enabled(true);
CHECK(text_edit->is_caret_mid_grapheme_enabled());
- text_edit->set_text("this ffi some test text.\n");
+ text_edit->set_text("this ffi some test text.\n\nthis ffi some test text.\n");
text_edit->select(0, 0, 0, 4);
text_edit->set_caret_line(0);
text_edit->set_caret_column(4);
+
+ text_edit->add_caret(2, 4);
+ text_edit->select(2, 0, 2, 4, 1);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1716,20 +2035,32 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
+ // For the second caret.
+ Array args2;
+ args2.push_back(2);
+ args2.push_back(2);
+ lines_edited_args.push_front(args2);
+
// With selection should be a normal delete.
SEND_GUI_ACTION(text_edit, "ui_text_delete_word");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " ffi some test text.\n");
+ CHECK(text_edit->get_text() == " ffi some test text.\n\n ffi some test text.\n");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
// With selection should be a normal delete.
- ((Array)lines_edited_args[0])[0] = 1;
+ ((Array)lines_edited_args[0])[0] = 3;
+ ((Array)lines_edited_args[1])[0] = 1;
text_edit->set_caret_column(text_edit->get_line(0).length());
+ text_edit->set_caret_column(text_edit->get_line(2).length(), false, 1);
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1739,16 +2070,23 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SEND_GUI_ACTION(text_edit, "ui_text_delete_word");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " ffi some test text.");
+ CHECK(text_edit->get_text() == " ffi some test text.\n ffi some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == text_edit->get_line(0).length());
CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK_FALSE("caret_changed");
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == text_edit->get_line(1).length());
+ CHECK_FALSE(text_edit->has_selection(0));
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- ((Array)lines_edited_args[0])[0] = 0;
+ ((Array)lines_edited_args[1])[0] = 0;
+ ((Array)lines_edited_args[0])[0] = 1;
+ ((Array)lines_edited_args[0])[1] = 1;
text_edit->set_caret_column(0);
+ text_edit->set_caret_column(0, false, 1);
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1759,10 +2097,14 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_editable(false);
SEND_GUI_ACTION(text_edit, "ui_text_delete_word");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " ffi some test text.");
+ CHECK(text_edit->get_text() == " ffi some test text.\n ffi some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
@@ -1770,10 +2112,14 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SEND_GUI_ACTION(text_edit, "ui_text_delete_word");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " some test text.");
+ CHECK(text_edit->get_text() == " some test text.\n some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
@@ -1783,10 +2129,15 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_caret_mid_grapheme_enabled(true);
CHECK(text_edit->is_caret_mid_grapheme_enabled());
- text_edit->set_text("this ffi some test text.\n");
+ text_edit->set_text("this ffi some test text.\nthis ffi some test text.");
text_edit->select(0, 0, 0, 4);
text_edit->set_caret_line(0);
text_edit->set_caret_column(4);
+
+ text_edit->add_caret(1, 4);
+ text_edit->select(1, 0, 1, 4, 1);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1794,19 +2145,31 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
+ // For the second caret.
+ Array args2;
+ args2.push_back(1);
+ args2.push_back(1);
+ lines_edited_args.push_front(args2);
+
// With selection should be a normal delete.
SEND_GUI_ACTION(text_edit, "ui_text_delete");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " ffi some test text.\n");
+ CHECK(text_edit->get_text() == " ffi some test text.\n ffi some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
// With selection should be a normal delete.
+ lines_edited_args.remove_at(0);
((Array)lines_edited_args[0])[0] = 1;
+ text_edit->set_caret_column(text_edit->get_line(1).length(), false, 1);
text_edit->set_caret_column(text_edit->get_line(0).length());
MessageQueue::get_singleton()->flush();
@@ -1817,16 +2180,25 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SEND_GUI_ACTION(text_edit, "ui_text_delete");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " ffi some test text.");
+ CHECK(text_edit->get_text() == " ffi some test text. ffi some test text.");
CHECK(text_edit->get_caret_line() == 0);
- CHECK(text_edit->get_caret_column() == text_edit->get_line(0).length());
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK_FALSE("caret_changed");
+ CHECK(text_edit->get_caret_column() == 20);
+ CHECK_FALSE(text_edit->has_selection(0));
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
- ((Array)lines_edited_args[0])[0] = 0;
+ // Caret should be removed due to column preservation.
+ CHECK(text_edit->get_caret_count() == 1);
+
+ // Lets add it back.
text_edit->set_caret_column(0);
+ text_edit->add_caret(0, 20);
+
+ ((Array)lines_edited_args[0])[0] = 0;
+ lines_edited_args.push_back(args2);
+ ((Array)lines_edited_args[1])[0] = 0;
+ ((Array)lines_edited_args[1])[1] = 0;
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1837,43 +2209,59 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_editable(false);
SEND_GUI_ACTION(text_edit, "ui_text_delete");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " ffi some test text.");
+ CHECK(text_edit->get_text() == " ffi some test text. ffi some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 0);
+ CHECK(text_edit->get_caret_column(1) == 20);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
text_edit->set_editable(true);
+ text_edit->start_action(TextEdit::EditAction::ACTION_NONE);
+
SEND_GUI_ACTION(text_edit, "ui_text_delete");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "ffi some test text.");
+ CHECK(text_edit->get_text() == "ffi some test text.ffi some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK_FALSE("caret_changed");
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 0);
+ CHECK(text_edit->get_caret_column(1) == 19);
+ CHECK_FALSE(text_edit->has_selection(0));
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ text_edit->start_action(TextEdit::EditAction::ACTION_NONE);
+
SEND_GUI_ACTION(text_edit, "ui_text_delete");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "fi some test text.");
+ CHECK(text_edit->get_text() == "fi some test text.fi some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK_FALSE("caret_changed");
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 0);
+ CHECK(text_edit->get_caret_column(1) == 18);
+ CHECK_FALSE(text_edit->has_selection(1));
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
text_edit->set_caret_mid_grapheme_enabled(false);
CHECK_FALSE(text_edit->is_caret_mid_grapheme_enabled());
+ text_edit->start_action(TextEdit::EditAction::ACTION_NONE);
+
text_edit->undo();
- text_edit->set_caret_line(0);
- text_edit->set_caret_column(0);
MessageQueue::get_singleton()->flush();
- CHECK(text_edit->get_text() == "ffi some test text.");
+ CHECK(text_edit->get_text() == "ffi some test text.ffi some test text.");
SIGNAL_DISCARD("text_set");
SIGNAL_DISCARD("text_changed");
@@ -1882,19 +2270,26 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SEND_GUI_ACTION(text_edit, "ui_text_delete");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == " some test text.");
+ CHECK(text_edit->get_text() == " some test text. some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
- SIGNAL_CHECK_FALSE("caret_changed");
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 0);
+ CHECK(text_edit->get_caret_column(1) == 16);
+ CHECK_FALSE(text_edit->has_selection(1));
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
}
SUBCASE("[TextEdit] ui_text_caret_word_left") {
- text_edit->set_text("\nthis is some test text.");
+ text_edit->set_text("\nthis is some test text.\nthis is some test text.");
text_edit->set_caret_line(1);
text_edit->set_caret_column(7);
+
+ text_edit->add_caret(2, 7);
+ CHECK(text_edit->get_caret_count() == 2);
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1902,47 +2297,67 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
+ // Shift should select.
#ifdef MACOS_ENABLED
SEND_GUI_KEY_EVENT(text_edit, Key::LEFT | KeyModifierMask::ALT | KeyModifierMask::SHIFT);
#else
SEND_GUI_KEY_EVENT(text_edit, Key::LEFT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
#endif
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nthis is some test text.");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 5);
- CHECK(text_edit->get_selected_text() == "is");
- CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text(0) == "is");
+ CHECK(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 5);
+ CHECK(text_edit->get_selected_text(1) == "is");
+ CHECK(text_edit->has_selection(1));
+
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // Should still move caret with selection.
SEND_GUI_ACTION(text_edit, "ui_text_caret_word_left");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nthis is some test text.");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
+
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // Normal word left.
SEND_GUI_ACTION(text_edit, "ui_text_caret_word_left");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nthis is some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 23);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
}
SUBCASE("[TextEdit] ui_text_caret_left") {
- text_edit->set_text("\nthis is some test text.");
+ text_edit->set_text("\nthis is some test text.\nthis is some test text.");
text_edit->set_caret_line(1);
text_edit->set_caret_column(7);
text_edit->select(1, 2, 1, 7);
+
+ text_edit->add_caret(2, 7);
+ text_edit->select(2, 2, 2, 7, 1);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -1950,62 +2365,91 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
+ // Normal left should deselect and place at selection start.
SEND_GUI_ACTION(text_edit, "ui_text_caret_left");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nthis is some test text.");
+
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 2);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 2);
+ CHECK_FALSE(text_edit->has_selection(1));
+
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // With shift should select.
SEND_GUI_KEY_EVENT(text_edit, Key::LEFT | KeyModifierMask::SHIFT);
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nthis is some test text.");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 1);
- CHECK(text_edit->get_selected_text() == "h");
- CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text(0) == "h");
+ CHECK(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 1);
+ CHECK(text_edit->get_selected_text(1) == "h");
+ CHECK(text_edit->has_selection(1));
+
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // All ready at select left, should only deselect.
SEND_GUI_ACTION(text_edit, "ui_text_caret_left");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nthis is some test text.");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 1);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 1);
+ CHECK_FALSE(text_edit->has_selection(1));
+
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // Normal left.
SEND_GUI_ACTION(text_edit, "ui_text_caret_left");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nthis is some test text.");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 0);
CHECK_FALSE(text_edit->has_selection());
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // Left at col 0 should go up a line.
SEND_GUI_ACTION(text_edit, "ui_text_caret_left");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "\nthis is some test text.");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 23);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
}
SUBCASE("[TextEdit] ui_text_caret_word_right") {
- text_edit->set_text("this is some test text\n");
+ text_edit->set_text("this is some test text\n\nthis is some test text\n");
text_edit->set_caret_line(0);
text_edit->set_caret_column(13);
+
+ text_edit->add_caret(2, 13);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -2013,47 +2457,67 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
+ // Shift should select.
#ifdef MACOS_ENABLED
SEND_GUI_KEY_EVENT(text_edit, Key::RIGHT | KeyModifierMask::ALT | KeyModifierMask::SHIFT);
#else
SEND_GUI_KEY_EVENT(text_edit, Key::RIGHT | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT);
#endif
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some test text\n");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 17);
- CHECK(text_edit->get_selected_text() == "test");
- CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text(0) == "test");
+ CHECK(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 17);
+ CHECK(text_edit->get_selected_text(1) == "test");
+ CHECK(text_edit->has_selection(1));
+
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // Should still move caret with selection.
SEND_GUI_ACTION(text_edit, "ui_text_caret_word_right");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some test text\n");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 22);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 22);
+ CHECK_FALSE(text_edit->has_selection(1));
+
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // Normal word right.
SEND_GUI_ACTION(text_edit, "ui_text_caret_word_right");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some test text\n");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 3);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
}
SUBCASE("[TextEdit] ui_text_caret_right") {
- text_edit->set_text("this is some test text\n");
+ text_edit->set_text("this is some test text\n\nthis is some test text\n");
text_edit->set_caret_line(0);
text_edit->set_caret_column(16);
text_edit->select(0, 16, 0, 20);
+
+ text_edit->add_caret(2, 16);
+ text_edit->select(2, 16, 2, 20, 1);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
SIGNAL_DISCARD("text_set");
@@ -2061,53 +2525,76 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
+ // Normal right should deselect and place at selection start.
SEND_GUI_ACTION(text_edit, "ui_text_caret_right");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some test text\n");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 20);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 20);
+ CHECK_FALSE(text_edit->has_selection(1));
+
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // With shift should select.
SEND_GUI_KEY_EVENT(text_edit, Key::RIGHT | KeyModifierMask::SHIFT);
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some test text\n");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 21);
- CHECK(text_edit->get_selected_text() == "x");
- CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text(0) == "x");
+ CHECK(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 21);
+ CHECK(text_edit->get_selected_text(1) == "x");
+ CHECK(text_edit->has_selection(1));
+
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // All ready at select right, should only deselect.
SEND_GUI_ACTION(text_edit, "ui_text_caret_right");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some test text\n");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 21);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 21);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // Normal right.
SEND_GUI_ACTION(text_edit, "ui_text_caret_right");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some test text\n");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 22);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 22);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // Right at end col should go down a line.
SEND_GUI_ACTION(text_edit, "ui_text_caret_right");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some test text\n");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 3);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
@@ -2117,9 +2604,13 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
text_edit->set_size(Size2(110, 100));
- text_edit->set_text("this is some\nother test\nlines\ngo here");
- text_edit->set_caret_line(4);
+ text_edit->set_text("this is some\nother test\nlines\ngo here\nthis is some\nother test\nlines\ngo here");
+ text_edit->set_caret_line(3);
text_edit->set_caret_column(7);
+
+ text_edit->add_caret(7, 7);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
CHECK(text_edit->is_line_wrapped(0));
@@ -2128,44 +2619,61 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
+ // Select + up should select everything to the left on that line.
SEND_GUI_KEY_EVENT(text_edit, Key::UP | KeyModifierMask::SHIFT);
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some\nother test\nlines\ngo here");
CHECK(text_edit->get_caret_line() == 2);
CHECK(text_edit->get_caret_column() == 5);
- CHECK(text_edit->get_selected_text() == "\ngo here");
- CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text(0) == "\ngo here");
+ CHECK(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 6);
+ CHECK(text_edit->get_caret_column(1) == 5);
+ CHECK(text_edit->get_selected_text(1) == "\ngo here");
+ CHECK(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // Should deselect and move up.
SEND_GUI_ACTION(text_edit, "ui_text_caret_up");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some\nother test\nlines\ngo here");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 8);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 5);
+ CHECK(text_edit->get_caret_column(1) == 8);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // Normal up over wrapped line.
SEND_GUI_ACTION(text_edit, "ui_text_caret_up");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some\nother test\nlines\ngo here");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 12);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 4);
+ CHECK(text_edit->get_caret_column(1) == 12);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
text_edit->set_caret_column(12, false);
+ // Normal up over wrapped line to line 0.
SEND_GUI_ACTION(text_edit, "ui_text_caret_up");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "this is some\nother test\nlines\ngo here");
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 7);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 4);
+ CHECK(text_edit->get_caret_column(1) == 7);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
@@ -2175,9 +2683,13 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
text_edit->set_size(Size2(110, 100));
- text_edit->set_text("go here\nlines\nother test\nthis is some");
+ text_edit->set_text("go here\nlines\nother test\nthis is some\ngo here\nlines\nother test\nthis is some");
text_edit->set_caret_line(0);
text_edit->set_caret_column(7);
+
+ text_edit->add_caret(4, 7);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
CHECK(text_edit->is_line_wrapped(3));
@@ -2186,44 +2698,61 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
+ // Select + down should select everything to the right on that line.
SEND_GUI_KEY_EVENT(text_edit, Key::DOWN | KeyModifierMask::SHIFT);
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "go here\nlines\nother test\nthis is some");
CHECK(text_edit->get_caret_line() == 1);
CHECK(text_edit->get_caret_column() == 5);
- CHECK(text_edit->get_selected_text() == "\nlines");
- CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text(0) == "\nlines");
+ CHECK(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 5);
+ CHECK(text_edit->get_caret_column(1) == 5);
+ CHECK(text_edit->get_selected_text(1) == "\nlines");
+ CHECK(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // Should deselect and move down.
SEND_GUI_ACTION(text_edit, "ui_text_caret_down");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "go here\nlines\nother test\nthis is some");
CHECK(text_edit->get_caret_line() == 2);
CHECK(text_edit->get_caret_column() == 8);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 6);
+ CHECK(text_edit->get_caret_column(1) == 8);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ // Normal down over wrapped line.
SEND_GUI_ACTION(text_edit, "ui_text_caret_down");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "go here\nlines\nother test\nthis is some");
CHECK(text_edit->get_caret_line() == 3);
CHECK(text_edit->get_caret_column() == 7);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 7);
+ CHECK(text_edit->get_caret_column(1) == 7);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
text_edit->set_caret_column(7, false);
+ // Normal down over wrapped line to last wrapped line.
SEND_GUI_ACTION(text_edit, "ui_text_caret_down");
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "go here\nlines\nother test\nthis is some");
CHECK(text_edit->get_caret_line() == 3);
CHECK(text_edit->get_caret_column() == 12);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 7);
+ CHECK(text_edit->get_caret_column(1) == 12);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
@@ -2236,6 +2765,10 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_text("this is some\nother test\nlines\ngo here");
text_edit->set_caret_line(4);
text_edit->set_caret_column(7);
+
+ text_edit->add_caret(3, 2);
+ CHECK(text_edit->get_caret_count() == 2);
+
MessageQueue::get_singleton()->flush();
CHECK(text_edit->is_line_wrapped(0));
@@ -2258,6 +2791,7 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ CHECK(text_edit->get_caret_count() == 1);
SEND_GUI_ACTION(text_edit, "ui_text_caret_document_start");
CHECK(text_edit->get_viewport()->is_input_handled());
@@ -2277,6 +2811,9 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_text("go here\nlines\nother test\nthis is some");
text_edit->set_caret_line(0);
text_edit->set_caret_column(0);
+
+ text_edit->add_caret(1, 0);
+ CHECK(text_edit->get_caret_count() == 2);
MessageQueue::get_singleton()->flush();
CHECK(text_edit->is_line_wrapped(3));
@@ -2299,6 +2836,7 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
+ CHECK(text_edit->get_caret_count() == 1);
SEND_GUI_ACTION(text_edit, "ui_text_caret_document_end");
CHECK(text_edit->get_viewport()->is_input_handled());
@@ -2315,9 +2853,12 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
text_edit->set_size(Size2(110, 100));
- text_edit->set_text(" this is some");
+ text_edit->set_text(" this is some\n this is some");
text_edit->set_caret_line(0);
text_edit->set_caret_column(text_edit->get_line(0).length());
+
+ text_edit->add_caret(1, text_edit->get_line(1).length());
+ CHECK(text_edit->get_caret_count() == 2);
MessageQueue::get_singleton()->flush();
CHECK(text_edit->is_line_wrapped(0));
@@ -2334,8 +2875,13 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
CHECK(text_edit->get_viewport()->is_input_handled());
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 10);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == "some");
+ CHECK(text_edit->has_selection(0));
+ CHECK(text_edit->get_selected_text(0) == "some");
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 10);
+ CHECK(text_edit->has_selection(1));
+ CHECK(text_edit->get_selected_text(1) == "some");
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
@@ -2344,7 +2890,11 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
CHECK(text_edit->get_viewport()->is_input_handled());
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 2);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 2);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
@@ -2353,7 +2903,11 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
CHECK(text_edit->get_viewport()->is_input_handled());
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 0);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 0);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
@@ -2362,7 +2916,11 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
CHECK(text_edit->get_viewport()->is_input_handled());
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 2);
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 2);
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
@@ -2372,9 +2930,12 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
text_edit->set_size(Size2(110, 100));
- text_edit->set_text(" this is some");
+ text_edit->set_text(" this is some\n this is some");
text_edit->set_caret_line(0);
text_edit->set_caret_column(0);
+
+ text_edit->add_caret(1, 0);
+ CHECK(text_edit->get_caret_count() == 2);
MessageQueue::get_singleton()->flush();
CHECK(text_edit->is_line_wrapped(0));
@@ -2391,8 +2952,13 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
CHECK(text_edit->get_viewport()->is_input_handled());
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == 9);
- CHECK(text_edit->has_selection());
- CHECK(text_edit->get_selected_text() == " this is");
+ CHECK(text_edit->has_selection(0));
+ CHECK(text_edit->get_selected_text(0) == " this is");
+
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == 9);
+ CHECK(text_edit->has_selection(1));
+ CHECK(text_edit->get_selected_text(1) == " this is");
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
@@ -2401,13 +2967,24 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
CHECK(text_edit->get_viewport()->is_input_handled());
CHECK(text_edit->get_caret_line() == 0);
CHECK(text_edit->get_caret_column() == text_edit->get_line(0).length());
- CHECK_FALSE(text_edit->has_selection());
+ CHECK_FALSE(text_edit->has_selection(0));
+
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_caret_line(1) == 1);
+ CHECK(text_edit->get_caret_column(1) == text_edit->get_line(1).length());
+ CHECK_FALSE(text_edit->has_selection(1));
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
}
SUBCASE("[TextEdit] unicode") {
+ text_edit->set_text("\n");
+ text_edit->set_caret_line(0);
+ text_edit->set_caret_column(0);
+
+ text_edit->add_caret(1, 0);
+ CHECK(text_edit->get_caret_count() == 2);
text_edit->insert_text_at_caret("a");
MessageQueue::get_singleton()->flush();
@@ -2416,10 +2993,17 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_DISCARD("lines_edited_from");
SIGNAL_DISCARD("caret_changed");
+ // For the second caret.
+ Array args2;
+ args2.push_back(1);
+ args2.push_back(1);
+ lines_edited_args.push_front(args2);
+
SEND_GUI_KEY_EVENT(text_edit, Key::A);
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "aA");
+ CHECK(text_edit->get_text() == "aA\naA");
CHECK(text_edit->get_caret_column() == 2);
+ CHECK(text_edit->get_caret_column(1) == 2);
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
@@ -2427,20 +3011,24 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
text_edit->set_editable(false);
SEND_GUI_KEY_EVENT(text_edit, Key::A);
CHECK_FALSE(text_edit->get_viewport()->is_input_handled()); // Should this be handled?
- CHECK(text_edit->get_text() == "aA");
+ CHECK(text_edit->get_text() == "aA\naA");
CHECK(text_edit->get_caret_column() == 2);
+ CHECK(text_edit->get_caret_column(1) == 2);
SIGNAL_CHECK_FALSE("caret_changed");
SIGNAL_CHECK_FALSE("text_changed");
SIGNAL_CHECK_FALSE("lines_edited_from");
text_edit->set_editable(true);
- lines_edited_args.push_back(lines_edited_args[0].duplicate());
+ lines_edited_args.push_back(lines_edited_args[1].duplicate());
+ lines_edited_args.push_front(args2.duplicate());
text_edit->select(0, 0, 0, 1);
+ text_edit->select(1, 0, 1, 1, 1);
SEND_GUI_KEY_EVENT(text_edit, Key::B);
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "BA");
+ CHECK(text_edit->get_text() == "BA\nBA");
CHECK(text_edit->get_caret_column() == 1);
+ CHECK(text_edit->get_caret_column(1) == 1);
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
@@ -2450,22 +3038,36 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SEND_GUI_KEY_EVENT(text_edit, Key::B);
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "BB");
+ CHECK(text_edit->get_text() == "BB\nBB");
CHECK(text_edit->get_caret_column() == 2);
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
text_edit->select(0, 0, 0, 1);
+ text_edit->select(1, 0, 1, 1, 1);
SEND_GUI_KEY_EVENT(text_edit, Key::A);
CHECK(text_edit->get_viewport()->is_input_handled());
- CHECK(text_edit->get_text() == "AB");
+ CHECK(text_edit->get_text() == "AB\nAB");
CHECK(text_edit->get_caret_column() == 1);
+ CHECK(text_edit->get_caret_column(1) == 1);
SIGNAL_CHECK("caret_changed", empty_signal_args);
SIGNAL_CHECK("text_changed", empty_signal_args);
SIGNAL_CHECK("lines_edited_from", lines_edited_args);
text_edit->set_overtype_mode_enabled(false);
CHECK_FALSE(text_edit->is_overtype_mode_enabled());
+
+ lines_edited_args.remove_at(0);
+ lines_edited_args.remove_at(1);
+
+ SEND_GUI_KEY_EVENT(text_edit, Key::TAB);
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_text() == "A\tB\nA\tB");
+ CHECK(text_edit->get_caret_column() == 2);
+ CHECK(text_edit->get_caret_column(1) == 2);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
}
SIGNAL_UNWATCH(text_edit, "text_set");
@@ -2558,7 +3160,7 @@ TEST_CASE("[SceneTree][TextEdit] versioning") {
CHECK(text_edit->has_redo());
text_edit->redo();
- CHECK(text_edit->get_line(0) == "test nested ops");
+ CHECK(text_edit->get_line(0) == "test ops nested");
CHECK(text_edit->get_version() == 3);
CHECK(text_edit->get_saved_version() == 3);
CHECK(text_edit->has_undo());
@@ -2779,6 +3381,136 @@ TEST_CASE("[SceneTree][TextEdit] caret") {
memdelete(text_edit);
}
+TEST_CASE("[SceneTree][TextEdit] multicaret") {
+ TextEdit *text_edit = memnew(TextEdit);
+ SceneTree::get_singleton()->get_root()->add_child(text_edit);
+ text_edit->set_multiple_carets_enabled(true);
+
+ Array empty_signal_args;
+ empty_signal_args.push_back(Array());
+
+ SIGNAL_WATCH(text_edit, "caret_changed");
+
+ text_edit->set_text("this is\nsome test\ntext");
+ text_edit->set_caret_line(0);
+ text_edit->set_caret_column(0);
+ MessageQueue::get_singleton()->flush();
+ SIGNAL_DISCARD("caret_changed");
+
+ SUBCASE("[TextEdit] add remove caret") {
+ // Overlapping
+ CHECK(text_edit->add_caret(0, 0) == -1);
+ MessageQueue::get_singleton()->flush();
+ SIGNAL_CHECK_FALSE("caret_changed");
+
+ // Selection
+ text_edit->select(0, 0, 2, 4);
+ CHECK(text_edit->add_caret(0, 0) == -1);
+ CHECK(text_edit->add_caret(2, 4) == -1);
+ CHECK(text_edit->add_caret(1, 2) == -1);
+
+ // Out of bounds
+ CHECK(text_edit->add_caret(-1, 0) == -1);
+ CHECK(text_edit->add_caret(5, 0) == -1);
+ CHECK(text_edit->add_caret(0, 100) == -1);
+
+ MessageQueue::get_singleton()->flush();
+ SIGNAL_CHECK_FALSE("caret_changed");
+
+ CHECK(text_edit->get_caret_count() == 1);
+
+ text_edit->deselect();
+ SIGNAL_CHECK_FALSE("caret_changed");
+
+ CHECK(text_edit->add_caret(0, 1) == 1);
+ MessageQueue::get_singleton()->flush();
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ CHECK(text_edit->get_caret_count() == 2);
+
+ CHECK(text_edit->get_caret_line(0) == 0);
+ CHECK(text_edit->get_caret_column(0) == 0);
+
+ CHECK(text_edit->get_caret_line(1) == 0);
+ CHECK(text_edit->get_caret_column(1) == 1);
+
+ ERR_PRINT_OFF;
+ text_edit->remove_caret(-1);
+ text_edit->remove_caret(5);
+ ERR_PRINT_ON;
+ CHECK(text_edit->get_caret_count() == 2);
+ SIGNAL_CHECK_FALSE("caret_changed");
+
+ text_edit->remove_caret(0);
+ SIGNAL_CHECK_FALSE("caret_changed");
+ CHECK(text_edit->get_caret_count() == 1);
+ CHECK(text_edit->get_caret_line(0) == 0);
+ CHECK(text_edit->get_caret_column(0) == 1);
+
+ ERR_PRINT_OFF;
+ text_edit->remove_caret(0);
+ CHECK(text_edit->get_caret_count() == 1);
+ ERR_PRINT_ON;
+ }
+
+ SUBCASE("[TextEdit] caret index edit order") {
+ Vector<int> caret_index_get_order;
+ caret_index_get_order.push_back(1);
+ caret_index_get_order.push_back(0);
+
+ CHECK(text_edit->add_caret(1, 0));
+ CHECK(text_edit->get_caret_count() == 2);
+ CHECK(text_edit->get_caret_index_edit_order() == caret_index_get_order);
+
+ text_edit->remove_secondary_carets();
+ text_edit->set_caret_line(1);
+ CHECK(text_edit->add_caret(0, 0));
+ CHECK(text_edit->get_caret_count() == 2);
+
+ caret_index_get_order.write[0] = 0;
+ caret_index_get_order.write[1] = 1;
+ CHECK(text_edit->get_caret_index_edit_order() == caret_index_get_order);
+ }
+
+ SUBCASE("[TextEdit] add caret at carets") {
+ text_edit->remove_secondary_carets();
+ text_edit->set_caret_line(1);
+ text_edit->set_caret_column(9);
+
+ text_edit->add_caret_at_carets(true);
+ CHECK(text_edit->get_caret_count() == 2);
+ CHECK(text_edit->get_caret_line(1) == 2);
+ CHECK(text_edit->get_caret_column(1) == 4);
+
+ text_edit->add_caret_at_carets(true);
+ CHECK(text_edit->get_caret_count() == 2);
+
+ text_edit->add_caret_at_carets(false);
+ CHECK(text_edit->get_caret_count() == 3);
+ CHECK(text_edit->get_caret_line(2) == 0);
+ CHECK(text_edit->get_caret_column(2) == 7);
+
+ text_edit->remove_secondary_carets();
+ text_edit->set_caret_line(0);
+ text_edit->set_caret_column(4);
+ text_edit->select(0, 0, 0, 4);
+ text_edit->add_caret_at_carets(true);
+ CHECK(text_edit->get_caret_count() == 2);
+ CHECK(text_edit->get_selection_from_line(1) == 1);
+ CHECK(text_edit->get_selection_to_line(1) == 1);
+ CHECK(text_edit->get_selection_from_column(1) == 0);
+ CHECK(text_edit->get_selection_to_column(1) == 3);
+
+ text_edit->add_caret_at_carets(true);
+ CHECK(text_edit->get_caret_count() == 3);
+ CHECK(text_edit->get_selection_from_line(2) == 2);
+ CHECK(text_edit->get_selection_to_line(2) == 2);
+ CHECK(text_edit->get_selection_from_column(2) == 0);
+ CHECK(text_edit->get_selection_to_column(2) == 4);
+ }
+
+ memdelete(text_edit);
+}
+
TEST_CASE("[SceneTree][TextEdit] line wrapping") {
TextEdit *text_edit = memnew(TextEdit);
SceneTree::get_singleton()->get_root()->add_child(text_edit);
@@ -3291,6 +4023,32 @@ TEST_CASE("[SceneTree][TextEdit] viewport") {
CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
CHECK(text_edit->get_caret_wrap_index() == 0);
+ // Typing and undo / redo should adjust viewport
+ text_edit->set_caret_line(0);
+ text_edit->set_caret_column(0);
+ text_edit->set_line_as_first_visible(5);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 5);
+
+ SEND_GUI_KEY_EVENT(text_edit, Key::A);
+ CHECK(text_edit->get_first_visible_line() == 0);
+
+ text_edit->set_line_as_first_visible(5);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 5);
+
+ text_edit->undo();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 0);
+
+ text_edit->set_line_as_first_visible(5);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 5);
+
+ text_edit->redo();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 0);
+
memdelete(text_edit);
}
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 4c861eacba..d58c19ac32 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -47,6 +47,7 @@
#include "tests/core/math/test_expression.h"
#include "tests/core/math/test_geometry_2d.h"
#include "tests/core/math/test_geometry_3d.h"
+#include "tests/core/math/test_math_funcs.h"
#include "tests/core/math/test_plane.h"
#include "tests/core/math/test_quaternion.h"
#include "tests/core/math/test_random_number_generator.h"
@@ -84,12 +85,15 @@
#include "tests/core/variant/test_dictionary.h"
#include "tests/core/variant/test_variant.h"
#include "tests/scene/test_animation.h"
+#include "tests/scene/test_arraymesh.h"
#include "tests/scene/test_audio_stream_wav.h"
#include "tests/scene/test_bit_map.h"
#include "tests/scene/test_code_edit.h"
#include "tests/scene/test_curve.h"
#include "tests/scene/test_gradient.h"
+#include "tests/scene/test_path_2d.h"
#include "tests/scene/test_path_3d.h"
+#include "tests/scene/test_primitives.h"
#include "tests/scene/test_sprite_frames.h"
#include "tests/scene/test_text_edit.h"
#include "tests/scene/test_theme.h"
@@ -188,18 +192,15 @@ struct GodotTestCaseListener : public doctest::IReporter {
String name = String(p_in.m_name);
if (name.find("[SceneTree]") != -1) {
- GLOBAL_DEF("memory/limits/multithreaded_server/rid_pool_prealloc", 60);
memnew(MessageQueue);
- GLOBAL_DEF("internationalization/rendering/force_right_to_left_layout_direction", false);
-
memnew(Input);
Error err = OK;
OS::get_singleton()->set_has_server_feature_callback(nullptr);
for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
if (String("headless") == DisplayServer::get_create_function_name(i)) {
- DisplayServer::create(i, "", DisplayServer::WindowMode::WINDOW_MODE_MINIMIZED, DisplayServer::VSyncMode::VSYNC_ENABLED, 0, Vector2i(0, 0), err);
+ DisplayServer::create(i, "", DisplayServer::WindowMode::WINDOW_MODE_MINIMIZED, DisplayServer::VSyncMode::VSYNC_ENABLED, 0, nullptr, Vector2i(0, 0), err);
break;
}
}
diff --git a/tests/test_validate_testing.h b/tests/test_validate_testing.h
index 1471a952cd..41185a7d16 100644
--- a/tests/test_validate_testing.h
+++ b/tests/test_validate_testing.h
@@ -86,7 +86,7 @@ TEST_SUITE("Validate tests") {
Plane plane(Vector3(1, 1, 1), 1.0);
INFO(plane);
- Quaternion quat(Vector3(0.5, 1.0, 2.0));
+ Quaternion quat = Quaternion::from_euler(Vector3(0.5, 1.0, 2.0));
INFO(quat);
AABB aabb(Vector3(), Vector3(100, 100, 100));