summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-04-05 21:17:03 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-04-05 21:17:03 +0200
commit0b20cb449a2c541b055fc58efaf64155d310846d (patch)
tree99f8e64654e1aea105022f96b1b60f486e8fcdbb
parent5c801f2741dec493bf2801203f9d0937c1f91cc4 (diff)
downloadweechat-0b20cb449a2c541b055fc58efaf64155d310846d.zip
tests: add tests on function irc_server_alloc_with_url
-rw-r--r--src/plugins/irc/irc-server.c3
-rw-r--r--tests/unit/plugins/irc/test-irc-server.cpp153
2 files changed, 155 insertions, 1 deletions
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 7392e1298..3be948895 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -1699,6 +1699,9 @@ irc_server_alloc_with_url (const char *irc_url)
int ipv6, ssl, length;
struct t_irc_server *ptr_server;
+ if (!irc_url || !irc_url[0])
+ return NULL;
+
irc_url2 = strdup (irc_url);
if (!irc_url2)
return NULL;
diff --git a/tests/unit/plugins/irc/test-irc-server.cpp b/tests/unit/plugins/irc/test-irc-server.cpp
index 457a2a5e0..506ba4266 100644
--- a/tests/unit/plugins/irc/test-irc-server.cpp
+++ b/tests/unit/plugins/irc/test-irc-server.cpp
@@ -27,6 +27,7 @@ extern "C"
{
#include <stdio.h>
#include <string.h>
+#include "src/core/wee-config-file.h"
#include "src/plugins/plugin.h"
#include "src/plugins/irc/irc-channel.h"
#include "src/plugins/irc/irc-server.h"
@@ -529,7 +530,157 @@ TEST(IrcServer, Alloc)
TEST(IrcServer, AllocWithUrl)
{
- /* TODO: write tests */
+ struct t_irc_server *server;
+
+ POINTERS_EQUAL(NULL, irc_server_alloc_with_url (NULL));
+ POINTERS_EQUAL(NULL, irc_server_alloc_with_url (""));
+
+ POINTERS_EQUAL(NULL, irc_server_alloc_with_url ("test"));
+
+ /* address */
+ server = irc_server_alloc_with_url ("irc://irc.example.org");
+ CHECK(server);
+ STRCMP_EQUAL(server->name, "irc.example.org");
+ STRCMP_EQUAL("irc.example.org/6667",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_ADDRESSES]));
+ LONGS_EQUAL(0, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_IPV6]));
+ LONGS_EQUAL(0, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_SSL]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_PASSWORD]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_NICKS]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+ irc_server_free (server);
+
+ /* address/port */
+ server = irc_server_alloc_with_url ("irc://irc.example.org:7000");
+ CHECK(server);
+ STRCMP_EQUAL(server->name, "irc.example.org");
+ STRCMP_EQUAL("irc.example.org/7000",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_ADDRESSES]));
+ LONGS_EQUAL(0, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_IPV6]));
+ LONGS_EQUAL(0, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_SSL]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_PASSWORD]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_NICKS]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+ irc_server_free (server);
+
+ /* address/port, IPv6 */
+ server = irc_server_alloc_with_url ("irc6://irc.example.org:7000");
+ CHECK(server);
+ STRCMP_EQUAL(server->name, "irc.example.org");
+ STRCMP_EQUAL("irc.example.org/7000",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_ADDRESSES]));
+ LONGS_EQUAL(1, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_IPV6]));
+ LONGS_EQUAL(0, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_SSL]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_PASSWORD]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_NICKS]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+ irc_server_free (server);
+
+ /* address, SSL */
+ server = irc_server_alloc_with_url ("ircs://irc.example.org");
+ CHECK(server);
+ STRCMP_EQUAL(server->name, "irc.example.org");
+ STRCMP_EQUAL("irc.example.org/6697",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_ADDRESSES]));
+ LONGS_EQUAL(0, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_IPV6]));
+ LONGS_EQUAL(1, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_SSL]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_PASSWORD]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_NICKS]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+ irc_server_free (server);
+
+ /* address, IPv6, SSL */
+ server = irc_server_alloc_with_url ("irc6s://irc.example.org");
+ CHECK(server);
+ STRCMP_EQUAL(server->name, "irc.example.org");
+ STRCMP_EQUAL("irc.example.org/6697",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_ADDRESSES]));
+ LONGS_EQUAL(1, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_IPV6]));
+ LONGS_EQUAL(1, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_SSL]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_PASSWORD]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_NICKS]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+ irc_server_free (server);
+
+ /* address/port, SSL */
+ server = irc_server_alloc_with_url ("ircs://irc.example.org:7000");
+ CHECK(server);
+ STRCMP_EQUAL(server->name, "irc.example.org");
+ STRCMP_EQUAL("irc.example.org/7000",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_ADDRESSES]));
+ LONGS_EQUAL(0, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_IPV6]));
+ LONGS_EQUAL(1, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_SSL]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_PASSWORD]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_NICKS]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+ irc_server_free (server);
+
+ /* address, nick */
+ server = irc_server_alloc_with_url ("irc://alice@irc.example.org");
+ CHECK(server);
+ STRCMP_EQUAL(server->name, "irc.example.org");
+ STRCMP_EQUAL("irc.example.org/6667",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_ADDRESSES]));
+ LONGS_EQUAL(0, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_IPV6]));
+ LONGS_EQUAL(0, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_SSL]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_PASSWORD]));
+ STRCMP_EQUAL("alice,alice1,alice2,alice3,alice4",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_NICKS]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+ irc_server_free (server);
+
+ /* address, nick, password */
+ server = irc_server_alloc_with_url ("irc://alice:secret@irc.example.org");
+ CHECK(server);
+ STRCMP_EQUAL(server->name, "irc.example.org");
+ STRCMP_EQUAL("irc.example.org/6667",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_ADDRESSES]));
+ LONGS_EQUAL(0, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_IPV6]));
+ LONGS_EQUAL(0, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_SSL]));
+ STRCMP_EQUAL("secret",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_PASSWORD]));
+ STRCMP_EQUAL("alice,alice1,alice2,alice3,alice4",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_NICKS]));
+ POINTERS_EQUAL(NULL,
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+ irc_server_free (server);
+
+ /* address, nick, password, channels */
+ server = irc_server_alloc_with_url (
+ "irc://alice:secret@irc.example.org/#test1,#test2");
+ CHECK(server);
+ STRCMP_EQUAL(server->name, "irc.example.org");
+ STRCMP_EQUAL("irc.example.org/6667",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_ADDRESSES]));
+ LONGS_EQUAL(0, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_IPV6]));
+ LONGS_EQUAL(0, CONFIG_BOOLEAN(server->options[IRC_SERVER_OPTION_SSL]));
+ STRCMP_EQUAL("secret",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_PASSWORD]));
+ STRCMP_EQUAL("alice,alice1,alice2,alice3,alice4",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_NICKS]));
+ STRCMP_EQUAL("#test1,#test2",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+ irc_server_free (server);
}