diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-08-09 14:53:03 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-08-09 14:53:03 +0200 |
commit | 17674f7b113bad17e888208af92dda350e3db3c0 (patch) | |
tree | 2b36cd696f5f35f388114f8e88fdea350ead0eb1 /tests/unit/plugins/irc | |
parent | 356712f44d7307f042fbcda0598c81caaf8711a3 (diff) | |
download | weechat-17674f7b113bad17e888208af92dda350e3db3c0.zip |
irc: add missing tags on multiline messages (closes #1987)
Diffstat (limited to 'tests/unit/plugins/irc')
-rw-r--r-- | tests/unit/plugins/irc/test-irc-batch.cpp | 44 | ||||
-rw-r--r-- | tests/unit/plugins/irc/test-irc-protocol.cpp | 26 | ||||
-rw-r--r-- | tests/unit/plugins/irc/test-irc-tag.cpp | 91 |
3 files changed, 143 insertions, 18 deletions
diff --git a/tests/unit/plugins/irc/test-irc-batch.cpp b/tests/unit/plugins/irc/test-irc-batch.cpp index 95687638e..774755430 100644 --- a/tests/unit/plugins/irc/test-irc-batch.cpp +++ b/tests/unit/plugins/irc/test-irc-batch.cpp @@ -26,6 +26,8 @@ extern "C" { #include <string.h> +#include "src/core/wee-hashtable.h" +#include "src/plugins/weechat-plugin.h" #include "src/plugins/irc/irc-batch.h" #include "src/plugins/irc/irc-server.h" } @@ -43,14 +45,23 @@ TEST(IrcBatch, Search) { struct t_irc_server *server; struct t_irc_batch *batch1, *batch2; + struct t_hashtable *tags; server = irc_server_alloc ("server"); CHECK(server); - batch1 = irc_batch_start_batch (server, "ref1", "parent_ref", "type", "params"); + tags = hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, NULL); + CHECK(tags); + hashtable_set (tags, "time", "2023-08-09T07:43:01.830Z"); + hashtable_set (tags, "msgid", "icqfzy7zdbpix4gy8pvzuv49kw"); + + batch1 = irc_batch_start_batch (server, "ref1", "parent_ref", "type", "params", tags); CHECK(batch1); - batch2 = irc_batch_start_batch (server, "ref2", "parent_ref", "type", "params"); + batch2 = irc_batch_start_batch (server, "ref2", "parent_ref", "type", "params", NULL); CHECK(batch2); POINTERS_EQUAL(NULL, irc_batch_search (NULL, NULL)); @@ -105,19 +116,29 @@ TEST(IrcBatch, StartBatch) { struct t_irc_server *server; struct t_irc_batch *batch; + struct t_hashtable *tags; server = irc_server_alloc ("server"); CHECK(server); + tags = hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, NULL); + CHECK(tags); + hashtable_set (tags, "time", "2023-08-09T07:43:01.830Z"); + hashtable_set (tags, "msgid", "icqfzy7zdbpix4gy8pvzuv49kw"); + POINTERS_EQUAL(NULL, server->batches); - batch = irc_batch_start_batch (server, "ref", NULL, "type", NULL); + batch = irc_batch_start_batch (server, "ref", NULL, "type", NULL, NULL); CHECK(batch); POINTERS_EQUAL(batch, server->batches); STRCMP_EQUAL("ref", batch->reference); POINTERS_EQUAL(NULL, batch->parent_ref); STRCMP_EQUAL("type", batch->type); POINTERS_EQUAL(NULL, batch->parameters); + POINTERS_EQUAL(NULL, batch->tags); CHECK(batch->start_time > 0); POINTERS_EQUAL(NULL, batch->messages); LONGS_EQUAL(0, batch->end_received); @@ -126,13 +147,19 @@ TEST(IrcBatch, StartBatch) POINTERS_EQUAL(NULL, server->batches); - batch = irc_batch_start_batch (server, "ref", "parent_ref", "type", "params"); + batch = irc_batch_start_batch (server, "ref", "parent_ref", "type", "params", + tags); CHECK(batch); POINTERS_EQUAL(batch, server->batches); STRCMP_EQUAL("ref", batch->reference); STRCMP_EQUAL("parent_ref", batch->parent_ref); STRCMP_EQUAL("type", batch->type); STRCMP_EQUAL("params", batch->parameters); + CHECK(batch->tags); + STRCMP_EQUAL("2023-08-09T07:43:01.830Z", + (const char *)hashtable_get (batch->tags, "time")); + STRCMP_EQUAL("icqfzy7zdbpix4gy8pvzuv49kw", + (const char *)hashtable_get (batch->tags, "msgid")); CHECK(batch->start_time > 0); POINTERS_EQUAL(NULL, batch->messages); @@ -159,7 +186,8 @@ TEST(IrcBatch, AddMessage) server = irc_server_alloc ("server"); CHECK(server); - batch = irc_batch_start_batch (server, "ref", "parent_ref", "type", "params"); + batch = irc_batch_start_batch (server, "ref", "parent_ref", "type", "params", + NULL); CHECK(batch); irc_batch_add_message (server, "ref", ":alice PRIVMSG #test: test1"); @@ -187,10 +215,12 @@ TEST(IrcBatch, FreeAll) server = irc_server_alloc ("server"); CHECK(server); - batch1 = irc_batch_start_batch (server, "ref1", "parent_ref", "type", "params"); + batch1 = irc_batch_start_batch (server, "ref1", "parent_ref", "type", "params", + NULL); CHECK(batch1); - batch2 = irc_batch_start_batch (server, "ref2", "parent_ref", "type", "params"); + batch2 = irc_batch_start_batch (server, "ref2", "parent_ref", "type", "params", + NULL); CHECK(batch2); POINTERS_EQUAL(batch1, server->batches); diff --git a/tests/unit/plugins/irc/test-irc-protocol.cpp b/tests/unit/plugins/irc/test-irc-protocol.cpp index e455d1cd3..101aa14ec 100644 --- a/tests/unit/plugins/irc/test-irc-protocol.cpp +++ b/tests/unit/plugins/irc/test-irc-protocol.cpp @@ -1626,7 +1626,8 @@ TEST(IrcProtocolWithServer, batch_with_batch_cap) POINTERS_EQUAL(NULL, irc_batch_search (ptr_server, "ref2")); /* multiline */ - RECV(":server BATCH +ref draft/multiline #test"); + RECV("@time=2023-08-09T07:43:01.830Z;msgid=icqfzy7zdbpix4gy8pvzuv49kw " + ":server BATCH +ref draft/multiline #test"); CHECK_NO_MSG; RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :line 1"); CHECK_NO_MSG; @@ -1634,13 +1635,14 @@ TEST(IrcProtocolWithServer, batch_with_batch_cap) CHECK_NO_MSG; RECV(":server BATCH -ref"); CHECK_CHAN("bob", "line 1", - "irc_privmsg,irc_tag_batch=ref,irc_batch_type_draft/multiline," - "notify_message,prefix_nick_248,nick_bob," - "host_user_b@host_b,log1"); + "irc_privmsg,irc_tag_batch=ref,irc_tag_time=2023-08-09T07:43:01.830Z," + "irc_tag_msgid=icqfzy7zdbpix4gy8pvzuv49kw," + "irc_batch_type_draft/multiline,notify_message,prefix_nick_248," + "nick_bob,host_user_b@host_b,log1"); CHECK_CHAN("bob", "line 2", - "irc_privmsg,irc_tag_batch=ref,irc_batch_type_draft/multiline," - "notify_message,prefix_nick_248,nick_bob," - "host_user_b@host_b,log1"); + "irc_privmsg,irc_tag_batch=ref,irc_tag_time=2023-08-09T07:43:01.830Z," + "irc_tag_msgid=icqfzy7zdbpix4gy8pvzuv49kw,irc_batch_type_draft/multiline," + "notify_message,prefix_nick_248,nick_bob,host_user_b@host_b,log1"); /* multiline with CTCP */ RECV(":server BATCH +ref draft/multiline #test"); @@ -1667,7 +1669,8 @@ TEST(IrcProtocolWithServer, batch_with_batch_cap) irc_server_buffer_set_input_multiline (ptr_server, 1); /* multiline */ - RECV(":server BATCH +ref draft/multiline #test"); + RECV("@time=2023-08-09T07:43:01.830Z;msgid=icqfzy7zdbpix4gy8pvzuv49kw " + ":server BATCH +ref draft/multiline #test"); CHECK_NO_MSG; RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :line 1"); CHECK_NO_MSG; @@ -1676,9 +1679,10 @@ TEST(IrcProtocolWithServer, batch_with_batch_cap) RECV(":server BATCH -ref"); CHECK_CHAN("bob", "line 1\n" "line 2", - "irc_privmsg,irc_tag_batch=ref,irc_batch_type_draft/multiline," - "notify_message,prefix_nick_248,nick_bob,host_user_b@host_b," - "log1"); + "irc_privmsg,irc_tag_batch=ref,irc_tag_time=2023-08-09T07:43:01.830Z," + "irc_tag_msgid=icqfzy7zdbpix4gy8pvzuv49kw," + "irc_batch_type_draft/multiline,notify_message,prefix_nick_248," + "nick_bob,host_user_b@host_b,log1"); /* multiline with CTCP */ RECV(":server BATCH +ref draft/multiline #test"); diff --git a/tests/unit/plugins/irc/test-irc-tag.cpp b/tests/unit/plugins/irc/test-irc-tag.cpp index a24afc0c8..b9993c8e1 100644 --- a/tests/unit/plugins/irc/test-irc-tag.cpp +++ b/tests/unit/plugins/irc/test-irc-tag.cpp @@ -21,6 +21,8 @@ #include "CppUTest/TestHarness.h" +#include "tests/tests.h" + extern "C" { #include <stdio.h> @@ -28,6 +30,8 @@ extern "C" #include "src/core/wee-hook.h" #include "src/plugins/irc/irc-tag.h" #include "src/plugins/plugin.h" + +extern char *irc_tag_hashtable_to_string (struct t_hashtable *tags); } #define WEE_CHECK_ESCAPE_VALUE(__result, __string) \ @@ -161,3 +165,90 @@ TEST(IrcTag, Parse) hashtable_free (hashtable); } + +/* + * Tests functions: + * irc_tag_add_to_string_cb + * irc_tag_hashtable_to_string + */ + +TEST(IrcTag, HashtableToString) +{ + char *str; + struct t_hashtable *tags; + + POINTERS_EQUAL(NULL, irc_tag_hashtable_to_string (NULL)); + + tags = hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, NULL); + CHECK(tags); + + WEE_TEST_STR("", irc_tag_hashtable_to_string (tags)); + + hashtable_set (tags, "time", "2023-08-09T07:43:01.830Z"); + hashtable_set (tags, "msgid", "icqfzy7zdbpix4gy8pvzuv49kw"); + hashtable_set (tags, "test", "value with spaces"); + + WEE_TEST_STR("time=2023-08-09T07:43:01.830Z;" + "msgid=icqfzy7zdbpix4gy8pvzuv49kw;" + "test=value\\swith\\sspaces", + irc_tag_hashtable_to_string (tags)); + + hashtable_free (tags); +} + +/* + * Tests functions: + * irc_tag_add_to_hashtable_cb + * irc_tag_add_tags_to_message + */ + +TEST(IrcTag, AddTagsToMessage) +{ + char *str; + struct t_hashtable *tags; + + POINTERS_EQUAL(NULL, irc_tag_add_tags_to_message (NULL, NULL)); + + WEE_TEST_STR("", irc_tag_add_tags_to_message ("", NULL)); + WEE_TEST_STR(":nick!user@host PRIVMSG #test :hello", + irc_tag_add_tags_to_message ( + ":nick!user@host PRIVMSG #test :hello", NULL)); + WEE_TEST_STR("@tag1;tag2=value2 :nick!user@host PRIVMSG #test :hello", + irc_tag_add_tags_to_message ( + "@tag1;tag2=value2 :nick!user@host PRIVMSG #test :hello", + NULL)); + + tags = hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, NULL); + CHECK(tags); + + WEE_TEST_STR(":nick!user@host PRIVMSG #test :hello", + irc_tag_add_tags_to_message ( + ":nick!user@host PRIVMSG #test :hello", tags)); + WEE_TEST_STR("@tag1;tag2=value2 :nick!user@host PRIVMSG #test :hello", + irc_tag_add_tags_to_message ( + "@tag1;tag2=value2 :nick!user@host PRIVMSG #test :hello", + tags)); + + hashtable_set (tags, "time", "2023-08-09T07:43:01.830Z"); + hashtable_set (tags, "msgid", "icqfzy7zdbpix4gy8pvzuv49kw"); + hashtable_set (tags, "test", "value with spaces"); + + WEE_TEST_STR("@time=2023-08-09T07:43:01.830Z;msgid=icqfzy7zdbpix4gy8pvzuv49kw;" + "test=value\\swith\\sspaces :nick!user@host PRIVMSG #test :hello", + irc_tag_add_tags_to_message ( + ":nick!user@host PRIVMSG #test :hello", tags)); + WEE_TEST_STR("@tag1;tag2=value2;time=2023-08-09T07:43:01.830Z;" + "msgid=icqfzy7zdbpix4gy8pvzuv49kw;test=value\\swith\\sspaces " + ":nick!user@host PRIVMSG #test :hello", + irc_tag_add_tags_to_message ( + "@tag1;tag2=value2 :nick!user@host PRIVMSG #test :hello", + tags)); + + hashtable_free (tags); +} |