summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2019-07-10 19:20:09 +0200
committerSébastien Helleu <flashcode@flashtux.org>2019-07-10 19:20:09 +0200
commit82a92bd4e9bc2330b9c25cc1a54be658bff1312e (patch)
tree465924f1a3514f4dbb5cf9b00fe7a543ffd45e26
parentirc: split function irc_ignore_check into three functions (diff)
downloadweechat-82a92bd4e9bc2330b9c25cc1a54be658bff1312e.tar.xz
weechat-82a92bd4e9bc2330b9c25cc1a54be658bff1312e.zip
irc: add unit tests on ignore functions
-rw-r--r--ChangeLog.adoc4
-rw-r--r--doc/en/weechat_dev.en.adoc3
-rw-r--r--doc/fr/weechat_dev.fr.adoc3
-rw-r--r--doc/ja/weechat_dev.ja.adoc6
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/unit/plugins/irc/test-irc-ignore.cpp216
7 files changed, 234 insertions, 0 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index d2ff9dcc2..c05bb3d64 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -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)
diff --git a/doc/en/weechat_dev.en.adoc b/doc/en/weechat_dev.en.adoc
index 825d2e837..58f5df1fb 100644
--- a/doc/en/weechat_dev.en.adoc
+++ b/doc/en/weechat_dev.en.adoc
@@ -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.
|===
diff --git a/doc/fr/weechat_dev.fr.adoc b/doc/fr/weechat_dev.fr.adoc
index fd8141d47..24d22680a 100644
--- a/doc/fr/weechat_dev.fr.adoc
+++ b/doc/fr/weechat_dev.fr.adoc
@@ -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.
|===
diff --git a/doc/ja/weechat_dev.ja.adoc b/doc/ja/weechat_dev.ja.adoc
index a856cc63b..d15d584c4 100644
--- a/doc/ja/weechat_dev.ja.adoc
+++ b/doc/ja/weechat_dev.ja.adoc
@@ -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 プロトコル
|===
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index e397eeed8..ead52cf32 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -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
)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d91d83b61..32cab6040 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
diff --git a/tests/unit/plugins/irc/test-irc-ignore.cpp b/tests/unit/plugins/irc/test-irc-ignore.cpp
new file mode 100644
index 000000000..6960ae71a
--- /dev/null
+++ b/tests/unit/plugins/irc/test-irc-ignore.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);
+}