diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_code_edit.h | 47 | ||||
-rw-r--r-- | tests/test_main.cpp | 8 | ||||
-rw-r--r-- | tests/test_math.cpp | 4 | ||||
-rw-r--r-- | tests/test_physics_2d.cpp | 2 | ||||
-rw-r--r-- | tests/test_physics_3d.cpp | 2 | ||||
-rw-r--r-- | tests/test_shader_lang.cpp | 57 | ||||
-rw-r--r-- | tests/test_text_server.h | 67 | ||||
-rw-r--r-- | tests/test_translation.h | 31 | ||||
-rw-r--r-- | tests/test_vector.h | 13 |
9 files changed, 161 insertions, 70 deletions
diff --git a/tests/test_code_edit.h b/tests/test_code_edit.h index fc8cec60af..0e31a976bf 100644 --- a/tests/test_code_edit.h +++ b/tests/test_code_edit.h @@ -3063,6 +3063,53 @@ TEST_CASE("[SceneTree][CodeEdit] line length guidelines") { memdelete(code_edit); } +TEST_CASE("[SceneTree][CodeEdit] Backspace delete") { + CodeEdit *code_edit = memnew(CodeEdit); + SceneTree::get_singleton()->get_root()->add_child(code_edit); + + /* Backspace with selection on first line. */ + code_edit->set_text(""); + code_edit->insert_text_at_caret("test backspace"); + code_edit->select(0, 0, 0, 5); + code_edit->backspace(); + CHECK(code_edit->get_line(0) == "backspace"); + + /* Backspace with selection on first line and caret at the beginning of file. */ + code_edit->set_text(""); + code_edit->insert_text_at_caret("test backspace"); + code_edit->select(0, 0, 0, 5); + code_edit->set_caret_column(0); + 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. */ + code_edit->set_text(""); + code_edit->insert_text_at_caret("line 1\nline 2"); + code_edit->set_caret_line(1); + code_edit->set_caret_column(0); + code_edit->backspace(); + CHECK(code_edit->get_line(0) == "line 1line 2"); + CHECK(code_edit->get_caret_line() == 0); + CHECK(code_edit->get_caret_column() == 6); + + /* Backspace delete all text if all text is selected. */ + code_edit->set_text(""); + code_edit->insert_text_at_caret("line 1\nline 2\nline 3"); + code_edit->select_all(); + code_edit->backspace(); + CHECK(code_edit->get_text() == ""); + + /* Backspace at the beginning without selection has no effect. */ + code_edit->set_text(""); + code_edit->insert_text_at_caret("line 1\nline 2\nline 3"); + code_edit->set_caret_line(0); + code_edit->set_caret_column(0); + code_edit->backspace(); + CHECK(code_edit->get_text() == "line 1\nline 2\nline 3"); + + memdelete(code_edit); +} + } // namespace TestCodeEdit #endif // TEST_CODE_EDIT_H diff --git a/tests/test_main.cpp b/tests/test_main.cpp index e4aa4c38ff..341fb1af61 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -174,10 +174,8 @@ struct GodotTestCaseListener : public doctest::IReporter { memnew(MessageQueue); GLOBAL_DEF("internationalization/rendering/force_right_to_left_layout_direction", false); - memnew(TextServerManager); - Error err = OK; - TextServerManager::initialize(0, err); + Error err = OK; 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)) { @@ -224,10 +222,6 @@ struct GodotTestCaseListener : public doctest::IReporter { clear_default_theme(); - if (TextServerManager::get_singleton()) { - memdelete(TextServerManager::get_singleton()); - } - if (navigation_3d_server) { memdelete(navigation_3d_server); navigation_3d_server = nullptr; diff --git a/tests/test_math.cpp b/tests/test_math.cpp index a44040dfe2..72272382ce 100644 --- a/tests/test_math.cpp +++ b/tests/test_math.cpp @@ -296,8 +296,8 @@ public: if (tk == TK_IDENTIFIER) { String name = value; if (use_next_class || p_known_class_name == name) { - for (Map<int, String>::Element *E = namespace_stack.front(); E; E = E->next()) { - class_name += E->get() + "."; + for (const KeyValue<int, String> &E : namespace_stack) { + class_name += E.value + "."; } class_name += String(value); break; diff --git a/tests/test_physics_2d.cpp b/tests/test_physics_2d.cpp index f63b866c3e..f6619db8fd 100644 --- a/tests/test_physics_2d.cpp +++ b/tests/test_physics_2d.cpp @@ -199,7 +199,7 @@ protected: if (mb.is_valid()) { if (mb->is_pressed()) { - Point2 p(mb->get_position().x, mb->get_position().y); + Point2 p = mb->get_position(); if (mb->get_button_index() == 1) { ray_to = p; diff --git a/tests/test_physics_3d.cpp b/tests/test_physics_3d.cpp index 3d1dad6545..d839ae26b7 100644 --- a/tests/test_physics_3d.cpp +++ b/tests/test_physics_3d.cpp @@ -361,7 +361,7 @@ public: RID mesh_instance = vs->instance_create2(capsule_mesh, scenario); character = ps->body_create(); - ps->body_set_mode(character, PhysicsServer3D::BODY_MODE_DYNAMIC_LOCKED); + 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); diff --git a/tests/test_shader_lang.cpp b/tests/test_shader_lang.cpp index ad763b344e..5598852f29 100644 --- a/tests/test_shader_lang.cpp +++ b/tests/test_shader_lang.cpp @@ -120,38 +120,43 @@ static String dump_node_code(SL::Node *p_node, int p_level) { case SL::Node::TYPE_SHADER: { SL::ShaderNode *pnode = (SL::ShaderNode *)p_node; - for (Map<StringName, SL::ShaderNode::Uniform>::Element *E = pnode->uniforms.front(); E; E = E->next()) { + for (const KeyValue<StringName, SL::ShaderNode::Uniform> &E : pnode->uniforms) { String ucode = "uniform "; - ucode += _prestr(E->get().precision); - ucode += _typestr(E->get().type); - ucode += " " + String(E->key()); - - if (E->get().default_value.size()) { - ucode += " = " + get_constant_text(E->get().type, E->get().default_value); - } + 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->get().hint) { - ucode += " : " + String(hint_name[E->get().hint]); + 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 (Map<StringName, SL::ShaderNode::Varying>::Element *E = pnode->varyings.front(); E; E = E->next()) { + for (const KeyValue<StringName, SL::ShaderNode::Varying> &E : pnode->varyings) { String vcode = "varying "; - vcode += _prestr(E->get().precision); - vcode += _typestr(E->get().type); - vcode += " " + String(E->key()); + vcode += _prestr(E.value.precision); + vcode += _typestr(E.value.type); + vcode += " " + String(E.key); code += vcode + "\n"; } @@ -183,8 +188,8 @@ static String dump_node_code(SL::Node *p_node, int p_level) { //variables code += _mktab(p_level - 1) + "{\n"; - for (Map<StringName, SL::BlockNode::Variable>::Element *E = bnode->variables.front(); E; E = E->next()) { - code += _mktab(p_level) + _prestr(E->get().precision) + _typestr(E->get().type) + " " + E->key() + ";\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++) { diff --git a/tests/test_text_server.h b/tests/test_text_server.h index b8ed4f89d0..af3df7bc79 100644 --- a/tests/test_text_server.h +++ b/tests/test_text_server.h @@ -41,19 +41,10 @@ namespace TestTextServer { TEST_SUITE("[[TextServer]") { TEST_CASE("[TextServer] Init, font loading and shaping") { - TextServerManager *tsman = memnew(TextServerManager); - Error err = OK; - - SUBCASE("[TextServer] Init") { - for (int i = 0; i < TextServerManager::get_interface_count(); i++) { - TextServer *ts = TextServerManager::initialize(i, err); - TEST_FAIL_COND((err != OK || ts == nullptr), "Text server ", TextServerManager::get_interface_name(i), " init failed."); - } - } - SUBCASE("[TextServer] Loading fonts") { - for (int i = 0; i < TextServerManager::get_interface_count(); i++) { - TextServer *ts = TextServerManager::initialize(i, err); + 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."); RID font = ts->create_font(); ts->font_set_data_ptr(font, _font_NotoSans_Regular, _font_NotoSans_Regular_size); @@ -63,8 +54,9 @@ TEST_SUITE("[[TextServer]") { } SUBCASE("[TextServer] Text layout: Font fallback") { - for (int i = 0; i < TextServerManager::get_interface_count(); i++) { - TextServer *ts = TextServerManager::initialize(i, err); + 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."); RID font1 = ts->create_font(); ts->font_set_data_ptr(font1, _font_NotoSans_Regular, _font_NotoSans_Regular_size); @@ -83,9 +75,10 @@ TEST_SUITE("[[TextServer]") { bool ok = ts->shaped_text_add_string(ctx, test, font, 16); TEST_FAIL_COND(!ok, "Adding text to the buffer failed."); - Vector<TextServer::Glyph> glyphs = ts->shaped_text_get_glyphs(ctx); - TEST_FAIL_COND(glyphs.size() == 0, "Shaping failed"); - for (int j = 0; j < glyphs.size(); j++) { + const Glyph *glyphs = ts->shaped_text_get_glyphs(ctx); + int gl_size = ts->shaped_text_get_glyph_count(ctx); + TEST_FAIL_COND(gl_size == 0, "Shaping failed"); + for (int j = 0; j < gl_size; j++) { if (glyphs[j].start < 6) { TEST_FAIL_COND(glyphs[j].font_rid != font[1], "Incorrect font selected."); } @@ -110,8 +103,9 @@ TEST_SUITE("[[TextServer]") { } SUBCASE("[TextServer] Text layout: BiDi") { - for (int i = 0; i < TextServerManager::get_interface_count(); i++) { - TextServer *ts = TextServerManager::initialize(i, err); + 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_BIDI_LAYOUT)) { continue; @@ -134,9 +128,10 @@ TEST_SUITE("[[TextServer]") { bool ok = ts->shaped_text_add_string(ctx, test, font, 16); TEST_FAIL_COND(!ok, "Adding text to the buffer failed."); - Vector<TextServer::Glyph> glyphs = ts->shaped_text_get_glyphs(ctx); - TEST_FAIL_COND(glyphs.size() == 0, "Shaping failed"); - for (int j = 0; j < glyphs.size(); j++) { + const Glyph *glyphs = ts->shaped_text_get_glyphs(ctx); + int gl_size = ts->shaped_text_get_glyph_count(ctx); + TEST_FAIL_COND(gl_size == 0, "Shaping failed"); + for (int j = 0; j < gl_size; j++) { if (glyphs[j].count > 0) { if (glyphs[j].start < 7) { TEST_FAIL_COND(((glyphs[j].flags & TextServer::GRAPHEME_IS_RTL) == TextServer::GRAPHEME_IS_RTL), "Incorrect direction."); @@ -160,8 +155,9 @@ TEST_SUITE("[[TextServer]") { } SUBCASE("[TextServer] Text layout: Line breaking") { - for (int i = 0; i < TextServerManager::get_interface_count(); i++) { - TextServer *ts = TextServerManager::initialize(i, err); + 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."); String test_1 = U"test test test"; // 5^ 10^ @@ -180,12 +176,17 @@ TEST_SUITE("[[TextServer]") { bool ok = ts->shaped_text_add_string(ctx, test_1, font, 16); TEST_FAIL_COND(!ok, "Adding text to the buffer failed."); - Vector<Vector2i> brks = ts->shaped_text_get_line_breaks(ctx, 1); - TEST_FAIL_COND(brks.size() != 3, "Invalid line breaks number."); - if (brks.size() == 3) { - TEST_FAIL_COND(brks[0] != Vector2i(0, 5), "Invalid line break position."); - TEST_FAIL_COND(brks[1] != Vector2i(5, 10), "Invalid line break position."); - TEST_FAIL_COND(brks[2] != Vector2i(10, 14), "Invalid line break position."); + PackedInt32Array brks = ts->shaped_text_get_line_breaks(ctx, 1); + TEST_FAIL_COND(brks.size() != 6, "Invalid line breaks number."); + if (brks.size() == 6) { + TEST_FAIL_COND(brks[0] != 0, "Invalid line break position."); + TEST_FAIL_COND(brks[1] != 5, "Invalid line break position."); + + TEST_FAIL_COND(brks[2] != 5, "Invalid line break position."); + TEST_FAIL_COND(brks[3] != 10, "Invalid line break position."); + + TEST_FAIL_COND(brks[4] != 10, "Invalid line break position."); + TEST_FAIL_COND(brks[5] != 14, "Invalid line break position."); } ts->free(ctx); @@ -198,8 +199,9 @@ TEST_SUITE("[[TextServer]") { } SUBCASE("[TextServer] Text layout: Justification") { - for (int i = 0; i < TextServerManager::get_interface_count(); i++) { - TextServer *ts = TextServerManager::initialize(i, err); + 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."); RID font1 = ts->create_font(); ts->font_set_data_ptr(font1, _font_NotoSans_Regular, _font_NotoSans_Regular_size); @@ -263,7 +265,6 @@ TEST_SUITE("[[TextServer]") { font.clear(); } } - memdelete(tsman); } } }; // namespace TestTextServer diff --git a/tests/test_translation.h b/tests/test_translation.h index 52ff49bf9b..93c53bbbc9 100644 --- a/tests/test_translation.h +++ b/tests/test_translation.h @@ -35,6 +35,10 @@ #include "core/string/translation.h" #include "core/string/translation_po.h" +#ifdef TOOLS_ENABLED +#include "editor/import/resource_importer_csv_translation.h" +#endif + #include "thirdparty/doctest/doctest.h" namespace TestTranslation { @@ -145,6 +149,33 @@ TEST_CASE("[OptimizedTranslation] Generate from Translation and read messages") CHECK(messages.size() == 0); } +#ifdef TOOLS_ENABLED +TEST_CASE("[Translation] CSV import") { + Ref<ResourceImporterCSVTranslation> import_csv_translation = memnew(ResourceImporterCSVTranslation); + + Map<StringName, Variant> options; + options["compress"] = false; + options["delimiter"] = 0; + + List<String> gen_files; + + Error result = import_csv_translation->import(TestUtils::get_data_path("translations.csv"), + "", options, nullptr, &gen_files); + CHECK(result == OK); + CHECK(gen_files.size() == 2); + + for (const String &file : gen_files) { + Ref<Translation> translation = ResourceLoader::load(file); + CHECK(translation.is_valid()); + TranslationServer::get_singleton()->add_translation(translation); + } + + TranslationServer::get_singleton()->set_locale("de"); + + CHECK(Object().tr("GOOD_MORNING", "") == "Guten Morgen"); +} +#endif // TOOLS_ENABLED + } // namespace TestTranslation #endif // TEST_TRANSLATION_H diff --git a/tests/test_vector.h b/tests/test_vector.h index 02c56e59f6..bfdf389aa7 100644 --- a/tests/test_vector.h +++ b/tests/test_vector.h @@ -472,6 +472,19 @@ TEST_CASE("[Vector] Sort custom") { CHECK(vector[7] == "World"); } +TEST_CASE("[Vector] Search") { + Vector<int> vector; + vector.push_back(1); + vector.push_back(2); + vector.push_back(3); + vector.push_back(5); + vector.push_back(8); + CHECK(vector.bsearch(2, true) == 1); + CHECK(vector.bsearch(2, false) == 2); + CHECK(vector.bsearch(5, true) == 3); + CHECK(vector.bsearch(5, false) == 4); +} + TEST_CASE("[Vector] Operators") { Vector<int> vector; vector.push_back(2); |