summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/plugins/logger/test-logger-backlog.cpp103
-rw-r--r--tests/unit/plugins/logger/test-logger-tail.cpp3
2 files changed, 105 insertions, 1 deletions
diff --git a/tests/unit/plugins/logger/test-logger-backlog.cpp b/tests/unit/plugins/logger/test-logger-backlog.cpp
index b399e3d46..b4925ab37 100644
--- a/tests/unit/plugins/logger/test-logger-backlog.cpp
+++ b/tests/unit/plugins/logger/test-logger-backlog.cpp
@@ -26,6 +26,7 @@
extern "C"
{
#include <stdio.h>
+#include "src/core/wee-arraylist.h"
#include "src/core/wee-config.h"
#include "src/gui/gui-buffer.h"
#include "src/gui/gui-color.h"
@@ -34,6 +35,7 @@ extern "C"
extern void logger_backlog_display_line (struct t_gui_buffer *buffer,
const char *line);
+extern struct t_arraylist *logger_backlog_group_messages (struct t_arraylist *lines);
}
TEST_GROUP(LoggerBacklog)
@@ -146,6 +148,107 @@ TEST(LoggerBacklog, DisplayLine)
}
/*
+ * Compares two messages in arraylist.
+ */
+
+int
+test_logger_backlog_msg_cmp_cb (void *data,
+ struct t_arraylist *arraylist,
+ void *pointer1,
+ void *pointer2)
+{
+ /* make C compiler happy */
+ (void) data;
+ (void) arraylist;
+
+ return strcmp ((const char *)pointer1, (const char *)pointer2);
+}
+
+/*
+ * Frees a message in arraylist.
+ */
+
+void
+test_logger_backlog_msg_free_cb (void *data, struct t_arraylist *arraylist,
+ void *pointer)
+{
+ /* make C compiler happy */
+ (void) data;
+ (void) arraylist;
+
+ free (pointer);
+}
+
+/*
+ * Tests functions:
+ * logger_backlog_msg_cmp_cb
+ * logger_backlog_msg_free_cb
+ * logger_backlog_group_messages
+ */
+
+TEST(LoggerBacklog, GroupMessages)
+{
+ struct t_arraylist *lines, *messages;
+ const char *test_lines_1[] = {
+ "2023-06-04 21:15:34\t\tMessage 1",
+ "2023-06-04 21:15:40\t\tMessage 2",
+ NULL,
+ };
+ const char *test_lines_2[] = {
+ "end of line",
+ "2023-06-04 21:15:34\t\tFirst line",
+ "of multiline message",
+ "end of message",
+ "2023-06-04 21:15:40\t\tMessage on one line",
+ NULL,
+ };
+ int i;
+
+ POINTERS_EQUAL(NULL, logger_backlog_group_messages (NULL));
+
+ lines = arraylist_new (3, 0, 1,
+ &test_logger_backlog_msg_cmp_cb, NULL,
+ &test_logger_backlog_msg_free_cb, NULL);
+
+ for (i = 0; test_lines_1[i]; i++)
+ {
+ arraylist_add (lines, strdup (test_lines_1[i]));
+ }
+
+ messages = logger_backlog_group_messages (lines);
+ CHECK(messages);
+ LONGS_EQUAL(2, arraylist_size (messages));
+ STRCMP_EQUAL("2023-06-04 21:15:34\t\tMessage 1",
+ (const char *)arraylist_get (messages, 0));
+ STRCMP_EQUAL("2023-06-04 21:15:40\t\tMessage 2",
+ (const char *)arraylist_get (messages, 1));
+ arraylist_free (messages);
+
+ arraylist_clear (lines);
+
+ for (i = 0; test_lines_2[i]; i++)
+ {
+ arraylist_add (lines, strdup (test_lines_2[i]));
+ }
+
+ messages = logger_backlog_group_messages (lines);
+ CHECK(messages);
+ LONGS_EQUAL(3, arraylist_size (messages));
+ STRCMP_EQUAL("end of line",
+ (const char *)arraylist_get (messages, 0));
+ STRCMP_EQUAL("2023-06-04 21:15:34\t\tFirst line\n"
+ "of multiline message\n"
+ "end of message",
+ (const char *)arraylist_get (messages, 1));
+ STRCMP_EQUAL("2023-06-04 21:15:40\t\tMessage on one line",
+ (const char *)arraylist_get (messages, 2));
+ arraylist_free (messages);
+
+
+ arraylist_free (lines);
+}
+
+/*
* Tests functions:
* logger_backlog_file
*/
diff --git a/tests/unit/plugins/logger/test-logger-tail.cpp b/tests/unit/plugins/logger/test-logger-tail.cpp
index c4f35f378..68f9176b5 100644
--- a/tests/unit/plugins/logger/test-logger-tail.cpp
+++ b/tests/unit/plugins/logger/test-logger-tail.cpp
@@ -71,8 +71,9 @@ TEST(LoggerTail, LoggerTailLastEol)
/*
* Tests functions:
+ * logger_tail_lines_cmp_cb
+ * logger_tail_lines_free_cb
* logger_tail_file
- * logger_tail_free
*/
TEST(LoggerTail, LoggerTailFile)