diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-01-30 11:41:06 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-01-30 11:41:06 +0100 |
commit | 9259442dbfbb51695a7f9c427da589fc1f92420d (patch) | |
tree | a66f959ccf1bce41481dca238b24406fba52d4da /tests | |
parent | bf3241208b553babdeb851d684060b81d30edc72 (diff) | |
download | weechat-9259442dbfbb51695a7f9c427da589fc1f92420d.zip |
core: add support of date and tags in messages displayed in buffers with free content, add function printf_y_date_tags (closes #1746)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/scripts/python/testapi.py | 16 | ||||
-rwxr-xr-x | tests/scripts/python/testapigen.py | 1 | ||||
-rw-r--r-- | tests/scripts/test-scripts.cpp | 5 | ||||
-rw-r--r-- | tests/unit/gui/test-gui-chat.cpp | 116 | ||||
-rw-r--r-- | tests/unit/gui/test-gui-line.cpp | 19 |
5 files changed, 138 insertions, 19 deletions
diff --git a/tests/scripts/python/testapi.py b/tests/scripts/python/testapi.py index 634370c22..4be516319 100644 --- a/tests/scripts/python/testapi.py +++ b/tests/scripts/python/testapi.py @@ -148,6 +148,16 @@ def test_key(): check(weechat.key_unbind('mouse', 'quiet:area:chat(plugin.test)') == 3) +def buffer_input_cb(data, buffer, input_data): + """Buffer input callback.""" + return weechat.WEECHAT_RC_OK + + +def buffer_close_cb(data, buffer): + """Buffer close callback.""" + return weechat.WEECHAT_RC_OK + + def test_display(): """Test display functions.""" check(weechat.prefix('action') != '') @@ -158,6 +168,12 @@ def test_display(): check(weechat.prefix('unknown') == '') check(weechat.color('green') != '') check(weechat.color('unknown') == '') + weechat.prnt('', '## test prnt') + weechat.prnt_date_tags('', 946681200, 'tag1,tag2', '## test prnt_date_tags') + buffer = weechat.buffer_new('test_free', 'buffer_input_cb', '', 'buffer_close_cb', '') + weechat.prnt_y(buffer, 0, '## test prnt_y') + weechat.prnt_y_date_tags(buffer, 0, 946681200, 'tag1,tag2', '## test prnt_y_date_tags') + weechat.buffer_close(buffer) def completion_cb(data, completion_item, buf, completion): diff --git a/tests/scripts/python/testapigen.py b/tests/scripts/python/testapigen.py index 4a63c8f1f..3d529ea4c 100755 --- a/tests/scripts/python/testapigen.py +++ b/tests/scripts/python/testapigen.py @@ -111,6 +111,7 @@ class WeechatScript(object): # pylint: disable=too-many-instance-attributes 'prnt': 'print', 'prnt_date_tags': 'print_date_tags', 'prnt_y': 'print_y', + 'prnt_y_date_tags': 'print_y_date_tags', } for node in ast.walk(self.tree): if isinstance(node, ast.Call) and \ diff --git a/tests/scripts/test-scripts.cpp b/tests/scripts/test-scripts.cpp index 33eaa3818..1dfc38f71 100644 --- a/tests/scripts/test-scripts.cpp +++ b/tests/scripts/test-scripts.cpp @@ -89,8 +89,11 @@ TEST_GROUP(Scripts) api_tests_errors++; else if (strstr (message, "TESTS END")) api_tests_end++; - else if ((message[0] != '>') && (message[0] != ' ')) + else if ((message[0] != '>') && (message[0] != ' ') + && (strncmp (message, "## ", 3) != 0)) + { api_tests_other++; + } } return WEECHAT_RC_OK; diff --git a/tests/unit/gui/test-gui-chat.cpp b/tests/unit/gui/test-gui-chat.cpp index 385c14b91..e359595e3 100644 --- a/tests/unit/gui/test-gui-chat.cpp +++ b/tests/unit/gui/test-gui-chat.cpp @@ -520,6 +520,27 @@ TEST(GuiChat, PrintDateTags) LONGS_EQUAL(4, ptr_data->prefix_length); STRCMP_EQUAL("this is a test", ptr_data->message); + /* message with empty tags */ + ptr_last_line = gui_buffers->own_lines->last_line; + gui_chat_printf_date_tags (gui_buffers, 0, "", "nick\tthis is a test"); + CHECK(ptr_last_line != gui_buffers->own_lines->last_line); + ptr_data = gui_buffers->own_lines->last_line->data; + CHECK(ptr_data); + POINTERS_EQUAL(gui_buffers, ptr_data->buffer); + LONGS_EQUAL(-1, ptr_data->y); + CHECK(ptr_data->date > 0); + CHECK(ptr_data->date == ptr_data->date_printed); + CHECK(ptr_data->str_time && ptr_data->str_time[0]); + LONGS_EQUAL(0, ptr_data->tags_count); + POINTERS_EQUAL(NULL, ptr_data->tags_array); + LONGS_EQUAL(1, ptr_data->displayed); + LONGS_EQUAL(0, ptr_data->notify_level); + LONGS_EQUAL(0, ptr_data->highlight); + LONGS_EQUAL(0, ptr_data->refresh_needed); + STRCMP_EQUAL("nick", ptr_data->prefix); + LONGS_EQUAL(4, ptr_data->prefix_length); + STRCMP_EQUAL("this is a test", ptr_data->message); + /* message with 3 tags */ ptr_last_line = gui_buffers->own_lines->last_line; gui_chat_printf_date_tags (gui_buffers, 0, "tag1,tag2,tag3", "nick\tthis is a test"); @@ -547,10 +568,10 @@ TEST(GuiChat, PrintDateTags) /* * Tests functions: - * gui_chat_printf_y + * gui_chat_printf_y_date_tags */ -TEST(GuiChat, PrintY) +TEST(GuiChat, PrintYDateTags) { struct t_gui_buffer *buffer; struct t_gui_line_data *ptr_data; @@ -560,30 +581,70 @@ TEST(GuiChat, PrintY) gui_buffer_set (buffer, "type", "free"); /* invalid buffer pointer */ - gui_chat_printf_y ((struct t_gui_buffer *)0x1, 0, "test"); + gui_chat_printf_y_date_tags ((struct t_gui_buffer *)0x1, 0, 0, NULL, "test"); POINTERS_EQUAL(NULL, buffer->own_lines->last_line); /* invalid buffer: not with free content */ - gui_chat_printf_y (gui_buffers, 0, "test"); + gui_chat_printf_y_date_tags (gui_buffers, 0, 0, NULL, "test"); POINTERS_EQUAL(NULL, buffer->own_lines->last_line); /* NULL message */ - gui_chat_printf_y (buffer, 0, NULL); + gui_chat_printf_y_date_tags (buffer, 0, 0, NULL, NULL); POINTERS_EQUAL(NULL, buffer->own_lines->last_line); /* empty message */ - gui_chat_printf_y (buffer, 0, ""); + gui_chat_printf_y_date_tags (buffer, 0, 0, NULL, ""); POINTERS_EQUAL(NULL, buffer->own_lines->last_line); /* message on first line */ - gui_chat_printf_y (buffer, 0, "this is a test on line 1"); + gui_chat_printf_y_date_tags (buffer, 0, 0, NULL, "this is a test on line 1"); CHECK(buffer->own_lines->last_line); ptr_data = buffer->own_lines->last_line->data; CHECK(ptr_data); POINTERS_EQUAL(buffer, ptr_data->buffer); LONGS_EQUAL(0, ptr_data->y); - LONGS_EQUAL(0, ptr_data->date); - LONGS_EQUAL(0, ptr_data->date_printed); + CHECK(ptr_data->date > 0); + CHECK(ptr_data->date == ptr_data->date_printed); + POINTERS_EQUAL(NULL, ptr_data->str_time); + LONGS_EQUAL(0, ptr_data->tags_count); + POINTERS_EQUAL(NULL, ptr_data->tags_array); + LONGS_EQUAL(1, ptr_data->displayed); + LONGS_EQUAL(0, ptr_data->notify_level); + LONGS_EQUAL(0, ptr_data->highlight); + LONGS_EQUAL(1, ptr_data->refresh_needed); + POINTERS_EQUAL(NULL, ptr_data->prefix); + LONGS_EQUAL(0, ptr_data->prefix_length); + STRCMP_EQUAL("this is a test on line 1", ptr_data->message); + + /* message on first line with past date */ + gui_chat_printf_y_date_tags (buffer, 0, 946681200, NULL, "this is a test on line 1"); + CHECK(buffer->own_lines->last_line); + ptr_data = buffer->own_lines->last_line->data; + CHECK(ptr_data); + POINTERS_EQUAL(buffer, ptr_data->buffer); + LONGS_EQUAL(0, ptr_data->y); + LONGS_EQUAL(946681200, ptr_data->date); + CHECK(ptr_data->date < ptr_data->date_printed); + POINTERS_EQUAL(NULL, ptr_data->str_time); + LONGS_EQUAL(0, ptr_data->tags_count); + POINTERS_EQUAL(NULL, ptr_data->tags_array); + LONGS_EQUAL(1, ptr_data->displayed); + LONGS_EQUAL(0, ptr_data->notify_level); + LONGS_EQUAL(0, ptr_data->highlight); + LONGS_EQUAL(1, ptr_data->refresh_needed); + POINTERS_EQUAL(NULL, ptr_data->prefix); + LONGS_EQUAL(0, ptr_data->prefix_length); + STRCMP_EQUAL("this is a test on line 1", ptr_data->message); + + /* message on first line with empty tags */ + gui_chat_printf_y_date_tags (buffer, 0, 0, "", "this is a test on line 1"); + CHECK(buffer->own_lines->last_line); + ptr_data = buffer->own_lines->last_line->data; + CHECK(ptr_data); + POINTERS_EQUAL(buffer, ptr_data->buffer); + LONGS_EQUAL(0, ptr_data->y); + CHECK(ptr_data->date > 0); + CHECK(ptr_data->date == ptr_data->date_printed); POINTERS_EQUAL(NULL, ptr_data->str_time); LONGS_EQUAL(0, ptr_data->tags_count); POINTERS_EQUAL(NULL, ptr_data->tags_array); @@ -595,15 +656,38 @@ TEST(GuiChat, PrintY) LONGS_EQUAL(0, ptr_data->prefix_length); STRCMP_EQUAL("this is a test on line 1", ptr_data->message); + /* message on first line with 3 tags */ + gui_chat_printf_y_date_tags (buffer, 0, 0, "tag1,tag2,tag3", "this is a test on line 1"); + CHECK(buffer->own_lines->last_line); + ptr_data = buffer->own_lines->last_line->data; + CHECK(ptr_data); + POINTERS_EQUAL(buffer, ptr_data->buffer); + LONGS_EQUAL(0, ptr_data->y); + CHECK(ptr_data->date > 0); + CHECK(ptr_data->date == ptr_data->date_printed); + POINTERS_EQUAL(NULL, ptr_data->str_time); + LONGS_EQUAL(3, ptr_data->tags_count); + CHECK(ptr_data->tags_array); + STRCMP_EQUAL("tag1", ptr_data->tags_array[0]); + STRCMP_EQUAL("tag2", ptr_data->tags_array[1]); + STRCMP_EQUAL("tag3", ptr_data->tags_array[2]); + LONGS_EQUAL(1, ptr_data->displayed); + LONGS_EQUAL(0, ptr_data->notify_level); + LONGS_EQUAL(0, ptr_data->highlight); + LONGS_EQUAL(1, ptr_data->refresh_needed); + POINTERS_EQUAL(NULL, ptr_data->prefix); + LONGS_EQUAL(0, ptr_data->prefix_length); + STRCMP_EQUAL("this is a test on line 1", ptr_data->message); + /* message on third line */ - gui_chat_printf_y (buffer, 2, "this is a test on line 3"); + gui_chat_printf_y_date_tags (buffer, 2, 0, NULL, "this is a test on line 3"); CHECK(buffer->own_lines->last_line); ptr_data = buffer->own_lines->last_line->data; CHECK(ptr_data); POINTERS_EQUAL(buffer, ptr_data->buffer); LONGS_EQUAL(2, ptr_data->y); - LONGS_EQUAL(0, ptr_data->date); - LONGS_EQUAL(0, ptr_data->date_printed); + CHECK(ptr_data->date > 0); + CHECK(ptr_data->date == ptr_data->date_printed); POINTERS_EQUAL(NULL, ptr_data->str_time); LONGS_EQUAL(0, ptr_data->tags_count); POINTERS_EQUAL(NULL, ptr_data->tags_array); @@ -616,7 +700,7 @@ TEST(GuiChat, PrintY) STRCMP_EQUAL("this is a test on line 3", ptr_data->message); /* delete first line */ - gui_chat_printf_y (buffer, 0, ""); + gui_chat_printf_y_date_tags (buffer, 0, 0, NULL, ""); ptr_data = buffer->own_lines->first_line->data; CHECK(ptr_data); POINTERS_EQUAL(buffer, ptr_data->buffer); @@ -635,13 +719,13 @@ TEST(GuiChat, PrintY) STRCMP_EQUAL("", ptr_data->message); /* delete third line */ - gui_chat_printf_y (buffer, 2, ""); + gui_chat_printf_y_date_tags (buffer, 2, 0, NULL, ""); CHECK(buffer->own_lines->first_line); CHECK(buffer->own_lines->first_line->next_line); POINTERS_EQUAL(NULL, buffer->own_lines->first_line->next_line->next_line); - /* delete secondline */ - gui_chat_printf_y (buffer, 1, ""); + /* delete second line */ + gui_chat_printf_y_date_tags (buffer, 1, 0, NULL, ""); CHECK(buffer->own_lines->first_line); POINTERS_EQUAL(NULL, buffer->own_lines->first_line->next_line); diff --git a/tests/unit/gui/test-gui-line.cpp b/tests/unit/gui/test-gui-line.cpp index 6032301c1..14e37a03f 100644 --- a/tests/unit/gui/test-gui-line.cpp +++ b/tests/unit/gui/test-gui-line.cpp @@ -36,7 +36,8 @@ extern "C" #define WEE_BUILD_STR_PREFIX_MSG(__result, __prefix, __message) \ line = gui_line_new (gui_buffers, -1, 0, 0, "tag1,tag2", \ __prefix, __message); \ - str = gui_line_build_string_prefix_message (line); \ + str = gui_line_build_string_prefix_message (line->data->prefix, \ + line->data->message); \ STRCMP_EQUAL(__result, str); \ free (str); \ gui_line_free_data (line); \ @@ -45,7 +46,9 @@ extern "C" #define WEE_BUILD_STR_MSG_TAGS(__tags, __message) \ line = gui_line_new (gui_buffers, -1, 0, 0, __tags, \ NULL, __message); \ - str = gui_line_build_string_message_tags (line); \ + str = gui_line_build_string_message_tags (line->data->message, \ + line->data->tags_count, \ + line->data->tags_array); \ STRCMP_EQUAL(str_result, str); \ free (str); \ gui_line_free_data (line); \ @@ -213,6 +216,18 @@ TEST(GuiLine, BuildStringMessageTags) struct t_gui_line *line; char *str, str_result[256]; + line = gui_line_new (gui_buffers, -1, 0, 0, "tag1,tag2", NULL, "test"); + POINTERS_EQUAL(NULL, + gui_line_build_string_message_tags (line->data->message, + -1, + line->data->tags_array)); + POINTERS_EQUAL(NULL, + gui_line_build_string_message_tags (line->data->message, + 1, + NULL)); + gui_line_free_data (line); + free (line); + snprintf (str_result, sizeof (str_result), "message%s [%s%s]", GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), |