diff --git a/ChangeLog.adoc b/ChangeLog.adoc index b4cf1d464..b44f08654 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -63,6 +63,7 @@ Bug fixes:: Tests:: * core: add tests on mouse events (issue #2082) + * gui: add tests on hotlist functions * scripts: make tests fail if a compiled scripting plugin fails to load * scripts: add tests on constants diff --git a/doc/en/weechat_dev.en.adoc b/doc/en/weechat_dev.en.adoc index 6af347fe8..9271aa558 100644 --- a/doc/en/weechat_dev.en.adoc +++ b/doc/en/weechat_dev.en.adoc @@ -439,6 +439,7 @@ WeeChat "core" is located in following directories: |          test-gui-chat.cpp | Tests: chat functions. |          test-gui-color.cpp | Tests: colors. |          test-gui-filter.cpp | Tests: filters. +|          test-gui-hotlist.cpp | Tests: hotlist functions. |          test-gui-input.cpp | Tests: input functions. |          test-gui-key.cpp | Tests: keys. |          test-gui-line.cpp | Tests: lines. diff --git a/doc/fr/weechat_dev.fr.adoc b/doc/fr/weechat_dev.fr.adoc index 322ed7b51..2e34f1073 100644 --- a/doc/fr/weechat_dev.fr.adoc +++ b/doc/fr/weechat_dev.fr.adoc @@ -441,6 +441,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants : |          test-gui-chat.cpp | Tests : fonctions de discussion. |          test-gui-color.cpp | Tests : couleurs. |          test-gui-filter.cpp | Tests : filtres. +|          test-gui-hotlist.cpp | Tests : fonctions hotlist. |          test-gui-input.cpp | Tests : fonctions d'entrée. |          test-gui-key.cpp | Tests : touches. |          test-gui-line.cpp | Tests : lignes. diff --git a/doc/ja/weechat_dev.ja.adoc b/doc/ja/weechat_dev.ja.adoc index de6145492..85c5fb4ba 100644 --- a/doc/ja/weechat_dev.ja.adoc +++ b/doc/ja/weechat_dev.ja.adoc @@ -490,6 +490,8 @@ WeeChat "core" は以下のディレクトリに配置されています: // TRANSLATION MISSING |          test-gui-filter.cpp | Tests: filters. // TRANSLATION MISSING +|          test-gui-hotlist.cpp | Tests: hotlist functions. +// TRANSLATION MISSING |          test-gui-input.cpp | Tests: input functions. // TRANSLATION MISSING |          test-gui-key.cpp | Tests: keys. diff --git a/doc/sr/weechat_dev.sr.adoc b/doc/sr/weechat_dev.sr.adoc index 6835aaf4a..745a38118 100644 --- a/doc/sr/weechat_dev.sr.adoc +++ b/doc/sr/weechat_dev.sr.adoc @@ -441,6 +441,8 @@ WeeChat „језгро” се налази у следећим директо |          test-gui-chat.cpp | Тестови: чет функције. |          test-gui-color.cpp | Тестови: боје. |          test-gui-filter.cpp | Тестови: филтери. +// TRANSLATION MISSING +|          test-gui-hotlist.cpp | Tests: hotlist functions. |          test-gui-input.cpp | Тестови: улазне функције. |          test-gui-key.cpp | Тестови: тастери. |          test-gui-line.cpp | Тестови: линије. diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c7d855aaf..4667b7a32 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -78,6 +78,7 @@ set(LIB_WEECHAT_UNIT_TESTS_CORE_SRC unit/gui/test-gui-chat.cpp unit/gui/test-gui-color.cpp unit/gui/test-gui-filter.cpp + unit/gui/test-gui-hotlist.cpp unit/gui/test-gui-input.cpp unit/gui/test-gui-key.cpp unit/gui/test-gui-line.cpp diff --git a/tests/tests.cpp b/tests/tests.cpp index c830da258..6060c0871 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -89,6 +89,7 @@ IMPORT_TEST_GROUP(GuiBuffer); IMPORT_TEST_GROUP(GuiChat); IMPORT_TEST_GROUP(GuiColor); IMPORT_TEST_GROUP(GuiFilter); +IMPORT_TEST_GROUP(GuiHotlist); IMPORT_TEST_GROUP(GuiInput); IMPORT_TEST_GROUP(GuiKey); IMPORT_TEST_GROUP(GuiLine); diff --git a/tests/unit/gui/test-gui-hotlist.cpp b/tests/unit/gui/test-gui-hotlist.cpp new file mode 100644 index 000000000..cd5fe5162 --- /dev/null +++ b/tests/unit/gui/test-gui-hotlist.cpp @@ -0,0 +1,517 @@ +/* + * test-gui-hotlist.cpp - test hotlist functions + * + * Copyright (C) 2024 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" + +extern "C" +{ +#include +#include +#include +#include "src/core/core-config.h" +#include "src/core/core-config-file.h" +#include "src/core/core-hook.h" +#include "src/gui/gui-buffer.h" +#include "src/gui/gui-hotlist.h" + +extern struct t_gui_hotlist *gui_hotlist_dup (struct t_gui_hotlist *hotlist); +extern int gui_hotlist_compare_hotlists (struct t_hdata *hdata_hotlist, + struct t_gui_hotlist *hotlist1, + struct t_gui_hotlist *hotlist2); +extern void gui_hotlist_free_all (struct t_gui_hotlist **hotlist, + struct t_gui_hotlist **last_hotlist); +} + +/* + * test buffers: + * buffer_test[0] ("test1"): + * low: 1, message: 0, private: 0, highlight: 0 + * local variable "priority": 6 + * buffer_test[1] ("test2"): + * low: 1, message: 2, private: 0, highlight: 3 + * local variable "priority": 4 + * buffer_test[2] ("Test3"): + * low: 0, message: 0, private: 1, highlight: 0 + * local variable "priority": 8 + * + * with default hotlist sort: + * [test2, test3, test1] + */ +struct t_gui_buffer *buffer_test[3]; +const char *buffer_names[3] = { "test1", "test2", "Test3" }; + +TEST_GROUP(GuiHotlist) +{ + void setup () + { + int i; + + for (i = 0; i < 3; i++) + { + buffer_test[i] = gui_buffer_new (NULL, buffer_names[i], + NULL, NULL, NULL, + NULL, NULL, NULL); + } + /* buffer "test1": 1 low */ + gui_hotlist_add (buffer_test[0], GUI_HOTLIST_LOW, NULL, 0); + gui_buffer_set (buffer_test[0], "localvar_set_priority", "6"); + /* buffer "test2": 1 low, 2 messages, 3 highlights */ + gui_hotlist_add (buffer_test[1], GUI_HOTLIST_PRIVATE, NULL, 0); + gui_hotlist_add (buffer_test[1], GUI_HOTLIST_MESSAGE, NULL, 0); + gui_hotlist_add (buffer_test[1], GUI_HOTLIST_MESSAGE, NULL, 0); + gui_hotlist_add (buffer_test[1], GUI_HOTLIST_HIGHLIGHT, NULL, 0); + gui_hotlist_add (buffer_test[1], GUI_HOTLIST_HIGHLIGHT, NULL, 0); + gui_hotlist_add (buffer_test[1], GUI_HOTLIST_HIGHLIGHT, NULL, 0); + gui_buffer_set (buffer_test[1], "localvar_set_priority", "4"); + /* buffer "Test3": 2 private */ + gui_hotlist_add (buffer_test[2], GUI_HOTLIST_PRIVATE, NULL, 0); + gui_hotlist_add (buffer_test[2], GUI_HOTLIST_PRIVATE, NULL, 0); + gui_buffer_set (buffer_test[2], "localvar_set_priority", "8"); + } + + void teardown () + { + int i; + + for (i = 0; i < 3; i++) + { + gui_buffer_close (buffer_test[i]); + buffer_test[i] = NULL; + } + } +}; + +/* + * Tests functions: + * gui_hotlist_changed_signal + */ + +TEST(GuiHotlist, ChangedSignal) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_hotlist_search_priority + */ + +TEST(GuiHotlist, SearchPriority) +{ + LONGS_EQUAL(-1, gui_hotlist_search_priority (NULL)); + LONGS_EQUAL(-1, gui_hotlist_search_priority ("")); + LONGS_EQUAL(-1, gui_hotlist_search_priority ("invalid")); + + LONGS_EQUAL(0, gui_hotlist_search_priority ("low")); + LONGS_EQUAL(1, gui_hotlist_search_priority ("message")); + LONGS_EQUAL(2, gui_hotlist_search_priority ("private")); + LONGS_EQUAL(3, gui_hotlist_search_priority ("highlight")); +} + +/* + * Tests functions: + * gui_hotlist_search + */ + +TEST(GuiHotlist, Search) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_hotlist_dup + */ + +TEST(GuiHotlist, Dup) +{ + struct t_gui_hotlist *hotlist, *hotlist_dup; + + hotlist = (struct t_gui_hotlist *)malloc (sizeof (*hotlist)); + CHECK(hotlist); + hotlist->priority = GUI_HOTLIST_HIGHLIGHT; + hotlist->creation_time.tv_sec = 1710623372; + hotlist->creation_time.tv_usec = 123456; + hotlist->buffer = gui_buffers; + hotlist->count[0] = 12; + hotlist->count[1] = 34; + hotlist->count[2] = 56; + hotlist->count[3] = 78; + hotlist->prev_hotlist = NULL; + hotlist->next_hotlist = NULL; + + hotlist_dup = gui_hotlist_dup (hotlist); + CHECK(hotlist_dup); + LONGS_EQUAL(GUI_HOTLIST_HIGHLIGHT, hotlist_dup->priority); + LONGS_EQUAL(1710623372, hotlist_dup->creation_time.tv_sec); + LONGS_EQUAL(123456, hotlist_dup->creation_time.tv_usec); + LONGS_EQUAL(12, hotlist_dup->count[0]); + LONGS_EQUAL(34, hotlist_dup->count[1]); + LONGS_EQUAL(56, hotlist_dup->count[2]); + LONGS_EQUAL(78, hotlist_dup->count[3]); + POINTERS_EQUAL(NULL, hotlist_dup->prev_hotlist); + POINTERS_EQUAL(NULL, hotlist_dup->next_hotlist); + + free (hotlist); + free (hotlist_dup); +} + +/* + * Tests functions: + * gui_hotlist_free + */ + +TEST(GuiHotlist, Free) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_hotlist_free_all + */ + +TEST(GuiHotlist, FreeAll) +{ + CHECK(gui_hotlist); + CHECK(last_gui_hotlist); + + gui_hotlist_free_all (&gui_hotlist, &last_gui_hotlist); + + POINTERS_EQUAL(NULL, gui_hotlist); + POINTERS_EQUAL(NULL, last_gui_hotlist); +} + +/* + * Tests functions: + * gui_hotlist_check_buffer_notify + */ + +TEST(GuiHotlist, CheckBufferNotify) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_hotlist_compare_hotlists + */ + +TEST(GuiHotlist, CompareHotlists) +{ + struct t_hdata *hdata_hotlist; + + hdata_hotlist = hook_hdata_get (NULL, "hotlist"); + + config_file_option_set (config_look_hotlist_sort, "buffer.number", 1); + + LONGS_EQUAL(0, gui_hotlist_compare_hotlists (hdata_hotlist, NULL, NULL)); + LONGS_EQUAL(1, gui_hotlist_compare_hotlists (hdata_hotlist, gui_hotlist, NULL)); + LONGS_EQUAL(-1, gui_hotlist_compare_hotlists (hdata_hotlist, NULL, gui_hotlist)); + + config_file_option_set (config_look_hotlist_sort, "-buffer.number", 1); + + LONGS_EQUAL(0, gui_hotlist_compare_hotlists (hdata_hotlist, NULL, NULL)); + LONGS_EQUAL(-1, gui_hotlist_compare_hotlists (hdata_hotlist, gui_hotlist, NULL)); + LONGS_EQUAL(1, gui_hotlist_compare_hotlists (hdata_hotlist, NULL, gui_hotlist)); + + config_file_option_reset (config_look_hotlist_sort, 1); +} + +/* + * Tests functions: + * gui_hotlist_find_pos + */ + +TEST(GuiHotlist, FindPos) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_hotlist_add_hotlist + */ + +TEST(GuiHotlist, AddHotlist) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_hotlist_add + */ + +TEST(GuiHotlist, Add) +{ + struct t_gui_hotlist *hotlist; + struct timeval tv; + + tv.tv_sec = 1710683593; + tv.tv_usec = 123456; + + hotlist = gui_hotlist_add (gui_buffers, GUI_HOTLIST_LOW, &tv, 0); + CHECK(hotlist); + + LONGS_EQUAL(GUI_HOTLIST_LOW, hotlist->priority); + LONGS_EQUAL(1710683593, hotlist->creation_time.tv_sec); + LONGS_EQUAL(123456, hotlist->creation_time.tv_usec); + POINTERS_EQUAL(gui_buffers, hotlist->buffer); + LONGS_EQUAL(1, hotlist->count[0]); + LONGS_EQUAL(0, hotlist->count[1]); + LONGS_EQUAL(0, hotlist->count[2]); + LONGS_EQUAL(0, hotlist->count[3]); + + gui_hotlist_remove_buffer (gui_buffers, 1); +} + +/* + * Tests functions: + * gui_hotlist_remove_buffer + * gui_hotlist_restore_buffer + */ + +TEST(GuiHotlist, RestoreBuffer) +{ + gui_hotlist_remove_buffer (buffer_test[1], 0); + + POINTERS_EQUAL(buffer_test[2], gui_hotlist->buffer); + POINTERS_EQUAL(buffer_test[0], gui_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist->next_hotlist); + + gui_hotlist_remove_buffer (buffer_test[2], 0); + + POINTERS_EQUAL(buffer_test[0], gui_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist); + + gui_hotlist_restore_buffer (buffer_test[1]); + + POINTERS_EQUAL(buffer_test[1], gui_hotlist->buffer); + POINTERS_EQUAL(buffer_test[0], gui_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist->next_hotlist); + + gui_hotlist_restore_buffer (buffer_test[2]); + + POINTERS_EQUAL(buffer_test[1], gui_hotlist->buffer); + POINTERS_EQUAL(buffer_test[2], gui_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(buffer_test[0], gui_hotlist->next_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist->next_hotlist->next_hotlist); + + gui_hotlist_remove_buffer (buffer_test[0], 0); + gui_hotlist_remove_buffer (buffer_test[1], 0); + gui_hotlist_remove_buffer (buffer_test[2], 0); + + POINTERS_EQUAL(NULL, gui_hotlist); +} + +/* + * Tests functions: + * gui_hotlist_restore_all_buffers + */ + +TEST(GuiHotlist, RestoreAllBuffers) +{ + if (gui_buffers->hotlist_removed) + { + free (gui_buffers->hotlist_removed); + gui_buffers->hotlist_removed = NULL; + } + + gui_hotlist_remove_buffer (buffer_test[0], 1); + gui_hotlist_remove_buffer (buffer_test[1], 1); + gui_hotlist_remove_buffer (buffer_test[2], 1); + + POINTERS_EQUAL(NULL, gui_hotlist); + + gui_hotlist_restore_all_buffers (); + + POINTERS_EQUAL(buffer_test[1], gui_hotlist->buffer); + POINTERS_EQUAL(buffer_test[2], gui_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(buffer_test[0], gui_hotlist->next_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist->next_hotlist->next_hotlist); +} + +/* + * Tests functions: + * gui_hotlist_resort + */ + +TEST(GuiHotlist, Resort) +{ + /* with default sort */ + POINTERS_EQUAL(buffer_test[1], gui_hotlist->buffer); + POINTERS_EQUAL(buffer_test[2], gui_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(buffer_test[0], gui_hotlist->next_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist->next_hotlist->next_hotlist); + + /* sort by buffer number */ + config_file_option_set (config_look_hotlist_sort, "buffer.number", 1); + POINTERS_EQUAL(buffer_test[0], gui_hotlist->buffer); + POINTERS_EQUAL(buffer_test[1], gui_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(buffer_test[2], gui_hotlist->next_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist->next_hotlist->next_hotlist); + + /* sort by buffer number (descending) */ + config_file_option_set (config_look_hotlist_sort, "-buffer.number", 1); + POINTERS_EQUAL(buffer_test[2], gui_hotlist->buffer); + POINTERS_EQUAL(buffer_test[1], gui_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(buffer_test[0], gui_hotlist->next_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist->next_hotlist->next_hotlist); + + /* sort by buffer name (case sensitive) */ + config_file_option_set (config_look_hotlist_sort, "buffer.name", 1); + POINTERS_EQUAL(buffer_test[2], gui_hotlist->buffer); + POINTERS_EQUAL(buffer_test[0], gui_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(buffer_test[1], gui_hotlist->next_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist->next_hotlist->next_hotlist); + + /* sort by buffer name (case insensitive) */ + config_file_option_set (config_look_hotlist_sort, "~buffer.name", 1); + POINTERS_EQUAL(buffer_test[0], gui_hotlist->buffer); + POINTERS_EQUAL(buffer_test[1], gui_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(buffer_test[2], gui_hotlist->next_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist->next_hotlist->next_hotlist); + + /* sort by local variable "priority" (descending) */ + config_file_option_set (config_look_hotlist_sort, "-buffer.local_variables.priority", 1); + POINTERS_EQUAL(buffer_test[2], gui_hotlist->buffer); + POINTERS_EQUAL(buffer_test[0], gui_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(buffer_test[1], gui_hotlist->next_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist->next_hotlist->next_hotlist); + + config_file_option_reset (config_look_hotlist_sort, 1); +} + +/* + * Tests functions: + * gui_hotlist_clear + */ + +TEST(GuiHotlist, Clear) +{ + CHECK(gui_hotlist); + + /* clear only low join/part (1) */ + gui_hotlist_clear (1); + + POINTERS_EQUAL(buffer_test[1], gui_hotlist->buffer); + POINTERS_EQUAL(buffer_test[2], gui_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist->next_hotlist); + + /* clear low join/part (1) + private (4) */ + gui_hotlist_clear (5); + + POINTERS_EQUAL(buffer_test[1], gui_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist); + + /* clear whole hotlist (1=join/part + 2=msg + 4=private + 5=highlight) */ + gui_hotlist_clear (15); + + POINTERS_EQUAL(NULL, gui_hotlist); +} + +/* + * Tests functions: + * gui_hotlist_clear_level_string + */ + +TEST(GuiHotlist, ClearLevelString) +{ + POINTERS_EQUAL(NULL, gui_hotlist_initial_buffer); + + gui_hotlist_clear_level_string (buffer_test[0], "lowest"); + + POINTERS_EQUAL(buffer_test[1], gui_hotlist->buffer); + POINTERS_EQUAL(buffer_test[2], gui_hotlist->next_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist->next_hotlist); + POINTERS_EQUAL(buffer_test[0], gui_hotlist_initial_buffer); + + gui_hotlist_clear_level_string (buffer_test[1], "highest"); + + POINTERS_EQUAL(buffer_test[2], gui_hotlist->buffer); + POINTERS_EQUAL(NULL, gui_hotlist->next_hotlist); + + POINTERS_EQUAL(buffer_test[1], gui_hotlist_initial_buffer); + gui_hotlist_clear_level_string (buffer_test[2], "4"); + + POINTERS_EQUAL(NULL, gui_hotlist); + POINTERS_EQUAL(buffer_test[2], gui_hotlist_initial_buffer); + + gui_hotlist_add (buffer_test[0], GUI_HOTLIST_PRIVATE, NULL, 0); + gui_hotlist_add (buffer_test[1], GUI_HOTLIST_MESSAGE, NULL, 0); + gui_hotlist_add (buffer_test[2], GUI_HOTLIST_HIGHLIGHT, NULL, 0); + + gui_hotlist_clear_level_string (buffer_test[1], NULL); + + POINTERS_EQUAL(NULL, gui_hotlist); + POINTERS_EQUAL(buffer_test[1], gui_hotlist_initial_buffer); +} + +/* + * Tests functions: + * gui_hotlist_remove_buffer + */ + +TEST(GuiHotlist, RemoveBuffer) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_hotlist_hdata_hotlist_cb + */ + +TEST(GuiHotlist, HdataHotlistCb) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_hotlist_add_to_infolist + */ + +TEST(GuiHotlist, AddToInfolist) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_hotlist_print_log + */ + +TEST(GuiHotlist, PrintLog) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_hotlist_end + */ + +TEST(GuiHotlist, End) +{ + /* TODO: write tests */ +}