diff options
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/core/test-core-util.cpp | 89 | ||||
-rw-r--r-- | tests/unit/gui/test-gui-chat.cpp | 94 | ||||
-rw-r--r-- | tests/unit/gui/test-gui-line.cpp | 83 | ||||
-rw-r--r-- | tests/unit/plugins/irc/test-irc-protocol.cpp | 46 |
4 files changed, 250 insertions, 62 deletions
diff --git a/tests/unit/core/test-core-util.cpp b/tests/unit/core/test-core-util.cpp index d4b167970..d0d3ed8dc 100644 --- a/tests/unit/core/test-core-util.cpp +++ b/tests/unit/core/test-core-util.cpp @@ -142,6 +142,95 @@ TEST(CoreUtil, GetTimeString) /* * Tests functions: + * util_strftimeval + */ + +TEST(CoreUtil, Strftimeval) +{ + struct timeval tv; + char str_time[256]; + + /* test date: 2023-12-25T10:29:09.456789Z */ + tv.tv_sec = 1703500149; + tv.tv_usec = 456789; + + LONGS_EQUAL(0, util_strftimeval (NULL, 0, NULL, NULL)); + LONGS_EQUAL(0, util_strftimeval (str_time, 0, NULL, NULL)); + LONGS_EQUAL(0, util_strftimeval (str_time, 0, "", NULL)); + LONGS_EQUAL(0, util_strftimeval (str_time, -1, "", &tv)); + + strcpy (str_time, "test"); + LONGS_EQUAL(0, util_strftimeval (str_time, sizeof (str_time), "", &tv)); + STRCMP_EQUAL("", str_time); + + strcpy (str_time, "test"); + LONGS_EQUAL(8, util_strftimeval (str_time, sizeof (str_time), + "%H:%M:%S", &tv)); + STRCMP_EQUAL("10:29:09", str_time); + + strcpy (str_time, "test"); + LONGS_EQUAL(19, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %H:%M:%S", &tv)); + STRCMP_EQUAL("2023-12-25 10:29:09", str_time); + + strcpy (str_time, "test"); + LONGS_EQUAL(19, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %H:%M:%S", &tv)); + STRCMP_EQUAL("2023-12-25 10:29:09", str_time); + + strcpy (str_time, "test"); + LONGS_EQUAL(21, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %% %H:%M:%S", &tv)); + STRCMP_EQUAL("2023-12-25 % 10:29:09", str_time); + + strcpy (str_time, "test"); + LONGS_EQUAL(21, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %H:%M:%S.%.1", &tv)); + STRCMP_EQUAL("2023-12-25 10:29:09.4", str_time); + + strcpy (str_time, "test"); + LONGS_EQUAL(22, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %H:%M:%S.%.2", &tv)); + STRCMP_EQUAL("2023-12-25 10:29:09.45", str_time); + + strcpy (str_time, "test"); + LONGS_EQUAL(23, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %H:%M:%S.%.3", &tv)); + STRCMP_EQUAL("2023-12-25 10:29:09.456", str_time); + + strcpy (str_time, "test"); + LONGS_EQUAL(24, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %H:%M:%S.%.4", &tv)); + STRCMP_EQUAL("2023-12-25 10:29:09.4567", str_time); + + strcpy (str_time, "test"); + LONGS_EQUAL(25, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %H:%M:%S.%.5", &tv)); + STRCMP_EQUAL("2023-12-25 10:29:09.45678", str_time); + + strcpy (str_time, "test"); + LONGS_EQUAL(26, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %H:%M:%S.%.6", &tv)); + STRCMP_EQUAL("2023-12-25 10:29:09.456789", str_time); + + strcpy (str_time, "test"); + LONGS_EQUAL(26, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %H:%M:%S.%f", &tv)); + STRCMP_EQUAL("2023-12-25 10:29:09.456789", str_time); + + /* invalid microseconds digits (must be 1-6) */ + strcpy (str_time, "test"); + LONGS_EQUAL(23, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %H:%M:%S.%.0", &tv)); + STRCMP_EQUAL("2023-12-25 10:29:09.%.0", str_time); + strcpy (str_time, "test"); + LONGS_EQUAL(23, util_strftimeval (str_time, sizeof (str_time), + "%Y-%m-%d %H:%M:%S.%.7", &tv)); + STRCMP_EQUAL("2023-12-25 10:29:09.%.7", str_time); +} + +/* + * Tests functions: * util_get_time_diff */ diff --git a/tests/unit/gui/test-gui-chat.cpp b/tests/unit/gui/test-gui-chat.cpp index 354271c5a..f5bc69205 100644 --- a/tests/unit/gui/test-gui-chat.cpp +++ b/tests/unit/gui/test-gui-chat.cpp @@ -428,35 +428,37 @@ TEST(GuiChat, PrintLinesWaitingBuffer) /* * Tests functions: - * gui_chat_printf_date_tags_internal - * gui_chat_printf_date_tags + * gui_chat_printf_datetime_tags_internal + * gui_chat_printf_datetime_tags */ -TEST(GuiChat, PrintDateTags) +TEST(GuiChat, PrintDatetimeTags) { struct t_gui_line *ptr_last_line; struct t_gui_line_data *ptr_data; /* invalid buffer */ ptr_last_line = gui_buffers->own_lines->last_line; - gui_chat_printf_date_tags ((struct t_gui_buffer *)0x1, 0, NULL, "test"); + gui_chat_printf_datetime_tags ((struct t_gui_buffer *)0x1, 0, 0, NULL, "test"); POINTERS_EQUAL(ptr_last_line, gui_buffers->own_lines->last_line); /* NULL message */ ptr_last_line = gui_buffers->own_lines->last_line; - gui_chat_printf_date_tags (gui_buffers, 0, NULL, NULL); + gui_chat_printf_datetime_tags (gui_buffers, 0, 0, NULL, NULL); POINTERS_EQUAL(ptr_last_line, gui_buffers->own_lines->last_line); /* empty message */ ptr_last_line = gui_buffers->own_lines->last_line; - gui_chat_printf_date_tags (gui_buffers, 0, NULL, ""); + gui_chat_printf_datetime_tags (gui_buffers, 0, 0, NULL, ""); 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_usec >= 0) && (ptr_data->date_usec <= 999999)); CHECK(ptr_data->date == ptr_data->date_printed); + CHECK(ptr_data->date_usec == ptr_data->date_usec_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); @@ -470,14 +472,16 @@ TEST(GuiChat, PrintDateTags) /* message (no prefix) */ ptr_last_line = gui_buffers->own_lines->last_line; - gui_chat_printf_date_tags (gui_buffers, 0, NULL, "this is a test"); + gui_chat_printf_datetime_tags (gui_buffers, 0, 0, NULL, "this 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_usec >= 0) && (ptr_data->date_usec <= 999999)); CHECK(ptr_data->date == ptr_data->date_printed); + CHECK(ptr_data->date_usec == ptr_data->date_usec_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); @@ -491,14 +495,16 @@ TEST(GuiChat, PrintDateTags) /* message with prefix */ ptr_last_line = gui_buffers->own_lines->last_line; - gui_chat_printf_date_tags (gui_buffers, 0, NULL, "nick\tthis is a test"); + gui_chat_printf_datetime_tags (gui_buffers, 0, 0, NULL, "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_usec >= 0) && (ptr_data->date_usec <= 999999)); CHECK(ptr_data->date == ptr_data->date_printed); + CHECK(ptr_data->date_usec == ptr_data->date_usec_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); @@ -512,14 +518,16 @@ TEST(GuiChat, PrintDateTags) /* message with prefix */ ptr_last_line = gui_buffers->own_lines->last_line; - gui_chat_printf_date_tags (gui_buffers, 0, NULL, "nick\tthis is a test"); + gui_chat_printf_datetime_tags (gui_buffers, 0, 0, NULL, "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_usec >= 0) && (ptr_data->date_usec <= 999999)); CHECK(ptr_data->date == ptr_data->date_printed); + CHECK(ptr_data->date_usec == ptr_data->date_usec_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); @@ -533,14 +541,16 @@ TEST(GuiChat, PrintDateTags) /* message with ignored prefix (space + tab) */ ptr_last_line = gui_buffers->own_lines->last_line; - gui_chat_printf_date_tags (gui_buffers, 0, NULL, " \tthis is a test"); + gui_chat_printf_datetime_tags (gui_buffers, 0, 0, NULL, " \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_usec >= 0) && (ptr_data->date_usec <= 999999)); CHECK(ptr_data->date == ptr_data->date_printed); + CHECK(ptr_data->date_usec == ptr_data->date_usec_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); @@ -554,14 +564,16 @@ TEST(GuiChat, PrintDateTags) /* message with no time displayed (two tabs) */ ptr_last_line = gui_buffers->own_lines->last_line; - gui_chat_printf_date_tags (gui_buffers, 0, NULL, "\t\tthis is a test"); + gui_chat_printf_datetime_tags (gui_buffers, 0, 0, NULL, "\t\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); LONGS_EQUAL(0, ptr_data->date); + LONGS_EQUAL(0, ptr_data->date_usec); CHECK(ptr_data->date_printed > 0); + CHECK((ptr_data->date_usec_printed >= 0) && (ptr_data->date_usec_printed <= 999999)); POINTERS_EQUAL(NULL, ptr_data->str_time); LONGS_EQUAL(0, ptr_data->tags_count); POINTERS_EQUAL(NULL, ptr_data->tags_array); @@ -575,13 +587,15 @@ TEST(GuiChat, PrintDateTags) /* message with past date */ ptr_last_line = gui_buffers->own_lines->last_line; - gui_chat_printf_date_tags (gui_buffers, 946681200, NULL, "nick\tthis is a test"); + gui_chat_printf_datetime_tags (gui_buffers, 946681200, 123456, NULL, + "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); LONGS_EQUAL(946681200, ptr_data->date); + LONGS_EQUAL(123456, ptr_data->date_usec); 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); @@ -596,14 +610,17 @@ TEST(GuiChat, PrintDateTags) /* 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"); + gui_chat_printf_datetime_tags (gui_buffers, 0, 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_usec >= 0) && (ptr_data->date_usec <= 999999)); CHECK(ptr_data->date == ptr_data->date_printed); + CHECK(ptr_data->date_usec == ptr_data->date_usec_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); @@ -617,14 +634,17 @@ TEST(GuiChat, PrintDateTags) /* 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"); + gui_chat_printf_datetime_tags (gui_buffers, 0, 0, "tag1,tag2,tag3", + "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_usec >= 0) && (ptr_data->date_usec <= 999999)); CHECK(ptr_data->date == ptr_data->date_printed); + CHECK(ptr_data->date_usec == ptr_data->date_usec_printed); CHECK(ptr_data->str_time && ptr_data->str_time[0]); LONGS_EQUAL(3, ptr_data->tags_count); CHECK(ptr_data->tags_array); @@ -642,10 +662,10 @@ TEST(GuiChat, PrintDateTags) /* * Tests functions: - * gui_chat_printf_y_date_tags + * gui_chat_printf_y_datetime_tags */ -TEST(GuiChat, PrintYDateTags) +TEST(GuiChat, PrintYDatetimeTags) { struct t_gui_buffer *buffer; struct t_gui_line_data *ptr_data; @@ -655,30 +675,34 @@ TEST(GuiChat, PrintYDateTags) gui_buffer_set (buffer, "type", "free"); /* invalid buffer pointer */ - gui_chat_printf_y_date_tags ((struct t_gui_buffer *)0x1, 0, 0, NULL, "test"); + gui_chat_printf_y_datetime_tags ((struct t_gui_buffer *)0x1, 0, 0, 0, NULL, + "test"); POINTERS_EQUAL(NULL, buffer->own_lines->last_line); /* invalid buffer: not with free content */ - gui_chat_printf_y_date_tags (gui_buffers, 0, 0, NULL, "test"); + gui_chat_printf_y_datetime_tags (gui_buffers, 0, 0, 0, NULL, "test"); POINTERS_EQUAL(NULL, buffer->own_lines->last_line); /* NULL message */ - gui_chat_printf_y_date_tags (buffer, 0, 0, NULL, NULL); + gui_chat_printf_y_datetime_tags (buffer, 0, 0, 0, NULL, NULL); POINTERS_EQUAL(NULL, buffer->own_lines->last_line); /* empty message */ - gui_chat_printf_y_date_tags (buffer, 0, 0, NULL, ""); + gui_chat_printf_y_datetime_tags (buffer, 0, 0, 0, NULL, ""); POINTERS_EQUAL(NULL, buffer->own_lines->last_line); /* message on first line */ - gui_chat_printf_y_date_tags (buffer, 0, 0, NULL, "this is a test on line 1"); + gui_chat_printf_y_datetime_tags (buffer, 0, 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); CHECK(ptr_data->date > 0); + CHECK((ptr_data->date_usec >= 0) && (ptr_data->date_usec <= 999999)); CHECK(ptr_data->date == ptr_data->date_printed); + CHECK(ptr_data->date_usec == ptr_data->date_usec_printed); POINTERS_EQUAL(NULL, ptr_data->str_time); LONGS_EQUAL(0, ptr_data->tags_count); POINTERS_EQUAL(NULL, ptr_data->tags_array); @@ -691,14 +715,17 @@ TEST(GuiChat, PrintYDateTags) 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"); + gui_chat_printf_y_datetime_tags (buffer, 0, 946681200, 123456, 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); + LONGS_EQUAL(123456, ptr_data->date_usec); CHECK(ptr_data->date < ptr_data->date_printed); + CHECK((ptr_data->date_usec_printed >= 0) && (ptr_data->date_usec_printed <= 999999)); POINTERS_EQUAL(NULL, ptr_data->str_time); LONGS_EQUAL(0, ptr_data->tags_count); POINTERS_EQUAL(NULL, ptr_data->tags_array); @@ -711,14 +738,17 @@ TEST(GuiChat, PrintYDateTags) 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"); + gui_chat_printf_y_datetime_tags (buffer, 0, 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_usec >= 0) && (ptr_data->date_usec <= 999999)); CHECK(ptr_data->date == ptr_data->date_printed); + CHECK(ptr_data->date_usec == ptr_data->date_usec_printed); POINTERS_EQUAL(NULL, ptr_data->str_time); LONGS_EQUAL(0, ptr_data->tags_count); POINTERS_EQUAL(NULL, ptr_data->tags_array); @@ -731,14 +761,17 @@ TEST(GuiChat, PrintYDateTags) 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"); + gui_chat_printf_y_datetime_tags (buffer, 0, 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_usec >= 0) && (ptr_data->date_usec <= 999999)); CHECK(ptr_data->date == ptr_data->date_printed); + CHECK(ptr_data->date_usec == ptr_data->date_usec_printed); POINTERS_EQUAL(NULL, ptr_data->str_time); LONGS_EQUAL(3, ptr_data->tags_count); CHECK(ptr_data->tags_array); @@ -754,14 +787,17 @@ TEST(GuiChat, PrintYDateTags) STRCMP_EQUAL("this is a test on line 1", ptr_data->message); /* message on third line */ - gui_chat_printf_y_date_tags (buffer, 2, 0, NULL, "this is a test on line 3"); + gui_chat_printf_y_datetime_tags (buffer, 2, 0, 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); CHECK(ptr_data->date > 0); + CHECK((ptr_data->date_usec >= 0) && (ptr_data->date_usec <= 999999)); CHECK(ptr_data->date == ptr_data->date_printed); + CHECK(ptr_data->date_usec == ptr_data->date_usec_printed); POINTERS_EQUAL(NULL, ptr_data->str_time); LONGS_EQUAL(0, ptr_data->tags_count); POINTERS_EQUAL(NULL, ptr_data->tags_array); @@ -774,13 +810,15 @@ TEST(GuiChat, PrintYDateTags) STRCMP_EQUAL("this is a test on line 3", ptr_data->message); /* delete first line */ - gui_chat_printf_y_date_tags (buffer, 0, 0, NULL, ""); + gui_chat_printf_y_datetime_tags (buffer, 0, 0, 0, NULL, ""); ptr_data = buffer->own_lines->first_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_usec); LONGS_EQUAL(0, ptr_data->date_printed); + LONGS_EQUAL(0, ptr_data->date_usec_printed); POINTERS_EQUAL(NULL, ptr_data->str_time); LONGS_EQUAL(0, ptr_data->tags_count); POINTERS_EQUAL(NULL, ptr_data->tags_array); @@ -793,13 +831,13 @@ TEST(GuiChat, PrintYDateTags) STRCMP_EQUAL("", ptr_data->message); /* delete third line */ - gui_chat_printf_y_date_tags (buffer, 2, 0, NULL, ""); + gui_chat_printf_y_datetime_tags (buffer, 2, 0, 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 second line */ - gui_chat_printf_y_date_tags (buffer, 1, 0, NULL, ""); + gui_chat_printf_y_datetime_tags (buffer, 1, 0, 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 4312cf87e..5a9e61bf3 100644 --- a/tests/unit/gui/test-gui-line.cpp +++ b/tests/unit/gui/test-gui-line.cpp @@ -24,6 +24,8 @@ extern "C" { #include <string.h> +#include <time.h> +#include <sys/time.h> #include "src/core/wee-config.h" #include "src/core/wee-string.h" #include "src/gui/gui-buffer.h" @@ -35,7 +37,7 @@ extern "C" } #define WEE_BUILD_STR_PREFIX_MSG(__result, __prefix, __message) \ - line = gui_line_new (gui_buffers, -1, 0, 0, "tag1,tag2", \ + line = gui_line_new (gui_buffers, -1, 0, 0, 0, 0, "tag1,tag2", \ __prefix, __message); \ str = gui_line_build_string_prefix_message (line->data->prefix, \ line->data->message); \ @@ -45,7 +47,7 @@ extern "C" free (line); #define WEE_BUILD_STR_MSG_TAGS(__tags, __message, __colors) \ - line = gui_line_new (gui_buffers, -1, 0, 0, __tags, \ + line = gui_line_new (gui_buffers, -1, 0, 0, 0, 0, __tags, \ NULL, __message); \ str = gui_line_build_string_message_tags (line->data->message, \ line->data->tags_count, \ @@ -218,7 +220,7 @@ TEST(GuiLine, BuildStringMessageTags) struct t_gui_line *line; char *str, str_message[256], str_result[256]; - line = gui_line_new (gui_buffers, -1, 0, 0, "tag1,tag2", NULL, "test"); + line = gui_line_new (gui_buffers, -1, 0, 0, 0, 0, "tag1,tag2", NULL, "test"); POINTERS_EQUAL(NULL, gui_line_build_string_message_tags (line->data->message, -1, @@ -846,21 +848,30 @@ TEST(GuiLine, New) { struct t_gui_buffer *buffer; struct t_gui_line *line1, *line2, *line3, *line4; - time_t date_printed, date; + struct timeval date_printed, date; char *str_time; - date_printed = time (NULL); - date = date_printed - 1; - str_time = gui_chat_get_time_string (date); + gettimeofday (&date_printed, NULL); + date.tv_sec = date_printed.tv_sec - 1; + date.tv_usec = date_printed.tv_usec; + str_time = gui_chat_get_time_string (date.tv_sec, date.tv_usec); POINTERS_EQUAL(NULL, - gui_line_new (NULL, 0, date, date_printed, NULL, NULL, NULL)); + gui_line_new ( + NULL, 0, + date.tv_sec, date.tv_usec, + date_printed.tv_sec, date_printed.tv_usec, + NULL, NULL, NULL)); /* create a new test buffer (formatted content) */ buffer = gui_buffer_new_user ("test", GUI_BUFFER_TYPE_FORMATTED); CHECK(buffer); - line1 = gui_line_new (buffer, 0, date, date_printed, NULL, NULL, NULL); + line1 = gui_line_new (buffer, + 0, + date.tv_sec, date.tv_usec, + date_printed.tv_sec, date_printed.tv_usec, + NULL, NULL, NULL); CHECK(line1); CHECK(line1->data); POINTERS_EQUAL(NULL, line1->prev_line); @@ -868,8 +879,10 @@ TEST(GuiLine, New) POINTERS_EQUAL(buffer, line1->data->buffer); LONGS_EQUAL(0, line1->data->id); LONGS_EQUAL(-1, line1->data->y); - LONGS_EQUAL(date, line1->data->date); - LONGS_EQUAL(date_printed, line1->data->date_printed); + LONGS_EQUAL(date.tv_sec, line1->data->date); + LONGS_EQUAL(date.tv_usec, line1->data->date_usec); + LONGS_EQUAL(date_printed.tv_sec, line1->data->date_printed); + LONGS_EQUAL(date_printed.tv_usec, line1->data->date_usec_printed); STRCMP_EQUAL(str_time, line1->data->str_time); LONGS_EQUAL(0, line1->data->tags_count); POINTERS_EQUAL(NULL, line1->data->tags_array); @@ -884,7 +897,11 @@ TEST(GuiLine, New) POINTERS_EQUAL(NULL, line1->prev_line); POINTERS_EQUAL(NULL, line1->next_line); - line2 = gui_line_new (buffer, 0, date, date_printed, "tag1,tag2,tag3", + line2 = gui_line_new (buffer, + 0, + date.tv_sec, date.tv_usec, + date_printed.tv_sec, date_printed.tv_usec, + "tag1,tag2,tag3", "prefix", "message"); CHECK(line2); CHECK(line2->data); @@ -893,8 +910,10 @@ TEST(GuiLine, New) POINTERS_EQUAL(buffer, line2->data->buffer); LONGS_EQUAL(1, line2->data->id); LONGS_EQUAL(-1, line2->data->y); - LONGS_EQUAL(date, line2->data->date); - LONGS_EQUAL(date_printed, line2->data->date_printed); + LONGS_EQUAL(date.tv_sec, line2->data->date); + LONGS_EQUAL(date.tv_usec, line2->data->date_usec); + LONGS_EQUAL(date_printed.tv_sec, line2->data->date_printed); + LONGS_EQUAL(date_printed.tv_usec, line2->data->date_usec_printed); STRCMP_EQUAL(str_time, line2->data->str_time); LONGS_EQUAL(3, line2->data->tags_count); CHECK(line2->data->tags_array); @@ -914,10 +933,18 @@ TEST(GuiLine, New) /* simulate next_line_id == INT_MAX and display 2 lines */ buffer->next_line_id = INT_MAX; - line3 = gui_line_new (buffer, 0, date, date_printed, NULL, NULL, "test"); + line3 = gui_line_new (buffer, + 0, + date.tv_sec, date.tv_usec, + date_printed.tv_sec, date_printed.tv_usec, + NULL, NULL, "test"); CHECK(line3); LONGS_EQUAL(INT_MAX, line3->data->id); - line4 = gui_line_new (buffer, 0, date, date_printed, NULL, NULL, "test"); + line4 = gui_line_new (buffer, + 0, + date.tv_sec, date.tv_usec, + date_printed.tv_sec, date_printed.tv_usec, + NULL, NULL, "test"); CHECK(line4); LONGS_EQUAL(0, line4->data->id); @@ -927,7 +954,11 @@ TEST(GuiLine, New) buffer = gui_buffer_new_user ("test", GUI_BUFFER_TYPE_FREE); CHECK(buffer); - line1 = gui_line_new (buffer, 0, date, date_printed, NULL, NULL, NULL); + line1 = gui_line_new (buffer, + 0, + date.tv_sec, date.tv_usec, + date_printed.tv_sec, date_printed.tv_usec, + NULL, NULL, NULL); CHECK(line1); CHECK(line1->data); POINTERS_EQUAL(NULL, line1->prev_line); @@ -935,8 +966,10 @@ TEST(GuiLine, New) POINTERS_EQUAL(buffer, line1->data->buffer); LONGS_EQUAL(0, line1->data->id); LONGS_EQUAL(0, line1->data->y); - LONGS_EQUAL(date, line1->data->date); - LONGS_EQUAL(date_printed, line1->data->date_printed); + LONGS_EQUAL(date.tv_sec, line1->data->date); + LONGS_EQUAL(date.tv_usec, line1->data->date_usec); + LONGS_EQUAL(date_printed.tv_sec, line1->data->date_printed); + LONGS_EQUAL(date_printed.tv_usec, line1->data->date_usec_printed); POINTERS_EQUAL(NULL, line1->data->str_time); LONGS_EQUAL(0, line1->data->tags_count); POINTERS_EQUAL(NULL, line1->data->tags_array); @@ -951,7 +984,11 @@ TEST(GuiLine, New) POINTERS_EQUAL(NULL, line1->prev_line); POINTERS_EQUAL(NULL, line1->next_line); - line2 = gui_line_new (buffer, 3, date, date_printed, "tag1,tag2,tag3", + line2 = gui_line_new (buffer, + 3, + date.tv_sec, date.tv_usec, + date_printed.tv_sec, date_printed.tv_usec, + "tag1,tag2,tag3", NULL, "message"); CHECK(line2); CHECK(line2->data); @@ -960,8 +997,10 @@ TEST(GuiLine, New) POINTERS_EQUAL(buffer, line2->data->buffer); LONGS_EQUAL(3, line2->data->id); LONGS_EQUAL(3, line2->data->y); - LONGS_EQUAL(date, line2->data->date); - LONGS_EQUAL(date_printed, line2->data->date_printed); + LONGS_EQUAL(date.tv_sec, line2->data->date); + LONGS_EQUAL(date.tv_usec, line2->data->date_usec); + LONGS_EQUAL(date_printed.tv_sec, line2->data->date_printed); + LONGS_EQUAL(date_printed.tv_usec, line2->data->date_usec_printed); POINTERS_EQUAL(NULL, line2->data->str_time); LONGS_EQUAL(3, line2->data->tags_count); CHECK(line2->data->tags_array); diff --git a/tests/unit/plugins/irc/test-irc-protocol.cpp b/tests/unit/plugins/irc/test-irc-protocol.cpp index 507af3851..f2ea8db90 100644 --- a/tests/unit/plugins/irc/test-irc-protocol.cpp +++ b/tests/unit/plugins/irc/test-irc-protocol.cpp @@ -28,6 +28,7 @@ extern "C" { #include <stdio.h> #include <string.h> +#include <time.h> #include "src/core/wee-arraylist.h" #include "src/core/wee-config-file.h" #include "src/core/wee-hashtable.h" @@ -56,6 +57,8 @@ extern const char *irc_protocol_nick_address (struct t_irc_server *server, struct t_irc_nick *nick, const char *nickname, const char *address); +extern void irc_protocol_parse_time (const char *time, time_t *date, + int *date_usec); extern char *irc_protocol_string_params (const char **params, int arg_start, int arg_end); extern char *irc_protocol_cap_to_enable (const char *capabilities, @@ -89,6 +92,14 @@ extern char *irc_protocol_cap_to_enable (const char *capabilities, __extra_tags)); \ } +#define WEE_CHECK_PARSE_TIME(__result_date, __result_date_usec, \ + __time) \ + date = 1; \ + date_usec = 1; \ + irc_protocol_parse_time (__time, &date, &date_usec); \ + LONGS_EQUAL(__result_date, date); \ + LONGS_EQUAL(__result_date_usec, date_usec); + #define WEE_CHECK_CAP_TO_ENABLE(__result, __string, __sasl_requested) \ str = irc_protocol_cap_to_enable (__string, __sasl_requested); \ STRCMP_EQUAL(__result, str); \ @@ -589,25 +600,36 @@ TEST(IrcProtocolWithServer, Tags) TEST(IrcProtocol, ParseTime) { + time_t date; + int date_usec; + /* invalid time formats */ - LONGS_EQUAL(0, irc_protocol_parse_time (NULL)); - LONGS_EQUAL(0, irc_protocol_parse_time ("")); - LONGS_EQUAL(0, irc_protocol_parse_time ("invalid")); + WEE_CHECK_PARSE_TIME(0, 0, NULL); + WEE_CHECK_PARSE_TIME(0, 0, ""); + WEE_CHECK_PARSE_TIME(0, 0, "invalid"); /* incomplete time formats */ - LONGS_EQUAL(0, irc_protocol_parse_time ("2019-01")); - LONGS_EQUAL(0, irc_protocol_parse_time ("2019-01-13")); - LONGS_EQUAL(0, irc_protocol_parse_time ("2019-01-13T14")); - LONGS_EQUAL(0, irc_protocol_parse_time ("2019-01-13T14:37")); + WEE_CHECK_PARSE_TIME(0, 0, "2019-01"); + WEE_CHECK_PARSE_TIME(0, 0, "2019-01-13"); + WEE_CHECK_PARSE_TIME(0, 0, "2019-01-13T14"); + WEE_CHECK_PARSE_TIME(0, 0, "2019-01-13T14:37"); /* valid time with ISO 8601 format*/ - LONGS_EQUAL(1547386699, irc_protocol_parse_time ("2019-01-13T13:38:19.123Z")); - LONGS_EQUAL(1547386699, irc_protocol_parse_time ("2019-01-13T13:38:19.123")); - LONGS_EQUAL(1547386699, irc_protocol_parse_time ("2019-01-13T13:38:19")); + WEE_CHECK_PARSE_TIME(1547386699, 0, "2019-01-13T13:38:19"); + WEE_CHECK_PARSE_TIME(1547386699, 0, "2019-01-13T13:38:19Z"); + WEE_CHECK_PARSE_TIME(1547386699, 123, "2019-01-13T13:38:19.000123"); + WEE_CHECK_PARSE_TIME(1547386699, 123, "2019-01-13T13:38:19.000123Z"); + WEE_CHECK_PARSE_TIME(1547386699, 123000, "2019-01-13T13:38:19.123"); + WEE_CHECK_PARSE_TIME(1547386699, 123000, "2019-01-13T13:38:19.123Z"); + WEE_CHECK_PARSE_TIME(1547386699, 123456, "2019-01-13T13:38:19.123456"); + WEE_CHECK_PARSE_TIME(1547386699, 123456, "2019-01-13T13:38:19.123456789"); /* valid time as timestamp */ - LONGS_EQUAL(1547386699, irc_protocol_parse_time ("1547386699.123")); - LONGS_EQUAL(1547386699, irc_protocol_parse_time ("1547386699")); + WEE_CHECK_PARSE_TIME(1547386699, 0, "1547386699"); + WEE_CHECK_PARSE_TIME(1547386699, 123, "1547386699.000123"); + WEE_CHECK_PARSE_TIME(1547386699, 123000, "1547386699.123"); + WEE_CHECK_PARSE_TIME(1547386699, 123456, "1547386699.123456"); + WEE_CHECK_PARSE_TIME(1547386699, 123456, "1547386699.123456789"); } /* |