diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/io/test_image.h | 4 | ||||
-rw-r--r-- | tests/core/math/test_basis.h | 129 | ||||
-rw-r--r-- | tests/scene/test_arraymesh.h | 321 | ||||
-rw-r--r-- | tests/scene/test_text_edit.h | 39 | ||||
-rw-r--r-- | tests/test_main.cpp | 3 |
5 files changed, 392 insertions, 104 deletions
diff --git a/tests/core/io/test_image.h b/tests/core/io/test_image.h index 38b616cda0..181d9a8a54 100644 --- a/tests/core/io/test_image.h +++ b/tests/core/io/test_image.h @@ -124,7 +124,7 @@ TEST_CASE("[Image] Saving and loading") { image_jpg->load_jpg_from_buffer(data_jpg) == OK, "The JPG image should load successfully."); - // Load WEBP + // Load WebP Ref<Image> image_webp = memnew(Image()); Ref<FileAccess> f_webp = FileAccess::open(TestUtils::get_data_path("images/icon.webp"), FileAccess::READ, &err); PackedByteArray data_webp; @@ -132,7 +132,7 @@ TEST_CASE("[Image] Saving and loading") { f_webp->get_buffer(data_webp.ptrw(), f_webp->get_length()); CHECK_MESSAGE( image_webp->load_webp_from_buffer(data_webp) == OK, - "The WEBP image should load successfully."); + "The WebP image should load successfully."); // Load PNG Ref<Image> image_png = memnew(Image()); diff --git a/tests/core/math/test_basis.h b/tests/core/math/test_basis.h index 90ca9e439f..f52b715cd7 100644 --- a/tests/core/math/test_basis.h +++ b/tests/core/math/test_basis.h @@ -38,15 +38,6 @@ namespace TestBasis { -enum RotOrder { - EulerXYZ, - EulerXZY, - EulerYZX, - EulerYXZ, - EulerZXY, - EulerZYX -}; - Vector3 deg_to_rad(const Vector3 &p_rotation) { return p_rotation / 180.0 * Math_PI; } @@ -55,88 +46,26 @@ Vector3 rad2deg(const Vector3 &p_rotation) { return p_rotation / Math_PI * 180.0; } -Basis EulerToBasis(RotOrder mode, const Vector3 &p_rotation) { - Basis ret; - switch (mode) { - case EulerXYZ: - ret.set_euler(p_rotation, Basis::EULER_ORDER_XYZ); - break; - - case EulerXZY: - ret.set_euler(p_rotation, Basis::EULER_ORDER_XZY); - break; - - case EulerYZX: - ret.set_euler(p_rotation, Basis::EULER_ORDER_YZX); - break; - - case EulerYXZ: - ret.set_euler(p_rotation, Basis::EULER_ORDER_YXZ); - break; - - case EulerZXY: - ret.set_euler(p_rotation, Basis::EULER_ORDER_ZXY); - break; - - case EulerZYX: - ret.set_euler(p_rotation, Basis::EULER_ORDER_ZYX); - break; - - default: - // If you land here, Please integrate all rotation orders. - FAIL("This is not unreachable."); - } - - return ret; -} - -Vector3 BasisToEuler(RotOrder mode, const Basis &p_rotation) { - switch (mode) { - case EulerXYZ: - return p_rotation.get_euler(Basis::EULER_ORDER_XYZ); - - case EulerXZY: - return p_rotation.get_euler(Basis::EULER_ORDER_XZY); - - case EulerYZX: - return p_rotation.get_euler(Basis::EULER_ORDER_YZX); - - case EulerYXZ: - return p_rotation.get_euler(Basis::EULER_ORDER_YXZ); - - case EulerZXY: - return p_rotation.get_euler(Basis::EULER_ORDER_ZXY); - - case EulerZYX: - return p_rotation.get_euler(Basis::EULER_ORDER_ZYX); - - default: - // If you land here, Please integrate all rotation orders. - FAIL("This is not unreachable."); - return Vector3(); - } -} - -String get_rot_order_name(RotOrder ro) { +String get_rot_order_name(Basis::EulerOrder ro) { switch (ro) { - case EulerXYZ: + case Basis::EULER_ORDER_XYZ: return "XYZ"; - case EulerXZY: + case Basis::EULER_ORDER_XZY: return "XZY"; - case EulerYZX: + case Basis::EULER_ORDER_YZX: return "YZX"; - case EulerYXZ: + case Basis::EULER_ORDER_YXZ: return "YXZ"; - case EulerZXY: + case Basis::EULER_ORDER_ZXY: return "ZXY"; - case EulerZYX: + case Basis::EULER_ORDER_ZYX: return "ZYX"; default: return "[Not supported]"; } } -void test_rotation(Vector3 deg_original_euler, RotOrder rot_order) { +void test_rotation(Vector3 deg_original_euler, Basis::EulerOrder rot_order) { // This test: // 1. Converts the rotation vector from deg to rad. // 2. Converts euler to basis. @@ -156,11 +85,11 @@ void test_rotation(Vector3 deg_original_euler, RotOrder rot_order) { // Euler to rotation const Vector3 original_euler = deg_to_rad(deg_original_euler); - const Basis to_rotation = EulerToBasis(rot_order, original_euler); + const Basis to_rotation = Basis::from_euler(original_euler, rot_order); // Euler from rotation - const Vector3 euler_from_rotation = BasisToEuler(rot_order, to_rotation); - const Basis rotation_from_computed_euler = EulerToBasis(rot_order, euler_from_rotation); + const Vector3 euler_from_rotation = to_rotation.get_euler(rot_order); + const Basis rotation_from_computed_euler = Basis::from_euler(euler_from_rotation, rot_order); Basis res = to_rotation.inverse() * rotation_from_computed_euler; @@ -184,13 +113,13 @@ void test_rotation(Vector3 deg_original_euler, RotOrder rot_order) { } TEST_CASE("[Basis] Euler conversions") { - Vector<RotOrder> rotorder_to_test; - rotorder_to_test.push_back(EulerXYZ); - rotorder_to_test.push_back(EulerXZY); - rotorder_to_test.push_back(EulerYZX); - rotorder_to_test.push_back(EulerYXZ); - rotorder_to_test.push_back(EulerZXY); - rotorder_to_test.push_back(EulerZYX); + Vector<Basis::EulerOrder> euler_order_to_test; + euler_order_to_test.push_back(Basis::EULER_ORDER_XYZ); + euler_order_to_test.push_back(Basis::EULER_ORDER_XZY); + euler_order_to_test.push_back(Basis::EULER_ORDER_YZX); + euler_order_to_test.push_back(Basis::EULER_ORDER_YXZ); + euler_order_to_test.push_back(Basis::EULER_ORDER_ZXY); + euler_order_to_test.push_back(Basis::EULER_ORDER_ZYX); Vector<Vector3> vectors_to_test; @@ -248,21 +177,21 @@ TEST_CASE("[Basis] Euler conversions") { vectors_to_test.push_back(Vector3(120.0, 150.0, -130.0)); vectors_to_test.push_back(Vector3(120.0, 150.0, 130.0)); - for (int h = 0; h < rotorder_to_test.size(); h += 1) { + for (int h = 0; h < euler_order_to_test.size(); h += 1) { for (int i = 0; i < vectors_to_test.size(); i += 1) { - test_rotation(vectors_to_test[i], rotorder_to_test[h]); + test_rotation(vectors_to_test[i], euler_order_to_test[h]); } } } TEST_CASE("[Stress][Basis] Euler conversions") { - Vector<RotOrder> rotorder_to_test; - rotorder_to_test.push_back(EulerXYZ); - rotorder_to_test.push_back(EulerXZY); - rotorder_to_test.push_back(EulerYZX); - rotorder_to_test.push_back(EulerYXZ); - rotorder_to_test.push_back(EulerZXY); - rotorder_to_test.push_back(EulerZYX); + Vector<Basis::EulerOrder> euler_order_to_test; + euler_order_to_test.push_back(Basis::EULER_ORDER_XYZ); + euler_order_to_test.push_back(Basis::EULER_ORDER_XZY); + euler_order_to_test.push_back(Basis::EULER_ORDER_YZX); + euler_order_to_test.push_back(Basis::EULER_ORDER_YXZ); + euler_order_to_test.push_back(Basis::EULER_ORDER_ZXY); + euler_order_to_test.push_back(Basis::EULER_ORDER_ZYX); Vector<Vector3> vectors_to_test; // Add 1000 random vectors with weirds numbers. @@ -274,9 +203,9 @@ TEST_CASE("[Stress][Basis] Euler conversions") { rng.randf_range(-1800, 1800))); } - for (int h = 0; h < rotorder_to_test.size(); h += 1) { + for (int h = 0; h < euler_order_to_test.size(); h += 1) { for (int i = 0; i < vectors_to_test.size(); i += 1) { - test_rotation(vectors_to_test[i], rotorder_to_test[h]); + test_rotation(vectors_to_test[i], euler_order_to_test[h]); } } } diff --git a/tests/scene/test_arraymesh.h b/tests/scene/test_arraymesh.h new file mode 100644 index 0000000000..fc23adcd06 --- /dev/null +++ b/tests/scene/test_arraymesh.h @@ -0,0 +1,321 @@ +/*************************************************************************/ +/* test_arraymesh.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_ARRAYMESH_H +#define TEST_ARRAYMESH_H + +#include "scene/resources/mesh.h" +#include "scene/resources/primitive_meshes.h" + +#include "tests/test_macros.h" + +namespace TestArrayMesh { + +TEST_CASE("[SceneTree][ArrayMesh] Adding and modifying blendshapes.") { + Ref<ArrayMesh> mesh = memnew(ArrayMesh); + StringName name_a{ "ShapeA" }; + StringName name_b{ "ShapeB" }; + + SUBCASE("Adding a blend shape to the mesh before a surface is added.") { + mesh->add_blend_shape(name_a); + mesh->add_blend_shape(name_b); + + CHECK(mesh->get_blend_shape_name(0) == name_a); + CHECK(mesh->get_blend_shape_name(1) == name_b); + } + + SUBCASE("Add same blend shape multiple times appends name with number.") { + mesh->add_blend_shape(name_a); + mesh->add_blend_shape(name_a); + mesh->add_blend_shape(name_a); + + CHECK(mesh->get_blend_shape_name(0) == "ShapeA"); + bool all_different = (static_cast<String>(mesh->get_blend_shape_name(0)) != static_cast<String>(mesh->get_blend_shape_name(1))) && + (static_cast<String>(mesh->get_blend_shape_name(1)) != static_cast<String>(mesh->get_blend_shape_name(2))) && + (static_cast<String>(mesh->get_blend_shape_name(0)) != static_cast<String>(mesh->get_blend_shape_name(2))); + bool all_have_name = static_cast<String>(mesh->get_blend_shape_name(1)).contains("ShapeA") && + static_cast<String>(mesh->get_blend_shape_name(2)).contains("ShapeA"); + CHECK((all_different && all_have_name)); + } + + SUBCASE("ArrayMesh keeps correct count of number of blend shapes") { + mesh->add_blend_shape(name_a); + mesh->add_blend_shape(name_a); + mesh->add_blend_shape(name_b); + mesh->add_blend_shape(name_b); + mesh->add_blend_shape(name_b); + + REQUIRE(mesh->get_blend_shape_count() == 5); + } + + SUBCASE("Adding blend shape after surface is added causes error") { + Ref<CylinderMesh> cylinder = memnew(CylinderMesh); + Array cylinder_array{}; + cylinder_array.resize(Mesh::ARRAY_MAX); + cylinder->create_mesh_array(cylinder_array, 3.f, 3.f, 5.f); + mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array); + + mesh->add_blend_shape(name_a); + CHECK(mesh->get_blend_shape_count() == 0); + } + + SUBCASE("Change blend shape name after adding.") { + mesh->add_blend_shape(name_a); + mesh->set_blend_shape_name(0, name_b); + + CHECK(mesh->get_blend_shape_name(0) == name_b); + } + + SUBCASE("Change blend shape name to the name of one already there, should append number to end") { + mesh->add_blend_shape(name_a); + mesh->add_blend_shape(name_b); + mesh->set_blend_shape_name(0, name_b); + + String name_string = mesh->get_blend_shape_name(0); + CHECK(name_string.contains("ShapeB")); + CHECK(name_string.length() > static_cast<String>(name_b).size()); + } + + SUBCASE("Clear all blend shapes before surface has been added.") { + mesh->add_blend_shape(name_a); + mesh->add_blend_shape(name_b); + CHECK(mesh->get_blend_shape_count() == 2); + + mesh->clear_blend_shapes(); + CHECK(mesh->get_blend_shape_count() == 0); + } + + SUBCASE("Can't clear blend shapes after surface had been added.") { + mesh->add_blend_shape(name_a); + mesh->add_blend_shape(name_b); + Ref<CylinderMesh> cylinder = memnew(CylinderMesh); + Array cylinder_array{}; + cylinder_array.resize(Mesh::ARRAY_MAX); + cylinder->create_mesh_array(cylinder_array, 3.f, 3.f, 5.f); + mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array); + + mesh->clear_blend_shapes(); + CHECK(mesh->get_blend_shape_count() == 2); + } + + SUBCASE("Set the blend shape mode of ArrayMesh and underlying mesh RID.") { + mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_RELATIVE); + CHECK(mesh->get_blend_shape_mode() == Mesh::BLEND_SHAPE_MODE_RELATIVE); + } +} + +TEST_CASE("[SceneTree][ArrayMesh] Surface meta data tests.") { + Ref<ArrayMesh> mesh = memnew(ArrayMesh); + Ref<CylinderMesh> cylinder = memnew(CylinderMesh); + Array cylinder_array{}; + cylinder_array.resize(Mesh::ARRAY_MAX); + cylinder->create_mesh_array(cylinder_array, 3.f, 3.f, 5.f); + mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array); + + Ref<BoxMesh> box = memnew(BoxMesh); + Array box_array{}; + box_array.resize(Mesh::ARRAY_MAX); + box->create_mesh_array(box_array, Vector3(2.f, 1.2f, 1.6f)); + mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, box_array); + + SUBCASE("Add 2 surfaces and count the number of surfaces in the mesh.") { + REQUIRE(mesh->get_surface_count() == 2); + } + + SUBCASE("Get the surface array from mesh.") { + REQUIRE(mesh->surface_get_arrays(0)[0] == cylinder_array[0]); + REQUIRE(mesh->surface_get_arrays(1)[0] == box_array[0]); + } + + SUBCASE("Get the array length of a particular surface.") { + CHECK(mesh->surface_get_array_len(0) == static_cast<Vector<Vector3>>(cylinder_array[RenderingServer::ARRAY_VERTEX]).size()); + CHECK(mesh->surface_get_array_len(1) == static_cast<Vector<Vector3>>(box_array[RenderingServer::ARRAY_VERTEX]).size()); + } + + SUBCASE("Get the index array length of a particular surface.") { + CHECK(mesh->surface_get_array_index_len(0) == static_cast<Vector<Vector3>>(cylinder_array[RenderingServer::ARRAY_INDEX]).size()); + CHECK(mesh->surface_get_array_index_len(1) == static_cast<Vector<Vector3>>(box_array[RenderingServer::ARRAY_INDEX]).size()); + } + + SUBCASE("Get correct primitive type") { + CHECK(mesh->surface_get_primitive_type(0) == Mesh::PRIMITIVE_TRIANGLES); + CHECK(mesh->surface_get_primitive_type(1) == Mesh::PRIMITIVE_TRIANGLES); + mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLE_STRIP, box_array); + CHECK(mesh->surface_get_primitive_type(2) == Mesh::PRIMITIVE_TRIANGLE_STRIP); + } + + SUBCASE("Returns correct format for the mesh") { + auto format = RS::ARRAY_FORMAT_BLEND_SHAPE_MASK | RS::ARRAY_FORMAT_TEX_UV | RS::ARRAY_FORMAT_INDEX; + CHECK((mesh->surface_get_format(0) & format) != 0); + CHECK((mesh->surface_get_format(1) & format) != 0); + } + + SUBCASE("Set a surface name and retrieve it by name.") { + mesh->surface_set_name(0, "surf1"); + CHECK(mesh->surface_find_by_name("surf1") == 0); + CHECK(mesh->surface_get_name(0) == "surf1"); + } + + SUBCASE("Set material to two different surfaces.") { + Ref<Material> mat = memnew(Material); + mesh->surface_set_material(0, mat); + CHECK(mesh->surface_get_material(0) == mat); + mesh->surface_set_material(1, mat); + CHECK(mesh->surface_get_material(1) == mat); + } + + SUBCASE("Set same material multiple times doesn't change material of surface.") { + Ref<Material> mat = memnew(Material); + mesh->surface_set_material(0, mat); + mesh->surface_set_material(0, mat); + mesh->surface_set_material(0, mat); + CHECK(mesh->surface_get_material(0) == mat); + } + + SUBCASE("Set material of surface then change to different material.") { + Ref<Material> mat1 = memnew(Material); + Ref<Material> mat2 = memnew(Material); + mesh->surface_set_material(1, mat1); + CHECK(mesh->surface_get_material(1) == mat1); + mesh->surface_set_material(1, mat2); + CHECK(mesh->surface_get_material(1) == mat2); + } + + SUBCASE("Get the LOD of the mesh.") { + Dictionary lod{}; + mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array, TypedArray<Array>{}, lod); + CHECK(mesh->surface_get_lods(2) == lod); + } + + SUBCASE("Get the blend shape arrays from the mesh.") { + TypedArray<Array> blend{}; + mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array, blend); + CHECK(mesh->surface_get_blend_shape_arrays(2) == blend); + } +} + +TEST_CASE("[SceneTree][ArrayMesh] Get/Set mesh metadata and actions") { + Ref<ArrayMesh> mesh = memnew(ArrayMesh); + Ref<CylinderMesh> cylinder = memnew(CylinderMesh); + Array cylinder_array{}; + cylinder_array.resize(Mesh::ARRAY_MAX); + cylinder->create_mesh_array(cylinder_array, 3.f, 3.f, 5.f); + mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, cylinder_array); + + Ref<BoxMesh> box = memnew(BoxMesh); + Array box_array{}; + box_array.resize(Mesh::ARRAY_MAX); + box->create_mesh_array(box_array, Vector3(2.f, 1.2f, 1.6f)); + mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, box_array); + + SUBCASE("Set the shadow mesh.") { + Ref<ArrayMesh> shadow = memnew(ArrayMesh); + mesh->set_shadow_mesh(shadow); + CHECK(mesh->get_shadow_mesh() == shadow); + } + + SUBCASE("Set the shadow mesh multiple times.") { + Ref<ArrayMesh> shadow = memnew(ArrayMesh); + mesh->set_shadow_mesh(shadow); + mesh->set_shadow_mesh(shadow); + mesh->set_shadow_mesh(shadow); + mesh->set_shadow_mesh(shadow); + CHECK(mesh->get_shadow_mesh() == shadow); + } + + SUBCASE("Set the same shadow mesh on multiple meshes.") { + Ref<ArrayMesh> shadow = memnew(ArrayMesh); + Ref<ArrayMesh> mesh2 = memnew(ArrayMesh); + mesh->set_shadow_mesh(shadow); + mesh2->set_shadow_mesh(shadow); + + CHECK(mesh->get_shadow_mesh() == shadow); + CHECK(mesh2->get_shadow_mesh() == shadow); + } + + SUBCASE("Set the shadow mesh and then change it.") { + Ref<ArrayMesh> shadow = memnew(ArrayMesh); + mesh->set_shadow_mesh(shadow); + CHECK(mesh->get_shadow_mesh() == shadow); + Ref<ArrayMesh> shadow2 = memnew(ArrayMesh); + mesh->set_shadow_mesh(shadow2); + CHECK(mesh->get_shadow_mesh() == shadow2); + } + + SUBCASE("Set custom AABB.") { + AABB bound{}; + mesh->set_custom_aabb(bound); + CHECK(mesh->get_custom_aabb() == bound); + } + + SUBCASE("Set custom AABB multiple times.") { + AABB bound{}; + mesh->set_custom_aabb(bound); + mesh->set_custom_aabb(bound); + mesh->set_custom_aabb(bound); + mesh->set_custom_aabb(bound); + CHECK(mesh->get_custom_aabb() == bound); + } + + SUBCASE("Set custom AABB then change to another AABB.") { + AABB bound{}; + AABB bound2{}; + mesh->set_custom_aabb(bound); + CHECK(mesh->get_custom_aabb() == bound); + mesh->set_custom_aabb(bound2); + CHECK(mesh->get_custom_aabb() == bound2); + } + + SUBCASE("Clear all surfaces should leave zero count.") { + mesh->clear_surfaces(); + CHECK(mesh->get_surface_count() == 0); + } + + SUBCASE("Able to get correct mesh RID.") { + RID rid = mesh->get_rid(); + CHECK(RS::get_singleton()->mesh_get_surface_count(rid) == 2); + } + + SUBCASE("Create surface from raw SurfaceData data.") { + RID mesh_rid = mesh->get_rid(); + RS::SurfaceData surface_data = RS::get_singleton()->mesh_get_surface(mesh_rid, 0); + Ref<ArrayMesh> mesh2 = memnew(ArrayMesh); + mesh2->add_surface(surface_data.format, Mesh::PRIMITIVE_TRIANGLES, surface_data.vertex_data, surface_data.attribute_data, + surface_data.skin_data, surface_data.vertex_count, surface_data.index_data, surface_data.index_count, surface_data.aabb); + CHECK(mesh2->get_surface_count() == 1); + CHECK(mesh2->surface_get_primitive_type(0) == Mesh::PRIMITIVE_TRIANGLES); + CHECK((mesh2->surface_get_format(0) & surface_data.format) != 0); + CHECK(mesh2->get_aabb().is_equal_approx(surface_data.aabb)); + } +} + +} // namespace TestArrayMesh + +#endif // TEST_ARRAYMESH_H diff --git a/tests/scene/test_text_edit.h b/tests/scene/test_text_edit.h index 4b92b9daff..652cbed6e8 100644 --- a/tests/scene/test_text_edit.h +++ b/tests/scene/test_text_edit.h @@ -3353,7 +3353,7 @@ TEST_CASE("[SceneTree][TextEdit] caret") { memdelete(text_edit); } -TEST_CASE("[SceneTree][TextEdit] muiticaret") { +TEST_CASE("[SceneTree][TextEdit] multicaret") { TextEdit *text_edit = memnew(TextEdit); SceneTree::get_singleton()->get_root()->add_child(text_edit); text_edit->set_multiple_carets_enabled(true); @@ -3443,6 +3443,43 @@ TEST_CASE("[SceneTree][TextEdit] muiticaret") { CHECK(text_edit->get_caret_index_edit_order() == caret_index_get_order); } + SUBCASE("[TextEdit] add caret at carets") { + text_edit->remove_secondary_carets(); + text_edit->set_caret_line(1); + text_edit->set_caret_column(9); + + text_edit->add_caret_at_carets(true); + CHECK(text_edit->get_caret_count() == 2); + CHECK(text_edit->get_caret_line(1) == 2); + CHECK(text_edit->get_caret_column(1) == 4); + + text_edit->add_caret_at_carets(true); + CHECK(text_edit->get_caret_count() == 2); + + text_edit->add_caret_at_carets(false); + CHECK(text_edit->get_caret_count() == 3); + CHECK(text_edit->get_caret_line(2) == 0); + CHECK(text_edit->get_caret_column(2) == 7); + + text_edit->remove_secondary_carets(); + text_edit->set_caret_line(0); + text_edit->set_caret_column(4); + text_edit->select(0, 0, 0, 4); + text_edit->add_caret_at_carets(true); + CHECK(text_edit->get_caret_count() == 2); + CHECK(text_edit->get_selection_from_line(1) == 1); + CHECK(text_edit->get_selection_to_line(1) == 1); + CHECK(text_edit->get_selection_from_column(1) == 0); + CHECK(text_edit->get_selection_to_column(1) == 3); + + text_edit->add_caret_at_carets(true); + CHECK(text_edit->get_caret_count() == 3); + CHECK(text_edit->get_selection_from_line(2) == 2); + CHECK(text_edit->get_selection_to_line(2) == 2); + CHECK(text_edit->get_selection_from_column(2) == 0); + CHECK(text_edit->get_selection_to_column(2) == 4); + } + memdelete(text_edit); } diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 4c861eacba..80099d1dd4 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -84,6 +84,7 @@ #include "tests/core/variant/test_dictionary.h" #include "tests/core/variant/test_variant.h" #include "tests/scene/test_animation.h" +#include "tests/scene/test_arraymesh.h" #include "tests/scene/test_audio_stream_wav.h" #include "tests/scene/test_bit_map.h" #include "tests/scene/test_code_edit.h" @@ -199,7 +200,7 @@ struct GodotTestCaseListener : public doctest::IReporter { OS::get_singleton()->set_has_server_feature_callback(nullptr); for (int i = 0; i < DisplayServer::get_create_function_count(); i++) { if (String("headless") == DisplayServer::get_create_function_name(i)) { - DisplayServer::create(i, "", DisplayServer::WindowMode::WINDOW_MODE_MINIMIZED, DisplayServer::VSyncMode::VSYNC_ENABLED, 0, Vector2i(0, 0), err); + DisplayServer::create(i, "", DisplayServer::WindowMode::WINDOW_MODE_MINIMIZED, DisplayServer::VSyncMode::VSYNC_ENABLED, 0, nullptr, Vector2i(0, 0), err); break; } } |