diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dc0e7bc57..a90149e0e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -70,6 +70,12 @@ if(ENABLE_IRC) ) endif() +if(ENABLE_LOGGER) + list(APPEND LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC + unit/plugins/logger/test-logger-backlog.cpp + ) +endif() + if (ENABLE_RELAY) list(APPEND LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC unit/plugins/relay/test-relay-auth.cpp diff --git a/tests/Makefile.am b/tests/Makefile.am index 0519fa31a..9d4f7650a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -84,6 +84,10 @@ tests_irc = unit/plugins/irc/test-irc-buffer.cpp \ unit/plugins/irc/test-irc-tag.cpp endif +if PLUGIN_LOGGER +tests_logger = unit/plugins/logger/test-logger-backlog.cpp +endif + if PLUGIN_RELAY tests_relay = unit/plugins/relay/test-relay-auth.cpp endif @@ -100,6 +104,7 @@ endif lib_weechat_unit_tests_plugins_la_SOURCES = unit/plugins/test-plugins.cpp \ $(tests_irc) \ + $(tests_logger) \ $(tests_relay) \ $(tests_trigger) \ $(tests_typing) diff --git a/tests/unit/plugins/logger/test-logger-backlog.cpp b/tests/unit/plugins/logger/test-logger-backlog.cpp new file mode 100644 index 000000000..2139f5f99 --- /dev/null +++ b/tests/unit/plugins/logger/test-logger-backlog.cpp @@ -0,0 +1,177 @@ +/* + * test-logger-backlog.cpp - test logger backlog functions + * + * Copyright (C) 2022 Sébastien Helleu + * + * This file is part of WeeChat, the extensible chat client. + * + * WeeChat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * WeeChat is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WeeChat. If not, see . + */ + +#include "CppUTest/TestHarness.h" + +extern "C" +{ +#include +#include "src/core/wee-config.h" +#include "src/gui/gui-buffer.h" +#include "src/gui/gui-color.h" +#include "src/gui/gui-line.h" +#include "src/plugins/logger/logger-config.h" + +extern void logger_backlog_display_line (struct t_gui_buffer *buffer, + const char *line); +} + +#include "tests/tests.h" + + +TEST_GROUP(LoggerBacklog) +{ +}; + +/* + * Tests functions: + * logger_backlog_check_conditions + */ + +TEST(LoggerBacklog, CheckConditions) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_backlog_display_line + */ + +TEST(LoggerBacklog, DisplayLine) +{ + char str_line[1024], string[1024]; + struct t_gui_line *ptr_line; + struct t_gui_line_data *ptr_data; + + ptr_line = gui_buffers->own_lines->last_line; + logger_backlog_display_line (gui_buffers, NULL); + POINTERS_EQUAL(ptr_line, gui_buffers->own_lines->last_line); + + /* empty string */ + logger_backlog_display_line (gui_buffers, ""); + ptr_data = gui_buffers->own_lines->last_line->data; + CHECK(ptr_data->date != 1645288340); + CHECK(ptr_data->date == ptr_data->date_printed); + LONGS_EQUAL(3, ptr_data->tags_count); + STRCMP_EQUAL("no_highlight", ptr_data->tags_array[0]); + STRCMP_EQUAL("notify_none", ptr_data->tags_array[1]); + STRCMP_EQUAL("logger_backlog", ptr_data->tags_array[2]); + STRCMP_EQUAL("", ptr_data->prefix); + snprintf (string, sizeof (string), + "%s", + gui_color_get_custom ( + gui_color_get_name ( + CONFIG_COLOR(logger_config_color_backlog_line)))); + STRCMP_EQUAL(string, ptr_data->message); + + /* invalid date */ + snprintf (str_line, sizeof (str_line), + "invalid date\tnick\tthe message"); + logger_backlog_display_line (gui_buffers, str_line); + ptr_data = gui_buffers->own_lines->last_line->data; + CHECK(ptr_data->date != 1645288340); + CHECK(ptr_data->date == ptr_data->date_printed); + LONGS_EQUAL(3, ptr_data->tags_count); + STRCMP_EQUAL("no_highlight", ptr_data->tags_array[0]); + STRCMP_EQUAL("notify_none", ptr_data->tags_array[1]); + STRCMP_EQUAL("logger_backlog", ptr_data->tags_array[2]); + snprintf (string, sizeof (string), + "%sinvalid date", + gui_color_get_custom ( + gui_color_get_name ( + CONFIG_COLOR(logger_config_color_backlog_line)))); + STRCMP_EQUAL(string, ptr_data->prefix); + snprintf (string, sizeof (string), + "%snick\tthe message", + gui_color_get_custom ( + gui_color_get_name ( + CONFIG_COLOR(logger_config_color_backlog_line)))); + STRCMP_EQUAL(string, ptr_data->message); + + /* valid line */ + snprintf (str_line, sizeof (str_line), + "2022-02-19 16:32:20\tnick\tthe message"); + logger_backlog_display_line (gui_buffers, str_line); + ptr_data = gui_buffers->own_lines->last_line->data; + LONGS_EQUAL(1645288340, ptr_data->date); + CHECK(ptr_data->date_printed > 1645288340); + LONGS_EQUAL(3, ptr_data->tags_count); + STRCMP_EQUAL("no_highlight", ptr_data->tags_array[0]); + STRCMP_EQUAL("notify_none", ptr_data->tags_array[1]); + STRCMP_EQUAL("logger_backlog", ptr_data->tags_array[2]); + snprintf (string, sizeof (string), + "%snick", + gui_color_get_custom ( + gui_color_get_name ( + CONFIG_COLOR(logger_config_color_backlog_line)))); + STRCMP_EQUAL(string, ptr_data->prefix); + snprintf (string, sizeof (string), + "%sthe message", + gui_color_get_custom ( + gui_color_get_name ( + CONFIG_COLOR(logger_config_color_backlog_line)))); + STRCMP_EQUAL(string, ptr_data->message); + + /* valid line with Tab in message */ + snprintf (str_line, sizeof (str_line), + "2022-02-19 16:32:21\tnick\tthe message\twith tab"); + logger_backlog_display_line (gui_buffers, str_line); + ptr_data = gui_buffers->own_lines->last_line->data; + LONGS_EQUAL(1645288341, ptr_data->date); + CHECK(ptr_data->date_printed > 1645288341); + LONGS_EQUAL(3, ptr_data->tags_count); + STRCMP_EQUAL("no_highlight", ptr_data->tags_array[0]); + STRCMP_EQUAL("notify_none", ptr_data->tags_array[1]); + STRCMP_EQUAL("logger_backlog", ptr_data->tags_array[2]); + snprintf (string, sizeof (string), + "%snick", + gui_color_get_custom ( + gui_color_get_name ( + CONFIG_COLOR(logger_config_color_backlog_line)))); + STRCMP_EQUAL(string, ptr_data->prefix); + snprintf (string, sizeof (string), + "%sthe message\twith tab", + gui_color_get_custom ( + gui_color_get_name ( + CONFIG_COLOR(logger_config_color_backlog_line)))); + STRCMP_EQUAL(string, ptr_data->message); +} + +/* + * Tests functions: + * logger_backlog_file + */ + +TEST(LoggerBacklog, File) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * logger_backlog_signal_cb + */ + +TEST(LoggerBacklog, SignalCb) +{ + /* TODO: write tests */ +}