summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2022-07-16 14:05:48 +0200
committerSébastien Helleu <flashcode@flashtux.org>2022-07-16 14:05:48 +0200
commit0440309cee9c738b76e5ba8eaa4b59ebd9d8951b (patch)
tree5d7c08ac4403c8f7a5ef0d4da0cf7aea83098e5d /tests
parente057c16b36a19f4c08fe81907026c3e2c257b07b (diff)
downloadweechat-0440309cee9c738b76e5ba8eaa4b59ebd9d8951b.zip
irc: fix duplicated channels in autojoin option when autojoin_dynamic is enabled (closes #1795)
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/plugins/irc/test-irc-join.cpp116
1 files changed, 116 insertions, 0 deletions
diff --git a/tests/unit/plugins/irc/test-irc-join.cpp b/tests/unit/plugins/irc/test-irc-join.cpp
index de40dd24b..54b8076b0 100644
--- a/tests/unit/plugins/irc/test-irc-join.cpp
+++ b/tests/unit/plugins/irc/test-irc-join.cpp
@@ -32,6 +32,11 @@ extern "C"
#include "src/plugins/irc/irc-channel.h"
#include "src/plugins/irc/irc-join.h"
#include "src/plugins/irc/irc-server.h"
+
+extern int irc_join_compare_join_channel (struct t_irc_server *server,
+ struct t_irc_join_channel *join_channel1,
+ struct t_irc_join_channel *join_channel2);
+
}
#define WEE_CHECK_ADD_CHANNEL(__result, __join, __channel, __key) \
@@ -92,7 +97,50 @@ TEST_GROUP(IrcJoin)
/*
* Tests functions:
+ * irc_join_compare_join_channel
+ */
+
+TEST(IrcJoin, CompateJoinChannel)
+{
+ struct t_irc_join_channel join_chan1, join_chan2;
+
+ join_chan1.name = NULL;
+ join_chan1.key = NULL;
+ join_chan2.name = NULL;
+ join_chan2.key = NULL;
+
+ LONGS_EQUAL(0, irc_join_compare_join_channel (NULL, &join_chan1, &join_chan2));
+
+ join_chan1.name = strdup ("#abc");
+ LONGS_EQUAL(1, irc_join_compare_join_channel (NULL, &join_chan1, &join_chan2));
+
+ join_chan2.name = strdup ("#abc");
+ LONGS_EQUAL(0, irc_join_compare_join_channel (NULL, &join_chan1, &join_chan2));
+
+ join_chan1.key = strdup ("key_abc");
+ LONGS_EQUAL(-1, irc_join_compare_join_channel (NULL, &join_chan1, &join_chan2));
+
+ join_chan2.key = strdup ("key_abc");
+ LONGS_EQUAL(0, irc_join_compare_join_channel (NULL, &join_chan1, &join_chan2));
+
+ free (join_chan2.key);
+ join_chan2.key = strdup ("key2_abc");
+ LONGS_EQUAL(45, irc_join_compare_join_channel (NULL, &join_chan1, &join_chan2));
+
+ free (join_chan2.name);
+ join_chan2.name = strdup ("#def");
+ LONGS_EQUAL(-1, irc_join_compare_join_channel (NULL, &join_chan1, &join_chan2));
+
+ free (join_chan1.name);
+ free (join_chan1.key);
+ free (join_chan2.name);
+ free (join_chan2.key);
+}
+
+/*
+ * Tests functions:
* irc_join_compare_cb
+ * irc_join_free_join_channel
* irc_join_free_cb
* irc_join_split
* irc_join_build_string
@@ -211,6 +259,22 @@ TEST(IrcJoin, SplitBuildString)
free (autojoin);
arraylist_free (arraylist);
+ /* duplicated channel */
+ arraylist = irc_join_split (NULL, "#abc,#def,#abc", 0);
+ CHECK(arraylist);
+ LONGS_EQUAL(2, arraylist->size);
+ channels = (struct t_irc_join_channel **)arraylist->data;
+ CHECK(channels[0]);
+ STRCMP_EQUAL("#abc", channels[0]->name);
+ POINTERS_EQUAL(NULL, channels[0]->key);
+ CHECK(channels[1]);
+ STRCMP_EQUAL("#def", channels[1]->name);
+ POINTERS_EQUAL(NULL, channels[1]->key);
+ autojoin = irc_join_build_string (arraylist);
+ STRCMP_EQUAL("#abc,#def", autojoin);
+ free (autojoin);
+ arraylist_free (arraylist);
+
/* server with casemapping RFC1459 */
server = irc_server_alloc ("my_ircd");
CHECK(server);
@@ -295,6 +359,12 @@ TEST(IrcJoin, AddChannel)
WEE_CHECK_ADD_CHANNEL("#abc,#xyz key_abc", "#xyz", "#abc", "key_abc");
WEE_CHECK_ADD_CHANNEL("#abc,#xyz,#def key_abc", "#xyz,#def", "#abc", "key_abc");
+
+ /* duplicated channel */
+ WEE_CHECK_ADD_CHANNEL("#abc,#def", "#abc,#def", "#abc", NULL);
+ WEE_CHECK_ADD_CHANNEL("#ABC,#def", "#abc,#def", "#ABC", NULL);
+ WEE_CHECK_ADD_CHANNEL("#abc,#def", "#abc,#def", "#def", NULL);
+ WEE_CHECK_ADD_CHANNEL("#abc,#DEF", "#abc,#def", "#DEF", NULL);
}
/*
@@ -323,6 +393,12 @@ TEST(IrcJoin, AddChannels)
WEE_CHECK_ADD_CHANNELS("#abc,#chan1,#chan2,#xyz,#chan3 key_abc,key1,key2",
"#abc,#xyz,#chan2 key_abc", "#chan1,#chan2,#chan3 key1,key2");
+
+ /* duplicated channel */
+ WEE_CHECK_ADD_CHANNELS("#abc,#def", "#abc,#def", "#abc");
+ WEE_CHECK_ADD_CHANNELS("#ABC,#def", "#abc,#def", "#ABC");
+ WEE_CHECK_ADD_CHANNELS("#abc,#def", "#abc,#def", "#def");
+ WEE_CHECK_ADD_CHANNELS("#abc,#DEF", "#abc,#def", "#DEF");
}
/*
@@ -378,6 +454,10 @@ TEST(IrcJoin, SortChannels)
WEE_CHECK_SORT_CHANNELS("#xyz,#abc key_xyz", "#xyz,#abc key_xyz");
WEE_CHECK_SORT_CHANNELS("#xyz,#zzz,#ABC,#def,#ghi key_xyz,key_zzz",
"#zzz,#xyz,#ghi,#def,#ABC key_zzz,key_xyz");
+
+ /* duplicated channel */
+ WEE_CHECK_SORT_CHANNELS("#abc,#def", "#abc,#def,#abc");
+ WEE_CHECK_SORT_CHANNELS("#abc,#DEF", "#abc,#def,#abc,#def,#DEF");
}
/*
@@ -469,6 +549,42 @@ TEST(IrcJoin, AddRemoveChannelsAutojoin)
"#abc,#xyz,#def,#ghi key_abc,key_xyz",
CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+ /* duplicated channel */
+ irc_join_add_channels_to_autojoin (server, "#abc key_abc");
+ STRCMP_EQUAL(
+ "#abc,#xyz,#def,#ghi key_abc,key_xyz",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+
+ /* duplicated channel */
+ irc_join_add_channels_to_autojoin (server, "#xyz key_xyz");
+ STRCMP_EQUAL(
+ "#abc,#xyz,#def,#ghi key_abc,key_xyz",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+
+ /* duplicated channel */
+ irc_join_add_channels_to_autojoin (server, "#def");
+ STRCMP_EQUAL(
+ "#abc,#xyz,#def,#ghi key_abc,key_xyz",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+
+ /* duplicated channel */
+ irc_join_add_channels_to_autojoin (server, "#DEF");
+ STRCMP_EQUAL(
+ "#abc,#xyz,#DEF,#ghi key_abc,key_xyz",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+
+ /* duplicated channel */
+ irc_join_add_channels_to_autojoin (server, "#ghi");
+ STRCMP_EQUAL(
+ "#abc,#xyz,#DEF,#ghi key_abc,key_xyz",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+
+ /* duplicated channel */
+ irc_join_add_channels_to_autojoin (server, "#GHI");
+ STRCMP_EQUAL(
+ "#abc,#xyz,#DEF,#GHI key_abc,key_xyz",
+ CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN]));
+
irc_server_free (server);
}