From 48c1aebb83dfc3b9d507ed1398c0430982b19b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 28 Jan 2023 18:32:46 +0100 Subject: [PATCH] tests: add tests on gui key functions (issue #1875) --- ChangeLog.adoc | 4 + doc/en/weechat_dev.en.adoc | 1 + doc/fr/weechat_dev.fr.adoc | 1 + doc/ja/weechat_dev.ja.adoc | 2 + doc/sr/weechat_dev.sr.adoc | 2 + src/gui/gui-key.c | 3 + tests/CMakeLists.txt | 1 + tests/tests.cpp | 1 + tests/unit/gui/test-gui-key.cpp | 586 ++++++++++++++++++++++++++++++++ 9 files changed, 601 insertions(+) create mode 100644 tests/unit/gui/test-gui-key.cpp diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 6f1383f44..00d863cbb 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -30,6 +30,10 @@ Bug fixes:: * irc: fix join of channels in "autojoin" server option on first connection to server if auto reconnection is performed (issue #1873) * typing: fix crash when pointer buffer is not received in callback for signal "input_text_changed" (issue #1869) +Tests:: + + * gui: add tests on key functions + Build:: * core: remove build with autotools (issue #1860) diff --git a/doc/en/weechat_dev.en.adoc b/doc/en/weechat_dev.en.adoc index 18c167355..5ffee709c 100644 --- a/doc/en/weechat_dev.en.adoc +++ b/doc/en/weechat_dev.en.adoc @@ -429,6 +429,7 @@ WeeChat "core" is located in following directories: |          test-gui-color.cpp | Tests: colors. |          test-gui-filter.cpp | Tests: filters. |          test-gui-input.cpp | Tests: input functions. +|          test-gui-key.cpp | Tests: keys. |          test-gui-line.cpp | Tests: lines. |          test-gui-nick.cpp | Tests: nicks. |       plugins/ | Root of unit tests for plugins. diff --git a/doc/fr/weechat_dev.fr.adoc b/doc/fr/weechat_dev.fr.adoc index d3f1d2a1c..b50eac0be 100644 --- a/doc/fr/weechat_dev.fr.adoc +++ b/doc/fr/weechat_dev.fr.adoc @@ -431,6 +431,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants : |          test-gui-color.cpp | Tests : couleurs. |          test-gui-filter.cpp | Tests : filtres. |          test-gui-input.cpp | Tests : fonctions d'entrée. +|          test-gui-key.cpp | Tests : touches. |          test-gui-line.cpp | Tests : lignes. |          test-gui-nick.cpp | Tests : pseudos. |       plugins/ | Racine des tests unitaires pour les extensions. diff --git a/doc/ja/weechat_dev.ja.adoc b/doc/ja/weechat_dev.ja.adoc index 529c0785e..d494e7272 100644 --- a/doc/ja/weechat_dev.ja.adoc +++ b/doc/ja/weechat_dev.ja.adoc @@ -464,6 +464,8 @@ WeeChat "core" は以下のディレクトリに配置されています: |          test-gui-filter.cpp | Tests: filters. // TRANSLATION MISSING |          test-gui-input.cpp | Tests: input functions. +// TRANSLATION MISSING +|          test-gui-key.cpp | Tests: keys. |          test-gui-line.cpp | テスト: 行 // TRANSLATION MISSING |          test-gui-nick.cpp | テスト: nicks diff --git a/doc/sr/weechat_dev.sr.adoc b/doc/sr/weechat_dev.sr.adoc index c8387cd97..0b8ad4195 100644 --- a/doc/sr/weechat_dev.sr.adoc +++ b/doc/sr/weechat_dev.sr.adoc @@ -431,6 +431,8 @@ WeeChat „језгро” се налази у следећим директо |          test-gui-color.cpp | Тестови: боје. |          test-gui-filter.cpp | Тестови: филтери. |          test-gui-input.cpp | Тестови: улазне функкције. +// TRANSLATION MISSING +|          test-gui-key.cpp | Тестови: keys. |          test-gui-line.cpp | Тестови: линије. |          test-gui-nick.cpp | Тестови: надимци. |       plugins/ | Корен unit тестова додатака. diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c index 5084156d8..e3678cfbc 100644 --- a/src/gui/gui-key.c +++ b/src/gui/gui-key.c @@ -278,6 +278,9 @@ gui_key_get_internal_code (const char *key) { char *result, *result2; + if (!key) + return NULL; + if ((key[0] == '@') && strchr (key, ':')) return strdup (key); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dd67a92cf..5d03c6532 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -51,6 +51,7 @@ set(LIB_WEECHAT_UNIT_TESTS_CORE_SRC unit/gui/test-gui-color.cpp unit/gui/test-gui-filter.cpp unit/gui/test-gui-input.cpp + unit/gui/test-gui-key.cpp unit/gui/test-gui-line.cpp unit/gui/test-gui-nick.cpp scripts/test-scripts.cpp diff --git a/tests/tests.cpp b/tests/tests.cpp index 616d35ab8..ef9a55a79 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -84,6 +84,7 @@ IMPORT_TEST_GROUP(GuiChat); IMPORT_TEST_GROUP(GuiColor); IMPORT_TEST_GROUP(GuiFilter); IMPORT_TEST_GROUP(GuiInput); +IMPORT_TEST_GROUP(GuiKey); IMPORT_TEST_GROUP(GuiLine); IMPORT_TEST_GROUP(GuiNick); /* scripts */ diff --git a/tests/unit/gui/test-gui-key.cpp b/tests/unit/gui/test-gui-key.cpp new file mode 100644 index 000000000..4d13b13ff --- /dev/null +++ b/tests/unit/gui/test-gui-key.cpp @@ -0,0 +1,586 @@ +/* + * test-gui-key.cpp - test key functions + * + * Copyright (C) 2023 Sébastien Helleu + * + * This file is part of WeeChat, the extensible chat client. + * + * WeeChat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * WeeChat is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WeeChat. If not, see . + */ + +#include "CppUTest/TestHarness.h" + +#include "tests/tests.h" + +extern "C" +{ +#include "src/gui/gui-key.h" +} + +TEST_GROUP(GuiKey) +{ +}; + +/* + * Tests functions: + * gui_key_init + */ + +TEST(GuiKey, Init) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_search_context + */ + +TEST(GuiKey, SearchContext) +{ + LONGS_EQUAL(-1, gui_key_search_context (NULL)); + LONGS_EQUAL(-1, gui_key_search_context ("")); + LONGS_EQUAL(-1, gui_key_search_context ("invalid")); + + LONGS_EQUAL(0, gui_key_search_context ("default")); + LONGS_EQUAL(1, gui_key_search_context ("search")); + LONGS_EQUAL(2, gui_key_search_context ("cursor")); + LONGS_EQUAL(3, gui_key_search_context ("mouse")); +} + +/* + * Tests functions: + * gui_key_get_current_context + */ + +TEST(GuiKey, GetCurrentContext) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_grab_init + */ + +TEST(GuiKey, GrabInit) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_grab_end_timer_cb + */ + +TEST(GuiKey, GrabEndTimerCb) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_get_internal_code + */ + +TEST(GuiKey, GetInternalCode) +{ + char *str; + + WEE_TEST_STR(NULL, gui_key_get_internal_code (NULL)); + WEE_TEST_STR("", gui_key_get_internal_code ("")); + WEE_TEST_STR("A", gui_key_get_internal_code ("A")); + WEE_TEST_STR("a", gui_key_get_internal_code ("a")); + + WEE_TEST_STR("@chat:t", gui_key_get_internal_code ("@chat:t")); + + WEE_TEST_STR("\x01[A", gui_key_get_internal_code ("meta-A")); + WEE_TEST_STR("\x01[a", gui_key_get_internal_code ("meta-a")); + + WEE_TEST_STR("\x01[[A", gui_key_get_internal_code ("meta2-A")); + WEE_TEST_STR("\x01[[a", gui_key_get_internal_code ("meta2-a")); + + WEE_TEST_STR("\x01" "A", gui_key_get_internal_code ("ctrl-A")); + WEE_TEST_STR("\x01" "a", gui_key_get_internal_code ("ctrl-a")); + + WEE_TEST_STR(" ", gui_key_get_internal_code ("space")); +} + +/* + * Tests functions: + * gui_key_get_expanded_name + */ + +TEST(GuiKey, GetExpandedName) +{ + char *str; + + WEE_TEST_STR(NULL, gui_key_get_expanded_name (NULL)); + WEE_TEST_STR("", gui_key_get_expanded_name ("")); + WEE_TEST_STR("A", gui_key_get_expanded_name ("A")); + WEE_TEST_STR("a", gui_key_get_expanded_name ("a")); + + WEE_TEST_STR("@chat:t", gui_key_get_expanded_name ("@chat:t")); + + WEE_TEST_STR("meta-A", gui_key_get_expanded_name ("\x01[A")); + WEE_TEST_STR("meta-a", gui_key_get_expanded_name ("\x01[a")); + + WEE_TEST_STR("meta2-A", gui_key_get_expanded_name ("\x01[[A")); + WEE_TEST_STR("meta2-a", gui_key_get_expanded_name ("\x01[[a")); + + WEE_TEST_STR("ctrl-A", gui_key_get_expanded_name ("\x01" "A")); + WEE_TEST_STR("ctrl-a", gui_key_get_expanded_name ("\x01" "a")); + + WEE_TEST_STR("space", gui_key_get_expanded_name (" ")); +} + +/* + * Tests functions: + * gui_key_find_pos + */ + +TEST(GuiKey, FindPos) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_insert_sorted + */ + +TEST(GuiKey, InsertSorted) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_set_area_type_name + */ + +TEST(GuiKey, SetAreaTypeName) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_set_areas + */ + +TEST(GuiKey, SetAreas) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_set_score + */ + +TEST(GuiKey, SetScore) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_is_safe + */ + +TEST(GuiKey, IsSafe) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_new + */ + +TEST(GuiKey, New) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_search + */ + +TEST(GuiKey, Search) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_cmp + */ + +TEST(GuiKey, Cmp) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_search_part + */ + +TEST(GuiKey, SearchPart) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_bind + */ + +TEST(GuiKey, Bind) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_bind_plugin_hashtable_map_cb + */ + +TEST(GuiKey, BindPluginHashtableMapCb) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_bind_plugin + */ + +TEST(GuiKey, BindPlugin) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_unbind + */ + +TEST(GuiKey, Unbind) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_unbind_plugin + */ + +TEST(GuiKey, UnbindPlugin) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_focus_matching + */ + +TEST(GuiKey, FocusMatching) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_focus_command + */ + +TEST(GuiKey, FocusCommand) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_focus + */ + +TEST(GuiKey, Focus) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_is_complete + */ + +TEST(GuiKey, IsComplete) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_pressed + */ + +TEST(GuiKey, Pressed) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_free + */ + +TEST(GuiKey, Free) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_free_all + */ + +TEST(GuiKey, FreeAll) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_buffer_optimize + */ + +TEST(GuiKey, BufferOptimize) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_buffer_reset + */ + +TEST(GuiKey, BufferReset) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_buffer_add + */ + +TEST(GuiKey, BufferAdd) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_buffer_search + */ + +TEST(GuiKey, BufferSearch) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_buffer_remove + */ + +TEST(GuiKey, BufferRemove) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_paste_remove_newline + */ + +TEST(GuiKey, PasteRemoveNewline) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_paste_replace_tabs + */ + +TEST(GuiKey, PasteReplaceTabs) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_paste_start + */ + +TEST(GuiKey, PasteStart) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_get_paste_lines + */ + +TEST(GuiKey, GetPasteLines) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_paste_check + */ + +TEST(GuiKey, PasteCheck) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_paste_bracketed_timer_cb + */ + +TEST(GuiKey, PasteBracketedTimerCb) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_paste_bracketed_timer_remove + */ + +TEST(GuiKey, PasteBracketedTimerRemove) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_paste_bracketed_timer_add + */ + +TEST(GuiKey, PasteBracketedTimerAdd) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_paste_bracketed_start + */ + +TEST(GuiKey, PasteBracketedStart) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_paste_bracketed_stop + */ + +TEST(GuiKey, PasteBracketedStop) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_paste_accept + */ + +TEST(GuiKey, PasteAccept) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_paste_cancel + */ + +TEST(GuiKey, PasteCancel) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_end + */ + +TEST(GuiKey, End) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_hdata_key_cb + */ + +TEST(GuiKey, HdataKeyCb) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_add_to_infolist + */ + +TEST(GuiKey, AddToInfolist) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_print_log_key + */ + +TEST(GuiKey, PrintLogKey) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_key_print_log + */ + +TEST(GuiKey, PrintLog) +{ + /* TODO: write tests */ +}