summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2020-03-30 20:58:16 +0200
committerSébastien Helleu <flashcode@flashtux.org>2020-03-30 20:58:16 +0200
commiteb7b12f0da64b62f9c47d646355e97c4d55d8f60 (patch)
treebc5848d65bbd2f7ca7d87b3bc895b953800717e4
parent052d4d1fc0149dfe716da5db6025ff97e4625bfa (diff)
downloadweechat-eb7b12f0da64b62f9c47d646355e97c4d55d8f60.zip
tests: add tests on IRC color functions
Functions tested: - irc_color_convert_rgb2irc - irc_color_convert_term2irc - irc_color_for_tags - irc_color_modifier_cb - irc_color_weechat_add_to_infolist
-rw-r--r--ChangeLog.adoc4
-rw-r--r--tests/unit/plugins/irc/test-irc-color.cpp112
2 files changed, 116 insertions, 0 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index 5eb56b751..c1200cbd3 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -18,6 +18,10 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
[[v2.9]]
== Version 2.9 (under dev)
+Tests::
+
+ * irc: add tests on IRC color functions
+
Build::
* core: fix build with cygport on Cygwin
diff --git a/tests/unit/plugins/irc/test-irc-color.cpp b/tests/unit/plugins/irc/test-irc-color.cpp
index f987c0521..bfa84ae8b 100644
--- a/tests/unit/plugins/irc/test-irc-color.cpp
+++ b/tests/unit/plugins/irc/test-irc-color.cpp
@@ -25,9 +25,14 @@ extern "C"
{
#include <stdio.h>
#include "src/core/wee-config-file.h"
+#include "src/core/wee-hook.h"
+#include "src/core/wee-infolist.h"
#include "src/gui/gui-color.h"
#include "src/plugins/irc/irc-color.h"
#include "src/plugins/irc/irc-config.h"
+
+extern int irc_color_convert_rgb2irc (int rgb);
+extern int irc_color_convert_term2irc (int color);
}
/* tests on irc_color_decode(): IRC color -> WeeChat color */
@@ -374,6 +379,32 @@ TEST(IrcColor, Encode)
/*
* Tests functions:
+ * irc_color_convert_rgb2irc
+ */
+
+TEST(IrcColor, ConvertRgb2Irc)
+{
+ LONGS_EQUAL(1, irc_color_convert_rgb2irc (0x000000));
+ LONGS_EQUAL(1, irc_color_convert_rgb2irc (0x010203));
+ LONGS_EQUAL(4, irc_color_convert_rgb2irc (0xFF0033));
+ LONGS_EQUAL(15, irc_color_convert_rgb2irc (0xAABBCC));
+}
+
+/*
+ * Tests functions:
+ * irc_color_convert_term2irc
+ */
+
+TEST(IrcColor, ConvertTerm2Irc)
+{
+ LONGS_EQUAL(1, irc_color_convert_term2irc (0));
+ LONGS_EQUAL(15, irc_color_convert_term2irc (123));
+ LONGS_EQUAL(13, irc_color_convert_term2irc (200));
+ LONGS_EQUAL(0, irc_color_convert_term2irc (255));
+}
+
+/*
+ * Tests functions:
* irc_color_decode_ansi
*/
@@ -525,3 +556,84 @@ TEST(IrcColor, DecodeAnsi)
IRC_COLOR_COLOR_STR);
WEE_CHECK_DECODE_ANSI(string, STRING_ANSI_DEFAULT_BG, 1);
}
+
+/*
+ * Tests functions:
+ * irc_color_for_tags
+ */
+
+TEST(IrcColor, ForTags)
+{
+ POINTERS_EQUAL(NULL, irc_color_for_tags (NULL));
+
+ STRCMP_EQUAL("", irc_color_for_tags (""));
+ STRCMP_EQUAL("test", irc_color_for_tags ("test"));
+ STRCMP_EQUAL("blue:red", irc_color_for_tags ("blue,red"));
+}
+
+/*
+ * Tests functions:
+ * irc_color_modifier_cb
+ */
+
+TEST(IrcColor, ModifierCallback)
+{
+ char string[1024], *result;
+
+ /* modifier "irc_color_decode" */
+ snprintf (string, sizeof (string),
+ "test_%sbold%s_end",
+ gui_color_get_custom ("bold"),
+ gui_color_get_custom ("-bold"));
+ result = hook_modifier_exec (NULL, "irc_color_decode",
+ "1", STRING_IRC_BOLD);
+ STRCMP_EQUAL(string, result);
+ free (result);
+
+ /* modifier "irc_color_encode" */
+ snprintf (string, sizeof (string),
+ "test_%sbold%s_end",
+ IRC_COLOR_BOLD_STR,
+ IRC_COLOR_BOLD_STR);
+ result = hook_modifier_exec (NULL, "irc_color_encode",
+ "1", STRING_USER_BOLD);
+ STRCMP_EQUAL(string, result);
+ free (result);
+
+ /* modifier "irc_color_encode" */
+ snprintf (string, sizeof (string),
+ "test_%sbold1%s_normal_%sbold2%s_normal_%sbold3%s_normal",
+ IRC_COLOR_BOLD_STR,
+ IRC_COLOR_BOLD_STR,
+ IRC_COLOR_BOLD_STR,
+ IRC_COLOR_BOLD_STR,
+ IRC_COLOR_BOLD_STR,
+ IRC_COLOR_BOLD_STR);
+ result = hook_modifier_exec (NULL, "irc_color_decode_ansi",
+ "1", STRING_ANSI_BOLD);
+ STRCMP_EQUAL(string, result);
+ free (result);
+}
+
+/*
+ * Tests functions:
+ * irc_color_weechat_add_to_infolist
+ */
+
+TEST(IrcColor, WeechatAddToInfolist)
+{
+ struct t_infolist *infolist;
+ struct t_infolist_item *ptr_item;
+ int num_items;
+
+ LONGS_EQUAL(0, irc_color_weechat_add_to_infolist (NULL));
+
+ infolist = infolist_new (NULL);
+ LONGS_EQUAL(1, irc_color_weechat_add_to_infolist (infolist));
+ num_items = 0;
+ for (ptr_item = infolist->items; ptr_item; ptr_item = ptr_item->next_item)
+ {
+ num_items++;
+ }
+ LONGS_EQUAL(IRC_NUM_COLORS, num_items);
+}