diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/io/test_image.h | 23 | ||||
-rw-r--r-- | tests/core/math/test_basis.h | 94 | ||||
-rw-r--r-- | tests/core/string/test_string.h | 81 | ||||
-rw-r--r-- | tests/core/variant/test_variant.h | 60 | ||||
-rw-r--r-- | tests/scene/test_primitives.h | 2 | ||||
-rw-r--r-- | tests/scene/test_text_edit.h | 2 | ||||
-rw-r--r-- | tests/scene/test_viewport.h | 644 | ||||
-rw-r--r-- | tests/servers/test_navigation_server_3d.h | 99 |
8 files changed, 959 insertions, 46 deletions
diff --git a/tests/core/io/test_image.h b/tests/core/io/test_image.h index 07c7c04e36..945a7e1ba3 100644 --- a/tests/core/io/test_image.h +++ b/tests/core/io/test_image.h @@ -403,6 +403,29 @@ TEST_CASE("[Image] Custom mipmaps") { } } +TEST_CASE("[Image] Convert image") { + for (int format = Image::FORMAT_RF; format < Image::FORMAT_RGBE9995; format++) { + for (int new_format = Image::FORMAT_RF; new_format < Image::FORMAT_RGBE9995; new_format++) { + Ref<Image> image = memnew(Image(4, 4, false, (Image::Format)format)); + image->convert((Image::Format)new_format); + String format_string = Image::format_names[(Image::Format)format]; + String new_format_string = Image::format_names[(Image::Format)new_format]; + format_string = "Error converting from " + format_string + " to " + new_format_string + "."; + CHECK_MESSAGE(image->get_format() == new_format, format_string); + } + } + + Ref<Image> image = memnew(Image(4, 4, false, Image::FORMAT_RGBA8)); + PackedByteArray image_data = image->get_data(); + image->convert((Image::Format)-1); + CHECK_MESSAGE(image->get_data() == image_data, "Image conversion to invalid type (-1) should not alter image."); + + Ref<Image> image2 = memnew(Image(4, 4, false, Image::FORMAT_RGBA8)); + image_data = image2->get_data(); + image2->convert((Image::Format)(Image::FORMAT_MAX + 1)); + CHECK_MESSAGE(image2->get_data() == image_data, "Image conversion to invalid type (Image::FORMAT_MAX + 1) should not alter image."); +} + } // namespace TestImage #endif // TEST_IMAGE_H diff --git a/tests/core/math/test_basis.h b/tests/core/math/test_basis.h index fcac9a6231..a9bc2e9b99 100644 --- a/tests/core/math/test_basis.h +++ b/tests/core/math/test_basis.h @@ -324,6 +324,100 @@ TEST_CASE("[Basis] Is conformal checks") { CHECK_FALSE_MESSAGE( Basis(Vector3(Math_SQRT12, Math_SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_conformal(), "Basis with the X axis skewed 45 degrees should not be conformal."); + + CHECK_MESSAGE( + Basis(0, 0, 0, 0, 0, 0, 0, 0, 0).is_conformal(), + "Edge case: Basis with all zeroes should return true for is_conformal (because a 0 scale is uniform)."); +} + +TEST_CASE("[Basis] Is orthogonal checks") { + CHECK_MESSAGE( + Basis().is_orthogonal(), + "Identity Basis should be orthogonal."); + + CHECK_MESSAGE( + Basis::from_euler(Vector3(1.2, 3.4, 5.6)).is_orthogonal(), + "Basis with only rotation should be orthogonal."); + + CHECK_MESSAGE( + Basis::from_scale(Vector3(-1, -1, -1)).is_orthogonal(), + "Basis with only a flip should be orthogonal."); + + CHECK_MESSAGE( + Basis::from_scale(Vector3(1.2, 3.4, 5.6)).is_orthogonal(), + "Basis with only scale should be orthogonal."); + + CHECK_MESSAGE( + Basis(Vector3(3, 4, 0), Vector3(4, -3, 0), Vector3(0, 0, 5)).is_orthogonal(), + "Basis with a flip, rotation, and uniform scale should be orthogonal."); + + CHECK_FALSE_MESSAGE( + Basis(Vector3(Math_SQRT12, Math_SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_orthogonal(), + "Basis with the X axis skewed 45 degrees should not be orthogonal."); + + CHECK_MESSAGE( + Basis(0, 0, 0, 0, 0, 0, 0, 0, 0).is_orthogonal(), + "Edge case: Basis with all zeroes should return true for is_orthogonal, since zero vectors are orthogonal to all vectors."); +} + +TEST_CASE("[Basis] Is orthonormal checks") { + CHECK_MESSAGE( + Basis().is_orthonormal(), + "Identity Basis should be orthonormal."); + + CHECK_MESSAGE( + Basis::from_euler(Vector3(1.2, 3.4, 5.6)).is_orthonormal(), + "Basis with only rotation should be orthonormal."); + + CHECK_MESSAGE( + Basis::from_scale(Vector3(-1, -1, -1)).is_orthonormal(), + "Basis with only a flip should be orthonormal."); + + CHECK_FALSE_MESSAGE( + Basis::from_scale(Vector3(1.2, 3.4, 5.6)).is_orthonormal(), + "Basis with only scale should not be orthonormal."); + + CHECK_FALSE_MESSAGE( + Basis(Vector3(3, 4, 0), Vector3(4, -3, 0), Vector3(0, 0, 5)).is_orthonormal(), + "Basis with a flip, rotation, and uniform scale should not be orthonormal."); + + CHECK_FALSE_MESSAGE( + Basis(Vector3(Math_SQRT12, Math_SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_orthonormal(), + "Basis with the X axis skewed 45 degrees should not be orthonormal."); + + CHECK_FALSE_MESSAGE( + Basis(0, 0, 0, 0, 0, 0, 0, 0, 0).is_orthonormal(), + "Edge case: Basis with all zeroes should return false for is_orthonormal, since the vectors do not have a length of 1."); +} + +TEST_CASE("[Basis] Is rotation checks") { + CHECK_MESSAGE( + Basis().is_rotation(), + "Identity Basis should be a rotation (a rotation of zero)."); + + CHECK_MESSAGE( + Basis::from_euler(Vector3(1.2, 3.4, 5.6)).is_rotation(), + "Basis with only rotation should be a rotation."); + + CHECK_FALSE_MESSAGE( + Basis::from_scale(Vector3(-1, -1, -1)).is_rotation(), + "Basis with only a flip should not be a rotation."); + + CHECK_FALSE_MESSAGE( + Basis::from_scale(Vector3(1.2, 3.4, 5.6)).is_rotation(), + "Basis with only scale should not be a rotation."); + + CHECK_FALSE_MESSAGE( + Basis(Vector3(2, 0, 0), Vector3(0, 0.5, 0), Vector3(0, 0, 1)).is_rotation(), + "Basis with a squeeze should not be a rotation."); + + CHECK_FALSE_MESSAGE( + Basis(Vector3(Math_SQRT12, Math_SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_rotation(), + "Basis with the X axis skewed 45 degrees should not be a rotation."); + + CHECK_FALSE_MESSAGE( + Basis(0, 0, 0, 0, 0, 0, 0, 0, 0).is_rotation(), + "Edge case: Basis with all zeroes should return false for is_rotation, because it is not just a rotation (has a scale of 0)."); } } // namespace TestBasis diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h index 02349aedc0..8a11491bb2 100644 --- a/tests/core/string/test_string.h +++ b/tests/core/string/test_string.h @@ -456,30 +456,93 @@ TEST_CASE("[String] Number to string") { } TEST_CASE("[String] String to integer") { - static const char *nums[4] = { "1237461283", "- 22", "0", " - 1123412" }; - static const int num[4] = { 1237461283, -22, 0, -1123412 }; + static const char *nums[14] = { "1237461283", "- 22", "0", " - 1123412", "", "10_000_000", "-1_2_3_4", "10__000", " 1 2 34 ", "-0", "007", "--45", "---46", "-7-2" }; + static const int num[14] = { 1237461283, -22, 0, -1123412, 0, 10000000, -1234, 10000, 1234, 0, 7, 45, -46, -72 }; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 14; i++) { CHECK(String(nums[i]).to_int() == num[i]); } + CHECK(String("0b1011").to_int() == 1011); // Looks like a binary number, but to_int() handles this as a base-10 number, "b" is just ignored. + CHECK(String("0x1012").to_int() == 1012); // Looks like a hexadecimal number, but to_int() handles this as a base-10 number, "x" is just ignored. + + ERR_PRINT_OFF + CHECK(String("999999999999999999999999999999999999999999999999999999999").to_int() == INT64_MAX); // Too large, largest possible is returned. + CHECK(String("-999999999999999999999999999999999999999999999999999999999").to_int() == INT64_MIN); // Too small, smallest possible is returned. + ERR_PRINT_ON } TEST_CASE("[String] Hex to integer") { - static const char *nums[4] = { "0xFFAE", "22", "0", "AADDAD" }; - static const int64_t num[4] = { 0xFFAE, 0x22, 0, 0xAADDAD }; + static const char *nums[12] = { "0xFFAE", "22", "0", "AADDAD", "0x7FFFFFFFFFFFFFFF", "-0xf", "", "000", "000f", "0xaA", "-ff", "-" }; + static const int64_t num[12] = { 0xFFAE, 0x22, 0, 0xAADDAD, 0x7FFFFFFFFFFFFFFF, -0xf, 0, 0, 0xf, 0xaa, -0xff, 0x0 }; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 12; i++) { CHECK(String(nums[i]).hex_to_int() == num[i]); } + + // Invalid hex strings should return 0. + static const char *invalid_nums[15] = { "qwerty", "QWERTY", "0xqwerty", "0x00qwerty", "qwerty00", "0x", "0x__", "__", "x12", "+", " ff", "ff ", "f f", "+ff", "--0x78" }; + + ERR_PRINT_OFF + for (int i = 0; i < 15; i++) { + CHECK(String(invalid_nums[i]).hex_to_int() == 0); + } + + CHECK(String("0xFFFFFFFFFFFFFFFFFFFFFFF").hex_to_int() == INT64_MAX); // Too large, largest possible is returned. + CHECK(String("-0xFFFFFFFFFFFFFFFFFFFFFFF").hex_to_int() == INT64_MIN); // Too small, smallest possible is returned. + ERR_PRINT_ON +} + +TEST_CASE("[String] Bin to integer") { + static const char *nums[10] = { "", "0", "0b0", "0b1", "0b", "1", "0b1010", "-0b11", "-1010", "0b0111111111111111111111111111111111111111111111111111111111111111" }; + static const int64_t num[10] = { 0, 0, 0, 1, 0, 1, 10, -3, -10, 0x7FFFFFFFFFFFFFFF }; + + for (int i = 0; i < 10; i++) { + CHECK(String(nums[i]).bin_to_int() == num[i]); + } + + // Invalid bin strings should return 0. The long "0x11...11" is just too long for a 64 bit int. + static const char *invalid_nums[16] = { "qwerty", "QWERTY", "0bqwerty", "0b00qwerty", "qwerty00", "0x__", "0b__", "__", "b12", "+", "-", "0x12ab", " 11", "11 ", "1 1", "--0b11" }; + + for (int i = 0; i < 16; i++) { + CHECK(String(invalid_nums[i]).bin_to_int() == 0); + } + + ERR_PRINT_OFF + CHECK(String("0b111111111111111111111111111111111111111111111111111111111111111111111111111111111").bin_to_int() == INT64_MAX); // Too large, largest possible is returned. + CHECK(String("-0b111111111111111111111111111111111111111111111111111111111111111111111111111111111").bin_to_int() == INT64_MIN); // Too small, smallest possible is returned. + ERR_PRINT_ON } TEST_CASE("[String] String to float") { - static const char *nums[4] = { "-12348298412.2", "0.05", "2.0002", " -0.0001" }; - static const double num[4] = { -12348298412.2, 0.05, 2.0002, -0.0001 }; + static const char *nums[12] = { "-12348298412.2", "0.05", "2.0002", " -0.0001", "0", "000", "123", "0.0", "000.000", "000.007", "234__", "3..14" }; + static const double num[12] = { -12348298412.2, 0.05, 2.0002, -0.0001, 0.0, 0.0, 123.0, 0.0, 0.0, 0.007, 234.0, 3.0 }; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 12; i++) { CHECK(!(ABS(String(nums[i]).to_float() - num[i]) > 0.00001)); } + + // Invalid float strings should return 0. + static const char *invalid_nums[6] = { "qwerty", "qwerty123", "0xffff", "0b1010", "--3.13", "__345" }; + + for (int i = 0; i < 6; i++) { + CHECK(String(invalid_nums[i]).to_float() == 0); + } + + // Very large exponents. + CHECK(String("1e308").to_float() == 1e308); + CHECK(String("-1e308").to_float() == -1e308); + + // Exponent is so high that value is INFINITY/-INFINITY. + CHECK(String("1e309").to_float() == INFINITY); + CHECK(String("1e511").to_float() == INFINITY); + CHECK(String("-1e309").to_float() == -INFINITY); + CHECK(String("-1e511").to_float() == -INFINITY); + + // Exponent is so high that a warning message is printed. Value is INFINITY/-INFINITY. + ERR_PRINT_OFF + CHECK(String("1e512").to_float() == INFINITY); + CHECK(String("-1e512").to_float() == -INFINITY); + ERR_PRINT_ON } TEST_CASE("[String] Slicing") { diff --git a/tests/core/variant/test_variant.h b/tests/core/variant/test_variant.h index 93ae3b4c43..54ca06c6c4 100644 --- a/tests/core/variant/test_variant.h +++ b/tests/core/variant/test_variant.h @@ -980,45 +980,45 @@ TEST_CASE("[Variant] Assignment To Vec2 from Bool,Int,Float,String,Vec2i,Vec3,Ve CHECK(basis_v.get_type() == Variant::VECTOR2); Variant aabb_v = AABB(); - string_v = "Hello"; - aabb_v = string_v; - CHECK(aabb_v == Variant("Hello")); - string_v = "Hello there"; - aabb_v = string_v; - CHECK(aabb_v.get_type() == Variant::STRING); + vec2_v = Vector2(2.2f, 3.5f); + aabb_v = vec2_v; + CHECK(aabb_v == Variant(Vector2(2.2f, 3.5f))); + vec2_v = Vector2(-5.4f, -7.9f); + aabb_v = vec2_v; + CHECK(aabb_v.get_type() == Variant::VECTOR2); Variant quaternion_v = Quaternion(); - string_v = "Hello"; - quaternion_v = string_v; - CHECK(quaternion_v == Variant("Hello")); - string_v = "Hello there"; - quaternion_v = string_v; - CHECK(quaternion_v.get_type() == Variant::STRING); + vec2_v = Vector2(2.2f, 3.5f); + quaternion_v = vec2_v; + CHECK(quaternion_v == Variant(Vector2(2.2f, 3.5f))); + vec2_v = Vector2(-5.4f, -7.9f); + quaternion_v = vec2_v; + CHECK(quaternion_v.get_type() == Variant::VECTOR2); Variant projection_v = Projection(); - string_v = "Hello"; - projection_v = string_v; - CHECK(projection_v == Variant("Hello")); - string_v = "Hello there"; - projection_v = string_v; - CHECK(projection_v.get_type() == Variant::STRING); + vec2_v = Vector2(2.2f, 3.5f); + projection_v = vec2_v; + CHECK(projection_v == Variant(Vector2(2.2f, 3.5f))); + vec2_v = Vector2(-5.4f, -7.9f); + projection_v = vec2_v; + CHECK(projection_v.get_type() == Variant::VECTOR2); Variant rid_v = RID(); - string_v = "Hello"; - rid_v = string_v; - CHECK(rid_v == Variant("Hello")); - string_v = "Hello there"; - rid_v = string_v; - CHECK(rid_v.get_type() == Variant::STRING); + vec2_v = Vector2(2.2f, 3.5f); + rid_v = vec2_v; + CHECK(rid_v == Variant(Vector2(2.2f, 3.5f))); + vec2_v = Vector2(-5.4f, -7.9f); + rid_v = vec2_v; + CHECK(rid_v.get_type() == Variant::VECTOR2); Object obj_one = Object(); Variant object_v = &obj_one; - string_v = "Hello"; - object_v = string_v; - CHECK(object_v == Variant("Hello")); - string_v = "Hello there"; - object_v = string_v; - CHECK(object_v.get_type() == Variant::STRING); + vec2_v = Vector2(2.2f, 3.5f); + object_v = vec2_v; + CHECK(object_v == Variant(Vector2(2.2f, 3.5f))); + vec2_v = Vector2(-5.4f, -7.9f); + object_v = vec2_v; + CHECK(object_v.get_type() == Variant::VECTOR2); } TEST_CASE("[Variant] Assignment To Vec2i from Bool,Int,Float,String,Vec2,Vec3,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") { diff --git a/tests/scene/test_primitives.h b/tests/scene/test_primitives.h index 9232a3020d..552f722d24 100644 --- a/tests/scene/test_primitives.h +++ b/tests/scene/test_primitives.h @@ -232,7 +232,7 @@ TEST_CASE("[SceneTree][Primitive][Cylinder] Cylinder Primitive") { CHECK(cylinder->get_bottom_radius() > 0); CHECK(cylinder->get_height() > 0); CHECK(cylinder->get_radial_segments() > 0); - CHECK(cylinder->get_rings() > 0); + CHECK(cylinder->get_rings() >= 0); } SUBCASE("[SceneTree][Primitive][Cylinder] Set properties and get them") { diff --git a/tests/scene/test_text_edit.h b/tests/scene/test_text_edit.h index 9c9ade4445..e81578a862 100644 --- a/tests/scene/test_text_edit.h +++ b/tests/scene/test_text_edit.h @@ -4118,7 +4118,7 @@ TEST_CASE("[SceneTree][TextEdit] setter getters") { CHECK_FALSE(text_edit->is_drawing_spaces()); } - SUBCASE("[TextEdit] draw minimao") { + SUBCASE("[TextEdit] draw minimap") { text_edit->set_draw_minimap(true); CHECK(text_edit->is_drawing_minimap()); text_edit->set_draw_minimap(false); diff --git a/tests/scene/test_viewport.h b/tests/scene/test_viewport.h index 0c53668c6d..1afae66ee0 100644 --- a/tests/scene/test_viewport.h +++ b/tests/scene/test_viewport.h @@ -50,17 +50,39 @@ protected: void _notification(int p_what) { switch (p_what) { case NOTIFICATION_MOUSE_ENTER: { + if (mouse_over) { + invalid_order = true; + } mouse_over = true; } break; case NOTIFICATION_MOUSE_EXIT: { + if (!mouse_over) { + invalid_order = true; + } mouse_over = false; } break; + + case NOTIFICATION_MOUSE_ENTER_SELF: { + if (mouse_over_self) { + invalid_order = true; + } + mouse_over_self = true; + } break; + + case NOTIFICATION_MOUSE_EXIT_SELF: { + if (!mouse_over_self) { + invalid_order = true; + } + mouse_over_self = false; + } break; } } public: bool mouse_over = false; + bool mouse_over_self = false; + bool invalid_order = false; }; // `NotificationControlViewport`-derived class that additionally @@ -119,12 +141,15 @@ public: TEST_CASE("[SceneTree][Viewport] Controls and InputEvent handling") { DragStart *node_a = memnew(DragStart); - Control *node_b = memnew(Control); + NotificationControlViewport *node_b = memnew(NotificationControlViewport); Node2D *node_c = memnew(Node2D); DragTarget *node_d = memnew(DragTarget); - Control *node_e = memnew(Control); + NotificationControlViewport *node_e = memnew(NotificationControlViewport); Node *node_f = memnew(Node); - Control *node_g = memnew(Control); + NotificationControlViewport *node_g = memnew(NotificationControlViewport); + NotificationControlViewport *node_h = memnew(NotificationControlViewport); + NotificationControlViewport *node_i = memnew(NotificationControlViewport); + NotificationControlViewport *node_j = memnew(NotificationControlViewport); node_a->set_name(SNAME("NodeA")); node_b->set_name(SNAME("NodeB")); @@ -133,6 +158,9 @@ TEST_CASE("[SceneTree][Viewport] Controls and InputEvent handling") { node_e->set_name(SNAME("NodeE")); node_f->set_name(SNAME("NodeF")); node_g->set_name(SNAME("NodeG")); + node_h->set_name(SNAME("NodeH")); + node_i->set_name(SNAME("NodeI")); + node_j->set_name(SNAME("NodeJ")); node_a->set_position(Point2i(0, 0)); node_b->set_position(Point2i(10, 10)); @@ -140,16 +168,25 @@ TEST_CASE("[SceneTree][Viewport] Controls and InputEvent handling") { node_d->set_position(Point2i(10, 10)); node_e->set_position(Point2i(10, 100)); node_g->set_position(Point2i(10, 100)); + node_h->set_position(Point2i(10, 120)); + node_i->set_position(Point2i(2, 0)); + node_j->set_position(Point2i(2, 0)); node_a->set_size(Point2i(30, 30)); node_b->set_size(Point2i(30, 30)); node_d->set_size(Point2i(30, 30)); node_e->set_size(Point2i(10, 10)); node_g->set_size(Point2i(10, 10)); + node_h->set_size(Point2i(10, 10)); + node_i->set_size(Point2i(10, 10)); + node_j->set_size(Point2i(10, 10)); node_a->set_focus_mode(Control::FOCUS_CLICK); node_b->set_focus_mode(Control::FOCUS_CLICK); node_d->set_focus_mode(Control::FOCUS_CLICK); node_e->set_focus_mode(Control::FOCUS_CLICK); node_g->set_focus_mode(Control::FOCUS_CLICK); + node_h->set_focus_mode(Control::FOCUS_CLICK); + node_i->set_focus_mode(Control::FOCUS_CLICK); + node_j->set_focus_mode(Control::FOCUS_CLICK); Window *root = SceneTree::get_singleton()->get_root(); DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton()); @@ -162,6 +199,9 @@ TEST_CASE("[SceneTree][Viewport] Controls and InputEvent handling") { // - e (Control) // - f (Node) // - g (Control) + // - h (Control) + // - i (Control) + // - j (Control) root->add_child(node_a); root->add_child(node_b); node_b->add_child(node_c); @@ -169,12 +209,17 @@ TEST_CASE("[SceneTree][Viewport] Controls and InputEvent handling") { root->add_child(node_e); node_e->add_child(node_f); node_f->add_child(node_g); + root->add_child(node_h); + node_h->add_child(node_i); + node_i->add_child(node_j); Point2i on_a = Point2i(5, 5); Point2i on_b = Point2i(15, 15); Point2i on_d = Point2i(25, 25); Point2i on_e = Point2i(15, 105); Point2i on_g = Point2i(15, 105); + Point2i on_i = Point2i(13, 125); + Point2i on_j = Point2i(15, 125); Point2i on_background = Point2i(500, 500); Point2i on_outside = Point2i(-1, -1); @@ -419,26 +464,612 @@ TEST_CASE("[SceneTree][Viewport] Controls and InputEvent handling") { SUBCASE("[Viewport][GuiInputEvent] Mouse Motion") { // FIXME: Tooltips are not yet tested. They likely require an internal clock. - SUBCASE("[Viewport][GuiInputEvent] Mouse Motion changes the Control, that it is over.") { + SUBCASE("[Viewport][GuiInputEvent] Mouse Motion changes the Control that it is over.") { SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); CHECK_FALSE(node_a->mouse_over); + CHECK_FALSE(node_a->mouse_over_self); // Move over Control. SEND_GUI_MOUSE_MOTION_EVENT(on_a, MouseButtonMask::NONE, Key::NONE); CHECK(node_a->mouse_over); + CHECK(node_a->mouse_over_self); // No change. SEND_GUI_MOUSE_MOTION_EVENT(on_a + Point2i(1, 1), MouseButtonMask::NONE, Key::NONE); CHECK(node_a->mouse_over); + CHECK(node_a->mouse_over_self); // Move over other Control. SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::NONE, Key::NONE); CHECK_FALSE(node_a->mouse_over); + CHECK_FALSE(node_a->mouse_over_self); CHECK(node_d->mouse_over); + CHECK(node_d->mouse_over_self); - // Move to background + // Move to background. SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); CHECK_FALSE(node_d->mouse_over); + CHECK_FALSE(node_d->mouse_over_self); + + CHECK_FALSE(node_a->invalid_order); + CHECK_FALSE(node_d->invalid_order); + } + + SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification propagation.") { + node_d->set_mouse_filter(Control::MOUSE_FILTER_PASS); + node_g->set_mouse_filter(Control::MOUSE_FILTER_PASS); + + SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_b->mouse_over); + CHECK_FALSE(node_b->mouse_over_self); + CHECK_FALSE(node_d->mouse_over); + CHECK_FALSE(node_d->mouse_over_self); + + // Move to Control node_d. node_b receives mouse over since it is only separated by a CanvasItem. + SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::NONE, Key::NONE); + CHECK(node_b->mouse_over); + CHECK_FALSE(node_b->mouse_over_self); + CHECK(node_d->mouse_over); + CHECK(node_d->mouse_over_self); + + // Move to background. + SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_b->mouse_over); + CHECK_FALSE(node_b->mouse_over_self); + CHECK_FALSE(node_d->mouse_over); + CHECK_FALSE(node_d->mouse_over_self); + + CHECK_FALSE(node_e->mouse_over); + CHECK_FALSE(node_e->mouse_over_self); + CHECK_FALSE(node_g->mouse_over); + CHECK_FALSE(node_g->mouse_over_self); + + // Move to Control node_g. node_g receives mouse over but node_e does not since it is separated by a non-CanvasItem. + SEND_GUI_MOUSE_MOTION_EVENT(on_g, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_e->mouse_over); + CHECK_FALSE(node_e->mouse_over_self); + CHECK(node_g->mouse_over); + CHECK(node_g->mouse_over_self); + + // Move to background. + SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_e->mouse_over); + CHECK_FALSE(node_e->mouse_over_self); + CHECK_FALSE(node_g->mouse_over); + CHECK_FALSE(node_g->mouse_over_self); + + CHECK_FALSE(node_b->invalid_order); + CHECK_FALSE(node_d->invalid_order); + CHECK_FALSE(node_e->invalid_order); + CHECK_FALSE(node_g->invalid_order); + + node_d->set_mouse_filter(Control::MOUSE_FILTER_STOP); + node_g->set_mouse_filter(Control::MOUSE_FILTER_STOP); + } + + SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification propagation when moving into child.") { + SIGNAL_WATCH(node_i, SNAME("mouse_entered")); + SIGNAL_WATCH(node_i, SNAME("mouse_exited")); + Array signal_args; + signal_args.push_back(Array()); + + node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS); + + // Move to background. + SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK_FALSE(node_j->mouse_over); + CHECK_FALSE(node_j->mouse_over_self); + + // Move to Control node_i. + SEND_GUI_MOUSE_MOTION_EVENT(on_i, MouseButtonMask::NONE, Key::NONE); + CHECK(node_i->mouse_over); + CHECK(node_i->mouse_over_self); + CHECK_FALSE(node_j->mouse_over); + CHECK_FALSE(node_j->mouse_over_self); + SIGNAL_CHECK(SNAME("mouse_entered"), signal_args); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Move to child Control node_j. node_i should not receive any new Mouse Enter signals. + SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Move to parent Control node_i. node_i should not receive any new Mouse Enter signals. + SEND_GUI_MOUSE_MOTION_EVENT(on_i, MouseButtonMask::NONE, Key::NONE); + CHECK(node_i->mouse_over); + CHECK(node_i->mouse_over_self); + CHECK_FALSE(node_j->mouse_over); + CHECK_FALSE(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Move to background. + SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK_FALSE(node_j->mouse_over); + CHECK_FALSE(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK(SNAME("mouse_exited"), signal_args); + + CHECK_FALSE(node_i->invalid_order); + CHECK_FALSE(node_j->invalid_order); + + node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP); + + SIGNAL_UNWATCH(node_i, SNAME("mouse_entered")); + SIGNAL_UNWATCH(node_i, SNAME("mouse_exited")); + } + + SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification propagation with top level.") { + node_c->set_as_top_level(true); + node_i->set_as_top_level(true); + node_c->set_position(node_b->get_global_position()); + node_i->set_position(node_h->get_global_position()); + node_d->set_mouse_filter(Control::MOUSE_FILTER_PASS); + node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS); + node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS); + + SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_b->mouse_over); + CHECK_FALSE(node_b->mouse_over_self); + CHECK_FALSE(node_d->mouse_over); + CHECK_FALSE(node_d->mouse_over_self); + + // Move to Control node_d. node_b does not receive mouse over since node_c is top level. + SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_b->mouse_over); + CHECK_FALSE(node_b->mouse_over_self); + CHECK(node_d->mouse_over); + CHECK(node_d->mouse_over_self); + + // Move to background. + SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_b->mouse_over); + CHECK_FALSE(node_b->mouse_over_self); + CHECK_FALSE(node_d->mouse_over); + CHECK_FALSE(node_d->mouse_over_self); + + CHECK_FALSE(node_g->mouse_over); + CHECK_FALSE(node_g->mouse_over_self); + CHECK_FALSE(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK_FALSE(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + + // Move to Control node_j. node_h does not receive mouse over since node_i is top level. + SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + + // Move to background. + SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK_FALSE(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK_FALSE(node_j->mouse_over); + CHECK_FALSE(node_j->mouse_over_self); + + CHECK_FALSE(node_b->invalid_order); + CHECK_FALSE(node_d->invalid_order); + CHECK_FALSE(node_e->invalid_order); + CHECK_FALSE(node_h->invalid_order); + CHECK_FALSE(node_i->invalid_order); + CHECK_FALSE(node_j->invalid_order); + + node_c->set_as_top_level(false); + node_i->set_as_top_level(false); + node_c->set_position(Point2i(0, 0)); + node_i->set_position(Point2i(0, 0)); + node_d->set_mouse_filter(Control::MOUSE_FILTER_STOP); + node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP); + node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP); + } + + SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification propagation with mouse filter stop.") { + node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP); + node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS); + + // Move to background. + SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK_FALSE(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK_FALSE(node_j->mouse_over); + CHECK_FALSE(node_j->mouse_over_self); + + // Move to Control node_j. node_h does not receive mouse over since node_i is MOUSE_FILTER_STOP. + SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + + // Move to background. + SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK_FALSE(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK_FALSE(node_j->mouse_over); + CHECK_FALSE(node_j->mouse_over_self); + + CHECK_FALSE(node_h->invalid_order); + CHECK_FALSE(node_i->invalid_order); + CHECK_FALSE(node_j->invalid_order); + + node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP); + node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP); + } + + SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification propagation with mouse filter ignore.") { + node_i->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); + node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS); + + // Move to background. + SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK_FALSE(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK_FALSE(node_j->mouse_over); + CHECK_FALSE(node_j->mouse_over_self); + + // Move to Control node_j. node_i does not receive mouse over since node_i is MOUSE_FILTER_IGNORE. + SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK_FALSE(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + + // Move to background. + SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK_FALSE(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK_FALSE(node_j->mouse_over); + CHECK_FALSE(node_j->mouse_over_self); + + CHECK_FALSE(node_h->invalid_order); + CHECK_FALSE(node_i->invalid_order); + CHECK_FALSE(node_j->invalid_order); + + node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP); + node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP); + } + + SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification when changing top level.") { + SIGNAL_WATCH(node_i, SNAME("mouse_entered")); + SIGNAL_WATCH(node_i, SNAME("mouse_exited")); + Array signal_args; + signal_args.push_back(Array()); + + node_d->set_mouse_filter(Control::MOUSE_FILTER_PASS); + node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS); + node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS); + + // Move to Control node_d. + SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::NONE, Key::NONE); + CHECK(node_b->mouse_over); + CHECK_FALSE(node_b->mouse_over_self); + CHECK(node_d->mouse_over); + CHECK(node_d->mouse_over_self); + + // Change node_c to be top level. node_b should receive Mouse Exit. + node_c->set_as_top_level(true); + CHECK_FALSE(node_b->mouse_over); + CHECK_FALSE(node_b->mouse_over_self); + CHECK(node_d->mouse_over); + CHECK(node_d->mouse_over_self); + + // Change node_c to be not top level. node_b should receive Mouse Enter. + node_c->set_as_top_level(false); + CHECK(node_b->mouse_over); + CHECK_FALSE(node_b->mouse_over_self); + CHECK(node_d->mouse_over); + CHECK(node_d->mouse_over_self); + + // Move to Control node_j. + SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK(SNAME("mouse_entered"), signal_args); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Change node_i to top level. node_h should receive Mouse Exit. node_i should not receive any new signals. + node_i->set_as_top_level(true); + CHECK_FALSE(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Change node_i to not top level. node_h should receive Mouse Enter. node_i should not receive any new signals. + node_i->set_as_top_level(false); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + CHECK_FALSE(node_b->invalid_order); + CHECK_FALSE(node_d->invalid_order); + CHECK_FALSE(node_e->invalid_order); + CHECK_FALSE(node_h->invalid_order); + CHECK_FALSE(node_i->invalid_order); + CHECK_FALSE(node_j->invalid_order); + + node_d->set_mouse_filter(Control::MOUSE_FILTER_STOP); + node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP); + node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP); + + SIGNAL_UNWATCH(node_i, SNAME("mouse_entered")); + SIGNAL_UNWATCH(node_i, SNAME("mouse_exited")); + } + + SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification when changing the mouse filter to stop.") { + SIGNAL_WATCH(node_i, SNAME("mouse_entered")); + SIGNAL_WATCH(node_i, SNAME("mouse_exited")); + Array signal_args; + signal_args.push_back(Array()); + + node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS); + node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS); + + // Move to Control node_j. + SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK(SNAME("mouse_entered"), signal_args); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Change node_i to MOUSE_FILTER_STOP. node_h should receive Mouse Exit. node_i should not receive any new signals. + node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP); + CHECK_FALSE(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Change node_i to MOUSE_FILTER_PASS. node_h should receive Mouse Enter. node_i should not receive any new signals. + node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + CHECK_FALSE(node_h->invalid_order); + CHECK_FALSE(node_i->invalid_order); + CHECK_FALSE(node_j->invalid_order); + + node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP); + node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP); + + SIGNAL_UNWATCH(node_i, SNAME("mouse_entered")); + SIGNAL_UNWATCH(node_i, SNAME("mouse_exited")); + } + + SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification when changing the mouse filter to ignore.") { + SIGNAL_WATCH(node_i, SNAME("mouse_entered")); + SIGNAL_WATCH(node_i, SNAME("mouse_exited")); + Array signal_args; + signal_args.push_back(Array()); + + node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS); + node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS); + + // Move to Control node_j. + SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK(SNAME("mouse_entered"), signal_args); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Change node_i to MOUSE_FILTER_IGNORE. node_i should receive Mouse Exit. + node_i->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK_FALSE(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK(SNAME("mouse_exited"), signal_args); + + // Change node_i to MOUSE_FILTER_PASS. node_i should receive Mouse Enter. + node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK(SNAME("mouse_entered"), signal_args); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Change node_j to MOUSE_FILTER_IGNORE. After updating the mouse motion, node_i should now have mouse_over_self. + node_j->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); + SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK(node_i->mouse_over_self); + CHECK_FALSE(node_j->mouse_over); + CHECK_FALSE(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Change node_j to MOUSE_FILTER_PASS. After updating the mouse motion, node_j should now have mouse_over_self. + node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS); + SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + CHECK_FALSE(node_h->invalid_order); + CHECK_FALSE(node_i->invalid_order); + CHECK_FALSE(node_j->invalid_order); + + node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP); + node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP); + + SIGNAL_UNWATCH(node_i, SNAME("mouse_entered")); + SIGNAL_UNWATCH(node_i, SNAME("mouse_exited")); + } + + SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification when removing the hovered Control.") { + SIGNAL_WATCH(node_h, SNAME("mouse_entered")); + SIGNAL_WATCH(node_h, SNAME("mouse_exited")); + Array signal_args; + signal_args.push_back(Array()); + + node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS); + node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS); + + // Move to Control node_j. + SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK(SNAME("mouse_entered"), signal_args); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Remove node_i from the tree. node_i and node_j should receive Mouse Exit. node_h should not receive any new signals. + node_h->remove_child(node_i); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK_FALSE(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK_FALSE(node_j->mouse_over); + CHECK_FALSE(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Add node_i to the tree and update the mouse. node_i and node_j should receive Mouse Enter. node_h should not receive any new signals. + node_h->add_child(node_i); + SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + CHECK_FALSE(node_h->invalid_order); + CHECK_FALSE(node_i->invalid_order); + CHECK_FALSE(node_j->invalid_order); + + node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP); + node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP); + + SIGNAL_UNWATCH(node_h, SNAME("mouse_entered")); + SIGNAL_UNWATCH(node_h, SNAME("mouse_exited")); + } + + SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification when hiding the hovered Control.") { + SIGNAL_WATCH(node_h, SNAME("mouse_entered")); + SIGNAL_WATCH(node_h, SNAME("mouse_exited")); + Array signal_args; + signal_args.push_back(Array()); + + node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS); + node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS); + + // Move to Control node_j. + SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK(SNAME("mouse_entered"), signal_args); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Hide node_i. node_i and node_j should receive Mouse Exit. node_h should not receive any new signals. + node_i->hide(); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK_FALSE(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK_FALSE(node_j->mouse_over); + CHECK_FALSE(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + // Show node_i and update the mouse. node_i and node_j should receive Mouse Enter. node_h should not receive any new signals. + node_i->show(); + SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE); + CHECK(node_h->mouse_over); + CHECK_FALSE(node_h->mouse_over_self); + CHECK(node_i->mouse_over); + CHECK_FALSE(node_i->mouse_over_self); + CHECK(node_j->mouse_over); + CHECK(node_j->mouse_over_self); + SIGNAL_CHECK_FALSE(SNAME("mouse_entered")); + SIGNAL_CHECK_FALSE(SNAME("mouse_exited")); + + CHECK_FALSE(node_h->invalid_order); + CHECK_FALSE(node_i->invalid_order); + CHECK_FALSE(node_j->invalid_order); + + node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP); + node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP); + + SIGNAL_UNWATCH(node_h, SNAME("mouse_entered")); + SIGNAL_UNWATCH(node_h, SNAME("mouse_exited")); } SUBCASE("[Viewport][GuiInputEvent] Window Mouse Enter/Exit signals.") { @@ -710,6 +1341,9 @@ TEST_CASE("[SceneTree][Viewport] Controls and InputEvent handling") { } } + memdelete(node_j); + memdelete(node_i); + memdelete(node_h); memdelete(node_g); memdelete(node_f); memdelete(node_e); diff --git a/tests/servers/test_navigation_server_3d.h b/tests/servers/test_navigation_server_3d.h index 691536da8e..5ab2975b74 100644 --- a/tests/servers/test_navigation_server_3d.h +++ b/tests/servers/test_navigation_server_3d.h @@ -429,6 +429,105 @@ TEST_SUITE("[Navigation]") { navigation_server->free(map); } + TEST_CASE("[NavigationServer3D] Server should make agents avoid dynamic obstacles when avoidance enabled") { + NavigationServer3D *navigation_server = NavigationServer3D::get_singleton(); + + RID map = navigation_server->map_create(); + RID agent_1 = navigation_server->agent_create(); + RID obstacle_1 = navigation_server->obstacle_create(); + + navigation_server->map_set_active(map, true); + + navigation_server->agent_set_map(agent_1, map); + navigation_server->agent_set_avoidance_enabled(agent_1, true); + navigation_server->agent_set_position(agent_1, Vector3(0, 0, 0)); + navigation_server->agent_set_radius(agent_1, 1); + navigation_server->agent_set_velocity(agent_1, Vector3(1, 0, 0)); + CallableMock agent_1_avoidance_callback_mock; + navigation_server->agent_set_avoidance_callback(agent_1, callable_mp(&agent_1_avoidance_callback_mock, &CallableMock::function1)); + + navigation_server->obstacle_set_map(obstacle_1, map); + navigation_server->obstacle_set_avoidance_enabled(obstacle_1, true); + navigation_server->obstacle_set_position(obstacle_1, Vector3(2.5, 0, 0.5)); + navigation_server->obstacle_set_radius(obstacle_1, 1); + + CHECK_EQ(agent_1_avoidance_callback_mock.function1_calls, 0); + navigation_server->process(0.0); // Give server some cycles to commit. + CHECK_EQ(agent_1_avoidance_callback_mock.function1_calls, 1); + Vector3 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0; + CHECK_MESSAGE(agent_1_safe_velocity.x > 0, "Agent 1 should move a bit along desired velocity (+X)."); + CHECK_MESSAGE(agent_1_safe_velocity.z < 0, "Agent 1 should move a bit to the side so that it avoids obstacle."); + + navigation_server->free(obstacle_1); + navigation_server->free(agent_1); + navigation_server->free(map); + navigation_server->process(0.0); // Give server some cycles to commit. + } + + TEST_CASE("[NavigationServer3D] Server should make agents avoid static obstacles when avoidance enabled") { + NavigationServer3D *navigation_server = NavigationServer3D::get_singleton(); + + RID map = navigation_server->map_create(); + RID agent_1 = navigation_server->agent_create(); + RID agent_2 = navigation_server->agent_create(); + RID obstacle_1 = navigation_server->obstacle_create(); + + navigation_server->map_set_active(map, true); + + navigation_server->agent_set_map(agent_1, map); + navigation_server->agent_set_avoidance_enabled(agent_1, true); + navigation_server->agent_set_radius(agent_1, 1.6); // Have hit the obstacle already. + navigation_server->agent_set_velocity(agent_1, Vector3(1, 0, 0)); + CallableMock agent_1_avoidance_callback_mock; + navigation_server->agent_set_avoidance_callback(agent_1, callable_mp(&agent_1_avoidance_callback_mock, &CallableMock::function1)); + + navigation_server->agent_set_map(agent_2, map); + navigation_server->agent_set_avoidance_enabled(agent_2, true); + navigation_server->agent_set_radius(agent_2, 1.4); // Haven't hit the obstacle yet. + navigation_server->agent_set_velocity(agent_2, Vector3(1, 0, 0)); + CallableMock agent_2_avoidance_callback_mock; + navigation_server->agent_set_avoidance_callback(agent_2, callable_mp(&agent_2_avoidance_callback_mock, &CallableMock::function1)); + + navigation_server->obstacle_set_map(obstacle_1, map); + navigation_server->obstacle_set_avoidance_enabled(obstacle_1, true); + PackedVector3Array obstacle_1_vertices; + + SUBCASE("Static obstacles should work on ground level") { + navigation_server->agent_set_position(agent_1, Vector3(0, 0, 0)); + navigation_server->agent_set_position(agent_2, Vector3(0, 0, 5)); + obstacle_1_vertices.push_back(Vector3(1.5, 0, 0.5)); + obstacle_1_vertices.push_back(Vector3(1.5, 0, 4.5)); + } + + SUBCASE("Static obstacles should work when elevated") { + navigation_server->agent_set_position(agent_1, Vector3(0, 5, 0)); + navigation_server->agent_set_position(agent_2, Vector3(0, 5, 5)); + obstacle_1_vertices.push_back(Vector3(1.5, 0, 0.5)); + obstacle_1_vertices.push_back(Vector3(1.5, 0, 4.5)); + navigation_server->obstacle_set_position(obstacle_1, Vector3(0, 5, 0)); + } + + navigation_server->obstacle_set_vertices(obstacle_1, obstacle_1_vertices); + + CHECK_EQ(agent_1_avoidance_callback_mock.function1_calls, 0); + CHECK_EQ(agent_2_avoidance_callback_mock.function1_calls, 0); + navigation_server->process(0.0); // Give server some cycles to commit. + CHECK_EQ(agent_1_avoidance_callback_mock.function1_calls, 1); + CHECK_EQ(agent_2_avoidance_callback_mock.function1_calls, 1); + Vector3 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0; + Vector3 agent_2_safe_velocity = agent_2_avoidance_callback_mock.function1_latest_arg0; + CHECK_MESSAGE(agent_1_safe_velocity.x > 0, "Agent 1 should move a bit along desired velocity (+X)."); + CHECK_MESSAGE(agent_1_safe_velocity.z < 0, "Agent 1 should move a bit to the side so that it avoids obstacle."); + CHECK_MESSAGE(agent_2_safe_velocity.x > 0, "Agent 2 should move a bit along desired velocity (+X)."); + CHECK_MESSAGE(agent_2_safe_velocity.z == 0, "Agent 2 should not move to the side."); + + navigation_server->free(obstacle_1); + navigation_server->free(agent_2); + navigation_server->free(agent_1); + navigation_server->free(map); + navigation_server->process(0.0); // Give server some cycles to commit. + } + #ifndef DISABLE_DEPRECATED // This test case uses only public APIs on purpose - other test cases use simplified baking. // FIXME: Remove once deprecated `region_bake_navigation_mesh()` is removed. |