diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-09-17 18:56:35 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-09-17 18:56:35 +0200 |
commit | a00edcf50ec77b941450e7a9670bb378904eef62 (patch) | |
tree | 78e091982ebf3000fb49bef5e0700b3ad495a372 | |
parent | be7380f9b3335d73f7ef646567ab72df408f8329 (diff) | |
download | weechat-a00edcf50ec77b941450e7a9670bb378904eef62.zip |
tests: add tests on filter functions
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | doc/en/weechat_dev.en.adoc | 1 | ||||
-rw-r--r-- | doc/fr/weechat_dev.fr.adoc | 1 | ||||
-rw-r--r-- | doc/ja/weechat_dev.ja.adoc | 2 | ||||
-rw-r--r-- | doc/sr/weechat_dev.sr.adoc | 2 | ||||
-rw-r--r-- | src/gui/gui-filter.c | 3 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/tests.cpp | 1 | ||||
-rw-r--r-- | tests/unit/gui/test-gui-filter.cpp | 323 |
10 files changed, 336 insertions, 0 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index d2312e9b5..48f8b130c 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -65,6 +65,7 @@ Tests:: * core: switch from Ubuntu 20.04 to 22.04 in CI * core: remove macOS 10.15, add macOS 12 in CI + * core: add tests on filter functions * scripts: add tests on hdata functions * scripts: fix run of Guile test script * xfer: add tests on file functions diff --git a/doc/en/weechat_dev.en.adoc b/doc/en/weechat_dev.en.adoc index a2a44ec14..18ece4d87 100644 --- a/doc/en/weechat_dev.en.adoc +++ b/doc/en/weechat_dev.en.adoc @@ -426,6 +426,7 @@ WeeChat "core" is located in following directories: | test-gui-buffer.cpp | Tests: buffer functions. | test-gui-chat.cpp | Tests: chat functions. | test-gui-color.cpp | Tests: colors. +| test-gui-filter.cpp | Tests: filters. | 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 4ed060136..16183b149 100644 --- a/doc/fr/weechat_dev.fr.adoc +++ b/doc/fr/weechat_dev.fr.adoc @@ -428,6 +428,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants : | test-gui-buffer.cpp | Tests : fonctions de tampons. | test-gui-chat.cpp | Tests : fonctions de discussion. | test-gui-color.cpp | Tests : couleurs. +| test-gui-filter.cpp | Tests : filtres. | 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 6e2fdb3a2..ee1b49ad8 100644 --- a/doc/ja/weechat_dev.ja.adoc +++ b/doc/ja/weechat_dev.ja.adoc @@ -458,6 +458,8 @@ WeeChat "core" は以下のディレクトリに配置されています: | test-gui-chat.cpp | Tests: chat functions. // TRANSLATION MISSING | test-gui-color.cpp | Tests: colors. +// TRANSLATION MISSING +| test-gui-filter.cpp | Tests: filters. | 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 e7b0f2672..cf660781b 100644 --- a/doc/sr/weechat_dev.sr.adoc +++ b/doc/sr/weechat_dev.sr.adoc @@ -428,6 +428,8 @@ WeeChat „језгро” се налази у следећим директо | test-gui-buffer.cpp | Тестови: бафер функције. | test-gui-chat.cpp | Тестови: чет функције. | test-gui-color.cpp | Тестови: боје. +// TRANSLATION MISSING +| test-gui-filter.cpp | Тестови: filters. | test-gui-line.cpp | Тестови: линије. | test-gui-nick.cpp | Тестови: надимци. | plugins/ | Корен unit тестова додатака. diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c index 3b42eb66e..242ea58da 100644 --- a/src/gui/gui-filter.c +++ b/src/gui/gui-filter.c @@ -251,6 +251,9 @@ gui_filter_search_by_name (const char *name) { struct t_gui_filter *ptr_filter; + if (!name) + return NULL; + for (ptr_filter = gui_filters; ptr_filter; ptr_filter = ptr_filter->next_filter) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c040c2d8a..eb53b8e3f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -48,6 +48,7 @@ set(LIB_WEECHAT_UNIT_TESTS_CORE_SRC unit/gui/test-gui-buffer.cpp unit/gui/test-gui-chat.cpp unit/gui/test-gui-color.cpp + unit/gui/test-gui-filter.cpp unit/gui/test-gui-line.cpp unit/gui/test-gui-nick.cpp scripts/test-scripts.cpp diff --git a/tests/Makefile.am b/tests/Makefile.am index 4b974636b..89a7a3d7a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -45,6 +45,7 @@ lib_weechat_unit_tests_core_a_SOURCES = unit/core/test-core-arraylist.cpp \ unit/gui/test-gui-buffer.cpp \ unit/gui/test-gui-chat.cpp \ unit/gui/test-gui-color.cpp \ + unit/gui/test-gui-filter.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 bf16dfea5..5f12a89cc 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -85,6 +85,7 @@ IMPORT_TEST_GROUP(GuiBarWindow); IMPORT_TEST_GROUP(GuiBuffer); IMPORT_TEST_GROUP(GuiChat); IMPORT_TEST_GROUP(GuiColor); +IMPORT_TEST_GROUP(GuiFilter); IMPORT_TEST_GROUP(GuiLine); IMPORT_TEST_GROUP(GuiNick); /* scripts */ diff --git a/tests/unit/gui/test-gui-filter.cpp b/tests/unit/gui/test-gui-filter.cpp new file mode 100644 index 000000000..d0c54ad1b --- /dev/null +++ b/tests/unit/gui/test-gui-filter.cpp @@ -0,0 +1,323 @@ +/* + * test-gui-filter.cpp - test filter functions + * + * Copyright (C) 2022 Sébastien Helleu <flashcode@flashtux.org> + * + * 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 <https://www.gnu.org/licenses/>. + */ + +#include "CppUTest/TestHarness.h" + +extern "C" +{ +#include <string.h> +#include "src/gui/gui-buffer.h" +#include "src/gui/gui-chat.h" +#include "src/gui/gui-filter.h" +#include "src/gui/gui-line.h" + +extern struct t_gui_filter *gui_filter_find_pos (struct t_gui_filter *filter); + +} + +TEST_GROUP(GuiFilter) +{ +}; + +/* + * Tests functions: + * gui_filter_check_line + */ + +TEST(GuiFilter, CheckLine) +{ + struct t_gui_filter *filter1, *filter2; + struct t_gui_line_data *line_data, *line_data_no_filter; + + gui_chat_printf_date_tags (NULL, 0, "tag1,tag2,tag3", "this is a test"); + gui_chat_printf_date_tags (NULL, 0, "no_filter", "this is a test"); + + line_data = gui_buffers->lines->last_line->prev_line->data; + line_data_no_filter = gui_buffers->lines->last_line->data; + + LONGS_EQUAL(1, gui_filter_check_line (line_data)); + + filter1 = gui_filter_new (1, "test1", "irc.test.#chan", "tag_xxx", "xxx"); + filter2 = gui_filter_new (1, "test2", "*", "*", "this is"); + + LONGS_EQUAL(0, gui_filter_check_line (line_data)); + LONGS_EQUAL(1, gui_filter_check_line (line_data_no_filter)); + + filter2->enabled = 0; + LONGS_EQUAL(1, gui_filter_check_line (line_data)); + filter2->enabled = 1; + LONGS_EQUAL(0, gui_filter_check_line (line_data)); + + gui_filter_free (filter1); + gui_filter_free (filter2); + + LONGS_EQUAL(1, gui_filter_check_line (line_data)); + LONGS_EQUAL(1, gui_filter_check_line (line_data_no_filter)); + + filter1 = gui_filter_new (1, "test1", "*", "*", "!xxx"); + LONGS_EQUAL(0, gui_filter_check_line (line_data)); + LONGS_EQUAL(1, gui_filter_check_line (line_data_no_filter)); + + gui_filter_free (filter1); +} + +/* + * Tests functions: + * gui_filter_buffer + */ + +TEST(GuiFilter, Buffer) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_filter_all_buffers + */ + +TEST(GuiFilter, AllBuffers) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_filter_global_enable + * gui_filter_global_disable + */ + +TEST(GuiFilter, GlobalEnableDisable) +{ + LONGS_EQUAL(1, gui_filters_enabled); + gui_filter_global_disable (); + LONGS_EQUAL(0, gui_filters_enabled); + gui_filter_global_enable (); + LONGS_EQUAL(1, gui_filters_enabled); +} + +/* + * Tests functions: + * gui_filter_search_by_name + */ + +TEST(GuiFilter, SearchByName) +{ + struct t_gui_filter *filter_abc, *filter_xyz; + + POINTERS_EQUAL(NULL, gui_filter_search_by_name (NULL)); + POINTERS_EQUAL(NULL, gui_filter_search_by_name ("")); + POINTERS_EQUAL(NULL, gui_filter_search_by_name ("abc")); + POINTERS_EQUAL(NULL, gui_filter_search_by_name ("xyz")); + POINTERS_EQUAL(NULL, gui_filter_search_by_name ("zzz")); + + filter_xyz = gui_filter_new (1, "xyz", "*", "tag_xyz", "regex_xyz"); + POINTERS_EQUAL(NULL, gui_filter_search_by_name ("abc")); + POINTERS_EQUAL(filter_xyz, gui_filter_search_by_name ("xyz")); + POINTERS_EQUAL(NULL, gui_filter_search_by_name ("zzz")); + + filter_abc = gui_filter_new (1, "abc", "*", "tag_abc", "regex_abc"); + POINTERS_EQUAL(filter_abc, gui_filter_search_by_name ("abc")); + POINTERS_EQUAL(filter_xyz, gui_filter_search_by_name ("xyz")); + POINTERS_EQUAL(NULL, gui_filter_search_by_name ("zzz")); + + gui_filter_free (filter_abc); + gui_filter_free (filter_xyz); +} + +/* + * Tests functions: + * gui_filter_new_error + */ + +TEST(GuiFilter, NewError) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_filter_find_pos + * gui_filter_add_to_list + * gui_filter_remove_from_list + * gui_filter_new + * gui_filter_free + * gui_filter_free_all + */ + +TEST(GuiFilter, New) +{ + struct t_gui_filter *filter_abc, *filter_test, *filter_xyz; + + POINTERS_EQUAL(NULL, gui_filter_new (1, NULL, NULL, NULL, NULL)); + POINTERS_EQUAL(NULL, gui_filter_new (1, "test", NULL, NULL, NULL)); + POINTERS_EQUAL(NULL, gui_filter_new (1, "test", "*", NULL, NULL)); + POINTERS_EQUAL(NULL, gui_filter_new (1, "test", "*", "tag_abc", NULL)); + + /* invalid regex */ + POINTERS_EQUAL(NULL, gui_filter_new (0, "abc", "*", "*", "prefix\\t*abc")); + POINTERS_EQUAL(NULL, gui_filter_new (0, "abc", "*", "*", "*prefix\\tabc")); + + filter_abc = gui_filter_new (0, "abc", "*", "tag_abc", "!regex_abc"); + LONGS_EQUAL(0, filter_abc->enabled); + STRCMP_EQUAL("abc", filter_abc->name); + STRCMP_EQUAL("*", filter_abc->buffer_name); + LONGS_EQUAL(1, filter_abc->num_buffers); + STRCMP_EQUAL("*", filter_abc->buffers[0]); + POINTERS_EQUAL(NULL, filter_abc->buffers[1]); + STRCMP_EQUAL("tag_abc", filter_abc->tags); + LONGS_EQUAL(1, filter_abc->tags_count); + STRCMP_EQUAL("tag_abc", filter_abc->tags_array[0][0]); + POINTERS_EQUAL(NULL, filter_abc->tags_array[0][1]); + POINTERS_EQUAL(NULL, filter_abc->tags_array[1]); + STRCMP_EQUAL("!regex_abc", filter_abc->regex); + POINTERS_EQUAL(NULL, filter_abc->regex_prefix); + CHECK(filter_abc->regex_message); + POINTERS_EQUAL(NULL, filter_abc->prev_filter); + POINTERS_EQUAL(NULL, filter_abc->next_filter); + POINTERS_EQUAL(filter_abc, gui_filters); + POINTERS_EQUAL(filter_abc, last_gui_filter); + + /* filter already existing */ + POINTERS_EQUAL(NULL, gui_filter_new (1, "abc", "*", "tag2_abc", "regex2_abc")); + + filter_xyz = gui_filter_new (1, "xyz", "irc.test.#chan,irc.test.#chan2", + "tag_xyz,tag2_xyz+tag3_xyz", "prefix\\txyz"); + LONGS_EQUAL(1, filter_xyz->enabled); + STRCMP_EQUAL("xyz", filter_xyz->name); + STRCMP_EQUAL("irc.test.#chan,irc.test.#chan2", filter_xyz->buffer_name); + LONGS_EQUAL(2, filter_xyz->num_buffers); + STRCMP_EQUAL("irc.test.#chan", filter_xyz->buffers[0]); + STRCMP_EQUAL("irc.test.#chan2", filter_xyz->buffers[1]); + POINTERS_EQUAL(NULL, filter_xyz->buffers[2]); + STRCMP_EQUAL("tag_xyz,tag2_xyz+tag3_xyz", filter_xyz->tags); + LONGS_EQUAL(2, filter_xyz->tags_count); + STRCMP_EQUAL("tag_xyz", filter_xyz->tags_array[0][0]); + POINTERS_EQUAL(NULL, filter_xyz->tags_array[0][1]); + STRCMP_EQUAL("tag2_xyz", filter_xyz->tags_array[1][0]); + STRCMP_EQUAL("tag3_xyz", filter_xyz->tags_array[1][1]); + POINTERS_EQUAL(NULL, filter_xyz->tags_array[1][2]); + POINTERS_EQUAL(NULL, filter_xyz->tags_array[2]); + STRCMP_EQUAL("prefix\\txyz", filter_xyz->regex); + CHECK(filter_xyz->regex_prefix); + CHECK(filter_xyz->regex_message); + POINTERS_EQUAL(filter_abc, filter_xyz->prev_filter); + POINTERS_EQUAL(NULL, filter_xyz->next_filter); + POINTERS_EQUAL(filter_abc, gui_filters); + POINTERS_EQUAL(filter_xyz, last_gui_filter); + + filter_test = gui_filter_new (1, "test", "*", "*", "regex_test"); + LONGS_EQUAL(1, filter_test->enabled); + STRCMP_EQUAL("test", filter_test->name); + STRCMP_EQUAL("*", filter_test->buffer_name); + LONGS_EQUAL(1, filter_test->num_buffers); + STRCMP_EQUAL("*", filter_test->buffers[0]); + POINTERS_EQUAL(NULL, filter_test->buffers[1]); + STRCMP_EQUAL("*", filter_test->tags); + LONGS_EQUAL(1, filter_test->tags_count); + STRCMP_EQUAL("*", filter_test->tags_array[0][0]); + POINTERS_EQUAL(NULL, filter_test->tags_array[0][1]); + POINTERS_EQUAL(NULL, filter_test->tags_array[1]); + STRCMP_EQUAL("regex_test", filter_test->regex); + POINTERS_EQUAL(NULL, filter_test->regex_prefix); + CHECK(filter_test->regex_message); + POINTERS_EQUAL(filter_abc, filter_test->prev_filter); + POINTERS_EQUAL(filter_xyz, filter_test->next_filter); + POINTERS_EQUAL(filter_abc, gui_filters); + POINTERS_EQUAL(filter_xyz, last_gui_filter); + + gui_filter_free (filter_test); + + gui_filter_free (NULL); + + gui_filter_free_all (); +} + +/* + * Tests functions: + * gui_filter_rename + */ + +TEST(GuiFilter, Rename) +{ + struct t_gui_filter *filter1, *filter2; + + LONGS_EQUAL(0, gui_filter_rename (NULL, NULL)); + + filter1 = gui_filter_new (1, "abc", "*", "tag_abc", "regex_abc"); + POINTERS_EQUAL(filter1, gui_filters); + POINTERS_EQUAL(filter1, last_gui_filter); + + filter2 = gui_filter_new (1, "xyz", "*", "tag_xyz", "regex_xyz"); + POINTERS_EQUAL(filter1, gui_filters); + POINTERS_EQUAL(filter2, last_gui_filter); + + LONGS_EQUAL(0, gui_filter_rename (filter1, NULL)); + LONGS_EQUAL(0, gui_filter_rename (filter1, "abc")); + + LONGS_EQUAL(1, gui_filter_rename (filter1, "a")); + STRCMP_EQUAL("a", filter1->name); + POINTERS_EQUAL(filter1, gui_filters); + POINTERS_EQUAL(filter2, last_gui_filter); + + LONGS_EQUAL(1, gui_filter_rename (filter1, "z")); + STRCMP_EQUAL("z", filter1->name); + POINTERS_EQUAL(filter2, gui_filters); + POINTERS_EQUAL(filter1, last_gui_filter); + + LONGS_EQUAL(1, gui_filter_rename (filter2, "zzz")); + STRCMP_EQUAL("zzz", filter2->name); + POINTERS_EQUAL(filter1, gui_filters); + POINTERS_EQUAL(filter2, last_gui_filter); + + gui_filter_free (filter1); + gui_filter_free (filter2); +} + +/* + * Tests functions: + * gui_filter_hdata_filter_cb + */ + +TEST(GuiFilter, HdataFilterCb) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_filter_add_to_infolist + */ + +TEST(GuiFilter, AddToInfolist) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * gui_filter_print_log + */ + +TEST(GuiFilter, PrintLog) +{ + /* TODO: write tests */ +} |