summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/en/weechat_dev.en.adoc1
-rw-r--r--doc/fr/weechat_dev.fr.adoc1
-rw-r--r--doc/ja/weechat_dev.ja.adoc2
-rw-r--r--doc/sr/weechat_dev.sr.adoc1
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/tests.cpp1
-rw-r--r--tests/unit/core/hook/test-hook-modifier.cpp294
-rw-r--r--tests/unit/core/test-core-hook.cpp208
8 files changed, 301 insertions, 208 deletions
diff --git a/doc/en/weechat_dev.en.adoc b/doc/en/weechat_dev.en.adoc
index 86c5561cc..a2161826b 100644
--- a/doc/en/weechat_dev.en.adoc
+++ b/doc/en/weechat_dev.en.adoc
@@ -437,6 +437,7 @@ WeeChat "core" is located in following directories:
|          test-core-sys.cpp | Tests: system functions.
|          hook/ | Root of unit tests for hooks.
|             test-hook-command.cpp | Tests: hooks "command".
+|             test-hook-modifier.cpp | Tests: hooks "modifier".
|       gui/ | Root of unit tests for interfaces.
|          test-gui-bar-window.cpp | Tests: bar window functions.
|          test-gui-buffer.cpp | Tests: buffer functions.
diff --git a/doc/fr/weechat_dev.fr.adoc b/doc/fr/weechat_dev.fr.adoc
index 51f8f9415..422d4eab3 100644
--- a/doc/fr/weechat_dev.fr.adoc
+++ b/doc/fr/weechat_dev.fr.adoc
@@ -439,6 +439,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants :
|          test-core-sys.cpp | Tests : fonctions système.
|          hook/ | Racine des tests pour les hooks.
|             test-hook-command.cpp | Tests : hooks "command".
+|             test-hook-modifier.cpp | Tests : hooks "modifier".
|       gui/ | Racine des tests unitaires pour les interfaces.
|          test-gui-bar-window.cpp | Tests : fonctions de fenêtres de barre.
|          test-gui-buffer.cpp | Tests : fonctions de tampons.
diff --git a/doc/ja/weechat_dev.ja.adoc b/doc/ja/weechat_dev.ja.adoc
index 6c054b398..8736ede6f 100644
--- a/doc/ja/weechat_dev.ja.adoc
+++ b/doc/ja/weechat_dev.ja.adoc
@@ -487,6 +487,8 @@ WeeChat "core" は以下のディレクトリに配置されています:
|          hook/ | Root of unit tests for hooks.
// TRANSLATION MISSING
|             test-hook-command.cpp | Tests: hooks "command".
+// TRANSLATION MISSING
+|             test-hook-modifier.cpp | Tests: hooks "modifier".
|       gui/ | インターフェースの単体テストを収める最上位ディレクトリ
// TRANSLATION MISSING
|          test-gui-bar-window.cpp | Tests: bar window functions.
diff --git a/doc/sr/weechat_dev.sr.adoc b/doc/sr/weechat_dev.sr.adoc
index fd0df161b..d1a1aa187 100644
--- a/doc/sr/weechat_dev.sr.adoc
+++ b/doc/sr/weechat_dev.sr.adoc
@@ -443,6 +443,7 @@ WeeChat „језгро” се налази у следећим директо
|          test-core-sys.cpp | Тестови: системске функције.
|          hook/ | Корен unit тестова за куке.
|             test-hook-command.cpp | Тестови: куке „command”.
+|             test-hook-modifier.cpp | Тестови: куке „modifier”.
|       gui/ | Корен unit тестова интерфејса.
|          test-gui-bar-window.cpp | Тестови: функције прозора траке.
|          test-gui-buffer.cpp | Тестови: бафер функције.
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 28e818fbb..ecb1b9632 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -70,6 +70,7 @@ set(LIB_WEECHAT_UNIT_TESTS_CORE_SRC
unit/core/test-core-util.cpp
unit/core/test-core-sys.cpp
unit/core/hook/test-hook-command.cpp
+ unit/core/hook/test-hook-modifier.cpp
unit/gui/test-gui-bar.cpp
unit/gui/test-gui-bar-item.cpp
unit/gui/test-gui-bar-item-custom.cpp
diff --git a/tests/tests.cpp b/tests/tests.cpp
index f0e801323..1702d702b 100644
--- a/tests/tests.cpp
+++ b/tests/tests.cpp
@@ -80,6 +80,7 @@ IMPORT_TEST_GROUP(CoreUtil);
IMPORT_TEST_GROUP(CoreSys);
/* core/hook */
IMPORT_TEST_GROUP(HookCommand);
+IMPORT_TEST_GROUP(HookModifier);
/* GUI */
IMPORT_TEST_GROUP(GuiBar);
IMPORT_TEST_GROUP(GuiBarItem);
diff --git a/tests/unit/core/hook/test-hook-modifier.cpp b/tests/unit/core/hook/test-hook-modifier.cpp
new file mode 100644
index 000000000..72e080c8f
--- /dev/null
+++ b/tests/unit/core/hook/test-hook-modifier.cpp
@@ -0,0 +1,294 @@
+/*
+ * test-hook-modifier.cpp - test hook modifier functions
+ *
+ * Copyright (C) 2018-2024 Sébastien Helleu <flashcode@flashtux.org>
+ *
+ * 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 <https://www.gnu.org/licenses/>.
+ */
+
+#include "CppUTest/TestHarness.h"
+
+#include "tests/tests.h"
+
+extern "C"
+{
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "src/core/weechat.h"
+#include "src/core/core-string.h"
+#include "src/core/core-hook.h"
+#include "src/gui/gui-buffer.h"
+#include "src/gui/gui-chat.h"
+#include "src/gui/gui-line.h"
+#include "src/plugins/plugin.h"
+}
+
+#define TEST_BUFFER_NAME "test"
+
+TEST_GROUP(HookModifier)
+{
+};
+
+/*
+ * Tests functions:
+ * hook_modifier_get_description
+ */
+
+TEST(HookModifier, GetDescription)
+{
+ /* TODO: write tests */
+}
+
+char *
+test_modifier_cb (const void *pointer, void *data,
+ const char *modifier, const char *modifier_data,
+ const char *string)
+{
+ char **items, *new_string;
+ const char *ptr_plugin, *ptr_tags, *ptr_msg;
+ int num_items, length, rc;
+ struct t_gui_buffer *ptr_buffer;
+
+ /* make C++ compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) modifier;
+
+ new_string = NULL;
+
+ /* split modifier_data, which is: "buffer_pointer;tags" */
+ items = string_split (modifier_data, ";", NULL,
+ WEECHAT_STRING_SPLIT_STRIP_LEFT
+ | WEECHAT_STRING_SPLIT_STRIP_RIGHT
+ | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
+ 2, &num_items);
+ if (!items || (num_items < 1))
+ goto error;
+
+ ptr_tags = (num_items >= 2) ? items[1] : NULL;
+
+ rc = sscanf (items[0], "%p", &ptr_buffer);
+ if ((rc == EOF) || (rc == 0))
+ goto error;
+
+ ptr_plugin = gui_buffer_get_plugin_name (ptr_buffer);
+ if (!ptr_plugin)
+ goto error;
+
+ /* do nothing on a buffer different from "core.test" */
+ if ((strcmp (ptr_plugin, "core") != 0)
+ || (strcmp (ptr_buffer->name, TEST_BUFFER_NAME) != 0))
+ {
+ goto error;
+ }
+
+ if (strncmp (string, "\t\t", 2) == 0)
+ {
+ ptr_msg = string + 2;
+ }
+ else
+ {
+ ptr_msg = strchr (string, '\t');
+ if (!ptr_msg)
+ goto error;
+ ptr_msg++;
+ }
+
+ length = strlen (string) + 128;
+ new_string = (char *)malloc (length);
+ if (!new_string)
+ goto error;
+ new_string[0] = '\0';
+
+ if (ptr_tags && strstr (ptr_tags, "add_prefix"))
+ {
+ /* add a prefix in message */
+ snprintf (new_string, length, "new prefix\t%s (modified)", ptr_msg);
+ }
+ else if (ptr_tags && strstr (ptr_tags, "add_date_prefix"))
+ {
+ /* add a date/prefix in message */
+ snprintf (new_string, length, "new prefix\t%s (modified)", ptr_msg);
+ }
+ else if (ptr_tags && strstr (ptr_tags, "update_prefix"))
+ {
+ /* update the prefix */
+ snprintf (new_string, length, "new prefix\t%s (modified)", ptr_msg);
+ }
+ else if (ptr_tags && strstr (ptr_tags, "remove_prefix"))
+ {
+ /* remove the prefix */
+ snprintf (new_string, length, " \t%s (modified)", ptr_msg);
+ }
+ else if (ptr_tags && strstr (ptr_tags, "remove_date_prefix"))
+ {
+ /* remove the date/prefix */
+ snprintf (new_string, length, "\t\t%s (modified)", ptr_msg);
+ }
+
+ if (!new_string[0])
+ {
+ /* default message returned: just add " (modified)" to the string */
+ snprintf (new_string, length, "%s (modified)", string);
+ }
+
+ return new_string;
+
+error:
+ if (items)
+ string_free_split (items);
+ if (new_string)
+ free (new_string);
+ return NULL;
+}
+
+/*
+ * Tests functions:
+ * hook_modifier
+ */
+
+TEST(HookModifier, Modifier)
+{
+ struct t_gui_buffer *test_buffer;
+ struct t_gui_line *ptr_line;
+ struct t_hook *hook;
+
+ /* create/open a test buffer */
+ test_buffer = gui_buffer_new (NULL, TEST_BUFFER_NAME,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL);
+ CHECK(test_buffer);
+
+ hook = hook_modifier (NULL, "weechat_print", &test_modifier_cb, NULL, NULL);
+
+ /* check hook contents */
+ CHECK(hook);
+ POINTERS_EQUAL(NULL, hook->plugin);
+ POINTERS_EQUAL(NULL, hook->subplugin);
+ LONGS_EQUAL(HOOK_TYPE_MODIFIER, hook->type);
+ LONGS_EQUAL(0, hook->deleted);
+ LONGS_EQUAL(0, hook->running);
+ LONGS_EQUAL(HOOK_PRIORITY_DEFAULT, hook->priority);
+ POINTERS_EQUAL(NULL, hook->callback_pointer);
+ POINTERS_EQUAL(NULL, hook->callback_data);
+ CHECK(hook->hook_data);
+ POINTERS_EQUAL(&test_modifier_cb, HOOK_MODIFIER(hook, callback));
+ STRCMP_EQUAL("weechat_print", HOOK_MODIFIER(hook, modifier));
+
+ /* message without prefix: unchanged */
+ gui_chat_printf_date_tags (test_buffer, 0, NULL, " \tmessage");
+ ptr_line = test_buffer->own_lines->last_line;
+ CHECK(ptr_line->data->date > 0);
+ STRCMP_EQUAL("", ptr_line->data->prefix);
+ STRCMP_EQUAL("message (modified)", ptr_line->data->message);
+
+ /* message without prefix: add a prefix */
+ gui_chat_printf_date_tags (test_buffer, 0, "add_prefix", " \tmessage");
+ ptr_line = test_buffer->own_lines->last_line;
+ CHECK(ptr_line->data->date > 0);
+ STRCMP_EQUAL("new prefix", ptr_line->data->prefix);
+ STRCMP_EQUAL("message (modified)", ptr_line->data->message);
+
+ /* message without date: unchanged */
+ gui_chat_printf_date_tags (test_buffer, 0, NULL, "\t\tmessage");
+ ptr_line = test_buffer->own_lines->last_line;
+ LONGS_EQUAL(0, ptr_line->data->date);
+ POINTERS_EQUAL(NULL, ptr_line->data->prefix);
+ STRCMP_EQUAL("message (modified)", ptr_line->data->message);
+
+ /* message without date: add a date/prefix */
+ gui_chat_printf_date_tags (test_buffer, 0, "add_date_prefix",
+ "\t\tmessage");
+ ptr_line = test_buffer->own_lines->last_line;
+ CHECK(ptr_line->data->date > 0);
+ STRCMP_EQUAL("new prefix", ptr_line->data->prefix);
+ STRCMP_EQUAL("message (modified)", ptr_line->data->message);
+
+ /* standard message: unchanged */
+ gui_chat_printf_date_tags (test_buffer, 0, NULL, "prefix\tmessage");
+ ptr_line = test_buffer->own_lines->last_line;
+ CHECK(ptr_line->data->date > 0);
+ STRCMP_EQUAL("prefix", ptr_line->data->prefix);
+ STRCMP_EQUAL("message (modified)", ptr_line->data->message);
+
+ /* standard message: update the prefix */
+ gui_chat_printf_date_tags (test_buffer, 0, "update_prefix",
+ "prefix\tmessage");
+ ptr_line = test_buffer->own_lines->last_line;
+ CHECK(ptr_line->data->date > 0);
+ STRCMP_EQUAL("new prefix", ptr_line->data->prefix);
+ STRCMP_EQUAL("message (modified)", ptr_line->data->message);
+
+ /* standard message: remove the prefix */
+ gui_chat_printf_date_tags (test_buffer, 0, "remove_prefix",
+ "prefix\tmessage");
+ ptr_line = test_buffer->own_lines->last_line;
+ CHECK(ptr_line->data->date > 0);
+ STRCMP_EQUAL("", ptr_line->data->prefix);
+ STRCMP_EQUAL("message (modified)", ptr_line->data->message);
+
+ /* standard message: remove the date/prefix */
+ gui_chat_printf_date_tags (test_buffer, 0, "remove_date_prefix",
+ "prefix\tmessage");
+ ptr_line = test_buffer->own_lines->last_line;
+ LONGS_EQUAL(0, ptr_line->data->date);
+ POINTERS_EQUAL(NULL, ptr_line->data->prefix);
+ STRCMP_EQUAL("message (modified)", ptr_line->data->message);
+
+ /* close the test buffer */
+ gui_buffer_close (test_buffer);
+}
+
+/*
+ * Tests functions:
+ * hook_modifier_exec
+ */
+
+TEST(HookModifier, Exec)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * hook_modifier_free_data
+ */
+
+TEST(HookModifier, FreeData)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * hook_modifier_add_to_infolist
+ */
+
+TEST(HookModifier, AddToInfolist)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * hook_modifier_print_log
+ */
+
+TEST(HookModifier, PrintLog)
+{
+ /* TODO: write tests */
+}
diff --git a/tests/unit/core/test-core-hook.cpp b/tests/unit/core/test-core-hook.cpp
index 2416591cd..1d07da30f 100644
--- a/tests/unit/core/test-core-hook.cpp
+++ b/tests/unit/core/test-core-hook.cpp
@@ -23,17 +23,8 @@
extern "C"
{
-#include <string.h>
-#include "src/core/core-hook.h"
-#include "src/core/core-string.h"
-#include "src/gui/gui-buffer.h"
-#include "src/gui/gui-chat.h"
-#include "src/gui/gui-line.h"
-#include "src/plugins/plugin.h"
}
-#define TEST_BUFFER_NAME "test"
-
TEST_GROUP(CoreHook)
{
};
@@ -168,205 +159,6 @@ TEST(CoreHook, Line)
/* TODO: write tests */
}
-char *
-test_modifier_cb (const void *pointer, void *data,
- const char *modifier, const char *modifier_data,
- const char *string)
-{
- char **items, *new_string;
- const char *ptr_plugin, *ptr_tags, *ptr_msg;
- int num_items, length, rc;
- struct t_gui_buffer *ptr_buffer;
-
- /* make C++ compiler happy */
- (void) pointer;
- (void) data;
- (void) modifier;
-
- new_string = NULL;
-
- /* split modifier_data, which is: "buffer_pointer;tags" */
- items = string_split (modifier_data, ";", NULL,
- WEECHAT_STRING_SPLIT_STRIP_LEFT
- | WEECHAT_STRING_SPLIT_STRIP_RIGHT
- | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
- 2, &num_items);
- if (!items || (num_items < 1))
- goto error;
-
- ptr_tags = (num_items >= 2) ? items[1] : NULL;
-
- rc = sscanf (items[0], "%p", &ptr_buffer);
- if ((rc == EOF) || (rc == 0))
- goto error;
-
- ptr_plugin = gui_buffer_get_plugin_name (ptr_buffer);
- if (!ptr_plugin)
- goto error;
-
- /* do nothing on a buffer different from "core.test" */
- if ((strcmp (ptr_plugin, "core") != 0)
- || (strcmp (ptr_buffer->name, TEST_BUFFER_NAME) != 0))
- {
- goto error;
- }
-
- if (strncmp (string, "\t\t", 2) == 0)
- {
- ptr_msg = string + 2;
- }
- else
- {
- ptr_msg = strchr (string, '\t');
- if (!ptr_msg)
- goto error;
- ptr_msg++;
- }
-
- length = strlen (string) + 128;
- new_string = (char *)malloc (length);
- if (!new_string)
- goto error;
- new_string[0] = '\0';
-
- if (ptr_tags && strstr (ptr_tags, "add_prefix"))
- {
- /* add a prefix in message */
- snprintf (new_string, length, "new prefix\t%s (modified)", ptr_msg);
- }
- else if (ptr_tags && strstr (ptr_tags, "add_date_prefix"))
- {
- /* add a date/prefix in message */
- snprintf (new_string, length, "new prefix\t%s (modified)", ptr_msg);
- }
- else if (ptr_tags && strstr (ptr_tags, "update_prefix"))
- {
- /* update the prefix */
- snprintf (new_string, length, "new prefix\t%s (modified)", ptr_msg);
- }
- else if (ptr_tags && strstr (ptr_tags, "remove_prefix"))
- {
- /* remove the prefix */
- snprintf (new_string, length, " \t%s (modified)", ptr_msg);
- }
- else if (ptr_tags && strstr (ptr_tags, "remove_date_prefix"))
- {
- /* remove the date/prefix */
- snprintf (new_string, length, "\t\t%s (modified)", ptr_msg);
- }
-
- if (!new_string[0])
- {
- /* default message returned: just add " (modified)" to the string */
- snprintf (new_string, length, "%s (modified)", string);
- }
-
- return new_string;
-
-error:
- if (items)
- string_free_split (items);
- if (new_string)
- free (new_string);
- return NULL;
-}
-
-/*
- * Tests functions:
- * hook_modifier
- */
-
-TEST(CoreHook, Modifier)
-{
- struct t_gui_buffer *test_buffer;
- struct t_gui_line *ptr_line;
- struct t_hook *hook;
-
- /* create/open a test buffer */
- test_buffer = gui_buffer_new (NULL, TEST_BUFFER_NAME,
- NULL, NULL, NULL,
- NULL, NULL, NULL);
- CHECK(test_buffer);
-
- hook = hook_modifier (NULL, "weechat_print", &test_modifier_cb, NULL, NULL);
-
- /* check hook contents */
- CHECK(hook);
- POINTERS_EQUAL(NULL, hook->plugin);
- POINTERS_EQUAL(NULL, hook->subplugin);
- LONGS_EQUAL(HOOK_TYPE_MODIFIER, hook->type);
- LONGS_EQUAL(0, hook->deleted);
- LONGS_EQUAL(0, hook->running);
- LONGS_EQUAL(HOOK_PRIORITY_DEFAULT, hook->priority);
- POINTERS_EQUAL(NULL, hook->callback_pointer);
- POINTERS_EQUAL(NULL, hook->callback_data);
- CHECK(hook->hook_data);
- POINTERS_EQUAL(&test_modifier_cb, HOOK_MODIFIER(hook, callback));
- STRCMP_EQUAL("weechat_print", HOOK_MODIFIER(hook, modifier));
-
- /* message without prefix: unchanged */
- gui_chat_printf_date_tags (test_buffer, 0, NULL, " \tmessage");
- ptr_line = test_buffer->own_lines->last_line;
- CHECK(ptr_line->data->date > 0);
- STRCMP_EQUAL("", ptr_line->data->prefix);
- STRCMP_EQUAL("message (modified)", ptr_line->data->message);
-
- /* message without prefix: add a prefix */
- gui_chat_printf_date_tags (test_buffer, 0, "add_prefix", " \tmessage");
- ptr_line = test_buffer->own_lines->last_line;
- CHECK(ptr_line->data->date > 0);
- STRCMP_EQUAL("new prefix", ptr_line->data->prefix);
- STRCMP_EQUAL("message (modified)", ptr_line->data->message);
-
- /* message without date: unchanged */
- gui_chat_printf_date_tags (test_buffer, 0, NULL, "\t\tmessage");
- ptr_line = test_buffer->own_lines->last_line;
- LONGS_EQUAL(0, ptr_line->data->date);
- POINTERS_EQUAL(NULL, ptr_line->data->prefix);
- STRCMP_EQUAL("message (modified)", ptr_line->data->message);
-
- /* message without date: add a date/prefix */
- gui_chat_printf_date_tags (test_buffer, 0, "add_date_prefix",
- "\t\tmessage");
- ptr_line = test_buffer->own_lines->last_line;
- CHECK(ptr_line->data->date > 0);
- STRCMP_EQUAL("new prefix", ptr_line->data->prefix);
- STRCMP_EQUAL("message (modified)", ptr_line->data->message);
-
- /* standard message: unchanged */
- gui_chat_printf_date_tags (test_buffer, 0, NULL, "prefix\tmessage");
- ptr_line = test_buffer->own_lines->last_line;
- CHECK(ptr_line->data->date > 0);
- STRCMP_EQUAL("prefix", ptr_line->data->prefix);
- STRCMP_EQUAL("message (modified)", ptr_line->data->message);
-
- /* standard message: update the prefix */
- gui_chat_printf_date_tags (test_buffer, 0, "update_prefix",
- "prefix\tmessage");
- ptr_line = test_buffer->own_lines->last_line;
- CHECK(ptr_line->data->date > 0);
- STRCMP_EQUAL("new prefix", ptr_line->data->prefix);
- STRCMP_EQUAL("message (modified)", ptr_line->data->message);
-
- /* standard message: remove the prefix */
- gui_chat_printf_date_tags (test_buffer, 0, "remove_prefix",
- "prefix\tmessage");
- ptr_line = test_buffer->own_lines->last_line;
- CHECK(ptr_line->data->date > 0);
- STRCMP_EQUAL("", ptr_line->data->prefix);
- STRCMP_EQUAL("message (modified)", ptr_line->data->message);
-
- /* standard message: remove the date/prefix */
- gui_chat_printf_date_tags (test_buffer, 0, "remove_date_prefix",
- "prefix\tmessage");
- ptr_line = test_buffer->own_lines->last_line;
- LONGS_EQUAL(0, ptr_line->data->date);
- POINTERS_EQUAL(NULL, ptr_line->data->prefix);
- STRCMP_EQUAL("message (modified)", ptr_line->data->message);
-
- /* close the test buffer */
- gui_buffer_close (test_buffer);
-}
/*
* Tests functions: