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/unit | |
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/unit')
-rw-r--r-- | tests/unit/gui/test-gui-chat.cpp | 116 | ||||
-rw-r--r-- | tests/unit/gui/test-gui-line.cpp | 19 |
2 files changed, 117 insertions, 18 deletions
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), |