]> jfr.im git - irc/weechat/weechat.git/commitdiff
tests: add tests on IRC function irc_channel_is_channel
authorSébastien Helleu <redacted>
Sat, 20 Jun 2020 08:07:56 +0000 (10:07 +0200)
committerSébastien Helleu <redacted>
Sat, 20 Jun 2020 10:04:40 +0000 (12:04 +0200)
ChangeLog.adoc
doc/en/weechat_dev.en.adoc
doc/fr/weechat_dev.fr.adoc
doc/ja/weechat_dev.ja.adoc
tests/CMakeLists.txt
tests/Makefile.am
tests/unit/plugins/irc/test-irc-channel.cpp [new file with mode: 0644]

index b0b951cf75baf9e9b03cbecf0d72ed7e99482641..43cd7b4c4e9c5c5ccd87a9cb1f3977a6de777995 100644 (file)
@@ -85,7 +85,7 @@ Tests::
   * core: add CI with GitHub Actions, move codecov.io upload to GitHub Actions
   * core: switch to Ubuntu Bionic on Travis CI, use pylint3 to lint Python scripts
   * core: run tests on plugins only if the plugins are enabled and compiled
-  * irc: add tests on IRC color functions
+  * irc: add tests on IRC color and channel functions
 
 Build::
 
index f691688dc4de0e1f3947ee3eaa6b6356a630d66f..10ed469b91c907150d37b03dfa6e0ce54e12bb9e 100644 (file)
@@ -411,6 +411,7 @@ WeeChat "core" is located in following directories:
 |          test-gui-nick.cpp        | Tests: nicks.
 |       plugins/                    | Root of unit tests for plugins.
 |          irc/                     | Root of unit tests for IRC plugin.
+|             test-irc-channel.cpp  | Tests: IRC channels.
 |             test-irc-color.cpp    | Tests: IRC colors.
 |             test-irc-config.cpp   | Tests: IRC configuration.
 |             test-irc-ignore.cpp   | Tests: IRC ignores.
index ea7dbfa49e3882a39d7e55929bcf144079a81d85..1b964ac83303b6ed9051dd5698566e8aca669045 100644 (file)
@@ -413,6 +413,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants :
 |          test-gui-nick.cpp        | Tests : pseudos.
 |       plugins/                    | Racine des tests unitaires pour les extensions.
 |          irc/                     | Racine des tests unitaires pour l'extension IRC.
+|             test-irc-channel.cpp  | Tests : canaux IRC.
 |             test-irc-color.cpp    | Tests : couleurs IRC.
 |             test-irc-config.cpp   | Tests : configuration IRC.
 |             test-irc-ignore.cpp   | Tests : ignores IRC.
index 98593604858682e8b32a019f8996853056ce4a65..744283d0684a3bafc5fa35b33d1a894587f4dfb1 100644 (file)
@@ -426,6 +426,7 @@ WeeChat "core" は以下のディレクトリに配置されています:
 |       plugins/                    | プラグインの単体テストを収める最上位ディレクトリ
 |          irc/                     | IRC プラグインの単体テストを収める最上位ディレクトリ
 // TRANSLATION MISSING
+|             test-irc-channel.cpp  | Tests: IRC channels.
 |             test-irc-color.cpp    | Tests: IRC colors.
 |             test-irc-config.cpp   | テスト: IRC 設定
 // TRANSLATION MISSING
index 5c6bd1abbed1770577b7515967bad81738c5fdd5..5b24c7b2d5c853240cf12a0794ccadd187abcbfc 100644 (file)
@@ -50,6 +50,7 @@ set(LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC unit/plugins/test-plugins.cpp)
 
 if(ENABLE_IRC)
   list(APPEND LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC
+    unit/plugins/irc/test-irc-channel.cpp
     unit/plugins/irc/test-irc-color.cpp
     unit/plugins/irc/test-irc-config.cpp
     unit/plugins/irc/test-irc-ignore.cpp
index 2f4b214f7d7032c3384d3340651127cd56a2e131..f97fe676f796f965862b47574c03bab340fca8b7 100644 (file)
@@ -65,7 +65,8 @@ tests_SOURCES = tests.cpp \
 lib_LTLIBRARIES = lib_weechat_unit_tests_plugins.la
 
 if PLUGIN_IRC
-tests_irc = unit/plugins/irc/test-irc-color.cpp \
+tests_irc = unit/plugins/irc/test-irc-channel.cpp \
+            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-message.cpp \
diff --git a/tests/unit/plugins/irc/test-irc-channel.cpp b/tests/unit/plugins/irc/test-irc-channel.cpp
new file mode 100644 (file)
index 0000000..b788189
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * test-irc-channel.cpp - test IRC channel functions
+ *
+ * Copyright (C) 2019-2020 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 <string.h>
+#include "src/plugins/irc/irc-channel.h"
+#include "src/plugins/irc/irc-server.h"
+}
+
+TEST_GROUP(IrcChannel)
+{
+};
+
+/*
+ * Tests functions:
+ *   irc_channel_valid
+ */
+
+TEST(IrcChannel, Valid)
+{
+    /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ *   irc_channel_is_channel
+ */
+
+TEST(IrcChannel, IsChannel)
+{
+    struct t_irc_server *server;
+
+    /* no server, default chantypes = "#&+!" */
+
+    /* empty channel */
+    LONGS_EQUAL(0, irc_channel_is_channel (NULL, NULL));
+    LONGS_EQUAL(0, irc_channel_is_channel (NULL, ""));
+
+    /* not a channel */
+    LONGS_EQUAL(0, irc_channel_is_channel (NULL, "abc"));
+    LONGS_EQUAL(0, irc_channel_is_channel (NULL, "/abc"));
+    LONGS_EQUAL(0, irc_channel_is_channel (NULL, ":abc"));
+
+    /* valid channel */
+    LONGS_EQUAL(1, irc_channel_is_channel (NULL, "#abc"));
+    LONGS_EQUAL(1, irc_channel_is_channel (NULL, "##abc"));
+    LONGS_EQUAL(1, irc_channel_is_channel (NULL, "&abc"));
+    LONGS_EQUAL(1, irc_channel_is_channel (NULL, "&&abc"));
+    LONGS_EQUAL(1, irc_channel_is_channel (NULL, "+abc"));
+    LONGS_EQUAL(1, irc_channel_is_channel (NULL, "++abc"));
+    LONGS_EQUAL(1, irc_channel_is_channel (NULL, "!abc"));
+    LONGS_EQUAL(1, irc_channel_is_channel (NULL, "!!abc"));
+
+    /* server with chantypes = "#" */
+    server = irc_server_alloc ("my_ircd");
+    CHECK(server);
+    if (server->chantypes)
+        free (server->chantypes);
+    server->chantypes = strdup ("#");
+
+    /* empty channel */
+    LONGS_EQUAL(0, irc_channel_is_channel (server, NULL));
+    LONGS_EQUAL(0, irc_channel_is_channel (server, ""));
+
+    /* not a channel */
+    LONGS_EQUAL(0, irc_channel_is_channel (server, "abc"));
+    LONGS_EQUAL(0, irc_channel_is_channel (server, "/abc"));
+    LONGS_EQUAL(0, irc_channel_is_channel (server, ":abc"));
+    LONGS_EQUAL(0, irc_channel_is_channel (server, "&abc"));
+    LONGS_EQUAL(0, irc_channel_is_channel (server, "+abc"));
+    LONGS_EQUAL(0, irc_channel_is_channel (server, "!abc"));
+
+    /* valid channel */
+    LONGS_EQUAL(1, irc_channel_is_channel (server, "#abc"));
+    LONGS_EQUAL(1, irc_channel_is_channel (server, "##abc"));
+
+    irc_server_free (server);
+}