summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/SCsub3
-rw-r--r--tests/core/string/test_string.h56
-rw-r--r--tests/core/variant/test_array.h18
-rw-r--r--tests/scene/test_code_edit.h25
-rw-r--r--tests/scene/test_text_edit.h48
-rw-r--r--tests/scene/test_viewport.h7
-rw-r--r--tests/test_main.cpp8
7 files changed, 163 insertions, 2 deletions
diff --git a/tests/SCsub b/tests/SCsub
index d96a1142e4..169c7c1efa 100644
--- a/tests/SCsub
+++ b/tests/SCsub
@@ -1,4 +1,5 @@
-#!/usr/bin/python
+#!/usr/bin/env python
+from misc.utility.scons_hints import *
Import("env")
diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h
index a9f615af84..0131f4c02a 100644
--- a/tests/core/string/test_string.h
+++ b/tests/core/string/test_string.h
@@ -1888,7 +1888,7 @@ TEST_CASE("[String] validate_node_name") {
CHECK(name_with_invalid_chars.validate_node_name() == "Name with invalid characters ____removed!");
}
-TEST_CASE("[String] validate_identifier") {
+TEST_CASE("[String] validate_ascii_identifier") {
String empty_string;
CHECK(empty_string.validate_ascii_identifier() == "_");
@@ -1902,6 +1902,20 @@ TEST_CASE("[String] validate_identifier") {
CHECK(name_with_invalid_chars.validate_ascii_identifier() == "Invalid_characters_______");
}
+TEST_CASE("[String] validate_unicode_identifier") {
+ String empty_string;
+ CHECK(empty_string.validate_unicode_identifier() == "_");
+
+ String numeric_only = "12345";
+ CHECK(numeric_only.validate_unicode_identifier() == "_12345");
+
+ String name_with_spaces = "Name with spaces";
+ CHECK(name_with_spaces.validate_unicode_identifier() == "Name_with_spaces");
+
+ String name_with_invalid_chars = U"Invalid characters:@*#&世界";
+ CHECK(name_with_invalid_chars.validate_unicode_identifier() == U"Invalid_characters_____世界");
+}
+
TEST_CASE("[String] Variant indexed get") {
Variant s = String("abcd");
bool valid = false;
@@ -1974,6 +1988,46 @@ TEST_CASE("[String] Variant ptr indexed set") {
CHECK_EQ(s, String("azcd"));
}
+TEST_CASE("[String] parse_url") {
+ String scheme, host, path, fragment;
+ int port;
+
+ SUBCASE("Typical URL") {
+ Error err = String("https://docs.godotengine.org/en/stable/").parse_url(scheme, host, port, path, fragment);
+ REQUIRE(err == OK);
+ CHECK_EQ(scheme, "https://");
+ CHECK_EQ(host, "docs.godotengine.org");
+ CHECK_EQ(port, 0);
+ CHECK_EQ(path, "/en/stable/");
+ CHECK_EQ(fragment, "");
+ }
+
+ SUBCASE("All Elements") {
+ Error err = String("https://www.example.com:8080/path/to/file.html#fragment").parse_url(scheme, host, port, path, fragment);
+ REQUIRE(err == OK);
+ CHECK_EQ(scheme, "https://");
+ CHECK_EQ(host, "www.example.com");
+ CHECK_EQ(port, 8080);
+ CHECK_EQ(path, "/path/to/file.html");
+ CHECK_EQ(fragment, "fragment");
+ }
+
+ SUBCASE("Invalid Scheme") {
+ Error err = String("http_://example.com").parse_url(scheme, host, port, path, fragment);
+ REQUIRE(err == ERR_INVALID_PARAMETER); // Host being empty is an error.
+ }
+
+ SUBCASE("Scheme vs Fragment") {
+ Error err = String("google.com/#goto=http://redirect_url/").parse_url(scheme, host, port, path, fragment);
+ REQUIRE(err == OK);
+ CHECK_EQ(scheme, "");
+ CHECK_EQ(host, "google.com");
+ CHECK_EQ(port, 0);
+ CHECK_EQ(path, "/");
+ CHECK_EQ(fragment, "goto=http://redirect_url/");
+ }
+}
+
TEST_CASE("[Stress][String] Empty via ' == String()'") {
for (int i = 0; i < 100000; ++i) {
String str = "Hello World!";
diff --git a/tests/core/variant/test_array.h b/tests/core/variant/test_array.h
index 787b8f39d9..15e2cebe09 100644
--- a/tests/core/variant/test_array.h
+++ b/tests/core/variant/test_array.h
@@ -634,6 +634,24 @@ TEST_CASE("[Array] Typed copying") {
a6.clear();
}
+static bool _find_custom_callable(const Variant &p_val) {
+ return (int)p_val % 2 == 0;
+}
+
+TEST_CASE("[Array] Test find_custom") {
+ Array a1 = build_array(1, 3, 4, 5, 8, 9);
+ // Find first even number.
+ int index = a1.find_custom(callable_mp_static(_find_custom_callable));
+ CHECK_EQ(index, 2);
+}
+
+TEST_CASE("[Array] Test rfind_custom") {
+ Array a1 = build_array(1, 3, 4, 5, 8, 9);
+ // Find last even number.
+ int index = a1.rfind_custom(callable_mp_static(_find_custom_callable));
+ CHECK_EQ(index, 4);
+}
+
} // namespace TestArray
#endif // TEST_ARRAY_H
diff --git a/tests/scene/test_code_edit.h b/tests/scene/test_code_edit.h
index 9ec1b812df..ef630ad4f7 100644
--- a/tests/scene/test_code_edit.h
+++ b/tests/scene/test_code_edit.h
@@ -4779,6 +4779,31 @@ TEST_CASE("[SceneTree][CodeEdit] text manipulation") {
CHECK(code_edit->get_caret_column(3) == 0);
}
+ SUBCASE("[SceneTree][CodeEdit] cut when empty selection clipboard disabled") {
+ DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton());
+ code_edit->set_empty_selection_clipboard_enabled(false);
+ DS->clipboard_set("");
+
+ code_edit->set_text("this is\nsome\n");
+ code_edit->set_caret_line(0);
+ code_edit->set_caret_column(6);
+ MessageQueue::get_singleton()->flush();
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ code_edit->cut();
+ MessageQueue::get_singleton()->flush();
+ CHECK(DS->clipboard_get() == "");
+ CHECK(code_edit->get_text() == "this is\nsome\n");
+ CHECK(code_edit->get_caret_line() == 0);
+ CHECK(code_edit->get_caret_column() == 6);
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ }
+
SUBCASE("[SceneTree][CodeEdit] new line") {
// Add a new line.
code_edit->set_text("test new line");
diff --git a/tests/scene/test_text_edit.h b/tests/scene/test_text_edit.h
index 46a5046b21..c41eebdf3a 100644
--- a/tests/scene/test_text_edit.h
+++ b/tests/scene/test_text_edit.h
@@ -3585,6 +3585,54 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
SIGNAL_CHECK_FALSE("lines_edited_from");
}
+ SUBCASE("[TextEdit] cut when empty selection clipboard disabled") {
+ text_edit->set_empty_selection_clipboard_enabled(false);
+ DS->clipboard_set("");
+
+ text_edit->set_text("this is\nsome\n");
+ text_edit->set_caret_line(0);
+ text_edit->set_caret_column(6);
+ MessageQueue::get_singleton()->flush();
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ text_edit->cut();
+ MessageQueue::get_singleton()->flush();
+ CHECK(DS->clipboard_get() == "");
+ CHECK(text_edit->get_text() == "this is\nsome\n");
+ CHECK(text_edit->get_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 6);
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ }
+
+ SUBCASE("[TextEdit] copy when empty selection clipboard disabled") {
+ text_edit->set_empty_selection_clipboard_enabled(false);
+ DS->clipboard_set("");
+
+ text_edit->set_text("this is\nsome\n");
+ text_edit->set_caret_line(0);
+ text_edit->set_caret_column(6);
+ MessageQueue::get_singleton()->flush();
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ text_edit->copy();
+ MessageQueue::get_singleton()->flush();
+ CHECK(DS->clipboard_get() == "");
+ CHECK(text_edit->get_text() == "this is\nsome\n");
+ CHECK(text_edit->get_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 6);
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ }
+
SIGNAL_UNWATCH(text_edit, "text_set");
SIGNAL_UNWATCH(text_edit, "text_changed");
SIGNAL_UNWATCH(text_edit, "lines_edited_from");
diff --git a/tests/scene/test_viewport.h b/tests/scene/test_viewport.h
index 9d02c41719..dde37944ec 100644
--- a/tests/scene/test_viewport.h
+++ b/tests/scene/test_viewport.h
@@ -38,6 +38,7 @@
#include "scene/main/canvas_layer.h"
#include "scene/main/window.h"
#include "scene/resources/2d/rectangle_shape_2d.h"
+#include "servers/physics_server_2d_dummy.h"
#include "tests/test_macros.h"
@@ -1550,6 +1551,12 @@ int TestArea2D::counter = 0;
TEST_CASE("[SceneTree][Viewport] Physics Picking 2D") {
// FIXME: MOUSE_MODE_CAPTURED if-conditions are not testable, because DisplayServerMock doesn't support it.
+ // NOTE: This test requires a real physics server.
+ PhysicsServer2DDummy *physics_server_2d_dummy = Object::cast_to<PhysicsServer2DDummy>(PhysicsServer2D::get_singleton());
+ if (physics_server_2d_dummy) {
+ return;
+ }
+
struct PickingCollider {
TestArea2D *a;
CollisionShape2D *c;
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 949e4f0b33..12ff3ad4bc 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -174,8 +174,10 @@
#include "servers/navigation_server_3d.h"
#endif // _3D_DISABLED
#include "servers/physics_server_2d.h"
+#include "servers/physics_server_2d_dummy.h"
#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h"
+#include "servers/physics_server_3d_dummy.h"
#endif // _3D_DISABLED
#include "servers/rendering/rendering_server_default.h"
@@ -290,10 +292,16 @@ struct GodotTestCaseListener : public doctest::IReporter {
#ifndef _3D_DISABLED
physics_server_3d = PhysicsServer3DManager::get_singleton()->new_default_server();
+ if (!physics_server_3d) {
+ physics_server_3d = memnew(PhysicsServer3DDummy);
+ }
physics_server_3d->init();
#endif // _3D_DISABLED
physics_server_2d = PhysicsServer2DManager::get_singleton()->new_default_server();
+ if (!physics_server_2d) {
+ physics_server_2d = memnew(PhysicsServer2DDummy);
+ }
physics_server_2d->init();
#ifndef _3D_DISABLED