diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/io/test_json.h | 10 | ||||
-rw-r--r-- | tests/core/object/test_class_db.h | 3 | ||||
-rw-r--r-- | tests/scene/test_packed_scene.h | 41 | ||||
-rw-r--r-- | tests/scene/test_window.h | 96 | ||||
-rw-r--r-- | tests/servers/rendering/test_shader_preprocessor.h | 3 | ||||
-rw-r--r-- | tests/servers/test_navigation_server_3d.h | 2 | ||||
-rw-r--r-- | tests/test_main.cpp | 1 |
7 files changed, 147 insertions, 9 deletions
diff --git a/tests/core/io/test_json.h b/tests/core/io/test_json.h index 73c7ac7a2e..bf2ed42740 100644 --- a/tests/core/io/test_json.h +++ b/tests/core/io/test_json.h @@ -186,20 +186,21 @@ TEST_CASE("[JSON] Parsing escape sequences") { } SUBCASE("Valid unicode escape sequences") { - String json_string = "\"\\u0000\""; + String json_string = "\"\\u0020\""; json.parse(json_string); CHECK_MESSAGE( json.get_error_line() == 0, - vformat("Parsing valid unicode escape sequence with value `0000` as JSON should parse successfully.")); + vformat("Parsing valid unicode escape sequence with value `0020` as JSON should parse successfully.")); String json_value = json.get_data(); CHECK_MESSAGE( - json_value == "\0", - vformat("Parsing valid unicode escape sequence with value `0000` as JSON should return the expected value.")); + json_value == " ", + vformat("Parsing valid unicode escape sequence with value `0020` as JSON should return the expected value.")); } SUBCASE("Invalid escape sequences") { + ERR_PRINT_OFF for (char32_t i = 0; i < 128; i++) { bool skip = false; for (int j = 0; j < valid_escapes.size(); j++) { @@ -228,6 +229,7 @@ TEST_CASE("[JSON] Parsing escape sequences") { err == ERR_PARSE_ERROR, vformat("Parsing invalid escape sequence with ASCII value `%d` as JSON should fail to parse with ERR_PARSE_ERROR.", i)); } + ERR_PRINT_ON } } } // namespace TestJSON diff --git a/tests/core/object/test_class_db.h b/tests/core/object/test_class_db.h index 3f091fd2fe..5f7de11c71 100644 --- a/tests/core/object/test_class_db.h +++ b/tests/core/object/test_class_db.h @@ -409,9 +409,6 @@ void validate_method(const Context &p_context, const ExposedClass &p_class, cons if (p_method.return_type.name != StringName()) { const ExposedClass *return_class = p_context.find_exposed_class(p_method.return_type); if (return_class) { - TEST_COND(return_class->is_singleton, - "Method return type is a singleton: '", p_class.name, ".", p_method.name, "'."); - if (p_class.api_type == ClassDB::API_CORE) { TEST_COND(return_class->api_type == ClassDB::API_EDITOR, "Method '", p_class.name, ".", p_method.name, "' has return type '", return_class->name, diff --git a/tests/scene/test_packed_scene.h b/tests/scene/test_packed_scene.h index 9e525ab5bf..3517aba31f 100644 --- a/tests/scene/test_packed_scene.h +++ b/tests/scene/test_packed_scene.h @@ -109,6 +109,47 @@ TEST_CASE("[PackedScene] Instantiate Packed Scene") { memdelete(instance); } +TEST_CASE("[PackedScene] Instantiate Packed Scene With Children") { + // Create a scene to pack. + Node *scene = memnew(Node); + scene->set_name("TestScene"); + + // Add persisting child nodes to the scene. + Node *child1 = memnew(Node); + child1->set_name("Child1"); + scene->add_child(child1); + child1->set_owner(scene); + + Node *child2 = memnew(Node); + child2->set_name("Child2"); + scene->add_child(child2); + child2->set_owner(scene); + + // Add non persisting child node to the scene. + Node *child3 = memnew(Node); + child3->set_name("Child3"); + scene->add_child(child3); + + // Pack the scene. + PackedScene packed_scene; + packed_scene.pack(scene); + + // Instantiate the packed scene. + Node *instance = packed_scene.instantiate(); + CHECK(instance != nullptr); + CHECK(instance->get_name() == "TestScene"); + + // Validate the child nodes of the instantiated scene. + CHECK(instance->get_child_count() == 2); + CHECK(instance->get_child(0)->get_name() == "Child1"); + CHECK(instance->get_child(1)->get_name() == "Child2"); + CHECK(instance->get_child(0)->get_owner() == instance); + CHECK(instance->get_child(1)->get_owner() == instance); + + memdelete(scene); + memdelete(instance); +} + } // namespace TestPackedScene #endif // TEST_PACKED_SCENE_H diff --git a/tests/scene/test_window.h b/tests/scene/test_window.h new file mode 100644 index 0000000000..e0c55101de --- /dev/null +++ b/tests/scene/test_window.h @@ -0,0 +1,96 @@ +/**************************************************************************/ +/* test_window.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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_WINDOW_H +#define TEST_WINDOW_H + +#include "scene/gui/control.h" +#include "scene/main/window.h" + +#include "tests/test_macros.h" + +namespace TestWindow { + +class NotificationControl : public Control { + GDCLASS(NotificationControl, Control); + +protected: + void _notification(int p_what) { + switch (p_what) { + case NOTIFICATION_MOUSE_ENTER: { + mouse_over = true; + } break; + + case NOTIFICATION_MOUSE_EXIT: { + mouse_over = false; + } break; + } + } + +public: + bool mouse_over = false; +}; + +TEST_CASE("[SceneTree][Window]") { + Window *root = SceneTree::get_singleton()->get_root(); + + SUBCASE("Control-mouse-over within Window-black bars should not happen") { + Window *w = memnew(Window); + root->add_child(w); + w->set_size(Size2i(400, 200)); + w->set_position(Size2i(0, 0)); + w->set_content_scale_size(Size2i(200, 200)); + w->set_content_scale_mode(Window::CONTENT_SCALE_MODE_CANVAS_ITEMS); + w->set_content_scale_aspect(Window::CONTENT_SCALE_ASPECT_KEEP); + NotificationControl *c = memnew(NotificationControl); + w->add_child(c); + c->set_size(Size2i(100, 100)); + c->set_position(Size2i(-50, -50)); + + CHECK_FALSE(c->mouse_over); + SEND_GUI_MOUSE_MOTION_EVENT(Point2i(110, 10), MouseButtonMask::NONE, Key::NONE); + CHECK(c->mouse_over); + SEND_GUI_MOUSE_MOTION_EVENT(Point2i(90, 10), MouseButtonMask::NONE, Key::NONE); + CHECK_FALSE(c->mouse_over); // GH-80011 + + /* TODO: + SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(90, 10), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE); + SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(Point2i(90, 10), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE); + CHECK(Control was not pressed); + */ + + memdelete(c); + memdelete(w); + } +} + +} // namespace TestWindow + +#endif // TEST_WINDOW_H diff --git a/tests/servers/rendering/test_shader_preprocessor.h b/tests/servers/rendering/test_shader_preprocessor.h index 41a009ccf5..d65eb522e8 100644 --- a/tests/servers/rendering/test_shader_preprocessor.h +++ b/tests/servers/rendering/test_shader_preprocessor.h @@ -52,8 +52,7 @@ bool is_variable_char(unsigned char c) { } bool is_operator_char(unsigned char c) { - static const std::string operators = "<>=+-*/"; - return operators.find(c) != std::string::npos; + return (c == '*') || (c == '+') || (c == '-') || (c == '/') || ((c >= '<') && (c <= '>')); } // Remove unnecessary spaces from a line. diff --git a/tests/servers/test_navigation_server_3d.h b/tests/servers/test_navigation_server_3d.h index 8ea69ec67c..a116559cb2 100644 --- a/tests/servers/test_navigation_server_3d.h +++ b/tests/servers/test_navigation_server_3d.h @@ -423,6 +423,7 @@ TEST_SUITE("[Navigation]") { navigation_server->free(map); } +#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. TEST_CASE("[NavigationServer3D][SceneTree][DEPRECATED] Server should be able to bake map correctly") { @@ -470,6 +471,7 @@ TEST_SUITE("[Navigation]") { memdelete(mesh_instance); memdelete(node_3d); } +#endif // DISABLE_DEPRECATED // This test case uses only public APIs on purpose - other test cases use simplified baking. TEST_CASE("[NavigationServer3D][SceneTree] Server should be able to bake map correctly") { diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 5ca03a20af..f1e348345b 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -115,6 +115,7 @@ #include "tests/scene/test_theme.h" #include "tests/scene/test_viewport.h" #include "tests/scene/test_visual_shader.h" +#include "tests/scene/test_window.h" #include "tests/servers/rendering/test_shader_preprocessor.h" #include "tests/servers/test_navigation_server_2d.h" #include "tests/servers/test_navigation_server_3d.h" |