summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-08-18 13:35:36 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-08-18 13:35:36 +0200
commitb756598070e44b207193d43b11231c5eae86c6c0 (patch)
tree81413876b3f2257abefec6f85b6f49bcb0fd763c
parent14334880d81828b262eeb7eacf7417b148eac3c5 (diff)
downloadweechat-b756598070e44b207193d43b11231c5eae86c6c0.zip
tests: add tests on GUI buffer functions
-rw-r--r--ChangeLog.adoc1
-rw-r--r--tests/unit/gui/test-gui-buffer.cpp231
2 files changed, 197 insertions, 35 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index 08b5745bb..f1750c9cb 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -52,6 +52,7 @@ Bug fixes::
Tests::
+ * core: add tests on GUI buffer functions
* irc: fix tests on function irc_join_compare_join_channel (issue #1997)
[[v4.0.3]]
diff --git a/tests/unit/gui/test-gui-buffer.cpp b/tests/unit/gui/test-gui-buffer.cpp
index 66309b9c7..1d9722c83 100644
--- a/tests/unit/gui/test-gui-buffer.cpp
+++ b/tests/unit/gui/test-gui-buffer.cpp
@@ -24,20 +24,29 @@
extern "C"
{
#include <string.h>
+#include "src/core/wee-config.h"
#include "src/core/wee-hashtable.h"
#include "src/core/wee-hook.h"
#include "src/core/wee-input.h"
+#include "src/core/wee-list.h"
#include "src/gui/gui-buffer.h"
#include "src/gui/gui-key.h"
#include "src/gui/gui-line.h"
#include "src/gui/gui-nicklist.h"
#include "src/plugins/plugin.h"
+extern void gui_buffer_local_var_remove_all (struct t_gui_buffer *buffer);
+extern int gui_buffer_notify_get (struct t_gui_buffer *buffer);
extern int gui_buffer_user_input_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
const char *input_data);
extern int gui_buffer_user_close_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer);
+extern void gui_buffer_set_short_name (struct t_gui_buffer *buffer,
+ const char *short_name);
+extern void gui_buffer_set_highlight_words_list (struct t_gui_buffer *buffer,
+ struct t_weelist *list);
+
}
#define TEST_BUFFER_NAME "test"
@@ -145,17 +154,56 @@ TEST(GuiBuffer, SearchNotify)
TEST(GuiBuffer, GetPluginName)
{
- /* TODO: write tests */
+ struct t_gui_buffer *buffer;
+
+ buffer = gui_buffer_new (NULL, TEST_BUFFER_NAME,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL);
+ CHECK(buffer);
+
+ POINTERS_EQUAL(NULL, gui_buffer_get_plugin_name (NULL));
+
+ STRCMP_EQUAL("core", gui_buffer_get_plugin_name (buffer));
+
+ buffer->plugin_name_for_upgrade = strdup ("test");
+ STRCMP_EQUAL("test", gui_buffer_get_plugin_name (buffer));
+
+ gui_buffer_close (buffer);
}
/*
* Tests functions:
* gui_buffer_get_short_name
+ * gui_buffer_set_short_name
*/
-TEST(GuiBuffer, GetShortName)
+TEST(GuiBuffer, GetSetShortName)
{
- /* TODO: write tests */
+ struct t_gui_buffer *buffer;
+
+ buffer = gui_buffer_new (NULL, TEST_BUFFER_NAME,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL);
+ CHECK(buffer);
+
+ POINTERS_EQUAL(NULL, gui_buffer_get_short_name (NULL));
+
+ POINTERS_EQUAL(NULL, buffer->short_name);
+ STRCMP_EQUAL(TEST_BUFFER_NAME, gui_buffer_get_short_name (buffer));
+
+ gui_buffer_set_short_name (buffer, NULL);
+ POINTERS_EQUAL(NULL, buffer->short_name);
+ STRCMP_EQUAL(TEST_BUFFER_NAME, gui_buffer_get_short_name (buffer));
+
+ gui_buffer_set_short_name (buffer, "short");
+ STRCMP_EQUAL("short", buffer->short_name);
+ STRCMP_EQUAL("short", gui_buffer_get_short_name (buffer));
+
+ gui_buffer_set_short_name (buffer, "");
+ POINTERS_EQUAL(NULL, buffer->short_name);
+ STRCMP_EQUAL(TEST_BUFFER_NAME, gui_buffer_get_short_name (buffer));
+
+ gui_buffer_close (buffer);
}
/*
@@ -165,37 +213,77 @@ TEST(GuiBuffer, GetShortName)
TEST(GuiBuffer, BuildFullName)
{
- /* TODO: write tests */
-}
+ struct t_gui_buffer *buffer;
-/*
- * Tests functions:
- * gui_buffer_local_var_add
- */
+ buffer = gui_buffer_new (NULL, TEST_BUFFER_NAME,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL);
+ CHECK(buffer);
-TEST(GuiBuffer, LocalVarAdd)
-{
- /* TODO: write tests */
-}
+ gui_buffer_build_full_name (NULL);
-/*
- * Tests functions:
- * gui_buffer_local_var_remove
- */
+ STRCMP_EQUAL("core." TEST_BUFFER_NAME, buffer->full_name);
-TEST(GuiBuffer, LocalVarRemove)
-{
- /* TODO: write tests */
+ buffer->plugin_name_for_upgrade = strdup ("test");
+ gui_buffer_build_full_name (buffer);
+ STRCMP_EQUAL("test." TEST_BUFFER_NAME, buffer->full_name);
+
+ free (buffer->plugin_name_for_upgrade);
+ buffer->plugin_name_for_upgrade = NULL;
+ gui_buffer_build_full_name (buffer);
+ STRCMP_EQUAL("core." TEST_BUFFER_NAME, buffer->full_name);
+
+ gui_buffer_close (buffer);
}
/*
* Tests functions:
+ * gui_buffer_local_var_add
+ * gui_buffer_local_var_remove
* gui_buffer_local_var_remove_all
*/
-TEST(GuiBuffer, LocalVarRemoveAll)
+TEST(GuiBuffer, LocalVarAddRemove)
{
- /* TODO: write tests */
+ struct t_gui_buffer *buffer;
+
+ buffer = gui_buffer_new (NULL, TEST_BUFFER_NAME,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL);
+ CHECK(buffer);
+
+ gui_buffer_local_var_add (NULL, NULL, NULL);
+
+ STRCMP_EQUAL("plugin:core,name:" TEST_BUFFER_NAME,
+ hashtable_get_string (buffer->local_variables, "keys_values"));
+
+ gui_buffer_local_var_add (buffer, NULL, NULL);
+ STRCMP_EQUAL("plugin:core,name:" TEST_BUFFER_NAME,
+ hashtable_get_string (buffer->local_variables, "keys_values"));
+
+ gui_buffer_local_var_add (buffer, "test_var", NULL);
+ STRCMP_EQUAL("plugin:core,name:" TEST_BUFFER_NAME,
+ hashtable_get_string (buffer->local_variables, "keys_values"));
+
+ gui_buffer_local_var_add (buffer, "test_var", "value");
+ STRCMP_EQUAL("plugin:core,name:" TEST_BUFFER_NAME ",test_var:value",
+ hashtable_get_string (buffer->local_variables, "keys_values"));
+
+ gui_buffer_local_var_remove (buffer, "no_such_var");
+ STRCMP_EQUAL("plugin:core,name:" TEST_BUFFER_NAME ",test_var:value",
+ hashtable_get_string (buffer->local_variables, "keys_values"));
+
+ gui_buffer_local_var_remove (buffer, "test_var");
+ STRCMP_EQUAL("plugin:core,name:" TEST_BUFFER_NAME,
+ hashtable_get_string (buffer->local_variables, "keys_values"));
+
+ gui_buffer_local_var_remove_all (NULL);
+
+ gui_buffer_local_var_remove_all (buffer);
+ POINTERS_EQUAL(NULL,
+ hashtable_get_string (buffer->local_variables, "keys_values"));
+
+ gui_buffer_close (buffer);
}
/*
@@ -205,7 +293,44 @@ TEST(GuiBuffer, LocalVarRemoveAll)
TEST(GuiBuffer, NotifyGet)
{
- /* TODO: write tests */
+ struct t_gui_buffer *buffer;
+ struct t_config_option *ptr_option;
+
+ buffer = gui_buffer_new (NULL, TEST_BUFFER_NAME,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL);
+ CHECK(buffer);
+
+ LONGS_EQUAL(CONFIG_ENUM(config_look_buffer_notify_default),
+ gui_buffer_notify_get (NULL));
+
+ LONGS_EQUAL(CONFIG_ENUM(config_look_buffer_notify_default),
+ gui_buffer_notify_get (buffer));
+
+ config_file_option_set_with_string (
+ "weechat.notify.core." TEST_BUFFER_NAME ".abc",
+ "highlight");
+ LONGS_EQUAL(CONFIG_ENUM(config_look_buffer_notify_default),
+ gui_buffer_notify_get (buffer));
+ config_file_search_with_string ("weechat.notify.core." TEST_BUFFER_NAME ".abc",
+ NULL, NULL, &ptr_option, NULL);
+ config_file_option_unset (ptr_option);
+
+ config_file_option_set_with_string (
+ "weechat.notify.core." TEST_BUFFER_NAME,
+ "highlight");
+ LONGS_EQUAL(GUI_BUFFER_NOTIFY_HIGHLIGHT,gui_buffer_notify_get (buffer));
+ config_file_search_with_string ("weechat.notify.core." TEST_BUFFER_NAME,
+ NULL, NULL, &ptr_option, NULL);
+ config_file_option_unset (ptr_option);
+
+ config_file_option_set_with_string ("weechat.notify.core", "message");
+ LONGS_EQUAL(GUI_BUFFER_NOTIFY_MESSAGE, gui_buffer_notify_get (buffer));
+ config_file_search_with_string ("weechat.notify.core",
+ NULL, NULL, &ptr_option, NULL);
+ config_file_option_unset (ptr_option);
+
+ gui_buffer_close (buffer);
}
/*
@@ -719,16 +844,6 @@ TEST(GuiBuffer, SetName)
/*
* Tests functions:
- * gui_buffer_set_short_name
- */
-
-TEST(GuiBuffer, SetShortName)
-{
- /* TODO: write tests */
-}
-
-/*
- * Tests functions:
* gui_buffer_set_type
*/
@@ -794,7 +909,25 @@ TEST(GuiBuffer, SetNicklistDisplayGroups)
TEST(GuiBuffer, SetHighlightWords)
{
- /* TODO: write tests */
+ struct t_gui_buffer *buffer;
+
+ buffer = gui_buffer_new (NULL, TEST_BUFFER_NAME,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL);
+ CHECK(buffer);
+
+ gui_buffer_set_highlight_words (NULL, NULL);
+
+ gui_buffer_set_highlight_words (buffer, NULL);
+ POINTERS_EQUAL(NULL, buffer->highlight_words);
+
+ gui_buffer_set_highlight_words (buffer, "");
+ POINTERS_EQUAL(NULL, buffer->highlight_words);
+
+ gui_buffer_set_highlight_words (buffer, "test");
+ STRCMP_EQUAL("test", buffer->highlight_words);
+
+ gui_buffer_close (buffer);
}
/*
@@ -804,7 +937,35 @@ TEST(GuiBuffer, SetHighlightWords)
TEST(GuiBuffer, SetHighlightWordsList)
{
- /* TODO: write tests */
+ struct t_gui_buffer *buffer;
+ struct t_weelist *list;
+
+ buffer = gui_buffer_new (NULL, TEST_BUFFER_NAME,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL);
+ CHECK(buffer);
+
+ gui_buffer_set_highlight_words_list (buffer, NULL);
+ POINTERS_EQUAL(NULL, buffer->highlight_words);
+
+ list = weelist_new ();
+
+ gui_buffer_set_highlight_words_list (buffer, list);
+ POINTERS_EQUAL(NULL, buffer->highlight_words);
+
+ /* add "word1" */
+ weelist_add (list, "word1", WEECHAT_LIST_POS_END, NULL);
+ gui_buffer_set_highlight_words_list (buffer, list);
+ STRCMP_EQUAL("word1", buffer->highlight_words);
+
+ /* add "word1" and "abc" ("word1" already there, ignored) */
+ weelist_add (list, "abc", WEECHAT_LIST_POS_END, NULL);
+ gui_buffer_set_highlight_words_list (buffer, list);
+ STRCMP_EQUAL("word1,abc", buffer->highlight_words);
+
+ weelist_free (list);
+
+ gui_buffer_close (buffer);
}
/*