summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_code_edit.h47
-rw-r--r--tests/test_main.cpp8
-rw-r--r--tests/test_shader_lang.cpp37
-rw-r--r--tests/test_text_server.h67
-rw-r--r--tests/test_vector.h13
5 files changed, 116 insertions, 56 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_shader_lang.cpp b/tests/test_shader_lang.cpp
index 6d58eb63cc..5598852f29 100644
--- a/tests/test_shader_lang.cpp
+++ b/tests/test_shader_lang.cpp
@@ -125,23 +125,28 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
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);
+ }
- 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]);
+ 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";
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_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);