diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-12 21:44:17 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-28 15:13:36 +0100 |
commit | 0dd1d1be1c5f1084802daf89e988f2c1d84559c7 (patch) | |
tree | d9292ed2fcc6e0a9950807532a1e81188bc787fd /tests | |
parent | 202b4d82c0b233a891e9e1a303833c15ae86e1d4 (diff) | |
download | weechat-0dd1d1be1c5f1084802daf89e988f2c1d84559c7.zip |
core: sort configuration files by name, reload them by priority (issue #1872)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tests.cpp | 11 | ||||
-rw-r--r-- | tests/unit/core/test-core-command.cpp | 11 | ||||
-rw-r--r-- | tests/unit/core/test-core-config-file.cpp | 30 | ||||
-rw-r--r-- | tests/unit/plugins/irc/test-irc-protocol.cpp | 9 |
4 files changed, 49 insertions, 12 deletions
diff --git a/tests/tests.cpp b/tests/tests.cpp index 00363e0d7..616d35ab8 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -222,22 +222,23 @@ record_stop () * The format of "message" argument is: "prefix message" (prefix and message * separated by a space). * - * Returns: - * 1: message has been displayed - * 0: message has NOT been displayed + * Returns index of message displayed (≥ 0), -1 if message has NOT been + * displayed. */ int record_search (const char *buffer, const char *message) { char str_message[8192]; + int index; snprintf (str_message, sizeof (str_message), "%s: \"%s\"", buffer, message); - return (arraylist_search (recorded_messages, str_message, - NULL, NULL) != NULL); + arraylist_search (recorded_messages, str_message, &index, NULL); + + return index; } /* diff --git a/tests/unit/core/test-core-command.cpp b/tests/unit/core/test-core-command.cpp index 0a24a0ff0..d2ec90bd0 100644 --- a/tests/unit/core/test-core-command.cpp +++ b/tests/unit/core/test-core-command.cpp @@ -42,7 +42,7 @@ extern "C" command_record ("core.weechat", __command); #define WEE_CHECK_MSG_BUFFER(__buffer_name, __message) \ - if (!record_search (__buffer_name, __message)) \ + if (record_search (__buffer_name, __message) < 0) \ { \ char **msg = command_build_error ( \ "Message not displayed on buffer " __buffer_name ": " \ @@ -54,6 +54,8 @@ extern "C" #define WEE_CHECK_MSG_CORE(__message) \ WEE_CHECK_MSG_BUFFER("core.weechat", __message); +#define WEE_SEARCH_MSG_CORE(__message) \ + record_search ("core.weechat", __message) TEST_GROUP(CoreCommand) @@ -369,7 +371,12 @@ TEST(CoreCommand, Quit) TEST(CoreCommand, Reload) { - /* TODO: write tests */ + WEE_CMD_CORE("/save"); + WEE_CMD_CORE("/reload"); + LONGS_EQUAL(0, WEE_SEARCH_MSG_CORE("Options reloaded from sec.conf")); + LONGS_EQUAL(1, WEE_SEARCH_MSG_CORE("Options reloaded from weechat.conf")); + LONGS_EQUAL(2, WEE_SEARCH_MSG_CORE("Options reloaded from plugins.conf")); + LONGS_EQUAL(3, WEE_SEARCH_MSG_CORE("Options reloaded from charset.conf")); } /* diff --git a/tests/unit/core/test-core-config-file.cpp b/tests/unit/core/test-core-config-file.cpp index 0a84c2f54..9c6a74732 100644 --- a/tests/unit/core/test-core-config-file.cpp +++ b/tests/unit/core/test-core-config-file.cpp @@ -32,6 +32,7 @@ extern "C" #include "src/gui/gui-color.h" #include "src/plugins/plugin.h" +extern struct t_config_file *config_file_find_pos (const char *name); extern char *config_file_option_full_name (struct t_config_option *option); extern int config_file_string_boolean_is_valid (const char *text); extern const char *config_file_option_escape (const char *name); @@ -43,6 +44,20 @@ TEST_GROUP(CoreConfigFile) /* * Tests functions: + * config_file_valid + */ + +TEST(CoreConfigFile, Valid) +{ + LONGS_EQUAL(0, config_file_valid (NULL)); + LONGS_EQUAL(0, config_file_valid ((struct t_config_file *)0x1)); + + LONGS_EQUAL(1, config_file_valid (config_file_search ("weechat"))); + LONGS_EQUAL(1, config_file_valid (config_file_search ("sec"))); +} + +/* + * Tests functions: * config_file_search */ @@ -58,11 +73,24 @@ TEST(CoreConfigFile, Search) /* * Tests functions: - * config_file_config_find_pos + * config_file_find_pos */ TEST(CoreConfigFile, FindPos) { + POINTERS_EQUAL(NULL, config_file_find_pos (NULL)); + POINTERS_EQUAL(config_files, config_file_find_pos ("")); + POINTERS_EQUAL(weechat_config_file->next_config, config_file_find_pos ("weechat")); + POINTERS_EQUAL(weechat_config_file->next_config, config_file_find_pos ("WEECHAT")); +} + +/* + * Tests functions: + * config_file_config_insert + */ + +TEST(CoreConfigFile, ConfigInsert) +{ /* TODO: write tests */ } diff --git a/tests/unit/plugins/irc/test-irc-protocol.cpp b/tests/unit/plugins/irc/test-irc-protocol.cpp index c5611e337..fa5d4158a 100644 --- a/tests/unit/plugins/irc/test-irc-protocol.cpp +++ b/tests/unit/plugins/irc/test-irc-protocol.cpp @@ -78,7 +78,7 @@ extern char *irc_protocol_cap_to_enable (const char *capabilities, server_recv (__irc_msg); #define CHECK_CORE(__message) \ - if (!record_search ("core.weechat", __message)) \ + if (record_search ("core.weechat", __message) < 0) \ { \ char **msg = server_build_error ( \ "Core message not displayed", \ @@ -89,7 +89,7 @@ extern char *irc_protocol_cap_to_enable (const char *capabilities, } #define CHECK_SRV(__message) \ - if (!record_search ("irc.server." IRC_FAKE_SERVER, __message)) \ + if (record_search ("irc.server." IRC_FAKE_SERVER, __message) < 0) \ { \ char **msg = server_build_error ( \ "Server message not displayed", \ @@ -113,7 +113,7 @@ extern char *irc_protocol_cap_to_enable (const char *capabilities, "(please report to developers): \"" __message "\""); #define CHECK_CHAN(__message) \ - if (!record_search ("irc." IRC_FAKE_SERVER ".#test", __message)) \ + if (record_search ("irc." IRC_FAKE_SERVER ".#test", __message) < 0) \ { \ char **msg = server_build_error ( \ "Channel message not displayed", \ @@ -124,7 +124,8 @@ extern char *irc_protocol_cap_to_enable (const char *capabilities, } #define CHECK_PV(__nick, __message) \ - if (!record_search ("irc." IRC_FAKE_SERVER "." __nick, __message)) \ + if (record_search ("irc." IRC_FAKE_SERVER "." __nick, \ + __message) < 0) \ { \ char **msg = server_build_error ( \ "Private message not displayed", \ |