summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/SCsub9
-rw-r--r--tests/core/io/test_config_file.h6
-rw-r--r--tests/core/io/test_file_access.h8
-rw-r--r--tests/core/io/test_image.h53
-rw-r--r--tests/core/io/test_json.h4
-rw-r--r--tests/core/io/test_marshalls.h4
-rw-r--r--tests/core/io/test_pck_packer.h8
-rw-r--r--tests/core/io/test_resource.h20
-rw-r--r--tests/core/io/test_xml_parser.h4
-rw-r--r--tests/core/math/test_aabb.h4
-rw-r--r--tests/core/math/test_astar.h26
-rw-r--r--tests/core/math/test_basis.h18
-rw-r--r--tests/core/math/test_color.h28
-rw-r--r--tests/core/math/test_expression.h6
-rw-r--r--tests/core/math/test_geometry_2d.h305
-rw-r--r--tests/core/math/test_geometry_3d.h8
-rw-r--r--tests/core/math/test_math.cpp690
-rw-r--r--tests/core/math/test_math.h41
-rw-r--r--tests/core/math/test_plane.h172
-rw-r--r--tests/core/math/test_random_number_generator.h4
-rw-r--r--tests/core/math/test_rect2.h276
-rw-r--r--tests/core/math/test_rect2i.h311
-rw-r--r--tests/core/math/test_vector2.h389
-rw-r--r--tests/core/math/test_vector2i.h145
-rw-r--r--tests/core/math/test_vector3.h417
-rw-r--r--tests/core/math/test_vector3i.h145
-rw-r--r--tests/core/object/test_class_db.h53
-rw-r--r--tests/core/object/test_method_bind.h20
-rw-r--r--tests/core/object/test_object.h12
-rw-r--r--tests/core/os/test_os.h158
-rw-r--r--tests/core/string/test_node_path.h4
-rw-r--r--tests/core/string/test_string.h180
-rw-r--r--tests/core/string/test_translation.h6
-rw-r--r--tests/core/templates/test_command_queue.h4
-rw-r--r--tests/core/templates/test_hash_map.h (renamed from tests/core/templates/test_ordered_hash_map.h)70
-rw-r--r--tests/core/templates/test_hash_set.h228
-rw-r--r--tests/core/templates/test_list.h4
-rw-r--r--tests/core/templates/test_local_vector.h15
-rw-r--r--tests/core/templates/test_lru.h4
-rw-r--r--tests/core/templates/test_oa_hash_map.cpp301
-rw-r--r--tests/core/templates/test_oa_hash_map.h41
-rw-r--r--tests/core/templates/test_paged_array.h4
-rw-r--r--tests/core/templates/test_vector.h40
-rw-r--r--tests/core/test_crypto.h4
-rw-r--r--tests/core/test_hashing_context.h4
-rw-r--r--tests/core/test_time.h17
-rw-r--r--tests/core/threads/test_worker_thread_pool.h158
-rw-r--r--tests/core/variant/test_array.h39
-rw-r--r--tests/core/variant/test_dictionary.h6
-rw-r--r--tests/core/variant/test_variant.h4
-rw-r--r--tests/scene/test_animation.h314
-rw-r--r--tests/scene/test_code_edit.h740
-rw-r--r--tests/scene/test_curve.h4
-rw-r--r--tests/scene/test_gradient.h4
-rw-r--r--tests/scene/test_gui.cpp259
-rw-r--r--tests/scene/test_gui.h41
-rw-r--r--tests/scene/test_path_3d.h6
-rw-r--r--tests/scene/test_path_follow_2d.h4
-rw-r--r--tests/scene/test_path_follow_3d.h4
-rw-r--r--tests/scene/test_text_edit.h3528
-rw-r--r--tests/scene/test_theme.h257
-rw-r--r--tests/servers/test_physics_2d.cpp398
-rw-r--r--tests/servers/test_physics_2d.h41
-rw-r--r--tests/servers/test_physics_3d.cpp410
-rw-r--r--tests/servers/test_physics_3d.h41
-rw-r--r--tests/servers/test_render.cpp232
-rw-r--r--tests/servers/test_render.h41
-rw-r--r--tests/servers/test_shader_lang.cpp367
-rw-r--r--tests/servers/test_shader_lang.h41
-rw-r--r--tests/servers/test_text_server.h312
-rw-r--r--tests/test_macros.cpp8
-rw-r--r--tests/test_macros.h134
-rw-r--r--tests/test_main.cpp98
-rw-r--r--tests/test_main.h4
-rw-r--r--tests/test_tools.h4
-rw-r--r--tests/test_utils.cpp4
-rw-r--r--tests/test_utils.h4
-rw-r--r--tests/test_validate_testing.h4
78 files changed, 7867 insertions, 3914 deletions
diff --git a/tests/SCsub b/tests/SCsub
index 31466fffc1..c59ce69b92 100644
--- a/tests/SCsub
+++ b/tests/SCsub
@@ -6,10 +6,6 @@ env.tests_sources = []
env_tests = env.Clone()
-# Include GDNative headers.
-if env["module_gdnative_enabled"]:
- env_tests.Append(CPPPATH=["#modules/gdnative/include"])
-
# We must disable the THREAD_LOCAL entirely in doctest to prevent crashes on debugging
# Since we link with /MT thread_local is always expired when the header is used
# So the debugger crashes the engine and it causes weird errors
@@ -22,11 +18,6 @@ if env_tests["platform"] == "windows":
if env_tests.msvc:
env_tests.Append(CCFLAGS=["/bigobj"])
-env_tests.add_source_files(env.tests_sources, "core/*.cpp")
-env_tests.add_source_files(env.tests_sources, "core/math/*.cpp")
-env_tests.add_source_files(env.tests_sources, "core/templates/*.cpp")
-env_tests.add_source_files(env.tests_sources, "scene/*.cpp")
-env_tests.add_source_files(env.tests_sources, "servers/*.cpp")
env_tests.add_source_files(env.tests_sources, "*.cpp")
lib = env_tests.add_library("tests", env.tests_sources)
diff --git a/tests/core/io/test_config_file.h b/tests/core/io/test_config_file.h
index f6fbaf9a88..355aca479e 100644
--- a/tests/core/io/test_config_file.h
+++ b/tests/core/io/test_config_file.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -155,7 +155,7 @@ antiAliasing=false
"a=b"=7
)");
- FileAccessRef file = FileAccess::open(config_path, FileAccess::READ);
+ Ref<FileAccess> file = FileAccess::open(config_path, FileAccess::READ);
CHECK_MESSAGE(file->get_as_utf8_string() == contents,
"The saved configuration file should match the expected format.");
}
diff --git a/tests/core/io/test_file_access.h b/tests/core/io/test_file_access.h
index f566899c9b..f0e1cceacf 100644
--- a/tests/core/io/test_file_access.h
+++ b/tests/core/io/test_file_access.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -38,7 +38,7 @@
namespace TestFileAccess {
TEST_CASE("[FileAccess] CSV read") {
- FileAccessRef f = FileAccess::open(TestUtils::get_data_path("translations.csv"), FileAccess::READ);
+ Ref<FileAccess> f = FileAccess::open(TestUtils::get_data_path("translations.csv"), FileAccess::READ);
Vector<String> header = f->get_csv_line(); // Default delimiter: ",".
REQUIRE(header.size() == 3);
@@ -77,8 +77,6 @@ TEST_CASE("[FileAccess] CSV read") {
CHECK(row5[0] == "What about");
CHECK(row5[1] == "tab separated");
CHECK(row5[2] == "lines, good?");
-
- f->close();
}
} // namespace TestFileAccess
diff --git a/tests/core/io/test_image.h b/tests/core/io/test_image.h
index 643d2f31ec..36e6b83bfd 100644
--- a/tests/core/io/test_image.h
+++ b/tests/core/io/test_image.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -106,7 +106,7 @@ TEST_CASE("[Image] Saving and loading") {
// Load BMP
Ref<Image> image_bmp = memnew(Image());
- FileAccessRef f_bmp = FileAccess::open(TestUtils::get_data_path("images/icon.bmp"), FileAccess::READ, &err);
+ Ref<FileAccess> f_bmp = FileAccess::open(TestUtils::get_data_path("images/icon.bmp"), FileAccess::READ, &err);
PackedByteArray data_bmp;
data_bmp.resize(f_bmp->get_length() + 1);
f_bmp->get_buffer(data_bmp.ptrw(), f_bmp->get_length());
@@ -116,7 +116,7 @@ TEST_CASE("[Image] Saving and loading") {
// Load JPG
Ref<Image> image_jpg = memnew(Image());
- FileAccessRef f_jpg = FileAccess::open(TestUtils::get_data_path("images/icon.jpg"), FileAccess::READ, &err);
+ Ref<FileAccess> f_jpg = FileAccess::open(TestUtils::get_data_path("images/icon.jpg"), FileAccess::READ, &err);
PackedByteArray data_jpg;
data_jpg.resize(f_jpg->get_length() + 1);
f_jpg->get_buffer(data_jpg.ptrw(), f_jpg->get_length());
@@ -126,7 +126,7 @@ TEST_CASE("[Image] Saving and loading") {
// Load WEBP
Ref<Image> image_webp = memnew(Image());
- FileAccessRef f_webp = FileAccess::open(TestUtils::get_data_path("images/icon.webp"), FileAccess::READ, &err);
+ Ref<FileAccess> f_webp = FileAccess::open(TestUtils::get_data_path("images/icon.webp"), FileAccess::READ, &err);
PackedByteArray data_webp;
data_webp.resize(f_webp->get_length() + 1);
f_webp->get_buffer(data_webp.ptrw(), f_webp->get_length());
@@ -136,7 +136,7 @@ TEST_CASE("[Image] Saving and loading") {
// Load PNG
Ref<Image> image_png = memnew(Image());
- FileAccessRef f_png = FileAccess::open(TestUtils::get_data_path("images/icon.png"), FileAccess::READ, &err);
+ Ref<FileAccess> f_png = FileAccess::open(TestUtils::get_data_path("images/icon.png"), FileAccess::READ, &err);
PackedByteArray data_png;
data_png.resize(f_png->get_length() + 1);
f_png->get_buffer(data_png.ptrw(), f_png->get_length());
@@ -146,7 +146,7 @@ TEST_CASE("[Image] Saving and loading") {
// Load TGA
Ref<Image> image_tga = memnew(Image());
- FileAccessRef f_tga = FileAccess::open(TestUtils::get_data_path("images/icon.tga"), FileAccess::READ, &err);
+ Ref<FileAccess> f_tga = FileAccess::open(TestUtils::get_data_path("images/icon.tga"), FileAccess::READ, &err);
PackedByteArray data_tga;
data_tga.resize(f_tga->get_length() + 1);
f_tga->get_buffer(data_tga.ptrw(), f_tga->get_length());
@@ -161,8 +161,8 @@ TEST_CASE("[Image] Basic getters") {
CHECK(image->get_height() == 4);
CHECK(image->get_size() == Vector2(8, 4));
CHECK(image->get_format() == Image::FORMAT_LA8);
- CHECK(image->get_used_rect() == Rect2(0, 0, 0, 0));
- Ref<Image> image_get_rect = image->get_rect(Rect2(0, 0, 2, 1));
+ CHECK(image->get_used_rect() == Rect2i(0, 0, 0, 0));
+ Ref<Image> image_get_rect = image->get_rect(Rect2i(0, 0, 2, 1));
CHECK(image_get_rect->get_size() == Vector2(2, 1));
}
@@ -213,8 +213,8 @@ TEST_CASE("[Image] Modifying pixels of an image") {
image->get_pixelv(Vector2(0, 0)).is_equal_approx(Color(1, 1, 1, 1)),
"Image's get_pixel() should return the same color value as the one being set with set_pixel() in the same position.");
CHECK_MESSAGE(
- image->get_used_rect() == Rect2(0, 0, 1, 1),
- "Image's get_used_rect should return the expected value, larger than Rect2(0, 0, 0, 0) if it's visible.");
+ image->get_used_rect() == Rect2i(0, 0, 1, 1),
+ "Image's get_used_rect should return the expected value, larger than Rect2i(0, 0, 0, 0) if it's visible.");
image->set_pixelv(Vector2(0, 0), Color(0.5, 0.5, 0.5, 0.5));
Ref<Image> image2 = memnew(Image(3, 3, false, Image::FORMAT_RGBA8));
@@ -233,19 +233,19 @@ TEST_CASE("[Image] Modifying pixels of an image") {
{
const int img_width = 3;
const int img_height = 3;
- Vector<Rect2> rects;
- rects.push_back(Rect2());
- rects.push_back(Rect2(-5, -5, 3, 3));
- rects.push_back(Rect2(img_width, 0, 12, 12));
- rects.push_back(Rect2(0, img_height, 12, 12));
- rects.push_back(Rect2(img_width + 1, img_height + 2, 12, 12));
- rects.push_back(Rect2(1, 1, 1, 1));
- rects.push_back(Rect2(0, 1, 2, 3));
- rects.push_back(Rect2(-5, 0, img_width + 10, 2));
- rects.push_back(Rect2(0, -5, 2, img_height + 10));
- rects.push_back(Rect2(-1, -1, img_width + 1, img_height + 1));
-
- for (const Rect2 &rect : rects) {
+ Vector<Rect2i> rects;
+ rects.push_back(Rect2i());
+ rects.push_back(Rect2i(-5, -5, 3, 3));
+ rects.push_back(Rect2i(img_width, 0, 12, 12));
+ rects.push_back(Rect2i(0, img_height, 12, 12));
+ rects.push_back(Rect2i(img_width + 1, img_height + 2, 12, 12));
+ rects.push_back(Rect2i(1, 1, 1, 1));
+ rects.push_back(Rect2i(0, 1, 2, 3));
+ rects.push_back(Rect2i(-5, 0, img_width + 10, 2));
+ rects.push_back(Rect2i(0, -5, 2, img_height + 10));
+ rects.push_back(Rect2i(-1, -1, img_width + 1, img_height + 1));
+
+ for (const Rect2i &rect : rects) {
Ref<Image> img = memnew(Image(img_width, img_height, false, Image::FORMAT_RGBA8));
CHECK_NOTHROW_MESSAGE(
img->fill_rect(rect, Color(1, 1, 1, 1)),
@@ -267,7 +267,7 @@ TEST_CASE("[Image] Modifying pixels of an image") {
}
// Blend two images together
- image->blend_rect(image2, Rect2(Vector2(0, 0), image2->get_size()), Vector2(0, 0));
+ image->blend_rect(image2, Rect2i(Vector2i(0, 0), image2->get_size()), Vector2i(0, 0));
CHECK_MESSAGE(
image->get_pixel(0, 0).a > 0.7,
"blend_rect() should blend the alpha values of the two images.");
@@ -279,7 +279,7 @@ TEST_CASE("[Image] Modifying pixels of an image") {
image3->set_pixel(0, 0, Color(0, 1, 0, 1));
//blit_rect() two images together
- image->blit_rect(image3, Rect2(Vector2(0, 0), image3->get_size()), Vector2(0, 0));
+ image->blit_rect(image3, Rect2i(Vector2i(0, 0), image3->get_size()), Vector2i(0, 0));
CHECK_MESSAGE(
image->get_pixel(0, 0).is_equal_approx(Color(0, 1, 0, 1)),
"blit_rect() should replace old colors and not blend them.");
@@ -300,4 +300,5 @@ TEST_CASE("[Image] Modifying pixels of an image") {
"flip_y() should not leave old pixels behind.");
}
} // namespace TestImage
+
#endif // TEST_IMAGE_H
diff --git a/tests/core/io/test_json.h b/tests/core/io/test_json.h
index 3af58dfa1c..478cf1766e 100644
--- a/tests/core/io/test_json.h
+++ b/tests/core/io/test_json.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/core/io/test_marshalls.h b/tests/core/io/test_marshalls.h
index 6bd916164e..546a2e9358 100644
--- a/tests/core/io/test_marshalls.h
+++ b/tests/core/io/test_marshalls.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/core/io/test_pck_packer.h b/tests/core/io/test_pck_packer.h
index 75a4abffbe..d21fbdaf50 100644
--- a/tests/core/io/test_pck_packer.h
+++ b/tests/core/io/test_pck_packer.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -52,7 +52,7 @@ TEST_CASE("[PCKPacker] Pack an empty PCK file") {
"Flushing the PCK should return an OK error code.");
Error err;
- FileAccessRef f = FileAccess::open(output_pck_path, FileAccess::READ, &err);
+ Ref<FileAccess> f = FileAccess::open(output_pck_path, FileAccess::READ, &err);
CHECK_MESSAGE(
err == OK,
"The generated empty PCK file should be opened successfully.");
@@ -106,7 +106,7 @@ TEST_CASE("[PCKPacker] Pack a PCK file with some files and directories") {
"Flushing the PCK should return an OK error code.");
Error err;
- FileAccessRef f = FileAccess::open(output_pck_path, FileAccess::READ, &err);
+ Ref<FileAccess> f = FileAccess::open(output_pck_path, FileAccess::READ, &err);
CHECK_MESSAGE(
err == OK,
"The generated non-empty PCK file should be opened successfully.");
diff --git a/tests/core/io/test_resource.h b/tests/core/io/test_resource.h
index cee3281995..c880ca7d2a 100644
--- a/tests/core/io/test_resource.h
+++ b/tests/core/io/test_resource.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -28,8 +28,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef TEST_RESOURCE
-#define TEST_RESOURCE
+#ifndef TEST_RESOURCE_H
+#define TEST_RESOURCE_H
#include "core/io/resource.h"
#include "core/io/resource_loader.h"
@@ -69,22 +69,22 @@ TEST_CASE("[Resource] Duplication") {
TEST_CASE("[Resource] Saving and loading") {
Ref<Resource> resource = memnew(Resource);
resource->set_name("Hello world");
- resource->set_meta(" ExampleMetadata ", Vector2i(40, 80));
+ resource->set_meta("ExampleMetadata", Vector2i(40, 80));
resource->set_meta("string", "The\nstring\nwith\nunnecessary\nline\n\t\\\nbreaks");
Ref<Resource> child_resource = memnew(Resource);
child_resource->set_name("I'm a child resource");
resource->set_meta("other_resource", child_resource);
const String save_path_binary = OS::get_singleton()->get_cache_path().plus_file("resource.res");
const String save_path_text = OS::get_singleton()->get_cache_path().plus_file("resource.tres");
- ResourceSaver::save(save_path_binary, resource);
- ResourceSaver::save(save_path_text, resource);
+ ResourceSaver::save(resource, save_path_binary);
+ ResourceSaver::save(resource, save_path_text);
const Ref<Resource> &loaded_resource_binary = ResourceLoader::load(save_path_binary);
CHECK_MESSAGE(
loaded_resource_binary->get_name() == "Hello world",
"The loaded resource name should be equal to the expected value.");
CHECK_MESSAGE(
- loaded_resource_binary->get_meta(" ExampleMetadata ") == Vector2i(40, 80),
+ loaded_resource_binary->get_meta("ExampleMetadata") == Vector2i(40, 80),
"The loaded resource metadata should be equal to the expected value.");
CHECK_MESSAGE(
loaded_resource_binary->get_meta("string") == "The\nstring\nwith\nunnecessary\nline\n\t\\\nbreaks",
@@ -99,7 +99,7 @@ TEST_CASE("[Resource] Saving and loading") {
loaded_resource_text->get_name() == "Hello world",
"The loaded resource name should be equal to the expected value.");
CHECK_MESSAGE(
- loaded_resource_text->get_meta(" ExampleMetadata ") == Vector2i(40, 80),
+ loaded_resource_text->get_meta("ExampleMetadata") == Vector2i(40, 80),
"The loaded resource metadata should be equal to the expected value.");
CHECK_MESSAGE(
loaded_resource_text->get_meta("string") == "The\nstring\nwith\nunnecessary\nline\n\t\\\nbreaks",
@@ -111,4 +111,4 @@ TEST_CASE("[Resource] Saving and loading") {
}
} // namespace TestResource
-#endif // TEST_RESOURCE
+#endif // TEST_RESOURCE_H
diff --git a/tests/core/io/test_xml_parser.h b/tests/core/io/test_xml_parser.h
index 2d00f29ddf..87592b56ce 100644
--- a/tests/core/io/test_xml_parser.h
+++ b/tests/core/io/test_xml_parser.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/core/math/test_aabb.h b/tests/core/math/test_aabb.h
index f5076ce1ed..526972a82f 100644
--- a/tests/core/math/test_aabb.h
+++ b/tests/core/math/test_aabb.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/core/math/test_astar.h b/tests/core/math/test_astar.h
index 2c183374ac..9f5e98ef94 100644
--- a/tests/core/math/test_astar.h
+++ b/tests/core/math/test_astar.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -37,7 +37,7 @@
namespace TestAStar {
-class ABCX : public AStar {
+class ABCX : public AStar3D {
public:
enum {
A,
@@ -58,7 +58,7 @@ public:
}
// Disable heuristic completely.
- real_t _compute_cost(int p_from, int p_to) {
+ real_t _compute_cost(int64_t p_from, int64_t p_to) {
if (p_from == A && p_to == C) {
return 1000;
}
@@ -66,18 +66,18 @@ public:
}
};
-TEST_CASE("[AStar] ABC path") {
+TEST_CASE("[AStar3D] ABC path") {
ABCX abcx;
- Vector<int> path = abcx.get_id_path(ABCX::A, ABCX::C);
+ Vector<int64_t> path = abcx.get_id_path(ABCX::A, ABCX::C);
REQUIRE(path.size() == 3);
CHECK(path[0] == ABCX::A);
CHECK(path[1] == ABCX::B);
CHECK(path[2] == ABCX::C);
}
-TEST_CASE("[AStar] ABCX path") {
+TEST_CASE("[AStar3D] ABCX path") {
ABCX abcx;
- Vector<int> path = abcx.get_id_path(ABCX::X, ABCX::C);
+ Vector<int64_t> path = abcx.get_id_path(ABCX::X, ABCX::C);
REQUIRE(path.size() == 4);
CHECK(path[0] == ABCX::X);
CHECK(path[1] == ABCX::A);
@@ -85,8 +85,8 @@ TEST_CASE("[AStar] ABCX path") {
CHECK(path[3] == ABCX::C);
}
-TEST_CASE("[AStar] Add/Remove") {
- AStar a;
+TEST_CASE("[AStar3D] Add/Remove") {
+ AStar3D a;
// Manual tests.
a.add_point(1, Vector3(0, 0, 0));
@@ -213,13 +213,13 @@ TEST_CASE("[AStar] Add/Remove") {
// It's been great work, cheers. \(^ ^)/
}
-TEST_CASE("[Stress][AStar] Find paths") {
+TEST_CASE("[Stress][AStar3D] Find paths") {
// Random stress tests with Floyd-Warshall.
const int N = 30;
Math::seed(0);
for (int test = 0; test < 1000; test++) {
- AStar a;
+ AStar3D a;
Vector3 p[N];
bool adj[N][N] = { { false } };
@@ -318,7 +318,7 @@ TEST_CASE("[Stress][AStar] Find paths") {
for (int u = 0; u < N; u++) {
for (int v = 0; v < N; v++) {
if (u != v) {
- Vector<int> route = a.get_id_path(u, v);
+ Vector<int64_t> route = a.get_id_path(u, v);
if (!Math::is_inf(d[u][v])) {
// Reachable.
if (route.size() == 0) {
diff --git a/tests/core/math/test_basis.h b/tests/core/math/test_basis.h
index 500c069a33..ae8ca4acde 100644
--- a/tests/core/math/test_basis.h
+++ b/tests/core/math/test_basis.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -164,9 +164,9 @@ void test_rotation(Vector3 deg_original_euler, RotOrder rot_order) {
Basis res = to_rotation.inverse() * rotation_from_computed_euler;
- CHECK_MESSAGE((res.get_axis(0) - Vector3(1.0, 0.0, 0.0)).length() <= 0.1, vformat("Fail due to X %s\n", String(res.get_axis(0))).utf8().ptr());
- CHECK_MESSAGE((res.get_axis(1) - Vector3(0.0, 1.0, 0.0)).length() <= 0.1, vformat("Fail due to Y %s\n", String(res.get_axis(1))).utf8().ptr());
- CHECK_MESSAGE((res.get_axis(2) - Vector3(0.0, 0.0, 1.0)).length() <= 0.1, vformat("Fail due to Z %s\n", String(res.get_axis(2))).utf8().ptr());
+ CHECK_MESSAGE((res.get_column(0) - Vector3(1.0, 0.0, 0.0)).length() <= 0.1, vformat("Fail due to X %s\n", String(res.get_column(0))).utf8().ptr());
+ CHECK_MESSAGE((res.get_column(1) - Vector3(0.0, 1.0, 0.0)).length() <= 0.1, vformat("Fail due to Y %s\n", String(res.get_column(1))).utf8().ptr());
+ 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);
@@ -175,9 +175,9 @@ void test_rotation(Vector3 deg_original_euler, RotOrder rot_order) {
res = to_rotation.inverse() * rotation_from_xyz_computed_euler;
- CHECK_MESSAGE((res.get_axis(0) - Vector3(1.0, 0.0, 0.0)).length() <= 0.1, vformat("Double check with XYZ rot order failed, due to X %s\n", String(res.get_axis(0))).utf8().ptr());
- CHECK_MESSAGE((res.get_axis(1) - Vector3(0.0, 1.0, 0.0)).length() <= 0.1, vformat("Double check with XYZ rot order failed, due to Y %s\n", String(res.get_axis(1))).utf8().ptr());
- CHECK_MESSAGE((res.get_axis(2) - Vector3(0.0, 0.0, 1.0)).length() <= 0.1, vformat("Double check with XYZ rot order failed, due to Z %s\n", String(res.get_axis(2))).utf8().ptr());
+ CHECK_MESSAGE((res.get_column(0) - Vector3(1.0, 0.0, 0.0)).length() <= 0.1, vformat("Double check with XYZ rot order failed, due to X %s\n", String(res.get_column(0))).utf8().ptr());
+ CHECK_MESSAGE((res.get_column(1) - Vector3(0.0, 1.0, 0.0)).length() <= 0.1, vformat("Double check with XYZ rot order failed, due to Y %s\n", String(res.get_column(1))).utf8().ptr());
+ CHECK_MESSAGE((res.get_column(2) - Vector3(0.0, 0.0, 1.0)).length() <= 0.1, vformat("Double check with XYZ rot order failed, due to Z %s\n", String(res.get_column(2))).utf8().ptr());
INFO(vformat("Rotation order: %s\n.", get_rot_order_name(rot_order)).utf8().ptr());
INFO(vformat("Original Rotation: %s\n", String(deg_original_euler)).utf8().ptr());
@@ -283,4 +283,4 @@ TEST_CASE("[Stress][Basis] Euler conversions") {
}
} // namespace TestBasis
-#endif
+#endif // TEST_BASIS_H
diff --git a/tests/core/math/test_color.h b/tests/core/math/test_color.h
index 82cf786f7a..51c3bc8bdc 100644
--- a/tests/core/math/test_color.h
+++ b/tests/core/math/test_color.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -144,17 +144,35 @@ TEST_CASE("[Color] Conversion methods") {
"The string representation should match the expected value.");
}
+TEST_CASE("[Color] Linear <-> sRGB conversion") {
+ const Color color = Color(0.35, 0.5, 0.6, 0.7);
+ const Color color_linear = color.srgb_to_linear();
+ const Color color_srgb = color.linear_to_srgb();
+ CHECK_MESSAGE(
+ color_linear.is_equal_approx(Color(0.100481, 0.214041, 0.318547, 0.7)),
+ "The color converted to linear color space should match the expected value.");
+ CHECK_MESSAGE(
+ color_srgb.is_equal_approx(Color(0.62621, 0.735357, 0.797738, 0.7)),
+ "The color converted to sRGB color space should match the expected value.");
+ CHECK_MESSAGE(
+ color_linear.linear_to_srgb().is_equal_approx(Color(0.35, 0.5, 0.6, 0.7)),
+ "The linear color converted back to sRGB color space should match the expected value.");
+ CHECK_MESSAGE(
+ color_srgb.srgb_to_linear().is_equal_approx(Color(0.35, 0.5, 0.6, 0.7)),
+ "The sRGB color converted back to linear color space should match the expected value.");
+}
+
TEST_CASE("[Color] Named colors") {
CHECK_MESSAGE(
- Color::named("red").is_equal_approx(Color(1, 0, 0)),
+ Color::named("red").is_equal_approx(Color::hex(0xFF0000FF)),
"The named color \"red\" should match the expected value.");
// Named colors have their names automatically normalized.
CHECK_MESSAGE(
- Color::named("white_smoke").is_equal_approx(Color(0.96, 0.96, 0.96)),
+ Color::named("white_smoke").is_equal_approx(Color::hex(0xF5F5F5FF)),
"The named color \"white_smoke\" should match the expected value.");
CHECK_MESSAGE(
- Color::named("Slate Blue").is_equal_approx(Color(0.42, 0.35, 0.80)),
+ Color::named("Slate Blue").is_equal_approx(Color::hex(0x6A5ACDFF)),
"The named color \"Slate Blue\" should match the expected value.");
ERR_PRINT_OFF;
diff --git a/tests/core/math/test_expression.h b/tests/core/math/test_expression.h
index cb1d29389f..6e3be541b0 100644
--- a/tests/core/math/test_expression.h
+++ b/tests/core/math/test_expression.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -137,7 +137,7 @@ TEST_CASE("[Expression] Scientific notation") {
expression.parse("2e5") == OK,
"The expression should parse successfully.");
CHECK_MESSAGE(
- Math::is_equal_approx(double(expression.execute()), 25),
+ Math::is_equal_approx(double(expression.execute()), 2e5),
"The expression 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 8f6669b572..db4e6e2177 100644
--- a/tests/core/math/test_geometry_2d.h
+++ b/tests/core/math/test_geometry_2d.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -135,7 +135,7 @@ TEST_CASE("[Geometry2D] Line intersection") {
"Parallel lines should not intersect.");
}
-TEST_CASE("[Geometry2D] Segment intersection.") {
+TEST_CASE("[Geometry2D] Segment intersection") {
Vector2 r;
CHECK(Geometry2D::segment_intersects_segment(Vector2(-1, 1), Vector2(1, -1), Vector2(1, 1), Vector2(-1, -1), &r));
@@ -148,6 +148,10 @@ TEST_CASE("[Geometry2D] Segment intersection.") {
Geometry2D::segment_intersects_segment(Vector2(-1, 1), Vector2(1, -1), Vector2(0, 1), Vector2(2, -1), &r),
"Parallel segments should not intersect.");
+ CHECK_FALSE_MESSAGE(
+ Geometry2D::segment_intersects_segment(Vector2(1, 2), Vector2(3, 2), Vector2(0, 2), Vector2(-2, 2), &r),
+ "Non-overlapping collinear segments should not intersect.");
+
CHECK_MESSAGE(
Geometry2D::segment_intersects_segment(Vector2(0, 0), Vector2(0, 1), Vector2(0, 0), Vector2(1, 0), &r),
"Touching segments should intersect.");
@@ -159,11 +163,114 @@ TEST_CASE("[Geometry2D] Segment intersection.") {
CHECK(r.is_equal_approx(Vector2(0, 0)));
}
+TEST_CASE("[Geometry2D] Segment intersection with circle") {
+ real_t minus_one = -1.0;
+ real_t zero = 0.0;
+ real_t one_quarter = 0.25;
+ real_t three_quarters = 0.75;
+ 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),
+ "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),
+ "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),
+ "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),
+ "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),
+ "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),
+ "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),
+ "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),
+ "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),
+ "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),
+ "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),
+ "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),
+ "Segment completely outside the circle should not intersect it");
+}
+
+TEST_CASE("[Geometry2D] Segment intersection with polygon") {
+ Vector<Point2> a;
+
+ a.push_back(Point2(-2, 2));
+ a.push_back(Point2(3, 4));
+ a.push_back(Point2(1, 1));
+ a.push_back(Point2(2, -2));
+ a.push_back(Point2(-1, -1));
+
+ CHECK_MESSAGE(
+ Geometry2D::is_segment_intersecting_polygon(Vector2(0, 2), Vector2(2, 2), a),
+ "Segment from inside to outside of polygon should intersect it.");
+ CHECK_MESSAGE(
+ Geometry2D::is_segment_intersecting_polygon(Vector2(2, 2), Vector2(0, 2), a),
+ "Segment from outside to inside of polygon should intersect it.");
+
+ CHECK_MESSAGE(
+ Geometry2D::is_segment_intersecting_polygon(Vector2(2, 4), Vector2(3, 3), a),
+ "Segment running through polygon should intersect it.");
+ CHECK_MESSAGE(
+ Geometry2D::is_segment_intersecting_polygon(Vector2(3, 3), Vector2(2, 4), a),
+ "Segment running through polygon should intersect it.");
+
+ CHECK_MESSAGE(
+ Geometry2D::is_segment_intersecting_polygon(Vector2(0, 0), Vector2(1, 1), a),
+ "Segment starting inside the polygon and ending on the polygon should intersect it");
+ CHECK_MESSAGE(
+ Geometry2D::is_segment_intersecting_polygon(Vector2(1, 1), Vector2(0, 0), a),
+ "Segment starting on the polygon and going inwards should intersect it");
+ CHECK_MESSAGE(
+ Geometry2D::is_segment_intersecting_polygon(Vector2(-2, 2), Vector2(-2, -1), a),
+ "Segment starting on the polygon and going outwards should intersect it");
+ CHECK_MESSAGE(
+ Geometry2D::is_segment_intersecting_polygon(Vector2(-2, 1), Vector2(-2, 2), a),
+ "Segment starting outside the polygon and ending on the polygon intersect it");
+
+ CHECK_FALSE_MESSAGE(
+ Geometry2D::is_segment_intersecting_polygon(Vector2(-1, 2), Vector2(1, -1), a),
+ "Segment completely within the polygon should not intersect it");
+ CHECK_FALSE_MESSAGE(
+ Geometry2D::is_segment_intersecting_polygon(Vector2(1, -1), Vector2(-1, 2), a),
+ "Segment completely within the polygon should not intersect it");
+ CHECK_FALSE_MESSAGE(
+ Geometry2D::is_segment_intersecting_polygon(Vector2(2, 2), Vector2(2, -1), a),
+ "Segment completely outside the polygon should not intersect it");
+ CHECK_FALSE_MESSAGE(
+ Geometry2D::is_segment_intersecting_polygon(Vector2(2, -1), Vector2(2, 2), a),
+ "Segment completely outside the polygon should not intersect it");
+}
+
TEST_CASE("[Geometry2D] Closest point to segment") {
Vector2 s[] = { Vector2(-4, -4), Vector2(4, 4) };
CHECK(Geometry2D::get_closest_point_to_segment(Vector2(4.1, 4.1), s).is_equal_approx(Vector2(4, 4)));
CHECK(Geometry2D::get_closest_point_to_segment(Vector2(-4.1, -4.1), s).is_equal_approx(Vector2(-4, -4)));
CHECK(Geometry2D::get_closest_point_to_segment(Vector2(-1, 1), s).is_equal_approx(Vector2(0, 0)));
+
+ Vector2 t[] = { Vector2(1, -2), Vector2(1, -2) };
+ CHECK_MESSAGE(
+ Geometry2D::get_closest_point_to_segment(Vector2(-3, 4), t).is_equal_approx(Vector2(1, -2)),
+ "Line segment is only a single point. This point should be the closest.");
}
TEST_CASE("[Geometry2D] Closest point to uncapped segment") {
@@ -186,6 +293,30 @@ TEST_CASE("[Geometry2D] Closest points between segments") {
Geometry2D::get_closest_points_between_segments(Vector2(-1, 1), Vector2(1, -1), Vector2(1, 1), Vector2(-1, -1), c1, c2);
CHECK(c1.is_equal_approx(Vector2(0, 0)));
CHECK(c2.is_equal_approx(Vector2(0, 0)));
+
+ Geometry2D::get_closest_points_between_segments(Vector2(-3, 4), Vector2(-3, 4), Vector2(-4, 3), Vector2(-2, 3), c1, c2);
+ CHECK_MESSAGE(
+ c1.is_equal_approx(Vector2(-3, 4)),
+ "1st line segment is only a point, this point should be the closest point to the 2nd line segment.");
+ CHECK_MESSAGE(
+ c2.is_equal_approx(Vector2(-3, 3)),
+ "1st line segment is only a point, this should not matter when determining the closest point on the 2nd line segment.");
+
+ Geometry2D::get_closest_points_between_segments(Vector2(-4, 3), Vector2(-2, 3), Vector2(-3, 4), Vector2(-3, 4), c1, c2);
+ CHECK_MESSAGE(
+ c1.is_equal_approx(Vector2(-3, 3)),
+ "2nd line segment is only a point, this should not matter when determining the closest point on the 1st line segment.");
+ CHECK_MESSAGE(
+ c2.is_equal_approx(Vector2(-3, 4)),
+ "2nd line segment is only a point, this point should be the closest point to the 1st line segment.");
+
+ Geometry2D::get_closest_points_between_segments(Vector2(5, -4), Vector2(5, -4), Vector2(-2, 1), Vector2(-2, 1), c1, c2);
+ CHECK_MESSAGE(
+ c1.is_equal_approx(Vector2(5, -4)),
+ "Both line segments are only a point. On the 1st line segment, that point should be the closest point to the 2nd line segment.");
+ CHECK_MESSAGE(
+ c2.is_equal_approx(Vector2(-2, 1)),
+ "Both line segments are only a point. On the 2nd line segment, that point should be the closest point to the 1st line segment.");
}
TEST_CASE("[Geometry2D] Make atlas") {
@@ -562,6 +693,174 @@ TEST_CASE("[Geometry2D] Clip polyline with polygon") {
CHECK(r[1][1].is_equal_approx(Vector2(55, 70)));
}
}
+
+TEST_CASE("[Geometry2D] Convex hull") {
+ Vector<Point2> a;
+ Vector<Point2> r;
+
+ a.push_back(Point2(-4, -8));
+ a.push_back(Point2(-10, -4));
+ a.push_back(Point2(8, 2));
+ a.push_back(Point2(-6, 10));
+ a.push_back(Point2(-12, 4));
+ a.push_back(Point2(10, -8));
+ a.push_back(Point2(4, 8));
+
+ SUBCASE("[Geometry2D] No points") {
+ r = Geometry2D::convex_hull(Vector<Vector2>());
+
+ CHECK_MESSAGE(r.is_empty(), "The convex hull should be empty if there are no input points.");
+ }
+
+ SUBCASE("[Geometry2D] Single point") {
+ Vector<Point2> b;
+ b.push_back(Point2(4, -3));
+
+ r = Geometry2D::convex_hull(b);
+ REQUIRE_MESSAGE(r.size() == 1, "Convex hull should contain 1 point.");
+ CHECK(r[0].is_equal_approx(b[0]));
+ }
+
+ SUBCASE("[Geometry2D] All points form the convex hull") {
+ r = Geometry2D::convex_hull(a);
+ REQUIRE_MESSAGE(r.size() == 8, "Convex hull should contain 8 points.");
+ CHECK(r[0].is_equal_approx(Point2(-12, 4)));
+ CHECK(r[1].is_equal_approx(Point2(-10, -4)));
+ CHECK(r[2].is_equal_approx(Point2(-4, -8)));
+ CHECK(r[3].is_equal_approx(Point2(10, -8)));
+ CHECK(r[4].is_equal_approx(Point2(8, 2)));
+ CHECK(r[5].is_equal_approx(Point2(4, 8)));
+ CHECK(r[6].is_equal_approx(Point2(-6, 10)));
+ CHECK(r[7].is_equal_approx(Point2(-12, 4)));
+ }
+
+ SUBCASE("[Geometry2D] Add extra points inside original convex hull") {
+ a.push_back(Point2(-4, -8));
+ a.push_back(Point2(0, 0));
+ a.push_back(Point2(0, 8));
+ a.push_back(Point2(-10, -3));
+ a.push_back(Point2(9, -4));
+ a.push_back(Point2(6, 4));
+
+ r = Geometry2D::convex_hull(a);
+ REQUIRE_MESSAGE(r.size() == 8, "Convex hull should contain 8 points.");
+ CHECK(r[0].is_equal_approx(Point2(-12, 4)));
+ CHECK(r[1].is_equal_approx(Point2(-10, -4)));
+ CHECK(r[2].is_equal_approx(Point2(-4, -8)));
+ CHECK(r[3].is_equal_approx(Point2(10, -8)));
+ CHECK(r[4].is_equal_approx(Point2(8, 2)));
+ CHECK(r[5].is_equal_approx(Point2(4, 8)));
+ CHECK(r[6].is_equal_approx(Point2(-6, 10)));
+ CHECK(r[7].is_equal_approx(Point2(-12, 4)));
+ }
+
+ SUBCASE("[Geometry2D] Add extra points on border of original convex hull") {
+ a.push_back(Point2(9, -3));
+ a.push_back(Point2(-2, -8));
+
+ r = Geometry2D::convex_hull(a);
+ REQUIRE_MESSAGE(r.size() == 8, "Convex hull should contain 8 points.");
+ CHECK(r[0].is_equal_approx(Point2(-12, 4)));
+ CHECK(r[1].is_equal_approx(Point2(-10, -4)));
+ CHECK(r[2].is_equal_approx(Point2(-4, -8)));
+ CHECK(r[3].is_equal_approx(Point2(10, -8)));
+ CHECK(r[4].is_equal_approx(Point2(8, 2)));
+ CHECK(r[5].is_equal_approx(Point2(4, 8)));
+ CHECK(r[6].is_equal_approx(Point2(-6, 10)));
+ CHECK(r[7].is_equal_approx(Point2(-12, 4)));
+ }
+
+ SUBCASE("[Geometry2D] Add extra points outside border of original convex hull") {
+ a.push_back(Point2(-11, -1));
+ a.push_back(Point2(7, 6));
+
+ r = Geometry2D::convex_hull(a);
+ REQUIRE_MESSAGE(r.size() == 10, "Convex hull should contain 10 points.");
+ CHECK(r[0].is_equal_approx(Point2(-12, 4)));
+ CHECK(r[1].is_equal_approx(Point2(-11, -1)));
+ CHECK(r[2].is_equal_approx(Point2(-10, -4)));
+ CHECK(r[3].is_equal_approx(Point2(-4, -8)));
+ CHECK(r[4].is_equal_approx(Point2(10, -8)));
+ CHECK(r[5].is_equal_approx(Point2(8, 2)));
+ CHECK(r[6].is_equal_approx(Point2(7, 6)));
+ CHECK(r[7].is_equal_approx(Point2(4, 8)));
+ CHECK(r[8].is_equal_approx(Point2(-6, 10)));
+ CHECK(r[9].is_equal_approx(Point2(-12, 4)));
+ }
+}
+
+TEST_CASE("[Geometry2D] Bresenham line") {
+ Vector<Vector2i> r;
+
+ SUBCASE("[Geometry2D] Single point") {
+ r = Geometry2D::bresenham_line(Point2i(0, 0), Point2i(0, 0));
+
+ REQUIRE_MESSAGE(r.size() == 1, "The Bresenham line should contain exactly one point.");
+ CHECK(r[0] == Vector2i(0, 0));
+ }
+
+ SUBCASE("[Geometry2D] Line parallel to x-axis") {
+ r = Geometry2D::bresenham_line(Point2i(1, 2), Point2i(5, 2));
+
+ REQUIRE_MESSAGE(r.size() == 5, "The Bresenham line should contain exactly five points.");
+ CHECK(r[0] == Vector2i(1, 2));
+ CHECK(r[1] == Vector2i(2, 2));
+ CHECK(r[2] == Vector2i(3, 2));
+ CHECK(r[3] == Vector2i(4, 2));
+ CHECK(r[4] == Vector2i(5, 2));
+ }
+
+ SUBCASE("[Geometry2D] 45 degree line from the origin") {
+ r = Geometry2D::bresenham_line(Point2i(0, 0), Point2i(4, 4));
+
+ REQUIRE_MESSAGE(r.size() == 5, "The Bresenham line should contain exactly five points.");
+ CHECK(r[0] == Vector2i(0, 0));
+ CHECK(r[1] == Vector2i(1, 1));
+ CHECK(r[2] == Vector2i(2, 2));
+ CHECK(r[3] == Vector2i(3, 3));
+ CHECK(r[4] == Vector2i(4, 4));
+ }
+
+ SUBCASE("[Geometry2D] Sloped line going up one unit") {
+ r = Geometry2D::bresenham_line(Point2i(0, 0), Point2i(4, 1));
+
+ REQUIRE_MESSAGE(r.size() == 5, "The Bresenham line should contain exactly five points.");
+ CHECK(r[0] == Vector2i(0, 0));
+ CHECK(r[1] == Vector2i(1, 0));
+ CHECK(r[2] == Vector2i(2, 0));
+ CHECK(r[3] == Vector2i(3, 1));
+ CHECK(r[4] == Vector2i(4, 1));
+ }
+
+ SUBCASE("[Geometry2D] Sloped line going up two units") {
+ r = Geometry2D::bresenham_line(Point2i(0, 0), Point2i(4, 2));
+
+ REQUIRE_MESSAGE(r.size() == 5, "The Bresenham line should contain exactly five points.");
+ CHECK(r[0] == Vector2i(0, 0));
+ CHECK(r[1] == Vector2i(1, 0));
+ CHECK(r[2] == Vector2i(2, 1));
+ CHECK(r[3] == Vector2i(3, 1));
+ CHECK(r[4] == Vector2i(4, 2));
+ }
+
+ SUBCASE("[Geometry2D] Long sloped line") {
+ r = Geometry2D::bresenham_line(Point2i(0, 0), Point2i(11, 5));
+
+ REQUIRE_MESSAGE(r.size() == 12, "The Bresenham line should contain exactly twelve points.");
+ CHECK(r[0] == Vector2i(0, 0));
+ CHECK(r[1] == Vector2i(1, 0));
+ CHECK(r[2] == Vector2i(2, 1));
+ CHECK(r[3] == Vector2i(3, 1));
+ CHECK(r[4] == Vector2i(4, 2));
+ CHECK(r[5] == Vector2i(5, 2));
+ CHECK(r[6] == Vector2i(6, 3));
+ CHECK(r[7] == Vector2i(7, 3));
+ CHECK(r[8] == Vector2i(8, 4));
+ CHECK(r[9] == Vector2i(9, 4));
+ CHECK(r[10] == Vector2i(10, 5));
+ CHECK(r[11] == Vector2i(11, 5));
+ }
+}
} // namespace TestGeometry2D
#endif // TEST_GEOMETRY_2D_H
diff --git a/tests/core/math/test_geometry_3d.h b/tests/core/math/test_geometry_3d.h
index f42003ffcf..99a4ef2d46 100644
--- a/tests/core/math/test_geometry_3d.h
+++ b/tests/core/math/test_geometry_3d.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -288,7 +288,7 @@ TEST_CASE("[Geometry3D] Is Point in Projected Triangle") {
TEST_CASE("[Geometry3D] Does Ray Intersect Triangle") {
struct Case {
Vector3 from, direction, v_1, v_2, v_3;
- Vector3 *result;
+ Vector3 *result = nullptr;
bool want;
Case(){};
Case(Vector3 p_from, Vector3 p_direction, Vector3 p_v_1, Vector3 p_v_2, Vector3 p_v_3, bool p_want) :
@@ -390,7 +390,7 @@ TEST_CASE("[Geometry3D] Triangle and Box Overlap") {
struct Case {
Vector3 box_centre;
Vector3 box_half_size;
- Vector3 *tri_verts;
+ Vector3 *tri_verts = nullptr;
bool want;
Case(){};
Case(Vector3 p_centre, Vector3 p_half_size, Vector3 *p_verts, bool p_want) :
diff --git a/tests/core/math/test_math.cpp b/tests/core/math/test_math.cpp
deleted file mode 100644
index 97e6055130..0000000000
--- a/tests/core/math/test_math.cpp
+++ /dev/null
@@ -1,690 +0,0 @@
-/*************************************************************************/
-/* test_math.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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. */
-/*************************************************************************/
-
-#include "test_math.h"
-
-#include "core/math/camera_matrix.h"
-#include "core/math/delaunay_3d.h"
-#include "core/math/geometry_2d.h"
-#include "core/os/main_loop.h"
-#include "core/os/os.h"
-
-namespace TestMath {
-
-class GetClassAndNamespace {
- String code;
- int idx;
- int line;
- String error_str;
- bool error;
- Variant value;
-
- String class_name;
-
- enum Token {
- TK_BRACKET_OPEN,
- TK_BRACKET_CLOSE,
- TK_CURLY_BRACKET_OPEN,
- TK_CURLY_BRACKET_CLOSE,
- TK_PERIOD,
- TK_COLON,
- TK_COMMA,
- TK_SYMBOL,
- TK_IDENTIFIER,
- TK_STRING,
- TK_NUMBER,
- TK_EOF,
- TK_ERROR
- };
-
- Token get_token() {
- while (true) {
- switch (code[idx]) {
- case '\n': {
- line++;
- idx++;
- break;
- };
- case 0: {
- return TK_EOF;
-
- } break;
- case '{': {
- idx++;
- return TK_CURLY_BRACKET_OPEN;
- };
- case '}': {
- idx++;
- return TK_CURLY_BRACKET_CLOSE;
- };
- case '[': {
- idx++;
- return TK_BRACKET_OPEN;
- };
- case ']': {
- idx++;
- return TK_BRACKET_CLOSE;
- };
- case ':': {
- idx++;
- return TK_COLON;
- };
- case ',': {
- idx++;
- return TK_COMMA;
- };
- case '.': {
- idx++;
- return TK_PERIOD;
- };
- case '#': {
- //compiler directive
- while (code[idx] != '\n' && code[idx] != 0) {
- idx++;
- }
- continue;
- } break;
- case '/': {
- switch (code[idx + 1]) {
- case '*': { // block comment
-
- idx += 2;
- while (true) {
- if (code[idx] == 0) {
- error_str = "Unterminated comment";
- error = true;
- return TK_ERROR;
- } else if (code[idx] == '*' && code[idx + 1] == '/') {
- idx += 2;
- break;
- } else if (code[idx] == '\n') {
- line++;
- }
-
- idx++;
- }
-
- } break;
- case '/': { // line comment skip
-
- while (code[idx] != '\n' && code[idx] != 0) {
- idx++;
- }
-
- } break;
- default: {
- value = "/";
- idx++;
- return TK_SYMBOL;
- }
- }
-
- continue; // a comment
- } break;
- case '\'':
- case '"': {
- char32_t begin_str = code[idx];
- idx++;
- String tk_string = String();
- while (true) {
- if (code[idx] == 0) {
- error_str = "Unterminated String";
- error = true;
- return TK_ERROR;
- } else if (code[idx] == begin_str) {
- idx++;
- break;
- } else if (code[idx] == '\\') {
- //escaped characters...
- idx++;
- char32_t next = code[idx];
- if (next == 0) {
- error_str = "Unterminated String";
- error = true;
- return TK_ERROR;
- }
- char32_t res = 0;
-
- switch (next) {
- case 'b':
- res = 8;
- break;
- case 't':
- res = 9;
- break;
- case 'n':
- res = 10;
- break;
- case 'f':
- res = 12;
- break;
- case 'r':
- res = 13;
- break;
- case '\"':
- res = '\"';
- break;
- case '\\':
- res = '\\';
- break;
- default: {
- res = next;
- } break;
- }
-
- tk_string += res;
-
- } else {
- if (code[idx] == '\n') {
- line++;
- }
- tk_string += code[idx];
- }
- idx++;
- }
-
- value = tk_string;
-
- return TK_STRING;
-
- } break;
- default: {
- if (code[idx] <= 32) {
- idx++;
- break;
- }
-
- if ((code[idx] >= 33 && code[idx] <= 47) || (code[idx] >= 58 && code[idx] <= 64) || (code[idx] >= 91 && code[idx] <= 96) || (code[idx] >= 123 && code[idx] <= 127)) {
- value = String::chr(code[idx]);
- idx++;
- return TK_SYMBOL;
- }
-
- if (code[idx] == '-' || (code[idx] >= '0' && code[idx] <= '9')) {
- //a number
- const char32_t *rptr;
- double number = String::to_float(&code[idx], &rptr);
- idx += (rptr - &code[idx]);
- value = number;
- return TK_NUMBER;
-
- } else if ((code[idx] >= 'A' && code[idx] <= 'Z') || (code[idx] >= 'a' && code[idx] <= 'z') || code[idx] > 127) {
- String id;
-
- while ((code[idx] >= 'A' && code[idx] <= 'Z') || (code[idx] >= 'a' && code[idx] <= 'z') || code[idx] > 127) {
- id += code[idx];
- idx++;
- }
-
- value = id;
- return TK_IDENTIFIER;
- } else {
- error_str = "Unexpected character.";
- error = true;
- return TK_ERROR;
- }
- }
- }
- }
- }
-
-public:
- Error parse(const String &p_code, const String &p_known_class_name = String()) {
- code = p_code;
- idx = 0;
- line = 0;
- error_str = String();
- error = false;
- value = Variant();
- class_name = String();
-
- bool use_next_class = false;
- Token tk = get_token();
-
- Map<int, String> namespace_stack;
- int curly_stack = 0;
-
- while (!error || tk != TK_EOF) {
- if (tk == TK_BRACKET_OPEN) {
- tk = get_token();
- if (tk == TK_IDENTIFIER && String(value) == "ScriptClass") {
- if (get_token() == TK_BRACKET_CLOSE) {
- use_next_class = true;
- }
- }
- } else if (tk == TK_IDENTIFIER && String(value) == "class") {
- tk = get_token();
- if (tk == TK_IDENTIFIER) {
- String name = value;
- if (use_next_class || p_known_class_name == name) {
- for (const KeyValue<int, String> &E : namespace_stack) {
- class_name += E.value + ".";
- }
- class_name += String(value);
- break;
- }
- }
-
- } else if (tk == TK_IDENTIFIER && String(value) == "namespace") {
- String name;
- int at_level = curly_stack;
- while (true) {
- tk = get_token();
- if (tk == TK_IDENTIFIER) {
- name += String(value);
- }
-
- tk = get_token();
- if (tk == TK_PERIOD) {
- name += ".";
- } else if (tk == TK_CURLY_BRACKET_OPEN) {
- curly_stack++;
- break;
- } else {
- break; //whathever else
- }
- }
-
- if (!name.is_empty()) {
- namespace_stack[at_level] = name;
- }
-
- } else if (tk == TK_CURLY_BRACKET_OPEN) {
- curly_stack++;
- } else if (tk == TK_CURLY_BRACKET_CLOSE) {
- curly_stack--;
- if (namespace_stack.has(curly_stack)) {
- namespace_stack.erase(curly_stack);
- }
- }
-
- tk = get_token();
- }
-
- if (error) {
- return ERR_PARSE_ERROR;
- }
-
- return OK;
- }
-
- String get_error() {
- return error_str;
- }
-
- String get_class() {
- return class_name;
- }
-};
-
-void test_vec(Plane p_vec) {
- CameraMatrix cm;
- cm.set_perspective(45, 1, 0, 100);
- Plane v0 = cm.xform4(p_vec);
-
- print_line("out: " + v0);
- v0.normal.z = (v0.d / 100.0 * 2.0 - 1.0) * v0.d;
- print_line("out_F: " + v0);
-}
-
-uint32_t ihash(uint32_t a) {
- a = (a + 0x7ed55d16) + (a << 12);
- a = (a ^ 0xc761c23c) ^ (a >> 19);
- a = (a + 0x165667b1) + (a << 5);
- a = (a + 0xd3a2646c) ^ (a << 9);
- a = (a + 0xfd7046c5) + (a << 3);
- a = (a ^ 0xb55a4f09) ^ (a >> 16);
- return a;
-}
-
-uint32_t ihash2(uint32_t a) {
- a = (a ^ 61) ^ (a >> 16);
- a = a + (a << 3);
- a = a ^ (a >> 4);
- a = a * 0x27d4eb2d;
- a = a ^ (a >> 15);
- return a;
-}
-
-uint32_t ihash3(uint32_t a) {
- a = (a + 0x479ab41d) + (a << 8);
- a = (a ^ 0xe4aa10ce) ^ (a >> 5);
- a = (a + 0x9942f0a6) - (a << 14);
- a = (a ^ 0x5aedd67d) ^ (a >> 3);
- a = (a + 0x17bea992) + (a << 7);
- return a;
-}
-
-MainLoop *test() {
- {
- Vector<Vector3> points;
- points.push_back(Vector3(0, 0, 0));
- points.push_back(Vector3(0, 0, 1));
- points.push_back(Vector3(0, 1, 0));
- points.push_back(Vector3(0, 1, 1));
- points.push_back(Vector3(1, 1, 0));
- points.push_back(Vector3(1, 0, 0));
- points.push_back(Vector3(1, 0, 1));
- points.push_back(Vector3(1, 1, 1));
-
- for (int i = 0; i < 800; i++) {
- points.push_back(Vector3(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0) * Vector3(25, 30, 33));
- }
-
- Vector<Delaunay3D::OutputSimplex> os = Delaunay3D::tetrahedralize(points);
- print_line("simplices in the end: " + itos(os.size()));
- for (int i = 0; i < os.size(); i++) {
- print_line("Simplex " + itos(i) + ": ");
- print_line(points[os[i].points[0]]);
- print_line(points[os[i].points[1]]);
- print_line(points[os[i].points[2]]);
- print_line(points[os[i].points[3]]);
- }
-
- {
- FileAccessRef f = FileAccess::open("res://bsp.obj", FileAccess::WRITE);
- for (int i = 0; i < os.size(); i++) {
- f->store_line("o Simplex" + itos(i));
- for (int j = 0; j < 4; j++) {
- f->store_line(vformat("v %f %f %f", points[os[i].points[j]].x, points[os[i].points[j]].y, points[os[i].points[j]].z));
- }
- static const int face_order[4][3] = {
- { 1, 2, 3 },
- { 1, 3, 4 },
- { 1, 2, 4 },
- { 2, 3, 4 }
- };
-
- for (int j = 0; j < 4; j++) {
- f->store_line(vformat("f %d %d %d", 4 * i + face_order[j][0], 4 * i + face_order[j][1], 4 * i + face_order[j][2]));
- }
- }
- f->close();
- }
-
- return nullptr;
- }
-
- {
- float r = 1;
- float g = 0.5;
- float b = 0.1;
-
- const float pow2to9 = 512.0f;
- const float B = 15.0f;
- const float N = 9.0f;
-
- float sharedexp = 65408.000f;
-
- float cRed = MAX(0.0f, MIN(sharedexp, r));
- float cGreen = MAX(0.0f, MIN(sharedexp, g));
- float cBlue = MAX(0.0f, MIN(sharedexp, b));
-
- float cMax = MAX(cRed, MAX(cGreen, cBlue));
-
- float expp = MAX(-B - 1.0f, floor(Math::log(cMax) / Math_LN2)) + 1.0f + B;
-
- float sMax = (float)floor((cMax / Math::pow(2.0f, expp - B - N)) + 0.5f);
-
- float exps = expp + 1.0f;
-
- if (0.0 <= sMax && sMax < pow2to9) {
- exps = expp;
- }
-
- float sRed = Math::floor((cRed / pow(2.0f, exps - B - N)) + 0.5f);
- float sGreen = Math::floor((cGreen / pow(2.0f, exps - B - N)) + 0.5f);
- float sBlue = Math::floor((cBlue / pow(2.0f, exps - B - N)) + 0.5f);
-
- print_line("R: " + rtos(sRed) + " G: " + rtos(sGreen) + " B: " + rtos(sBlue) + " EXP: " + rtos(exps));
-
- uint32_t rgbe = (Math::fast_ftoi(sRed) & 0x1FF) | ((Math::fast_ftoi(sGreen) & 0x1FF) << 9) | ((Math::fast_ftoi(sBlue) & 0x1FF) << 18) | ((Math::fast_ftoi(exps) & 0x1F) << 27);
-
- float rb = rgbe & 0x1ff;
- float gb = (rgbe >> 9) & 0x1ff;
- float bb = (rgbe >> 18) & 0x1ff;
- float eb = (rgbe >> 27);
- float mb = Math::pow(2.0, eb - 15.0 - 9.0);
- float rd = rb * mb;
- float gd = gb * mb;
- float bd = bb * mb;
-
- print_line("RGBE: " + Color(rd, gd, bd));
- }
-
- Vector<int> ints;
- ints.resize(20);
-
- {
- int *w;
- w = ints.ptrw();
- for (int i = 0; i < ints.size(); i++) {
- w[i] = i;
- }
- }
-
- Vector<int> posho = ints;
-
- {
- const int *r = posho.ptr();
- for (int i = 0; i < posho.size(); i++) {
- print_line(itos(i) + " : " + itos(r[i]));
- }
- }
-
- List<String> cmdlargs = OS::get_singleton()->get_cmdline_args();
-
- if (cmdlargs.is_empty()) {
- //try editor!
- return nullptr;
- }
-
- String test = cmdlargs.back()->get();
- if (test == "math") {
- // Not a file name but the test name, abort.
- // FIXME: This test is ugly as heck, needs fixing :)
- return nullptr;
- }
-
- FileAccess *fa = FileAccess::open(test, FileAccess::READ);
- ERR_FAIL_COND_V_MSG(!fa, nullptr, "Could not open file: " + test);
-
- Vector<uint8_t> buf;
- uint64_t flen = fa->get_length();
- buf.resize(fa->get_length() + 1);
- fa->get_buffer(buf.ptrw(), flen);
- buf.write[flen] = 0;
-
- String code;
- code.parse_utf8((const char *)&buf[0]);
-
- GetClassAndNamespace getclass;
- if (getclass.parse(code)) {
- print_line("Parse error: " + getclass.get_error());
- } else {
- print_line("Found class: " + getclass.get_class());
- }
-
- {
- Vector<int> hashes;
- List<StringName> tl;
- ClassDB::get_class_list(&tl);
-
- for (const StringName &E : tl) {
- Vector<uint8_t> m5b = E.operator String().md5_buffer();
- hashes.push_back(hashes.size());
- }
-
- for (int i = nearest_shift(hashes.size()); i < 20; i++) {
- bool success = true;
- for (int s = 0; s < 10000; s++) {
- Set<uint32_t> existing;
- success = true;
-
- for (int j = 0; j < hashes.size(); j++) {
- uint32_t eh = ihash2(ihash3(hashes[j] + ihash(s) + s)) & ((1 << i) - 1);
- if (existing.has(eh)) {
- success = false;
- break;
- }
- existing.insert(eh);
- }
-
- if (success) {
- print_line("success at " + itos(i) + "/" + itos(nearest_shift(hashes.size())) + " shift " + itos(s));
- break;
- }
- }
- if (success) {
- break;
- }
- }
-
- print_line("DONE");
- }
-
- {
- print_line("NUM: " + itos(-128));
- }
-
- {
- Vector3 v(1, 2, 3);
- v.normalize();
- real_t a = 0.3;
-
- Basis m(v, a);
-
- Vector3 v2(7, 3, 1);
- v2.normalize();
- real_t a2 = 0.8;
-
- Basis m2(v2, a2);
-
- Quaternion q = m;
- Quaternion q2 = m2;
-
- Basis m3 = m.inverse() * m2;
- Quaternion q3 = (q.inverse() * q2); //.normalized();
-
- print_line(Quaternion(m3));
- print_line(q3);
-
- print_line("before v: " + v + " a: " + rtos(a));
- q.get_axis_angle(v, a);
- print_line("after v: " + v + " a: " + rtos(a));
- }
-
- String ret;
-
- List<String> args;
- args.push_back("-l");
- Error err = OS::get_singleton()->execute("/bin/ls", args, &ret);
- print_line("error: " + itos(err));
- print_line(ret);
-
- Basis m3;
- m3.rotate(Vector3(1, 0, 0), 0.2);
- m3.rotate(Vector3(0, 1, 0), 1.77);
- m3.rotate(Vector3(0, 0, 1), 212);
- Basis m32;
- m32.set_euler(m3.get_euler());
- print_line("ELEULEEEEEEEEEEEEEEEEEER: " + m3.get_euler() + " vs " + m32.get_euler());
-
- {
- Dictionary d;
- d["momo"] = 1;
- Dictionary b = d;
- b["44"] = 4;
- }
-
- print_line("inters: " + rtos(Geometry2D::segment_intersects_circle(Vector2(-5, 0), Vector2(-2, 0), Vector2(), 1.0)));
-
- print_line("cross: " + Vector3(1, 2, 3).cross(Vector3(4, 5, 7)));
- print_line("dot: " + rtos(Vector3(1, 2, 3).dot(Vector3(4, 5, 7))));
- print_line("abs: " + Vector3(-1, 2, -3).abs());
- print_line("distance_to: " + rtos(Vector3(1, 2, 3).distance_to(Vector3(4, 5, 7))));
- print_line("distance_squared_to: " + rtos(Vector3(1, 2, 3).distance_squared_to(Vector3(4, 5, 7))));
- print_line("plus: " + (Vector3(1, 2, 3) + Vector3(Vector3(4, 5, 7))));
- print_line("minus: " + (Vector3(1, 2, 3) - Vector3(Vector3(4, 5, 7))));
- print_line("mul: " + (Vector3(1, 2, 3) * Vector3(Vector3(4, 5, 7))));
- print_line("div: " + (Vector3(1, 2, 3) / Vector3(Vector3(4, 5, 7))));
- print_line("mul scalar: " + (Vector3(1, 2, 3) * 2.0));
- print_line("premul scalar: " + (2.0 * Vector3(1, 2, 3)));
- print_line("div scalar: " + (Vector3(1, 2, 3) / 3.0));
- print_line("length: " + rtos(Vector3(1, 2, 3).length()));
- print_line("length squared: " + rtos(Vector3(1, 2, 3).length_squared()));
- print_line("normalized: " + Vector3(1, 2, 3).normalized());
- print_line("inverse: " + Vector3(1, 2, 3).inverse());
-
- {
- Vector3 v(4, 5, 7);
- v.normalize();
- print_line("normalize: " + v);
- }
-
- {
- Vector3 v(4, 5, 7);
- v += Vector3(1, 2, 3);
- print_line("+=: " + v);
- }
-
- {
- Vector3 v(4, 5, 7);
- v -= Vector3(1, 2, 3);
- print_line("-=: " + v);
- }
-
- {
- Vector3 v(4, 5, 7);
- v *= Vector3(1, 2, 3);
- print_line("*=: " + v);
- }
-
- {
- Vector3 v(4, 5, 7);
- v /= Vector3(1, 2, 3);
- print_line("/=: " + v);
- }
-
- {
- Vector3 v(4, 5, 7);
- v *= 2.0;
- print_line("scalar *=: " + v);
- }
-
- {
- Vector3 v(4, 5, 7);
- v /= 2.0;
- print_line("scalar /=: " + v);
- }
-
- return nullptr;
-}
-} // namespace TestMath
diff --git a/tests/core/math/test_math.h b/tests/core/math/test_math.h
deleted file mode 100644
index ab5fb6a050..0000000000
--- a/tests/core/math/test_math.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*************************************************************************/
-/* test_math.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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_H
-#define TEST_MATH_H
-
-class MainLoop;
-
-namespace TestMath {
-
-MainLoop *test();
-}
-
-#endif
diff --git a/tests/core/math/test_plane.h b/tests/core/math/test_plane.h
new file mode 100644
index 0000000000..d81a5af1ce
--- /dev/null
+++ b/tests/core/math/test_plane.h
@@ -0,0 +1,172 @@
+/*************************************************************************/
+/* test_plane.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_PLANE_H
+#define TEST_PLANE_H
+
+#include "core/math/plane.h"
+
+#include "thirdparty/doctest/doctest.h"
+
+namespace TestPlane {
+
+// Plane
+
+TEST_CASE("[Plane] Constructor methods") {
+ const Plane plane = Plane(32, 22, 16, 3);
+ const Plane plane_vector = Plane(Vector3(32, 22, 16), 3);
+ const Plane plane_copy_plane = Plane(plane);
+
+ CHECK_MESSAGE(
+ plane == plane_vector,
+ "Planes created with same values but different methods should be equal.");
+
+ CHECK_MESSAGE(
+ plane == plane_copy_plane,
+ "Planes created with same values but different methods should be equal.");
+}
+
+TEST_CASE("[Plane] Basic getters") {
+ const Plane plane = Plane(32, 22, 16, 3);
+ const Plane plane_normalized = Plane(32.0 / 42, 22.0 / 42, 16.0 / 42, 3.0 / 42);
+
+ CHECK_MESSAGE(
+ plane.get_normal().is_equal_approx(Vector3(32, 22, 16)),
+ "get_normal() should return the expected value.");
+
+ CHECK_MESSAGE(
+ plane.normalized().is_equal_approx(plane_normalized),
+ "normalized() should return a copy of the normalized value.");
+}
+
+TEST_CASE("[Plane] Basic setters") {
+ Plane plane = Plane(32, 22, 16, 3);
+ plane.set_normal(Vector3(4, 2, 3));
+
+ CHECK_MESSAGE(
+ plane.is_equal_approx(Plane(4, 2, 3, 3)),
+ "set_normal() should result in the expected plane.");
+
+ plane = Plane(32, 22, 16, 3);
+ plane.normalize();
+
+ CHECK_MESSAGE(
+ plane.is_equal_approx(Plane(32.0 / 42, 22.0 / 42, 16.0 / 42, 3.0 / 42)),
+ "normalize() should result in the expected plane.");
+}
+
+TEST_CASE("[Plane] Plane-point operations") {
+ const Plane plane = Plane(32, 22, 16, 3);
+ const Plane y_facing_plane = Plane(0, 1, 0, 4);
+
+ CHECK_MESSAGE(
+ plane.center().is_equal_approx(Vector3(32 * 3, 22 * 3, 16 * 3)),
+ "center() should return a vector pointing to the center of the plane.");
+
+ CHECK_MESSAGE(
+ y_facing_plane.is_point_over(Vector3(0, 5, 0)),
+ "is_point_over() should return the expected result.");
+
+ CHECK_MESSAGE(
+ y_facing_plane.get_any_perpendicular_normal().is_equal_approx(Vector3(1, 0, 0)),
+ "get_any_perpindicular_normal() should return the expected result.");
+
+ // TODO distance_to()
+}
+
+TEST_CASE("[Plane] Has point") {
+ const Plane x_facing_plane = Plane(1, 0, 0, 0);
+ const Plane y_facing_plane = Plane(0, 1, 0, 0);
+ const Plane z_facing_plane = Plane(0, 0, 1, 0);
+
+ const Vector3 x_axis_point = Vector3(10, 0, 0);
+ const Vector3 y_axis_point = Vector3(0, 10, 0);
+ const Vector3 z_axis_point = Vector3(0, 0, 10);
+
+ const Plane x_facing_plane_with_d_offset = Plane(1, 0, 0, 1);
+ const Vector3 y_axis_point_with_d_offset = Vector3(1, 10, 0);
+
+ CHECK_MESSAGE(
+ x_facing_plane.has_point(y_axis_point),
+ "has_point() with contained Vector3 should return the expected result.");
+ CHECK_MESSAGE(
+ x_facing_plane.has_point(z_axis_point),
+ "has_point() with contained Vector3 should return the expected result.");
+
+ CHECK_MESSAGE(
+ y_facing_plane.has_point(x_axis_point),
+ "has_point() with contained Vector3 should return the expected result.");
+ CHECK_MESSAGE(
+ y_facing_plane.has_point(z_axis_point),
+ "has_point() with contained Vector3 should return the expected result.");
+
+ CHECK_MESSAGE(
+ z_facing_plane.has_point(y_axis_point),
+ "has_point() with contained Vector3 should return the expected result.");
+ CHECK_MESSAGE(
+ z_facing_plane.has_point(x_axis_point),
+ "has_point() with contained Vector3 should return the expected result.");
+
+ CHECK_MESSAGE(
+ x_facing_plane_with_d_offset.has_point(y_axis_point_with_d_offset),
+ "has_point() with passed Vector3 should return the expected result.");
+}
+
+TEST_CASE("[Plane] Intersection") {
+ const Plane x_facing_plane = Plane(1, 0, 0, 1);
+ const Plane y_facing_plane = Plane(0, 1, 0, 2);
+ const Plane z_facing_plane = Plane(0, 0, 1, 3);
+
+ Vector3 vec_out;
+
+ CHECK_MESSAGE(
+ x_facing_plane.intersect_3(y_facing_plane, z_facing_plane, &vec_out),
+ "intersect_3() should return the expected result.");
+ CHECK_MESSAGE(
+ vec_out.is_equal_approx(Vector3(1, 2, 3)),
+ "intersect_3() should modify vec_out to the expected result.");
+
+ CHECK_MESSAGE(
+ x_facing_plane.intersects_ray(Vector3(0, 1, 1), Vector3(2, 0, 0), &vec_out),
+ "intersects_ray() should return the expected result.");
+ CHECK_MESSAGE(
+ vec_out.is_equal_approx(Vector3(1, 1, 1)),
+ "intersects_ray() should modify vec_out to the expected result.");
+
+ CHECK_MESSAGE(
+ x_facing_plane.intersects_segment(Vector3(0, 1, 1), Vector3(2, 1, 1), &vec_out),
+ "intersects_segment() should return the expected result.");
+ CHECK_MESSAGE(
+ vec_out.is_equal_approx(Vector3(1, 1, 1)),
+ "intersects_segment() should modify vec_out to the expected result.");
+}
+} // namespace TestPlane
+
+#endif // TEST_PLANE_H
diff --git a/tests/core/math/test_random_number_generator.h b/tests/core/math/test_random_number_generator.h
index 39c4771c19..e8cd47b9d7 100644
--- a/tests/core/math/test_random_number_generator.h
+++ b/tests/core/math/test_random_number_generator.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/core/math/test_rect2.h b/tests/core/math/test_rect2.h
index aabb950461..0b1106ac3c 100644
--- a/tests/core/math/test_rect2.h
+++ b/tests/core/math/test_rect2.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -32,15 +32,11 @@
#define TEST_RECT2_H
#include "core/math/rect2.h"
+#include "core/math/rect2i.h"
#include "thirdparty/doctest/doctest.h"
namespace TestRect2 {
-// We also test Rect2i here, for consistency with the source code where Rect2
-// and Rect2i are defined in the same file.
-
-// Rect2
-
TEST_CASE("[Rect2] Constructor methods") {
const Rect2 rect = Rect2(0, 100, 1280, 720);
const Rect2 rect_vector = Rect2(Vector2(0, 100), Vector2(1280, 720));
@@ -304,272 +300,6 @@ 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.");
}
-
-// Rect2i
-
-TEST_CASE("[Rect2i] Constructor methods") {
- Rect2i recti = Rect2i(0, 100, 1280, 720);
- Rect2i recti_vector = Rect2i(Vector2i(0, 100), Vector2i(1280, 720));
- Rect2i recti_copy_recti = Rect2i(recti);
- Rect2i recti_copy_rect = Rect2i(Rect2(0, 100, 1280, 720));
-
- CHECK_MESSAGE(
- recti == recti_vector,
- "Rect2is created with the same dimensions but by different methods should be equal.");
- CHECK_MESSAGE(
- recti == recti_copy_recti,
- "Rect2is created with the same dimensions but by different methods should be equal.");
- CHECK_MESSAGE(
- recti == recti_copy_rect,
- "Rect2is created with the same dimensions but by different methods should be equal.");
-}
-
-TEST_CASE("[Rect2i] String conversion") {
- // Note: This also depends on the Vector2 string representation.
- CHECK_MESSAGE(
- String(Rect2i(0, 100, 1280, 720)) == "[P: (0, 100), S: (1280, 720)]",
- "The string representation should match the expected value.");
-}
-
-TEST_CASE("[Rect2i] Basic getters") {
- const Rect2i rect = Rect2i(0, 100, 1280, 720);
- CHECK_MESSAGE(
- rect.get_position() == Vector2i(0, 100),
- "get_position() should return the expected value.");
- CHECK_MESSAGE(
- rect.get_size() == Vector2i(1280, 720),
- "get_size() should return the expected value.");
- CHECK_MESSAGE(
- rect.get_end() == Vector2i(1280, 820),
- "get_end() should return the expected value.");
- CHECK_MESSAGE(
- rect.get_center() == Vector2i(640, 460),
- "get_center() should return the expected value.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 1281, 721).get_center() == Vector2i(640, 460),
- "get_center() should return the expected value.");
-}
-
-TEST_CASE("[Rect2i] Basic setters") {
- Rect2i rect = Rect2i(0, 100, 1280, 720);
- rect.set_end(Vector2i(4000, 4000));
- CHECK_MESSAGE(
- rect == Rect2i(0, 100, 4000, 3900),
- "set_end() should result in the expected Rect2i.");
-
- rect = Rect2i(0, 100, 1280, 720);
- rect.set_position(Vector2i(4000, 4000));
- CHECK_MESSAGE(
- rect == Rect2i(4000, 4000, 1280, 720),
- "set_position() should result in the expected Rect2i.");
-
- rect = Rect2i(0, 100, 1280, 720);
- rect.set_size(Vector2i(4000, 4000));
- CHECK_MESSAGE(
- rect == Rect2i(0, 100, 4000, 4000),
- "set_size() should result in the expected Rect2i.");
-}
-
-TEST_CASE("[Rect2i] Area getters") {
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).get_area() == 921'600,
- "get_area() should return the expected value.");
- CHECK_MESSAGE(
- Rect2i(0, 100, -1280, -720).get_area() == 921'600,
- "get_area() should return the expected value.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, -720).get_area() == -921'600,
- "get_area() should return the expected value.");
- CHECK_MESSAGE(
- Rect2i(0, 100, -1280, 720).get_area() == -921'600,
- "get_area() should return the expected value.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 0, 720).get_area() == 0,
- "get_area() should return the expected value.");
-
- CHECK_MESSAGE(
- !Rect2i(0, 100, 1280, 720).has_no_area(),
- "has_no_area() should return the expected value on Rect2i with an area.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 0, 500).has_no_area(),
- "has_no_area() should return the expected value on Rect2i with no area.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 500, 0).has_no_area(),
- "has_no_area() should return the expected value on Rect2i with no area.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 0, 0).has_no_area(),
- "has_no_area() should return the expected value on Rect2i with no area.");
-}
-
-TEST_CASE("[Rect2i] Absolute coordinates") {
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).abs() == Rect2i(0, 100, 1280, 720),
- "abs() should return the expected Rect2i.");
- CHECK_MESSAGE(
- Rect2i(0, -100, 1280, 720).abs() == Rect2i(0, -100, 1280, 720),
- "abs() should return the expected Rect2i.");
- CHECK_MESSAGE(
- Rect2i(0, -100, -1280, -720).abs() == Rect2i(-1280, -820, 1280, 720),
- "abs() should return the expected Rect2i.");
- CHECK_MESSAGE(
- Rect2i(0, 100, -1280, 720).abs() == Rect2i(-1280, 100, 1280, 720),
- "abs() should return the expected Rect2i.");
-}
-
-TEST_CASE("[Rect2i] Intersection") {
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).intersection(Rect2i(0, 300, 100, 100)) == Rect2i(0, 300, 100, 100),
- "intersection() with fully enclosed Rect2i should return the expected result.");
- // The resulting Rect2i is 100 pixels high because the first Rect2i is vertically offset by 100 pixels.
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).intersection(Rect2i(1200, 700, 100, 100)) == Rect2i(1200, 700, 80, 100),
- "intersection() with partially enclosed Rect2i should return the expected result.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).intersection(Rect2i(-4000, -4000, 100, 100)) == Rect2i(),
- "intersection() with non-enclosed Rect2i should return the expected result.");
-}
-
-TEST_CASE("[Rect2i] Enclosing") {
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).encloses(Rect2i(0, 300, 100, 100)),
- "encloses() with fully contained Rect2i should return the expected result.");
- CHECK_MESSAGE(
- !Rect2i(0, 100, 1280, 720).encloses(Rect2i(1200, 700, 100, 100)),
- "encloses() with partially contained Rect2i should return the expected result.");
- CHECK_MESSAGE(
- !Rect2i(0, 100, 1280, 720).encloses(Rect2i(-4000, -4000, 100, 100)),
- "encloses() with non-contained Rect2i should return the expected result.");
-}
-
-TEST_CASE("[Rect2i] Expanding") {
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).expand(Vector2i(500, 600)) == Rect2i(0, 100, 1280, 720),
- "expand() with contained Vector2i should return the expected result.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).expand(Vector2i(0, 0)) == Rect2i(0, 0, 1280, 820),
- "expand() with non-contained Vector2i should return the expected result.");
-}
-
-TEST_CASE("[Rect2i] Growing") {
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).grow(100) == Rect2i(-100, 0, 1480, 920),
- "grow() with positive value should return the expected Rect2i.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).grow(-100) == Rect2i(100, 200, 1080, 520),
- "grow() with negative value should return the expected Rect2i.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).grow(-4000) == Rect2i(4000, 4100, -6720, -7280),
- "grow() with large negative value should return the expected Rect2i.");
-
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).grow_individual(100, 200, 300, 400) == Rect2i(-100, -100, 1680, 1320),
- "grow_individual() with positive values should return the expected Rect2i.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).grow_individual(-100, 200, 300, -400) == Rect2i(100, -100, 1480, 520),
- "grow_individual() with positive and negative values should return the expected Rect2i.");
-
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).grow_side(SIDE_TOP, 500) == Rect2i(0, -400, 1280, 1220),
- "grow_side() with positive value should return the expected Rect2i.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).grow_side(SIDE_TOP, -500) == Rect2i(0, 600, 1280, 220),
- "grow_side() with negative value should return the expected Rect2i.");
-}
-
-TEST_CASE("[Rect2i] Has point") {
- Rect2i rect = Rect2i(0, 100, 1280, 720);
- CHECK_MESSAGE(
- rect.has_point(Vector2i(500, 600)),
- "has_point() with contained Vector2i should return the expected result.");
- CHECK_MESSAGE(
- !rect.has_point(Vector2i(0, 0)),
- "has_point() with non-contained Vector2i should return the expected result.");
-
- CHECK_MESSAGE(
- rect.has_point(rect.position),
- "has_point() with positive size should include `position`.");
- CHECK_MESSAGE(
- rect.has_point(rect.position + Vector2i(1, 1)),
- "has_point() with positive size should include `position + (1, 1)`.");
- CHECK_MESSAGE(
- !rect.has_point(rect.position + Vector2i(1, -1)),
- "has_point() with positive size should not include `position + (1, -1)`.");
- CHECK_MESSAGE(
- !rect.has_point(rect.position + rect.size),
- "has_point() with positive size should not include `position + size`.");
- CHECK_MESSAGE(
- !rect.has_point(rect.position + rect.size + Vector2i(1, 1)),
- "has_point() with positive size should not include `position + size + (1, 1)`.");
- CHECK_MESSAGE(
- rect.has_point(rect.position + rect.size + Vector2i(-1, -1)),
- "has_point() with positive size should include `position + size + (-1, -1)`.");
- CHECK_MESSAGE(
- !rect.has_point(rect.position + rect.size + Vector2i(-1, 1)),
- "has_point() with positive size should not include `position + size + (-1, 1)`.");
-
- CHECK_MESSAGE(
- rect.has_point(rect.position + Vector2i(0, 10)),
- "has_point() with point located on left edge should return true.");
- CHECK_MESSAGE(
- !rect.has_point(rect.position + Vector2i(rect.size.x, 10)),
- "has_point() with point located on right edge should return false.");
- CHECK_MESSAGE(
- rect.has_point(rect.position + Vector2i(10, 0)),
- "has_point() with point located on top edge should return true.");
- CHECK_MESSAGE(
- !rect.has_point(rect.position + Vector2i(10, rect.size.y)),
- "has_point() with point located on bottom edge should return false.");
-
- /*
- // FIXME: Disabled for now until GH-37617 is fixed one way or another.
- // More tests should then be written like for the positive size case.
- rect = Rect2i(0, 100, -1280, -720);
- CHECK_MESSAGE(
- rect.has_point(rect.position),
- "has_point() with negative size should include `position`.");
- CHECK_MESSAGE(
- !rect.has_point(rect.position + rect.size),
- "has_point() with negative size should not include `position + size`.");
- */
-
- rect = Rect2i(-4000, -200, 1280, 720);
- CHECK_MESSAGE(
- rect.has_point(rect.position + Vector2i(0, 10)),
- "has_point() with negative position and point located on left edge should return true.");
- CHECK_MESSAGE(
- !rect.has_point(rect.position + Vector2i(rect.size.x, 10)),
- "has_point() with negative position and point located on right edge should return false.");
- CHECK_MESSAGE(
- rect.has_point(rect.position + Vector2i(10, 0)),
- "has_point() with negative position and point located on top edge should return true.");
- CHECK_MESSAGE(
- !rect.has_point(rect.position + Vector2i(10, rect.size.y)),
- "has_point() with negative position and point located on bottom edge should return false.");
-}
-
-TEST_CASE("[Rect2i] Intersection") {
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).intersects(Rect2i(0, 300, 100, 100)),
- "intersects() with fully enclosed Rect2i should return the expected result.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).intersects(Rect2i(1200, 700, 100, 100)),
- "intersects() with partially enclosed Rect2i should return the expected result.");
- CHECK_MESSAGE(
- !Rect2i(0, 100, 1280, 720).intersects(Rect2i(-4000, -4000, 100, 100)),
- "intersects() with non-enclosed Rect2i should return the expected result.");
-}
-
-TEST_CASE("[Rect2i] Merging") {
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).merge(Rect2i(0, 300, 100, 100)) == Rect2i(0, 100, 1280, 720),
- "merge() with fully enclosed Rect2i should return the expected result.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).merge(Rect2i(1200, 700, 100, 100)) == Rect2i(0, 100, 1300, 720),
- "merge() with partially enclosed Rect2i should return the expected result.");
- CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).merge(Rect2i(-4000, -4000, 100, 100)) == Rect2i(-4000, -4000, 5280, 4820),
- "merge() with non-enclosed Rect2i should return the expected result.");
-}
} // namespace TestRect2
#endif // TEST_RECT2_H
diff --git a/tests/core/math/test_rect2i.h b/tests/core/math/test_rect2i.h
new file mode 100644
index 0000000000..0d1a088a66
--- /dev/null
+++ b/tests/core/math/test_rect2i.h
@@ -0,0 +1,311 @@
+/*************************************************************************/
+/* test_rect2i.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_RECT2I_H
+#define TEST_RECT2I_H
+
+#include "core/math/rect2.h"
+#include "core/math/rect2i.h"
+
+#include "thirdparty/doctest/doctest.h"
+
+namespace TestRect2i {
+TEST_CASE("[Rect2i] Constructor methods") {
+ Rect2i recti = Rect2i(0, 100, 1280, 720);
+ Rect2i recti_vector = Rect2i(Vector2i(0, 100), Vector2i(1280, 720));
+ Rect2i recti_copy_recti = Rect2i(recti);
+ Rect2i recti_copy_rect = Rect2i(Rect2(0, 100, 1280, 720));
+
+ CHECK_MESSAGE(
+ recti == recti_vector,
+ "Rect2is created with the same dimensions but by different methods should be equal.");
+ CHECK_MESSAGE(
+ recti == recti_copy_recti,
+ "Rect2is created with the same dimensions but by different methods should be equal.");
+ CHECK_MESSAGE(
+ recti == recti_copy_rect,
+ "Rect2is created with the same dimensions but by different methods should be equal.");
+}
+
+TEST_CASE("[Rect2i] String conversion") {
+ // Note: This also depends on the Vector2 string representation.
+ CHECK_MESSAGE(
+ String(Rect2i(0, 100, 1280, 720)) == "[P: (0, 100), S: (1280, 720)]",
+ "The string representation should match the expected value.");
+}
+
+TEST_CASE("[Rect2i] Basic getters") {
+ const Rect2i rect = Rect2i(0, 100, 1280, 720);
+ CHECK_MESSAGE(
+ rect.get_position() == Vector2i(0, 100),
+ "get_position() should return the expected value.");
+ CHECK_MESSAGE(
+ rect.get_size() == Vector2i(1280, 720),
+ "get_size() should return the expected value.");
+ CHECK_MESSAGE(
+ rect.get_end() == Vector2i(1280, 820),
+ "get_end() should return the expected value.");
+ CHECK_MESSAGE(
+ rect.get_center() == Vector2i(640, 460),
+ "get_center() should return the expected value.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1281, 721).get_center() == Vector2i(640, 460),
+ "get_center() should return the expected value.");
+}
+
+TEST_CASE("[Rect2i] Basic setters") {
+ Rect2i rect = Rect2i(0, 100, 1280, 720);
+ rect.set_end(Vector2i(4000, 4000));
+ CHECK_MESSAGE(
+ rect == Rect2i(0, 100, 4000, 3900),
+ "set_end() should result in the expected Rect2i.");
+
+ rect = Rect2i(0, 100, 1280, 720);
+ rect.set_position(Vector2i(4000, 4000));
+ CHECK_MESSAGE(
+ rect == Rect2i(4000, 4000, 1280, 720),
+ "set_position() should result in the expected Rect2i.");
+
+ rect = Rect2i(0, 100, 1280, 720);
+ rect.set_size(Vector2i(4000, 4000));
+ CHECK_MESSAGE(
+ rect == Rect2i(0, 100, 4000, 4000),
+ "set_size() should result in the expected Rect2i.");
+}
+
+TEST_CASE("[Rect2i] Area getters") {
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).get_area() == 921'600,
+ "get_area() should return the expected value.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, -1280, -720).get_area() == 921'600,
+ "get_area() should return the expected value.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, -720).get_area() == -921'600,
+ "get_area() should return the expected value.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, -1280, 720).get_area() == -921'600,
+ "get_area() should return the expected value.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 0, 720).get_area() == 0,
+ "get_area() should return the expected value.");
+
+ CHECK_MESSAGE(
+ !Rect2i(0, 100, 1280, 720).has_no_area(),
+ "has_no_area() should return the expected value on Rect2i with an area.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 0, 500).has_no_area(),
+ "has_no_area() should return the expected value on Rect2i with no area.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 500, 0).has_no_area(),
+ "has_no_area() should return the expected value on Rect2i with no area.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 0, 0).has_no_area(),
+ "has_no_area() should return the expected value on Rect2i with no area.");
+}
+
+TEST_CASE("[Rect2i] Absolute coordinates") {
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).abs() == Rect2i(0, 100, 1280, 720),
+ "abs() should return the expected Rect2i.");
+ CHECK_MESSAGE(
+ Rect2i(0, -100, 1280, 720).abs() == Rect2i(0, -100, 1280, 720),
+ "abs() should return the expected Rect2i.");
+ CHECK_MESSAGE(
+ Rect2i(0, -100, -1280, -720).abs() == Rect2i(-1280, -820, 1280, 720),
+ "abs() should return the expected Rect2i.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, -1280, 720).abs() == Rect2i(-1280, 100, 1280, 720),
+ "abs() should return the expected Rect2i.");
+}
+
+TEST_CASE("[Rect2i] Intersection") {
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).intersection(Rect2i(0, 300, 100, 100)) == Rect2i(0, 300, 100, 100),
+ "intersection() with fully enclosed Rect2i should return the expected result.");
+ // The resulting Rect2i is 100 pixels high because the first Rect2i is vertically offset by 100 pixels.
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).intersection(Rect2i(1200, 700, 100, 100)) == Rect2i(1200, 700, 80, 100),
+ "intersection() with partially enclosed Rect2i should return the expected result.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).intersection(Rect2i(-4000, -4000, 100, 100)) == Rect2i(),
+ "intersection() with non-enclosed Rect2i should return the expected result.");
+}
+
+TEST_CASE("[Rect2i] Enclosing") {
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).encloses(Rect2i(0, 300, 100, 100)),
+ "encloses() with fully contained Rect2i should return the expected result.");
+ CHECK_MESSAGE(
+ !Rect2i(0, 100, 1280, 720).encloses(Rect2i(1200, 700, 100, 100)),
+ "encloses() with partially contained Rect2i should return the expected result.");
+ CHECK_MESSAGE(
+ !Rect2i(0, 100, 1280, 720).encloses(Rect2i(-4000, -4000, 100, 100)),
+ "encloses() with non-contained Rect2i should return the expected result.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).encloses(Rect2i(0, 100, 1280, 720)),
+ "encloses() with identical Rect2i should return the expected result.");
+}
+
+TEST_CASE("[Rect2i] Expanding") {
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).expand(Vector2i(500, 600)) == Rect2i(0, 100, 1280, 720),
+ "expand() with contained Vector2i should return the expected result.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).expand(Vector2i(0, 0)) == Rect2i(0, 0, 1280, 820),
+ "expand() with non-contained Vector2i should return the expected result.");
+}
+
+TEST_CASE("[Rect2i] Growing") {
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).grow(100) == Rect2i(-100, 0, 1480, 920),
+ "grow() with positive value should return the expected Rect2i.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).grow(-100) == Rect2i(100, 200, 1080, 520),
+ "grow() with negative value should return the expected Rect2i.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).grow(-4000) == Rect2i(4000, 4100, -6720, -7280),
+ "grow() with large negative value should return the expected Rect2i.");
+
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).grow_individual(100, 200, 300, 400) == Rect2i(-100, -100, 1680, 1320),
+ "grow_individual() with positive values should return the expected Rect2i.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).grow_individual(-100, 200, 300, -400) == Rect2i(100, -100, 1480, 520),
+ "grow_individual() with positive and negative values should return the expected Rect2i.");
+
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).grow_side(SIDE_TOP, 500) == Rect2i(0, -400, 1280, 1220),
+ "grow_side() with positive value should return the expected Rect2i.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).grow_side(SIDE_TOP, -500) == Rect2i(0, 600, 1280, 220),
+ "grow_side() with negative value should return the expected Rect2i.");
+}
+
+TEST_CASE("[Rect2i] Has point") {
+ Rect2i rect = Rect2i(0, 100, 1280, 720);
+ CHECK_MESSAGE(
+ rect.has_point(Vector2i(500, 600)),
+ "has_point() with contained Vector2i should return the expected result.");
+ CHECK_MESSAGE(
+ !rect.has_point(Vector2i(0, 0)),
+ "has_point() with non-contained Vector2i should return the expected result.");
+
+ CHECK_MESSAGE(
+ rect.has_point(rect.position),
+ "has_point() with positive size should include `position`.");
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + Vector2i(1, 1)),
+ "has_point() with positive size should include `position + (1, 1)`.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + Vector2i(1, -1)),
+ "has_point() with positive size should not include `position + (1, -1)`.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + rect.size),
+ "has_point() with positive size should not include `position + size`.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + rect.size + Vector2i(1, 1)),
+ "has_point() with positive size should not include `position + size + (1, 1)`.");
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + rect.size + Vector2i(-1, -1)),
+ "has_point() with positive size should include `position + size + (-1, -1)`.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + rect.size + Vector2i(-1, 1)),
+ "has_point() with positive size should not include `position + size + (-1, 1)`.");
+
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + Vector2i(0, 10)),
+ "has_point() with point located on left edge should return true.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + Vector2i(rect.size.x, 10)),
+ "has_point() with point located on right edge should return false.");
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + Vector2i(10, 0)),
+ "has_point() with point located on top edge should return true.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + Vector2i(10, rect.size.y)),
+ "has_point() with point located on bottom edge should return false.");
+
+ /*
+ // FIXME: Disabled for now until GH-37617 is fixed one way or another.
+ // More tests should then be written like for the positive size case.
+ rect = Rect2i(0, 100, -1280, -720);
+ CHECK_MESSAGE(
+ rect.has_point(rect.position),
+ "has_point() with negative size should include `position`.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + rect.size),
+ "has_point() with negative size should not include `position + size`.");
+ */
+
+ rect = Rect2i(-4000, -200, 1280, 720);
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + Vector2i(0, 10)),
+ "has_point() with negative position and point located on left edge should return true.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + Vector2i(rect.size.x, 10)),
+ "has_point() with negative position and point located on right edge should return false.");
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + Vector2i(10, 0)),
+ "has_point() with negative position and point located on top edge should return true.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + Vector2i(10, rect.size.y)),
+ "has_point() with negative position and point located on bottom edge should return false.");
+}
+
+TEST_CASE("[Rect2i] Intersection") {
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).intersects(Rect2i(0, 300, 100, 100)),
+ "intersects() with fully enclosed Rect2i should return the expected result.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).intersects(Rect2i(1200, 700, 100, 100)),
+ "intersects() with partially enclosed Rect2i should return the expected result.");
+ CHECK_MESSAGE(
+ !Rect2i(0, 100, 1280, 720).intersects(Rect2i(-4000, -4000, 100, 100)),
+ "intersects() with non-enclosed Rect2i should return the expected result.");
+ CHECK_MESSAGE(
+ !Rect2i(0, 0, 2, 2).intersects(Rect2i(2, 2, 2, 2)),
+ "intersects() with adjacent Rect2i should return the expected result.");
+}
+
+TEST_CASE("[Rect2i] Merging") {
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).merge(Rect2i(0, 300, 100, 100)) == Rect2i(0, 100, 1280, 720),
+ "merge() with fully enclosed Rect2i should return the expected result.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).merge(Rect2i(1200, 700, 100, 100)) == Rect2i(0, 100, 1300, 720),
+ "merge() with partially enclosed Rect2i should return the expected result.");
+ CHECK_MESSAGE(
+ Rect2i(0, 100, 1280, 720).merge(Rect2i(-4000, -4000, 100, 100)) == Rect2i(-4000, -4000, 5280, 4820),
+ "merge() with non-enclosed Rect2i should return the expected result.");
+}
+} // namespace TestRect2i
+
+#endif // TEST_RECT2I_H
diff --git a/tests/core/math/test_vector2.h b/tests/core/math/test_vector2.h
new file mode 100644
index 0000000000..9b7800164a
--- /dev/null
+++ b/tests/core/math/test_vector2.h
@@ -0,0 +1,389 @@
+/*************************************************************************/
+/* test_vector2.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_VECTOR2_H
+#define TEST_VECTOR2_H
+
+#include "core/math/vector2.h"
+#include "core/math/vector2i.h"
+#include "tests/test_macros.h"
+
+namespace TestVector2 {
+
+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),
+ "Vector2 angle_to should work as expected.");
+ CHECK_MESSAGE(
+ Math::is_equal_approx(vector_y.angle_to(vector_x), (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),
+ "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),
+ "Vector2 angle_to_point should work as expected.");
+}
+
+TEST_CASE("[Vector2] Axis methods") {
+ Vector2 vector = Vector2(1.2, 3.4);
+ CHECK_MESSAGE(
+ vector.max_axis_index() == Vector2::Axis::AXIS_Y,
+ "Vector2 max_axis_index should work as expected.");
+ CHECK_MESSAGE(
+ vector.min_axis_index() == Vector2::Axis::AXIS_X,
+ "Vector2 min_axis_index should work as expected.");
+ CHECK_MESSAGE(
+ vector[vector.min_axis_index()] == (real_t)1.2,
+ "Vector2 array operator should work as expected.");
+ vector[Vector2::Axis::AXIS_Y] = 3.7;
+ CHECK_MESSAGE(
+ vector[Vector2::Axis::AXIS_Y] == (real_t)3.7,
+ "Vector2 array operator setter should work as expected.");
+}
+
+TEST_CASE("[Vector2] Interpolation methods") {
+ const Vector2 vector1 = Vector2(1, 2);
+ const Vector2 vector2 = Vector2(4, 5);
+ CHECK_MESSAGE(
+ vector1.lerp(vector2, 0.5) == Vector2(2.5, 3.5),
+ "Vector2 lerp should work as expected.");
+ CHECK_MESSAGE(
+ vector1.lerp(vector2, 1.0 / 3.0).is_equal_approx(Vector2(2, 3)),
+ "Vector2 lerp should work as expected.");
+ CHECK_MESSAGE(
+ vector1.normalized().slerp(vector2.normalized(), 0.5).is_equal_approx(Vector2(0.538953602313995361, 0.84233558177947998)),
+ "Vector2 slerp should work as expected.");
+ CHECK_MESSAGE(
+ vector1.normalized().slerp(vector2.normalized(), 1.0 / 3.0).is_equal_approx(Vector2(0.508990883827209473, 0.860771894454956055)),
+ "Vector2 slerp should work as expected.");
+ CHECK_MESSAGE(
+ Vector2(5, 0).slerp(Vector2(0, 5), 0.5).is_equal_approx(Vector2(5, 5) * Math_SQRT12),
+ "Vector2 slerp with non-normalized values should work as expected.");
+ CHECK_MESSAGE(
+ Vector2(1, 1).slerp(Vector2(2, 2), 0.5).is_equal_approx(Vector2(1.5, 1.5)),
+ "Vector2 slerp with colinear inputs should behave as expected.");
+ CHECK_MESSAGE(
+ Vector2().slerp(Vector2(), 0.5) == Vector2(),
+ "Vector2 slerp with both inputs as zero vectors should return a zero vector.");
+ CHECK_MESSAGE(
+ Vector2().slerp(Vector2(1, 1), 0.5) == Vector2(0.5, 0.5),
+ "Vector2 slerp with one input as zero should behave like a regular lerp.");
+ CHECK_MESSAGE(
+ 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 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)),
+ "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),
+ "Vector2 cubic_interpolate should work as expected.");
+ CHECK_MESSAGE(
+ vector1.cubic_interpolate(vector2, Vector2(), Vector2(7, 7), 1.0 / 3.0).is_equal_approx(Vector2(1.851851940155029297, 2.962963104248046875)),
+ "Vector2 cubic_interpolate should work as expected.");
+ CHECK_MESSAGE(
+ Vector2(1, 0).move_toward(Vector2(10, 0), 3) == Vector2(4, 0),
+ "Vector2 move_toward should work as expected.");
+}
+
+TEST_CASE("[Vector2] Length methods") {
+ const Vector2 vector1 = Vector2(10, 10);
+ const Vector2 vector2 = Vector2(20, 30);
+ CHECK_MESSAGE(
+ 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),
+ "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 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),
+ "Vector2 distance_to should work as expected.");
+}
+
+TEST_CASE("[Vector2] Limiting methods") {
+ const Vector2 vector = Vector2(10, 10);
+ CHECK_MESSAGE(
+ vector.limit_length().is_equal_approx(Vector2(Math_SQRT12, Math_SQRT12)),
+ "Vector2 limit_length should work as expected.");
+ CHECK_MESSAGE(
+ vector.limit_length(5).is_equal_approx(5 * Vector2(Math_SQRT12, Math_SQRT12)),
+ "Vector2 limit_length should work as expected.");
+
+ CHECK_MESSAGE(
+ Vector2(-5, 15).clamp(Vector2(), vector).is_equal_approx(Vector2(0, 10)),
+ "Vector2 clamp should work as expected.");
+ CHECK_MESSAGE(
+ vector.clamp(Vector2(0, 15), Vector2(5, 20)).is_equal_approx(Vector2(5, 15)),
+ "Vector2 clamp should work as expected.");
+}
+
+TEST_CASE("[Vector2] Normalization methods") {
+ CHECK_MESSAGE(
+ Vector2(1, 0).is_normalized() == true,
+ "Vector2 is_normalized should return true for a normalized vector.");
+ CHECK_MESSAGE(
+ Vector2(1, 1).is_normalized() == false,
+ "Vector2 is_normalized should return false for a non-normalized vector.");
+ CHECK_MESSAGE(
+ Vector2(1, 0).normalized() == Vector2(1, 0),
+ "Vector2 normalized should return the same vector for a normalized vector.");
+ CHECK_MESSAGE(
+ Vector2(1, 1).normalized().is_equal_approx(Vector2(Math_SQRT12, Math_SQRT12)),
+ "Vector2 normalized should work as expected.");
+}
+
+TEST_CASE("[Vector2] Operators") {
+ const Vector2 decimal1 = Vector2(2.3, 4.9);
+ const Vector2 decimal2 = Vector2(1.2, 3.4);
+ const Vector2 power1 = Vector2(0.75, 1.5);
+ const Vector2 power2 = Vector2(0.5, 0.125);
+ const Vector2 int1 = Vector2(4, 5);
+ const Vector2 int2 = Vector2(1, 2);
+
+ CHECK_MESSAGE(
+ (decimal1 + decimal2).is_equal_approx(Vector2(3.5, 8.3)),
+ "Vector2 addition should behave as expected.");
+ CHECK_MESSAGE(
+ (power1 + power2) == Vector2(1.25, 1.625),
+ "Vector2 addition with powers of two should give exact results.");
+ CHECK_MESSAGE(
+ (int1 + int2) == Vector2(5, 7),
+ "Vector2 addition with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ (decimal1 - decimal2).is_equal_approx(Vector2(1.1, 1.5)),
+ "Vector2 subtraction should behave as expected.");
+ CHECK_MESSAGE(
+ (power1 - power2) == Vector2(0.25, 1.375),
+ "Vector2 subtraction with powers of two should give exact results.");
+ CHECK_MESSAGE(
+ (int1 - int2) == Vector2(3, 3),
+ "Vector2 subtraction with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ (decimal1 * decimal2).is_equal_approx(Vector2(2.76, 16.66)),
+ "Vector2 multiplication should behave as expected.");
+ CHECK_MESSAGE(
+ (power1 * power2) == Vector2(0.375, 0.1875),
+ "Vector2 multiplication with powers of two should give exact results.");
+ CHECK_MESSAGE(
+ (int1 * int2) == Vector2(4, 10),
+ "Vector2 multiplication with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ (decimal1 / decimal2).is_equal_approx(Vector2(1.91666666666666666, 1.44117647058823529)),
+ "Vector2 division should behave as expected.");
+ CHECK_MESSAGE(
+ (power1 / power2) == Vector2(1.5, 12.0),
+ "Vector2 division with powers of two should give exact results.");
+ CHECK_MESSAGE(
+ (int1 / int2) == Vector2(4, 2.5),
+ "Vector2 division with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ (decimal1 * 2).is_equal_approx(Vector2(4.6, 9.8)),
+ "Vector2 multiplication should behave as expected.");
+ CHECK_MESSAGE(
+ (power1 * 2) == Vector2(1.5, 3),
+ "Vector2 multiplication with powers of two should give exact results.");
+ CHECK_MESSAGE(
+ (int1 * 2) == Vector2(8, 10),
+ "Vector2 multiplication with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ (decimal1 / 2).is_equal_approx(Vector2(1.15, 2.45)),
+ "Vector2 division should behave as expected.");
+ CHECK_MESSAGE(
+ (power1 / 2) == Vector2(0.375, 0.75),
+ "Vector2 division with powers of two should give exact results.");
+ CHECK_MESSAGE(
+ (int1 / 2) == Vector2(2, 2.5),
+ "Vector2 division with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ ((Vector2i)decimal1) == Vector2i(2, 4),
+ "Vector2 cast to Vector2i should work as expected.");
+ CHECK_MESSAGE(
+ ((Vector2i)decimal2) == Vector2i(1, 3),
+ "Vector2 cast to Vector2i should work as expected.");
+ CHECK_MESSAGE(
+ Vector2(Vector2i(1, 2)) == Vector2(1, 2),
+ "Vector2 constructed from Vector2i should work as expected.");
+
+ CHECK_MESSAGE(
+ ((String)decimal1) == "(2.3, 4.9)",
+ "Vector2 cast to String should work as expected.");
+ CHECK_MESSAGE(
+ ((String)decimal2) == "(1.2, 3.4)",
+ "Vector2 cast to String should work as expected.");
+ CHECK_MESSAGE(
+ ((String)Vector2(9.8, 9.9)) == "(9.8, 9.9)",
+ "Vector2 cast to String should work as expected.");
+#ifdef REAL_T_IS_DOUBLE
+ CHECK_MESSAGE(
+ ((String)Vector2(Math_PI, Math_TAU)) == "(3.14159265358979, 6.28318530717959)",
+ "Vector2 cast to String should print the correct amount of digits for real_t = double.");
+#else
+ CHECK_MESSAGE(
+ ((String)Vector2(Math_PI, Math_TAU)) == "(3.141593, 6.283185)",
+ "Vector2 cast to String should print the correct amount of digits for real_t = float.");
+#endif // REAL_T_IS_DOUBLE
+}
+
+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),
+ "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.");
+ CHECK_MESSAGE(
+ (-vector).posmod(2).is_equal_approx(Vector2(0.8, 0.6)),
+ "Vector2 posmod should work as expected.");
+ CHECK_MESSAGE(
+ vector.posmodv(Vector2(1, 2)).is_equal_approx(Vector2(0.2, 1.4)),
+ "Vector2 posmodv should work as expected.");
+ 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 / 4).is_equal_approx(Vector2(-3.4, 1.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(
+ Vector2(3.4, 5.6).snapped(Vector2(1, 1)) == Vector2(3, 6),
+ "Vector2 snapped to integers should be the same as rounding.");
+ CHECK_MESSAGE(
+ vector.snapped(Vector2(0.25, 0.25)) == Vector2(1.25, 3.5),
+ "Vector2 snapped to 0.25 should give exact results.");
+}
+
+TEST_CASE("[Vector2] Plane methods") {
+ const Vector2 vector = Vector2(1.2, 3.4);
+ const Vector2 vector_y = Vector2(0, 1);
+ 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.reflect(vector_y) == Vector2(-1.2, 3.4),
+ "Vector2 reflect on a plane with normal of the Y axis should.");
+ CHECK_MESSAGE(
+ vector.project(vector_y) == Vector2(0, 3.4),
+ "Vector2 projected on the X axis should only give the Y component.");
+ 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.");
+}
+
+TEST_CASE("[Vector2] Rounding methods") {
+ const Vector2 vector1 = Vector2(1.2, 5.6);
+ const Vector2 vector2 = Vector2(1.2, -5.6);
+ CHECK_MESSAGE(
+ vector1.abs() == vector1,
+ "Vector2 abs should work as expected.");
+ CHECK_MESSAGE(
+ vector2.abs() == vector1,
+ "Vector2 abs should work as expected.");
+
+ CHECK_MESSAGE(
+ vector1.ceil() == Vector2(2, 6),
+ "Vector2 ceil should work as expected.");
+ CHECK_MESSAGE(
+ vector2.ceil() == Vector2(2, -5),
+ "Vector2 ceil should work as expected.");
+
+ CHECK_MESSAGE(
+ vector1.floor() == Vector2(1, 5),
+ "Vector2 floor should work as expected.");
+ CHECK_MESSAGE(
+ vector2.floor() == Vector2(1, -6),
+ "Vector2 floor should work as expected.");
+
+ CHECK_MESSAGE(
+ vector1.round() == Vector2(1, 6),
+ "Vector2 round should work as expected.");
+ CHECK_MESSAGE(
+ vector2.round() == Vector2(1, -6),
+ "Vector2 round should work as expected.");
+
+ CHECK_MESSAGE(
+ vector1.sign() == Vector2(1, 1),
+ "Vector2 sign should work as expected.");
+ CHECK_MESSAGE(
+ vector2.sign() == Vector2(1, -1),
+ "Vector2 sign should work as expected.");
+}
+
+TEST_CASE("[Vector2] Linear algebra methods") {
+ const Vector2 vector_x = Vector2(1, 0);
+ const Vector2 vector_y = Vector2(0, 1);
+ 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(
+ vector_x.dot(vector_y) == 0.0,
+ "Vector2 dot product of perpendicular vectors should be zero.");
+ CHECK_MESSAGE(
+ vector_x.dot(vector_x) == 1.0,
+ "Vector2 dot product of identical unit vectors should be one.");
+ CHECK_MESSAGE(
+ (vector_x * 10).dot(vector_x * 10) == 100.0,
+ "Vector2 dot product of same direction vectors should behave as expected.");
+}
+} // namespace TestVector2
+
+#endif // TEST_VECTOR2_H
diff --git a/tests/core/math/test_vector2i.h b/tests/core/math/test_vector2i.h
new file mode 100644
index 0000000000..841bb793a4
--- /dev/null
+++ b/tests/core/math/test_vector2i.h
@@ -0,0 +1,145 @@
+/*************************************************************************/
+/* test_vector2i.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_VECTOR2I_H
+#define TEST_VECTOR2I_H
+
+#include "core/math/vector2.h"
+#include "core/math/vector2i.h"
+#include "tests/test_macros.h"
+
+namespace TestVector2i {
+
+TEST_CASE("[Vector2i] Axis methods") {
+ Vector2i vector = Vector2i(2, 3);
+ CHECK_MESSAGE(
+ vector.max_axis_index() == Vector2i::Axis::AXIS_Y,
+ "Vector2i max_axis_index should work as expected.");
+ CHECK_MESSAGE(
+ vector.min_axis_index() == Vector2i::Axis::AXIS_X,
+ "Vector2i min_axis_index should work as expected.");
+ CHECK_MESSAGE(
+ vector[vector.min_axis_index()] == 2,
+ "Vector2i array operator should work as expected.");
+ vector[Vector2i::Axis::AXIS_Y] = 5;
+ CHECK_MESSAGE(
+ vector[Vector2i::Axis::AXIS_Y] == 5,
+ "Vector2i array operator setter should work as expected.");
+}
+
+TEST_CASE("[Vector2i] Clamp method") {
+ const Vector2i vector = Vector2i(10, 10);
+ CHECK_MESSAGE(
+ Vector2i(-5, 15).clamp(Vector2i(), vector) == Vector2i(0, 10),
+ "Vector2i clamp should work as expected.");
+ CHECK_MESSAGE(
+ vector.clamp(Vector2i(0, 15), Vector2i(5, 20)) == Vector2i(5, 15),
+ "Vector2i clamp should work as expected.");
+}
+
+TEST_CASE("[Vector2i] Length methods") {
+ const Vector2i vector1 = Vector2i(10, 10);
+ const Vector2i vector2 = Vector2i(20, 30);
+ CHECK_MESSAGE(
+ 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),
+ "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),
+ "Vector2i length should work as expected.");
+}
+
+TEST_CASE("[Vector2i] Operators") {
+ const Vector2i vector1 = Vector2i(5, 9);
+ const Vector2i vector2 = Vector2i(2, 3);
+
+ CHECK_MESSAGE(
+ (vector1 + vector2) == Vector2i(7, 12),
+ "Vector2i addition with integers should give exact results.");
+ CHECK_MESSAGE(
+ (vector1 - vector2) == Vector2i(3, 6),
+ "Vector2i subtraction with integers should give exact results.");
+ CHECK_MESSAGE(
+ (vector1 * vector2) == Vector2i(10, 27),
+ "Vector2i multiplication with integers should give exact results.");
+ CHECK_MESSAGE(
+ (vector1 / vector2) == Vector2i(2, 3),
+ "Vector2i division with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ (vector1 * 2) == Vector2i(10, 18),
+ "Vector2i multiplication with integers should give exact results.");
+ CHECK_MESSAGE(
+ (vector1 / 2) == Vector2i(2, 4),
+ "Vector2i division with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ ((Vector2)vector1) == Vector2(5, 9),
+ "Vector2i cast to Vector2 should work as expected.");
+ CHECK_MESSAGE(
+ ((Vector2)vector2) == Vector2(2, 3),
+ "Vector2i cast to Vector2 should work as expected.");
+ CHECK_MESSAGE(
+ Vector2i(Vector2(1.1, 2.9)) == Vector2i(1, 2),
+ "Vector2i constructed from Vector2 should work as expected.");
+}
+
+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),
+ "Vector2i aspect should work as expected.");
+}
+
+TEST_CASE("[Vector2i] Abs and sign methods") {
+ const Vector2i vector1 = Vector2i(1, 3);
+ const Vector2i vector2 = Vector2i(1, -3);
+ CHECK_MESSAGE(
+ vector1.abs() == vector1,
+ "Vector2i abs should work as expected.");
+ CHECK_MESSAGE(
+ vector2.abs() == vector1,
+ "Vector2i abs should work as expected.");
+
+ CHECK_MESSAGE(
+ vector1.sign() == Vector2i(1, 1),
+ "Vector2i sign should work as expected.");
+ CHECK_MESSAGE(
+ vector2.sign() == Vector2i(1, -1),
+ "Vector2i sign should work as expected.");
+}
+} // namespace TestVector2i
+
+#endif // TEST_VECTOR2I_H
diff --git a/tests/core/math/test_vector3.h b/tests/core/math/test_vector3.h
new file mode 100644
index 0000000000..6f99fada2b
--- /dev/null
+++ b/tests/core/math/test_vector3.h
@@ -0,0 +1,417 @@
+/*************************************************************************/
+/* test_vector3.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_VECTOR3_H
+#define TEST_VECTOR3_H
+
+#include "core/math/vector3.h"
+#include "tests/test_macros.h"
+
+#define Math_SQRT13 0.57735026918962576450914878050196
+#define Math_SQRT3 1.7320508075688772935274463415059
+
+namespace TestVector3 {
+
+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),
+ "Vector3 angle_to should work as expected.");
+ CHECK_MESSAGE(
+ Math::is_equal_approx(vector_x.angle_to(vector_yz), (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),
+ "Vector3 angle_to should work as expected.");
+ CHECK_MESSAGE(
+ Math::is_equal_approx(vector_y.angle_to(vector_yz), (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),
+ "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),
+ "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),
+ "Vector3 signed_angle_to should work as expected.");
+}
+
+TEST_CASE("[Vector3] Axis methods") {
+ Vector3 vector = Vector3(1.2, 3.4, 5.6);
+ CHECK_MESSAGE(
+ vector.max_axis_index() == Vector3::Axis::AXIS_Z,
+ "Vector3 max_axis_index should work as expected.");
+ CHECK_MESSAGE(
+ 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.");
+ 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,
+ "Vector3 array operator setter should work as expected.");
+}
+
+TEST_CASE("[Vector3] Interpolation methods") {
+ const Vector3 vector1 = Vector3(1, 2, 3);
+ const Vector3 vector2 = Vector3(4, 5, 6);
+ CHECK_MESSAGE(
+ vector1.lerp(vector2, 0.5) == Vector3(2.5, 3.5, 4.5),
+ "Vector3 lerp should work as expected.");
+ CHECK_MESSAGE(
+ vector1.lerp(vector2, 1.0 / 3.0).is_equal_approx(Vector3(2, 3, 4)),
+ "Vector3 lerp should work as expected.");
+ CHECK_MESSAGE(
+ vector1.normalized().slerp(vector2.normalized(), 0.5).is_equal_approx(Vector3(0.363866806030273438, 0.555698215961456299, 0.747529566287994385)),
+ "Vector3 slerp should work as expected.");
+ CHECK_MESSAGE(
+ vector1.normalized().slerp(vector2.normalized(), 1.0 / 3.0).is_equal_approx(Vector3(0.332119762897491455, 0.549413740634918213, 0.766707837581634521)),
+ "Vector3 slerp should work as expected.");
+ CHECK_MESSAGE(
+ Vector3(5, 0, 0).slerp(Vector3(0, 3, 4), 0.5).is_equal_approx(Vector3(3.535533905029296875, 2.121320486068725586, 2.828427314758300781)),
+ "Vector3 slerp with non-normalized values should work as expected.");
+ CHECK_MESSAGE(
+ Vector3(1, 1, 1).slerp(Vector3(2, 2, 2), 0.5).is_equal_approx(Vector3(1.5, 1.5, 1.5)),
+ "Vector3 slerp with colinear inputs should behave as expected.");
+ CHECK_MESSAGE(
+ Vector3().slerp(Vector3(), 0.5) == Vector3(),
+ "Vector3 slerp with both inputs as zero vectors should return a zero vector.");
+ CHECK_MESSAGE(
+ Vector3().slerp(Vector3(1, 1, 1), 0.5) == Vector3(0.5, 0.5, 0.5),
+ "Vector3 slerp with one input as zero should behave like a regular lerp.");
+ CHECK_MESSAGE(
+ 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 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)),
+ "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),
+ "Vector3 cubic_interpolate should work as expected.");
+ CHECK_MESSAGE(
+ vector1.cubic_interpolate(vector2, Vector3(), Vector3(7, 7, 7), 1.0 / 3.0).is_equal_approx(Vector3(1.851851940155029297, 2.962963104248046875, 4.074074268341064453)),
+ "Vector3 cubic_interpolate should work as expected.");
+ CHECK_MESSAGE(
+ Vector3(1, 0, 0).move_toward(Vector3(10, 0, 0), 3) == Vector3(4, 0, 0),
+ "Vector3 move_toward should work as expected.");
+}
+
+TEST_CASE("[Vector3] Length methods") {
+ const Vector3 vector1 = Vector3(10, 10, 10);
+ const Vector3 vector2 = Vector3(20, 30, 40);
+ CHECK_MESSAGE(
+ 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),
+ "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),
+ "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),
+ "Vector3 distance_to should work as expected.");
+}
+
+TEST_CASE("[Vector3] Limiting methods") {
+ const Vector3 vector = Vector3(10, 10, 10);
+ CHECK_MESSAGE(
+ vector.limit_length().is_equal_approx(Vector3(Math_SQRT13, Math_SQRT13, Math_SQRT13)),
+ "Vector3 limit_length should work as expected.");
+ CHECK_MESSAGE(
+ vector.limit_length(5).is_equal_approx(5 * Vector3(Math_SQRT13, Math_SQRT13, Math_SQRT13)),
+ "Vector3 limit_length should work as expected.");
+
+ CHECK_MESSAGE(
+ Vector3(-5, 5, 15).clamp(Vector3(), vector) == Vector3(0, 5, 10),
+ "Vector3 clamp should work as expected.");
+ CHECK_MESSAGE(
+ vector.clamp(Vector3(0, 10, 15), Vector3(5, 10, 20)) == Vector3(5, 10, 15),
+ "Vector3 clamp should work as expected.");
+}
+
+TEST_CASE("[Vector3] Normalization methods") {
+ CHECK_MESSAGE(
+ Vector3(1, 0, 0).is_normalized() == true,
+ "Vector3 is_normalized should return true for a normalized vector.");
+ CHECK_MESSAGE(
+ Vector3(1, 1, 1).is_normalized() == false,
+ "Vector3 is_normalized should return false for a non-normalized vector.");
+ CHECK_MESSAGE(
+ Vector3(1, 0, 0).normalized() == Vector3(1, 0, 0),
+ "Vector3 normalized should return the same vector for a normalized vector.");
+ CHECK_MESSAGE(
+ Vector3(1, 1, 0).normalized().is_equal_approx(Vector3(Math_SQRT12, Math_SQRT12, 0)),
+ "Vector3 normalized should work as expected.");
+ CHECK_MESSAGE(
+ Vector3(1, 1, 1).normalized().is_equal_approx(Vector3(Math_SQRT13, Math_SQRT13, Math_SQRT13)),
+ "Vector3 normalized should work as expected.");
+}
+
+TEST_CASE("[Vector3] Operators") {
+ const Vector3 decimal1 = Vector3(2.3, 4.9, 7.8);
+ const Vector3 decimal2 = Vector3(1.2, 3.4, 5.6);
+ const Vector3 power1 = Vector3(0.75, 1.5, 0.625);
+ const Vector3 power2 = Vector3(0.5, 0.125, 0.25);
+ const Vector3 int1 = Vector3(4, 5, 9);
+ const Vector3 int2 = Vector3(1, 2, 3);
+
+ CHECK_MESSAGE(
+ (decimal1 + decimal2).is_equal_approx(Vector3(3.5, 8.3, 13.4)),
+ "Vector3 addition should behave as expected.");
+ CHECK_MESSAGE(
+ (power1 + power2) == Vector3(1.25, 1.625, 0.875),
+ "Vector3 addition with powers of two should give exact results.");
+ CHECK_MESSAGE(
+ (int1 + int2) == Vector3(5, 7, 12),
+ "Vector3 addition with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ (decimal1 - decimal2).is_equal_approx(Vector3(1.1, 1.5, 2.2)),
+ "Vector3 subtraction should behave as expected.");
+ CHECK_MESSAGE(
+ (power1 - power2) == Vector3(0.25, 1.375, 0.375),
+ "Vector3 subtraction with powers of two should give exact results.");
+ CHECK_MESSAGE(
+ (int1 - int2) == Vector3(3, 3, 6),
+ "Vector3 subtraction with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ (decimal1 * decimal2).is_equal_approx(Vector3(2.76, 16.66, 43.68)),
+ "Vector3 multiplication should behave as expected.");
+ CHECK_MESSAGE(
+ (power1 * power2) == Vector3(0.375, 0.1875, 0.15625),
+ "Vector3 multiplication with powers of two should give exact results.");
+ CHECK_MESSAGE(
+ (int1 * int2) == Vector3(4, 10, 27),
+ "Vector3 multiplication with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ (decimal1 / decimal2).is_equal_approx(Vector3(1.91666666666666666, 1.44117647058823529, 1.39285714285714286)),
+ "Vector3 division should behave as expected.");
+ CHECK_MESSAGE(
+ (power1 / power2) == Vector3(1.5, 12.0, 2.5),
+ "Vector3 division with powers of two should give exact results.");
+ CHECK_MESSAGE(
+ (int1 / int2) == Vector3(4, 2.5, 3),
+ "Vector3 division with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ (decimal1 * 2).is_equal_approx(Vector3(4.6, 9.8, 15.6)),
+ "Vector3 multiplication should behave as expected.");
+ CHECK_MESSAGE(
+ (power1 * 2) == Vector3(1.5, 3, 1.25),
+ "Vector3 multiplication with powers of two should give exact results.");
+ CHECK_MESSAGE(
+ (int1 * 2) == Vector3(8, 10, 18),
+ "Vector3 multiplication with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ (decimal1 / 2).is_equal_approx(Vector3(1.15, 2.45, 3.9)),
+ "Vector3 division should behave as expected.");
+ CHECK_MESSAGE(
+ (power1 / 2) == Vector3(0.375, 0.75, 0.3125),
+ "Vector3 division with powers of two should give exact results.");
+ CHECK_MESSAGE(
+ (int1 / 2) == Vector3(2, 2.5, 4.5),
+ "Vector3 division with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ ((Vector3i)decimal1) == Vector3i(2, 4, 7),
+ "Vector3 cast to Vector3i should work as expected.");
+ CHECK_MESSAGE(
+ ((Vector3i)decimal2) == Vector3i(1, 3, 5),
+ "Vector3 cast to Vector3i should work as expected.");
+ CHECK_MESSAGE(
+ Vector3(Vector3i(1, 2, 3)) == Vector3(1, 2, 3),
+ "Vector3 constructed from Vector3i should work as expected.");
+
+ CHECK_MESSAGE(
+ ((String)decimal1) == "(2.3, 4.9, 7.8)",
+ "Vector3 cast to String should work as expected.");
+ CHECK_MESSAGE(
+ ((String)decimal2) == "(1.2, 3.4, 5.6)",
+ "Vector3 cast to String should work as expected.");
+ CHECK_MESSAGE(
+ ((String)Vector3(9.7, 9.8, 9.9)) == "(9.7, 9.8, 9.9)",
+ "Vector3 cast to String should work as expected.");
+#ifdef REAL_T_IS_DOUBLE
+ CHECK_MESSAGE(
+ ((String)Vector3(Math_E, Math_SQRT2, Math_SQRT3)) == "(2.71828182845905, 1.4142135623731, 1.73205080756888)",
+ "Vector3 cast to String should print the correct amount of digits for real_t = double.");
+#else
+ CHECK_MESSAGE(
+ ((String)Vector3(Math_E, Math_SQRT2, Math_SQRT3)) == "(2.718282, 1.414214, 1.732051)",
+ "Vector3 cast to String should print the correct amount of digits for real_t = float.");
+#endif // REAL_T_IS_DOUBLE
+}
+
+TEST_CASE("[Vector3] Other methods") {
+ const Vector3 vector = Vector3(1.2, 3.4, 5.6);
+ CHECK_MESSAGE(
+ vector.direction_to(Vector3()).is_equal_approx(-vector.normalized()),
+ "Vector3 direction_to should work as expected.");
+ CHECK_MESSAGE(
+ Vector3(1, 1, 1).direction_to(Vector3(2, 2, 2)).is_equal_approx(Vector3(Math_SQRT13, Math_SQRT13, Math_SQRT13)),
+ "Vector3 direction_to should work as expected.");
+ CHECK_MESSAGE(
+ vector.inverse().is_equal_approx(Vector3(1 / 1.2, 1 / 3.4, 1 / 5.6)),
+ "Vector3 inverse should work as expected.");
+ CHECK_MESSAGE(
+ vector.posmod(2).is_equal_approx(Vector3(1.2, 1.4, 1.6)),
+ "Vector3 posmod should work as expected.");
+ CHECK_MESSAGE(
+ (-vector).posmod(2).is_equal_approx(Vector3(0.8, 0.6, 0.4)),
+ "Vector3 posmod should work as expected.");
+ CHECK_MESSAGE(
+ vector.posmodv(Vector3(1, 2, 3)).is_equal_approx(Vector3(0.2, 1.4, 2.6)),
+ "Vector3 posmodv should work as expected.");
+ 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 / 4).is_equal_approx(Vector3(5.6, 3.4, -1.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(
+ vector.snapped(Vector3(0.25, 0.25, 0.25)) == Vector3(1.25, 3.5, 5.5),
+ "Vector3 snapped to 0.25 should give exact results.");
+}
+
+TEST_CASE("[Vector3] Plane methods") {
+ const Vector3 vector = Vector3(1.2, 3.4, 5.6);
+ const Vector3 vector_y = Vector3(0, 1, 0);
+ 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.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.project(vector_y) == Vector3(0, 3.4, 0),
+ "Vector3 projected on the X axis should only give the Y component.");
+ 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.");
+}
+
+TEST_CASE("[Vector3] Rounding methods") {
+ const Vector3 vector1 = Vector3(1.2, 3.4, 5.6);
+ const Vector3 vector2 = Vector3(1.2, -3.4, -5.6);
+ CHECK_MESSAGE(
+ vector1.abs() == vector1,
+ "Vector3 abs should work as expected.");
+ CHECK_MESSAGE(
+ vector2.abs() == vector1,
+ "Vector3 abs should work as expected.");
+
+ CHECK_MESSAGE(
+ vector1.ceil() == Vector3(2, 4, 6),
+ "Vector3 ceil should work as expected.");
+ CHECK_MESSAGE(
+ vector2.ceil() == Vector3(2, -3, -5),
+ "Vector3 ceil should work as expected.");
+
+ CHECK_MESSAGE(
+ vector1.floor() == Vector3(1, 3, 5),
+ "Vector3 floor should work as expected.");
+ CHECK_MESSAGE(
+ vector2.floor() == Vector3(1, -4, -6),
+ "Vector3 floor should work as expected.");
+
+ CHECK_MESSAGE(
+ vector1.round() == Vector3(1, 3, 6),
+ "Vector3 round should work as expected.");
+ CHECK_MESSAGE(
+ vector2.round() == Vector3(1, -3, -6),
+ "Vector3 round should work as expected.");
+
+ CHECK_MESSAGE(
+ vector1.sign() == Vector3(1, 1, 1),
+ "Vector3 sign should work as expected.");
+ CHECK_MESSAGE(
+ vector2.sign() == Vector3(1, -1, -1),
+ "Vector3 sign should work as expected.");
+}
+
+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);
+ CHECK_MESSAGE(
+ vector_x.cross(vector_y) == vector_z,
+ "Vector3 cross product of X and Y should give Z.");
+ CHECK_MESSAGE(
+ vector_y.cross(vector_x) == -vector_z,
+ "Vector3 cross product of Y and X should give negative Z.");
+ CHECK_MESSAGE(
+ vector_y.cross(vector_z) == vector_x,
+ "Vector3 cross product of Y and Z should give X.");
+ CHECK_MESSAGE(
+ vector_z.cross(vector_x) == vector_y,
+ "Vector3 cross product of Z and X should give Y.");
+
+ CHECK_MESSAGE(
+ vector_x.dot(vector_y) == 0.0,
+ "Vector3 dot product of perpendicular vectors should be zero.");
+ CHECK_MESSAGE(
+ vector_x.dot(vector_x) == 1.0,
+ "Vector3 dot product of identical unit vectors should be one.");
+ CHECK_MESSAGE(
+ (vector_x * 10).dot(vector_x * 10) == 100.0,
+ "Vector3 dot product of same direction vectors should behave as expected.");
+}
+} // namespace TestVector3
+
+#endif // TEST_VECTOR3_H
diff --git a/tests/core/math/test_vector3i.h b/tests/core/math/test_vector3i.h
new file mode 100644
index 0000000000..b1c6944eba
--- /dev/null
+++ b/tests/core/math/test_vector3i.h
@@ -0,0 +1,145 @@
+/*************************************************************************/
+/* test_vector3i.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_VECTOR3I_H
+#define TEST_VECTOR3I_H
+
+#include "core/math/vector3i.h"
+#include "tests/test_macros.h"
+
+namespace TestVector3i {
+
+TEST_CASE("[Vector3i] Axis methods") {
+ Vector3i vector = Vector3i(1, 2, 3);
+ CHECK_MESSAGE(
+ vector.max_axis_index() == Vector3i::Axis::AXIS_Z,
+ "Vector3i max_axis_index should work as expected.");
+ CHECK_MESSAGE(
+ 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.");
+ 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,
+ "Vector3i array operator setter should work as expected.");
+}
+
+TEST_CASE("[Vector3i] Clamp method") {
+ const Vector3i vector = Vector3i(10, 10, 10);
+ CHECK_MESSAGE(
+ Vector3i(-5, 5, 15).clamp(Vector3i(), vector) == Vector3i(0, 5, 10),
+ "Vector3i clamp should work as expected.");
+ CHECK_MESSAGE(
+ vector.clamp(Vector3i(0, 10, 15), Vector3i(5, 10, 20)) == Vector3i(5, 10, 15),
+ "Vector3i clamp should work as expected.");
+}
+
+TEST_CASE("[Vector3i] Length methods") {
+ const Vector3i vector1 = Vector3i(10, 10, 10);
+ const Vector3i vector2 = Vector3i(20, 30, 40);
+ CHECK_MESSAGE(
+ 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),
+ "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),
+ "Vector3i length should work as expected.");
+}
+
+TEST_CASE("[Vector3i] Operators") {
+ const Vector3i vector1 = Vector3i(4, 5, 9);
+ const Vector3i vector2 = Vector3i(1, 2, 3);
+
+ CHECK_MESSAGE(
+ (vector1 + vector2) == Vector3i(5, 7, 12),
+ "Vector3i addition with integers should give exact results.");
+ CHECK_MESSAGE(
+ (vector1 - vector2) == Vector3i(3, 3, 6),
+ "Vector3i subtraction with integers should give exact results.");
+ CHECK_MESSAGE(
+ (vector1 * vector2) == Vector3i(4, 10, 27),
+ "Vector3i multiplication with integers should give exact results.");
+ CHECK_MESSAGE(
+ (vector1 / vector2) == Vector3i(4, 2, 3),
+ "Vector3i division with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ (vector1 * 2) == Vector3i(8, 10, 18),
+ "Vector3i multiplication with integers should give exact results.");
+ CHECK_MESSAGE(
+ (vector1 / 2) == Vector3i(2, 2, 4),
+ "Vector3i division with integers should give exact results.");
+
+ CHECK_MESSAGE(
+ ((Vector3)vector1) == Vector3(4, 5, 9),
+ "Vector3i cast to Vector3 should work as expected.");
+ CHECK_MESSAGE(
+ ((Vector3)vector2) == Vector3(1, 2, 3),
+ "Vector3i cast to Vector3 should work as expected.");
+ CHECK_MESSAGE(
+ Vector3i(Vector3(1.1, 2.9, 3.9)) == Vector3i(1, 2, 3),
+ "Vector3i constructed from Vector3 should work as expected.");
+}
+
+TEST_CASE("[Vector3i] Abs and sign methods") {
+ const Vector3i vector1 = Vector3i(1, 3, 5);
+ const Vector3i vector2 = Vector3i(1, -3, -5);
+ CHECK_MESSAGE(
+ vector1.abs() == vector1,
+ "Vector3i abs should work as expected.");
+ CHECK_MESSAGE(
+ vector2.abs() == vector1,
+ "Vector3i abs should work as expected.");
+
+ CHECK_MESSAGE(
+ vector1.sign() == Vector3i(1, 1, 1),
+ "Vector3i sign should work as expected.");
+ CHECK_MESSAGE(
+ vector2.sign() == Vector3i(1, -1, -1),
+ "Vector3i sign should work as expected.");
+}
+} // namespace TestVector3i
+
+#endif // TEST_VECTOR3I_H
diff --git a/tests/core/object/test_class_db.h b/tests/core/object/test_class_db.h
index 4b27905485..c7535426df 100644
--- a/tests/core/object/test_class_db.h
+++ b/tests/core/object/test_class_db.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -46,7 +46,7 @@ struct TypeReference {
struct ConstantData {
String name;
- int value = 0;
+ int64_t value = 0;
};
struct EnumData {
@@ -173,7 +173,7 @@ struct NamesCache {
}
};
-typedef OrderedHashMap<StringName, ExposedClass> ExposedClasses;
+typedef HashMap<StringName, ExposedClass> ExposedClasses;
struct Context {
Vector<StringName> enum_types;
@@ -183,13 +183,13 @@ struct Context {
NamesCache names_cache;
const ExposedClass *find_exposed_class(const StringName &p_name) const {
- ExposedClasses::ConstElement elem = exposed_classes.find(p_name);
- return elem ? &elem.value() : nullptr;
+ ExposedClasses::ConstIterator elem = exposed_classes.find(p_name);
+ return elem ? &elem->value : nullptr;
}
const ExposedClass *find_exposed_class(const TypeReference &p_type_ref) const {
- ExposedClasses::ConstElement elem = exposed_classes.find(p_type_ref.name);
- return elem ? &elem.value() : nullptr;
+ ExposedClasses::ConstIterator elem = exposed_classes.find(p_type_ref.name);
+ return elem ? &elem->value : nullptr;
}
bool has_type(const TypeReference &p_type_ref) const {
@@ -519,7 +519,7 @@ void add_exposed_classes(Context &r_context) {
List<PropertyInfo> property_list;
ClassDB::get_property_list(class_name, &property_list, true);
- Map<StringName, StringName> accessor_methods;
+ HashMap<StringName, StringName> accessor_methods;
for (const PropertyInfo &property : property_list) {
if (property.usage & PROPERTY_USAGE_GROUP || property.usage & PROPERTY_USAGE_SUBGROUP || property.usage & PROPERTY_USAGE_CATEGORY || (property.type == Variant::NIL && property.usage & PROPERTY_USAGE_ARRAY)) {
@@ -597,7 +597,7 @@ void add_exposed_classes(Context &r_context) {
(exposed_class.name != r_context.names_cache.object_class || String(method.name) != "free"),
warn_msg.utf8().get_data());
- } else if (return_info.type == Variant::INT && return_info.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
+ } else if (return_info.type == Variant::INT && return_info.usage & (PROPERTY_USAGE_CLASS_IS_ENUM | PROPERTY_USAGE_CLASS_IS_BITFIELD)) {
method.return_type.name = return_info.class_name;
method.return_type.is_enum = true;
} else if (return_info.class_name != StringName()) {
@@ -626,7 +626,7 @@ void add_exposed_classes(Context &r_context) {
ArgumentData arg;
arg.name = orig_arg_name;
- if (arg_info.type == Variant::INT && arg_info.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
+ if (arg_info.type == Variant::INT && arg_info.usage & (PROPERTY_USAGE_CLASS_IS_ENUM | PROPERTY_USAGE_CLASS_IS_BITFIELD)) {
arg.type.name = arg_info.class_name;
arg.type.is_enum = true;
} else if (arg_info.class_name != StringName()) {
@@ -671,21 +671,16 @@ 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
const HashMap<StringName, MethodInfo> &signal_map = class_info->signal_map;
- const StringName *k = nullptr;
- while ((k = signal_map.next(k))) {
+ for (const KeyValue<StringName, MethodInfo> &K : signal_map) {
SignalData signal;
- const MethodInfo &method_info = signal_map.get(*k);
+ const MethodInfo &method_info = signal_map.get(K.key);
signal.name = method_info.name;
@@ -699,7 +694,7 @@ void add_exposed_classes(Context &r_context) {
ArgumentData arg;
arg.name = orig_arg_name;
- if (arg_info.type == Variant::INT && arg_info.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
+ if (arg_info.type == Variant::INT && arg_info.usage & (PROPERTY_USAGE_CLASS_IS_ENUM | PROPERTY_USAGE_CLASS_IS_BITFIELD)) {
arg.type.name = arg_info.class_name;
arg.type.is_enum = true;
} else if (arg_info.class_name != StringName()) {
@@ -737,20 +732,18 @@ void add_exposed_classes(Context &r_context) {
List<String> constants;
ClassDB::get_integer_constant_list(class_name, &constants, true);
- const HashMap<StringName, List<StringName>> &enum_map = class_info->enum_map;
- k = nullptr;
+ const HashMap<StringName, ClassDB::ClassInfo::EnumInfo> &enum_map = class_info->enum_map;
- while ((k = enum_map.next(k))) {
+ for (const KeyValue<StringName, ClassDB::ClassInfo::EnumInfo> &K : enum_map) {
EnumData enum_;
- enum_.name = *k;
+ enum_.name = K.key;
- const List<StringName> &enum_constants = enum_map.get(*k);
- for (const StringName &E : enum_constants) {
+ for (const StringName &E : K.value.constants) {
const StringName &constant_name = E;
TEST_FAIL_COND(String(constant_name).find("::") != -1,
"Enum constant contains '::', check bindings to remove the scope: '",
String(class_name), ".", String(enum_.name), ".", String(constant_name), "'.");
- int *value = class_info->constant_map.getptr(constant_name);
+ int64_t *value = class_info->constant_map.getptr(constant_name);
TEST_FAIL_COND(!value, "Missing enum constant value: '",
String(class_name), ".", String(enum_.name), ".", String(constant_name), "'.");
constants.erase(constant_name);
@@ -764,7 +757,7 @@ void add_exposed_classes(Context &r_context) {
exposed_class.enums.push_back(enum_);
- r_context.enum_types.push_back(String(class_name) + "." + String(*k));
+ r_context.enum_types.push_back(String(class_name) + "." + String(K.key));
}
for (const String &E : constants) {
@@ -772,7 +765,7 @@ void add_exposed_classes(Context &r_context) {
TEST_FAIL_COND(constant_name.find("::") != -1,
"Constant contains '::', check bindings to remove the scope: '",
String(class_name), ".", constant_name, "'.");
- int *value = class_info->constant_map.getptr(StringName(E));
+ int64_t *value = class_info->constant_map.getptr(StringName(E));
TEST_FAIL_COND(!value, "Missing constant value: '", String(class_name), ".", String(constant_name), "'.");
ConstantData constant;
@@ -854,8 +847,8 @@ TEST_SUITE("[ClassDB]") {
TEST_FAIL_COND(object_class->base != StringName(),
"Object class derives from another class: '", object_class->base, "'.");
- for (ExposedClasses::Element E = context.exposed_classes.front(); E; E = E.next()) {
- validate_class(context, E.value());
+ for (const KeyValue<StringName, ExposedClass> &E : context.exposed_classes) {
+ validate_class(context, E.value);
}
}
}
diff --git a/tests/core/object/test_method_bind.h b/tests/core/object/test_method_bind.h
index c3a869a8a4..350a08b6e2 100644
--- a/tests/core/object/test_method_bind.h
+++ b/tests/core/object/test_method_bind.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -51,9 +51,15 @@ public:
TEST_METHODRC,
TEST_METHODRC_ARGS,
TEST_METHOD_DEFARGS,
+ TEST_METHOD_OBJECT_CAST,
TEST_MAX
};
+ class ObjectSubclass : public Object {
+ public:
+ int value = 1;
+ };
+
int test_num = 0;
bool test_valid[TEST_MAX];
@@ -98,6 +104,10 @@ public:
test_valid[TEST_METHOD_DEFARGS] = p_arg1 == 1 && p_arg2 == 2 && p_arg3 == 3 && p_arg4 == 4 && p_arg5 == 5; //temporary
}
+ void test_method_object_cast(ObjectSubclass *p_object) {
+ test_valid[TEST_METHOD_OBJECT_CAST] = p_object->value == 1;
+ }
+
static void _bind_methods() {
ClassDB::bind_method(D_METHOD("test_method"), &MethodBindTester::test_method);
ClassDB::bind_method(D_METHOD("test_method_args"), &MethodBindTester::test_method_args);
@@ -108,6 +118,7 @@ public:
ClassDB::bind_method(D_METHOD("test_methodrc"), &MethodBindTester::test_methodrc);
ClassDB::bind_method(D_METHOD("test_methodrc_args"), &MethodBindTester::test_methodrc_args);
ClassDB::bind_method(D_METHOD("test_method_default_args"), &MethodBindTester::test_method_default_args, DEFVAL(9) /* wrong on purpose */, DEFVAL(4), DEFVAL(5));
+ ClassDB::bind_method(D_METHOD("test_method_object_cast", "object"), &MethodBindTester::test_method_object_cast);
}
virtual void run_tests() {
@@ -134,6 +145,10 @@ public:
test_valid[TEST_METHODRC_ARGS] = int(call("test_methodrc_args", test_num)) == test_num && test_valid[TEST_METHODRC_ARGS];
call("test_method_default_args", 1, 2, 3, 4);
+
+ ObjectSubclass *obj = memnew(ObjectSubclass);
+ call("test_method_object_cast", obj);
+ memdelete(obj);
}
};
@@ -152,6 +167,7 @@ TEST_CASE("[MethodBind] check all method binds") {
CHECK(mbt->test_valid[MethodBindTester::TEST_METHODRC]);
CHECK(mbt->test_valid[MethodBindTester::TEST_METHODRC_ARGS]);
CHECK(mbt->test_valid[MethodBindTester::TEST_METHOD_DEFARGS]);
+ CHECK(mbt->test_valid[MethodBindTester::TEST_METHOD_OBJECT_CAST]);
memdelete(mbt);
}
diff --git a/tests/core/object/test_object.h b/tests/core/object/test_object.h
index 4109ea521a..88a3e4ccad 100644
--- a/tests/core/object/test_object.h
+++ b/tests/core/object/test_object.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -87,7 +87,7 @@ public:
bool has_method(const StringName &p_method) const override {
return false;
}
- Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override {
+ 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 {
@@ -95,8 +95,8 @@ public:
Ref<Script> get_script() const override {
return Ref<Script>();
}
- const Vector<Multiplayer::RPCConfig> get_rpc_methods() const override {
- return Vector<Multiplayer::RPCConfig>();
+ const Variant get_rpc_config() const override {
+ return Variant();
}
ScriptLanguage *get_language() override {
return nullptr;
@@ -133,7 +133,7 @@ TEST_CASE("[Object] Core getters") {
}
TEST_CASE("[Object] Metadata") {
- const String meta_path = "hello/world complex métadata\n\n\t\tpath";
+ const String meta_path = "complex_metadata_path";
Object object;
object.set_meta(meta_path, Color(0, 1, 0));
diff --git a/tests/core/os/test_os.h b/tests/core/os/test_os.h
new file mode 100644
index 0000000000..c46da5e156
--- /dev/null
+++ b/tests/core/os/test_os.h
@@ -0,0 +1,158 @@
+/*************************************************************************/
+/* test_os.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_OS_H
+#define TEST_OS_H
+
+#include "core/os/os.h"
+
+#include "thirdparty/doctest/doctest.h"
+
+namespace TestOS {
+
+TEST_CASE("[OS] Environment variables") {
+#ifdef WINDOWS_ENABLED
+ CHECK_MESSAGE(
+ OS::get_singleton()->has_environment("USERPROFILE"),
+ "The USERPROFILE environment variable should be present.");
+#else
+ CHECK_MESSAGE(
+ OS::get_singleton()->has_environment("HOME"),
+ "The HOME environment variable should be present.");
+#endif
+
+ OS::get_singleton()->set_environment("HELLO", "world");
+ CHECK_MESSAGE(
+ OS::get_singleton()->get_environment("HELLO") == "world",
+ "The previously-set HELLO environment variable should return the expected value.");
+}
+
+TEST_CASE("[OS] Command line arguments") {
+ List<String> arguments = OS::get_singleton()->get_cmdline_args();
+ bool found = false;
+ for (int i = 0; i < arguments.size(); i++) {
+ if (arguments[i] == "--test") {
+ found = true;
+ break;
+ }
+ }
+ CHECK_MESSAGE(
+ found,
+ "The `--test` option must be present in the list of command line arguments.");
+}
+
+TEST_CASE("[OS] Executable and data paths") {
+ CHECK_MESSAGE(
+ OS::get_singleton()->get_executable_path().is_absolute_path(),
+ "The executable path returned should be an absolute path.");
+ CHECK_MESSAGE(
+ OS::get_singleton()->get_data_path().is_absolute_path(),
+ "The user data path returned should be an absolute path.");
+ CHECK_MESSAGE(
+ OS::get_singleton()->get_config_path().is_absolute_path(),
+ "The user configuration path returned should be an absolute path.");
+ CHECK_MESSAGE(
+ OS::get_singleton()->get_cache_path().is_absolute_path(),
+ "The cache path returned should be an absolute path.");
+}
+
+TEST_CASE("[OS] Ticks") {
+ CHECK_MESSAGE(
+ OS::get_singleton()->get_ticks_usec() > 1000,
+ "The returned ticks (in microseconds) must be greater than 1,000.");
+ CHECK_MESSAGE(
+ OS::get_singleton()->get_ticks_msec() > 1,
+ "The returned ticks (in milliseconds) must be greater than 1.");
+}
+
+TEST_CASE("[OS] Feature tags") {
+ CHECK_MESSAGE(
+ OS::get_singleton()->has_feature("editor"),
+ "The binary has the \"editor\" feature tag.");
+ CHECK_MESSAGE(
+ !OS::get_singleton()->has_feature("standalone"),
+ "The binary does not have the \"standalone\" feature tag.");
+ CHECK_MESSAGE(
+ OS::get_singleton()->has_feature("debug"),
+ "The binary has the \"debug\" feature tag.");
+ CHECK_MESSAGE(
+ !OS::get_singleton()->has_feature("release"),
+ "The binary does not have the \"release\" feature tag.");
+}
+
+TEST_CASE("[OS] Process ID") {
+ CHECK_MESSAGE(
+ OS::get_singleton()->get_process_id() >= 1,
+ "The returned process ID should be greater than zero.");
+}
+
+TEST_CASE("[OS] Processor count and memory information") {
+ CHECK_MESSAGE(
+ OS::get_singleton()->get_processor_count() >= 1,
+ "The returned processor count should be greater than zero.");
+ CHECK_MESSAGE(
+ OS::get_singleton()->get_static_memory_usage() >= 1,
+ "The returned static memory usage should be greater than zero.");
+ CHECK_MESSAGE(
+ OS::get_singleton()->get_static_memory_peak_usage() >= 1,
+ "The returned static memory peak usage should be greater than zero.");
+}
+
+TEST_CASE("[OS] Execute") {
+#ifdef WINDOWS_ENABLED
+ List<String> arguments;
+ arguments.push_back("/C");
+ arguments.push_back("dir > NUL");
+ int exit_code;
+ const Error err = OS::get_singleton()->execute("cmd", arguments, nullptr, &exit_code);
+ CHECK_MESSAGE(
+ err == OK,
+ "(Running the command `cmd /C \"dir > NUL\"` returns the expected Godot error code (OK).");
+ CHECK_MESSAGE(
+ exit_code == 0,
+ "Running the command `cmd /C \"dir > NUL\"` returns a zero (successful) exit code.");
+#else
+ List<String> arguments;
+ arguments.push_back("-c");
+ arguments.push_back("ls > /dev/null");
+ int exit_code;
+ const Error err = OS::get_singleton()->execute("sh", arguments, nullptr, &exit_code);
+ CHECK_MESSAGE(
+ err == OK,
+ "(Running the command `sh -c \"ls > /dev/null\"` returns the expected Godot error code (OK).");
+ CHECK_MESSAGE(
+ exit_code == 0,
+ "Running the command `sh -c \"ls > /dev/null\"` returns a zero (successful) exit code.");
+#endif
+}
+
+} // namespace TestOS
+
+#endif // TEST_OS_H
diff --git a/tests/core/string/test_node_path.h b/tests/core/string/test_node_path.h
index 0216a30f8f..d2de766889 100644
--- a/tests/core/string/test_node_path.h
+++ b/tests/core/string/test_node_path.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h
index eef1cac894..0c5704d6c9 100644
--- a/tests/core/string/test_string.h
+++ b/tests/core/string/test_string.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -38,8 +38,9 @@
namespace TestString {
int u32scmp(const char32_t *l, const char32_t *r) {
- for (; *l == *r && *l && *r; l++, r++)
- ;
+ for (; *l == *r && *l && *r; l++, r++) {
+ // Continue.
+ }
return *l - *r;
}
@@ -88,12 +89,12 @@ TEST_CASE("[String] UTF8") {
static const char32_t u32str[] = { 0x0045, 0x0020, 0x304A, 0x360F, 0x3088, 0x3046, 0x1F3A4, 0 };
static const uint8_t u8str[] = { 0x45, 0x20, 0xE3, 0x81, 0x8A, 0xE3, 0x98, 0x8F, 0xE3, 0x82, 0x88, 0xE3, 0x81, 0x86, 0xF0, 0x9F, 0x8E, 0xA4, 0 };
String s = u32str;
- bool err = s.parse_utf8(s.utf8().get_data());
- CHECK(!err);
+ Error err = s.parse_utf8(s.utf8().get_data());
+ CHECK(err == OK);
CHECK(s == u32str);
err = s.parse_utf8((const char *)u8str);
- CHECK(!err);
+ CHECK(err == OK);
CHECK(s == u32str);
CharString cs = (const char *)u8str;
@@ -105,12 +106,12 @@ TEST_CASE("[String] UTF16") {
static const char32_t u32str[] = { 0x0045, 0x0020, 0x304A, 0x360F, 0x3088, 0x3046, 0x1F3A4, 0 };
static const char16_t u16str[] = { 0x0045, 0x0020, 0x304A, 0x360F, 0x3088, 0x3046, 0xD83C, 0xDFA4, 0 };
String s = u32str;
- bool err = s.parse_utf16(s.utf16().get_data());
- CHECK(!err);
+ Error err = s.parse_utf16(s.utf16().get_data());
+ CHECK(err == OK);
CHECK(s == u32str);
err = s.parse_utf16(u16str);
- CHECK(!err);
+ CHECK(err == OK);
CHECK(s == u32str);
Char16String cs = u16str;
@@ -122,8 +123,8 @@ TEST_CASE("[String] UTF8 with BOM") {
static const char32_t u32str[] = { 0x0045, 0x0020, 0x304A, 0x360F, 0x3088, 0x3046, 0x1F3A4, 0 };
static const uint8_t u8str[] = { 0xEF, 0xBB, 0xBF, 0x45, 0x20, 0xE3, 0x81, 0x8A, 0xE3, 0x98, 0x8F, 0xE3, 0x82, 0x88, 0xE3, 0x81, 0x86, 0xF0, 0x9F, 0x8E, 0xA4, 0 };
String s;
- bool err = s.parse_utf8((const char *)u8str);
- CHECK(!err);
+ Error err = s.parse_utf8((const char *)u8str);
+ CHECK(err == OK);
CHECK(s == u32str);
CharString cs = (const char *)u8str;
@@ -136,12 +137,12 @@ TEST_CASE("[String] UTF16 with BOM") {
static const char16_t u16str[] = { 0xFEFF, 0x0020, 0x0045, 0x304A, 0x360F, 0x3088, 0x3046, 0xD83C, 0xDFA4, 0 };
static const char16_t u16str_swap[] = { 0xFFFE, 0x2000, 0x4500, 0x4A30, 0x0F36, 0x8830, 0x4630, 0x3CD8, 0xA4DF, 0 };
String s;
- bool err = s.parse_utf16(u16str);
- CHECK(!err);
+ Error err = s.parse_utf16(u16str);
+ CHECK(err == OK);
CHECK(s == u32str);
err = s.parse_utf16(u16str_swap);
- CHECK(!err);
+ CHECK(err == OK);
CHECK(s == u32str);
Char16String cs = u16str;
@@ -151,29 +152,48 @@ TEST_CASE("[String] UTF16 with BOM") {
CHECK(String::utf16(cs) == s);
}
-TEST_CASE("[String] Invalid UTF8") {
+TEST_CASE("[String] Invalid UTF8 (non-standard)") {
ERR_PRINT_OFF
- static const uint8_t u8str[] = { 0x45, 0xE3, 0x81, 0x8A, 0x8F, 0xE3, 0xE3, 0x98, 0x8F, 0xE3, 0x82, 0x88, 0xE3, 0x81, 0x86, 0xF0, 0x9F, 0x8E, 0xA4, 0 };
+ static const uint8_t u8str[] = { 0x45, 0xE3, 0x81, 0x8A, 0xE3, 0x82, 0x88, 0xE3, 0x81, 0x86, 0xF0, 0x9F, 0x8E, 0xA4, 0xF0, 0x82, 0x82, 0xAC, 0xED, 0xA0, 0x81, 0 };
+ // + +2 +2 +2 +3 overlong +3 unpaired +2
+ static const char32_t u32str[] = { 0x45, 0x304A, 0x3088, 0x3046, 0x1F3A4, 0x20AC, 0xD801, 0 };
String s;
- bool err = s.parse_utf8((const char *)u8str);
- CHECK(err);
- CHECK(s.is_empty());
+ Error err = s.parse_utf8((const char *)u8str);
+ CHECK(err == ERR_PARSE_ERROR);
+ CHECK(s == u32str);
CharString cs = (const char *)u8str;
- CHECK(String::utf8(cs).is_empty());
+ CHECK(String::utf8(cs) == s);
ERR_PRINT_ON
}
-TEST_CASE("[String] Invalid UTF16") {
+TEST_CASE("[String] Invalid UTF8 (unrecoverable)") {
+ ERR_PRINT_OFF
+ static const uint8_t u8str[] = { 0x45, 0xE3, 0x81, 0x8A, 0x8F, 0xE3, 0xE3, 0x98, 0x8F, 0xE3, 0x82, 0x88, 0xE3, 0x81, 0x86, 0xC0, 0x80, 0xF0, 0x9F, 0x8E, 0xA4, 0xF0, 0x82, 0x82, 0xAC, 0xED, 0xA0, 0x81, 0 };
+ // + +2 inv +2 inv inv inv +2 +2 ovl NUL +1 +3 overlong +3 unpaired +2
+ static const char32_t u32str[] = { 0x45, 0x304A, 0x20, 0x20, 0x20, 0x20, 0x3088, 0x3046, 0x20, 0x1F3A4, 0x20AC, 0xD801, 0 };
+ String s;
+ Error err = s.parse_utf8((const char *)u8str);
+ CHECK(err == ERR_INVALID_DATA);
+ CHECK(s == u32str);
+
+ CharString cs = (const char *)u8str;
+ CHECK(String::utf8(cs) == s);
+ ERR_PRINT_ON
+}
+
+TEST_CASE("[String] Invalid UTF16 (non-standard)") {
ERR_PRINT_OFF
static const char16_t u16str[] = { 0x0045, 0x304A, 0x3088, 0x3046, 0xDFA4, 0 };
+ // + + + + unpaired
+ static const char32_t u32str[] = { 0x0045, 0x304A, 0x3088, 0x3046, 0xDFA4, 0 };
String s;
- bool err = s.parse_utf16(u16str);
- CHECK(err);
- CHECK(s.is_empty());
+ Error err = s.parse_utf16(u16str);
+ CHECK(err == ERR_PARSE_ERROR);
+ CHECK(s == u32str);
Char16String cs = u16str;
- CHECK(String::utf16(cs).is_empty());
+ CHECK(String::utf16(cs) == s);
ERR_PRINT_ON
}
@@ -244,12 +264,25 @@ TEST_CASE("[String] Testing for empty string") {
CHECK(String("").is_empty());
}
+TEST_CASE("[String] Contains") {
+ String s = "C:\\Godot\\project\\string_test.tscn";
+ CHECK(s.contains(":\\"));
+ CHECK(s.contains("Godot"));
+ CHECK(s.contains(String("project\\string_test")));
+ CHECK(s.contains(String("\\string_test.tscn")));
+
+ CHECK(!s.contains("://"));
+ CHECK(!s.contains("Godoh"));
+ CHECK(!s.contains(String("project\\string test")));
+ CHECK(!s.contains(String("\\char_test.tscn")));
+}
+
TEST_CASE("[String] Test chr") {
CHECK(String::chr('H') == "H");
CHECK(String::chr(0x3012)[0] == 0x3012);
ERR_PRINT_OFF
- CHECK(String::chr(0xd812)[0] == 0xfffd); // Unpaired UTF-16 surrogate
- CHECK(String::chr(0x20d812)[0] == 0xfffd); // Outside UTF-32 range
+ CHECK(String::chr(0xd812)[0] == 0xd812); // Unpaired UTF-16 surrogate
+ CHECK(String::chr(0x20d812)[0] == 0x20d812); // Outside UTF-32 range
ERR_PRINT_ON
}
@@ -355,11 +388,17 @@ TEST_CASE("[String] Number to string") {
CHECK(String::num(42.100023, 4) == "42.1"); // No trailing zeros.
// String::num_real tests.
+ CHECK(String::num_real(1.0) == "1.0");
+ CHECK(String::num_real(1.0, false) == "1");
+ CHECK(String::num_real(9.9) == "9.9");
+ CHECK(String::num_real(9.99) == "9.99");
+ CHECK(String::num_real(9.999) == "9.999");
+ CHECK(String::num_real(9.9999) == "9.9999");
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(Math_PI) == "3.14159265358979", "Prints the appropriate amount of digits for real_t = double.");
- CHECK_MESSAGE(String::num_real(3.1415f) == "3.14149999618530", "Prints more digits of 32-bit float when real_t = double (ones that would be reliable for 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(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.");
@@ -616,6 +655,38 @@ TEST_CASE("[String] sprintf") {
REQUIRE(error == false);
CHECK(output == String("fish -5 frog"));
+ // Negative int left padded with spaces.
+ format = "fish %5d frog";
+ args.clear();
+ args.push_back(-5);
+ output = format.sprintf(args, &error);
+ REQUIRE(error == false);
+ CHECK(output == String("fish -5 frog"));
+
+ // Negative int left padded with zeros.
+ format = "fish %05d frog";
+ args.clear();
+ args.push_back(-5);
+ output = format.sprintf(args, &error);
+ REQUIRE(error == false);
+ CHECK(output == String("fish -0005 frog"));
+
+ // Negative int right padded with spaces.
+ format = "fish %-5d frog";
+ args.clear();
+ args.push_back(-5);
+ output = format.sprintf(args, &error);
+ REQUIRE(error == false);
+ CHECK(output == String("fish -5 frog"));
+
+ // Negative int right padded with zeros. (0 ignored)
+ format = "fish %-05d frog";
+ args.clear();
+ args.push_back(-5);
+ output = format.sprintf(args, &error);
+ REQUIRE(error == false);
+ CHECK(output == String("fish -5 frog"));
+
// Hex (lower)
format = "fish %x frog";
args.clear();
@@ -706,6 +777,14 @@ TEST_CASE("[String] sprintf") {
REQUIRE(error == false);
CHECK(output == String("fish 100 frog"));
+ // Negative real right padded with zeros. (0 ignored)
+ format = "fish %-011f frog";
+ args.clear();
+ args.push_back(-99.99);
+ output = format.sprintf(args, &error);
+ REQUIRE(error == false);
+ CHECK(output == String("fish -99.990000 frog"));
+
/////// Strings.
// String
@@ -871,7 +950,7 @@ TEST_CASE("[String] is_subsequence_of") {
String a = "is subsequence of";
CHECK(String("sub").is_subsequence_of(a));
CHECK(!String("Sub").is_subsequence_of(a));
- CHECK(String("Sub").is_subsequence_ofi(a));
+ CHECK(String("Sub").is_subsequence_ofn(a));
}
TEST_CASE("[String] match") {
@@ -1065,9 +1144,9 @@ TEST_CASE("[String] lstrip and rstrip") {
#undef STRIP_TEST
}
-TEST_CASE("[String] ensuring empty string into parse_utf8 passes empty string") {
+TEST_CASE("[String] Ensuring empty string into parse_utf8 passes empty string") {
String empty;
- CHECK(empty.parse_utf8(nullptr, -1));
+ CHECK(empty.parse_utf8(nullptr, -1) == ERR_INVALID_DATA);
}
TEST_CASE("[String] Cyrillic to_lower()") {
@@ -1132,6 +1211,25 @@ TEST_CASE("[String] c-escape/unescape") {
CHECK(s.c_escape().c_unescape() == s);
}
+TEST_CASE("[String] indent") {
+ static const char *input[] = {
+ "",
+ "aaa\nbbb",
+ "\tcontains\n\tindent",
+ "empty\n\nline",
+ };
+ static const char *expected[] = {
+ "",
+ "\taaa\n\tbbb",
+ "\t\tcontains\n\t\tindent",
+ "\tempty\n\n\tline",
+ };
+
+ for (int i = 0; i < 3; i++) {
+ CHECK(String(input[i]).indent("\t") == expected[i]);
+ }
+}
+
TEST_CASE("[String] dedent") {
String s = " aaa\n bbb";
String t = "aaa\nbbb";
@@ -1361,13 +1459,27 @@ TEST_CASE("[String] validate_node_name") {
String name_with_spaces = "Name with spaces";
CHECK(name_with_spaces.validate_node_name() == "Name with spaces");
- String name_with_kana = "Name with kana ゴドツ";
- CHECK(name_with_kana.validate_node_name() == "Name with kana ゴドツ");
+ String name_with_kana = U"Name with kana ゴドツ";
+ CHECK(name_with_kana.validate_node_name() == U"Name with kana ゴドツ");
String name_with_invalid_chars = "Name with invalid characters :.@removed!";
CHECK(name_with_invalid_chars.validate_node_name() == "Name with invalid characters removed!");
}
+TEST_CASE("[String] validate_identifier") {
+ String empty_string;
+ CHECK(empty_string.validate_identifier() == "_");
+
+ String numeric_only = "12345";
+ CHECK(numeric_only.validate_identifier() == "_2345");
+
+ String name_with_spaces = "Name with spaces";
+ CHECK(name_with_spaces.validate_identifier() == "Name_with_spaces");
+
+ String name_with_invalid_chars = String::utf8("Invalid characters:@*#&世界");
+ CHECK(name_with_invalid_chars.validate_identifier() == "Invalid_characters_______");
+}
+
TEST_CASE("[String] Variant indexed get") {
Variant s = String("abcd");
bool valid = false;
diff --git a/tests/core/string/test_translation.h b/tests/core/string/test_translation.h
index 47e06add40..0a1903ccbf 100644
--- a/tests/core/string/test_translation.h
+++ b/tests/core/string/test_translation.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -154,7 +154,7 @@ TEST_CASE("[OptimizedTranslation] Generate from Translation and read messages")
TEST_CASE("[Translation] CSV import") {
Ref<ResourceImporterCSVTranslation> import_csv_translation = memnew(ResourceImporterCSVTranslation);
- Map<StringName, Variant> options;
+ HashMap<StringName, Variant> options;
options["compress"] = false;
options["delimiter"] = 0;
diff --git a/tests/core/templates/test_command_queue.h b/tests/core/templates/test_command_queue.h
index 5d228f2bf6..0d016f5d06 100644
--- a/tests/core/templates/test_command_queue.h
+++ b/tests/core/templates/test_command_queue.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/core/templates/test_ordered_hash_map.h b/tests/core/templates/test_hash_map.h
index 35ce0fc656..7a3d5f5d47 100644
--- a/tests/core/templates/test_ordered_hash_map.h
+++ b/tests/core/templates/test_hash_map.h
@@ -1,12 +1,12 @@
/*************************************************************************/
-/* test_ordered_hash_map.h */
+/* test_hash_map.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -28,56 +28,53 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef TEST_ORDERED_HASH_MAP_H
-#define TEST_ORDERED_HASH_MAP_H
+#ifndef TEST_HASH_MAP_H
+#define TEST_HASH_MAP_H
-#include "core/templates/ordered_hash_map.h"
+#include "core/templates/hash_map.h"
#include "tests/test_macros.h"
-namespace TestOrderedHashMap {
+namespace TestHashMap {
-TEST_CASE("[OrderedHashMap] Insert element") {
- OrderedHashMap<int, int> map;
- OrderedHashMap<int, int>::Element e = map.insert(42, 84);
+TEST_CASE("[HashMap] Insert element") {
+ HashMap<int, int> map;
+ HashMap<int, int>::Iterator e = map.insert(42, 84);
CHECK(e);
- CHECK(e.key() == 42);
- CHECK(e.get() == 84);
- CHECK(e.value() == 84);
+ CHECK(e->key == 42);
+ CHECK(e->value == 84);
CHECK(map[42] == 84);
CHECK(map.has(42));
CHECK(map.find(42));
}
-TEST_CASE("[OrderedHashMap] Overwrite element") {
- OrderedHashMap<int, int> map;
+TEST_CASE("[HashMap] Overwrite element") {
+ HashMap<int, int> map;
map.insert(42, 84);
map.insert(42, 1234);
CHECK(map[42] == 1234);
}
-TEST_CASE("[OrderedHashMap] Erase via element") {
- OrderedHashMap<int, int> map;
- OrderedHashMap<int, int>::Element e = map.insert(42, 84);
-
- map.erase(e);
- CHECK(!e);
+TEST_CASE("[HashMap] Erase via element") {
+ HashMap<int, int> map;
+ HashMap<int, int>::Iterator e = map.insert(42, 84);
+ map.remove(e);
CHECK(!map.has(42));
CHECK(!map.find(42));
}
-TEST_CASE("[OrderedHashMap] Erase via key") {
- OrderedHashMap<int, int> map;
+TEST_CASE("[HashMap] Erase via key") {
+ HashMap<int, int> map;
map.insert(42, 84);
map.erase(42);
CHECK(!map.has(42));
CHECK(!map.find(42));
}
-TEST_CASE("[OrderedHashMap] Size") {
- OrderedHashMap<int, int> map;
+TEST_CASE("[HashMap] Size") {
+ HashMap<int, int> map;
map.insert(42, 84);
map.insert(123, 84);
map.insert(123, 84);
@@ -87,8 +84,8 @@ TEST_CASE("[OrderedHashMap] Size") {
CHECK(map.size() == 4);
}
-TEST_CASE("[OrderedHashMap] Iteration") {
- OrderedHashMap<int, int> map;
+TEST_CASE("[HashMap] Iteration") {
+ HashMap<int, int> map;
map.insert(42, 84);
map.insert(123, 12385);
map.insert(0, 12934);
@@ -102,34 +99,35 @@ TEST_CASE("[OrderedHashMap] Iteration") {
expected.push_back(Pair<int, int>(123485, 1238888));
int idx = 0;
- for (OrderedHashMap<int, int>::Element E = map.front(); E; E = E.next()) {
- CHECK(expected[idx] == Pair<int, int>(E.key(), E.value()));
+ for (const KeyValue<int, int> &E : map) {
+ CHECK(expected[idx] == Pair<int, int>(E.key, E.value));
++idx;
}
}
-TEST_CASE("[OrderedHashMap] Const iteration") {
- OrderedHashMap<int, int> map;
+TEST_CASE("[HashMap] Const iteration") {
+ HashMap<int, int> map;
map.insert(42, 84);
map.insert(123, 12385);
map.insert(0, 12934);
map.insert(123485, 1238888);
map.insert(123, 111111);
- const OrderedHashMap<int, int> const_map = map;
+ const HashMap<int, int> const_map = map;
Vector<Pair<int, int>> expected;
expected.push_back(Pair<int, int>(42, 84));
expected.push_back(Pair<int, int>(123, 111111));
expected.push_back(Pair<int, int>(0, 12934));
expected.push_back(Pair<int, int>(123485, 1238888));
+ expected.push_back(Pair<int, int>(123, 111111));
int idx = 0;
- for (OrderedHashMap<int, int>::ConstElement E = const_map.front(); E; E = E.next()) {
- CHECK(expected[idx] == Pair<int, int>(E.key(), E.value()));
+ for (const KeyValue<int, int> &E : const_map) {
+ CHECK(expected[idx] == Pair<int, int>(E.key, E.value));
++idx;
}
}
-} // namespace TestOrderedHashMap
+} // namespace TestHashMap
-#endif // TEST_ORDERED_HASH_MAP_H
+#endif // TEST_HASH_MAP_H
diff --git a/tests/core/templates/test_hash_set.h b/tests/core/templates/test_hash_set.h
new file mode 100644
index 0000000000..3b9a800641
--- /dev/null
+++ b/tests/core/templates/test_hash_set.h
@@ -0,0 +1,228 @@
+/*************************************************************************/
+/* test_hash_set.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_HASH_SET_H
+#define TEST_HASH_SET_H
+
+#include "core/templates/hash_set.h"
+
+#include "tests/test_macros.h"
+
+namespace TestHashSet {
+
+TEST_CASE("[HashSet] Insert element") {
+ print_line("SMALL BEGIN MEM: ", Memory::get_mem_usage());
+ HashSet<int> set;
+ HashSet<int>::Iterator e = set.insert(42);
+
+ CHECK(e);
+ CHECK(*e == 42);
+ CHECK(set.has(42));
+ CHECK(set.find(42));
+ set.reset();
+ print_line("SMALL END MEM: ", Memory::get_mem_usage());
+}
+
+TEST_CASE("[HashSet] Insert existing element") {
+ HashSet<int> set;
+ set.insert(42);
+ set.insert(42);
+
+ CHECK(set.has(42));
+ CHECK(set.size() == 1);
+}
+
+TEST_CASE("[HashSet] Insert, iterate and remove many elements") {
+ const int elem_max = 12343;
+ HashSet<int> set;
+ for (int i = 0; i < elem_max; i++) {
+ set.insert(i);
+ }
+
+ //insert order should have been kept
+ int idx = 0;
+ for (const int &K : set) {
+ CHECK(idx == K);
+ CHECK(set.has(idx));
+ idx++;
+ }
+
+ Vector<int> elems_still_valid;
+
+ for (int i = 0; i < elem_max; i++) {
+ if ((i % 5) == 0) {
+ set.erase(i);
+ } else {
+ elems_still_valid.push_back(i);
+ }
+ }
+
+ CHECK(elems_still_valid.size() == set.size());
+
+ for (int i = 0; i < elems_still_valid.size(); i++) {
+ CHECK(set.has(elems_still_valid[i]));
+ }
+}
+
+TEST_CASE("[HashSet] Insert, iterate and remove many strings") {
+ // This tests a key that uses allocation, to see if any leaks occur
+
+ uint64_t pre_mem = Memory::get_mem_usage();
+ const int elem_max = 4018;
+ HashSet<String> set;
+ for (int i = 0; i < elem_max; i++) {
+ set.insert(itos(i));
+ }
+
+ //insert order should have been kept
+ int idx = 0;
+ for (const String &K : set) {
+ CHECK(itos(idx) == K);
+ CHECK(set.has(itos(idx)));
+ idx++;
+ }
+
+ Vector<String> elems_still_valid;
+
+ for (int i = 0; i < elem_max; i++) {
+ if ((i % 5) == 0) {
+ set.erase(itos(i));
+ } else {
+ elems_still_valid.push_back(itos(i));
+ }
+ }
+
+ CHECK(elems_still_valid.size() == set.size());
+
+ for (int i = 0; i < elems_still_valid.size(); i++) {
+ CHECK(set.has(elems_still_valid[i]));
+ }
+
+ elems_still_valid.clear();
+ set.reset();
+
+ CHECK(Memory::get_mem_usage() == pre_mem);
+}
+
+TEST_CASE("[HashSet] Erase via element") {
+ HashSet<int> set;
+ HashSet<int>::Iterator e = set.insert(42);
+ set.remove(e);
+ CHECK(!set.has(42));
+ CHECK(!set.find(42));
+}
+
+TEST_CASE("[HashSet] Erase via key") {
+ HashSet<int> set;
+ set.insert(42);
+ set.insert(49);
+ set.erase(42);
+ CHECK(!set.has(42));
+ CHECK(!set.find(42));
+}
+
+TEST_CASE("[HashSet] Insert and erase half elements") {
+ HashSet<int> set;
+ set.insert(1);
+ set.insert(2);
+ set.insert(3);
+ set.insert(4);
+ set.erase(1);
+ set.erase(3);
+
+ CHECK(set.size() == 2);
+ CHECK(set.has(2));
+ CHECK(set.has(4));
+}
+
+TEST_CASE("[HashSet] Size") {
+ HashSet<int> set;
+ set.insert(42);
+ set.insert(123);
+ set.insert(123);
+ set.insert(0);
+ set.insert(123485);
+
+ CHECK(set.size() == 4);
+}
+
+TEST_CASE("[HashSet] Iteration") {
+ HashSet<int> set;
+ set.insert(42);
+ set.insert(123);
+ set.insert(0);
+ set.insert(123485);
+
+ Vector<int> expected;
+ expected.push_back(42);
+ expected.push_back(123);
+ expected.push_back(0);
+ expected.push_back(123485);
+
+ int idx = 0;
+ for (const int &E : set) {
+ CHECK(expected[idx] == E);
+ ++idx;
+ }
+}
+
+TEST_CASE("[HashSet] Copy") {
+ HashSet<int> set;
+ set.insert(42);
+ set.insert(123);
+ set.insert(0);
+ set.insert(123485);
+
+ Vector<int> expected;
+ expected.push_back(42);
+ expected.push_back(123);
+ expected.push_back(0);
+ expected.push_back(123485);
+
+ HashSet<int> copy_assign = set;
+
+ int idx = 0;
+ for (const int &E : copy_assign) {
+ CHECK(expected[idx] == E);
+ ++idx;
+ }
+
+ HashSet<int> copy_construct(set);
+
+ idx = 0;
+ for (const int &E : copy_construct) {
+ CHECK(expected[idx] == E);
+ ++idx;
+ }
+}
+
+} // namespace TestHashSet
+
+#endif // TEST_HASH_SET_H
diff --git a/tests/core/templates/test_list.h b/tests/core/templates/test_list.h
index 52d5edff70..49da0b8aad 100644
--- a/tests/core/templates/test_list.h
+++ b/tests/core/templates/test_list.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/core/templates/test_local_vector.h b/tests/core/templates/test_local_vector.h
index 67bcf515f9..b2464c3914 100644
--- a/tests/core/templates/test_local_vector.h
+++ b/tests/core/templates/test_local_vector.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -37,6 +37,17 @@
namespace TestLocalVector {
+TEST_CASE("[LocalVector] List Initialization.") {
+ LocalVector<int> vector{ 0, 1, 2, 3, 4 };
+
+ CHECK(vector.size() == 5);
+ CHECK(vector[0] == 0);
+ CHECK(vector[1] == 1);
+ CHECK(vector[2] == 2);
+ CHECK(vector[3] == 3);
+ CHECK(vector[4] == 4);
+}
+
TEST_CASE("[LocalVector] Push Back.") {
LocalVector<int> vector;
vector.push_back(0);
diff --git a/tests/core/templates/test_lru.h b/tests/core/templates/test_lru.h
index 9359909c53..354f53e164 100644
--- a/tests/core/templates/test_lru.h
+++ b/tests/core/templates/test_lru.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/core/templates/test_oa_hash_map.cpp b/tests/core/templates/test_oa_hash_map.cpp
deleted file mode 100644
index f7b2b7cdb0..0000000000
--- a/tests/core/templates/test_oa_hash_map.cpp
+++ /dev/null
@@ -1,301 +0,0 @@
-/*************************************************************************/
-/* test_oa_hash_map.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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. */
-/*************************************************************************/
-
-#include "test_oa_hash_map.h"
-
-#include "core/os/os.h"
-#include "core/templates/oa_hash_map.h"
-
-namespace TestOAHashMap {
-
-struct CountedItem {
- static int count;
-
- int id = -1;
- bool destroyed = false;
-
- CountedItem() {
- count++;
- }
-
- CountedItem(int p_id) :
- id(p_id) {
- count++;
- }
-
- CountedItem(const CountedItem &p_other) :
- id(p_other.id) {
- count++;
- }
-
- void operator=(const CountedItem &p_other) {
- id = p_other.id;
- count++;
- }
-
- ~CountedItem() {
- CRASH_COND(destroyed);
- count--;
- destroyed = true;
- }
-};
-
-int CountedItem::count;
-
-MainLoop *test() {
- OS::get_singleton()->print("\n\n\nHello from test\n");
-
- // test element tracking.
- {
- OAHashMap<int, int> map;
-
- map.set(42, 1337);
- map.set(1337, 21);
- map.set(42, 11880);
-
- int value = 0;
- map.lookup(42, value);
-
- OS::get_singleton()->print("capacity %d\n", map.get_capacity());
- OS::get_singleton()->print("elements %d\n", map.get_num_elements());
-
- OS::get_singleton()->print("map[42] = %d\n", value);
- }
-
- // rehashing and deletion
- {
- OAHashMap<int, int> map;
-
- for (int i = 0; i < 500; i++) {
- map.set(i, i * 2);
- }
-
- for (int i = 0; i < 500; i += 2) {
- map.remove(i);
- }
-
- uint32_t num_elems = 0;
- for (int i = 0; i < 500; i++) {
- int tmp;
- if (map.lookup(i, tmp) && tmp == i * 2) {
- num_elems++;
- }
- }
-
- OS::get_singleton()->print("elements %d == %d.\n", map.get_num_elements(), num_elems);
- }
-
- // iteration
- {
- OAHashMap<String, int> map;
-
- map.set("Hello", 1);
- map.set("World", 2);
- map.set("Godot rocks", 42);
-
- for (OAHashMap<String, int>::Iterator it = map.iter(); it.valid; it = map.next_iter(it)) {
- OS::get_singleton()->print("map[\"%s\"] = %d\n", it.key->utf8().get_data(), *it.value);
- }
- }
-
- // stress test / test for issue #22928
- {
- OAHashMap<int, int> map;
- int dummy = 0;
- const int N = 1000;
- uint32_t *keys = new uint32_t[N];
-
- Math::seed(0);
-
- // insert a couple of random keys (with a dummy value, which is ignored)
- for (int i = 0; i < N; i++) {
- keys[i] = Math::rand();
- map.set(keys[i], dummy);
-
- if (!map.lookup(keys[i], dummy)) {
- OS::get_singleton()->print("could not find 0x%X despite it was just inserted!\n", unsigned(keys[i]));
- }
- }
-
- // check whether the keys are still present
- for (int i = 0; i < N; i++) {
- if (!map.lookup(keys[i], dummy)) {
- OS::get_singleton()->print("could not find 0x%X despite it has been inserted previously! (not checking the other keys, breaking...)\n", unsigned(keys[i]));
- break;
- }
- }
-
- delete[] keys;
- }
-
- // regression test / test for issue related to #31402
- {
- OS::get_singleton()->print("test for issue #31402 started...\n");
-
- const int num_test_values = 12;
- int test_values[num_test_values] = { 0, 24, 48, 72, 96, 120, 144, 168, 192, 216, 240, 264 };
-
- int dummy = 0;
- OAHashMap<int, int> map;
- map.clear();
-
- for (int i = 0; i < num_test_values; ++i) {
- map.set(test_values[i], dummy);
- }
-
- OS::get_singleton()->print("test for issue #31402 passed.\n");
- }
-
- // test collision resolution, should not crash or run indefinitely
- {
- OAHashMap<int, int> map(4);
- map.set(1, 1);
- map.set(5, 1);
- map.set(9, 1);
- map.set(13, 1);
- map.remove(5);
- map.remove(9);
- map.remove(13);
- map.set(5, 1);
- }
-
- // test memory management of items, should not crash or leak items
- {
- // Exercise different patterns of removal
- for (int i = 0; i < 4; ++i) {
- {
- OAHashMap<String, CountedItem> map;
- int id = 0;
- for (int j = 0; j < 100; ++j) {
- map.insert(itos(j), CountedItem(id));
- }
- if (i <= 1) {
- for (int j = 0; j < 100; ++j) {
- map.remove(itos(j));
- }
- }
- if (i % 2 == 0) {
- map.clear();
- }
- }
-
- if (CountedItem::count != 0) {
- OS::get_singleton()->print("%d != 0 (not performing the other test sub-cases, breaking...)\n", CountedItem::count);
- break;
- }
- }
- }
-
- // Test map with 0 capacity.
- {
- OAHashMap<int, String> original_map(0);
- original_map.set(1, "1");
- OS::get_singleton()->print("OAHashMap 0 capacity initialization passed.\n");
- }
-
- // Test copy constructor.
- {
- OAHashMap<int, String> original_map;
- original_map.set(1, "1");
- original_map.set(2, "2");
- original_map.set(3, "3");
- original_map.set(4, "4");
- original_map.set(5, "5");
-
- OAHashMap<int, String> map_copy(original_map);
-
- bool pass = true;
- for (
- OAHashMap<int, String>::Iterator it = original_map.iter();
- it.valid;
- it = original_map.next_iter(it)) {
- if (map_copy.lookup_ptr(*it.key) == nullptr) {
- pass = false;
- }
- if (*it.value != *map_copy.lookup_ptr(*it.key)) {
- pass = false;
- }
- }
- if (pass) {
- OS::get_singleton()->print("OAHashMap copy constructor test passed.\n");
- } else {
- OS::get_singleton()->print("OAHashMap copy constructor test FAILED.\n");
- }
-
- map_copy.set(1, "Random String");
- if (*map_copy.lookup_ptr(1) == *original_map.lookup_ptr(1)) {
- OS::get_singleton()->print("OAHashMap copy constructor, atomic copy test FAILED.\n");
- } else {
- OS::get_singleton()->print("OAHashMap copy constructor, atomic copy test passed.\n");
- }
- }
-
- // Test assign operator.
- {
- OAHashMap<int, String> original_map;
- original_map.set(1, "1");
- original_map.set(2, "2");
- original_map.set(3, "3");
- original_map.set(4, "4");
- original_map.set(5, "5");
-
- OAHashMap<int, String> map_copy(100000);
- map_copy.set(1, "Just a string.");
- map_copy = original_map;
-
- bool pass = true;
- for (
- OAHashMap<int, String>::Iterator it = map_copy.iter();
- it.valid;
- it = map_copy.next_iter(it)) {
- if (original_map.lookup_ptr(*it.key) == nullptr) {
- pass = false;
- }
- if (*it.value != *original_map.lookup_ptr(*it.key)) {
- pass = false;
- }
- }
- if (pass) {
- OS::get_singleton()->print("OAHashMap assign operation test passed.\n");
- } else {
- OS::get_singleton()->print("OAHashMap assign operation test FAILED.\n");
- }
-
- map_copy.set(1, "Random String");
- if (*map_copy.lookup_ptr(1) == *original_map.lookup_ptr(1)) {
- OS::get_singleton()->print("OAHashMap assign operation atomic copy test FAILED.\n");
- } else {
- OS::get_singleton()->print("OAHashMap assign operation atomic copy test passed.\n");
- }
- }
-
- return nullptr;
-}
-} // namespace TestOAHashMap
diff --git a/tests/core/templates/test_oa_hash_map.h b/tests/core/templates/test_oa_hash_map.h
deleted file mode 100644
index f229ac94ea..0000000000
--- a/tests/core/templates/test_oa_hash_map.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*************************************************************************/
-/* test_oa_hash_map.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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_OA_HASH_MAP_H
-#define TEST_OA_HASH_MAP_H
-
-class MainLoop;
-
-namespace TestOAHashMap {
-
-MainLoop *test();
-}
-
-#endif // TEST_OA_HASH_MAP_H
diff --git a/tests/core/templates/test_paged_array.h b/tests/core/templates/test_paged_array.h
index 7efd3799f3..86cf3a2dfc 100644
--- a/tests/core/templates/test_paged_array.h
+++ b/tests/core/templates/test_paged_array.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/core/templates/test_vector.h b/tests/core/templates/test_vector.h
index 6ea865dacc..f27d6a332e 100644
--- a/tests/core/templates/test_vector.h
+++ b/tests/core/templates/test_vector.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -37,6 +37,17 @@
namespace TestVector {
+TEST_CASE("[Vector] List initialization") {
+ Vector<int> vector{ 0, 1, 2, 3, 4 };
+
+ CHECK(vector.size() == 5);
+ CHECK(vector[0] == 0);
+ CHECK(vector[1] == 1);
+ CHECK(vector[2] == 2);
+ CHECK(vector[3] == 3);
+ CHECK(vector[4] == 4);
+}
+
TEST_CASE("[Vector] Push back and append") {
Vector<int> vector;
vector.push_back(0);
@@ -246,27 +257,42 @@ TEST_CASE("[Vector] Slice") {
vector.push_back(3);
vector.push_back(4);
+ Vector<int> slice0 = vector.slice(0, 0);
+ CHECK(slice0.size() == 0);
+
Vector<int> slice1 = vector.slice(1, 3);
CHECK(slice1.size() == 2);
CHECK(slice1[0] == 1);
CHECK(slice1[1] == 2);
Vector<int> slice2 = vector.slice(1, -1);
- CHECK(slice2.size() == 4);
+ CHECK(slice2.size() == 3);
CHECK(slice2[0] == 1);
CHECK(slice2[1] == 2);
CHECK(slice2[2] == 3);
- CHECK(slice2[3] == 4);
- Vector<int> slice3 = vector.slice(3, -1);
+ Vector<int> slice3 = vector.slice(3);
CHECK(slice3.size() == 2);
CHECK(slice3[0] == 3);
CHECK(slice3[1] == 4);
Vector<int> slice4 = vector.slice(2, -2);
- CHECK(slice4.size() == 2);
+ CHECK(slice4.size() == 1);
CHECK(slice4[0] == 2);
- CHECK(slice4[1] == 3);
+
+ Vector<int> slice5 = vector.slice(-2);
+ CHECK(slice5.size() == 2);
+ CHECK(slice5[0] == 3);
+ CHECK(slice5[1] == 4);
+
+ Vector<int> slice6 = vector.slice(2, 42);
+ CHECK(slice6.size() == 3);
+ CHECK(slice6[0] == 2);
+ CHECK(slice6[1] == 3);
+ CHECK(slice6[2] == 4);
+
+ Vector<int> slice7 = vector.slice(5, 1);
+ CHECK(slice7.size() == 0);
}
TEST_CASE("[Vector] Find, has") {
diff --git a/tests/core/test_crypto.h b/tests/core/test_crypto.h
index 3b909c7df8..ce4edc71ae 100644
--- a/tests/core/test_crypto.h
+++ b/tests/core/test_crypto.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/core/test_hashing_context.h b/tests/core/test_hashing_context.h
index 728a5f2cfa..4795d24103 100644
--- a/tests/core/test_hashing_context.h
+++ b/tests/core/test_hashing_context.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/core/test_time.h b/tests/core/test_time.h
index 28f1cb2f20..177512c832 100644
--- a/tests/core/test_time.h
+++ b/tests/core/test_time.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -79,6 +79,9 @@ TEST_CASE("[Time] Unix time conversion to/from datetime string") {
CHECK_MESSAGE(time->get_date_string_from_unix_time(1391904000) == "2014-02-09", "Time get_date_string_from_unix_time: The date for GODOT IS OPEN SOURCE without time is as expected.");
CHECK_MESSAGE(time->get_time_string_from_unix_time(79830) == "22:10:30", "Time get_time_string_from_unix_time: The time for GODOT IS OPEN SOURCE without date is as expected.");
CHECK_MESSAGE(time->get_datetime_string_from_unix_time(31494784780800) == "1000000-01-01T00:00:00", "Time get_datetime_string_from_unix_time: The timestamp for the year a million is as expected.");
+ CHECK_MESSAGE(time->get_offset_string_from_offset_minutes(0) == "+00:00", "Time get_offset_string_from_offset_minutes: The offset string is as expected.");
+ CHECK_MESSAGE(time->get_offset_string_from_offset_minutes(-600) == "-10:00", "Time get_offset_string_from_offset_minutes: The offset string is as expected.");
+ CHECK_MESSAGE(time->get_offset_string_from_offset_minutes(345) == "+05:45", "Time get_offset_string_from_offset_minutes: The offset string is as expected.");
}
TEST_CASE("[Time] Datetime dictionary conversion methods") {
@@ -115,11 +118,11 @@ TEST_CASE("[Time] Datetime dictionary conversion methods") {
CHECK_MESSAGE((Time::Weekday)(int)time->get_datetime_dict_from_unix_time(0)[WEEKDAY_KEY] == Time::Weekday::WEEKDAY_THURSDAY, "Time get_datetime_dict_from_unix_time: The weekday for the Unix epoch is a Thursday as expected.");
CHECK_MESSAGE((Time::Weekday)(int)time->get_datetime_dict_from_unix_time(1391983830)[WEEKDAY_KEY] == Time::Weekday::WEEKDAY_SUNDAY, "Time get_datetime_dict_from_unix_time: The weekday for GODOT IS OPEN SOURCE is a Sunday as expected.");
- CHECK_MESSAGE(time->get_datetime_dict_from_string("2014-02-09T22:10:30").hash() == datetime.hash(), "Time get_datetime_dict_from_string: The dictionary from string for GODOT IS OPEN SOURCE works as expected.");
- CHECK_MESSAGE(!time->get_datetime_dict_from_string("2014-02-09T22:10:30", false).has(WEEKDAY_KEY), "Time get_datetime_dict_from_string: The dictionary from string for GODOT IS OPEN SOURCE without weekday doesn't contain the weekday key as expected.");
- CHECK_MESSAGE(time->get_datetime_string_from_dict(datetime) == "2014-02-09T22:10:30", "Time get_datetime_string_from_dict: The string from dictionary for GODOT IS OPEN SOURCE works as expected.");
- CHECK_MESSAGE(time->get_datetime_string_from_dict(time->get_datetime_dict_from_string("2014-02-09T22:10:30")) == "2014-02-09T22:10:30", "Time get_datetime_string_from_dict: The round-trip string to dict to string GODOT IS OPEN SOURCE works as expected.");
- CHECK_MESSAGE(time->get_datetime_string_from_dict(time->get_datetime_dict_from_string("2014-02-09 22:10:30"), true) == "2014-02-09 22:10:30", "Time get_datetime_string_from_dict: The round-trip string to dict to string GODOT IS OPEN SOURCE with spaces works as expected.");
+ CHECK_MESSAGE(time->get_datetime_dict_from_datetime_string("2014-02-09T22:10:30").hash() == datetime.hash(), "Time get_datetime_dict_from_string: The dictionary from string for GODOT IS OPEN SOURCE works as expected.");
+ CHECK_MESSAGE(!time->get_datetime_dict_from_datetime_string("2014-02-09T22:10:30", false).has(WEEKDAY_KEY), "Time get_datetime_dict_from_string: The dictionary from string for GODOT IS OPEN SOURCE without weekday doesn't contain the weekday key as expected.");
+ CHECK_MESSAGE(time->get_datetime_string_from_datetime_dict(datetime) == "2014-02-09T22:10:30", "Time get_datetime_string_from_dict: The string from dictionary for GODOT IS OPEN SOURCE works as expected.");
+ CHECK_MESSAGE(time->get_datetime_string_from_datetime_dict(time->get_datetime_dict_from_datetime_string("2014-02-09T22:10:30")) == "2014-02-09T22:10:30", "Time get_datetime_string_from_dict: The round-trip string to dict to string GODOT IS OPEN SOURCE works as expected.");
+ CHECK_MESSAGE(time->get_datetime_string_from_datetime_dict(time->get_datetime_dict_from_datetime_string("2014-02-09 22:10:30"), true) == "2014-02-09 22:10:30", "Time get_datetime_string_from_dict: The round-trip string to dict to string GODOT IS OPEN SOURCE with spaces works as expected.");
}
TEST_CASE("[Time] System time methods") {
diff --git a/tests/core/threads/test_worker_thread_pool.h b/tests/core/threads/test_worker_thread_pool.h
new file mode 100644
index 0000000000..641b293c8a
--- /dev/null
+++ b/tests/core/threads/test_worker_thread_pool.h
@@ -0,0 +1,158 @@
+/*************************************************************************/
+/* test_worker_thread_pool.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_WORKER_THREAD_POOL_H
+#define TEST_WORKER_THREAD_POOL_H
+
+#include "core/object/worker_thread_pool.h"
+
+#include "tests/test_macros.h"
+
+namespace TestWorkerThreadPool {
+
+int u32scmp(const char32_t *l, const char32_t *r) {
+ for (; *l == *r && *l && *r; l++, r++) {
+ // Continue.
+ }
+ return *l - *r;
+}
+
+static void static_test(void *p_arg) {
+ SafeNumeric<uint32_t> *counter = (SafeNumeric<uint32_t> *)p_arg;
+ counter->increment();
+}
+
+static SafeNumeric<uint32_t> callable_counter;
+
+static void static_callable_test() {
+ callable_counter.increment();
+}
+
+TEST_CASE("[WorkerThreadPool] Process 256 threads using native task") {
+ const int count = 256;
+ SafeNumeric<uint32_t> counter;
+ WorkerThreadPool::TaskID tasks[count];
+ for (int i = 0; i < count; i++) {
+ tasks[i] = WorkerThreadPool::get_singleton()->add_native_task(static_test, &counter, true);
+ }
+ for (int i = 0; i < count; i++) {
+ WorkerThreadPool::get_singleton()->wait_for_task_completion(tasks[i]);
+ }
+
+ CHECK(counter.get() == count);
+}
+
+TEST_CASE("[WorkerThreadPool] Process 256 threads using native low priority") {
+ const int count = 256;
+ SafeNumeric<uint32_t> counter = SafeNumeric<uint32_t>(0);
+ WorkerThreadPool::TaskID tasks[count];
+ for (int i = 0; i < count; i++) {
+ tasks[i] = WorkerThreadPool::get_singleton()->add_native_task(static_test, &counter, false);
+ }
+ for (int i = 0; i < count; i++) {
+ WorkerThreadPool::get_singleton()->wait_for_task_completion(tasks[i]);
+ }
+
+ CHECK(counter.get() == count);
+}
+
+TEST_CASE("[WorkerThreadPool] Process 256 threads using callable") {
+ const int count = 256;
+ WorkerThreadPool::TaskID tasks[count];
+ callable_counter.set(0);
+ for (int i = 0; i < count; i++) {
+ tasks[i] = WorkerThreadPool::get_singleton()->add_task(callable_mp_static(static_callable_test), true);
+ }
+ for (int i = 0; i < count; i++) {
+ WorkerThreadPool::get_singleton()->wait_for_task_completion(tasks[i]);
+ }
+
+ CHECK(callable_counter.get() == count);
+}
+
+TEST_CASE("[WorkerThreadPool] Process 256 threads using callable low priority") {
+ const int count = 256;
+ WorkerThreadPool::TaskID tasks[count];
+ callable_counter.set(0);
+ for (int i = 0; i < count; i++) {
+ tasks[i] = WorkerThreadPool::get_singleton()->add_task(callable_mp_static(static_callable_test), false);
+ }
+ for (int i = 0; i < count; i++) {
+ WorkerThreadPool::get_singleton()->wait_for_task_completion(tasks[i]);
+ }
+
+ CHECK(callable_counter.get() == count);
+}
+
+static void static_group_test(void *p_arg, uint32_t p_index) {
+ SafeNumeric<uint32_t> *counter = (SafeNumeric<uint32_t> *)p_arg;
+ counter->exchange_if_greater(p_index);
+}
+
+TEST_CASE("[WorkerThreadPool] Process 256 elements on native task group") {
+ const int count = 256;
+ SafeNumeric<uint32_t> counter;
+ WorkerThreadPool::GroupID group = WorkerThreadPool::get_singleton()->add_native_group_task(static_group_test, &counter, count, -1, true);
+ WorkerThreadPool::get_singleton()->wait_for_group_task_completion(group);
+ CHECK(counter.get() == count - 1);
+}
+
+TEST_CASE("[WorkerThreadPool] Process 256 elements on native task group low priority") {
+ const int count = 256;
+ SafeNumeric<uint32_t> counter;
+ WorkerThreadPool::GroupID group = WorkerThreadPool::get_singleton()->add_native_group_task(static_group_test, &counter, count, -1, false);
+ WorkerThreadPool::get_singleton()->wait_for_group_task_completion(group);
+ CHECK(counter.get() == count - 1);
+}
+
+static SafeNumeric<uint32_t> callable_group_counter;
+
+static void static_callable_group_test(uint32_t p_index) {
+ callable_group_counter.exchange_if_greater(p_index);
+}
+
+TEST_CASE("[WorkerThreadPool] Process 256 elements on native task group") {
+ const int count = 256;
+ WorkerThreadPool::GroupID group = WorkerThreadPool::get_singleton()->add_group_task(callable_mp_static(static_callable_group_test), count, -1, true);
+ WorkerThreadPool::get_singleton()->wait_for_group_task_completion(group);
+ CHECK(callable_group_counter.get() == count - 1);
+}
+
+TEST_CASE("[WorkerThreadPool] Process 256 elements on native task group low priority") {
+ const int count = 256;
+ callable_group_counter.set(0);
+ WorkerThreadPool::GroupID group = WorkerThreadPool::get_singleton()->add_group_task(callable_mp_static(static_callable_group_test), count, -1, false);
+ WorkerThreadPool::get_singleton()->wait_for_group_task_completion(group);
+ CHECK(callable_group_counter.get() == count - 1);
+}
+
+} // namespace TestWorkerThreadPool
+
+#endif // TEST_WORKER_THREAD_POOL_H
diff --git a/tests/core/variant/test_array.h b/tests/core/variant/test_array.h
index d02b3d0e39..6093048307 100644
--- a/tests/core/variant/test_array.h
+++ b/tests/core/variant/test_array.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -254,27 +254,52 @@ TEST_CASE("[Array] slice()") {
array.push_back(3);
array.push_back(4);
+ Array slice0 = array.slice(0, 0);
+ CHECK(slice0.size() == 0);
+
Array slice1 = array.slice(1, 3);
CHECK(slice1.size() == 2);
CHECK(slice1[0] == Variant(1));
CHECK(slice1[1] == Variant(2));
Array slice2 = array.slice(1, -1);
- CHECK(slice2.size() == 4);
+ CHECK(slice2.size() == 3);
CHECK(slice2[0] == Variant(1));
CHECK(slice2[1] == Variant(2));
CHECK(slice2[2] == Variant(3));
- CHECK(slice2[3] == Variant(4));
- Array slice3 = array.slice(3, -1);
+ Array slice3 = array.slice(3);
CHECK(slice3.size() == 2);
CHECK(slice3[0] == Variant(3));
CHECK(slice3[1] == Variant(4));
Array slice4 = array.slice(2, -2);
- CHECK(slice4.size() == 2);
+ CHECK(slice4.size() == 1);
CHECK(slice4[0] == Variant(2));
- CHECK(slice4[1] == Variant(3));
+
+ Array slice5 = array.slice(-2);
+ CHECK(slice5.size() == 2);
+ CHECK(slice5[0] == Variant(3));
+ CHECK(slice5[1] == Variant(4));
+
+ Array slice6 = array.slice(2, 42);
+ CHECK(slice6.size() == 3);
+ CHECK(slice6[0] == Variant(2));
+ CHECK(slice6[1] == Variant(3));
+ CHECK(slice6[2] == Variant(4));
+
+ Array slice7 = array.slice(4, 0, -2);
+ CHECK(slice7.size() == 2);
+ CHECK(slice7[0] == Variant(4));
+ CHECK(slice7[1] == Variant(2));
+
+ ERR_PRINT_OFF;
+ Array slice8 = array.slice(4, 1);
+ CHECK(slice8.size() == 0);
+
+ Array slice9 = array.slice(3, -4);
+ CHECK(slice9.size() == 0);
+ ERR_PRINT_ON;
}
TEST_CASE("[Array] Duplicate array") {
diff --git a/tests/core/variant/test_dictionary.h b/tests/core/variant/test_dictionary.h
index 65079698a3..729035919d 100644
--- a/tests/core/variant/test_dictionary.h
+++ b/tests/core/variant/test_dictionary.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -196,7 +196,7 @@ TEST_CASE("[Dictionary] Duplicate dictionary") {
Dictionary shallow_d = d.duplicate(false);
CHECK_MESSAGE(shallow_d.id() != d.id(), "Should create a new array");
CHECK_MESSAGE(Dictionary(shallow_d[1]).id() == Dictionary(d[1]).id(), "Should keep nested dictionary");
- CHECK_MESSAGE(Array(shallow_d[2]).id() == Array(d[2]).id(), "Should keep nested array");
+ CHECK_MESSAGE(Array(shallow_d[k2]).id() == Array(d[k2]).id(), "Should keep nested array");
CHECK_EQ(shallow_d, d);
shallow_d[0] = 0;
CHECK_NE(shallow_d, d);
diff --git a/tests/core/variant/test_variant.h b/tests/core/variant/test_variant.h
index 0d16fa092c..916686d7c1 100644
--- a/tests/core/variant/test_variant.h
+++ b/tests/core/variant/test_variant.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/scene/test_animation.h b/tests/scene/test_animation.h
new file mode 100644
index 0000000000..9199713fd9
--- /dev/null
+++ b/tests/scene/test_animation.h
@@ -0,0 +1,314 @@
+/*************************************************************************/
+/* test_animation.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_ANIMATION_H
+#define TEST_ANIMATION_H
+
+#include "scene/resources/animation.h"
+
+#include "tests/test_macros.h"
+
+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)));
+}
+
+TEST_CASE("[Animation] Create value track") {
+ // This creates an animation that makes the node "Enemy" move to the right by
+ // 100 pixels in 0.5 seconds.
+ Ref<Animation> animation = memnew(Animation);
+ const int track_index = animation->add_track(Animation::TYPE_VALUE);
+ CHECK(track_index == 0);
+ animation->track_set_path(track_index, NodePath("Enemy:position:x"));
+ animation->track_insert_key(track_index, 0.0, 0);
+ animation->track_insert_key(track_index, 0.5, 100);
+
+ CHECK(animation->get_track_count() == 1);
+ CHECK(!animation->track_is_compressed(0));
+ 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(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)));
+
+ 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)));
+ // 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)));
+
+ // 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->blend_shape_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
+ ERR_PRINT_ON;
+}
+
+TEST_CASE("[Animation] Create 3D position track") {
+ Ref<Animation> animation = memnew(Animation);
+ const int track_index = animation->add_track(Animation::TYPE_POSITION_3D);
+ animation->track_set_path(track_index, NodePath("Enemy:position"));
+ animation->position_track_insert_key(track_index, 0.0, Vector3(0, 1, 2));
+ animation->position_track_insert_key(track_index, 0.5, Vector3(3.5, 4, 5));
+
+ CHECK(animation->get_track_count() == 1);
+ CHECK(!animation->track_is_compressed(0));
+ CHECK(Vector3(animation->track_get_key_value(0, 0)).is_equal_approx(Vector3(0, 1, 2)));
+ CHECK(Vector3(animation->track_get_key_value(0, 1)).is_equal_approx(Vector3(3.5, 4, 5)));
+
+ Vector3 r_interpolation;
+
+ CHECK(animation->position_track_interpolate(0, -0.2, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Vector3(0, 1, 2)));
+
+ CHECK(animation->position_track_interpolate(0, 0.0, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Vector3(0, 1, 2)));
+
+ CHECK(animation->position_track_interpolate(0, 0.2, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Vector3(1.4, 2.2, 3.2)));
+
+ CHECK(animation->position_track_interpolate(0, 0.4, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Vector3(2.8, 3.4, 4.4)));
+
+ CHECK(animation->position_track_interpolate(0, 0.5, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Vector3(3.5, 4, 5)));
+
+ CHECK(animation->position_track_interpolate(0, 0.6, &r_interpolation) == OK);
+ 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)));
+
+ // 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->blend_shape_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
+ ERR_PRINT_ON;
+}
+
+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)));
+
+ 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))));
+
+ Quaternion r_interpolation;
+
+ CHECK(animation->rotation_track_interpolate(0, -0.2, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Quaternion(0.403423, 0.259035, 0.73846, 0.47416)));
+
+ CHECK(animation->rotation_track_interpolate(0, 0.0, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Quaternion(0.403423, 0.259035, 0.73846, 0.47416)));
+
+ CHECK(animation->rotation_track_interpolate(0, 0.2, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Quaternion(0.336182, 0.30704, 0.751515, 0.477425)));
+
+ CHECK(animation->rotation_track_interpolate(0, 0.4, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Quaternion(0.266585, 0.352893, 0.759303, 0.477344)));
+
+ CHECK(animation->rotation_track_interpolate(0, 0.5, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Quaternion(0.231055, 0.374912, 0.761204, 0.476048)));
+
+ CHECK(animation->rotation_track_interpolate(0, 0.6, &r_interpolation) == OK);
+ 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)));
+
+ // 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->blend_shape_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
+ ERR_PRINT_ON;
+}
+
+TEST_CASE("[Animation] Create 3D scale track") {
+ Ref<Animation> animation = memnew(Animation);
+ const int track_index = animation->add_track(Animation::TYPE_SCALE_3D);
+ animation->track_set_path(track_index, NodePath("Enemy:scale"));
+ animation->scale_track_insert_key(track_index, 0.0, Vector3(0, 1, 2));
+ animation->scale_track_insert_key(track_index, 0.5, Vector3(3.5, 4, 5));
+
+ CHECK(animation->get_track_count() == 1);
+ CHECK(!animation->track_is_compressed(0));
+ CHECK(Vector3(animation->track_get_key_value(0, 0)).is_equal_approx(Vector3(0, 1, 2)));
+ CHECK(Vector3(animation->track_get_key_value(0, 1)).is_equal_approx(Vector3(3.5, 4, 5)));
+
+ Vector3 r_interpolation;
+
+ CHECK(animation->scale_track_interpolate(0, -0.2, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Vector3(0, 1, 2)));
+
+ CHECK(animation->scale_track_interpolate(0, 0.0, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Vector3(0, 1, 2)));
+
+ CHECK(animation->scale_track_interpolate(0, 0.2, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Vector3(1.4, 2.2, 3.2)));
+
+ CHECK(animation->scale_track_interpolate(0, 0.4, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Vector3(2.8, 3.4, 4.4)));
+
+ CHECK(animation->scale_track_interpolate(0, 0.5, &r_interpolation) == OK);
+ CHECK(r_interpolation.is_equal_approx(Vector3(3.5, 4, 5)));
+
+ CHECK(animation->scale_track_interpolate(0, 0.6, &r_interpolation) == OK);
+ 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)));
+
+ // 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->blend_shape_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
+ ERR_PRINT_ON;
+}
+
+TEST_CASE("[Animation] Create blend shape track") {
+ Ref<Animation> animation = memnew(Animation);
+ const int track_index = animation->add_track(Animation::TYPE_BLEND_SHAPE);
+ animation->track_set_path(track_index, NodePath("Enemy:scale"));
+ // Negative values for blend shapes should work as expected.
+ animation->blend_shape_track_insert_key(track_index, 0.0, -1.0);
+ animation->blend_shape_track_insert_key(track_index, 0.5, 1.0);
+
+ CHECK(animation->get_track_count() == 1);
+ CHECK(!animation->track_is_compressed(0));
+
+ 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(animation->blend_shape_track_get_key(0, 1, &r_blend) == OK);
+ CHECK(Math::is_equal_approx(r_blend, 1.0f));
+
+ CHECK(animation->blend_shape_track_interpolate(0, -0.2, &r_blend) == OK);
+ CHECK(Math::is_equal_approx(r_blend, -1.0f));
+
+ CHECK(animation->blend_shape_track_interpolate(0, 0.0, &r_blend) == OK);
+ CHECK(Math::is_equal_approx(r_blend, -1.0f));
+
+ CHECK(animation->blend_shape_track_interpolate(0, 0.2, &r_blend) == OK);
+ CHECK(Math::is_equal_approx(r_blend, -0.2f));
+
+ CHECK(animation->blend_shape_track_interpolate(0, 0.4, &r_blend) == OK);
+ CHECK(Math::is_equal_approx(r_blend, 0.6f));
+
+ CHECK(animation->blend_shape_track_interpolate(0, 0.5, &r_blend) == OK);
+ CHECK(Math::is_equal_approx(r_blend, 1.0f));
+
+ CHECK(animation->blend_shape_track_interpolate(0, 0.6, &r_blend) == OK);
+ CHECK(Math::is_equal_approx(r_blend, 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)));
+
+ // This is a blend shape 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(animation->scale_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
+ CHECK(Math::is_zero_approx(animation->bezier_track_interpolate(0, 0.0)));
+ ERR_PRINT_ON;
+}
+
+TEST_CASE("[Animation] Create Bezier track") {
+ Ref<Animation> animation = memnew(Animation);
+ const int track_index = animation->add_track(Animation::TYPE_BEZIER);
+ animation->track_set_path(track_index, NodePath("Enemy:scale"));
+ animation->bezier_track_insert_key(track_index, 0.0, -1.0, Vector2(-1, -1), Vector2(1, 1));
+ animation->bezier_track_insert_key(track_index, 0.5, 1.0, Vector2(0, 1), Vector2(1, 0.5));
+
+ 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(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)));
+
+ // This is a bezier 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(animation->scale_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
+ CHECK(animation->blend_shape_track_interpolate(0, 0.0, nullptr) == ERR_INVALID_PARAMETER);
+ ERR_PRINT_ON;
+}
+
+} // namespace TestAnimation
+
+#endif // TEST_ANIMATION_H
diff --git a/tests/scene/test_code_edit.h b/tests/scene/test_code_edit.h
index 4b5a049a07..7605f24cf8 100644
--- a/tests/scene/test_code_edit.h
+++ b/tests/scene/test_code_edit.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -40,6 +40,7 @@ namespace TestCodeEdit {
TEST_CASE("[SceneTree][CodeEdit] line gutters") {
CodeEdit *code_edit = memnew(CodeEdit);
SceneTree::get_singleton()->get_root()->add_child(code_edit);
+ code_edit->grab_focus();
SUBCASE("[CodeEdit] breakpoints") {
SIGNAL_WATCH(code_edit, "breakpoint_toggled");
@@ -881,6 +882,7 @@ TEST_CASE("[SceneTree][CodeEdit] line gutters") {
TEST_CASE("[SceneTree][CodeEdit] delimiters") {
CodeEdit *code_edit = memnew(CodeEdit);
SceneTree::get_singleton()->get_root()->add_child(code_edit);
+ code_edit->grab_focus();
const Point2 OUTSIDE_DELIMETER = Point2(-1, -1);
@@ -1104,7 +1106,7 @@ TEST_CASE("[SceneTree][CodeEdit] delimiters") {
CHECK(code_edit->get_delimiter_start_key(idx) == "#");
CHECK(code_edit->get_delimiter_end_key(idx) == "");
- /* Check nested strings are handeled correctly. */
+ /* Check nested strings are handled correctly. */
code_edit->set_text(" \n# # \n ");
/* Check line above is not in string. */
@@ -1132,7 +1134,7 @@ TEST_CASE("[SceneTree][CodeEdit] delimiters") {
CHECK(code_edit->get_delimiter_start_position(2, 1) == OUTSIDE_DELIMETER);
CHECK(code_edit->get_delimiter_end_position(2, 1) == OUTSIDE_DELIMETER);
- /* Check is in string with no column retruns true if entire line is comment excluding whitespace. */
+ /* Check is in string with no column returns true if entire line is comment excluding whitespace. */
code_edit->set_text(" \n # # \n ");
CHECK(code_edit->is_in_string(1) != -1);
@@ -1195,7 +1197,7 @@ TEST_CASE("[SceneTree][CodeEdit] delimiters") {
CHECK(code_edit->get_delimiter_start_key(idx) == "#");
CHECK(code_edit->get_delimiter_end_key(idx) == "");
- /* Check nested comments are handeled correctly. */
+ /* Check nested comments are handled correctly. */
code_edit->set_text(" \n# # \n ");
/* Check line above is not in comment. */
@@ -1223,7 +1225,7 @@ TEST_CASE("[SceneTree][CodeEdit] delimiters") {
CHECK(code_edit->get_delimiter_start_position(2, 1) == OUTSIDE_DELIMETER);
CHECK(code_edit->get_delimiter_end_position(2, 1) == OUTSIDE_DELIMETER);
- /* Check is in comment with no column retruns true if entire line is comment excluding whitespace. */
+ /* Check is in comment with no column returns true if entire line is comment excluding whitespace. */
code_edit->set_text(" \n # # \n ");
CHECK(code_edit->is_in_comment(1) != -1);
@@ -1491,7 +1493,7 @@ TEST_CASE("[SceneTree][CodeEdit] delimiters") {
CHECK(code_edit->get_delimiter_start_key(idx) == "#");
CHECK(code_edit->get_delimiter_end_key(idx) == "#");
- /* Check is in string with no column retruns true if entire line is string excluding whitespace. */
+ /* Check is in string with no column returns true if entire line is string excluding whitespace. */
code_edit->set_text(" \n # \n\n #\n ");
CHECK(code_edit->is_in_string(1) != -1);
CHECK(code_edit->is_in_string(2) != -1);
@@ -1680,7 +1682,7 @@ TEST_CASE("[SceneTree][CodeEdit] delimiters") {
CHECK(code_edit->get_delimiter_start_key(idx) == "#");
CHECK(code_edit->get_delimiter_end_key(idx) == "#");
- /* Check is in comment with no column retruns true if entire line is comment excluding whitespace. */
+ /* Check is in comment with no column returns true if entire line is comment excluding whitespace. */
code_edit->set_text(" \n # \n\n #\n ");
CHECK(code_edit->is_in_comment(1) != -1);
CHECK(code_edit->is_in_comment(2) != -1);
@@ -1746,7 +1748,7 @@ TEST_CASE("[SceneTree][CodeEdit] delimiters") {
CHECK(code_edit->get_delimiter_start_key(idx) == "#");
CHECK(code_edit->get_delimiter_end_key(idx) == "#");
- /* Check is in comment with no column retruns true as inner delimiter should not be counted. */
+ /* Check is in comment with no column returns true as inner delimiter should not be counted. */
CHECK(code_edit->is_in_comment(1) != -1);
CHECK(code_edit->is_in_comment(2) != -1);
CHECK(code_edit->is_in_comment(3) != -1);
@@ -1759,6 +1761,7 @@ TEST_CASE("[SceneTree][CodeEdit] delimiters") {
TEST_CASE("[SceneTree][CodeEdit] indent") {
CodeEdit *code_edit = memnew(CodeEdit);
SceneTree::get_singleton()->get_root()->add_child(code_edit);
+ code_edit->grab_focus();
SUBCASE("[CodeEdit] indent settings") {
code_edit->set_indent_size(10);
@@ -2176,8 +2179,24 @@ TEST_CASE("[SceneTree][CodeEdit] indent") {
SEND_GUI_ACTION(code_edit, "ui_text_newline");
CHECK(code_edit->get_line(0) == "test: # string");
CHECK(code_edit->get_line(1) == "");
+ code_edit->remove_string_delimiter("#");
+
+ /* Non-whitespace prevents auto-indentation. */
+ code_edit->add_comment_delimiter("#", "");
+ code_edit->set_text("");
+ code_edit->insert_text_at_caret("test := 0 # comment");
+ SEND_GUI_ACTION(code_edit, "ui_text_newline");
+ CHECK(code_edit->get_line(0) == "test := 0 # comment");
+ CHECK(code_edit->get_line(1) == "");
code_edit->remove_comment_delimiter("#");
+ /* Even when there's no comments. */
+ code_edit->set_text("");
+ code_edit->insert_text_at_caret("test := 0");
+ SEND_GUI_ACTION(code_edit, "ui_text_newline");
+ CHECK(code_edit->get_line(0) == "test := 0");
+ CHECK(code_edit->get_line(1) == "");
+
/* If between brace pairs an extra line is added. */
code_edit->set_text("");
code_edit->insert_text_at_caret("test{}");
@@ -2253,8 +2272,24 @@ TEST_CASE("[SceneTree][CodeEdit] indent") {
SEND_GUI_ACTION(code_edit, "ui_text_newline");
CHECK(code_edit->get_line(0) == "test: # string");
CHECK(code_edit->get_line(1) == "");
+ code_edit->remove_string_delimiter("#");
+
+ /* Non-whitespace prevents auto-indentation. */
+ code_edit->add_comment_delimiter("#", "");
+ code_edit->set_text("");
+ code_edit->insert_text_at_caret("test := 0 # comment");
+ SEND_GUI_ACTION(code_edit, "ui_text_newline");
+ CHECK(code_edit->get_line(0) == "test := 0 # comment");
+ CHECK(code_edit->get_line(1) == "");
code_edit->remove_comment_delimiter("#");
+ /* Even when there's no comments. */
+ code_edit->set_text("");
+ code_edit->insert_text_at_caret("test := 0");
+ SEND_GUI_ACTION(code_edit, "ui_text_newline");
+ CHECK(code_edit->get_line(0) == "test := 0");
+ CHECK(code_edit->get_line(1) == "");
+
/* If between brace pairs an extra line is added. */
code_edit->set_text("");
code_edit->insert_text_at_caret("test{}");
@@ -2288,6 +2323,7 @@ TEST_CASE("[SceneTree][CodeEdit] indent") {
TEST_CASE("[SceneTree][CodeEdit] folding") {
CodeEdit *code_edit = memnew(CodeEdit);
SceneTree::get_singleton()->get_root()->add_child(code_edit);
+ code_edit->grab_focus();
SUBCASE("[CodeEdit] folding settings") {
code_edit->set_line_folding_enabled(true);
@@ -2672,6 +2708,7 @@ TEST_CASE("[SceneTree][CodeEdit] folding") {
TEST_CASE("[SceneTree][CodeEdit] completion") {
CodeEdit *code_edit = memnew(CodeEdit);
SceneTree::get_singleton()->get_root()->add_child(code_edit);
+ code_edit->grab_focus();
SUBCASE("[CodeEdit] auto brace completion") {
code_edit->set_auto_brace_completion_enabled(true);
@@ -2786,6 +2823,52 @@ TEST_CASE("[SceneTree][CodeEdit] completion") {
SEND_GUI_KEY_EVENT(code_edit, Key::APOSTROPHE);
SEND_GUI_KEY_EVENT(code_edit, Key::QUOTEDBL);
CHECK(code_edit->get_line(0) == "'\"'");
+
+ /* Wrap single line selection with brackets */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("abc");
+ code_edit->select_all();
+ SEND_GUI_KEY_EVENT(code_edit, Key::BRACKETLEFT);
+ CHECK(code_edit->get_line(0) == "[abc]");
+
+ /* Caret should be after the last character of the single line selection */
+ CHECK(code_edit->get_caret_column() == 4);
+
+ /* Wrap multi line selection with brackets */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("abc\nabc");
+ code_edit->select_all();
+ SEND_GUI_KEY_EVENT(code_edit, Key::BRACKETLEFT);
+ CHECK(code_edit->get_text() == "[abc\nabc]");
+
+ /* Caret should be after the last character of the multi line selection */
+ CHECK(code_edit->get_caret_line() == 1);
+ CHECK(code_edit->get_caret_column() == 3);
+
+ /* If inserted character is not a auto brace completion open key, replace selected text with the inserted character */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("abc");
+ code_edit->select_all();
+ SEND_GUI_KEY_EVENT(code_edit, Key::KEY_1);
+ CHECK(code_edit->get_text() == "1");
+
+ /* If potential multichar and single brace completion is matched, it should wrap the single. */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("\'\'abc");
+ code_edit->select(0, 2, 0, 5);
+ SEND_GUI_KEY_EVENT(code_edit, Key::APOSTROPHE);
+ CHECK(code_edit->get_text() == "\'\'\'abc\'");
+
+ /* If only the potential multichar brace completion is matched, it does not wrap or complete. */
+ auto_brace_completion_pairs.erase("\'");
+ code_edit->set_auto_brace_completion_pairs(auto_brace_completion_pairs);
+ CHECK_FALSE(code_edit->has_auto_brace_completion_open_key("\'"));
+
+ code_edit->clear();
+ code_edit->insert_text_at_caret("\'\'abc");
+ code_edit->select(0, 2, 0, 5);
+ SEND_GUI_KEY_EVENT(code_edit, Key::APOSTROPHE);
+ CHECK(code_edit->get_text() == "\'\'\'");
}
SUBCASE("[CodeEdit] autocomplete") {
@@ -2812,7 +2895,7 @@ TEST_CASE("[SceneTree][CodeEdit] completion") {
}
SUBCASE("[CodeEdit] autocomplete request") {
- SIGNAL_WATCH(code_edit, "request_code_completion");
+ SIGNAL_WATCH(code_edit, "code_completion_requested");
code_edit->set_code_completion_enabled(true);
Array signal_args;
@@ -2820,13 +2903,13 @@ TEST_CASE("[SceneTree][CodeEdit] completion") {
/* Force request. */
code_edit->request_code_completion();
- SIGNAL_CHECK_FALSE("request_code_completion");
+ SIGNAL_CHECK_FALSE("code_completion_requested");
code_edit->request_code_completion(true);
- SIGNAL_CHECK("request_code_completion", signal_args);
+ SIGNAL_CHECK("code_completion_requested", signal_args);
/* Manual request should force. */
SEND_GUI_ACTION(code_edit, "ui_text_completion_query");
- SIGNAL_CHECK("request_code_completion", signal_args);
+ SIGNAL_CHECK("code_completion_requested", signal_args);
/* Insert prefix. */
TypedArray<String> completion_prefixes;
@@ -2835,12 +2918,12 @@ TEST_CASE("[SceneTree][CodeEdit] completion") {
code_edit->insert_text_at_caret(".");
code_edit->request_code_completion();
- SIGNAL_CHECK("request_code_completion", signal_args);
+ SIGNAL_CHECK("code_completion_requested", signal_args);
/* Should work with space too. */
code_edit->insert_text_at_caret(" ");
code_edit->request_code_completion();
- SIGNAL_CHECK("request_code_completion", signal_args);
+ SIGNAL_CHECK("code_completion_requested", signal_args);
/* Should work when complete ends with prefix. */
code_edit->clear();
@@ -2849,297 +2932,299 @@ TEST_CASE("[SceneTree][CodeEdit] completion") {
code_edit->update_code_completion_options();
code_edit->confirm_code_completion();
CHECK(code_edit->get_line(0) == "test.");
- SIGNAL_CHECK("request_code_completion", signal_args);
+ SIGNAL_CHECK("code_completion_requested", signal_args);
- SIGNAL_UNWATCH(code_edit, "request_code_completion");
+ SIGNAL_UNWATCH(code_edit, "code_completion_requested");
}
SUBCASE("[CodeEdit] autocomplete completion") {
- CHECK(code_edit->get_code_completion_selected_index() == -1);
- code_edit->set_code_completion_enabled(true);
- CHECK(code_edit->get_code_completion_selected_index() == -1);
-
- code_edit->update_code_completion_options();
- code_edit->set_code_completion_selected_index(1);
- CHECK(code_edit->get_code_completion_selected_index() == -1);
- CHECK(code_edit->get_code_completion_option(0).size() == 0);
- CHECK(code_edit->get_code_completion_options().size() == 0);
-
- /* Adding does not update the list. */
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "item_0.", "item_0");
-
- code_edit->set_code_completion_selected_index(1);
- CHECK(code_edit->get_code_completion_selected_index() == -1);
- CHECK(code_edit->get_code_completion_option(0).size() == 0);
- CHECK(code_edit->get_code_completion_options().size() == 0);
-
- /* After update, pending add should not be counted, */
- /* also does not work on col 0 */
- code_edit->insert_text_at_caret("i");
- code_edit->update_code_completion_options();
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0", Color(1, 0, 0), RES(), Color(1, 0, 0));
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "item_1.", "item_1");
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "item_2.", "item_2");
-
- ERR_PRINT_OFF;
- code_edit->set_code_completion_selected_index(1);
- ERR_PRINT_ON;
- CHECK(code_edit->get_code_completion_selected_index() == 0);
- CHECK(code_edit->get_code_completion_option(0).size() == 6);
- CHECK(code_edit->get_code_completion_options().size() == 1);
-
- /* Check cancel closes completion. */
- SEND_GUI_ACTION(code_edit, "ui_cancel");
- CHECK(code_edit->get_code_completion_selected_index() == -1);
-
- code_edit->update_code_completion_options();
- CHECK(code_edit->get_code_completion_selected_index() == 0);
- code_edit->set_code_completion_selected_index(1);
- CHECK(code_edit->get_code_completion_selected_index() == 1);
- CHECK(code_edit->get_code_completion_option(0).size() == 6);
- CHECK(code_edit->get_code_completion_options().size() == 3);
-
- /* Check data. */
- Dictionary option = code_edit->get_code_completion_option(0);
- CHECK((int)option["kind"] == (int)CodeEdit::CodeCompletionKind::KIND_CLASS);
- CHECK(option["display_text"] == "item_0.");
- CHECK(option["insert_text"] == "item_0");
- CHECK(option["font_color"] == Color(1, 0, 0));
- CHECK(option["icon"] == RES());
- CHECK(option["default_value"] == Color(1, 0, 0));
-
- /* Set size for mouse input. */
- code_edit->set_size(Size2(100, 100));
-
- /* Check input. */
- SEND_GUI_ACTION(code_edit, "ui_end");
- CHECK(code_edit->get_code_completion_selected_index() == 2);
-
- SEND_GUI_ACTION(code_edit, "ui_home");
- CHECK(code_edit->get_code_completion_selected_index() == 0);
-
- SEND_GUI_ACTION(code_edit, "ui_page_down");
- CHECK(code_edit->get_code_completion_selected_index() == 2);
-
- SEND_GUI_ACTION(code_edit, "ui_page_up");
- CHECK(code_edit->get_code_completion_selected_index() == 0);
-
- SEND_GUI_ACTION(code_edit, "ui_up");
- CHECK(code_edit->get_code_completion_selected_index() == 2);
+ if (TS->has_feature(TextServer::FEATURE_FONT_DYNAMIC) && TS->has_feature(TextServer::FEATURE_SIMPLE_LAYOUT)) {
+ CHECK(code_edit->get_code_completion_selected_index() == -1);
+ code_edit->set_code_completion_enabled(true);
+ CHECK(code_edit->get_code_completion_selected_index() == -1);
+
+ code_edit->update_code_completion_options();
+ code_edit->set_code_completion_selected_index(1);
+ CHECK(code_edit->get_code_completion_selected_index() == -1);
+ CHECK(code_edit->get_code_completion_option(0).size() == 0);
+ CHECK(code_edit->get_code_completion_options().size() == 0);
+
+ /* Adding does not update the list. */
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "item_0.", "item_0");
+
+ code_edit->set_code_completion_selected_index(1);
+ CHECK(code_edit->get_code_completion_selected_index() == -1);
+ CHECK(code_edit->get_code_completion_option(0).size() == 0);
+ CHECK(code_edit->get_code_completion_options().size() == 0);
+
+ /* After update, pending add should not be counted, */
+ /* also does not work on col 0 */
+ code_edit->insert_text_at_caret("i");
+ code_edit->update_code_completion_options();
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0", Color(1, 0, 0), Ref<Resource>(), Color(1, 0, 0));
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "item_1.", "item_1");
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_VARIABLE, "item_2.", "item_2");
- SEND_GUI_ACTION(code_edit, "ui_down");
- CHECK(code_edit->get_code_completion_selected_index() == 0);
+ ERR_PRINT_OFF;
+ code_edit->set_code_completion_selected_index(1);
+ ERR_PRINT_ON;
+ CHECK(code_edit->get_code_completion_selected_index() == 0);
+ CHECK(code_edit->get_code_completion_option(0).size() == 6);
+ CHECK(code_edit->get_code_completion_options().size() == 1);
- SEND_GUI_KEY_EVENT(code_edit, Key::T);
- CHECK(code_edit->get_code_completion_selected_index() == 0);
+ /* Check cancel closes completion. */
+ SEND_GUI_ACTION(code_edit, "ui_cancel");
+ CHECK(code_edit->get_code_completion_selected_index() == -1);
- SEND_GUI_ACTION(code_edit, "ui_left");
- CHECK(code_edit->get_code_completion_selected_index() == 0);
+ code_edit->update_code_completion_options();
+ CHECK(code_edit->get_code_completion_selected_index() == 0);
+ code_edit->set_code_completion_selected_index(1);
+ CHECK(code_edit->get_code_completion_selected_index() == 1);
+ CHECK(code_edit->get_code_completion_option(0).size() == 6);
+ CHECK(code_edit->get_code_completion_options().size() == 3);
- SEND_GUI_ACTION(code_edit, "ui_right");
- CHECK(code_edit->get_code_completion_selected_index() == 0);
+ /* Check data. */
+ Dictionary option = code_edit->get_code_completion_option(0);
+ CHECK((int)option["kind"] == (int)CodeEdit::CodeCompletionKind::KIND_CLASS);
+ CHECK(option["display_text"] == "item_0.");
+ CHECK(option["insert_text"] == "item_0");
+ CHECK(option["font_color"] == Color(1, 0, 0));
+ CHECK(option["icon"] == Ref<Resource>());
+ CHECK(option["default_value"] == Color(1, 0, 0));
- SEND_GUI_ACTION(code_edit, "ui_text_backspace");
- CHECK(code_edit->get_code_completion_selected_index() == 0);
-
- Point2 caret_pos = code_edit->get_caret_draw_pos();
- caret_pos.y -= code_edit->get_line_height();
- SEND_GUI_MOUSE_EVENT(code_edit, caret_pos, MouseButton::WHEEL_DOWN, MouseButton::NONE);
- CHECK(code_edit->get_code_completion_selected_index() == 1);
+ /* Set size for mouse input. */
+ code_edit->set_size(Size2(100, 100));
- SEND_GUI_MOUSE_EVENT(code_edit, caret_pos, MouseButton::WHEEL_UP, MouseButton::NONE);
- CHECK(code_edit->get_code_completion_selected_index() == 0);
+ /* Check input. */
+ SEND_GUI_ACTION(code_edit, "ui_end");
+ CHECK(code_edit->get_code_completion_selected_index() == 2);
- /* Single click selects. */
- SEND_GUI_MOUSE_EVENT(code_edit, caret_pos, MouseButton::LEFT, MouseButton::MASK_LEFT);
- CHECK(code_edit->get_code_completion_selected_index() == 2);
+ SEND_GUI_ACTION(code_edit, "ui_home");
+ CHECK(code_edit->get_code_completion_selected_index() == 0);
- /* Double click inserts. */
- SEND_GUI_DOUBLE_CLICK(code_edit, caret_pos);
- CHECK(code_edit->get_code_completion_selected_index() == -1);
- CHECK(code_edit->get_line(0) == "item_2");
+ SEND_GUI_ACTION(code_edit, "ui_page_down");
+ CHECK(code_edit->get_code_completion_selected_index() == 2);
- code_edit->set_auto_brace_completion_enabled(false);
+ SEND_GUI_ACTION(code_edit, "ui_page_up");
+ CHECK(code_edit->get_code_completion_selected_index() == 0);
- /* Does nothing in readonly. */
- code_edit->undo();
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0");
- code_edit->update_code_completion_options();
- code_edit->set_editable(false);
- code_edit->confirm_code_completion();
- code_edit->set_editable(true);
- CHECK(code_edit->get_line(0) == "i");
+ SEND_GUI_ACTION(code_edit, "ui_up");
+ CHECK(code_edit->get_code_completion_selected_index() == 2);
- /* Replace */
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1 test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "item_0 test");
+ SEND_GUI_ACTION(code_edit, "ui_down");
+ CHECK(code_edit->get_code_completion_selected_index() == 0);
- /* Replace string. */
- code_edit->clear();
- code_edit->insert_text_at_caret("\"item_1 test\"");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "\"item_0\"");
+ SEND_GUI_KEY_EVENT(code_edit, Key::T);
+ CHECK(code_edit->get_code_completion_selected_index() == 0);
- /* Normal replace if no end is given. */
- code_edit->clear();
- code_edit->insert_text_at_caret("\"item_1 test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "\"item_0\" test");
+ SEND_GUI_ACTION(code_edit, "ui_left");
+ CHECK(code_edit->get_code_completion_selected_index() == 0);
- /* Insert at completion. */
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1 test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_accept");
- CHECK(code_edit->get_line(0) == "item_01 test");
+ SEND_GUI_ACTION(code_edit, "ui_right");
+ CHECK(code_edit->get_code_completion_selected_index() == 0);
- /* Insert at completion with string should have same output. */
- code_edit->clear();
- code_edit->insert_text_at_caret("\"item_1 test\"");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_accept");
- CHECK(code_edit->get_line(0) == "\"item_0\"1 test\"");
-
- /* Merge symbol at end on insert text. */
- /* End on completion entry. */
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1 test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0(", "item_0(");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "item_0( test");
- CHECK(code_edit->get_caret_column() == 7);
-
- /* End of text*/
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1( test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0", "item_0");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "item_0( test");
- CHECK(code_edit->get_caret_column() == 6);
-
- /* End of both. */
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1( test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0(", "item_0(");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "item_0( test");
- CHECK(code_edit->get_caret_column() == 7);
-
- /* Full set. */
- /* End on completion entry. */
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1 test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0()", "item_0()");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "item_0() test");
- CHECK(code_edit->get_caret_column() == 8);
-
- /* End of text*/
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1() test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0", "item_0");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "item_0() test");
- CHECK(code_edit->get_caret_column() == 6);
-
- /* End of both. */
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1() test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0()", "item_0()");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "item_0() test");
- CHECK(code_edit->get_caret_column() == 8);
-
- /* Autobrace completion. */
- code_edit->set_auto_brace_completion_enabled(true);
+ SEND_GUI_ACTION(code_edit, "ui_text_backspace");
+ CHECK(code_edit->get_code_completion_selected_index() == 0);
- /* End on completion entry. */
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1 test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0(", "item_0(");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "item_0() test");
- CHECK(code_edit->get_caret_column() == 7);
+ Point2 caret_pos = code_edit->get_caret_draw_pos();
+ caret_pos.y -= code_edit->get_line_height();
+ SEND_GUI_MOUSE_BUTTON_EVENT(code_edit, caret_pos, MouseButton::WHEEL_DOWN, MouseButton::NONE, Key::NONE);
+ CHECK(code_edit->get_code_completion_selected_index() == 1);
- /* End of text*/
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1( test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0", "item_0");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "item_0( test");
- CHECK(code_edit->get_caret_column() == 6);
+ SEND_GUI_MOUSE_BUTTON_EVENT(code_edit, caret_pos, MouseButton::WHEEL_UP, MouseButton::NONE, Key::NONE);
+ CHECK(code_edit->get_code_completion_selected_index() == 0);
- /* End of both. */
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1( test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0(", "item_0(");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "item_0( test");
- CHECK(code_edit->get_caret_column() == 7);
+ /* Single click selects. */
+ SEND_GUI_MOUSE_BUTTON_EVENT(code_edit, caret_pos, MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE);
+ CHECK(code_edit->get_code_completion_selected_index() == 2);
- /* Full set. */
- /* End on completion entry. */
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1 test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0()", "item_0()");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "item_0() test");
- CHECK(code_edit->get_caret_column() == 8);
+ /* Double click inserts. */
+ SEND_GUI_DOUBLE_CLICK(code_edit, caret_pos, Key::NONE);
+ CHECK(code_edit->get_code_completion_selected_index() == -1);
+ CHECK(code_edit->get_line(0) == "item_2");
- /* End of text*/
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1() test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0", "item_0");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "item_0() test");
- CHECK(code_edit->get_caret_column() == 6);
+ code_edit->set_auto_brace_completion_enabled(false);
- /* End of both. */
- code_edit->clear();
- code_edit->insert_text_at_caret("item_1() test");
- code_edit->set_caret_column(2);
- code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0()", "item_0()");
- code_edit->update_code_completion_options();
- SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
- CHECK(code_edit->get_line(0) == "item_0() test");
- CHECK(code_edit->get_caret_column() == 8);
+ /* Does nothing in readonly. */
+ code_edit->undo();
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0");
+ code_edit->update_code_completion_options();
+ code_edit->set_editable(false);
+ code_edit->confirm_code_completion();
+ code_edit->set_editable(true);
+ CHECK(code_edit->get_line(0) == "i");
+
+ /* Replace */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1 test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "item_0 test");
+
+ /* Replace string. */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("\"item_1 test\"");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "\"item_0\"");
+
+ /* Normal replace if no end is given. */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("\"item_1 test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "\"item_0\" test");
+
+ /* Insert at completion. */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1 test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_accept");
+ CHECK(code_edit->get_line(0) == "item_01 test");
+
+ /* Insert at completion with string should have same output. */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("\"item_1 test\"");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0.", "item_0");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_accept");
+ CHECK(code_edit->get_line(0) == "\"item_0\"1 test\"");
+
+ /* Merge symbol at end on insert text. */
+ /* End on completion entry. */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1 test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0(", "item_0(");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "item_0( test");
+ CHECK(code_edit->get_caret_column() == 7);
+
+ /* End of text*/
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1( test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0", "item_0");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "item_0( test");
+ CHECK(code_edit->get_caret_column() == 6);
+
+ /* End of both. */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1( test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0(", "item_0(");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "item_0( test");
+ CHECK(code_edit->get_caret_column() == 7);
+
+ /* Full set. */
+ /* End on completion entry. */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1 test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0()", "item_0()");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "item_0() test");
+ CHECK(code_edit->get_caret_column() == 8);
+
+ /* End of text*/
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1() test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0", "item_0");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "item_0() test");
+ CHECK(code_edit->get_caret_column() == 6);
+
+ /* End of both. */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1() test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0()", "item_0()");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "item_0() test");
+ CHECK(code_edit->get_caret_column() == 8);
+
+ /* Autobrace completion. */
+ code_edit->set_auto_brace_completion_enabled(true);
+
+ /* End on completion entry. */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1 test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0(", "item_0(");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "item_0() test");
+ CHECK(code_edit->get_caret_column() == 7);
+
+ /* End of text*/
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1( test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0", "item_0");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "item_0( test");
+ CHECK(code_edit->get_caret_column() == 6);
+
+ /* End of both. */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1( test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0(", "item_0(");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "item_0( test");
+ CHECK(code_edit->get_caret_column() == 7);
+
+ /* Full set. */
+ /* End on completion entry. */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1 test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0()", "item_0()");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "item_0() test");
+ CHECK(code_edit->get_caret_column() == 8);
+
+ /* End of text*/
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1() test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0", "item_0");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "item_0() test");
+ CHECK(code_edit->get_caret_column() == 6);
+
+ /* End of both. */
+ code_edit->clear();
+ code_edit->insert_text_at_caret("item_1() test");
+ code_edit->set_caret_column(2);
+ code_edit->add_code_completion_option(CodeEdit::CodeCompletionKind::KIND_CLASS, "item_0()", "item_0()");
+ code_edit->update_code_completion_options();
+ SEND_GUI_ACTION(code_edit, "ui_text_completion_replace");
+ CHECK(code_edit->get_line(0) == "item_0() test");
+ CHECK(code_edit->get_caret_column() == 8);
+ }
}
memdelete(code_edit);
@@ -3148,42 +3233,46 @@ TEST_CASE("[SceneTree][CodeEdit] completion") {
TEST_CASE("[SceneTree][CodeEdit] symbol lookup") {
CodeEdit *code_edit = memnew(CodeEdit);
SceneTree::get_singleton()->get_root()->add_child(code_edit);
+ code_edit->grab_focus();
code_edit->set_symbol_lookup_on_click_enabled(true);
CHECK(code_edit->is_symbol_lookup_on_click_enabled());
- /* Set size for mouse input. */
- code_edit->set_size(Size2(100, 100));
+ if (TS->has_feature(TextServer::FEATURE_FONT_DYNAMIC) && TS->has_feature(TextServer::FEATURE_SIMPLE_LAYOUT)) {
+ /* Set size for mouse input. */
+ code_edit->set_size(Size2(100, 100));
- code_edit->set_text("this is some text");
+ code_edit->set_text("this is some text");
- Point2 caret_pos = code_edit->get_caret_draw_pos();
- caret_pos.x += 55;
- SEND_GUI_MOUSE_EVENT(code_edit, caret_pos, MouseButton::NONE, MouseButton::NONE);
- CHECK(code_edit->get_text_for_symbol_lookup() == "this is s" + String::chr(0xFFFF) + "ome text");
+ Point2 caret_pos = code_edit->get_caret_draw_pos();
+ caret_pos.x += 58;
+ SEND_GUI_MOUSE_BUTTON_EVENT(code_edit, caret_pos, MouseButton::NONE, MouseButton::NONE, Key::NONE);
+ CHECK(code_edit->get_text_for_symbol_lookup() == "this is s" + String::chr(0xFFFF) + "ome text");
- SIGNAL_WATCH(code_edit, "symbol_validate");
+ SIGNAL_WATCH(code_edit, "symbol_validate");
-#ifdef OSX_ENABLED
- SEND_GUI_KEY_EVENT(code_edit, Key::META);
+#ifdef MACOS_ENABLED
+ SEND_GUI_KEY_EVENT(code_edit, Key::META);
#else
- SEND_GUI_KEY_EVENT(code_edit, Key::CTRL);
+ SEND_GUI_KEY_EVENT(code_edit, Key::CTRL);
#endif
- Array signal_args;
- Array arg;
- arg.push_back("some");
- signal_args.push_back(arg);
- SIGNAL_CHECK("symbol_validate", signal_args);
+ Array signal_args;
+ Array arg;
+ arg.push_back("some");
+ signal_args.push_back(arg);
+ SIGNAL_CHECK("symbol_validate", signal_args);
- SIGNAL_UNWATCH(code_edit, "symbol_validate");
+ SIGNAL_UNWATCH(code_edit, "symbol_validate");
- memdelete(code_edit);
+ memdelete(code_edit);
+ }
}
TEST_CASE("[SceneTree][CodeEdit] line length guidelines") {
CodeEdit *code_edit = memnew(CodeEdit);
SceneTree::get_singleton()->get_root()->add_child(code_edit);
+ code_edit->grab_focus();
TypedArray<int> guide_lines;
@@ -3204,6 +3293,7 @@ TEST_CASE("[SceneTree][CodeEdit] line length guidelines") {
TEST_CASE("[SceneTree][CodeEdit] Backspace delete") {
CodeEdit *code_edit = memnew(CodeEdit);
SceneTree::get_singleton()->get_root()->add_child(code_edit);
+ code_edit->grab_focus();
/* Backspace with selection on first line. */
code_edit->set_text("");
@@ -3220,7 +3310,7 @@ TEST_CASE("[SceneTree][CodeEdit] Backspace delete") {
code_edit->backspace();
CHECK(code_edit->get_line(0) == "backspace");
- /* Move caret up to the previous line on backspace if carret is at the first column. */
+ /* Move caret up to the previous line on backspace if caret is at the first column. */
code_edit->set_text("");
code_edit->insert_text_at_caret("line 1\nline 2");
code_edit->set_caret_line(1);
@@ -3248,6 +3338,56 @@ TEST_CASE("[SceneTree][CodeEdit] Backspace delete") {
memdelete(code_edit);
}
+TEST_CASE("[SceneTree][CodeEdit] New Line") {
+ CodeEdit *code_edit = memnew(CodeEdit);
+ SceneTree::get_singleton()->get_root()->add_child(code_edit);
+ code_edit->grab_focus();
+
+ /* Add a new line. */
+ code_edit->set_text("");
+ code_edit->insert_text_at_caret("test new line");
+ code_edit->set_caret_line(0);
+ code_edit->set_caret_column(13);
+ SEND_GUI_ACTION(code_edit, "ui_text_newline");
+ CHECK(code_edit->get_line(0) == "test new line");
+ CHECK(code_edit->get_line(1) == "");
+
+ /* Split line with new line. */
+ code_edit->set_text("");
+ code_edit->insert_text_at_caret("test new line");
+ code_edit->set_caret_line(0);
+ code_edit->set_caret_column(5);
+ SEND_GUI_ACTION(code_edit, "ui_text_newline");
+ CHECK(code_edit->get_line(0) == "test ");
+ CHECK(code_edit->get_line(1) == "new line");
+
+ /* Delete selection and split with new line. */
+ code_edit->set_text("");
+ code_edit->insert_text_at_caret("test new line");
+ code_edit->select(0, 0, 0, 5);
+ SEND_GUI_ACTION(code_edit, "ui_text_newline");
+ CHECK(code_edit->get_line(0) == "");
+ CHECK(code_edit->get_line(1) == "new line");
+
+ /* Blank new line below with selection should not split. */
+ code_edit->set_text("");
+ code_edit->insert_text_at_caret("test new line");
+ code_edit->select(0, 0, 0, 5);
+ SEND_GUI_ACTION(code_edit, "ui_text_newline_blank");
+ CHECK(code_edit->get_line(0) == "test new line");
+ CHECK(code_edit->get_line(1) == "");
+
+ /* Blank new line above with selection should not split. */
+ code_edit->set_text("");
+ code_edit->insert_text_at_caret("test new line");
+ code_edit->select(0, 0, 0, 5);
+ SEND_GUI_ACTION(code_edit, "ui_text_newline_above");
+ CHECK(code_edit->get_line(0) == "");
+ CHECK(code_edit->get_line(1) == "test new line");
+
+ memdelete(code_edit);
+}
+
} // namespace TestCodeEdit
#endif // TEST_CODE_EDIT_H
diff --git a/tests/scene/test_curve.h b/tests/scene/test_curve.h
index 4ee1a1c15c..0370ab15fd 100644
--- a/tests/scene/test_curve.h
+++ b/tests/scene/test_curve.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/scene/test_gradient.h b/tests/scene/test_gradient.h
index fc595b02f2..b0e6128932 100644
--- a/tests/scene/test_gradient.h
+++ b/tests/scene/test_gradient.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/scene/test_gui.cpp b/tests/scene/test_gui.cpp
deleted file mode 100644
index 086943838c..0000000000
--- a/tests/scene/test_gui.cpp
+++ /dev/null
@@ -1,259 +0,0 @@
-/*************************************************************************/
-/* test_gui.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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 _3D_DISABLED
-
-#include "test_gui.h"
-
-#include "scene/gui/button.h"
-#include "scene/gui/label.h"
-#include "scene/gui/line_edit.h"
-#include "scene/gui/menu_button.h"
-#include "scene/gui/option_button.h"
-#include "scene/gui/panel.h"
-#include "scene/gui/progress_bar.h"
-#include "scene/gui/rich_text_label.h"
-#include "scene/gui/scroll_bar.h"
-#include "scene/gui/spin_box.h"
-#include "scene/gui/tab_container.h"
-#include "scene/gui/tree.h"
-
-namespace TestGUI {
-
-class TestMainLoop : public SceneTree {
-public:
- virtual void request_quit() {
- quit();
- }
- virtual void initialize() {
- SceneTree::initialize();
-
- Panel *frame = memnew(Panel);
- frame->set_anchor(SIDE_RIGHT, Control::ANCHOR_END);
- frame->set_anchor(SIDE_BOTTOM, Control::ANCHOR_END);
- frame->set_end(Point2(0, 0));
-
- Ref<Theme> t = memnew(Theme);
- frame->set_theme(t);
-
- get_root()->add_child(frame);
-
- Label *label = memnew(Label);
-
- label->set_position(Point2(80, 90));
- label->set_size(Point2(170, 80));
- label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_FILL);
- label->set_text("There was once upon a time a beautiful unicorn that loved to play with little girls...");
-
- frame->add_child(label);
-
- Button *button = memnew(Button);
-
- button->set_position(Point2(20, 20));
- button->set_size(Point2(1, 1));
- button->set_text("This is a biggie button");
-
- frame->add_child(button);
-
- Tree *tree = memnew(Tree);
- tree->set_columns(2);
-
- tree->set_position(Point2(230, 210));
- tree->set_size(Point2(150, 250));
-
- TreeItem *item = tree->create_item();
- item->set_editable(0, true);
- item->set_text(0, "root");
- item = tree->create_item(tree->get_root());
- item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
- item->set_editable(0, true);
- item->set_text(0, "check");
- item->set_cell_mode(1, TreeItem::CELL_MODE_CHECK);
- item->set_editable(1, true);
- item->set_text(1, "check2");
- item = tree->create_item(tree->get_root());
- item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
- item->set_editable(0, true);
- item->set_range_config(0, 0, 20, 0.1);
- item->set_range(0, 2);
- item->add_button(0, Theme::get_default()->get_icon("folder", "FileDialog"));
- item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
- item->set_editable(1, true);
- item->set_range_config(1, 0, 20, 0.1);
- item->set_range(1, 3);
-
- item = tree->create_item(tree->get_root());
- item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
- item->set_editable(0, true);
- item->set_text(0, "Have,Many,Several,Options!");
- item->set_range(0, 2);
-
- item = tree->create_item(item);
- item->set_editable(0, true);
- item->set_text(0, "Gershwin!");
-
- frame->add_child(tree);
-
- LineEdit *line_edit = memnew(LineEdit);
-
- line_edit->set_position(Point2(30, 190));
- line_edit->set_size(Point2(180, 1));
-
- frame->add_child(line_edit);
-
- HScrollBar *hscroll = memnew(HScrollBar);
-
- hscroll->set_position(Point2(30, 290));
- hscroll->set_size(Point2(180, 1));
- hscroll->set_max(10);
- hscroll->set_page(4);
-
- frame->add_child(hscroll);
-
- SpinBox *spin = memnew(SpinBox);
-
- spin->set_position(Point2(30, 260));
- spin->set_size(Point2(120, 1));
-
- frame->add_child(spin);
- hscroll->share(spin);
-
- ProgressBar *progress = memnew(ProgressBar);
-
- progress->set_position(Point2(30, 330));
- progress->set_size(Point2(120, 1));
-
- frame->add_child(progress);
- hscroll->share(progress);
-
- MenuButton *menu_button = memnew(MenuButton);
-
- menu_button->set_text("I'm a menu!");
- menu_button->set_position(Point2(30, 380));
- menu_button->set_size(Point2(1, 1));
-
- frame->add_child(menu_button);
-
- PopupMenu *popup = menu_button->get_popup();
-
- popup->add_item("Hello, testing");
- popup->add_item("My Dearest");
- popup->add_separator();
- popup->add_item("Popup");
- popup->add_check_item("Check Popup");
- popup->set_item_checked(4, true);
- popup->add_separator();
- popup->add_radio_check_item("Option A");
- popup->set_item_checked(6, true);
- popup->add_radio_check_item("Option B");
-
- OptionButton *options = memnew(OptionButton);
-
- options->add_item("Hello, testing");
- options->add_item("My Dearest");
-
- options->set_position(Point2(230, 180));
- options->set_size(Point2(1, 1));
-
- frame->add_child(options);
-
- RichTextLabel *richtext = memnew(RichTextLabel);
-
- richtext->set_position(Point2(600, 210));
- richtext->set_size(Point2(180, 250));
- richtext->set_anchor_and_offset(SIDE_RIGHT, Control::ANCHOR_END, -20);
-
- frame->add_child(richtext);
-
- richtext->add_text("Hello, My Friends!\n\nWelcome to the amazing world of ");
-
- richtext->add_newline();
- richtext->add_newline();
-
- richtext->push_color(Color(1, 0.5, 0.5));
- richtext->add_text("leprechauns");
- richtext->pop();
-
- richtext->add_text(" and ");
- richtext->push_color(Color(0, 1.0, 0.5));
- richtext->add_text("faeries.\n");
- richtext->pop();
- richtext->add_text("In this new episode, we will attempt to ");
- richtext->push_font(richtext->get_theme_font(SNAME("mono_font"), SNAME("Fonts")));
- richtext->push_color(Color(0.7, 0.5, 1.0));
- richtext->add_text("deliver something nice");
- richtext->pop();
- richtext->pop();
- richtext->add_text(" to all the viewers! Unfortunately, I need to ");
- richtext->push_underline();
- richtext->add_text("keep writing a lot of text");
- richtext->pop();
- richtext->add_text(" so the label control overflows and the scrollbar appears.\n");
- richtext->push_meta("http://www.scrollingcapabilities.xz");
- richtext->add_text("This allows to test for the scrolling capabilities ");
- richtext->pop();
- richtext->add_text("of the rich text label for huge text (not like this text will really be huge but, you know).\nAs long as it is so long that it will work nicely for a test/demo, then it's welcomed in my book...\nChanging subject, the day is cloudy today and I'm wondering if I'll get che chance to travel somewhere nice. Sometimes, watching the clouds from satellite images may give a nice insight about how pressure zones in our planet work, although it also makes it pretty obvious to see why most weather forecasts get it wrong so often.\nClouds are so difficult to predict!\nBut it's pretty cool how our civilization has adapted to having water falling from the sky each time it rains...");
-
- TabContainer *tabc = memnew(TabContainer);
-
- Control *ctl = memnew(Control);
- ctl->set_name("tab 1");
- tabc->add_child(ctl);
-
- ctl = memnew(Control);
- ctl->set_name("tab 2");
- tabc->add_child(ctl);
- label = memnew(Label);
- label->set_text("Some Label");
- label->set_position(Point2(20, 20));
- ctl->add_child(label);
-
- ctl = memnew(Control);
- ctl->set_name("tab 3");
- button = memnew(Button);
- button->set_text("Some Button");
- button->set_position(Point2(30, 50));
- ctl->add_child(button);
-
- tabc->add_child(ctl);
-
- frame->add_child(tabc);
-
- tabc->set_position(Point2(400, 210));
- tabc->set_size(Point2(180, 250));
- }
-};
-
-MainLoop *test() {
- return memnew(TestMainLoop);
-}
-} // namespace TestGUI
-
-#endif // _3D_DISABLED
diff --git a/tests/scene/test_gui.h b/tests/scene/test_gui.h
deleted file mode 100644
index 84bce620e2..0000000000
--- a/tests/scene/test_gui.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*************************************************************************/
-/* test_gui.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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_GUI_H
-#define TEST_GUI_H
-
-class MainLoop;
-
-namespace TestGUI {
-
-MainLoop *test();
-}
-
-#endif
diff --git a/tests/scene/test_path_3d.h b/tests/scene/test_path_3d.h
index 1fcef3adde..8ac3d7b5b4 100644
--- a/tests/scene/test_path_3d.h
+++ b/tests/scene/test_path_3d.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -81,4 +81,4 @@ TEST_CASE("[Path3D] Curve setter and getter") {
} // namespace TestPath3D
-#endif // TEST_PATH_3D
+#endif // TEST_PATH_3D_H
diff --git a/tests/scene/test_path_follow_2d.h b/tests/scene/test_path_follow_2d.h
index ddfcc5552a..abd12fe862 100644
--- a/tests/scene/test_path_follow_2d.h
+++ b/tests/scene/test_path_follow_2d.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/scene/test_path_follow_3d.h b/tests/scene/test_path_follow_3d.h
index 6a505dbb39..9ffe49e3d6 100644
--- a/tests/scene/test_path_follow_3d.h
+++ b/tests/scene/test_path_follow_3d.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/scene/test_text_edit.h b/tests/scene/test_text_edit.h
new file mode 100644
index 0000000000..0fce359c5a
--- /dev/null
+++ b/tests/scene/test_text_edit.h
@@ -0,0 +1,3528 @@
+/*************************************************************************/
+/* test_text_edit.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_TEXT_EDIT_H
+#define TEST_TEXT_EDIT_H
+
+#include "scene/gui/text_edit.h"
+
+#include "tests/test_macros.h"
+
+namespace TestTextEdit {
+
+TEST_CASE("[SceneTree][TextEdit] text entry") {
+ TextEdit *text_edit = memnew(TextEdit);
+ SceneTree::get_singleton()->get_root()->add_child(text_edit);
+ text_edit->grab_focus();
+
+ Array empty_signal_args;
+ empty_signal_args.push_back(Array());
+
+ SUBCASE("[TextEdit] text entry") {
+ SIGNAL_WATCH(text_edit, "text_set");
+ SIGNAL_WATCH(text_edit, "text_changed");
+ SIGNAL_WATCH(text_edit, "lines_edited_from");
+ SIGNAL_WATCH(text_edit, "caret_changed");
+
+ Array args1;
+ args1.push_back(0);
+ args1.push_back(0);
+ Array lines_edited_args;
+ lines_edited_args.push_back(args1);
+ lines_edited_args.push_back(args1.duplicate());
+
+ SUBCASE("[TextEdit] clear and set text") {
+ // "text_changed" should not be emitted on clear / set.
+ text_edit->clear();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "");
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK(text_edit->get_line_count() == 1);
+ SIGNAL_CHECK("text_set", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+
+ text_edit->set_text("test text");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "test text");
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK(text_edit->get_line_count() == 1);
+ SIGNAL_CHECK("text_set", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+
+ text_edit->clear();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "");
+ CHECK(text_edit->get_caret_column() == 0);
+ SIGNAL_CHECK("text_set", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+
+ // Can undo / redo words when editable.
+ text_edit->undo();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "test text");
+ CHECK(text_edit->get_caret_column() == 9);
+ 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("text_set");
+
+ text_edit->redo();
+ MessageQueue::get_singleton()->flush();
+ 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("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);
+ 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("text_set");
+
+ // Clear.
+ text_edit->set_editable(false);
+
+ Array lines_edited_clear_args;
+ Array new_args = args1.duplicate();
+ new_args[0] = 1;
+ lines_edited_clear_args.push_back(new_args);
+
+ text_edit->clear();
+ MessageQueue::get_singleton()->flush();
+ 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("text_changed");
+
+ text_edit->set_editable(true);
+
+ text_edit->undo();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "");
+ CHECK(text_edit->get_caret_column() == 0);
+ SIGNAL_CHECK_FALSE("text_set");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("caret_changed");
+
+ // Can still undo set_text.
+ text_edit->set_editable(false);
+
+ text_edit->set_text("test text");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "test text");
+ CHECK(text_edit->get_caret_column() == 0);
+ SIGNAL_CHECK("text_set", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+
+ text_edit->set_editable(true);
+
+ text_edit->undo();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "");
+ CHECK(text_edit->get_caret_column() == 0);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_set");
+
+ // Any selections are removed.
+ text_edit->set_text("test text");
+ MessageQueue::get_singleton()->flush();
+ text_edit->select_all();
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "test text");
+ CHECK(text_edit->get_caret_column() == 9);
+ CHECK(text_edit->has_selection());
+ SIGNAL_CHECK("text_set", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+
+ text_edit->set_text("test");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "test");
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK("text_set", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+
+ text_edit->select_all();
+ MessageQueue::get_singleton()->flush();
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ CHECK(text_edit->has_selection());
+
+ text_edit->clear();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "");
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK("text_set", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ }
+
+ SUBCASE("[TextEdit] set and get line") {
+ // Set / Get line is 0 indexed.
+ text_edit->set_line(1, "test");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ SIGNAL_CHECK_FALSE("text_set");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("caret_changed");
+
+ text_edit->set_line(0, "test");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "test");
+ CHECK(text_edit->get_line(0) == "test");
+ CHECK(text_edit->get_line(1) == "");
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_set");
+ SIGNAL_CHECK_FALSE("caret_changed");
+
+ // Setting to a longer line, caret and selections should be preserved.
+ text_edit->select_all();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->has_selection());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+
+ text_edit->set_line(0, "test text");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_line(0) == "test text");
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "test");
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_set");
+
+ // Setting to a shorter line, selection and caret should be adjusted. Also works if not editable.
+ text_edit->set_editable(false);
+ text_edit->set_line(0, "te");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_line(0) == "te");
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "te");
+ 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("text_set");
+ text_edit->set_editable(true);
+
+ // Undo / redo should work.
+ text_edit->undo();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_line(0) == "test text");
+ 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);
+ SIGNAL_CHECK_FALSE("text_set");
+
+ text_edit->redo();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_line(0) == "te");
+ CHECK_FALSE(text_edit->has_selection()); // Currently not handled.
+ 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("text_set");
+
+ // Out of range.
+ ERR_PRINT_OFF;
+ text_edit->set_line(-1, "test");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_line(0) == "te");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("text_set");
+
+ text_edit->set_line(1, "test");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_line(0) == "te");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("text_set");
+
+ ERR_PRINT_ON;
+ }
+
+ SUBCASE("[TextEdit] swap lines") {
+ ((Array)lines_edited_args[1])[1] = 1;
+
+ text_edit->set_text("testing\nswap");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "testing\nswap");
+ SIGNAL_CHECK("text_set", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+
+ text_edit->set_caret_column(text_edit->get_line(0).length());
+ MessageQueue::get_singleton()->flush();
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+
+ ((Array)lines_edited_args[1])[1] = 0;
+ Array swap_args;
+ swap_args.push_back(1);
+ swap_args.push_back(1);
+ lines_edited_args.push_back(swap_args);
+ lines_edited_args.push_back(swap_args);
+
+ // Order does not matter. Should also work if not editable.
+ text_edit->set_editable(false);
+ text_edit->swap_lines(1, 0);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "swap\ntesting");
+ 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("text_set");
+ text_edit->set_editable(true);
+
+ lines_edited_args.reverse();
+
+ // Single undo/redo action
+ text_edit->undo();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "testing\nswap");
+ 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("text_set");
+
+ lines_edited_args.reverse();
+
+ text_edit->redo();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "swap\ntesting");
+ 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("text_set");
+
+ // Out of range.
+ ERR_PRINT_OFF;
+ text_edit->swap_lines(-1, 0);
+ CHECK(text_edit->get_text() == "swap\ntesting");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("text_set");
+
+ text_edit->swap_lines(0, -1);
+ CHECK(text_edit->get_text() == "swap\ntesting");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("text_set");
+
+ text_edit->swap_lines(2, 0);
+ CHECK(text_edit->get_text() == "swap\ntesting");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("text_set");
+
+ text_edit->swap_lines(0, 2);
+ CHECK(text_edit->get_text() == "swap\ntesting");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("text_set");
+ ERR_PRINT_ON;
+ }
+
+ SUBCASE("[TextEdit] insert line at") {
+ ((Array)lines_edited_args[1])[1] = 1;
+
+ text_edit->set_text("testing\nswap");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "testing\nswap");
+ SIGNAL_CHECK("text_set", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+
+ text_edit->select_all();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selection_from_line() == 0);
+ CHECK(text_edit->get_selection_to_line() == 1);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+
+ // insert before should move caret and selecion, and works when not editable.
+ text_edit->set_editable(false);
+ lines_edited_args.remove_at(0);
+ text_edit->insert_line_at(0, "new");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "new\ntesting\nswap");
+ CHECK(text_edit->get_caret_line() == 2);
+ CHECK(text_edit->get_caret_column() == text_edit->get_line(2).size() - 1);
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selection_from_line() == 1);
+ CHECK(text_edit->get_selection_to_line() == 2);
+ 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("text_set");
+ text_edit->set_editable(true);
+
+ // can undo/redo as single action
+ ((Array)lines_edited_args[0])[0] = 1;
+ ((Array)lines_edited_args[0])[1] = 0;
+ text_edit->undo();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "testing\nswap");
+ CHECK_FALSE(text_edit->has_selection()); // Not currently handled.
+ 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("text_set");
+
+ ((Array)lines_edited_args[0])[0] = 0;
+ ((Array)lines_edited_args[0])[1] = 1;
+ text_edit->redo();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "new\ntesting\nswap");
+ CHECK_FALSE(text_edit->has_selection()); // Not currently handled.
+ 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("text_set");
+
+ // Adding inside selection extends selection.
+ text_edit->select_all();
+ MessageQueue::get_singleton()->flush();
+ 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);
+
+ ((Array)lines_edited_args[0])[0] = 2;
+ ((Array)lines_edited_args[0])[1] = 3;
+ text_edit->insert_line_at(2, "after");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "new\ntesting\nafter\nswap");
+ CHECK(text_edit->get_caret_line() == 3);
+ CHECK(text_edit->get_caret_column() == text_edit->get_line(3).size() - 1);
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selection_from_line() == 0);
+ CHECK(text_edit->get_selection_to_line() == 3);
+ 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("text_set");
+
+ // Out of range.
+ ERR_PRINT_OFF;
+ text_edit->insert_line_at(-1, "after");
+ CHECK(text_edit->get_text() == "new\ntesting\nafter\nswap");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("text_set");
+
+ text_edit->insert_line_at(4, "after");
+ CHECK(text_edit->get_text() == "new\ntesting\nafter\nswap");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("text_set");
+ ERR_PRINT_ON;
+ }
+
+ SUBCASE("[TextEdit] insert line at caret") {
+ lines_edited_args.pop_back();
+ ((Array)lines_edited_args[0])[1] = 1;
+
+ text_edit->insert_text_at_caret("testing\nswap");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "testing\nswap");
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == text_edit->get_line(1).size() - 1);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_set");
+
+ text_edit->set_caret_line(0, false);
+ text_edit->set_caret_column(2);
+ SIGNAL_DISCARD("caret_changed");
+
+ ((Array)lines_edited_args[0])[1] = 0;
+ text_edit->insert_text_at_caret("mid");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "temidsting\nswap");
+ CHECK(text_edit->get_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 5);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_set");
+
+ text_edit->select(0, 0, 0, text_edit->get_line(0).length());
+ CHECK(text_edit->has_selection());
+ lines_edited_args.push_back(args1.duplicate());
+
+ text_edit->set_editable(false);
+ text_edit->insert_text_at_caret("new line");
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "new line\nswap");
+ CHECK(text_edit->get_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == text_edit->get_line(0).size() - 1);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_set");
+ text_edit->set_editable(true);
+
+ text_edit->undo();
+ 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->has_selection());
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_set");
+
+ text_edit->redo();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "new line\nswap");
+ CHECK(text_edit->get_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 8);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_set");
+ }
+
+ SIGNAL_UNWATCH(text_edit, "text_set");
+ SIGNAL_UNWATCH(text_edit, "text_changed");
+ SIGNAL_UNWATCH(text_edit, "lines_edited_from");
+ SIGNAL_UNWATCH(text_edit, "caret_changed");
+ }
+
+ SUBCASE("[TextEdit] indent level") {
+ CHECK(text_edit->get_indent_level(0) == 0);
+ CHECK(text_edit->get_first_non_whitespace_column(0) == 0);
+
+ text_edit->set_line(0, "a");
+ CHECK(text_edit->get_indent_level(0) == 0);
+ CHECK(text_edit->get_first_non_whitespace_column(0) == 0);
+
+ text_edit->set_line(0, "\t");
+ CHECK(text_edit->get_indent_level(0) == 4);
+ CHECK(text_edit->get_first_non_whitespace_column(0) == 1);
+
+ text_edit->set_tab_size(8);
+ CHECK(text_edit->get_indent_level(0) == 8);
+
+ text_edit->set_line(0, "\t a");
+ CHECK(text_edit->get_first_non_whitespace_column(0) == 2);
+ CHECK(text_edit->get_indent_level(0) == 9);
+ }
+
+ SUBCASE("[TextEdit] selection") {
+ SIGNAL_WATCH(text_edit, "text_set");
+ SIGNAL_WATCH(text_edit, "text_changed");
+ SIGNAL_WATCH(text_edit, "lines_edited_from");
+ SIGNAL_WATCH(text_edit, "caret_changed");
+
+ Array args1;
+ args1.push_back(0);
+ args1.push_back(0);
+ Array lines_edited_args;
+ lines_edited_args.push_back(args1);
+ lines_edited_args.push_back(args1.duplicate());
+
+ SUBCASE("[TextEdit] select all") {
+ text_edit->select_all();
+ CHECK_FALSE(text_edit->has_selection());
+ ERR_PRINT_OFF;
+ CHECK(text_edit->get_selection_from_line() == -1);
+ CHECK(text_edit->get_selection_from_column() == -1);
+ CHECK(text_edit->get_selection_to_line() == -1);
+ CHECK(text_edit->get_selection_to_column() == -1);
+ CHECK(text_edit->get_selected_text() == "");
+ ERR_PRINT_ON;
+
+ text_edit->set_text("test\nselection");
+ SEND_GUI_ACTION(text_edit, "ui_text_select_all");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_selected_text() == "test\nselection");
+ 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() == 1);
+ CHECK(text_edit->get_selection_to_column() == 9);
+ CHECK(text_edit->get_selection_mode() == TextEdit::SelectionMode::SELECTION_MODE_SHIFT);
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 9);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+
+ text_edit->set_caret_line(0);
+ text_edit->set_caret_column(0);
+ text_edit->set_selecting_enabled(false);
+ 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() == 0);
+
+ text_edit->select_all();
+ 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() == 0);
+ }
+
+ SUBCASE("[TextEdit] select word under caret") {
+ text_edit->set_text("test test");
+ text_edit->set_caret_column(0);
+ 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);
+
+ text_edit->select_word_under_caret();
+ CHECK_FALSE(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "");
+
+ 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);
+ 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);
+ 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->select_word_under_caret();
+ CHECK_FALSE(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "");
+
+ 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);
+ SIGNAL_CHECK_FALSE("caret_changed");
+ }
+
+ SUBCASE("[TextEdit] deselect on focus loss") {
+ text_edit->set_text("test");
+
+ text_edit->set_deselect_on_focus_loss_enabled(true);
+ CHECK(text_edit->is_deselect_on_focus_loss_enabled());
+
+ text_edit->grab_focus();
+ text_edit->select_all();
+ CHECK(text_edit->has_focus());
+ CHECK(text_edit->has_selection());
+
+ text_edit->release_focus();
+ CHECK_FALSE(text_edit->has_focus());
+ CHECK_FALSE(text_edit->has_selection());
+
+ text_edit->set_deselect_on_focus_loss_enabled(false);
+ CHECK_FALSE(text_edit->is_deselect_on_focus_loss_enabled());
+
+ text_edit->grab_focus();
+ text_edit->select_all();
+ CHECK(text_edit->has_focus());
+ CHECK(text_edit->has_selection());
+
+ text_edit->release_focus();
+ CHECK_FALSE(text_edit->has_focus());
+ CHECK(text_edit->has_selection());
+
+ text_edit->set_deselect_on_focus_loss_enabled(true);
+ CHECK_FALSE(text_edit->has_selection());
+ }
+
+ SUBCASE("[TextEdit] key select") {
+ text_edit->set_text("test");
+
+ text_edit->grab_focus();
+ SEND_GUI_KEY_EVENT(text_edit, Key::RIGHT | KeyModifierMask::SHIFT)
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "t");
+
+#ifdef MACOS_ENABLED
+ SEND_GUI_KEY_EVENT(text_edit, Key::RIGHT | KeyModifierMask::SHIFT | KeyModifierMask::ALT)
+#else
+ SEND_GUI_KEY_EVENT(text_edit, Key::RIGHT | KeyModifierMask::SHIFT | KeyModifierMask::CMD)
+#endif
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "test");
+
+ SEND_GUI_KEY_EVENT(text_edit, Key::LEFT | KeyModifierMask::SHIFT)
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "tes");
+
+#ifdef MACOS_ENABLED
+ SEND_GUI_KEY_EVENT(text_edit, Key::LEFT | KeyModifierMask::SHIFT | KeyModifierMask::ALT)
+#else
+ SEND_GUI_KEY_EVENT(text_edit, Key::LEFT | KeyModifierMask::SHIFT | KeyModifierMask::CMD)
+#endif
+ CHECK_FALSE(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "");
+
+ SEND_GUI_KEY_EVENT(text_edit, Key::RIGHT | KeyModifierMask::SHIFT)
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "t");
+
+ SEND_GUI_KEY_EVENT(text_edit, Key::RIGHT)
+ CHECK_FALSE(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "");
+
+ SEND_GUI_KEY_EVENT(text_edit, Key::LEFT | KeyModifierMask::SHIFT)
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "t");
+
+ SEND_GUI_KEY_EVENT(text_edit, Key::LEFT)
+ CHECK_FALSE(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "");
+
+ text_edit->set_selecting_enabled(false);
+ SEND_GUI_KEY_EVENT(text_edit, Key::RIGHT | KeyModifierMask::SHIFT)
+ CHECK_FALSE(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "");
+ text_edit->set_selecting_enabled(true);
+ }
+
+ SUBCASE("[TextEdit] mouse drag select") {
+ /* Set size for mouse input. */
+ text_edit->set_size(Size2(200, 200));
+
+ text_edit->set_text("this is some text\nfor selection");
+ text_edit->grab_focus();
+ MessageQueue::get_singleton()->flush();
+
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 1), MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE);
+ SEND_GUI_MOUSE_MOTION_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 7), MouseButton::MASK_LEFT, Key::NONE);
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "for s");
+ CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
+ CHECK(text_edit->get_selection_from_line() == 1);
+ CHECK(text_edit->get_selection_from_column() == 0);
+ CHECK(text_edit->get_selection_to_line() == 1);
+ CHECK(text_edit->get_selection_to_column() == 5);
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 5);
+
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 9), MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE);
+ CHECK_FALSE(text_edit->has_selection());
+
+ text_edit->set_selecting_enabled(false);
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 1), MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE);
+ SEND_GUI_MOUSE_MOTION_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 7), MouseButton::MASK_LEFT, Key::NONE);
+ CHECK_FALSE(text_edit->has_selection());
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 5);
+ text_edit->set_selecting_enabled(true);
+ }
+
+ SUBCASE("[TextEdit] mouse word select") {
+ /* Set size for mouse input. */
+ text_edit->set_size(Size2(200, 200));
+
+ text_edit->set_text("this is some text\nfor selection");
+ MessageQueue::get_singleton()->flush();
+ SIGNAL_DISCARD("caret_changed");
+
+ SEND_GUI_DOUBLE_CLICK(text_edit, text_edit->get_pos_at_line_column(0, 2), Key::NONE);
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "for");
+ CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
+ CHECK(text_edit->get_selection_from_line() == 1);
+ CHECK(text_edit->get_selection_from_column() == 0);
+ CHECK(text_edit->get_selection_to_line() == 1);
+ CHECK(text_edit->get_selection_to_column() == 3);
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 3);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+
+ SEND_GUI_MOUSE_MOTION_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 7), MouseButton::MASK_LEFT, Key::NONE);
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "for selection");
+ CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_WORD);
+ CHECK(text_edit->get_selection_from_line() == 1);
+ CHECK(text_edit->get_selection_from_column() == 0);
+ CHECK(text_edit->get_selection_to_line() == 1);
+ CHECK(text_edit->get_selection_to_column() == 13);
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 13);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+
+ Point2i line_0 = text_edit->get_pos_at_line_column(0, 0);
+ line_0.y /= 2;
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, line_0, MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE);
+ CHECK_FALSE(text_edit->has_selection());
+
+ text_edit->set_selecting_enabled(false);
+ SEND_GUI_DOUBLE_CLICK(text_edit, text_edit->get_pos_at_line_column(0, 2), Key::NONE);
+ CHECK_FALSE(text_edit->has_selection());
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 3);
+ text_edit->set_selecting_enabled(true);
+ }
+
+ SUBCASE("[TextEdit] mouse line select") {
+ /* Set size for mouse input. */
+ text_edit->set_size(Size2(200, 200));
+
+ text_edit->set_text("this is some text\nfor selection");
+ MessageQueue::get_singleton()->flush();
+
+ SEND_GUI_DOUBLE_CLICK(text_edit, text_edit->get_pos_at_line_column(0, 2), Key::NONE);
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 2), MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE);
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "for selection");
+ CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_LINE);
+ CHECK(text_edit->get_selection_from_line() == 1);
+ CHECK(text_edit->get_selection_from_column() == 0);
+ CHECK(text_edit->get_selection_to_line() == 1);
+ CHECK(text_edit->get_selection_to_column() == 13);
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 0);
+
+ Point2i line_0 = text_edit->get_pos_at_line_column(0, 0);
+ line_0.y /= 2;
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, line_0, MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE);
+ CHECK_FALSE(text_edit->has_selection());
+
+ text_edit->set_selecting_enabled(false);
+ SEND_GUI_DOUBLE_CLICK(text_edit, text_edit->get_pos_at_line_column(0, 2), Key::NONE);
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 2), MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE);
+ CHECK_FALSE(text_edit->has_selection());
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 0);
+ text_edit->set_selecting_enabled(true);
+ }
+
+ SUBCASE("[TextEdit] mouse shift click select") {
+ /* Set size for mouse input. */
+ text_edit->set_size(Size2(200, 200));
+
+ text_edit->set_text("this is some text\nfor selection");
+ MessageQueue::get_singleton()->flush();
+
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 0), MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE);
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 7), MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE | KeyModifierMask::SHIFT);
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "for s");
+ CHECK(text_edit->get_selection_mode() == TextEdit::SELECTION_MODE_POINTER);
+ CHECK(text_edit->get_selection_from_line() == 1);
+ CHECK(text_edit->get_selection_from_column() == 0);
+ CHECK(text_edit->get_selection_to_line() == 1);
+ CHECK(text_edit->get_selection_to_column() == 5);
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 5);
+
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 9), MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE);
+ CHECK_FALSE(text_edit->has_selection());
+
+ text_edit->set_selecting_enabled(false);
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 0), MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE);
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 7), MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE | KeyModifierMask::SHIFT);
+ CHECK_FALSE(text_edit->has_selection());
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 5);
+ text_edit->set_selecting_enabled(true);
+ }
+
+ SUBCASE("[TextEdit] select and deselect") {
+ text_edit->set_text("this is some text\nfor selection");
+ MessageQueue::get_singleton()->flush();
+
+ text_edit->select(-1, -1, 500, 500);
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "this is some text\nfor selection");
+
+ text_edit->deselect();
+ CHECK_FALSE(text_edit->has_selection());
+
+ text_edit->select(500, 500, -1, -1);
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == "this is some text\nfor selection");
+
+ text_edit->deselect();
+ CHECK_FALSE(text_edit->has_selection());
+
+ text_edit->select(0, 4, 0, 8);
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == " is ");
+
+ text_edit->deselect();
+ CHECK_FALSE(text_edit->has_selection());
+
+ text_edit->select(0, 8, 0, 4);
+ CHECK(text_edit->has_selection());
+ CHECK(text_edit->get_selected_text() == " is ");
+
+ text_edit->set_selecting_enabled(false);
+ CHECK_FALSE(text_edit->has_selection());
+ text_edit->select(0, 8, 0, 4);
+ CHECK_FALSE(text_edit->has_selection());
+ text_edit->set_selecting_enabled(true);
+
+ text_edit->select(0, 8, 0, 4);
+ CHECK(text_edit->has_selection());
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_right");
+ CHECK_FALSE(text_edit->has_selection());
+
+ text_edit->delete_selection();
+ CHECK(text_edit->get_text() == "this is some text\nfor selection");
+
+ 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");
+
+ text_edit->undo();
+ CHECK(text_edit->has_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->redo();
+ 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);
+
+ text_edit->undo();
+ CHECK(text_edit->has_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());
+
+ text_edit->delete_selection();
+ CHECK_FALSE(text_edit->has_selection());
+ CHECK(text_edit->get_text() == "thissome text\nfor selection");
+
+ text_edit->undo();
+ CHECK(text_edit->has_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->redo();
+ 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);
+
+ text_edit->undo();
+ CHECK(text_edit->has_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->set_editable(false);
+ text_edit->delete_selection();
+ text_edit->set_editable(false);
+ CHECK_FALSE(text_edit->has_selection());
+ CHECK(text_edit->get_text() == "thissome text\nfor selection");
+
+ text_edit->undo();
+ CHECK_FALSE(text_edit->has_selection());
+ CHECK(text_edit->get_text() == "thissome text\nfor selection");
+ }
+
+ // Add readonly test?
+ SUBCASE("[TextEdit] text drag") {
+ TextEdit *target_text_edit = memnew(TextEdit);
+ SceneTree::get_singleton()->get_root()->add_child(target_text_edit);
+ text_edit->get_viewport()->set_embedding_subwindows(true); // Bypass display server for drop handling.
+
+ target_text_edit->set_size(Size2(200, 200));
+ target_text_edit->set_position(Point2(400, 0));
+
+ text_edit->set_size(Size2(200, 200));
+
+ CHECK_FALSE(text_edit->is_mouse_over_selection());
+ text_edit->set_text("drag me");
+ text_edit->select_all();
+ text_edit->grab_click_focus();
+ MessageQueue::get_singleton()->flush();
+
+ Point2i line_0 = text_edit->get_pos_at_line_column(0, 0);
+ line_0.y /= 2;
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, line_0, MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE);
+ CHECK(text_edit->is_mouse_over_selection());
+ SEND_GUI_MOUSE_MOTION_EVENT(text_edit, text_edit->get_pos_at_line_column(0, 7), MouseButton::MASK_LEFT, Key::NONE);
+ CHECK(text_edit->get_viewport()->gui_is_dragging());
+ CHECK(text_edit->get_viewport()->gui_get_drag_data() == "drag me");
+
+ line_0 = target_text_edit->get_pos_at_line_column(0, 0);
+ line_0.y /= 2;
+ line_0.x += 401; // As empty add one.
+ SEND_GUI_MOUSE_MOTION_EVENT(target_text_edit, line_0, MouseButton::MASK_LEFT, Key::NONE);
+ CHECK(text_edit->get_viewport()->gui_is_dragging());
+
+ SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(target_text_edit, line_0, MouseButton::LEFT, MouseButton::MASK_LEFT, Key::NONE);
+
+ CHECK_FALSE(text_edit->get_viewport()->gui_is_dragging());
+ CHECK(text_edit->get_text() == "");
+ CHECK(target_text_edit->get_text() == "drag me");
+
+ memdelete(target_text_edit);
+ }
+
+ SIGNAL_UNWATCH(text_edit, "text_set");
+ SIGNAL_UNWATCH(text_edit, "text_changed");
+ SIGNAL_UNWATCH(text_edit, "lines_edited_from");
+ SIGNAL_UNWATCH(text_edit, "caret_changed");
+ }
+
+ SUBCASE("[TextEdit] overridable actions") {
+ SIGNAL_WATCH(text_edit, "text_set");
+ SIGNAL_WATCH(text_edit, "text_changed");
+ SIGNAL_WATCH(text_edit, "lines_edited_from");
+ SIGNAL_WATCH(text_edit, "caret_changed");
+
+ Array args1;
+ args1.push_back(0);
+ args1.push_back(0);
+ Array lines_edited_args;
+ lines_edited_args.push_back(args1);
+
+ SUBCASE("[TextEdit] backspace") {
+ text_edit->set_text("this is\nsome\n");
+ text_edit->set_caret_line(0);
+ text_edit->set_caret_column(0);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ text_edit->backspace();
+ MessageQueue::get_singleton()->flush();
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ text_edit->set_caret_line(2);
+ text_edit->set_caret_column(0);
+ MessageQueue::get_singleton()->flush();
+ SIGNAL_DISCARD("caret_changed");
+
+ ((Array)lines_edited_args[0])[0] = 2;
+ ((Array)lines_edited_args[0])[1] = 1;
+ text_edit->backspace();
+ MessageQueue::get_singleton()->flush();
+
+ CHECK(text_edit->get_text() == "this is\nsome");
+ CHECK(text_edit->get_caret_line() == 1);
+ 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);
+
+ ((Array)lines_edited_args[0])[0] = 1;
+ text_edit->backspace();
+ MessageQueue::get_singleton()->flush();
+
+ CHECK(text_edit->get_text() == "this is\nsom");
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 3);
+ 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();
+ text_edit->select(1, 0, 1, 3);
+ text_edit->backspace();
+ MessageQueue::get_singleton()->flush();
+
+ CHECK(text_edit->get_text() == "this is\n");
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 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->set_editable(false);
+ text_edit->backspace();
+ text_edit->set_editable(true);
+ MessageQueue::get_singleton()->flush();
+
+ CHECK(text_edit->get_text() == "this is\n");
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 0);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ text_edit->undo();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_text() == "this is\nsom");
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 3);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ }
+
+ SUBCASE("[TextEdit] cut") {
+ 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");
+
+ ERR_PRINT_OFF;
+ text_edit->cut();
+ MessageQueue::get_singleton()->flush();
+ ERR_PRINT_ON; // Can't check display server content.
+
+ ((Array)lines_edited_args[0])[0] = 1;
+ CHECK(text_edit->get_text() == "some\n");
+ 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);
+
+ ((Array)lines_edited_args[0])[0] = 0;
+ ((Array)lines_edited_args[0])[1] = 1;
+ 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);
+ 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] = 1;
+ ((Array)lines_edited_args[0])[1] = 0;
+ 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");
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+
+ text_edit->set_text("this is\nsome\n");
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ ((Array)lines_edited_args[0])[0] = 0;
+ text_edit->select(0, 5, 0, 7);
+ ERR_PRINT_OFF;
+ SEND_GUI_ACTION(text_edit, "ui_cut");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ MessageQueue::get_singleton()->flush();
+ ERR_PRINT_ON; // Can't check display server content.
+ CHECK(text_edit->get_text() == "this \nsome\n");
+ CHECK(text_edit->get_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 5);
+ 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_editable(false);
+ text_edit->cut();
+ MessageQueue::get_singleton()->flush();
+ text_edit->set_editable(true);
+ CHECK(text_edit->get_text() == "this \nsome\n");
+ CHECK(text_edit->get_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 5);
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ }
+
+ SUBCASE("[TextEdit] copy") {
+ // TODO: Cannot test need display server support.
+ }
+
+ SUBCASE("[TextEdit] paste") {
+ // TODO: Cannot test need display server support.
+ }
+
+ SUBCASE("[TextEdit] paste primary") {
+ // TODO: Cannot test need display server support.
+ }
+
+ SIGNAL_UNWATCH(text_edit, "text_set");
+ SIGNAL_UNWATCH(text_edit, "text_changed");
+ SIGNAL_UNWATCH(text_edit, "lines_edited_from");
+ SIGNAL_UNWATCH(text_edit, "caret_changed");
+ }
+
+ // Add undo / redo tests?
+ SUBCASE("[TextEdit] input") {
+ SIGNAL_WATCH(text_edit, "text_set");
+ SIGNAL_WATCH(text_edit, "text_changed");
+ SIGNAL_WATCH(text_edit, "lines_edited_from");
+ SIGNAL_WATCH(text_edit, "caret_changed");
+
+ Array args1;
+ args1.push_back(0);
+ args1.push_back(0);
+ Array lines_edited_args;
+ lines_edited_args.push_back(args1);
+
+ SUBCASE("[TextEdit] ui_text_newline_above") {
+ text_edit->set_text("this is some test text.");
+ text_edit->select(0, 0, 0, 4);
+ text_edit->set_caret_column(4);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ ((Array)lines_edited_args[0])[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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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);
+ 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_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 4);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ text_edit->set_editable(true);
+
+ 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_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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->select(0, 0, 0, 4);
+ text_edit->set_caret_column(4);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ ((Array)lines_edited_args[0])[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_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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_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_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ text_edit->set_editable(true);
+ }
+
+ SUBCASE("[TextEdit] ui_text_newline") {
+ text_edit->set_text("this is some test text.");
+ text_edit->select(0, 0, 0, 4);
+ text_edit->set_caret_column(4);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ 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;
+ 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_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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_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_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ text_edit->set_editable(true);
+ }
+
+ SUBCASE("[TextEdit] ui_text_backspace_all_to_left") {
+ text_edit->set_text("\nthis is some test text.");
+ text_edit->select(1, 0, 1, 4);
+ text_edit->set_caret_line(1);
+ text_edit->set_caret_column(4);
+ MessageQueue::get_singleton()->flush();
+
+ Ref<InputEvent> tmpevent = InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::ALT | KeyModifierMask::CMD);
+ InputMap::get_singleton()->action_add_event("ui_text_backspace_all_to_left", tmpevent);
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ // With selection should be a normal backspace.
+ ((Array)lines_edited_args[0])[0] = 1;
+ ((Array)lines_edited_args[0])[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_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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;
+
+ // 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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());
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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_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");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ text_edit->set_editable(true);
+
+ ((Array)lines_edited_args[0])[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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+
+ InputMap::get_singleton()->action_erase_event("ui_text_backspace_all_to_left", tmpevent);
+ }
+
+ SUBCASE("[TextEdit] ui_text_backspace_word") {
+ text_edit->set_text("\nthis is some test text.");
+ text_edit->select(1, 0, 1, 4);
+ text_edit->set_caret_line(1);
+ text_edit->set_caret_column(4);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ // With selection should be a normal backspace.
+ ((Array)lines_edited_args[0])[0] = 1;
+ ((Array)lines_edited_args[0])[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_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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;
+
+ // 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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_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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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());
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ ((Array)lines_edited_args[0])[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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 14);
+ CHECK_FALSE(text_edit->has_selection());
+ 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->select(1, 0, 1, 4);
+ text_edit->set_caret_line(1);
+ text_edit->set_caret_column(4);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ // With selection should be a normal backspace.
+ ((Array)lines_edited_args[0])[0] = 1;
+ ((Array)lines_edited_args[0])[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_caret_line() == 1);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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;
+
+ // 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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());
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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_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");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ text_edit->set_editable(true);
+
+ ((Array)lines_edited_args[0])[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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 18);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+
+ // Select the entire text, from right to left
+ text_edit->select(0, 18, 0, 0);
+ text_edit->set_caret_line(0);
+ text_edit->set_caret_column(0);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ }
+
+ SUBCASE("[TextEdit] ui_text_delete_all_to_right") {
+ Ref<InputEvent> tmpevent = InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::ALT | KeyModifierMask::CMD);
+ 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->select(0, 0, 0, 4);
+ text_edit->set_caret_line(0);
+ text_edit->set_caret_column(4);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ // 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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());
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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_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");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ text_edit->set_caret_column(0);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ text_edit->set_editable(true);
+
+ 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+
+ InputMap::get_singleton()->action_erase_event("ui_text_delete_all_to_right", tmpevent);
+ }
+
+ SUBCASE("[TextEdit] ui_text_delete_word") {
+ 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->select(0, 0, 0, 4);
+ text_edit->set_caret_line(0);
+ text_edit->set_caret_column(4);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ // 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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;
+ text_edit->set_caret_column(text_edit->get_line(0).length());
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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_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");
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+
+ ((Array)lines_edited_args[0])[0] = 0;
+ text_edit->set_caret_column(0);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ text_edit->set_editable(true);
+
+ 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+ }
+
+ SUBCASE("[TextEdit] ui_text_delete") {
+ 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->select(0, 0, 0, 4);
+ text_edit->set_caret_line(0);
+ text_edit->set_caret_column(4);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ // 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ 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;
+ text_edit->set_caret_column(text_edit->get_line(0).length());
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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_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");
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+
+ ((Array)lines_edited_args[0])[0] = 0;
+ text_edit->set_caret_column(0);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ text_edit->set_editable(true);
+
+ 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+
+ 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ 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->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.");
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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_caret_line() == 0);
+ CHECK(text_edit->get_caret_column() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ 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_caret_line(1);
+ text_edit->set_caret_column(7);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+#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 | 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ 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_caret_line(1);
+ text_edit->set_caret_column(7);
+ text_edit->select(1, 2, 1, 7);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ 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_caret_line(0);
+ text_edit->set_caret_column(13);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+#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 | 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ 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_caret_line(0);
+ text_edit->set_caret_column(16);
+ text_edit->select(0, 16, 0, 20);
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ }
+
+ SUBCASE("[TextEdit] ui_text_caret_up") {
+ 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_caret_column(7);
+ MessageQueue::get_singleton()->flush();
+
+ CHECK(text_edit->is_line_wrapped(0));
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ 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);
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ }
+
+ SUBCASE("[TextEdit] ui_text_caret_down") {
+ 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_caret_line(0);
+ text_edit->set_caret_column(7);
+ MessageQueue::get_singleton()->flush();
+
+ CHECK(text_edit->is_line_wrapped(3));
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ 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());
+ 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);
+
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ }
+
+ SUBCASE("[TextEdit] ui_text_caret_document_start") {
+ 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_caret_column(7);
+ MessageQueue::get_singleton()->flush();
+
+ CHECK(text_edit->is_line_wrapped(0));
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+#ifdef MACOS_ENABLED
+ SEND_GUI_KEY_EVENT(text_edit, Key::UP | KeyModifierMask::CMD | KeyModifierMask::SHIFT);
+#else
+ SEND_GUI_KEY_EVENT(text_edit, Key::HOME | KeyModifierMask::CMD | KeyModifierMask::SHIFT);
+#endif
+ 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() == 0);
+ CHECK(text_edit->get_selected_text() == "this is some\nother test\nlines\ngo here");
+ CHECK(text_edit->has_selection());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_document_start");
+ 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() == 0);
+ CHECK_FALSE(text_edit->has_selection());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ }
+
+ SUBCASE("[TextEdit] ui_text_caret_document_end") {
+ 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_caret_line(0);
+ text_edit->set_caret_column(0);
+ MessageQueue::get_singleton()->flush();
+
+ CHECK(text_edit->is_line_wrapped(3));
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+#ifdef MACOS_ENABLED
+ SEND_GUI_KEY_EVENT(text_edit, Key::DOWN | KeyModifierMask::CMD | KeyModifierMask::SHIFT);
+#else
+ SEND_GUI_KEY_EVENT(text_edit, Key::END | KeyModifierMask::CMD | KeyModifierMask::SHIFT);
+#endif
+ 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(text_edit->get_selected_text() == "go here\nlines\nother test\nthis is some");
+ CHECK(text_edit->has_selection());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_document_end");
+ 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());
+ SIGNAL_CHECK_FALSE("caret_changed");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ }
+
+ SUBCASE("[TextEdit] ui_text_caret_line_start") {
+ 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_caret_line(0);
+ text_edit->set_caret_column(text_edit->get_line(0).length());
+ MessageQueue::get_singleton()->flush();
+
+ CHECK(text_edit->is_line_wrapped(0));
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+#ifdef MACOS_ENABLED
+ SEND_GUI_KEY_EVENT(text_edit, Key::LEFT | KeyModifierMask::CMD | KeyModifierMask::SHIFT);
+#else
+ SEND_GUI_KEY_EVENT(text_edit, Key::HOME | KeyModifierMask::SHIFT);
+#endif
+ 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");
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_line_start");
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_line_start");
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_line_start");
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ }
+
+ SUBCASE("[TextEdit] ui_text_caret_line_end") {
+ 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_caret_line(0);
+ text_edit->set_caret_column(0);
+ MessageQueue::get_singleton()->flush();
+
+ CHECK(text_edit->is_line_wrapped(0));
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+#ifdef MACOS_ENABLED
+ SEND_GUI_KEY_EVENT(text_edit, Key::RIGHT | KeyModifierMask::CMD | KeyModifierMask::SHIFT);
+#else
+ SEND_GUI_KEY_EVENT(text_edit, Key::END | KeyModifierMask::SHIFT);
+#endif
+ 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");
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_line_end");
+ 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());
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ }
+
+ SUBCASE("[TextEdit] unicode") {
+ text_edit->insert_text_at_caret("a");
+ MessageQueue::get_singleton()->flush();
+
+ SIGNAL_DISCARD("text_set");
+ SIGNAL_DISCARD("text_changed");
+ SIGNAL_DISCARD("lines_edited_from");
+ SIGNAL_DISCARD("caret_changed");
+
+ 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_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->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_caret_column() == 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());
+
+ text_edit->select(0, 0, 0, 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_caret_column() == 1);
+ SIGNAL_CHECK("caret_changed", empty_signal_args);
+ SIGNAL_CHECK("text_changed", empty_signal_args);
+ SIGNAL_CHECK("lines_edited_from", lines_edited_args);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_toggle_insert_mode");
+ CHECK(text_edit->is_overtype_mode_enabled());
+
+ 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_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);
+ 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_caret_column() == 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());
+ }
+
+ SIGNAL_UNWATCH(text_edit, "text_set");
+ SIGNAL_UNWATCH(text_edit, "text_changed");
+ SIGNAL_UNWATCH(text_edit, "lines_edited_from");
+ SIGNAL_UNWATCH(text_edit, "caret_changed");
+ }
+
+ memdelete(text_edit);
+}
+
+TEST_CASE("[SceneTree][TextEdit] context menu") {
+ TextEdit *text_edit = memnew(TextEdit);
+ SceneTree::get_singleton()->get_root()->add_child(text_edit);
+
+ text_edit->get_viewport()->set_embedding_subwindows(true); // Bypass display server for drop handling.
+
+ text_edit->set_size(Size2(800, 200));
+ text_edit->set_line(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius mattis leo, sed porta ex lacinia bibendum. Nunc bibendum pellentesque.");
+ MessageQueue::get_singleton()->flush();
+
+ text_edit->set_context_menu_enabled(false);
+ CHECK_FALSE(text_edit->is_context_menu_enabled());
+
+ CHECK_FALSE(text_edit->is_menu_visible());
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, Point2i(600, 10), MouseButton::RIGHT, MouseButton::MASK_RIGHT, Key::NONE);
+ CHECK_FALSE(text_edit->is_menu_visible());
+
+ text_edit->set_context_menu_enabled(true);
+ CHECK(text_edit->is_context_menu_enabled());
+
+ CHECK_FALSE(text_edit->is_menu_visible());
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, Point2i(700, 10), MouseButton::RIGHT, MouseButton::MASK_RIGHT, Key::NONE);
+ CHECK(text_edit->is_menu_visible());
+
+ memdelete(text_edit);
+}
+
+TEST_CASE("[SceneTree][TextEdit] versioning") {
+ TextEdit *text_edit = memnew(TextEdit);
+ SceneTree::get_singleton()->get_root()->add_child(text_edit);
+
+ // Action undo / redo states are tested in the action test e.g selection_delete.
+ CHECK_FALSE(text_edit->has_undo());
+ CHECK_FALSE(text_edit->has_redo());
+ CHECK(text_edit->get_version() == 0);
+ CHECK(text_edit->get_saved_version() == 0);
+
+ text_edit->begin_complex_operation();
+ text_edit->begin_complex_operation();
+ text_edit->begin_complex_operation();
+
+ text_edit->insert_text_at_caret("test");
+ CHECK(text_edit->get_version() == 1);
+ CHECK(text_edit->get_saved_version() == 0);
+ CHECK(text_edit->has_undo());
+ CHECK_FALSE(text_edit->has_redo());
+
+ text_edit->end_complex_operation();
+
+ // Can undo and redo mid op.
+ text_edit->insert_text_at_caret(" nested");
+ CHECK(text_edit->get_version() == 2);
+ CHECK(text_edit->get_saved_version() == 0);
+ CHECK(text_edit->has_undo());
+ CHECK_FALSE(text_edit->has_redo());
+ text_edit->undo();
+
+ CHECK(text_edit->has_redo());
+ text_edit->redo();
+
+ text_edit->end_complex_operation();
+
+ text_edit->insert_text_at_caret(" ops");
+ CHECK(text_edit->get_version() == 3);
+ CHECK(text_edit->get_saved_version() == 0);
+ CHECK(text_edit->has_undo());
+ CHECK_FALSE(text_edit->has_redo());
+
+ text_edit->end_complex_operation();
+
+ text_edit->tag_saved_version();
+ CHECK(text_edit->get_saved_version() == 3);
+
+ text_edit->undo();
+ CHECK(text_edit->get_line(0) == "");
+ CHECK(text_edit->get_version() == 0);
+ CHECK(text_edit->get_saved_version() == 3);
+ CHECK_FALSE(text_edit->has_undo());
+ CHECK(text_edit->has_redo());
+
+ text_edit->redo();
+ CHECK(text_edit->get_line(0) == "test nested ops");
+ CHECK(text_edit->get_version() == 3);
+ CHECK(text_edit->get_saved_version() == 3);
+ CHECK(text_edit->has_undo());
+ CHECK_FALSE(text_edit->has_redo());
+
+ text_edit->clear_undo_history();
+ CHECK_FALSE(text_edit->has_undo());
+ CHECK_FALSE(text_edit->has_redo());
+ CHECK(text_edit->get_version() == 3); // Should this be cleared?
+ CHECK(text_edit->get_saved_version() == 0);
+
+ memdelete(text_edit);
+}
+
+TEST_CASE("[SceneTree][TextEdit] search") {
+ TextEdit *text_edit = memnew(TextEdit);
+ SceneTree::get_singleton()->get_root()->add_child(text_edit);
+
+ text_edit->set_text("hay needle, hay\nHAY NEEDLE, HAY");
+ int length = text_edit->get_line(1).length();
+
+ CHECK(text_edit->search("test", 0, 0, 0) == Point2i(-1, -1));
+ CHECK(text_edit->search("test", TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(-1, -1));
+ CHECK(text_edit->search("test", TextEdit::SEARCH_WHOLE_WORDS, 0, 0) == Point2i(-1, -1));
+ CHECK(text_edit->search("test", TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(-1, -1));
+
+ CHECK(text_edit->search("test", 0, 1, length) == Point2i(-1, -1));
+ CHECK(text_edit->search("test", TextEdit::SEARCH_MATCH_CASE, 1, length) == Point2i(-1, -1));
+ CHECK(text_edit->search("test", TextEdit::SEARCH_WHOLE_WORDS, 1, length) == Point2i(-1, -1));
+ CHECK(text_edit->search("test", TextEdit::SEARCH_BACKWARDS, 1, length) == Point2i(-1, -1));
+
+ CHECK(text_edit->search("needle", 0, 0, 0) == Point2i(4, 0));
+ CHECK(text_edit->search("needle", 0, 1, length) == Point2i(4, 0));
+ CHECK(text_edit->search("needle", 0, 0, 5) == Point2i(4, 1));
+ CHECK(text_edit->search("needle", TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(4, 1));
+ CHECK(text_edit->search("needle", TextEdit::SEARCH_BACKWARDS, 1, 5) == Point2i(4, 1));
+ CHECK(text_edit->search("needle", TextEdit::SEARCH_BACKWARDS, 1, 3) == Point2i(4, 0));
+
+ CHECK(text_edit->search("needle", TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(4, 0));
+ CHECK(text_edit->search("needle", TextEdit::SEARCH_MATCH_CASE | TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(4, 0));
+
+ CHECK(text_edit->search("needle", TextEdit::SEARCH_WHOLE_WORDS | TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(4, 0));
+ CHECK(text_edit->search("needle", TextEdit::SEARCH_WHOLE_WORDS | TextEdit::SEARCH_MATCH_CASE | TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(4, 0));
+
+ CHECK(text_edit->search("need", TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(4, 0));
+ CHECK(text_edit->search("need", TextEdit::SEARCH_MATCH_CASE | TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(4, 0));
+
+ CHECK(text_edit->search("need", TextEdit::SEARCH_WHOLE_WORDS | TextEdit::SEARCH_MATCH_CASE, 0, 0) == Point2i(-1, -1));
+ CHECK(text_edit->search("need", TextEdit::SEARCH_WHOLE_WORDS | TextEdit::SEARCH_MATCH_CASE | TextEdit::SEARCH_BACKWARDS, 0, 0) == Point2i(-1, -1));
+
+ ERR_PRINT_OFF;
+ CHECK(text_edit->search("", 0, 0, 0) == Point2i(-1, -1));
+ CHECK(text_edit->search("needle", 0, -1, 0) == Point2i(-1, -1));
+ CHECK(text_edit->search("needle", 0, 0, -1) == Point2i(-1, -1));
+ CHECK(text_edit->search("needle", 0, 100, 0) == Point2i(-1, -1));
+ CHECK(text_edit->search("needle", 0, 0, 100) == Point2i(-1, -1));
+ ERR_PRINT_ON;
+
+ memdelete(text_edit);
+}
+
+TEST_CASE("[SceneTree][TextEdit] mouse") {
+ TextEdit *text_edit = memnew(TextEdit);
+ SceneTree::get_singleton()->get_root()->add_child(text_edit);
+
+ text_edit->set_size(Size2(800, 200));
+ text_edit->set_line(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius mattis leo, sed porta ex lacinia bibendum. Nunc bibendum pellentesque.");
+ MessageQueue::get_singleton()->flush();
+
+ CHECK(text_edit->get_word_at_pos(text_edit->get_pos_at_line_column(0, 1)) == "Lorem");
+ CHECK(text_edit->get_word_at_pos(text_edit->get_pos_at_line_column(0, 9)) == "ipsum");
+
+ ERR_PRINT_OFF;
+ CHECK(text_edit->get_pos_at_line_column(0, -1) == Point2i(-1, -1));
+ CHECK(text_edit->get_pos_at_line_column(-1, 0) == Point2i(-1, -1));
+ CHECK(text_edit->get_pos_at_line_column(-1, -1) == Point2i(-1, -1));
+
+ CHECK(text_edit->get_pos_at_line_column(0, 500) == Point2i(-1, -1));
+ CHECK(text_edit->get_pos_at_line_column(2, 0) == Point2i(-1, -1));
+ CHECK(text_edit->get_pos_at_line_column(2, 500) == Point2i(-1, -1));
+
+ // Out of view.
+ CHECK(text_edit->get_pos_at_line_column(0, text_edit->get_line(0).length() - 1) == Point2i(-1, -1));
+ ERR_PRINT_ON;
+
+ // Add method to get drawn column count?
+ Point2i start_pos = text_edit->get_pos_at_line_column(0, 0);
+ Point2i end_pos = text_edit->get_pos_at_line_column(0, 105);
+
+ CHECK(text_edit->get_line_column_at_pos(Point2i(start_pos.x, start_pos.y)) == Point2i(0, 0));
+ CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y)) == Point2i(104, 0));
+
+ // Should this return Point2i(-1, -1) if its also < 0 not just > vis_lines.
+ CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y), false) == Point2i(90, 0));
+ CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y + 100), false) == Point2i(-1, -1));
+ CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y + 100), false) == Point2i(-1, -1));
+ CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y - 100), false) == Point2i(104, 0));
+ CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y - 100), false) == Point2i(90, 0));
+
+ CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y)) == Point2i(90, 0));
+ CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y + 100)) == Point2i(141, 0));
+ CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y + 100)) == Point2i(141, 0));
+ CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x, end_pos.y - 100)) == Point2i(104, 0));
+ CHECK(text_edit->get_line_column_at_pos(Point2i(end_pos.x - 100, end_pos.y - 100)) == Point2i(90, 0));
+
+ memdelete(text_edit);
+}
+
+TEST_CASE("[SceneTree][TextEdit] caret") {
+ TextEdit *text_edit = memnew(TextEdit);
+ SceneTree::get_singleton()->get_root()->add_child(text_edit);
+
+ text_edit->set_size(Size2(800, 200));
+ text_edit->grab_focus();
+ text_edit->set_line(0, "ffi");
+
+ text_edit->set_caret_mid_grapheme_enabled(true);
+ CHECK(text_edit->is_caret_mid_grapheme_enabled());
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_right");
+ CHECK(text_edit->get_caret_column() == 1);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_right");
+ CHECK(text_edit->get_caret_column() == 2);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_right");
+ CHECK(text_edit->get_caret_column() == 3);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_left");
+ CHECK(text_edit->get_caret_column() == 2);
+
+ text_edit->set_caret_mid_grapheme_enabled(false);
+ CHECK_FALSE(text_edit->is_caret_mid_grapheme_enabled());
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_left");
+ CHECK(text_edit->get_caret_column() == 0);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_right");
+ CHECK(text_edit->get_caret_column() == 3);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_left");
+ CHECK(text_edit->get_caret_column() == 0);
+
+ text_edit->set_line(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius mattis leo, sed porta ex lacinia bibendum. Nunc bibendum pellentesque.");
+ for (int i = 0; i < 3; i++) {
+ text_edit->insert_line_at(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius mattis leo, sed porta ex lacinia bibendum. Nunc bibendum pellentesque.");
+ }
+ MessageQueue::get_singleton()->flush();
+
+ text_edit->set_caret_blink_enabled(false);
+ CHECK_FALSE(text_edit->is_caret_blink_enabled());
+
+ text_edit->set_caret_blink_enabled(true);
+ CHECK(text_edit->is_caret_blink_enabled());
+
+ text_edit->set_caret_blink_speed(10);
+ CHECK(text_edit->get_caret_blink_speed() == 10);
+
+ ERR_PRINT_OFF;
+ text_edit->set_caret_blink_speed(-1);
+ CHECK(text_edit->get_caret_blink_speed() == 10);
+
+ text_edit->set_caret_blink_speed(0);
+ CHECK(text_edit->get_caret_blink_speed() == 10);
+ ERR_PRINT_ON;
+
+ text_edit->set_caret_type(TextEdit::CaretType::CARET_TYPE_LINE);
+ CHECK(text_edit->get_caret_type() == TextEdit::CaretType::CARET_TYPE_LINE);
+
+ text_edit->set_caret_type(TextEdit::CaretType::CARET_TYPE_BLOCK);
+ CHECK(text_edit->get_caret_type() == TextEdit::CaretType::CARET_TYPE_BLOCK);
+
+ text_edit->set_caret_type(TextEdit::CaretType::CARET_TYPE_LINE);
+ CHECK(text_edit->get_caret_type() == TextEdit::CaretType::CARET_TYPE_LINE);
+
+ int caret_col = text_edit->get_caret_column();
+ text_edit->set_move_caret_on_right_click_enabled(false);
+ CHECK_FALSE(text_edit->is_move_caret_on_right_click_enabled());
+
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, Point2i(100, 1), MouseButton::RIGHT, MouseButton::MASK_RIGHT, Key::NONE);
+ CHECK(text_edit->get_caret_column() == caret_col);
+
+ text_edit->set_move_caret_on_right_click_enabled(true);
+ CHECK(text_edit->is_move_caret_on_right_click_enabled());
+
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, Point2i(100, 1), MouseButton::RIGHT, MouseButton::MASK_RIGHT, Key::NONE);
+ CHECK(text_edit->get_caret_column() != caret_col);
+
+ text_edit->set_move_caret_on_right_click_enabled(false);
+ CHECK_FALSE(text_edit->is_move_caret_on_right_click_enabled());
+
+ text_edit->set_caret_column(0);
+ CHECK(text_edit->get_word_under_caret() == "Lorem");
+
+ text_edit->set_caret_column(4);
+ CHECK(text_edit->get_word_under_caret() == "Lorem");
+
+ // Should this work?
+ text_edit->set_caret_column(5);
+ CHECK(text_edit->get_word_under_caret() == "");
+
+ text_edit->set_caret_column(6);
+ CHECK(text_edit->get_word_under_caret() == "");
+
+ text_edit->set_caret_line(1);
+ CHECK(text_edit->get_caret_line() == 1);
+
+ text_edit->set_caret_line(-1);
+ CHECK(text_edit->get_caret_line() == 0);
+ text_edit->set_caret_line(100);
+ CHECK(text_edit->get_caret_line() == 3);
+
+ text_edit->set_caret_column(-1);
+ CHECK(text_edit->get_caret_column() == 0);
+ text_edit->set_caret_column(10000000);
+ CHECK(text_edit->get_caret_column() == 141);
+
+ memdelete(text_edit);
+}
+
+TEST_CASE("[SceneTree][TextEdit] line wrapping") {
+ TextEdit *text_edit = memnew(TextEdit);
+ SceneTree::get_singleton()->get_root()->add_child(text_edit);
+ text_edit->grab_focus();
+
+ // Set size for boundary.
+ text_edit->set_size(Size2(800, 200));
+ text_edit->set_line(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius mattis leo, sed porta ex lacinia bibendum. Nunc bibendum pellentesque.");
+ CHECK_FALSE(text_edit->is_line_wrapped(0));
+ CHECK(text_edit->get_line_wrap_count(0) == 0);
+ CHECK(text_edit->get_line_wrap_index_at_column(0, 130) == 0);
+ CHECK(text_edit->get_line_wrapped_text(0).size() == 1);
+
+ SIGNAL_WATCH(text_edit, "text_set");
+ SIGNAL_WATCH(text_edit, "text_changed");
+ SIGNAL_WATCH(text_edit, "lines_edited_from");
+ SIGNAL_WATCH(text_edit, "caret_changed");
+
+ text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
+ SIGNAL_CHECK_FALSE("text_set");
+ SIGNAL_CHECK_FALSE("text_changed");
+ SIGNAL_CHECK_FALSE("lines_edited_from");
+ SIGNAL_CHECK_FALSE("caret_changed");
+
+ CHECK(text_edit->is_line_wrapped(0));
+ CHECK(text_edit->get_line_wrap_count(0) == 1);
+ CHECK(text_edit->get_line_wrap_index_at_column(0, 130) == 1);
+ CHECK(text_edit->get_line_wrapped_text(0).size() == 2);
+
+ SIGNAL_UNWATCH(text_edit, "text_set");
+ SIGNAL_UNWATCH(text_edit, "text_changed");
+ SIGNAL_UNWATCH(text_edit, "lines_edited_from");
+ SIGNAL_UNWATCH(text_edit, "caret_changed");
+
+ ERR_PRINT_OFF;
+ CHECK_FALSE(text_edit->is_line_wrapped(-1));
+ CHECK_FALSE(text_edit->is_line_wrapped(1));
+ CHECK(text_edit->get_line_wrap_count(-1) == 0);
+ CHECK(text_edit->get_line_wrap_count(1) == 0);
+ CHECK(text_edit->get_line_wrap_index_at_column(-1, 0) == 0);
+ CHECK(text_edit->get_line_wrap_index_at_column(0, -1) == 0);
+ CHECK(text_edit->get_line_wrap_index_at_column(1, 0) == 0);
+ CHECK(text_edit->get_line_wrap_index_at_column(0, 10000) == 0);
+ CHECK(text_edit->get_line_wrapped_text(-1).size() == 0);
+ CHECK(text_edit->get_line_wrapped_text(1).size() == 0);
+ ERR_PRINT_ON;
+
+ memdelete(text_edit);
+}
+
+TEST_CASE("[SceneTree][TextEdit] viewport") {
+ TextEdit *text_edit = memnew(TextEdit);
+ SceneTree::get_singleton()->get_root()->add_child(text_edit);
+
+ // No subcases here for performance.
+ text_edit->set_size(Size2(800, 600));
+ for (int i = 0; i < 50; i++) {
+ text_edit->insert_line_at(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius mattis leo, sed porta ex lacinia bibendum. Nunc bibendum pellentesque.");
+ }
+ MessageQueue::get_singleton()->flush();
+
+ const int visible_lines = text_edit->get_visible_line_count();
+ const int total_visible_lines = text_edit->get_total_visible_line_count();
+ CHECK(total_visible_lines == 51);
+
+ // First visible line.
+ CHECK(text_edit->get_first_visible_line() == 0);
+ CHECK(text_edit->get_v_scroll() == 0);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ text_edit->set_line_as_first_visible(visible_lines);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == visible_lines);
+ CHECK(text_edit->get_v_scroll() == visible_lines);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ ERR_PRINT_OFF;
+ text_edit->set_line_as_first_visible(-1);
+ text_edit->set_line_as_first_visible(500);
+ text_edit->set_line_as_first_visible(0, -1);
+ text_edit->set_line_as_first_visible(0, 500);
+ CHECK(text_edit->get_first_visible_line() == visible_lines);
+ ERR_PRINT_ON;
+
+ // Wrap.
+ text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_total_visible_line_count() > total_visible_lines);
+
+ text_edit->set_line_as_first_visible(5, 1);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 5);
+ CHECK(text_edit->get_v_scroll() == 11);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines - 6);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
+
+ // Reset.
+ text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_total_visible_line_count() == total_visible_lines);
+ text_edit->set_line_as_first_visible(0);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 0);
+ CHECK(text_edit->get_v_scroll() == 0);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ // Last visible line.
+ text_edit->set_line_as_last_visible(visible_lines * 2);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == visible_lines);
+ CHECK(text_edit->get_v_scroll() == visible_lines);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ ERR_PRINT_OFF;
+ text_edit->set_line_as_last_visible(-1);
+ text_edit->set_line_as_last_visible(500);
+ text_edit->set_line_as_last_visible(0, -1);
+ text_edit->set_line_as_last_visible(0, 500);
+ CHECK(text_edit->get_first_visible_line() == visible_lines);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
+ ERR_PRINT_ON;
+
+ // Wrap.
+ text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_total_visible_line_count() > total_visible_lines);
+
+ text_edit->set_line_as_last_visible(visible_lines + 5, 1);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 16);
+ CHECK(text_edit->get_v_scroll() == 32.0);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines + 5);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ // Reset.
+ text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_total_visible_line_count() == total_visible_lines);
+ text_edit->set_line_as_first_visible(0);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 0);
+ CHECK(text_edit->get_v_scroll() == 0);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ // Center.
+ text_edit->set_line_as_center_visible(visible_lines + (visible_lines / 2));
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == visible_lines);
+ CHECK(text_edit->get_v_scroll() == visible_lines);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ ERR_PRINT_OFF;
+ text_edit->set_line_as_last_visible(-1);
+ text_edit->set_line_as_last_visible(500);
+ text_edit->set_line_as_last_visible(0, -1);
+ text_edit->set_line_as_last_visible(0, 500);
+ CHECK(text_edit->get_first_visible_line() == visible_lines);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
+ ERR_PRINT_ON;
+
+ // Wrap.
+ text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_total_visible_line_count() > total_visible_lines);
+
+ text_edit->set_line_as_center_visible(visible_lines + (visible_lines / 2) + 5, 1);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == visible_lines + (visible_lines / 2));
+ CHECK(text_edit->get_v_scroll() == (visible_lines * 3));
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
+
+ // Scroll past eof.
+ int line_count = text_edit->get_line_count();
+ text_edit->set_scroll_past_end_of_file_enabled(true);
+ MessageQueue::get_singleton()->flush();
+ text_edit->set_line_as_center_visible(line_count - 1);
+ MessageQueue::get_singleton()->flush();
+
+ CHECK(text_edit->get_first_visible_line() == (visible_lines * 2) + 3);
+ CHECK(text_edit->get_v_scroll() == (visible_lines * 4) + 6);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) + 8);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ text_edit->set_scroll_past_end_of_file_enabled(false);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == (visible_lines * 2) + 3);
+ CHECK(text_edit->get_v_scroll() == (visible_lines * 4) - 4);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) + 8);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ // Reset.
+ text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_total_visible_line_count() == total_visible_lines);
+ text_edit->set_line_as_first_visible(0);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 0);
+ CHECK(text_edit->get_v_scroll() == 0);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ // Auto adjust - todo: horizontal scroll.
+ // Below.
+ MessageQueue::get_singleton()->flush();
+ CHECK_FALSE(text_edit->is_caret_visible());
+ text_edit->set_caret_line(visible_lines + 5, false);
+ CHECK_FALSE(text_edit->is_caret_visible());
+ text_edit->adjust_viewport_to_caret();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->is_caret_visible());
+ CHECK(text_edit->get_first_visible_line() == 5);
+ CHECK(text_edit->get_v_scroll() == 5);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines - 1) + 5);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ text_edit->center_viewport_to_caret();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == visible_lines - 5);
+ CHECK(text_edit->get_v_scroll() == visible_lines - 5);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 6);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ // Caret visible, do nothing.
+ text_edit->adjust_viewport_to_caret();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == visible_lines - 5);
+ CHECK(text_edit->get_v_scroll() == visible_lines - 5);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 6);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ // Above.
+ text_edit->set_caret_line(1, false);
+ MessageQueue::get_singleton()->flush();
+ text_edit->adjust_viewport_to_caret();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->is_caret_visible());
+ CHECK(text_edit->get_first_visible_line() == 1);
+ CHECK(text_edit->get_v_scroll() == 1);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ text_edit->set_line_as_first_visible(0);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 0);
+ CHECK(text_edit->get_v_scroll() == 0);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ text_edit->adjust_viewport_to_caret();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 0);
+ CHECK(text_edit->get_v_scroll() == 0);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ // Wrap
+ text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_total_visible_line_count() > total_visible_lines);
+
+ text_edit->set_caret_line(visible_lines + 5, false, true, 1);
+ MessageQueue::get_singleton()->flush();
+ text_edit->adjust_viewport_to_caret();
+ MessageQueue::get_singleton()->flush();
+
+ CHECK(text_edit->get_first_visible_line() == (visible_lines / 2) + 4);
+ CHECK(text_edit->get_v_scroll() == (visible_lines + (visible_lines / 2)) - 1);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines) + 3);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
+ CHECK(text_edit->get_caret_wrap_index() == 1);
+
+ text_edit->center_viewport_to_caret();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == visible_lines);
+ CHECK(text_edit->get_v_scroll() == (visible_lines * 2) + 1);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 11);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
+
+ // Caret visible, do nothing.
+ text_edit->adjust_viewport_to_caret();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == visible_lines);
+ CHECK(text_edit->get_v_scroll() == (visible_lines * 2) + 1);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 11);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
+
+ // Above.
+ text_edit->set_caret_line(1, false, true, 1);
+ MessageQueue::get_singleton()->flush();
+ text_edit->adjust_viewport_to_caret();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->is_caret_visible());
+ CHECK(text_edit->get_first_visible_line() == 1);
+ CHECK(text_edit->get_v_scroll() == 3);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines / 2) + 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 1);
+ CHECK(text_edit->get_caret_wrap_index() == 1);
+
+ text_edit->set_line_as_first_visible(0);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->is_caret_visible());
+ CHECK(text_edit->get_first_visible_line() == 0);
+ CHECK(text_edit->get_v_scroll() == 0);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines - 11);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ text_edit->adjust_viewport_to_caret();
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 0);
+ CHECK(text_edit->get_v_scroll() == 0);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines - 11);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ // Reset.
+ text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_total_visible_line_count() == total_visible_lines);
+ text_edit->set_line_as_first_visible(0);
+ MessageQueue::get_singleton()->flush();
+ CHECK(text_edit->get_first_visible_line() == 0);
+ CHECK(text_edit->get_v_scroll() == 0);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ // Smooth scroll.
+ text_edit->set_v_scroll_speed(10);
+ CHECK(text_edit->get_v_scroll_speed() == 10);
+ ERR_PRINT_OFF;
+ text_edit->set_v_scroll_speed(-1);
+ CHECK(text_edit->get_v_scroll_speed() == 10);
+
+ text_edit->set_v_scroll_speed(0);
+ CHECK(text_edit->get_v_scroll_speed() == 10);
+
+ text_edit->set_v_scroll_speed(1);
+ CHECK(text_edit->get_v_scroll_speed() == 1);
+ ERR_PRINT_ON;
+
+ // Scroll.
+ int v_scroll = text_edit->get_v_scroll();
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, Point2i(10, 10), MouseButton::WHEEL_DOWN, MouseButton::WHEEL_DOWN, Key::NONE);
+ CHECK(text_edit->get_v_scroll() > v_scroll);
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, Point2i(10, 10), MouseButton::WHEEL_UP, MouseButton::WHEEL_UP, Key::NONE);
+ CHECK(text_edit->get_v_scroll() == v_scroll);
+
+ // smooth scroll speed.
+ text_edit->set_smooth_scroll_enabled(true);
+
+ v_scroll = text_edit->get_v_scroll();
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, Point2i(10, 10), MouseButton::WHEEL_DOWN, MouseButton::WHEEL_DOWN, Key::NONE);
+ text_edit->notification(TextEdit::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
+ CHECK(text_edit->get_v_scroll() >= v_scroll);
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, Point2i(10, 10), MouseButton::WHEEL_UP, MouseButton::WHEEL_UP, Key::NONE);
+ text_edit->notification(TextEdit::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
+ CHECK(text_edit->get_v_scroll() == v_scroll);
+
+ v_scroll = text_edit->get_v_scroll();
+ text_edit->set_v_scroll_speed(10000);
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, Point2i(10, 10), MouseButton::WHEEL_DOWN, MouseButton::WHEEL_DOWN, Key::NONE);
+ text_edit->notification(TextEdit::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
+ CHECK(text_edit->get_v_scroll() >= v_scroll);
+ SEND_GUI_MOUSE_BUTTON_EVENT(text_edit, Point2i(10, 10), MouseButton::WHEEL_UP, MouseButton::WHEEL_UP, Key::NONE);
+ text_edit->notification(TextEdit::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
+ CHECK(text_edit->get_v_scroll() == v_scroll);
+
+ ERR_PRINT_OFF;
+ CHECK(text_edit->get_scroll_pos_for_line(-1) == 0);
+ CHECK(text_edit->get_scroll_pos_for_line(1000) == 0);
+ CHECK(text_edit->get_scroll_pos_for_line(1, -1) == 0);
+ CHECK(text_edit->get_scroll_pos_for_line(1, 100) == 0);
+ ERR_PRINT_ON;
+
+ text_edit->set_h_scroll(-100);
+ CHECK(text_edit->get_h_scroll() == 0);
+
+ text_edit->set_h_scroll(10000000);
+ CHECK(text_edit->get_h_scroll() == 313);
+
+ text_edit->set_h_scroll(-100);
+ CHECK(text_edit->get_h_scroll() == 0);
+
+ text_edit->set_smooth_scroll_enabled(false);
+
+ CHECK(text_edit->get_first_visible_line() == 0);
+ CHECK(text_edit->get_v_scroll() == 0);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+
+ text_edit->grab_focus();
+ SEND_GUI_ACTION(text_edit, "ui_text_scroll_down");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_first_visible_line() == 1);
+ CHECK(text_edit->get_v_scroll() == 1);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_scroll_up");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_first_visible_line() == 0);
+ CHECK(text_edit->get_v_scroll() == 0);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ // Page down, similar to VSCode, to end of page then scroll.
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_page_down");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_caret_line() == 21);
+ CHECK(text_edit->get_first_visible_line() == 0);
+ CHECK(text_edit->get_v_scroll() == 0);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_page_down");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_caret_line() == 41);
+ CHECK(text_edit->get_first_visible_line() == 20);
+ CHECK(text_edit->get_v_scroll() == 20);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines - 1) * 2);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_page_up");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_caret_line() == 21);
+ CHECK(text_edit->get_first_visible_line() == 20);
+ CHECK(text_edit->get_v_scroll() == 20);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines - 1) * 2);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_page_up");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_caret_line() == 1);
+ CHECK(text_edit->get_first_visible_line() == 1);
+ CHECK(text_edit->get_v_scroll() == 1);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
+ MessageQueue::get_singleton()->flush();
+
+ text_edit->grab_focus();
+ SEND_GUI_ACTION(text_edit, "ui_text_scroll_down");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_caret_line() == 2);
+ CHECK(text_edit->get_first_visible_line() == 2);
+ CHECK(text_edit->get_v_scroll() == 2);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines + 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_scroll_up");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_caret_line() == 2);
+ CHECK(text_edit->get_first_visible_line() == 1);
+ CHECK(text_edit->get_v_scroll() == 1);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ // Page down, similar to VSCode, to end of page then scroll.
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_page_down");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_caret_line() == 22);
+ CHECK(text_edit->get_first_visible_line() == 1);
+ CHECK(text_edit->get_v_scroll() == 1);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_page_down");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_caret_line() == 42);
+ CHECK(text_edit->get_first_visible_line() == 21);
+ CHECK(text_edit->get_v_scroll() == 21);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_page_up");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_caret_line() == 22);
+ CHECK(text_edit->get_first_visible_line() == 21);
+ CHECK(text_edit->get_v_scroll() == 21);
+ CHECK(text_edit->get_last_full_visible_line() == (visible_lines * 2) - 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ SEND_GUI_ACTION(text_edit, "ui_text_caret_page_up");
+ CHECK(text_edit->get_viewport()->is_input_handled());
+ CHECK(text_edit->get_caret_line() == 2);
+ CHECK(text_edit->get_first_visible_line() == 2);
+ CHECK(text_edit->get_v_scroll() == 2);
+ CHECK(text_edit->get_last_full_visible_line() == visible_lines + 1);
+ CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0);
+ CHECK(text_edit->get_caret_wrap_index() == 0);
+
+ memdelete(text_edit);
+}
+
+TEST_CASE("[SceneTree][TextEdit] setter getters") {
+ TextEdit *text_edit = memnew(TextEdit);
+ SceneTree::get_singleton()->get_root()->add_child(text_edit);
+
+ SUBCASE("[TextEdit] set and get placeholder") {
+ text_edit->set_placeholder("test\nplaceholder");
+ CHECK(text_edit->get_placeholder() == "test\nplaceholder");
+
+ CHECK(text_edit->get_text() == "");
+ CHECK(text_edit->get_line_count() == 1);
+ CHECK(text_edit->get_last_full_visible_line() == 0);
+ }
+
+ SUBCASE("[TextEdit] highlight current line") {
+ text_edit->set_highlight_current_line(true);
+ CHECK(text_edit->is_highlight_current_line_enabled());
+ text_edit->set_highlight_current_line(false);
+ CHECK_FALSE(text_edit->is_highlight_current_line_enabled());
+ }
+
+ SUBCASE("[TextEdit] highlight all occurrences") {
+ text_edit->set_highlight_all_occurrences(true);
+ CHECK(text_edit->is_highlight_all_occurrences_enabled());
+ text_edit->set_highlight_all_occurrences(false);
+ CHECK_FALSE(text_edit->is_highlight_all_occurrences_enabled());
+ }
+
+ SUBCASE("[TextEdit] draw control chars") {
+ text_edit->set_draw_control_chars(true);
+ CHECK(text_edit->get_draw_control_chars());
+ text_edit->set_draw_control_chars(false);
+ CHECK_FALSE(text_edit->get_draw_control_chars());
+ }
+
+ SUBCASE("[TextEdit] draw tabs") {
+ text_edit->set_draw_tabs(true);
+ CHECK(text_edit->is_drawing_tabs());
+ text_edit->set_draw_tabs(false);
+ CHECK_FALSE(text_edit->is_drawing_tabs());
+ }
+
+ SUBCASE("[TextEdit] draw spaces") {
+ text_edit->set_draw_spaces(true);
+ CHECK(text_edit->is_drawing_spaces());
+ text_edit->set_draw_spaces(false);
+ CHECK_FALSE(text_edit->is_drawing_spaces());
+ }
+
+ SUBCASE("[TextEdit] draw minimao") {
+ text_edit->set_draw_minimap(true);
+ CHECK(text_edit->is_drawing_minimap());
+ text_edit->set_draw_minimap(false);
+ CHECK_FALSE(text_edit->is_drawing_minimap());
+ }
+
+ SUBCASE("[TextEdit] minimap width") {
+ text_edit->set_minimap_width(-1);
+ CHECK(text_edit->get_minimap_width() == -1);
+ text_edit->set_minimap_width(1000);
+ CHECK(text_edit->get_minimap_width() == 1000);
+ }
+
+ SUBCASE("[TextEdit] line color background") {
+ ERR_PRINT_OFF;
+ text_edit->set_line_background_color(-1, Color("#ff0000"));
+ text_edit->set_line_background_color(0, Color("#00ff00"));
+ text_edit->set_line_background_color(1, Color("#0000ff"));
+
+ CHECK(text_edit->get_line_background_color(-1) == Color());
+ CHECK(text_edit->get_line_background_color(0) == Color("#00ff00"));
+ CHECK(text_edit->get_line_background_color(1) == Color());
+ ERR_PRINT_ON;
+
+ text_edit->set_line_background_color(0, Color("#ffff00"));
+ CHECK(text_edit->get_line_background_color(0) == Color("#ffff00"));
+ }
+
+ memdelete(text_edit);
+}
+
+TEST_CASE("[SceneTree][TextEdit] gutters") {
+ TextEdit *text_edit = memnew(TextEdit);
+ SceneTree::get_singleton()->get_root()->add_child(text_edit);
+
+ Array empty_signal_args;
+ empty_signal_args.push_back(Array());
+
+ SIGNAL_WATCH(text_edit, "gutter_clicked");
+ SIGNAL_WATCH(text_edit, "gutter_added");
+ SIGNAL_WATCH(text_edit, "gutter_removed");
+
+ SUBCASE("[TextEdit] gutter add and remove") {
+ text_edit->add_gutter();
+ CHECK(text_edit->get_gutter_count() == 1);
+ SIGNAL_CHECK("gutter_added", empty_signal_args);
+
+ text_edit->set_gutter_name(0, "test_gutter");
+ CHECK(text_edit->get_gutter_name(0) == "test_gutter");
+
+ text_edit->set_gutter_width(0, 10);
+ CHECK(text_edit->get_gutter_width(0) == 10);
+ CHECK(text_edit->get_total_gutter_width() > 10);
+ CHECK(text_edit->get_total_gutter_width() < 20);
+
+ text_edit->add_gutter(-100);
+ text_edit->set_gutter_width(1, 10);
+ CHECK(text_edit->get_total_gutter_width() > 20);
+ CHECK(text_edit->get_total_gutter_width() < 30);
+ CHECK(text_edit->get_gutter_count() == 2);
+ CHECK(text_edit->get_gutter_name(0) == "test_gutter");
+ SIGNAL_CHECK("gutter_added", empty_signal_args);
+
+ text_edit->set_gutter_draw(1, false);
+ CHECK(text_edit->get_total_gutter_width() > 10);
+ CHECK(text_edit->get_total_gutter_width() < 20);
+
+ text_edit->add_gutter(100);
+ CHECK(text_edit->get_gutter_count() == 3);
+ CHECK(text_edit->get_gutter_name(0) == "test_gutter");
+ SIGNAL_CHECK("gutter_added", empty_signal_args);
+
+ text_edit->add_gutter(0);
+ CHECK(text_edit->get_gutter_count() == 4);
+ CHECK(text_edit->get_gutter_name(1) == "test_gutter");
+ SIGNAL_CHECK("gutter_added", empty_signal_args);
+
+ text_edit->remove_gutter(2);
+ CHECK(text_edit->get_gutter_name(1) == "test_gutter");
+ CHECK(text_edit->get_gutter_count() == 3);
+ SIGNAL_CHECK("gutter_removed", empty_signal_args);
+
+ text_edit->remove_gutter(0);
+ CHECK(text_edit->get_gutter_name(0) == "test_gutter");
+ CHECK(text_edit->get_gutter_count() == 2);
+ SIGNAL_CHECK("gutter_removed", empty_signal_args);
+
+ ERR_PRINT_OFF;
+ text_edit->remove_gutter(-1);
+ SIGNAL_CHECK_FALSE("gutter_removed");
+
+ text_edit->remove_gutter(100);
+ SIGNAL_CHECK_FALSE("gutter_removed");
+
+ CHECK(text_edit->get_gutter_name(-1) == "");
+ CHECK(text_edit->get_gutter_name(100) == "");
+ ERR_PRINT_ON;
+ }
+
+ SUBCASE("[TextEdit] gutter data") {
+ text_edit->add_gutter();
+ CHECK(text_edit->get_gutter_count() == 1);
+ SIGNAL_CHECK("gutter_added", empty_signal_args);
+
+ text_edit->set_gutter_name(0, "test_gutter");
+ CHECK(text_edit->get_gutter_name(0) == "test_gutter");
+
+ text_edit->set_gutter_width(0, 10);
+ CHECK(text_edit->get_gutter_width(0) == 10);
+
+ text_edit->set_gutter_clickable(0, true);
+ CHECK(text_edit->is_gutter_clickable(0));
+
+ text_edit->set_gutter_overwritable(0, true);
+ CHECK(text_edit->is_gutter_overwritable(0));
+
+ text_edit->set_gutter_type(0, TextEdit::GutterType::GUTTER_TYPE_CUSTOM);
+ CHECK(text_edit->get_gutter_type(0) == TextEdit::GutterType::GUTTER_TYPE_CUSTOM);
+
+ text_edit->set_text("test\ntext");
+
+ ERR_PRINT_OFF;
+ text_edit->set_line_gutter_metadata(1, 0, "test");
+ text_edit->set_line_gutter_metadata(0, -1, "test");
+ text_edit->set_line_gutter_metadata(0, 2, "test");
+ text_edit->set_line_gutter_metadata(2, 0, "test");
+ text_edit->set_line_gutter_metadata(-1, 0, "test");
+
+ CHECK(text_edit->get_line_gutter_metadata(1, 0) == "test");
+ CHECK(text_edit->get_line_gutter_metadata(0, -1) == "");
+ CHECK(text_edit->get_line_gutter_metadata(0, 2) == "");
+ CHECK(text_edit->get_line_gutter_metadata(2, 0) == "");
+ CHECK(text_edit->get_line_gutter_metadata(-1, 0) == "");
+
+ text_edit->set_line_gutter_text(1, 0, "test");
+ text_edit->set_line_gutter_text(0, -1, "test");
+ text_edit->set_line_gutter_text(0, 2, "test");
+ text_edit->set_line_gutter_text(2, 0, "test");
+ text_edit->set_line_gutter_text(-1, 0, "test");
+
+ CHECK(text_edit->get_line_gutter_text(1, 0) == "test");
+ CHECK(text_edit->get_line_gutter_text(0, -1) == "");
+ CHECK(text_edit->get_line_gutter_text(0, 2) == "");
+ CHECK(text_edit->get_line_gutter_text(2, 0) == "");
+ CHECK(text_edit->get_line_gutter_text(-1, 0) == "");
+
+ text_edit->set_line_gutter_item_color(1, 0, Color(1, 0, 0));
+ text_edit->set_line_gutter_item_color(0, -1, Color(1, 0, 0));
+ text_edit->set_line_gutter_item_color(0, 2, Color(1, 0, 0));
+ text_edit->set_line_gutter_item_color(2, 0, Color(1, 0, 0));
+ text_edit->set_line_gutter_item_color(-1, 0, Color(1, 0, 0));
+
+ CHECK(text_edit->get_line_gutter_item_color(1, 0) == Color(1, 0, 0));
+ CHECK(text_edit->get_line_gutter_item_color(0, -1) == Color());
+ CHECK(text_edit->get_line_gutter_item_color(0, 2) == Color());
+ CHECK(text_edit->get_line_gutter_item_color(2, 0) == Color());
+ CHECK(text_edit->get_line_gutter_item_color(-1, 0) == Color());
+
+ text_edit->set_line_gutter_clickable(1, 0, true);
+ text_edit->set_line_gutter_clickable(0, -1, true);
+ text_edit->set_line_gutter_clickable(0, 2, true);
+ text_edit->set_line_gutter_clickable(2, 0, true);
+ text_edit->set_line_gutter_clickable(-1, 0, true);
+
+ CHECK(text_edit->is_line_gutter_clickable(1, 0) == true);
+ CHECK(text_edit->is_line_gutter_clickable(0, -1) == false);
+ CHECK(text_edit->is_line_gutter_clickable(0, 2) == false);
+ CHECK(text_edit->is_line_gutter_clickable(2, 0) == false);
+ CHECK(text_edit->is_line_gutter_clickable(-1, 0) == false);
+ ERR_PRINT_ON;
+
+ // Merging tested via CodeEdit gutters.
+ }
+
+ SIGNAL_UNWATCH(text_edit, "gutter_clicked");
+ SIGNAL_UNWATCH(text_edit, "gutter_added");
+ SIGNAL_UNWATCH(text_edit, "gutter_removed");
+ memdelete(text_edit);
+}
+
+} // namespace TestTextEdit
+
+#endif // TEST_TEXT_EDIT_H
diff --git a/tests/scene/test_theme.h b/tests/scene/test_theme.h
new file mode 100644
index 0000000000..f7cfa0fd5b
--- /dev/null
+++ b/tests/scene/test_theme.h
@@ -0,0 +1,257 @@
+/*************************************************************************/
+/* test_theme.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_THEME_H
+#define TEST_THEME_H
+
+#include "scene/resources/theme.h"
+#include "tests/test_tools.h"
+
+#include "thirdparty/doctest/doctest.h"
+
+namespace TestTheme {
+
+class Fixture {
+public:
+ struct DataEntry {
+ Theme::DataType type;
+ Variant value;
+ } const valid_data[Theme::DATA_TYPE_MAX] = {
+ { Theme::DATA_TYPE_COLOR, Color() },
+ { Theme::DATA_TYPE_CONSTANT, 42 },
+ { Theme::DATA_TYPE_FONT, Ref<FontFile>(memnew(FontFile)) },
+ { Theme::DATA_TYPE_FONT_SIZE, 42 },
+ { Theme::DATA_TYPE_ICON, Ref<Texture>(memnew(ImageTexture)) },
+ { Theme::DATA_TYPE_STYLEBOX, Ref<StyleBox>(memnew(StyleBoxFlat)) },
+ };
+
+ const StringName valid_item_name = "valid_item_name";
+ const StringName valid_type_name = "ValidTypeName";
+};
+
+TEST_CASE_FIXTURE(Fixture, "[Theme] Good theme type names") {
+ StringName names[] = {
+ "", // Empty name.
+ "CapitalizedName",
+ "snake_cased_name",
+ "42",
+ "_Underscore_",
+ };
+
+ SUBCASE("add_type") {
+ for (const StringName &name : names) {
+ Ref<Theme> theme = memnew(Theme);
+
+ ErrorDetector ed;
+ theme->add_type(name);
+ CHECK_FALSE(ed.has_error);
+ }
+ }
+
+ SUBCASE("set_theme_item") {
+ for (const StringName &name : names) {
+ for (const DataEntry &entry : valid_data) {
+ Ref<Theme> theme = memnew(Theme);
+
+ ErrorDetector ed;
+ theme->set_theme_item(entry.type, valid_item_name, name, entry.value);
+ CHECK_FALSE(ed.has_error);
+ }
+ }
+ }
+
+ SUBCASE("add_theme_item_type") {
+ for (const StringName &name : names) {
+ for (const DataEntry &entry : valid_data) {
+ Ref<Theme> theme = memnew(Theme);
+
+ ErrorDetector ed;
+ theme->add_theme_item_type(entry.type, name);
+ CHECK_FALSE(ed.has_error);
+ }
+ }
+ }
+
+ SUBCASE("set_type_variation") {
+ for (const StringName &name : names) {
+ Ref<Theme> theme = memnew(Theme);
+
+ ErrorDetector ed;
+ theme->set_type_variation(valid_type_name, name);
+ CHECK(ed.has_error == (name == StringName()));
+ }
+ for (const StringName &name : names) {
+ Ref<Theme> theme = memnew(Theme);
+
+ ErrorDetector ed;
+ theme->set_type_variation(name, valid_type_name);
+ CHECK(ed.has_error == (name == StringName()));
+ }
+ }
+}
+
+TEST_CASE_FIXTURE(Fixture, "[Theme] Bad theme type names") {
+ StringName names[] = {
+ "With/Slash",
+ "With Space",
+ "With@various$symbols!",
+ String::utf8("contains_汉字"),
+ };
+
+ SUBCASE("add_type") {
+ for (const StringName &name : names) {
+ Ref<Theme> theme = memnew(Theme);
+
+ ErrorDetector ed;
+ theme->add_type(name);
+ CHECK(ed.has_error);
+ }
+ }
+
+ SUBCASE("set_theme_item") {
+ for (const StringName &name : names) {
+ for (const DataEntry &entry : valid_data) {
+ Ref<Theme> theme = memnew(Theme);
+
+ ErrorDetector ed;
+ theme->set_theme_item(entry.type, valid_item_name, name, entry.value);
+ CHECK(ed.has_error);
+ }
+ }
+ }
+
+ SUBCASE("add_theme_item_type") {
+ for (const StringName &name : names) {
+ for (const DataEntry &entry : valid_data) {
+ Ref<Theme> theme = memnew(Theme);
+
+ ErrorDetector ed;
+ theme->add_theme_item_type(entry.type, name);
+ CHECK(ed.has_error);
+ }
+ }
+ }
+
+ SUBCASE("set_type_variation") {
+ for (const StringName &name : names) {
+ Ref<Theme> theme = memnew(Theme);
+
+ ErrorDetector ed;
+ theme->set_type_variation(valid_type_name, name);
+ CHECK(ed.has_error);
+ }
+ for (const StringName &name : names) {
+ Ref<Theme> theme = memnew(Theme);
+
+ ErrorDetector ed;
+ theme->set_type_variation(name, valid_type_name);
+ CHECK(ed.has_error);
+ }
+ }
+}
+
+TEST_CASE_FIXTURE(Fixture, "[Theme] Good theme item names") {
+ StringName names[] = {
+ "CapitalizedName",
+ "snake_cased_name",
+ "42",
+ "_Underscore_",
+ };
+
+ SUBCASE("set_theme_item") {
+ for (const StringName &name : names) {
+ for (const DataEntry &entry : valid_data) {
+ Ref<Theme> theme = memnew(Theme);
+
+ ErrorDetector ed;
+ theme->set_theme_item(entry.type, name, valid_type_name, entry.value);
+ CHECK_FALSE(ed.has_error);
+ CHECK(theme->has_theme_item(entry.type, name, valid_type_name));
+ }
+ }
+ }
+
+ SUBCASE("rename_theme_item") {
+ for (const StringName &name : names) {
+ for (const DataEntry &entry : valid_data) {
+ Ref<Theme> theme = memnew(Theme);
+ theme->set_theme_item(entry.type, valid_item_name, valid_type_name, entry.value);
+
+ ErrorDetector ed;
+ theme->rename_theme_item(entry.type, valid_item_name, name, valid_type_name);
+ CHECK_FALSE(ed.has_error);
+ CHECK_FALSE(theme->has_theme_item(entry.type, valid_item_name, valid_type_name));
+ CHECK(theme->has_theme_item(entry.type, name, valid_type_name));
+ }
+ }
+ }
+}
+
+TEST_CASE_FIXTURE(Fixture, "[Theme] Bad theme item names") {
+ StringName names[] = {
+ "", // Empty name.
+ "With/Slash",
+ "With Space",
+ "With@various$symbols!",
+ String::utf8("contains_汉字"),
+ };
+
+ SUBCASE("set_theme_item") {
+ for (const StringName &name : names) {
+ for (const DataEntry &entry : valid_data) {
+ Ref<Theme> theme = memnew(Theme);
+
+ ErrorDetector ed;
+ theme->set_theme_item(entry.type, name, valid_type_name, entry.value);
+ CHECK(ed.has_error);
+ CHECK_FALSE(theme->has_theme_item(entry.type, name, valid_type_name));
+ }
+ }
+ }
+
+ SUBCASE("rename_theme_item") {
+ for (const StringName &name : names) {
+ for (const DataEntry &entry : valid_data) {
+ Ref<Theme> theme = memnew(Theme);
+ theme->set_theme_item(entry.type, valid_item_name, valid_type_name, entry.value);
+
+ ErrorDetector ed;
+ theme->rename_theme_item(entry.type, valid_item_name, name, valid_type_name);
+ CHECK(ed.has_error);
+ CHECK(theme->has_theme_item(entry.type, valid_item_name, valid_type_name));
+ CHECK_FALSE(theme->has_theme_item(entry.type, name, valid_type_name));
+ }
+ }
+ }
+}
+
+} // namespace TestTheme
+
+#endif // TEST_THEME_H
diff --git a/tests/servers/test_physics_2d.cpp b/tests/servers/test_physics_2d.cpp
deleted file mode 100644
index 06aa88b5c0..0000000000
--- a/tests/servers/test_physics_2d.cpp
+++ /dev/null
@@ -1,398 +0,0 @@
-/*************************************************************************/
-/* test_physics_2d.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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. */
-/*************************************************************************/
-
-#include "test_physics_2d.h"
-
-#include "core/os/main_loop.h"
-#include "servers/physics_server_2d.h"
-#include "servers/rendering_server.h"
-
-static const unsigned char convex_png[] = {
- 0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49, 0x48, 0x44, 0x52, 0x0, 0x0, 0x0, 0x40, 0x0, 0x0, 0x0, 0x40, 0x8, 0x6, 0x0, 0x0, 0x0, 0xaa, 0x69, 0x71, 0xde, 0x0, 0x0, 0x0, 0x1, 0x73, 0x52, 0x47, 0x42, 0x0, 0xae, 0xce, 0x1c, 0xe9, 0x0, 0x0, 0x0, 0x6, 0x62, 0x4b, 0x47, 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf9, 0x43, 0xbb, 0x7f, 0x0, 0x0, 0x0, 0x9, 0x70, 0x48, 0x59, 0x73, 0x0, 0x0, 0xb, 0x13, 0x0, 0x0, 0xb, 0x13, 0x1, 0x0, 0x9a, 0x9c, 0x18, 0x0, 0x0, 0x0, 0x7, 0x74, 0x49, 0x4d, 0x45, 0x7, 0xdb, 0x6, 0xa, 0x3, 0x13, 0x31, 0x66, 0xa7, 0xac, 0x79, 0x0, 0x0, 0x4, 0xef, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0xed, 0x9b, 0xdd, 0x4e, 0x2a, 0x57, 0x14, 0xc7, 0xf7, 0x1e, 0xc0, 0x19, 0x38, 0x32, 0x80, 0xa, 0x6a, 0xda, 0x18, 0xa3, 0xc6, 0x47, 0x50, 0x7b, 0xa1, 0xd9, 0x36, 0x27, 0x7e, 0x44, 0xed, 0x45, 0x4d, 0x93, 0x3e, 0x40, 0x1f, 0x64, 0x90, 0xf4, 0x1, 0xbc, 0xf0, 0xc2, 0x9c, 0x57, 0x30, 0x4d, 0xbc, 0xa8, 0x6d, 0xc, 0x69, 0x26, 0xb5, 0x68, 0x8b, 0x35, 0x7e, 0x20, 0xb4, 0xf5, 0x14, 0xbf, 0x51, 0x3c, 0x52, 0xe, 0xc, 0xe, 0xc8, 0xf0, 0xb1, 0x7a, 0x51, 0x3d, 0xb1, 0x9e, 0x19, 0x1c, 0x54, 0x70, 0x1c, 0xdc, 0x9, 0x17, 0x64, 0x8, 0xc9, 0xff, 0xb7, 0xd6, 0x7f, 0xcd, 0x3f, 0x2b, 0xd9, 0x8, 0xbd, 0x9c, 0xda, 0x3e, 0xf8, 0x31, 0xff, 0xc, 0x0, 0x8, 0x42, 0x88, 0x9c, 0x9f, 0x9f, 0xbf, 0xa, 0x87, 0xc3, 0xad, 0x7d, 0x7d, 0x7d, 0x7f, 0x23, 0x84, 0x78, 0x8c, 0x31, 0xaf, 0x55, 0x0, 0xc6, 0xc7, 0x14, 0x1e, 0x8f, 0xc7, 0xbf, 0x38, 0x3c, 0x3c, 0x6c, 0x9b, 0x9f, 0x9f, 0x6f, 0xb8, 0x82, 0x9b, 0xee, 0xe8, 0xe8, 0xf8, 0x12, 0x0, 0xbe, 0xd3, 0x2a, 0x8, 0xfc, 0x50, 0xd1, 0xf9, 0x7c, 0x9e, 0x8a, 0x46, 0xa3, 0x5f, 0x9d, 0x9e, 0x9e, 0x7e, 0xb2, 0xb0, 0xb0, 0x60, 0xe5, 0x79, 0x1e, 0xf1, 0xfc, 0x7f, 0x3a, 0x9, 0x21, 0x88, 0x10, 0x82, 0x26, 0x26, 0x26, 0xde, 0x77, 0x75, 0x75, 0x85, 0x59, 0x96, 0xfd, 0x5e, 0x6b, 0x20, 0xf0, 0x7d, 0x85, 0x4b, 0x92, 0xf4, 0xfa, 0xe0, 0xe0, 0xe0, 0xd3, 0xb9, 0xb9, 0xb9, 0x46, 0x49, 0x92, 0xea, 0x6f, 0xa, 0xbf, 0x7d, 0x8, 0x21, 0x68, 0x70, 0x70, 0xb0, 0x38, 0x39, 0x39, 0x79, 0xd6, 0xd9, 0xd9, 0xb9, 0xcf, 0x30, 0xcc, 0xa2, 0xd6, 0xad, 0x21, 0x2b, 0x1c, 0x0, 0x38, 0x41, 0x10, 0xfc, 0xdb, 0xdb, 0xdb, 0x27, 0x1e, 0x8f, 0x27, 0x4b, 0x8, 0x1, 0x84, 0x90, 0xea, 0xf, 0x21, 0x4, 0x3c, 0x1e, 0x4f, 0x76, 0x67, 0x67, 0x67, 0x3f, 0x9f, 0xcf, 0xff, 0x7c, 0x5, 0xf3, 0xd9, 0x0, 0xe0, 0x2, 0x81, 0xc0, 0xa9, 0xdb, 0xed, 0x2e, 0x94, 0x2b, 0x5c, 0xe, 0xc4, 0xca, 0xca, 0x8a, 0x18, 0x8d, 0x46, 0x3, 0x0, 0xc0, 0x69, 0x1e, 0x4, 0x0, 0x90, 0x48, 0x24, 0x12, 0xe4, 0x38, 0xee, 0x41, 0xc2, 0x6f, 0x43, 0xe0, 0x38, 0xe, 0xfc, 0x7e, 0xbf, 0x10, 0x8b, 0xc5, 0xd6, 0x35, 0xd, 0x22, 0x9b, 0xcd, 0x7a, 0x96, 0x97, 0x97, 0x33, 0xf, 0xad, 0x7c, 0x29, 0x10, 0x9b, 0x9b, 0x9b, 0xef, 0x2e, 0x2e, 0x2e, 0x7e, 0xd5, 0x1c, 0x8, 0x0, 0x20, 0xe1, 0x70, 0x38, 0xfc, 0x98, 0xd5, 0x57, 0x2, 0xe1, 0x76, 0xbb, 0xf3, 0xa1, 0x50, 0xe8, 0x38, 0x9b, 0xcd, 0xfe, 0xa2, 0x9, 0x8, 0x0, 0x40, 0x2e, 0x2f, 0x2f, 0x7d, 0x4b, 0x4b, 0x4b, 0xb9, 0x4a, 0x54, 0x5f, 0x9, 0xc4, 0xd2, 0xd2, 0x92, 0xb4, 0xb7, 0xb7, 0xf7, 0x36, 0x97, 0xcb, 0x4d, 0x3d, 0x29, 0x8, 0x0, 0xe0, 0x42, 0xa1, 0xd0, 0x71, 0xb5, 0xc4, 0xdf, 0xb6, 0xc5, 0x93, 0xe, 0x4a, 0x0, 0x20, 0xa9, 0x54, 0xea, 0x37, 0xb7, 0xdb, 0x5d, 0xa8, 0xa6, 0x78, 0x39, 0x10, 0x6b, 0x6b, 0x6b, 0xf1, 0x64, 0x32, 0xb9, 0x5a, 0x55, 0x10, 0x0, 0xc0, 0x6d, 0x6c, 0x6c, 0x9c, 0x57, 0xbb, 0xfa, 0x25, 0x40, 0x14, 0x3, 0x81, 0x40, 0x34, 0x93, 0xc9, 0x2c, 0x57, 0x1c, 0x4, 0x0, 0x90, 0x58, 0x2c, 0xb6, 0x5e, 0xe9, 0xc1, 0x77, 0x1f, 0x10, 0x53, 0x53, 0x53, 0x52, 0xc5, 0x83, 0x14, 0x0, 0x70, 0x7e, 0xbf, 0x5f, 0xd0, 0x42, 0xf5, 0x95, 0x40, 0xf8, 0x7c, 0xbe, 0xcb, 0xa3, 0xa3, 0xa3, 0x3f, 0x1e, 0xbd, 0x1b, 0x0, 0x80, 0x1c, 0x1f, 0x1f, 0x87, 0xb4, 0x56, 0xfd, 0xaa, 0x5, 0x29, 0x51, 0x14, 0xbf, 0xf5, 0xf9, 0x7c, 0x97, 0x5a, 0xad, 0xbe, 0x12, 0x88, 0xf5, 0xf5, 0xf5, 0xd8, 0x83, 0x83, 0x54, 0xb5, 0x42, 0x8f, 0x66, 0x83, 0x94, 0xd6, 0xbd, 0x5f, 0xce, 0x7c, 0x38, 0x3c, 0x3c, 0xfc, 0xb3, 0x50, 0x28, 0xb8, 0xcb, 0x2, 0x1, 0x0, 0xdc, 0xf4, 0xf4, 0xf4, 0xfe, 0x73, 0x15, 0x2f, 0x17, 0xa4, 0x22, 0x91, 0x48, 0x50, 0xb5, 0x2d, 0x0, 0x80, 0x9b, 0x99, 0x99, 0x79, 0xfb, 0xdc, 0x1, 0xc8, 0x5, 0xa9, 0x44, 0x22, 0xf1, 0xfb, 0x9d, 0x10, 0x0, 0x80, 0x9b, 0x9d, 0x9d, 0xd, 0xea, 0x5, 0xc0, 0xad, 0xfd, 0x43, 0x1a, 0x0, 0xb8, 0xdb, 0x9a, 0xa9, 0x8f, 0xb6, 0xa4, 0x46, 0xa3, 0xa4, 0xb7, 0xd5, 0x37, 0xcf, 0xf3, 0x68, 0x75, 0x75, 0xf5, 0x4c, 0xee, 0x99, 0x1c, 0x80, 0x9c, 0x1e, 0xf7, 0xff, 0x16, 0x8b, 0x45, 0x50, 0x5, 0xa0, 0xb7, 0xb7, 0xb7, 0x85, 0x10, 0xa2, 0x2b, 0xf1, 0x84, 0x10, 0xd4, 0xdf, 0xdf, 0x6f, 0x57, 0x3, 0x80, 0x37, 0x18, 0xc, 0x5, 0x3d, 0x2, 0xa0, 0x69, 0x3a, 0x8b, 0x10, 0xe2, 0x4b, 0x2, 0xc0, 0x18, 0xf3, 0xc1, 0x60, 0x70, 0x47, 0x8f, 0x16, 0x38, 0x3a, 0x3a, 0x5a, 0x93, 0x5b, 0xc3, 0x7f, 0x64, 0x81, 0xba, 0xba, 0x3a, 0x49, 0x8f, 0x0, 0x1a, 0x1a, 0x1a, 0xd4, 0xcd, 0x0, 0x93, 0xc9, 0xa4, 0xcb, 0x21, 0xe8, 0x74, 0x3a, 0xd5, 0x1, 0xa0, 0x69, 0x5a, 0x77, 0x1d, 0x80, 0x31, 0x2e, 0x38, 0x9d, 0x4e, 0xb1, 0x66, 0x1, 0x30, 0xc, 0x23, 0x28, 0x3d, 0x93, 0x9b, 0x1, 0xb9, 0x9a, 0x6, 0x60, 0x36, 0x9b, 0x75, 0xd7, 0x1, 0x4a, 0x21, 0xa8, 0x26, 0x0, 0x94, 0xa, 0x41, 0xb2, 0x0, 0x18, 0x86, 0xc9, 0xe9, 0xd, 0x80, 0x52, 0x8, 0x92, 0x5, 0x60, 0xb1, 0x58, 0x74, 0x67, 0x1, 0xa5, 0x10, 0xa4, 0x4, 0x40, 0x77, 0x43, 0xd0, 0xe1, 0x70, 0xa8, 0x9f, 0x1, 0x14, 0x45, 0x1, 0x45, 0x51, 0x79, 0x3d, 0x1, 0x68, 0x6e, 0x6e, 0x4e, 0xaa, 0x6, 0x80, 0x10, 0x42, 0x6, 0x83, 0x41, 0x37, 0x36, 0x28, 0x15, 0x82, 0x6a, 0x2, 0x0, 0x4d, 0xd3, 0xa9, 0x52, 0xcf, 0x95, 0x0, 0xe8, 0x66, 0xe, 0x98, 0xcd, 0x66, 0xa1, 0x6c, 0x0, 0x7a, 0x5a, 0x8b, 0x59, 0x2c, 0x96, 0x64, 0xcd, 0x2, 0xb8, 0x2b, 0x4, 0xe9, 0xde, 0x2, 0x77, 0x85, 0xa0, 0x9a, 0xb0, 0x40, 0xa9, 0x10, 0xa4, 0x8, 0xc0, 0x64, 0x32, 0xe9, 0x6, 0x40, 0xa9, 0x10, 0x54, 0xaa, 0x3, 0x74, 0xf3, 0x16, 0x70, 0xb9, 0x5c, 0xe5, 0x3, 0xe8, 0xe9, 0xe9, 0x69, 0xd5, 0xc3, 0x66, 0x18, 0x63, 0x5c, 0x68, 0x6a, 0x6a, 0x12, 0xcb, 0x5, 0xa0, 0x9b, 0xd5, 0x38, 0x4d, 0xd3, 0x29, 0x8a, 0xa2, 0xa0, 0x2c, 0x0, 0x18, 0x63, 0x3e, 0x14, 0xa, 0xfd, 0x55, 0xb, 0x21, 0x48, 0xd1, 0x2, 0x7a, 0x59, 0x8d, 0xdf, 0x1b, 0x80, 0x1e, 0x56, 0xe3, 0x84, 0x10, 0x34, 0x30, 0x30, 0x60, 0xbb, 0xeb, 0x77, 0x46, 0x5, 0xef, 0x48, 0xcf, 0x4d, 0xec, 0x8d, 0x99, 0x5, 0xf5, 0xf5, 0xf5, 0xef, 0x46, 0x47, 0x47, 0xb, 0x2e, 0x97, 0xeb, 0xbc, 0x54, 0x8, 0x52, 0x4, 0xc0, 0x30, 0x8c, 0xf4, 0x5c, 0x4, 0x9b, 0x4c, 0xa6, 0xf4, 0xf8, 0xf8, 0xb8, 0xc8, 0xb2, 0x6c, 0x32, 0x9d, 0x4e, 0xff, 0xd4, 0xdd, 0xdd, 0x7d, 0x66, 0x34, 0x1a, 0x8b, 0xd7, 0x3, 0xfd, 0xae, 0x5b, 0x29, 0xb2, 0x57, 0x66, 0xb6, 0xb6, 0xb6, 0xde, 0xc4, 0xe3, 0xf1, 0x6f, 0xae, 0xaf, 0xc1, 0x28, 0x5d, 0x85, 0x79, 0x2, 0xc1, 0x60, 0xb5, 0x5a, 0xa3, 0xa3, 0xa3, 0xa3, 0x45, 0xab, 0xd5, 0x9a, 0x2a, 0x16, 0x8b, 0x8b, 0x6d, 0x6d, 0x6d, 0xef, 0xd5, 0x8a, 0x55, 0xd, 0x20, 0x91, 0x48, 0xbc, 0x3e, 0x38, 0x38, 0xf8, 0xda, 0x6e, 0xb7, 0xf7, 0x5f, 0x5c, 0x5c, 0xd4, 0x7b, 0xbd, 0xde, 0xbc, 0x20, 0x8, 0xcd, 0x85, 0x42, 0x81, 0xfe, 0xf0, 0xae, 0xac, 0x10, 0x98, 0x9b, 0xd5, 0xc5, 0x18, 0x17, 0x59, 0x96, 0x3d, 0x1d, 0x19, 0x19, 0x1, 0x96, 0x65, 0x5, 0x8a, 0xa2, 0x7e, 0x6c, 0x69, 0x69, 0x49, 0x3d, 0x44, 0xb0, 0x2a, 0x0, 0x1f, 0xcc, 0x74, 0x75, 0x41, 0xea, 0xfa, 0x7b, 0x32, 0x99, 0x64, 0x76, 0x77, 0x77, 0x5d, 0xe, 0x87, 0xa3, 0x5f, 0x14, 0xc5, 0x57, 0x57, 0x60, 0x5a, 0x8b, 0xc5, 0xa2, 0xf1, 0xbe, 0x50, 0x6e, 0xa, 0x66, 0x18, 0x26, 0x31, 0x36, 0x36, 0x96, 0x65, 0x59, 0x36, 0x29, 0x49, 0x92, 0xb7, 0xbd, 0xbd, 0xfd, 0x9f, 0x72, 0xda, 0xf9, 0xd1, 0x1, 0xa8, 0x1, 0x93, 0xcf, 0xe7, 0xa9, 0x93, 0x93, 0x13, 0x1b, 0x4d, 0xd3, 0x9f, 0xb, 0x82, 0x60, 0xf5, 0x7a, 0xbd, 0xd9, 0x54, 0x2a, 0xe5, 0xcc, 0x64, 0x32, 0xe, 0xb9, 0x6e, 0xb9, 0x16, 0x8c, 0x31, 0x2e, 0xda, 0x6c, 0xb6, 0xc8, 0xd0, 0xd0, 0x10, 0x65, 0xb3, 0xd9, 0x92, 0x95, 0xa8, 0x6e, 0xc5, 0x0, 0xa8, 0xe9, 0x96, 0x68, 0x34, 0x6a, 0xdd, 0xdf, 0xdf, 0x6f, 0x76, 0xb9, 0x5c, 0x9f, 0x89, 0xa2, 0x58, 0xbf, 0xb8, 0xb8, 0x8, 0x26, 0x93, 0x29, 0x3b, 0x3c, 0x3c, 0x8c, 0xed, 0x76, 0x7b, 0xd2, 0x68, 0x34, 0xfe, 0xd0, 0xd8, 0xd8, 0x98, 0xae, 0xb6, 0xe0, 0x8a, 0x1, 0x50, 0xb, 0xe6, 0xa9, 0x5, 0xbf, 0x9c, 0x97, 0xf3, 0xff, 0xf3, 0x2f, 0x6a, 0x82, 0x7f, 0xf6, 0x4e, 0xca, 0x1b, 0xf5, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
-};
-
-class TestPhysics2DMainLoop : public MainLoop {
- GDCLASS(TestPhysics2DMainLoop, MainLoop);
-
- RID circle_img;
- RID circle_shape;
- RID space;
- RID canvas;
- RID ray;
- RID ray_query;
- Transform2D view_xform;
-
- Vector2 ray_from, ray_to;
-
- struct BodyShapeData {
- RID image;
- RID shape;
- };
-
- BodyShapeData body_shape_data[8];
-
- void _create_body_shape_data() {
- RenderingServer *vs = RenderingServer::get_singleton();
- PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
-
- // SEGMENT
-
- {
- Vector<uint8_t> pixels;
- pixels.resize(32 * 2 * 2);
- for (int i = 0; i < 2; i++) {
- for (int j = 0; j < 32; j++) {
- pixels.set(i * 32 * 2 + j * 2 + 0, (j == 0) ? 255 : 0);
- pixels.set(i * 32 * 2 + j * 2 + 1, 255);
- }
- }
-
- Ref<Image> image = memnew(Image(32, 2, 0, Image::FORMAT_LA8, pixels));
-
- body_shape_data[PhysicsServer2D::SHAPE_SEGMENT].image = vs->texture_2d_create(image);
-
- RID segment_shape = ps->segment_shape_create();
- Rect2 sg(Point2(-16, 0), Point2(16, 0));
- ps->shape_set_data(segment_shape, sg);
-
- body_shape_data[PhysicsServer2D::SHAPE_SEGMENT].shape = segment_shape;
- }
- // CIRCLE
-
- {
- Vector<uint8_t> pixels;
- pixels.resize(32 * 32 * 2);
- for (int i = 0; i < 32; i++) {
- for (int j = 0; j < 32; j++) {
- bool black = Vector2(i - 16, j - 16).length_squared() < 16 * 16;
-
- pixels.set(i * 32 * 2 + j * 2 + 0, (i == 16 || j == 16) ? 255 : 0);
- pixels.set(i * 32 * 2 + j * 2 + 1, black ? 255 : 0);
- }
- }
-
- Ref<Image> image = memnew(Image(32, 32, 0, Image::FORMAT_LA8, pixels));
-
- body_shape_data[PhysicsServer2D::SHAPE_CIRCLE].image = vs->texture_2d_create(image);
-
- RID circle_shape = ps->circle_shape_create();
- ps->shape_set_data(circle_shape, 16);
-
- body_shape_data[PhysicsServer2D::SHAPE_CIRCLE].shape = circle_shape;
- }
-
- // BOX
-
- {
- Vector<uint8_t> pixels;
- pixels.resize(32 * 32 * 2);
- for (int i = 0; i < 32; i++) {
- for (int j = 0; j < 32; j++) {
- bool black = i > 0 && i < 31 && j > 0 && j < 31;
-
- pixels.set(i * 32 * 2 + j * 2 + 0, black ? 0 : 255);
- pixels.set(i * 32 * 2 + j * 2 + 1, 255);
- }
- }
-
- Ref<Image> image = memnew(Image(32, 32, 0, Image::FORMAT_LA8, pixels));
-
- body_shape_data[PhysicsServer2D::SHAPE_RECTANGLE].image = vs->texture_2d_create(image);
-
- RID rectangle_shape = ps->rectangle_shape_create();
- ps->shape_set_data(rectangle_shape, Vector2(16, 16));
-
- body_shape_data[PhysicsServer2D::SHAPE_RECTANGLE].shape = rectangle_shape;
- }
-
- // CAPSULE
-
- {
- Vector<uint8_t> pixels;
- pixels.resize(32 * 64 * 2);
- for (int i = 0; i < 64; i++) {
- for (int j = 0; j < 32; j++) {
- int si = i > 48 ? i - 32 : (i < 16 ? i : 16);
- bool black = Vector2(si - 16, j - 16).length_squared() < 16 * 16;
-
- pixels.set(i * 32 * 2 + j * 2 + 0, (i == 16 || j == 16 || i == 48) ? 255 : 0);
- pixels.set(i * 32 * 2 + j * 2 + 1, black ? 255 : 0);
- }
- }
-
- Ref<Image> image = memnew(Image(32, 64, 0, Image::FORMAT_LA8, pixels));
-
- body_shape_data[PhysicsServer2D::SHAPE_CAPSULE].image = vs->texture_2d_create(image);
-
- RID capsule_shape = ps->capsule_shape_create();
- ps->shape_set_data(capsule_shape, Vector2(16, 32));
-
- body_shape_data[PhysicsServer2D::SHAPE_CAPSULE].shape = capsule_shape;
- }
-
- // CONVEX
-
- {
- Ref<Image> image = memnew(Image(convex_png));
-
- body_shape_data[PhysicsServer2D::SHAPE_CONVEX_POLYGON].image = vs->texture_2d_create(image);
-
- RID convex_polygon_shape = ps->convex_polygon_shape_create();
-
- Vector<Vector2> arr;
- Point2 sb(32, 32);
- arr.push_back(Point2(20, 3) - sb);
- arr.push_back(Point2(58, 23) - sb);
- arr.push_back(Point2(55, 54) - sb);
- arr.push_back(Point2(27, 60) - sb);
- arr.push_back(Point2(5, 56) - sb);
- arr.push_back(Point2(4, 20) - sb);
- arr.push_back(Point2(11, 7) - sb);
- ps->shape_set_data(convex_polygon_shape, arr);
-
- body_shape_data[PhysicsServer2D::SHAPE_CONVEX_POLYGON].shape = convex_polygon_shape;
- }
- }
-
- void _do_ray_query() {
- /*
- PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
- ps->query_intersection_segment(ray_query,ray_from,ray_to);
- */
- }
-
-protected:
- void input_event(const Ref<InputEvent> &p_event) {
- Ref<InputEventMouseButton> mb = p_event;
-
- if (mb.is_valid()) {
- if (mb->is_pressed()) {
- Point2 p = mb->get_position();
-
- if (mb->get_button_index() == MouseButton::LEFT) {
- ray_to = p;
- _do_ray_query();
- } else if (mb->get_button_index() == MouseButton::RIGHT) {
- ray_from = p;
- _do_ray_query();
- }
- }
- }
-
- Ref<InputEventMouseMotion> mm = p_event;
-
- if (mm.is_valid()) {
- Point2 p = mm->get_position();
-
- if ((mm->get_button_mask() & MouseButton::MASK_LEFT) != MouseButton::NONE) {
- ray_to = p;
- _do_ray_query();
- } else if ((mm->get_button_mask() & MouseButton::MASK_RIGHT) != MouseButton::NONE) {
- ray_from = p;
- _do_ray_query();
- }
- }
- }
-
- RID _add_body(PhysicsServer2D::ShapeType p_shape, const Transform2D &p_xform) {
- RenderingServer *vs = RenderingServer::get_singleton();
- PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
-
- RID body = ps->body_create();
- ps->body_add_shape(body, body_shape_data[p_shape].shape);
- ps->body_set_space(body, space);
- ps->body_set_continuous_collision_detection_mode(body, PhysicsServer2D::CCD_MODE_CAST_SHAPE);
- ps->body_set_state(body, PhysicsServer2D::BODY_STATE_TRANSFORM, p_xform);
-
- //print_line("add body with xform: "+p_xform);
- RID sprite = vs->canvas_item_create();
- vs->canvas_item_set_parent(sprite, canvas);
- vs->canvas_item_set_transform(sprite, p_xform);
- Size2 imgsize(5, 5); //vs->texture_get_width(body_shape_data[p_shape].image), vs->texture_get_height(body_shape_data[p_shape].image));
- vs->canvas_item_add_texture_rect(sprite, Rect2(-imgsize / 2.0, imgsize), body_shape_data[p_shape].image);
-
- ps->body_set_force_integration_callback(body, callable_mp(this, &TestPhysics2DMainLoop::_body_moved), sprite);
-
- return body;
- }
-
- void _add_world_boundary(const Vector2 &p_normal, real_t p_d) {
- PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
-
- Array arr;
- arr.push_back(p_normal);
- arr.push_back(p_d);
-
- RID world_boundary = ps->world_boundary_shape_create();
- ps->shape_set_data(world_boundary, arr);
-
- RID plane_body = ps->body_create();
- ps->body_set_mode(plane_body, PhysicsServer2D::BODY_MODE_STATIC);
- ps->body_set_space(plane_body, space);
- ps->body_add_shape(plane_body, world_boundary);
- }
-
- void _add_concave(const Vector<Vector2> &p_points, const Transform2D &p_xform = Transform2D()) {
- PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
- RenderingServer *vs = RenderingServer::get_singleton();
-
- RID concave = ps->concave_polygon_shape_create();
- ps->shape_set_data(concave, p_points);
- RID body = ps->body_create();
- ps->body_set_mode(body, PhysicsServer2D::BODY_MODE_STATIC);
- ps->body_set_space(body, space);
- ps->body_add_shape(body, concave);
- ps->body_set_state(body, PhysicsServer2D::BODY_STATE_TRANSFORM, p_xform);
-
- RID sprite = vs->canvas_item_create();
- vs->canvas_item_set_parent(sprite, canvas);
- vs->canvas_item_set_transform(sprite, p_xform);
- for (int i = 0; i < p_points.size(); i += 2) {
- vs->canvas_item_add_line(sprite, p_points[i], p_points[i + 1], Color(0, 0, 0), 2);
- }
- }
-
- void _body_moved(Object *p_state, RID p_sprite) {
- PhysicsDirectBodyState2D *state = (PhysicsDirectBodyState2D *)p_state;
- RenderingServer::get_singleton()->canvas_item_set_transform(p_sprite, state->get_transform());
- }
-
- void _ray_query_callback(const RID &p_rid, ObjectID p_id, int p_shape, const Vector2 &p_point, const Vector2 &p_normal) {
- Vector2 ray_end;
-
- if (p_rid.is_valid()) {
- ray_end = p_point;
- } else {
- ray_end = ray_to;
- }
-
- RenderingServer *vs = RenderingServer::get_singleton();
-
- vs->canvas_item_clear(ray);
- vs->canvas_item_add_line(ray, ray_from, ray_end, p_rid.is_valid() ? Color(0, 1, 0.4) : Color(1, 0.4, 0), 2);
- if (p_rid.is_valid()) {
- vs->canvas_item_add_line(ray, ray_end, ray_end + p_normal * 20, p_rid.is_valid() ? Color(0, 1, 0.4) : Color(1, 0.4, 0), 2);
- }
- }
-
- static void _bind_methods() {
- ClassDB::bind_method(D_METHOD("_ray_query_callback"), &TestPhysics2DMainLoop::_ray_query_callback);
- }
-
-public:
- virtual void initialize() override {
- RenderingServer *vs = RenderingServer::get_singleton();
- PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
-
- space = ps->space_create();
- ps->space_set_active(space, true);
- ps->set_active(true);
- ps->area_set_param(space, PhysicsServer2D::AREA_PARAM_GRAVITY_VECTOR, Vector2(0, 1));
- ps->area_set_param(space, PhysicsServer2D::AREA_PARAM_GRAVITY, 980);
-
- {
- RID vp = vs->viewport_create();
- canvas = vs->canvas_create();
-
- Size2i screen_size = DisplayServer::get_singleton()->window_get_size();
- vs->viewport_attach_canvas(vp, canvas);
- vs->viewport_set_size(vp, screen_size.x, screen_size.y);
- vs->viewport_attach_to_screen(vp, Rect2(Vector2(), screen_size));
- vs->viewport_set_active(vp, true);
-
- Transform2D smaller;
- //smaller.scale(Vector2(0.6,0.6));
- //smaller.elements[2]=Vector2(100,0);
-
- //view_xform = smaller;
- vs->viewport_set_canvas_transform(vp, canvas, view_xform);
- }
-
- ray = vs->canvas_item_create();
- vs->canvas_item_set_parent(ray, canvas);
- //ray_query = ps->query_create(this,"_ray_query_callback",Variant());
- //ps->query_intersection(ray_query,space);
-
- _create_body_shape_data();
-
- for (int i = 0; i < 32; i++) {
- PhysicsServer2D::ShapeType types[4] = {
- PhysicsServer2D::SHAPE_CIRCLE,
- PhysicsServer2D::SHAPE_CAPSULE,
- PhysicsServer2D::SHAPE_RECTANGLE,
- PhysicsServer2D::SHAPE_CONVEX_POLYGON,
-
- };
-
- PhysicsServer2D::ShapeType type = types[i % 4];
- //type=PhysicsServer2D::SHAPE_SEGMENT;
- _add_body(type, Transform2D(i * 0.8, Point2(152 + i * 40, 100 - 40 * i)));
- /*
- if (i==0)
- ps->body_set_mode(b,PhysicsServer2D::BODY_MODE_STATIC);
- */
- }
-
- //RID b= _add_body(PhysicsServer2D::SHAPE_CIRCLE,Transform2D(0,Point2(101,140)));
- //ps->body_set_mode(b,PhysicsServer2D::BODY_MODE_STATIC);
-
- Point2 prev;
-
- Vector<Point2> parr;
- for (int i = 0; i < 30; i++) {
- Point2 p(i * 60, Math::randf() * 70 + 340);
- if (i > 0) {
- parr.push_back(prev);
- parr.push_back(p);
- }
- prev = p;
- }
-
- _add_concave(parr);
- //_add_world_boundary(Vector2(0.0,-1).normalized(),-300);
- //_add_world_boundary(Vector2(1,0).normalized(),50);
- //_add_world_boundary(Vector2(-1,0).normalized(),-600);
- }
-
- virtual bool process(double p_time) override {
- return false;
- }
- virtual void finalize() override {
- }
-
- TestPhysics2DMainLoop() {}
-};
-
-namespace TestPhysics2D {
-
-MainLoop *test() {
- return memnew(TestPhysics2DMainLoop);
-}
-} // namespace TestPhysics2D
diff --git a/tests/servers/test_physics_2d.h b/tests/servers/test_physics_2d.h
deleted file mode 100644
index 2ae1053a03..0000000000
--- a/tests/servers/test_physics_2d.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*************************************************************************/
-/* test_physics_2d.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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_PHYSICS_2D_H
-#define TEST_PHYSICS_2D_H
-
-class MainLoop;
-
-namespace TestPhysics2D {
-
-MainLoop *test();
-}
-
-#endif // TEST_PHYSICS_2D_H
diff --git a/tests/servers/test_physics_3d.cpp b/tests/servers/test_physics_3d.cpp
deleted file mode 100644
index 7cb74b1ee3..0000000000
--- a/tests/servers/test_physics_3d.cpp
+++ /dev/null
@@ -1,410 +0,0 @@
-/*************************************************************************/
-/* test_physics_3d.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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. */
-/*************************************************************************/
-
-#include "test_physics_3d.h"
-
-#include "core/math/convex_hull.h"
-#include "core/math/geometry_3d.h"
-#include "core/os/main_loop.h"
-#include "servers/physics_server_3d.h"
-#include "servers/rendering_server.h"
-
-class TestPhysics3DMainLoop : public MainLoop {
- GDCLASS(TestPhysics3DMainLoop, MainLoop);
-
- enum {
- LINK_COUNT = 20,
- };
-
- RID test_cube;
-
- RID plane;
- RID sphere;
- RID light;
- RID camera;
- RID mover;
- RID scenario;
- RID space;
-
- RID character;
-
- real_t ofs_x, ofs_y;
-
- Point2 joy_direction;
-
- List<RID> bodies;
- Map<PhysicsServer3D::ShapeType, RID> type_shape_map;
- Map<PhysicsServer3D::ShapeType, RID> type_mesh_map;
-
- void body_changed_transform(Object *p_state, RID p_visual_instance) {
- PhysicsDirectBodyState3D *state = (PhysicsDirectBodyState3D *)p_state;
- RenderingServer *vs = RenderingServer::get_singleton();
- Transform3D t = state->get_transform();
- vs->instance_set_transform(p_visual_instance, t);
- }
-
- bool quit;
-
-protected:
- RID create_body(PhysicsServer3D::ShapeType p_shape, PhysicsServer3D::BodyMode p_body, const Transform3D p_location, bool p_active_default = true, const Transform3D &p_shape_xform = Transform3D()) {
- RenderingServer *vs = RenderingServer::get_singleton();
- PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
-
- RID mesh_instance = vs->instance_create2(type_mesh_map[p_shape], scenario);
- RID body = ps->body_create();
- ps->body_set_mode(body, p_body);
- ps->body_set_state(body, PhysicsServer3D::BODY_STATE_SLEEPING, !p_active_default);
- ps->body_set_space(body, space);
- ps->body_set_param(body, PhysicsServer3D::BODY_PARAM_BOUNCE, 0.0);
- //todo set space
- ps->body_add_shape(body, type_shape_map[p_shape]);
- ps->body_set_force_integration_callback(body, callable_mp(this, &TestPhysics3DMainLoop::body_changed_transform), mesh_instance);
-
- ps->body_set_state(body, PhysicsServer3D::BODY_STATE_TRANSFORM, p_location);
- bodies.push_back(body);
-
- if (p_body == PhysicsServer3D::BODY_MODE_STATIC) {
- vs->instance_set_transform(mesh_instance, p_location);
- }
- return body;
- }
-
- RID create_world_boundary(const Plane &p_plane) {
- PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
-
- RID world_boundary_shape = ps->shape_create(PhysicsServer3D::SHAPE_WORLD_BOUNDARY);
- ps->shape_set_data(world_boundary_shape, p_plane);
-
- RID b = ps->body_create();
- ps->body_set_mode(b, PhysicsServer3D::BODY_MODE_STATIC);
-
- ps->body_set_space(b, space);
- ps->body_add_shape(b, world_boundary_shape);
- return b;
- }
-
- void configure_body(RID p_body, real_t p_mass, real_t p_friction, real_t p_bounce) {
- PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
- ps->body_set_param(p_body, PhysicsServer3D::BODY_PARAM_MASS, p_mass);
- ps->body_set_param(p_body, PhysicsServer3D::BODY_PARAM_FRICTION, p_friction);
- ps->body_set_param(p_body, PhysicsServer3D::BODY_PARAM_BOUNCE, p_bounce);
- }
-
- void initialize_shapes() {
- RenderingServer *vs = RenderingServer::get_singleton();
- PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
-
- /* SPHERE SHAPE */
- RID sphere_mesh = vs->make_sphere_mesh(10, 20, 0.5);
- type_mesh_map[PhysicsServer3D::SHAPE_SPHERE] = sphere_mesh;
-
- RID sphere_shape = ps->shape_create(PhysicsServer3D::SHAPE_SPHERE);
- ps->shape_set_data(sphere_shape, 0.5);
- type_shape_map[PhysicsServer3D::SHAPE_SPHERE] = sphere_shape;
-
- /* BOX SHAPE */
-
- Vector<Plane> box_planes = Geometry3D::build_box_planes(Vector3(0.5, 0.5, 0.5));
- RID box_mesh = vs->mesh_create();
- Geometry3D::MeshData box_data = Geometry3D::build_convex_mesh(box_planes);
- vs->mesh_add_surface_from_mesh_data(box_mesh, box_data);
- type_mesh_map[PhysicsServer3D::SHAPE_BOX] = box_mesh;
-
- RID box_shape = ps->shape_create(PhysicsServer3D::SHAPE_BOX);
- ps->shape_set_data(box_shape, Vector3(0.5, 0.5, 0.5));
- type_shape_map[PhysicsServer3D::SHAPE_BOX] = box_shape;
-
- /* CAPSULE SHAPE */
-
- Vector<Plane> capsule_planes = Geometry3D::build_capsule_planes(0.5, 0.7, 12, Vector3::AXIS_Z);
-
- RID capsule_mesh = vs->mesh_create();
- Geometry3D::MeshData capsule_data = Geometry3D::build_convex_mesh(capsule_planes);
- vs->mesh_add_surface_from_mesh_data(capsule_mesh, capsule_data);
-
- type_mesh_map[PhysicsServer3D::SHAPE_CAPSULE] = capsule_mesh;
-
- RID capsule_shape = ps->shape_create(PhysicsServer3D::SHAPE_CAPSULE);
- Dictionary capsule_params;
- capsule_params["radius"] = 0.5;
- capsule_params["height"] = 1.4;
- ps->shape_set_data(capsule_shape, capsule_params);
- type_shape_map[PhysicsServer3D::SHAPE_CAPSULE] = capsule_shape;
-
- /* CONVEX SHAPE */
-
- Vector<Plane> convex_planes = Geometry3D::build_cylinder_planes(0.5, 0.7, 5, Vector3::AXIS_Z);
-
- RID convex_mesh = vs->mesh_create();
- Geometry3D::MeshData convex_data = Geometry3D::build_convex_mesh(convex_planes);
- ConvexHullComputer::convex_hull(convex_data.vertices, convex_data);
- vs->mesh_add_surface_from_mesh_data(convex_mesh, convex_data);
-
- type_mesh_map[PhysicsServer3D::SHAPE_CONVEX_POLYGON] = convex_mesh;
-
- RID convex_shape = ps->shape_create(PhysicsServer3D::SHAPE_CONVEX_POLYGON);
- ps->shape_set_data(convex_shape, convex_data.vertices);
- type_shape_map[PhysicsServer3D::SHAPE_CONVEX_POLYGON] = convex_shape;
- }
-
- void make_trimesh(Vector<Vector3> p_faces, const Transform3D &p_xform = Transform3D()) {
- RenderingServer *vs = RenderingServer::get_singleton();
- PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
- RID trimesh_shape = ps->shape_create(PhysicsServer3D::SHAPE_CONCAVE_POLYGON);
- Dictionary trimesh_params;
- trimesh_params["faces"] = p_faces;
- trimesh_params["backface_collision"] = false;
- ps->shape_set_data(trimesh_shape, trimesh_params);
- Vector<Vector3> normals; // for drawing
- for (int i = 0; i < p_faces.size() / 3; i++) {
- Plane p(p_faces[i * 3 + 0], p_faces[i * 3 + 1], p_faces[i * 3 + 2]);
- normals.push_back(p.normal);
- normals.push_back(p.normal);
- normals.push_back(p.normal);
- }
-
- RID trimesh_mesh = vs->mesh_create();
- Array d;
- d.resize(RS::ARRAY_MAX);
- d[RS::ARRAY_VERTEX] = p_faces;
- d[RS::ARRAY_NORMAL] = normals;
- vs->mesh_add_surface_from_arrays(trimesh_mesh, RS::PRIMITIVE_TRIANGLES, d);
-
- RID triins = vs->instance_create2(trimesh_mesh, scenario);
-
- RID tribody = ps->body_create();
- ps->body_set_mode(tribody, PhysicsServer3D::BODY_MODE_STATIC);
- ps->body_set_space(tribody, space);
- //todo set space
- ps->body_add_shape(tribody, trimesh_shape);
- Transform3D tritrans = p_xform;
- ps->body_set_state(tribody, PhysicsServer3D::BODY_STATE_TRANSFORM, tritrans);
- vs->instance_set_transform(triins, tritrans);
- }
-
- void make_grid(int p_width, int p_height, real_t p_cellsize, real_t p_cellheight, const Transform3D &p_xform = Transform3D()) {
- Vector<Vector<real_t>> grid;
-
- grid.resize(p_width);
-
- for (int i = 0; i < p_width; i++) {
- grid.write[i].resize(p_height);
-
- for (int j = 0; j < p_height; j++) {
- grid.write[i].write[j] = 1.0 + Math::random(-p_cellheight, p_cellheight);
- }
- }
-
- Vector<Vector3> faces;
-
- for (int i = 1; i < p_width; i++) {
- for (int j = 1; j < p_height; j++) {
-#define MAKE_VERTEX(m_x, m_z) \
- faces.push_back(Vector3((m_x - p_width / 2) * p_cellsize, grid[m_x][m_z], (m_z - p_height / 2) * p_cellsize))
-
- MAKE_VERTEX(i, j - 1);
- MAKE_VERTEX(i, j);
- MAKE_VERTEX(i - 1, j);
-
- MAKE_VERTEX(i - 1, j - 1);
- MAKE_VERTEX(i, j - 1);
- MAKE_VERTEX(i - 1, j);
- }
- }
-
- make_trimesh(faces, p_xform);
- }
-
-public:
- virtual void input_event(const Ref<InputEvent> &p_event) {
- Ref<InputEventMouseMotion> mm = p_event;
- if (mm.is_valid() && (mm->get_button_mask() & MouseButton::MASK_MIDDLE) != MouseButton::NONE) {
- ofs_y -= mm->get_relative().y / 200.0;
- ofs_x += mm->get_relative().x / 200.0;
- }
-
- if (mm.is_valid() && (mm->get_button_mask() & MouseButton::MASK_LEFT) != MouseButton::NONE) {
- real_t y = -mm->get_relative().y / 20.0;
- real_t x = mm->get_relative().x / 20.0;
-
- if (mover.is_valid()) {
- PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
- Transform3D t = ps->body_get_state(mover, PhysicsServer3D::BODY_STATE_TRANSFORM);
- t.origin += Vector3(x, y, 0);
-
- ps->body_set_state(mover, PhysicsServer3D::BODY_STATE_TRANSFORM, t);
- }
- }
- }
-
- virtual void request_quit() {
- quit = true;
- }
- virtual void initialize() override {
- ofs_x = ofs_y = 0;
- initialize_shapes();
-
- PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
- space = ps->space_create();
- ps->space_set_active(space, true);
-
- RenderingServer *vs = RenderingServer::get_singleton();
-
- /* LIGHT */
- RID lightaux = vs->directional_light_create();
- scenario = vs->scenario_create();
- vs->light_set_shadow(lightaux, true);
- light = vs->instance_create2(lightaux, scenario);
- Transform3D t;
- t.rotate(Vector3(1.0, 0, 0), 0.6);
- vs->instance_set_transform(light, t);
-
- /* CAMERA */
-
- camera = vs->camera_create();
-
- RID viewport = vs->viewport_create();
- Size2i screen_size = DisplayServer::get_singleton()->window_get_size();
- vs->viewport_set_size(viewport, screen_size.x, screen_size.y);
- vs->viewport_attach_to_screen(viewport, Rect2(Vector2(), screen_size));
- vs->viewport_set_active(viewport, true);
- vs->viewport_attach_camera(viewport, camera);
- vs->viewport_set_scenario(viewport, scenario);
-
- vs->camera_set_perspective(camera, 60, 0.1, 40.0);
- vs->camera_set_transform(camera, Transform3D(Basis(), Vector3(0, 9, 12)));
-
- Transform3D gxf;
- gxf.basis.scale(Vector3(1.4, 0.4, 1.4));
- gxf.origin = Vector3(-2, 1, -2);
- make_grid(5, 5, 2.5, 1, gxf);
- test_fall();
- quit = false;
- }
- virtual bool physics_process(double p_time) override {
- if (mover.is_valid()) {
- static real_t joy_speed = 10;
- PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
- Transform3D t = ps->body_get_state(mover, PhysicsServer3D::BODY_STATE_TRANSFORM);
- t.origin += Vector3(joy_speed * joy_direction.x * p_time, -joy_speed * joy_direction.y * p_time, 0);
- ps->body_set_state(mover, PhysicsServer3D::BODY_STATE_TRANSFORM, t);
- };
-
- Transform3D cameratr;
- cameratr.rotate(Vector3(0, 1, 0), ofs_x);
- cameratr.rotate(Vector3(1, 0, 0), -ofs_y);
- cameratr.translate(Vector3(0, 2, 8));
- RenderingServer *vs = RenderingServer::get_singleton();
- vs->camera_set_transform(camera, cameratr);
-
- return quit;
- }
- virtual void finalize() override {
- }
-
- void test_joint() {
- }
-
- void test_hinge() {
- }
-
- void test_character() {
- RenderingServer *vs = RenderingServer::get_singleton();
- PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
-
- Vector<Plane> capsule_planes = Geometry3D::build_capsule_planes(0.5, 1, 12, 5, Vector3::AXIS_Y);
-
- RID capsule_mesh = vs->mesh_create();
- Geometry3D::MeshData capsule_data = Geometry3D::build_convex_mesh(capsule_planes);
- vs->mesh_add_surface_from_mesh_data(capsule_mesh, capsule_data);
- type_mesh_map[PhysicsServer3D::SHAPE_CAPSULE] = capsule_mesh;
-
- RID capsule_shape = ps->shape_create(PhysicsServer3D::SHAPE_CAPSULE);
- Dictionary capsule_params;
- capsule_params["radius"] = 0.5;
- capsule_params["height"] = 1;
- Transform3D shape_xform;
- shape_xform.rotate(Vector3(1, 0, 0), Math_PI / 2.0);
- //shape_xform.origin=Vector3(1,1,1);
- ps->shape_set_data(capsule_shape, capsule_params);
-
- RID mesh_instance = vs->instance_create2(capsule_mesh, scenario);
- character = ps->body_create();
- ps->body_set_mode(character, PhysicsServer3D::BODY_MODE_DYNAMIC_LINEAR);
- ps->body_set_space(character, space);
- //todo add space
- ps->body_add_shape(character, capsule_shape);
- ps->body_set_force_integration_callback(character, callable_mp(this, &TestPhysics3DMainLoop::body_changed_transform), mesh_instance);
-
- ps->body_set_state(character, PhysicsServer3D::BODY_STATE_TRANSFORM, Transform3D(Basis(), Vector3(-2, 5, -2)));
- bodies.push_back(character);
- }
-
- void test_fall() {
- for (int i = 0; i < 35; i++) {
- static const PhysicsServer3D::ShapeType shape_idx[] = {
- PhysicsServer3D::SHAPE_CAPSULE,
- PhysicsServer3D::SHAPE_BOX,
- PhysicsServer3D::SHAPE_SPHERE,
- PhysicsServer3D::SHAPE_CONVEX_POLYGON
- };
-
- PhysicsServer3D::ShapeType type = shape_idx[i % 4];
-
- Transform3D t;
-
- t.origin = Vector3(0.0 * i, 3.5 + 1.1 * i, 0.7 + 0.0 * i);
- t.basis.rotate(Vector3(0.2, -1, 0), Math_PI / 2 * 0.6);
-
- create_body(type, PhysicsServer3D::BODY_MODE_DYNAMIC, t);
- }
-
- create_world_boundary(Plane(Vector3(0, 1, 0), -1));
- }
-
- void test_activate() {
- create_body(PhysicsServer3D::SHAPE_BOX, PhysicsServer3D::BODY_MODE_DYNAMIC, Transform3D(Basis(), Vector3(0, 2, 0)), true);
- create_world_boundary(Plane(Vector3(0, 1, 0), -1));
- }
-
- virtual bool process(double p_time) override {
- return false;
- }
-
- TestPhysics3DMainLoop() {
- }
-};
-
-namespace TestPhysics3D {
-
-MainLoop *test() {
- return memnew(TestPhysics3DMainLoop);
-}
-} // namespace TestPhysics3D
diff --git a/tests/servers/test_physics_3d.h b/tests/servers/test_physics_3d.h
deleted file mode 100644
index b86327cdb4..0000000000
--- a/tests/servers/test_physics_3d.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*************************************************************************/
-/* test_physics_3d.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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_PHYSICS_H
-#define TEST_PHYSICS_H
-
-class MainLoop;
-
-namespace TestPhysics3D {
-
-MainLoop *test();
-}
-
-#endif
diff --git a/tests/servers/test_render.cpp b/tests/servers/test_render.cpp
deleted file mode 100644
index 183f049238..0000000000
--- a/tests/servers/test_render.cpp
+++ /dev/null
@@ -1,232 +0,0 @@
-/*************************************************************************/
-/* test_render.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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. */
-/*************************************************************************/
-
-#include "test_render.h"
-
-#include "core/math/convex_hull.h"
-#include "core/os/main_loop.h"
-#include "servers/rendering_server.h"
-
-#define OBJECT_COUNT 50
-
-namespace TestRender {
-
-class TestMainLoop : public MainLoop {
- RID test_cube;
- RID instance;
- RID camera;
- RID viewport;
- RID light;
- RID scenario;
-
- struct InstanceInfo {
- RID instance;
- Transform3D base;
- Vector3 rot_axis;
- };
-
- List<InstanceInfo> instances;
-
- float ofs;
- bool quit;
-
-protected:
-public:
- virtual void input_event(const Ref<InputEvent> &p_event) {
- if (p_event->is_pressed()) {
- quit = true;
- }
- }
-
- virtual void init() {
- print_line("INITIALIZING TEST RENDER");
- RenderingServer *vs = RenderingServer::get_singleton();
- test_cube = vs->get_test_cube();
- scenario = vs->scenario_create();
-
- Vector<Vector3> vts;
-
- /*
- Vector<Plane> sp = Geometry3D::build_sphere_planes(2,5,5);
- Geometry3D::MeshData md2 = Geometry3D::build_convex_mesh(sp);
- vts=md2.vertices;
-*/
- /*
-
- static const int s = 20;
- for(int i=0;i<s;i++) {
- Basis rot(Vector3(0,1,0),i*Math_PI/s);
-
- for(int j=0;j<s;j++) {
- Vector3 v;
- v.x=Math::sin(j*Math_PI*2/s);
- v.y=Math::cos(j*Math_PI*2/s);
-
- vts.push_back( rot.xform(v*2 ) );
- }
- }*/
- /*for(int i=0;i<100;i++) {
- vts.push_back( Vector3(Math::randf()*2-1.0,Math::randf()*2-1.0,Math::randf()*2-1.0).normalized()*2);
- }*/
- /*
- vts.push_back(Vector3(0,0,1));
- vts.push_back(Vector3(0,0,-1));
- vts.push_back(Vector3(0,1,0));
- vts.push_back(Vector3(0,-1,0));
- vts.push_back(Vector3(1,0,0));
- vts.push_back(Vector3(-1,0,0));*/
-
- vts.push_back(Vector3(1, 1, 1));
- vts.push_back(Vector3(1, -1, 1));
- vts.push_back(Vector3(-1, 1, 1));
- vts.push_back(Vector3(-1, -1, 1));
- vts.push_back(Vector3(1, 1, -1));
- vts.push_back(Vector3(1, -1, -1));
- vts.push_back(Vector3(-1, 1, -1));
- vts.push_back(Vector3(-1, -1, -1));
-
- Geometry3D::MeshData md;
- Error err = ConvexHullComputer::convex_hull(vts, md);
- print_line("ERR: " + itos(err));
- test_cube = vs->mesh_create();
- vs->mesh_add_surface_from_mesh_data(test_cube, md);
- //vs->scenario_set_debug(scenario,RS::SCENARIO_DEBUG_WIREFRAME);
-
- /*
- RID sm = vs->shader_create();
- //vs->shader_set_fragment_code(sm,"OUT_ALPHA=mod(TIME,1);");
- //vs->shader_set_vertex_code(sm,"OUT_VERTEX=IN_VERTEX*mod(TIME,1);");
- vs->shader_set_fragment_code(sm,"OUT_DIFFUSE=vec3(1,0,1);OUT_GLOW=abs(sin(TIME));");
- RID tcmat = vs->mesh_surface_get_material(test_cube,0);
- vs->material_set_shader(tcmat,sm);
- */
-
- List<String> cmdline = OS::get_singleton()->get_cmdline_args();
- int object_count = OBJECT_COUNT;
- if (cmdline.size() > 0 && cmdline[cmdline.size() - 1].to_int()) {
- object_count = cmdline[cmdline.size() - 1].to_int();
- };
-
- for (int i = 0; i < object_count; i++) {
- InstanceInfo ii;
-
- ii.instance = vs->instance_create2(test_cube, scenario);
-
- ii.base.translate(Math::random(-20, 20), Math::random(-20, 20), Math::random(-20, 18));
- ii.base.rotate(Vector3(0, 1, 0), Math::randf() * Math_PI);
- ii.base.rotate(Vector3(1, 0, 0), Math::randf() * Math_PI);
- vs->instance_set_transform(ii.instance, ii.base);
-
- ii.rot_axis = Vector3(Math::random(-1, 1), Math::random(-1, 1), Math::random(-1, 1)).normalized();
-
- instances.push_back(ii);
- }
-
- camera = vs->camera_create();
-
- // vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
-
- viewport = vs->viewport_create();
- Size2i screen_size = DisplayServer::get_singleton()->window_get_size();
- vs->viewport_set_size(viewport, screen_size.x, screen_size.y);
- vs->viewport_attach_to_screen(viewport, Rect2(Vector2(), screen_size));
- vs->viewport_set_active(viewport, true);
- vs->viewport_attach_camera(viewport, camera);
- vs->viewport_set_scenario(viewport, scenario);
- vs->camera_set_transform(camera, Transform3D(Basis(), Vector3(0, 3, 30)));
- vs->camera_set_perspective(camera, 60, 0.1, 1000);
-
- /*
- RID lightaux = vs->light_create( RenderingServer::LIGHT_OMNI );
- vs->light_set_var( lightaux, RenderingServer::LIGHT_VAR_RADIUS, 80 );
- vs->light_set_var( lightaux, RenderingServer::LIGHT_VAR_ATTENUATION, 1 );
- vs->light_set_var( lightaux, RenderingServer::LIGHT_VAR_ENERGY, 1.5 );
- light = vs->instance_create( lightaux );
- */
- RID lightaux;
-
- lightaux = vs->directional_light_create();
- //vs->light_set_color( lightaux, RenderingServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
- vs->light_set_color(lightaux, Color(1.0, 1.0, 1.0));
- //vs->light_set_shadow( lightaux, true );
- light = vs->instance_create2(lightaux, scenario);
- Transform3D lla;
- //lla.set_look_at(Vector3(),Vector3(1, -1, 1));
- lla.basis = Basis::looking_at(Vector3(0.0, -0.836026, -0.548690));
-
- vs->instance_set_transform(light, lla);
-
- lightaux = vs->omni_light_create();
- //vs->light_set_color( lightaux, RenderingServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,1.0) );
- vs->light_set_color(lightaux, Color(1.0, 1.0, 0.0));
- vs->light_set_param(lightaux, RenderingServer::LIGHT_PARAM_RANGE, 4);
- vs->light_set_param(lightaux, RenderingServer::LIGHT_PARAM_ENERGY, 8);
- //vs->light_set_shadow( lightaux, true );
- //light = vs->instance_create( lightaux );
-
- ofs = 0;
- quit = false;
- }
- virtual bool iteration(double p_time) {
- RenderingServer *vs = RenderingServer::get_singleton();
- //Transform3D t;
- //t.rotate(Vector3(0, 1, 0), ofs);
- //t.translate(Vector3(0,0,20 ));
- //vs->camera_set_transform(camera, t);
-
- ofs += p_time * 0.05;
-
- //return quit;
-
- for (const InstanceInfo &E : instances) {
- Transform3D pre(Basis(E.rot_axis, ofs), Vector3());
- vs->instance_set_transform(E.instance, pre * E.base);
- /*
- if( !E->next() ) {
- vs->free( E.instance );
- instances.erase(E );
- }*/
- }
-
- return quit;
- }
-
- virtual bool idle(double p_time) {
- return quit;
- }
-
- virtual void finish() {
- }
-};
-
-MainLoop *test() {
- return memnew(TestMainLoop);
-}
-} // namespace TestRender
diff --git a/tests/servers/test_render.h b/tests/servers/test_render.h
deleted file mode 100644
index 1d773cb347..0000000000
--- a/tests/servers/test_render.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*************************************************************************/
-/* test_render.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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_RENDER_H
-#define TEST_RENDER_H
-
-class MainLoop;
-
-namespace TestRender {
-
-MainLoop *test();
-}
-
-#endif // TEST_RENDER_H
diff --git a/tests/servers/test_shader_lang.cpp b/tests/servers/test_shader_lang.cpp
deleted file mode 100644
index 1f8f395e64..0000000000
--- a/tests/servers/test_shader_lang.cpp
+++ /dev/null
@@ -1,367 +0,0 @@
-/*************************************************************************/
-/* test_shader_lang.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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. */
-/*************************************************************************/
-
-#include "test_shader_lang.h"
-
-#include "core/os/main_loop.h"
-#include "core/os/os.h"
-#include "servers/rendering/shader_language.h"
-
-typedef ShaderLanguage SL;
-
-namespace TestShaderLang {
-
-static String _mktab(int p_level) {
- String tb;
- for (int i = 0; i < p_level; i++) {
- tb += "\t";
- }
-
- return tb;
-}
-
-static String _typestr(SL::DataType p_type) {
- return ShaderLanguage::get_datatype_name(p_type);
-}
-
-static String _prestr(SL::DataPrecision p_pres) {
- switch (p_pres) {
- case SL::PRECISION_LOWP:
- return "lowp ";
- case SL::PRECISION_MEDIUMP:
- return "mediump ";
- case SL::PRECISION_HIGHP:
- return "highp ";
- case SL::PRECISION_DEFAULT:
- return "";
- }
- return "";
-}
-
-static String _opstr(SL::Operator p_op) {
- return ShaderLanguage::get_operator_text(p_op);
-}
-
-static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value> &p_values) {
- switch (p_type) {
- case SL::TYPE_BOOL:
- return p_values[0].boolean ? "true" : "false";
- case SL::TYPE_BVEC2:
- return String() + "bvec2(" + (p_values[0].boolean ? "true" : "false") + (p_values[1].boolean ? "true" : "false") + ")";
- case SL::TYPE_BVEC3:
- return String() + "bvec3(" + (p_values[0].boolean ? "true" : "false") + "," + (p_values[1].boolean ? "true" : "false") + "," + (p_values[2].boolean ? "true" : "false") + ")";
- case SL::TYPE_BVEC4:
- return String() + "bvec4(" + (p_values[0].boolean ? "true" : "false") + "," + (p_values[1].boolean ? "true" : "false") + "," + (p_values[2].boolean ? "true" : "false") + "," + (p_values[3].boolean ? "true" : "false") + ")";
- case SL::TYPE_INT:
- return rtos(p_values[0].sint);
- case SL::TYPE_IVEC2:
- return String() + "ivec2(" + rtos(p_values[0].sint) + "," + rtos(p_values[1].sint) + ")";
- case SL::TYPE_IVEC3:
- return String() + "ivec3(" + rtos(p_values[0].sint) + "," + rtos(p_values[1].sint) + "," + rtos(p_values[2].sint) + ")";
- case SL::TYPE_IVEC4:
- return String() + "ivec4(" + rtos(p_values[0].sint) + "," + rtos(p_values[1].sint) + "," + rtos(p_values[2].sint) + "," + rtos(p_values[3].sint) + ")";
- case SL::TYPE_UINT:
- return rtos(p_values[0].real);
- case SL::TYPE_UVEC2:
- return String() + "uvec2(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + ")";
- case SL::TYPE_UVEC3:
- return String() + "uvec3(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + ")";
- case SL::TYPE_UVEC4:
- return String() + "uvec4(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + "," + rtos(p_values[3].real) + ")";
- case SL::TYPE_FLOAT:
- return rtos(p_values[0].real);
- case SL::TYPE_VEC2:
- return String() + "vec2(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + ")";
- case SL::TYPE_VEC3:
- return String() + "vec3(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + ")";
- case SL::TYPE_VEC4:
- return String() + "vec4(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + "," + rtos(p_values[3].real) + ")";
- default:
- ERR_FAIL_V(String());
- }
-}
-
-static String dump_node_code(SL::Node *p_node, int p_level) {
- String code;
-
- switch (p_node->type) {
- case SL::Node::TYPE_SHADER: {
- SL::ShaderNode *pnode = (SL::ShaderNode *)p_node;
-
- for (const KeyValue<StringName, SL::ShaderNode::Uniform> &E : pnode->uniforms) {
- String ucode = "uniform ";
- ucode += _prestr(E.value.precision);
- ucode += _typestr(E.value.type);
- ucode += " " + String(E.key);
- if (E.value.array_size > 0) {
- ucode += "[";
- ucode += itos(E.value.array_size);
- ucode += "]";
- } else {
- if (E.value.default_value.size()) {
- ucode += " = " + get_constant_text(E.value.type, E.value.default_value);
- }
-
- static const char *hint_name[SL::ShaderNode::Uniform::HINT_MAX] = {
- "",
- "color",
- "range",
- "albedo",
- "normal",
- "black",
- "white"
- };
-
- if (E.value.hint) {
- ucode += " : " + String(hint_name[E.value.hint]);
- }
- }
-
- code += ucode + "\n";
- }
-
- for (const KeyValue<StringName, SL::ShaderNode::Varying> &E : pnode->varyings) {
- String vcode = "varying ";
- vcode += _prestr(E.value.precision);
- vcode += _typestr(E.value.type);
- vcode += " " + String(E.key);
-
- code += vcode + "\n";
- }
- for (int i = 0; i < pnode->functions.size(); i++) {
- SL::FunctionNode *fnode = pnode->functions[i].function;
-
- String header;
- header = _typestr(fnode->return_type) + " " + fnode->name + "(";
- for (int j = 0; j < fnode->arguments.size(); j++) {
- if (j > 0) {
- header += ", ";
- }
- header += _prestr(fnode->arguments[j].precision) + _typestr(fnode->arguments[j].type) + " " + fnode->arguments[j].name;
- }
-
- header += ")\n";
- code += header;
- code += dump_node_code(fnode->body, p_level + 1);
- }
-
- //code+=dump_node_code(pnode->body,p_level);
- } break;
- case SL::Node::TYPE_STRUCT: {
- } break;
- case SL::Node::TYPE_FUNCTION: {
- } break;
- case SL::Node::TYPE_BLOCK: {
- SL::BlockNode *bnode = (SL::BlockNode *)p_node;
-
- //variables
- code += _mktab(p_level - 1) + "{\n";
- for (const KeyValue<StringName, SL::BlockNode::Variable> &E : bnode->variables) {
- code += _mktab(p_level) + _prestr(E.value.precision) + _typestr(E.value.type) + " " + E.key + ";\n";
- }
-
- for (int i = 0; i < bnode->statements.size(); i++) {
- String scode = dump_node_code(bnode->statements[i], p_level);
-
- if (bnode->statements[i]->type == SL::Node::TYPE_CONTROL_FLOW) {
- code += scode; //use directly
- } else {
- code += _mktab(p_level) + scode + ";\n";
- }
- }
- code += _mktab(p_level - 1) + "}\n";
-
- } break;
- case SL::Node::TYPE_VARIABLE: {
- SL::VariableNode *vnode = (SL::VariableNode *)p_node;
- code = vnode->name;
-
- } break;
- case SL::Node::TYPE_VARIABLE_DECLARATION: {
- // FIXME: Implement
- } break;
- case SL::Node::TYPE_ARRAY: {
- SL::ArrayNode *vnode = (SL::ArrayNode *)p_node;
- code = vnode->name;
- } break;
- case SL::Node::TYPE_ARRAY_DECLARATION: {
- // FIXME: Implement
- } break;
- case SL::Node::TYPE_ARRAY_CONSTRUCT: {
- // FIXME: Implement
- } break;
- case SL::Node::TYPE_CONSTANT: {
- SL::ConstantNode *cnode = (SL::ConstantNode *)p_node;
- return get_constant_text(cnode->datatype, cnode->values);
-
- } break;
- case SL::Node::TYPE_OPERATOR: {
- SL::OperatorNode *onode = (SL::OperatorNode *)p_node;
-
- switch (onode->op) {
- case SL::OP_ASSIGN:
- case SL::OP_ASSIGN_ADD:
- case SL::OP_ASSIGN_SUB:
- case SL::OP_ASSIGN_MUL:
- case SL::OP_ASSIGN_DIV:
- case SL::OP_ASSIGN_SHIFT_LEFT:
- case SL::OP_ASSIGN_SHIFT_RIGHT:
- case SL::OP_ASSIGN_MOD:
- case SL::OP_ASSIGN_BIT_AND:
- case SL::OP_ASSIGN_BIT_OR:
- case SL::OP_ASSIGN_BIT_XOR:
- code = dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op) + dump_node_code(onode->arguments[1], p_level);
- break;
- case SL::OP_BIT_INVERT:
- case SL::OP_NEGATE:
- case SL::OP_NOT:
- case SL::OP_DECREMENT:
- case SL::OP_INCREMENT:
- code = _opstr(onode->op) + dump_node_code(onode->arguments[0], p_level);
- break;
- case SL::OP_POST_DECREMENT:
- case SL::OP_POST_INCREMENT:
- code = dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op);
- break;
- case SL::OP_CALL:
- case SL::OP_CONSTRUCT:
- code = dump_node_code(onode->arguments[0], p_level) + "(";
- for (int i = 1; i < onode->arguments.size(); i++) {
- if (i > 1) {
- code += ", ";
- }
- code += dump_node_code(onode->arguments[i], p_level);
- }
- code += ")";
- break;
- case SL::OP_EMPTY:
- break;
- default: {
- code = "(" + dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op) + dump_node_code(onode->arguments[1], p_level) + ")";
- break;
- }
- }
-
- } break;
- case SL::Node::TYPE_CONTROL_FLOW: {
- SL::ControlFlowNode *cfnode = (SL::ControlFlowNode *)p_node;
- if (cfnode->flow_op == SL::FLOW_OP_IF) {
- code += _mktab(p_level) + "if (" + dump_node_code(cfnode->expressions[0], p_level) + ")\n";
- code += dump_node_code(cfnode->blocks[0], p_level + 1);
- if (cfnode->blocks.size() == 2) {
- code += _mktab(p_level) + "else\n";
- code += dump_node_code(cfnode->blocks[1], p_level + 1);
- }
-
- } else if (cfnode->flow_op == SL::FLOW_OP_RETURN) {
- if (cfnode->blocks.size()) {
- code = "return " + dump_node_code(cfnode->blocks[0], p_level);
- } else {
- code = "return";
- }
- }
-
- } break;
- case SL::Node::TYPE_MEMBER: {
- SL::MemberNode *mnode = (SL::MemberNode *)p_node;
- code = dump_node_code(mnode->owner, p_level) + "." + mnode->name;
-
- } break;
- }
-
- return code;
-}
-
-static Error recreate_code(void *p_str, SL::ShaderNode *p_program) {
- String *str = (String *)p_str;
-
- *str = dump_node_code(p_program, 0);
-
- return OK;
-}
-
-MainLoop *test() {
- List<String> cmdlargs = OS::get_singleton()->get_cmdline_args();
-
- if (cmdlargs.is_empty()) {
- //try editor!
- print_line("usage: godot -test shader_lang <shader>");
- return nullptr;
- }
-
- String test = cmdlargs.back()->get();
-
- FileAccess *fa = FileAccess::open(test, FileAccess::READ);
-
- if (!fa) {
- ERR_FAIL_V(nullptr);
- }
-
- String code;
-
- while (true) {
- char32_t c = fa->get_8();
- if (fa->eof_reached()) {
- break;
- }
- code += c;
- }
-
- SL sl;
- print_line("tokens:\n\n" + sl.token_debug(code));
-
- Map<StringName, SL::FunctionInfo> dt;
- dt["fragment"].built_ins["ALBEDO"] = SL::TYPE_VEC3;
- dt["fragment"].can_discard = true;
-
- Vector<StringName> rm;
- rm.push_back("popo");
- Set<String> types;
- types.insert("spatial");
-
- ShaderLanguage::ShaderCompileInfo info;
- info.functions = dt;
- info.render_modes = rm;
- info.shader_types = types;
-
- Error err = sl.compile(code, info);
-
- if (err) {
- print_line("Error at line: " + rtos(sl.get_error_line()) + ": " + sl.get_error_text());
- return nullptr;
- } else {
- String code2;
- recreate_code(&code2, sl.get_shader());
- print_line("code:\n\n" + code2);
- }
-
- return nullptr;
-}
-} // namespace TestShaderLang
diff --git a/tests/servers/test_shader_lang.h b/tests/servers/test_shader_lang.h
deleted file mode 100644
index de7ec002b6..0000000000
--- a/tests/servers/test_shader_lang.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*************************************************************************/
-/* test_shader_lang.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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_SHADER_LANG_H
-#define TEST_SHADER_LANG_H
-
-class MainLoop;
-
-namespace TestShaderLang {
-
-MainLoop *test();
-}
-
-#endif // TEST_SHADER_LANG_H
diff --git a/tests/servers/test_text_server.h b/tests/servers/test_text_server.h
index 4edffe3711..61207216fc 100644
--- a/tests/servers/test_text_server.h
+++ b/tests/servers/test_text_server.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -28,11 +28,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifdef TOOLS_ENABLED
-
#ifndef TEST_TEXT_SERVER_H
#define TEST_TEXT_SERVER_H
+#ifdef TOOLS_ENABLED
+
#include "editor/builtin_fonts.gen.h"
#include "servers/text_server.h"
#include "tests/test_macros.h"
@@ -46,10 +46,14 @@ TEST_SUITE("[[TextServer]") {
Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(i);
TEST_FAIL_COND(ts.is_null(), "Invalid TS interface.");
+ if (!ts->has_feature(TextServer::FEATURE_FONT_DYNAMIC)) {
+ continue;
+ }
+
RID font = ts->create_font();
ts->font_set_data_ptr(font, _font_NotoSans_Regular, _font_NotoSans_Regular_size);
TEST_FAIL_COND(font == RID(), "Loading font failed.");
- ts->free(font);
+ ts->free_rid(font);
}
}
@@ -58,12 +62,16 @@ TEST_SUITE("[[TextServer]") {
Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(i);
TEST_FAIL_COND(ts.is_null(), "Invalid TS interface.");
+ if (!ts->has_feature(TextServer::FEATURE_FONT_DYNAMIC) || !ts->has_feature(TextServer::FEATURE_SIMPLE_LAYOUT)) {
+ continue;
+ }
+
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);
- Vector<RID> font;
+ Array font;
font.push_back(font1);
font.push_back(font2);
@@ -93,10 +101,10 @@ TEST_SUITE("[[TextServer]") {
TEST_FAIL_COND(glyphs[j].font_size != 16, "Incorrect glyph font size.");
}
- ts->free(ctx);
+ ts->free_rid(ctx);
for (int j = 0; j < font.size(); j++) {
- ts->free(font[j]);
+ ts->free_rid(font[j]);
}
font.clear();
}
@@ -107,7 +115,7 @@ TEST_SUITE("[[TextServer]") {
Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(i);
TEST_FAIL_COND(ts.is_null(), "Invalid TS interface.");
- if (!ts->has_feature(TextServer::FEATURE_BIDI_LAYOUT)) {
+ if (!ts->has_feature(TextServer::FEATURE_FONT_DYNAMIC) || !ts->has_feature(TextServer::FEATURE_BIDI_LAYOUT)) {
continue;
}
@@ -116,7 +124,7 @@ TEST_SUITE("[[TextServer]") {
RID font2 = ts->create_font();
ts->font_set_data_ptr(font2, _font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size);
- Vector<RID> font;
+ Array font;
font.push_back(font1);
font.push_back(font2);
@@ -145,10 +153,220 @@ TEST_SUITE("[[TextServer]") {
}
}
- ts->free(ctx);
+ ts->free_rid(ctx);
for (int j = 0; j < font.size(); j++) {
- ts->free(font[j]);
+ ts->free_rid(font[j]);
+ }
+ font.clear();
+ }
+ }
+
+ SUBCASE("[TextServer] Text layout: Line break and align points") {
+ for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
+ Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(i);
+ TEST_FAIL_COND(ts.is_null(), "Invalid TS interface.");
+
+ if (!ts->has_feature(TextServer::FEATURE_FONT_DYNAMIC) || !ts->has_feature(TextServer::FEATURE_SIMPLE_LAYOUT)) {
+ continue;
+ }
+
+ 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);
+ RID font3 = ts->create_font();
+ ts->font_set_data_ptr(font3, _font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size);
+
+ Array font;
+ font.push_back(font1);
+ font.push_back(font2);
+ font.push_back(font3);
+
+ {
+ String test = U"Test test long text long text\n";
+ RID ctx = ts->create_shaped_text();
+ TEST_FAIL_COND(ctx == RID(), "Creating text buffer failed.");
+ bool ok = ts->shaped_text_add_string(ctx, test, font, 16);
+ TEST_FAIL_COND(!ok, "Adding text to the buffer failed.");
+ ts->shaped_text_update_breaks(ctx);
+ ts->shaped_text_update_justification_ops(ctx);
+
+ const Glyph *glyphs = ts->shaped_text_get_glyphs(ctx);
+ int gl_size = ts->shaped_text_get_glyph_count(ctx);
+
+ TEST_FAIL_COND(gl_size != 30, "Invalid glyph count.");
+ for (int j = 0; j < gl_size; j++) {
+ bool hard = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_HARD) == TextServer::GRAPHEME_IS_BREAK_HARD;
+ bool soft = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_SOFT) == TextServer::GRAPHEME_IS_BREAK_SOFT;
+ bool space = (glyphs[j].flags & TextServer::GRAPHEME_IS_SPACE) == TextServer::GRAPHEME_IS_SPACE;
+ bool virt = (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) == TextServer::GRAPHEME_IS_VIRTUAL;
+ bool elo = (glyphs[j].flags & TextServer::GRAPHEME_IS_ELONGATION) == TextServer::GRAPHEME_IS_ELONGATION;
+ if (j == 4 || j == 9 || j == 14 || j == 19 || j == 24) {
+ TEST_FAIL_COND((!soft || !space || hard || virt || elo), "Invalid glyph flags.");
+ } else if (j == 29) {
+ TEST_FAIL_COND((soft || !space || !hard || virt || elo), "Invalid glyph flags.");
+ } else {
+ TEST_FAIL_COND((soft || space || hard || virt || elo), "Invalid glyph flags.");
+ }
+ }
+ ts->free_rid(ctx);
+ }
+
+ {
+ String test = U"الحمـد";
+ RID ctx = ts->create_shaped_text();
+ TEST_FAIL_COND(ctx == RID(), "Creating text buffer failed.");
+ bool ok = ts->shaped_text_add_string(ctx, test, font, 16);
+ TEST_FAIL_COND(!ok, "Adding text to the buffer failed.");
+ ts->shaped_text_update_breaks(ctx);
+
+ const Glyph *glyphs = ts->shaped_text_get_glyphs(ctx);
+ int gl_size = ts->shaped_text_get_glyph_count(ctx);
+ TEST_FAIL_COND(gl_size != 6, "Invalid glyph count.");
+ for (int j = 0; j < gl_size; j++) {
+ bool hard = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_HARD) == TextServer::GRAPHEME_IS_BREAK_HARD;
+ bool soft = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_SOFT) == TextServer::GRAPHEME_IS_BREAK_SOFT;
+ bool space = (glyphs[j].flags & TextServer::GRAPHEME_IS_SPACE) == TextServer::GRAPHEME_IS_SPACE;
+ bool virt = (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) == TextServer::GRAPHEME_IS_VIRTUAL;
+ bool elo = (glyphs[j].flags & TextServer::GRAPHEME_IS_ELONGATION) == TextServer::GRAPHEME_IS_ELONGATION;
+ TEST_FAIL_COND((soft || space || hard || virt || elo), "Invalid glyph flags.");
+ }
+
+ if (ts->has_feature(TextServer::FEATURE_KASHIDA_JUSTIFICATION)) {
+ ts->shaped_text_update_justification_ops(ctx);
+
+ glyphs = ts->shaped_text_get_glyphs(ctx);
+ gl_size = ts->shaped_text_get_glyph_count(ctx);
+
+ TEST_FAIL_COND(gl_size != 6, "Invalid glyph count.");
+ for (int j = 0; j < gl_size; j++) {
+ bool hard = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_HARD) == TextServer::GRAPHEME_IS_BREAK_HARD;
+ bool soft = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_SOFT) == TextServer::GRAPHEME_IS_BREAK_SOFT;
+ bool space = (glyphs[j].flags & TextServer::GRAPHEME_IS_SPACE) == TextServer::GRAPHEME_IS_SPACE;
+ bool virt = (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) == TextServer::GRAPHEME_IS_VIRTUAL;
+ bool elo = (glyphs[j].flags & TextServer::GRAPHEME_IS_ELONGATION) == TextServer::GRAPHEME_IS_ELONGATION;
+ if (j == 1) {
+ TEST_FAIL_COND((soft || space || hard || virt || !elo), "Invalid glyph flags.");
+ } else {
+ TEST_FAIL_COND((soft || space || hard || virt || elo), "Invalid glyph flags.");
+ }
+ }
+ }
+ ts->free_rid(ctx);
+ }
+
+ {
+ String test = U"الحمـد الرياضي العربي";
+ RID ctx = ts->create_shaped_text();
+ TEST_FAIL_COND(ctx == RID(), "Creating text buffer failed.");
+ bool ok = ts->shaped_text_add_string(ctx, test, font, 16);
+ TEST_FAIL_COND(!ok, "Adding text to the buffer failed.");
+ ts->shaped_text_update_breaks(ctx);
+
+ const Glyph *glyphs = ts->shaped_text_get_glyphs(ctx);
+ int gl_size = ts->shaped_text_get_glyph_count(ctx);
+
+ TEST_FAIL_COND(gl_size != 21, "Invalid glyph count.");
+ for (int j = 0; j < gl_size; j++) {
+ bool hard = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_HARD) == TextServer::GRAPHEME_IS_BREAK_HARD;
+ bool soft = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_SOFT) == TextServer::GRAPHEME_IS_BREAK_SOFT;
+ bool space = (glyphs[j].flags & TextServer::GRAPHEME_IS_SPACE) == TextServer::GRAPHEME_IS_SPACE;
+ bool virt = (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) == TextServer::GRAPHEME_IS_VIRTUAL;
+ bool elo = (glyphs[j].flags & TextServer::GRAPHEME_IS_ELONGATION) == TextServer::GRAPHEME_IS_ELONGATION;
+ if (j == 6 || j == 14) {
+ TEST_FAIL_COND((!soft || !space || hard || virt || elo), "Invalid glyph flags.");
+ } else {
+ TEST_FAIL_COND((soft || space || hard || virt || elo), "Invalid glyph flags.");
+ }
+ }
+
+ if (ts->has_feature(TextServer::FEATURE_KASHIDA_JUSTIFICATION)) {
+ ts->shaped_text_update_justification_ops(ctx);
+
+ glyphs = ts->shaped_text_get_glyphs(ctx);
+ gl_size = ts->shaped_text_get_glyph_count(ctx);
+
+ TEST_FAIL_COND(gl_size != 23, "Invalid glyph count.");
+ for (int j = 0; j < gl_size; j++) {
+ bool hard = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_HARD) == TextServer::GRAPHEME_IS_BREAK_HARD;
+ bool soft = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_SOFT) == TextServer::GRAPHEME_IS_BREAK_SOFT;
+ bool space = (glyphs[j].flags & TextServer::GRAPHEME_IS_SPACE) == TextServer::GRAPHEME_IS_SPACE;
+ bool virt = (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) == TextServer::GRAPHEME_IS_VIRTUAL;
+ bool elo = (glyphs[j].flags & TextServer::GRAPHEME_IS_ELONGATION) == TextServer::GRAPHEME_IS_ELONGATION;
+ if (j == 7 || j == 16) {
+ TEST_FAIL_COND((!soft || !space || hard || virt || elo), "Invalid glyph flags.");
+ } else if (j == 3 || j == 9) {
+ TEST_FAIL_COND((soft || space || hard || !virt || !elo), "Invalid glyph flags.");
+ } else if (j == 18) {
+ TEST_FAIL_COND((soft || space || hard || virt || !elo), "Invalid glyph flags.");
+ } else {
+ TEST_FAIL_COND((soft || space || hard || virt || elo), "Invalid glyph flags.");
+ }
+ }
+ }
+
+ ts->free_rid(ctx);
+ }
+
+ {
+ String test = U"เป็น ภาษา ราชการ และ ภาษา";
+ RID ctx = ts->create_shaped_text();
+ TEST_FAIL_COND(ctx == RID(), "Creating text buffer failed.");
+ bool ok = ts->shaped_text_add_string(ctx, test, font, 16);
+ TEST_FAIL_COND(!ok, "Adding text to the buffer failed.");
+ ts->shaped_text_update_breaks(ctx);
+ ts->shaped_text_update_justification_ops(ctx);
+
+ const Glyph *glyphs = ts->shaped_text_get_glyphs(ctx);
+ int gl_size = ts->shaped_text_get_glyph_count(ctx);
+
+ TEST_FAIL_COND(gl_size != 25, "Invalid glyph count.");
+ for (int j = 0; j < gl_size; j++) {
+ bool hard = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_HARD) == TextServer::GRAPHEME_IS_BREAK_HARD;
+ bool soft = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_SOFT) == TextServer::GRAPHEME_IS_BREAK_SOFT;
+ bool space = (glyphs[j].flags & TextServer::GRAPHEME_IS_SPACE) == TextServer::GRAPHEME_IS_SPACE;
+ bool virt = (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) == TextServer::GRAPHEME_IS_VIRTUAL;
+ bool elo = (glyphs[j].flags & TextServer::GRAPHEME_IS_ELONGATION) == TextServer::GRAPHEME_IS_ELONGATION;
+ if (j == 4 || j == 9 || j == 16 || j == 20) {
+ TEST_FAIL_COND((!soft || !space || hard || virt || elo), "Invalid glyph flags.");
+ } else {
+ TEST_FAIL_COND((soft || space || hard || virt || elo), "Invalid glyph flags.");
+ }
+ }
+ ts->free_rid(ctx);
+ }
+
+ if (ts->has_feature(TextServer::FEATURE_BREAK_ITERATORS)) {
+ String test = U"เป็นภาษาราชการและภาษา";
+ RID ctx = ts->create_shaped_text();
+ TEST_FAIL_COND(ctx == RID(), "Creating text buffer failed.");
+ bool ok = ts->shaped_text_add_string(ctx, test, font, 16);
+ TEST_FAIL_COND(!ok, "Adding text to the buffer failed.");
+ ts->shaped_text_update_breaks(ctx);
+ ts->shaped_text_update_justification_ops(ctx);
+
+ const Glyph *glyphs = ts->shaped_text_get_glyphs(ctx);
+ int gl_size = ts->shaped_text_get_glyph_count(ctx);
+
+ TEST_FAIL_COND(gl_size != 25, "Invalid glyph count.");
+ for (int j = 0; j < gl_size; j++) {
+ bool hard = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_HARD) == TextServer::GRAPHEME_IS_BREAK_HARD;
+ bool soft = (glyphs[j].flags & TextServer::GRAPHEME_IS_BREAK_SOFT) == TextServer::GRAPHEME_IS_BREAK_SOFT;
+ bool space = (glyphs[j].flags & TextServer::GRAPHEME_IS_SPACE) == TextServer::GRAPHEME_IS_SPACE;
+ bool virt = (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) == TextServer::GRAPHEME_IS_VIRTUAL;
+ bool elo = (glyphs[j].flags & TextServer::GRAPHEME_IS_ELONGATION) == TextServer::GRAPHEME_IS_ELONGATION;
+ if (j == 4 || j == 9 || j == 16 || j == 20) {
+ TEST_FAIL_COND((!soft || !space || hard || !virt || elo), "Invalid glyph flags.");
+ } else {
+ TEST_FAIL_COND((soft || space || hard || virt || elo), "Invalid glyph flags.");
+ }
+ }
+ ts->free_rid(ctx);
+ }
+
+ for (int j = 0; j < font.size(); j++) {
+ ts->free_rid(font[j]);
}
font.clear();
}
@@ -159,6 +377,10 @@ TEST_SUITE("[[TextServer]") {
Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(i);
TEST_FAIL_COND(ts.is_null(), "Invalid TS interface.");
+ if (!ts->has_feature(TextServer::FEATURE_FONT_DYNAMIC) || !ts->has_feature(TextServer::FEATURE_SIMPLE_LAYOUT)) {
+ continue;
+ }
+
String test_1 = U"test test test";
// 5^ 10^
@@ -167,7 +389,7 @@ TEST_SUITE("[[TextServer]") {
RID font2 = ts->create_font();
ts->font_set_data_ptr(font2, _font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size);
- Vector<RID> font;
+ Array font;
font.push_back(font1);
font.push_back(font2);
@@ -189,10 +411,10 @@ TEST_SUITE("[[TextServer]") {
TEST_FAIL_COND(brks[5] != 14, "Invalid line break position.");
}
- ts->free(ctx);
+ ts->free_rid(ctx);
for (int j = 0; j < font.size(); j++) {
- ts->free(font[j]);
+ ts->free_rid(font[j]);
}
font.clear();
}
@@ -203,12 +425,16 @@ TEST_SUITE("[[TextServer]") {
Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(i);
TEST_FAIL_COND(ts.is_null(), "Invalid TS interface.");
+ if (!ts->has_feature(TextServer::FEATURE_FONT_DYNAMIC) || !ts->has_feature(TextServer::FEATURE_SIMPLE_LAYOUT)) {
+ continue;
+ }
+
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_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size);
- Vector<RID> font;
+ Array font;
font.push_back(font1);
font.push_back(font2);
@@ -232,7 +458,7 @@ TEST_SUITE("[[TextServer]") {
width = ts->shaped_text_fit_to_width(ctx, 100, TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA);
TEST_FAIL_COND((width <= width_old || width > 100), "Invalid fill width.");
- ts->free(ctx);
+ ts->free_rid(ctx);
ctx = ts->create_shaped_text();
TEST_FAIL_COND(ctx == RID(), "Creating text buffer failed.");
@@ -245,7 +471,7 @@ TEST_SUITE("[[TextServer]") {
width = ts->shaped_text_fit_to_width(ctx, 100, TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA);
TEST_FAIL_COND((width <= width_old || width > 100), "Invalid fill width.");
- ts->free(ctx);
+ ts->free_rid(ctx);
}
ctx = ts->create_shaped_text();
@@ -257,10 +483,10 @@ TEST_SUITE("[[TextServer]") {
width = ts->shaped_text_fit_to_width(ctx, 100, TextServer::JUSTIFICATION_WORD_BOUND);
TEST_FAIL_COND((width <= width_old || width > 100), "Invalid fill width.");
- ts->free(ctx);
+ ts->free_rid(ctx);
for (int j = 0; j < font.size(); j++) {
- ts->free(font[j]);
+ ts->free_rid(font[j]);
}
font.clear();
}
@@ -288,9 +514,53 @@ TEST_SUITE("[[TextServer]") {
CHECK(ts->strip_diacritics(U"ṽṿ ẁẃẅẇẉ ẋẍ ẏ ẑẓẕ ẖ ẗẘẙẛ") == U"vv wwwww xx y zzz h twys");
}
}
+
+ SUBCASE("[TextServer] Word break") {
+ for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
+ Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(i);
+
+ if (!ts->has_feature(TextServer::FEATURE_SIMPLE_LAYOUT)) {
+ continue;
+ }
+
+ TEST_FAIL_COND(ts.is_null(), "Invalid TS interface.");
+ {
+ String text1 = U"linguistically similar and effectively form";
+ // 14^ 22^ 26^ 38^
+ PackedInt32Array breaks = ts->string_get_word_breaks(text1, "en");
+ CHECK(breaks.size() == 4);
+ if (breaks.size() == 4) {
+ CHECK(breaks[0] == 14);
+ CHECK(breaks[1] == 22);
+ CHECK(breaks[2] == 26);
+ CHECK(breaks[3] == 38);
+ }
+ }
+
+ if (ts->has_feature(TextServer::FEATURE_BREAK_ITERATORS)) {
+ String text2 = U"เป็นภาษาราชการและภาษาประจำชาติของประเทศไทย";
+ // เป็น ภาษา ราชการ และ ภาษา ประจำ ชาติ ของ ประเทศไทย
+ // 3^ 7^ 13^ 16^ 20^ 25^ 29^ 32^
+
+ PackedInt32Array breaks = ts->string_get_word_breaks(text2, "th");
+ CHECK(breaks.size() == 8);
+ if (breaks.size() == 8) {
+ CHECK(breaks[0] == 3);
+ CHECK(breaks[1] == 7);
+ CHECK(breaks[2] == 13);
+ CHECK(breaks[3] == 16);
+ CHECK(breaks[4] == 20);
+ CHECK(breaks[5] == 25);
+ CHECK(breaks[6] == 29);
+ CHECK(breaks[7] == 32);
+ }
+ }
+ }
+ }
}
}
}; // namespace TestTextServer
-#endif // TEST_TEXT_SERVER_H
#endif // TOOLS_ENABLED
+
+#endif // TEST_TEXT_SERVER_H
diff --git a/tests/test_macros.cpp b/tests/test_macros.cpp
index b0b28ab374..8c510cb4a5 100644
--- a/tests/test_macros.cpp
+++ b/tests/test_macros.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -31,11 +31,11 @@
#define DOCTEST_CONFIG_IMPLEMENT
#include "test_macros.h"
-Map<String, TestFunc> *test_commands = nullptr;
+HashMap<String, TestFunc> *test_commands = nullptr;
int register_test_command(String p_command, TestFunc p_function) {
if (!test_commands) {
- test_commands = new Map<String, TestFunc>;
+ test_commands = new HashMap<String, TestFunc>;
}
test_commands->insert(p_command, p_function);
return 0;
diff --git a/tests/test_macros.h b/tests/test_macros.h
index b04c2117b7..eff09fb4b0 100644
--- a/tests/test_macros.h
+++ b/tests/test_macros.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -63,22 +63,22 @@
// Stringify all `Variant` compatible types for doctest output by default.
// https://github.com/onqtam/doctest/blob/master/doc/markdown/stringification.md
-#define DOCTEST_STRINGIFY_VARIANT(m_type) \
- template <> \
- struct doctest::StringMaker<m_type> { \
- static doctest::String convert(const m_type &p_val) { \
- const Variant val = p_val; \
- return val.get_construct_string().utf8().get_data(); \
- } \
+#define DOCTEST_STRINGIFY_VARIANT(m_type) \
+ template <> \
+ struct doctest::StringMaker<m_type> { \
+ static doctest::String convert(const m_type &p_val) { \
+ const Variant val = p_val; \
+ return val.operator ::String().utf8().get_data(); \
+ } \
};
-#define DOCTEST_STRINGIFY_VARIANT_POINTER(m_type) \
- template <> \
- struct doctest::StringMaker<m_type> { \
- static doctest::String convert(const m_type *p_val) { \
- const Variant val = p_val; \
- return val.get_construct_string().utf8().get_data(); \
- } \
+#define DOCTEST_STRINGIFY_VARIANT_POINTER(m_type) \
+ template <> \
+ struct doctest::StringMaker<m_type> { \
+ static doctest::String convert(const m_type *p_val) { \
+ const Variant val = p_val; \
+ return val.operator ::String().utf8().get_data(); \
+ } \
};
DOCTEST_STRINGIFY_VARIANT(Variant);
@@ -122,20 +122,21 @@ DOCTEST_STRINGIFY_VARIANT(PackedColorArray);
// Example usage: `godot --test gdscript-parser`.
typedef void (*TestFunc)();
-extern Map<String, TestFunc> *test_commands;
+extern HashMap<String, TestFunc> *test_commands;
int register_test_command(String p_command, TestFunc p_function);
-#define REGISTER_TEST_COMMAND(m_command, m_function) \
- DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_VAR_)) = \
- register_test_command(m_command, m_function); \
- DOCTEST_GLOBAL_NO_WARNINGS_END()
+#define REGISTER_TEST_COMMAND(m_command, m_function) \
+ DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_), \
+ register_test_command(m_command, m_function))
// Utility macros to send an event actions to a given object
// Requires Message Queue and InputMap to be setup.
// SEND_GUI_ACTION - takes an object and a input map key. e.g SEND_GUI_ACTION(code_edit, "ui_text_newline").
// SEND_GUI_KEY_EVENT - takes an object and a keycode set. e.g SEND_GUI_KEY_EVENT(code_edit, Key::A | KeyModifierMask::CMD).
-// SEND_GUI_MOUSE_EVENT - takes an object, position, mouse button and mouse mask e.g SEND_GUI_MOUSE_EVENT(code_edit, Vector2(50, 50), MOUSE_BUTTON_NONE, MOUSE_BUTTON_NONE);
-// SEND_GUI_DOUBLE_CLICK - takes an object and a postion. e.g SEND_GUI_DOUBLE_CLICK(code_edit, Vector2(50, 50));
+// SEND_GUI_MOUSE_BUTTON_EVENT - takes an object, position, mouse button, mouse mask and modifiers e.g SEND_GUI_MOUSE_BUTTON_EVENT(code_edit, Vector2(50, 50), MOUSE_BUTTON_NONE, MOUSE_BUTTON_NONE, Key::None);
+// SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT - takes an object, position, mouse button, mouse mask and modifiers e.g SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(code_edit, Vector2(50, 50), MOUSE_BUTTON_NONE, MOUSE_BUTTON_NONE, Key::None);
+// SEND_GUI_MOUSE_MOTION_EVENT - takes an object, position, mouse mask and modifiers e.g SEND_GUI_MOUSE_MOTION_EVENT(code_edit, Vector2(50, 50), MouseButton::MASK_LEFT, KeyModifierMask::CMD);
+// SEND_GUI_DOUBLE_CLICK - takes an object, position and modifiers. e.g SEND_GUI_DOUBLE_CLICK(code_edit, Vector2(50, 50), KeyModifierMask::CMD);
#define SEND_GUI_ACTION(m_object, m_action) \
{ \
@@ -143,7 +144,7 @@ int register_test_command(String p_command, TestFunc p_function);
const List<Ref<InputEvent>>::Element *first_event = events->front(); \
Ref<InputEventKey> event = first_event->get(); \
event->set_pressed(true); \
- m_object->gui_input(event); \
+ m_object->get_viewport()->push_input(event); \
MessageQueue::get_singleton()->flush(); \
}
@@ -151,31 +152,64 @@ int register_test_command(String p_command, TestFunc p_function);
{ \
Ref<InputEventKey> event = InputEventKey::create_reference(m_input); \
event->set_pressed(true); \
- m_object->gui_input(event); \
+ m_object->get_viewport()->push_input(event); \
MessageQueue::get_singleton()->flush(); \
}
-#define _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask) \
- Ref<InputEventMouseButton> event; \
- event.instantiate(); \
- event->set_position(m_local_pos); \
- event->set_button_index(m_input); \
- event->set_button_mask(m_mask); \
+#define _UPDATE_EVENT_MODIFERS(m_event, m_modifers) \
+ m_event->set_shift_pressed(((m_modifers)&KeyModifierMask::SHIFT) != Key::NONE); \
+ m_event->set_alt_pressed(((m_modifers)&KeyModifierMask::ALT) != Key::NONE); \
+ m_event->set_ctrl_pressed(((m_modifers)&KeyModifierMask::CTRL) != Key::NONE); \
+ m_event->set_command_pressed(((m_modifers)&KeyModifierMask::CMD) != Key::NONE); \
+ m_event->set_meta_pressed(((m_modifers)&KeyModifierMask::META) != Key::NONE);
+
+#define _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask, m_modifers) \
+ Ref<InputEventMouseButton> event; \
+ event.instantiate(); \
+ event->set_position(m_local_pos); \
+ event->set_button_index(m_input); \
+ event->set_button_mask(m_mask); \
+ event->set_factor(1); \
+ _UPDATE_EVENT_MODIFERS(event, m_modifers); \
event->set_pressed(true);
-#define SEND_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask) \
- { \
- _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask); \
- m_object->get_viewport()->push_input(event); \
- MessageQueue::get_singleton()->flush(); \
+#define SEND_GUI_MOUSE_BUTTON_EVENT(m_object, m_local_pos, m_input, m_mask, m_modifers) \
+ { \
+ _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask, m_modifers); \
+ m_object->get_viewport()->push_input(event); \
+ MessageQueue::get_singleton()->flush(); \
}
-#define SEND_GUI_DOUBLE_CLICK(m_object, m_local_pos) \
- { \
- _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, MouseButton::LEFT, MouseButton::LEFT); \
- event->set_double_click(true); \
- m_object->get_viewport()->push_input(event); \
- MessageQueue::get_singleton()->flush(); \
+#define SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(m_object, m_local_pos, m_input, m_mask, m_modifers) \
+ { \
+ _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, m_input, m_mask, m_modifers); \
+ event->set_pressed(false); \
+ m_object->get_viewport()->push_input(event); \
+ MessageQueue::get_singleton()->flush(); \
+ }
+
+#define SEND_GUI_DOUBLE_CLICK(m_object, m_local_pos, m_modifers) \
+ { \
+ _CREATE_GUI_MOUSE_EVENT(m_object, m_local_pos, MouseButton::LEFT, MouseButton::LEFT, m_modifers); \
+ event->set_double_click(true); \
+ m_object->get_viewport()->push_input(event); \
+ MessageQueue::get_singleton()->flush(); \
+ }
+
+// We toggle _print_error_enabled to prevent display server not supported warnings.
+#define SEND_GUI_MOUSE_MOTION_EVENT(m_object, m_local_pos, m_mask, m_modifers) \
+ { \
+ bool errors_enabled = _print_error_enabled; \
+ _print_error_enabled = false; \
+ Ref<InputEventMouseMotion> event; \
+ event.instantiate(); \
+ event->set_position(m_local_pos); \
+ event->set_button_mask(m_mask); \
+ event->set_relative(Vector2(10, 10)); \
+ _UPDATE_EVENT_MODIFERS(event, m_modifers); \
+ m_object->get_viewport()->push_input(event); \
+ MessageQueue::get_singleton()->flush(); \
+ _print_error_enabled = errors_enabled; \
}
// Utility class / macros for testing signals
@@ -192,14 +226,14 @@ int register_test_command(String p_command, TestFunc p_function);
//
// Use SIGNAL_DISCARD("signal_name") to discard records all of the given signal, use only in placed you don't need to check.
//
-// All signals are automaticaly discared between test/sub test cases.
+// All signals are automatically discarded between test/sub test cases.
class SignalWatcher : public Object {
private:
inline static SignalWatcher *singleton;
- /* Equal to: Map<String, Vector<Vector<Variant>>> */
- Map<String, Array> _signals;
+ /* Equal to: RBMap<String, Vector<Vector<Variant>>> */
+ HashMap<String, Array> _signals;
void _add_signal_entry(const Array &p_args, const String &p_name) {
if (!_signals.has(p_name)) {
_signals[p_name] = Array();
@@ -237,22 +271,20 @@ public:
static SignalWatcher *get_singleton() { return singleton; }
void watch_signal(Object *p_object, const String &p_signal) {
- Vector<Variant> args;
- args.push_back(p_signal);
MethodInfo method_info;
ClassDB::get_signal(p_object->get_class(), p_signal, &method_info);
switch (method_info.arguments.size()) {
case 0: {
- p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_zero), args);
+ p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_zero).bind(p_signal));
} break;
case 1: {
- p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_one), args);
+ p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_one).bind(p_signal));
} break;
case 2: {
- p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_two), args);
+ p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_two).bind(p_signal));
} break;
case 3: {
- p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_three), args);
+ p_object->connect(p_signal, callable_mp(this, &SignalWatcher::_signal_callback_three).bind(p_signal));
} break;
default: {
MESSAGE("Signal ", p_signal, " arg count not supported.");
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index a09be08de8..40fe562be1 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -45,38 +45,43 @@
#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.h"
+#include "tests/core/math/test_plane.h"
#include "tests/core/math/test_random_number_generator.h"
#include "tests/core/math/test_rect2.h"
+#include "tests/core/math/test_rect2i.h"
+#include "tests/core/math/test_vector2.h"
+#include "tests/core/math/test_vector2i.h"
+#include "tests/core/math/test_vector3.h"
+#include "tests/core/math/test_vector3i.h"
#include "tests/core/object/test_class_db.h"
#include "tests/core/object/test_method_bind.h"
#include "tests/core/object/test_object.h"
+#include "tests/core/os/test_os.h"
#include "tests/core/string/test_node_path.h"
#include "tests/core/string/test_string.h"
#include "tests/core/string/test_translation.h"
#include "tests/core/templates/test_command_queue.h"
+#include "tests/core/templates/test_hash_map.h"
+#include "tests/core/templates/test_hash_set.h"
#include "tests/core/templates/test_list.h"
#include "tests/core/templates/test_local_vector.h"
#include "tests/core/templates/test_lru.h"
-#include "tests/core/templates/test_oa_hash_map.h"
-#include "tests/core/templates/test_ordered_hash_map.h"
#include "tests/core/templates/test_paged_array.h"
#include "tests/core/templates/test_vector.h"
#include "tests/core/test_crypto.h"
#include "tests/core/test_hashing_context.h"
#include "tests/core/test_time.h"
+#include "tests/core/threads/test_worker_thread_pool.h"
#include "tests/core/variant/test_array.h"
#include "tests/core/variant/test_dictionary.h"
#include "tests/core/variant/test_variant.h"
+#include "tests/scene/test_animation.h"
#include "tests/scene/test_code_edit.h"
#include "tests/scene/test_curve.h"
#include "tests/scene/test_gradient.h"
-#include "tests/scene/test_gui.h"
#include "tests/scene/test_path_3d.h"
-#include "tests/servers/test_physics_2d.h"
-#include "tests/servers/test_physics_3d.h"
-#include "tests/servers/test_render.h"
-#include "tests/servers/test_shader_lang.h"
+#include "tests/scene/test_text_edit.h"
+#include "tests/scene/test_theme.h"
#include "tests/servers/test_text_server.h"
#include "tests/test_validate_testing.h"
@@ -85,6 +90,11 @@
#include "tests/test_macros.h"
#include "scene/resources/default_theme/default_theme.h"
+#include "servers/navigation_server_2d.h"
+#include "servers/navigation_server_3d.h"
+#include "servers/physics_server_2d.h"
+#include "servers/physics_server_3d.h"
+#include "servers/rendering/rendering_server_default.h"
int test_main(int argc, char *argv[]) {
bool run_tests = true;
@@ -99,9 +109,9 @@ int test_main(int argc, char *argv[]) {
// Run custom test tools.
if (test_commands) {
- for (Map<String, TestFunc>::Element *E = test_commands->front(); E; E = E->next()) {
- if (args.find(E->key())) {
- const TestFunc &test_func = E->get();
+ for (const KeyValue<String, TestFunc> &E : (*test_commands)) {
+ if (args.find(E.key)) {
+ const TestFunc &test_func = E.value;
test_func();
run_tests = false;
break;
@@ -150,19 +160,15 @@ int test_main(int argc, char *argv[]) {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-#include "servers/navigation_server_2d.h"
-#include "servers/navigation_server_3d.h"
-#include "servers/rendering/rendering_server_default.h"
-
struct GodotTestCaseListener : public doctest::IReporter {
GodotTestCaseListener(const doctest::ContextOptions &p_in) {}
SignalWatcher *signal_watcher = nullptr;
- PhysicsServer3D *physics_3d_server = nullptr;
- PhysicsServer2D *physics_2d_server = nullptr;
- NavigationServer3D *navigation_3d_server = nullptr;
- NavigationServer2D *navigation_2d_server = nullptr;
+ PhysicsServer3D *physics_server_3d = nullptr;
+ PhysicsServer2D *physics_server_2d = nullptr;
+ NavigationServer3D *navigation_server_3d = nullptr;
+ NavigationServer2D *navigation_server_2d = nullptr;
void test_case_start(const doctest::TestCaseData &p_in) override {
SignalWatcher::get_singleton()->_clear_signals();
@@ -175,6 +181,8 @@ struct GodotTestCaseListener : public doctest::IReporter {
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++) {
@@ -187,19 +195,19 @@ struct GodotTestCaseListener : public doctest::IReporter {
RenderingServerDefault::get_singleton()->init();
RenderingServerDefault::get_singleton()->set_render_loop_enabled(false);
- physics_3d_server = PhysicsServer3DManager::new_default_server();
- physics_3d_server->init();
+ physics_server_3d = PhysicsServer3DManager::new_default_server();
+ physics_server_3d->init();
- physics_2d_server = PhysicsServer2DManager::new_default_server();
- physics_2d_server->init();
+ physics_server_2d = PhysicsServer2DManager::new_default_server();
+ physics_server_2d->init();
- navigation_3d_server = NavigationServer3DManager::new_default_server();
- navigation_2d_server = memnew(NavigationServer2D);
+ navigation_server_3d = NavigationServer3DManager::new_default_server();
+ navigation_server_2d = memnew(NavigationServer2D);
memnew(InputMap);
InputMap::get_singleton()->load_default();
- make_default_theme(false, Ref<Font>());
+ make_default_theme(1.0, Ref<Font>());
memnew(SceneTree);
SceneTree::get_singleton()->initialize();
@@ -222,31 +230,35 @@ struct GodotTestCaseListener : public doctest::IReporter {
clear_default_theme();
- if (navigation_3d_server) {
- memdelete(navigation_3d_server);
- navigation_3d_server = nullptr;
+ if (navigation_server_3d) {
+ memdelete(navigation_server_3d);
+ navigation_server_3d = nullptr;
+ }
+
+ if (navigation_server_2d) {
+ memdelete(navigation_server_2d);
+ navigation_server_2d = nullptr;
}
- if (navigation_2d_server) {
- memdelete(navigation_2d_server);
- navigation_2d_server = nullptr;
+ if (physics_server_3d) {
+ physics_server_3d->finish();
+ memdelete(physics_server_3d);
+ physics_server_3d = nullptr;
}
- if (physics_3d_server) {
- physics_3d_server->finish();
- memdelete(physics_3d_server);
- physics_3d_server = nullptr;
+ if (physics_server_2d) {
+ physics_server_2d->finish();
+ memdelete(physics_server_2d);
+ physics_server_2d = nullptr;
}
- if (physics_2d_server) {
- physics_2d_server->finish();
- memdelete(physics_2d_server);
- physics_2d_server = nullptr;
+ if (Input::get_singleton()) {
+ memdelete(Input::get_singleton());
}
if (RenderingServer::get_singleton()) {
RenderingServer::get_singleton()->sync();
- RenderingServer::get_singleton()->global_variables_clear();
+ RenderingServer::get_singleton()->global_shader_uniforms_clear();
RenderingServer::get_singleton()->finish();
memdelete(RenderingServer::get_singleton());
}
diff --git a/tests/test_main.h b/tests/test_main.h
index 8c506a776f..8e6a7361fc 100644
--- a/tests/test_main.h
+++ b/tests/test_main.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/test_tools.h b/tests/test_tools.h
index e1192458d0..8ee7a4718f 100644
--- a/tests/test_tools.h
+++ b/tests/test_tools.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp
index 890dea3ee1..11cb6398aa 100644
--- a/tests/test_utils.cpp
+++ b/tests/test_utils.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/test_utils.h b/tests/test_utils.h
index ccebe2e449..499ddb84b2 100644
--- a/tests/test_utils.h
+++ b/tests/test_utils.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
diff --git a/tests/test_validate_testing.h b/tests/test_validate_testing.h
index 40b255e18a..413a7e351d 100644
--- a/tests/test_validate_testing.h
+++ b/tests/test_validate_testing.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */