irc: add unit tests on ignore functions
parent
162ca1fade
commit
82a92bd4e9
|
@ -37,6 +37,10 @@ Bug fixes::
|
|||
* irc: strip spaces at beginning/end of addresses in server option "addresses" (issue #195)
|
||||
* irc: fix display of enabled/disabled client capabilities received in command CAP ACK (issue #151)
|
||||
|
||||
Tests::
|
||||
|
||||
* unit: add tests on IRC ignore functions
|
||||
|
||||
Build::
|
||||
|
||||
* debian: disable Javascript plugin on Debian Buster/Bullseye (issue #1374)
|
||||
|
|
|
@ -402,7 +402,10 @@ WeeChat "core" is located in following directories:
|
|||
| test-gui-line.cpp | Tests: lines.
|
||||
| plugins/ | Root of unit tests for plugins.
|
||||
| irc/ | Root of unit tests for IRC plugin.
|
||||
| test-irc-color.cpp | Tests: IRC colors.
|
||||
| test-irc-config.cpp | Tests: IRC configuration.
|
||||
| test-irc-ignore.cpp | Tests: IRC ignores.
|
||||
| test-irc-mode.cpp | Tests: IRC modes.
|
||||
| test-irc-protocol.cpp | Tests: IRC protocol.
|
||||
|
||||
|===
|
||||
|
|
|
@ -404,7 +404,10 @@ Le cœur de WeeChat est situé dans les répertoires suivants :
|
|||
| test-gui-line.cpp | Tests : lignes.
|
||||
| plugins/ | Racine des tests unitaires pour les extensions.
|
||||
| irc/ | Racine des tests unitaires pour l'extension IRC.
|
||||
| test-irc-color.cpp | Tests : couleurs IRC.
|
||||
| test-irc-config.cpp | Tests : configuration IRC.
|
||||
| test-irc-ignore.cpp | Tests : ignores IRC.
|
||||
| test-irc-mode.cpp | Tests : modes IRC.
|
||||
| test-irc-protocol.cpp | Tests : protocole IRC.
|
||||
|===
|
||||
|
||||
|
|
|
@ -408,7 +408,13 @@ WeeChat "core" は以下のディレクトリに配置されています:
|
|||
| test-gui-line.cpp | テスト: 行
|
||||
| plugins/ | プラグインの単体テストを収める最上位ディレクトリ
|
||||
| irc/ | IRC プラグインの単体テストを収める最上位ディレクトリ
|
||||
// TRANSLATION MISSING
|
||||
| test-irc-color.cpp | Tests: IRC colors.
|
||||
| test-irc-config.cpp | テスト: IRC 設定
|
||||
// TRANSLATION MISSING
|
||||
| test-irc-ignore.cpp | Tests: IRC ignores.
|
||||
// TRANSLATION MISSING
|
||||
| test-irc-mode.cpp | Tests: IRC modes.
|
||||
| test-irc-protocol.cpp | テスト: IRC プロトコル
|
||||
|===
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ add_library(weechat_unit_tests_core STATIC ${LIB_WEECHAT_UNIT_TESTS_CORE_SRC})
|
|||
set(LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC
|
||||
unit/plugins/irc/test-irc-color.cpp
|
||||
unit/plugins/irc/test-irc-config.cpp
|
||||
unit/plugins/irc/test-irc-ignore.cpp
|
||||
unit/plugins/irc/test-irc-mode.cpp
|
||||
unit/plugins/irc/test-irc-protocol.cpp
|
||||
)
|
||||
|
|
|
@ -63,6 +63,7 @@ lib_LTLIBRARIES = lib_weechat_unit_tests_plugins.la
|
|||
|
||||
lib_weechat_unit_tests_plugins_la_SOURCES = unit/plugins/irc/test-irc-color.cpp \
|
||||
unit/plugins/irc/test-irc-config.cpp \
|
||||
unit/plugins/irc/test-irc-ignore.cpp \
|
||||
unit/plugins/irc/test-irc-mode.cpp \
|
||||
unit/plugins/irc/test-irc-protocol.cpp
|
||||
|
||||
|
|
|
@ -0,0 +1,216 @@
|
|||
/*
|
||||
* test-irc-ignore.cpp - test IRC ignore functions
|
||||
*
|
||||
* Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "CppUTest/TestHarness.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "src/plugins/irc/irc-ignore.h"
|
||||
#include "src/plugins/irc/irc-server.h"
|
||||
}
|
||||
|
||||
TEST_GROUP(IrcIgnore)
|
||||
{
|
||||
};
|
||||
|
||||
/*
|
||||
* Tests functions:
|
||||
* irc_ignore_new
|
||||
*/
|
||||
|
||||
TEST(IrcIgnore, New)
|
||||
{
|
||||
struct t_irc_ignore *ignore;
|
||||
|
||||
POINTERS_EQUAL(NULL, irc_ignore_new (NULL, NULL, NULL));
|
||||
|
||||
ignore = irc_ignore_new ("^user@host$", NULL, NULL);
|
||||
CHECK(ignore);
|
||||
LONGS_EQUAL(1, ignore->number);
|
||||
STRCMP_EQUAL("^user@host$", ignore->mask);
|
||||
CHECK(ignore->regex_mask);
|
||||
STRCMP_EQUAL("*", ignore->server);
|
||||
STRCMP_EQUAL("*", ignore->channel);
|
||||
irc_ignore_free (ignore);
|
||||
|
||||
ignore = irc_ignore_new ("^user@host$", "freenode", "#weechat");
|
||||
CHECK(ignore);
|
||||
LONGS_EQUAL(1, ignore->number);
|
||||
STRCMP_EQUAL("^user@host$", ignore->mask);
|
||||
CHECK(ignore->regex_mask);
|
||||
STRCMP_EQUAL("freenode", ignore->server);
|
||||
STRCMP_EQUAL("#weechat", ignore->channel);
|
||||
irc_ignore_free (ignore);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests functions:
|
||||
* irc_ignore_free
|
||||
* irc_ignore_free_all
|
||||
*/
|
||||
|
||||
TEST(IrcIgnore, Free)
|
||||
{
|
||||
struct t_irc_ignore *ignore1, *ignore2, *ignore3;
|
||||
|
||||
ignore1 = irc_ignore_new ("^user1@host$", NULL, NULL);
|
||||
CHECK(ignore1);
|
||||
LONGS_EQUAL(1, ignore1->number);
|
||||
POINTERS_EQUAL(ignore1, irc_ignore_list);
|
||||
POINTERS_EQUAL(ignore1, last_irc_ignore);
|
||||
|
||||
ignore2 = irc_ignore_new ("^user2@host$", NULL, NULL);
|
||||
CHECK(ignore2);
|
||||
LONGS_EQUAL(2, ignore2->number);
|
||||
POINTERS_EQUAL(ignore1, irc_ignore_list);
|
||||
POINTERS_EQUAL(ignore2, last_irc_ignore);
|
||||
|
||||
ignore3 = irc_ignore_new ("^user3@host$", NULL, NULL);
|
||||
CHECK(ignore3);
|
||||
LONGS_EQUAL(3, ignore3->number);
|
||||
POINTERS_EQUAL(ignore1, irc_ignore_list);
|
||||
POINTERS_EQUAL(ignore3, last_irc_ignore);
|
||||
|
||||
irc_ignore_free (ignore1);
|
||||
|
||||
LONGS_EQUAL(1, ignore2->number);
|
||||
LONGS_EQUAL(2, ignore3->number);
|
||||
POINTERS_EQUAL(ignore2, irc_ignore_list);
|
||||
POINTERS_EQUAL(ignore3, last_irc_ignore);
|
||||
|
||||
irc_ignore_free_all ();
|
||||
|
||||
POINTERS_EQUAL(NULL, irc_ignore_list);
|
||||
POINTERS_EQUAL(NULL, last_irc_ignore);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests functions:
|
||||
* irc_ignore_valid
|
||||
*/
|
||||
|
||||
TEST(IrcIgnore, Valid)
|
||||
{
|
||||
struct t_irc_ignore *ignore, *ignore_invalid;
|
||||
|
||||
ignore = irc_ignore_new ("^user@host$", NULL, NULL);
|
||||
CHECK(ignore);
|
||||
LONGS_EQUAL(1, ignore->number);
|
||||
|
||||
LONGS_EQUAL(0, irc_ignore_valid (NULL));
|
||||
|
||||
ignore_invalid = (struct t_irc_ignore *)(((unsigned long)ignore) ^ 1);
|
||||
LONGS_EQUAL(0, irc_ignore_valid (ignore_invalid));
|
||||
|
||||
LONGS_EQUAL(1, irc_ignore_valid (ignore));
|
||||
|
||||
irc_ignore_free_all ();
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests functions:
|
||||
* irc_ignore_search
|
||||
* irc_ignore_search_by_number
|
||||
*/
|
||||
|
||||
TEST(IrcIgnore, Search)
|
||||
{
|
||||
struct t_irc_ignore *ignore1, *ignore2;
|
||||
|
||||
ignore1 = irc_ignore_new ("^user1@host$", "freenode", "#weechat");
|
||||
CHECK(ignore1);
|
||||
LONGS_EQUAL(1, ignore1->number);
|
||||
|
||||
ignore2 = irc_ignore_new ("^user2@host$", "server2", "#channel2");
|
||||
CHECK(ignore2);
|
||||
LONGS_EQUAL(2, ignore2->number);
|
||||
|
||||
POINTERS_EQUAL(NULL, irc_ignore_search ("not_found", NULL, NULL));
|
||||
POINTERS_EQUAL(NULL, irc_ignore_search ("not_found",
|
||||
"freenode", "#weechat"));
|
||||
POINTERS_EQUAL(NULL, irc_ignore_search ("^user1@host$",
|
||||
"server1", "#weechat"));
|
||||
POINTERS_EQUAL(NULL, irc_ignore_search ("^user1@host$",
|
||||
"freenode", "#channel1"));
|
||||
POINTERS_EQUAL(NULL, irc_ignore_search ("^user1@host$", NULL, NULL));
|
||||
POINTERS_EQUAL(NULL, irc_ignore_search ("^user2@host$", NULL, NULL));
|
||||
|
||||
POINTERS_EQUAL(ignore1, irc_ignore_search ("^user1@host$",
|
||||
"freenode", "#weechat"));
|
||||
POINTERS_EQUAL(ignore2, irc_ignore_search ("^user2@host$",
|
||||
"server2", "#channel2"));
|
||||
|
||||
POINTERS_EQUAL(NULL, irc_ignore_search_by_number (-1));
|
||||
POINTERS_EQUAL(NULL, irc_ignore_search_by_number (0));
|
||||
POINTERS_EQUAL(NULL, irc_ignore_search_by_number (3));
|
||||
|
||||
POINTERS_EQUAL(ignore1, irc_ignore_search_by_number (1));
|
||||
POINTERS_EQUAL(ignore2, irc_ignore_search_by_number (2));
|
||||
|
||||
irc_ignore_free_all ();
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests functions:
|
||||
* irc_ignore_check_host
|
||||
*/
|
||||
|
||||
TEST(IrcIgnore, CheckHost)
|
||||
{
|
||||
struct t_irc_server *server;
|
||||
struct t_irc_ignore *ignore1, *ignore2;
|
||||
|
||||
server = irc_server_alloc ("test_ignore");
|
||||
CHECK(server);
|
||||
|
||||
ignore1 = irc_ignore_new ("^user1@host$", "freenode", "#weechat");
|
||||
CHECK(ignore1);
|
||||
LONGS_EQUAL(1, ignore1->number);
|
||||
|
||||
ignore2 = irc_ignore_new ("^nick2$", NULL, NULL);
|
||||
CHECK(ignore2);
|
||||
LONGS_EQUAL(2, ignore2->number);
|
||||
|
||||
/* check server */
|
||||
LONGS_EQUAL(0, irc_ignore_check_server (ignore1, "test"));
|
||||
LONGS_EQUAL(1, irc_ignore_check_server (ignore1, "freenode"));
|
||||
LONGS_EQUAL(1, irc_ignore_check_server (ignore2, "test"));
|
||||
LONGS_EQUAL(1, irc_ignore_check_server (ignore2, "freenode"));
|
||||
|
||||
/* check channel */
|
||||
LONGS_EQUAL(0, irc_ignore_check_channel (ignore1, server, "#test", "nick"));
|
||||
LONGS_EQUAL(1, irc_ignore_check_channel (ignore1, server, "#weechat", "nick"));
|
||||
LONGS_EQUAL(0, irc_ignore_check_channel (ignore1, server, "test", "nick"));
|
||||
LONGS_EQUAL(0, irc_ignore_check_channel (ignore1, server, "weechat", "nick"));
|
||||
LONGS_EQUAL(1, irc_ignore_check_channel (ignore2, server, "#test", "nick"));
|
||||
LONGS_EQUAL(1, irc_ignore_check_channel (ignore2, server, "#weechat", "nick"));
|
||||
|
||||
/* check host */
|
||||
LONGS_EQUAL(0, irc_ignore_check_host (ignore1, "nick1", "nick!aaa@bbb"));
|
||||
LONGS_EQUAL(0, irc_ignore_check_host (ignore1, "nick1", "test"));
|
||||
LONGS_EQUAL(1, irc_ignore_check_host (ignore1, "nick1", "user1@host"));
|
||||
LONGS_EQUAL(1, irc_ignore_check_host (ignore1, "nick1", "nick1!user1@host"));
|
||||
LONGS_EQUAL(0, irc_ignore_check_host (ignore2, "nick1", "nick1!aaa@bbb"));
|
||||
LONGS_EQUAL(1, irc_ignore_check_host (ignore2, "nick2", "nick2!aaa@bbb"));
|
||||
|
||||
irc_ignore_free_all ();
|
||||
irc_server_free (server);
|
||||
}
|
Loading…
Reference in New Issue