diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/core/io/test_image.h | 10 | ||||
| -rw-r--r-- | tests/core/math/test_math_funcs.h | 31 | ||||
| -rw-r--r-- | tests/core/object/test_object.h | 72 | ||||
| -rw-r--r-- | tests/core/string/test_string.h | 16 | ||||
| -rw-r--r-- | tests/data/images/icon.dds | bin | 87536 -> 0 bytes | |||
| -rw-r--r-- | tests/scene/test_code_edit.h | 38 | ||||
| -rw-r--r-- | tests/scene/test_viewport.h | 16 | ||||
| -rw-r--r-- | tests/scene/test_window.h | 6 | ||||
| -rw-r--r-- | tests/servers/test_text_server.h | 6 | ||||
| -rw-r--r-- | tests/test_main.cpp | 19 |
10 files changed, 161 insertions, 53 deletions
diff --git a/tests/core/io/test_image.h b/tests/core/io/test_image.h index 1897971113..07c7c04e36 100644 --- a/tests/core/io/test_image.h +++ b/tests/core/io/test_image.h @@ -115,16 +115,6 @@ TEST_CASE("[Image] Saving and loading") { image_bmp->load_bmp_from_buffer(data_bmp) == OK, "The BMP image should load successfully."); - // Load DDS - Ref<Image> image_dds = memnew(Image()); - Ref<FileAccess> f_dds = FileAccess::open(TestUtils::get_data_path("images/icon.dds"), FileAccess::READ, &err); - PackedByteArray data_dds; - data_dds.resize(f_dds->get_length() + 1); - f_dds->get_buffer(data_dds.ptrw(), f_dds->get_length()); - CHECK_MESSAGE( - image_dds->load_dds_from_buffer(data_dds) == OK, - "The DDS image should load successfully."); - // Load JPG Ref<Image> image_jpg = memnew(Image()); Ref<FileAccess> f_jpg = FileAccess::open(TestUtils::get_data_path("images/icon.jpg"), FileAccess::READ, &err); diff --git a/tests/core/math/test_math_funcs.h b/tests/core/math/test_math_funcs.h index b6cb9620f1..e3504ef1e5 100644 --- a/tests/core/math/test_math_funcs.h +++ b/tests/core/math/test_math_funcs.h @@ -175,6 +175,37 @@ TEST_CASE_TEMPLATE("[Math] asin/acos/atan", T, float, double) { CHECK(Math::atan((T)450.0) == doctest::Approx((T)1.5685741082)); } +TEST_CASE_TEMPLATE("[Math] asinh/acosh/atanh", T, float, double) { + CHECK(Math::asinh((T)-2.0) == doctest::Approx((T)-1.4436354751)); + CHECK(Math::asinh((T)-0.1) == doctest::Approx((T)-0.0998340788)); + CHECK(Math::asinh((T)0.1) == doctest::Approx((T)0.0998340788)); + CHECK(Math::asinh((T)0.5) == doctest::Approx((T)0.4812118250)); + CHECK(Math::asinh((T)1.0) == doctest::Approx((T)0.8813735870)); + CHECK(Math::asinh((T)2.0) == doctest::Approx((T)1.4436354751)); + + CHECK(Math::acosh((T)-2.0) == doctest::Approx((T)0.0)); + CHECK(Math::acosh((T)-0.1) == doctest::Approx((T)0.0)); + CHECK(Math::acosh((T)0.1) == doctest::Approx((T)0.0)); + CHECK(Math::acosh((T)0.5) == doctest::Approx((T)0.0)); + CHECK(Math::acosh((T)1.0) == doctest::Approx((T)0.0)); + CHECK(Math::acosh((T)2.0) == doctest::Approx((T)1.3169578969)); + CHECK(Math::acosh((T)450.0) == doctest::Approx((T)6.8023935287)); + + CHECK(Math::is_inf(Math::atanh((T)-2.0))); + CHECK(Math::atanh((T)-2.0) < (T)0.0); + CHECK(Math::is_inf(Math::atanh((T)-1.0))); + CHECK(Math::atanh((T)-1.0) < (T)0.0); + CHECK(Math::atanh((T)-0.1) == doctest::Approx((T)-0.1003353477)); + CHECK(Math::atanh((T)0.1) == doctest::Approx((T)0.1003353477)); + CHECK(Math::atanh((T)0.5) == doctest::Approx((T)0.5493061443)); + CHECK(Math::is_inf(Math::atanh((T)1.0))); + CHECK(Math::atanh((T)1.0) > (T)0.0); + CHECK(Math::is_inf(Math::atanh((T)1.5))); + CHECK(Math::atanh((T)1.5) > (T)0.0); + CHECK(Math::is_inf(Math::atanh((T)450.0))); + CHECK(Math::atanh((T)450.0) > (T)0.0); +} + TEST_CASE_TEMPLATE("[Math] sinc/sincn/atan2", T, float, double) { CHECK(Math::sinc((T)-0.1) == doctest::Approx((T)0.9983341665)); CHECK(Math::sinc((T)0.1) == doctest::Approx((T)0.9983341665)); diff --git a/tests/core/object/test_object.h b/tests/core/object/test_object.h index 8ab6221a1c..e5d91db650 100644 --- a/tests/core/object/test_object.h +++ b/tests/core/object/test_object.h @@ -82,6 +82,8 @@ public: Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid) const override { return Variant::PACKED_FLOAT32_ARRAY; } + virtual void validate_property(PropertyInfo &p_property) const override { + } bool property_can_revert(const StringName &p_name) const override { return false; }; @@ -96,7 +98,7 @@ public: Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override { return Variant(); } - void notification(int p_notification) override { + void notification(int p_notification, bool p_reversed = false) override { } Ref<Script> get_script() const override { return Ref<Script>(); @@ -424,6 +426,74 @@ TEST_CASE("[Object] Signals") { } } +class NotificationObject1 : public Object { + GDCLASS(NotificationObject1, Object); + +protected: + void _notification(int p_what) { + switch (p_what) { + case 12345: { + order_internal1 = order_global++; + } break; + } + } + +public: + static int order_global; + int order_internal1 = -1; + + void reset_order() { + order_internal1 = -1; + order_global = 1; + } +}; + +int NotificationObject1::order_global = 1; + +class NotificationObject2 : public NotificationObject1 { + GDCLASS(NotificationObject2, NotificationObject1); + +protected: + void _notification(int p_what) { + switch (p_what) { + case 12345: { + order_internal2 = order_global++; + } break; + } + } + +public: + int order_internal2 = -1; + void reset_order() { + NotificationObject1::reset_order(); + order_internal2 = -1; + } +}; + +TEST_CASE("[Object] Notification order") { // GH-52325 + NotificationObject2 *test_notification_object = memnew(NotificationObject2); + + SUBCASE("regular order") { + test_notification_object->notification(12345, false); + + CHECK_EQ(test_notification_object->order_internal1, 1); + CHECK_EQ(test_notification_object->order_internal2, 2); + + test_notification_object->reset_order(); + } + + SUBCASE("reverse order") { + test_notification_object->notification(12345, true); + + CHECK_EQ(test_notification_object->order_internal1, 2); + CHECK_EQ(test_notification_object->order_internal2, 1); + + test_notification_object->reset_order(); + } + + memdelete(test_notification_object); +} + } // namespace TestObject #endif // TEST_OBJECT_H diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h index 659fb003d3..c10ad6e13d 100644 --- a/tests/core/string/test_string.h +++ b/tests/core/string/test_string.h @@ -805,6 +805,22 @@ TEST_CASE("[String] sprintf") { REQUIRE(error == false); CHECK(output == String("fish +99.990000 frog")); + // Real with sign (negative zero). + format = "fish %+f frog"; + args.clear(); + args.push_back(-0.0); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish -0.000000 frog")); + + // Real with sign (positive zero). + format = "fish %+f frog"; + args.clear(); + args.push_back(0.0); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish +0.000000 frog")); + // Real with 1 decimal. format = "fish %.1f frog"; args.clear(); diff --git a/tests/data/images/icon.dds b/tests/data/images/icon.dds Binary files differdeleted file mode 100644 index 8a9de402cb..0000000000 --- a/tests/data/images/icon.dds +++ /dev/null diff --git a/tests/scene/test_code_edit.h b/tests/scene/test_code_edit.h index d6858fbcb4..72421c9cc9 100644 --- a/tests/scene/test_code_edit.h +++ b/tests/scene/test_code_edit.h @@ -3446,7 +3446,7 @@ TEST_CASE("[SceneTree][CodeEdit] completion") { } SUBCASE("[CodeEdit] autocomplete suggestion order") { - /* Favorize less fragmented suggestion. */ + /* Prefer less fragmented suggestion. */ code_edit->clear(); code_edit->insert_text_at_caret("te"); code_edit->set_caret_column(2); @@ -3456,7 +3456,7 @@ TEST_CASE("[SceneTree][CodeEdit] completion") { code_edit->confirm_code_completion(); CHECK(code_edit->get_line(0) == "test"); - /* Favorize suggestion starting from the string to complete (matching start). */ + /* Prefer suggestion starting with the string to complete (matching start). */ code_edit->clear(); code_edit->insert_text_at_caret("te"); code_edit->set_caret_column(2); @@ -3466,7 +3466,7 @@ TEST_CASE("[SceneTree][CodeEdit] completion") { code_edit->confirm_code_completion(); CHECK(code_edit->get_line(0) == "test"); - /* Favorize less fragment to matching start. */ + /* Prefer less fragment over matching start. */ code_edit->clear(); code_edit->insert_text_at_caret("te"); code_edit->set_caret_column(2); @@ -3476,37 +3476,37 @@ TEST_CASE("[SceneTree][CodeEdit] completion") { code_edit->confirm_code_completion(); CHECK(code_edit->get_line(0) == "stest"); - /* Favorize closer location. */ + /* Prefer good capitalization. */ code_edit->clear(); code_edit->insert_text_at_caret("te"); code_edit->set_caret_column(2); code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "test", "test"); - code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "test_bis", "test_bis", Color(1, 1, 1), Ref<Resource>(), Variant::NIL, CodeEdit::LOCATION_LOCAL); + code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "Test", "Test"); code_edit->update_code_completion_options(); code_edit->confirm_code_completion(); - CHECK(code_edit->get_line(0) == "test_bis"); + CHECK(code_edit->get_line(0) == "test"); - /* Favorize matching start to location. */ + /* Prefer matching start over good capitalization. */ code_edit->clear(); code_edit->insert_text_at_caret("te"); code_edit->set_caret_column(2); - code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "test", "test"); - code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "stest_bis", "test_bis", Color(1, 1, 1), Ref<Resource>(), Variant::NIL, CodeEdit::LOCATION_LOCAL); + code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "Test", "Test"); + code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "stest_bis", "test_bis"); code_edit->update_code_completion_options(); code_edit->confirm_code_completion(); - CHECK(code_edit->get_line(0) == "test"); + CHECK(code_edit->get_line(0) == "Test"); - /* Favorize good capitalization. */ + /* Prefer closer location. */ code_edit->clear(); code_edit->insert_text_at_caret("te"); code_edit->set_caret_column(2); code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "test", "test"); - code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "Test", "Test"); + code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "test_bis", "test_bis", Color(1, 1, 1), Ref<Resource>(), Variant::NIL, CodeEdit::LOCATION_LOCAL); code_edit->update_code_completion_options(); code_edit->confirm_code_completion(); - CHECK(code_edit->get_line(0) == "test"); + CHECK(code_edit->get_line(0) == "test_bis"); - /* Favorize location to good capitalization. */ + /* Prefer good capitalization over location. */ code_edit->clear(); code_edit->insert_text_at_caret("te"); code_edit->set_caret_column(2); @@ -3514,9 +3514,9 @@ TEST_CASE("[SceneTree][CodeEdit] completion") { code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "Test", "Test", Color(1, 1, 1), Ref<Resource>(), Variant::NIL, CodeEdit::LOCATION_LOCAL); code_edit->update_code_completion_options(); code_edit->confirm_code_completion(); - CHECK(code_edit->get_line(0) == "Test"); + CHECK(code_edit->get_line(0) == "test"); - /* Favorize string to complete being closest to the start of the suggestion (closest to start). */ + /* Prefer the start of the string to complete being closest to the start of the suggestion (closest to start). */ code_edit->clear(); code_edit->insert_text_at_caret("te"); code_edit->set_caret_column(2); @@ -3526,12 +3526,12 @@ TEST_CASE("[SceneTree][CodeEdit] completion") { code_edit->confirm_code_completion(); CHECK(code_edit->get_line(0) == "stest"); - /* Favorize good capitalization to closest to start. */ + /* Prefer location over closest to start. */ code_edit->clear(); code_edit->insert_text_at_caret("te"); code_edit->set_caret_column(2); - code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "sTest", "stest"); - code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "sstest", "sstest"); + code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "stest", "stest"); + code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "sstest", "sstest", Color(1, 1, 1), Ref<Resource>(), Variant::NIL, CodeEdit::LOCATION_LOCAL); code_edit->update_code_completion_options(); code_edit->confirm_code_completion(); CHECK(code_edit->get_line(0) == "sstest"); diff --git a/tests/scene/test_viewport.h b/tests/scene/test_viewport.h index dd4786977e..0c53668c6d 100644 --- a/tests/scene/test_viewport.h +++ b/tests/scene/test_viewport.h @@ -43,8 +43,8 @@ namespace TestViewport { -class NotificationControl : public Control { - GDCLASS(NotificationControl, Control); +class NotificationControlViewport : public Control { + GDCLASS(NotificationControlViewport, Control); protected: void _notification(int p_what) { @@ -63,11 +63,11 @@ public: bool mouse_over = false; }; -// `NotificationControl`-derived class that additionally +// `NotificationControlViewport`-derived class that additionally // - allows start Dragging // - stores mouse information of last event -class DragStart : public NotificationControl { - GDCLASS(DragStart, NotificationControl); +class DragStart : public NotificationControlViewport { + GDCLASS(DragStart, NotificationControlViewport); public: MouseButton last_mouse_button; @@ -93,9 +93,9 @@ public: } }; -// `NotificationControl`-derived class that acts as a Drag and Drop target. -class DragTarget : public NotificationControl { - GDCLASS(DragTarget, NotificationControl); +// `NotificationControlViewport`-derived class that acts as a Drag and Drop target. +class DragTarget : public NotificationControlViewport { + GDCLASS(DragTarget, NotificationControlViewport); public: Variant drag_data; diff --git a/tests/scene/test_window.h b/tests/scene/test_window.h index e0c55101de..592cccfd7e 100644 --- a/tests/scene/test_window.h +++ b/tests/scene/test_window.h @@ -38,8 +38,8 @@ namespace TestWindow { -class NotificationControl : public Control { - GDCLASS(NotificationControl, Control); +class NotificationControlWindow : public Control { + GDCLASS(NotificationControlWindow, Control); protected: void _notification(int p_what) { @@ -69,7 +69,7 @@ TEST_CASE("[SceneTree][Window]") { 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); + NotificationControlWindow *c = memnew(NotificationControlWindow); w->add_child(c); c->set_size(Size2i(100, 100)); c->set_position(Size2i(-50, -50)); diff --git a/tests/servers/test_text_server.h b/tests/servers/test_text_server.h index eef5b850ca..0f23929e1e 100644 --- a/tests/servers/test_text_server.h +++ b/tests/servers/test_text_server.h @@ -70,7 +70,7 @@ TEST_SUITE("[TextServer]") { ts->font_set_data_ptr(font1, _font_NotoSans_Regular, _font_NotoSans_Regular_size); ts->font_set_allow_system_fallback(font1, false); RID font2 = ts->create_font(); - ts->font_set_data_ptr(font2, _font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size); + ts->font_set_data_ptr(font2, _font_NotoSansThai_Regular, _font_NotoSansThai_Regular_size); ts->font_set_allow_system_fallback(font2, false); Array font; @@ -177,7 +177,7 @@ TEST_SUITE("[TextServer]") { ts->font_set_data_ptr(font1, _font_NotoSans_Regular, _font_NotoSans_Regular_size); ts->font_set_allow_system_fallback(font1, false); RID font2 = ts->create_font(); - ts->font_set_data_ptr(font2, _font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size); + ts->font_set_data_ptr(font2, _font_NotoSansThai_Regular, _font_NotoSansThai_Regular_size); ts->font_set_allow_system_fallback(font2, false); RID font3 = ts->create_font(); ts->font_set_data_ptr(font3, _font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size); @@ -511,7 +511,7 @@ TEST_SUITE("[TextServer]") { RID font1 = ts->create_font(); ts->font_set_data_ptr(font1, _font_NotoSans_Regular, _font_NotoSans_Regular_size); RID font2 = ts->create_font(); - ts->font_set_data_ptr(font2, _font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size); + ts->font_set_data_ptr(font2, _font_NotoSansThai_Regular, _font_NotoSansThai_Regular_size); Array font; font.push_back(font1); diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 6cc7aad48e..3a80fc8c00 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -212,7 +212,6 @@ struct GodotTestCaseListener : public doctest::IReporter { PhysicsServer2D *physics_server_2d = nullptr; NavigationServer3D *navigation_server_3d = nullptr; NavigationServer2D *navigation_server_2d = nullptr; - ThemeDB *theme_db = nullptr; void test_case_start(const doctest::TestCaseData &p_in) override { reinitialize(); @@ -238,6 +237,12 @@ struct GodotTestCaseListener : public doctest::IReporter { RenderingServerDefault::get_singleton()->init(); RenderingServerDefault::get_singleton()->set_render_loop_enabled(false); + // ThemeDB requires RenderingServer to initialize the default theme. + // So we have to do this for each test case. Also make sure there is + // no residual theme from something else. + ThemeDB::get_singleton()->finalize_theme(); + ThemeDB::get_singleton()->initialize_theme_noproject(); + physics_server_3d = PhysicsServer3DManager::get_singleton()->new_default_server(); physics_server_3d->init(); @@ -252,9 +257,6 @@ struct GodotTestCaseListener : public doctest::IReporter { memnew(InputMap); InputMap::get_singleton()->load_default(); - theme_db = memnew(ThemeDB); - theme_db->initialize_theme_noproject(); - memnew(SceneTree); SceneTree::get_singleton()->initialize(); if (!DisplayServer::get_singleton()->has_feature(DisplayServer::Feature::FEATURE_SUBWINDOWS)) { @@ -294,11 +296,6 @@ struct GodotTestCaseListener : public doctest::IReporter { memdelete(SceneTree::get_singleton()); } - if (theme_db) { - memdelete(theme_db); - theme_db = nullptr; - } - if (navigation_server_3d) { memdelete(navigation_server_3d); navigation_server_3d = nullptr; @@ -326,6 +323,10 @@ struct GodotTestCaseListener : public doctest::IReporter { } if (RenderingServer::get_singleton()) { + // ThemeDB requires RenderingServer to finalize the default theme. + // So we have to do this for each test case. + ThemeDB::get_singleton()->finalize_theme(); + RenderingServer::get_singleton()->sync(); RenderingServer::get_singleton()->global_shader_parameters_clear(); RenderingServer::get_singleton()->finish(); |
