From 8c3f16dbe3e6ea2998cc804bdb02d92d84b21149 Mon Sep 17 00:00:00 2001 From: 90 Date: Mon, 8 Apr 2024 18:46:27 +0100 Subject: core: add support for $XDG_STATE_HOME --- tests/unit/core/test-core-string.cpp | 20 +++++++++++++++++++- tests/unit/plugins/test-plugin-api-info.cpp | 10 +++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp index 2d6552a31..580fc64ce 100644 --- a/tests/unit/core/test-core-string.cpp +++ b/tests/unit/core/test-core-string.cpp @@ -962,7 +962,8 @@ TEST(CoreString, EvalPathHome) { char *home, *result; int length_home, length_weechat_config_dir, length_weechat_data_dir; - int length_weechat_cache_dir, length_weechat_runtime_dir; + int length_weechat_state_dir, length_weechat_cache_dir; + int length_weechat_runtime_dir; struct t_hashtable *extra_vars, *options; home = getenv ("HOME"); @@ -971,6 +972,7 @@ TEST(CoreString, EvalPathHome) length_weechat_config_dir = strlen (weechat_config_dir); length_weechat_data_dir = strlen (weechat_data_dir); + length_weechat_state_dir = strlen (weechat_state_dir); length_weechat_cache_dir = strlen (weechat_cache_dir); length_weechat_runtime_dir = strlen (weechat_runtime_dir); @@ -1014,6 +1016,14 @@ TEST(CoreString, EvalPathHome) STRCMP_EQUAL(result + length_weechat_data_dir, "/test"); free (result); + /* "%h" with forced state dir */ + hashtable_set (options, "directory", "state"); + result = string_eval_path_home ("%h/test", NULL, NULL, options); + CHECK(strncmp (result, weechat_state_dir, length_weechat_state_dir) == 0); + LONGS_EQUAL(length_weechat_state_dir + 5, strlen (result)); + STRCMP_EQUAL(result + length_weechat_state_dir, "/test"); + free (result); + /* "%h" with forced cache dir */ hashtable_set (options, "directory", "cache"); result = string_eval_path_home ("%h/test", NULL, NULL, options); @@ -1048,6 +1058,14 @@ TEST(CoreString, EvalPathHome) STRCMP_EQUAL(result + length_weechat_data_dir, "/path"); free (result); + /* state dir */ + result = string_eval_path_home ("${weechat_state_dir}/path", + NULL, NULL, NULL); + CHECK(strncmp (result, weechat_state_dir, length_weechat_state_dir) == 0); + LONGS_EQUAL(length_weechat_state_dir + 5, strlen (result)); + STRCMP_EQUAL(result + length_weechat_state_dir, "/path"); + free (result); + /* cache dir */ result = string_eval_path_home ("${weechat_cache_dir}/path", NULL, NULL, NULL); diff --git a/tests/unit/plugins/test-plugin-api-info.cpp b/tests/unit/plugins/test-plugin-api-info.cpp index 07a31f9b0..a58c14f4d 100644 --- a/tests/unit/plugins/test-plugin-api-info.cpp +++ b/tests/unit/plugins/test-plugin-api-info.cpp @@ -164,8 +164,9 @@ TEST(PluginApiInfo, AbsolutePath) * plugin_api_info_absolute_path * plugin_api_info_weechat_config_dir_cb * plugin_api_info_weechat_data_dir_cb + * plugin_api_info_weechat_state_dir_cb * plugin_api_info_weechat_cache_dir_cb - * plugin_api_info_weechat_cache_dir_cb + * plugin_api_info_weechat_runtime_dir_cb */ TEST(PluginApiInfo, WeechatDir) @@ -186,6 +187,13 @@ TEST(PluginApiInfo, WeechatDir) CHECK(strstr (str, "/tmp_weechat_test")); free (str); + str = hook_info_get (NULL, "weechat_state_dir", NULL); + CHECK(str); + CHECK(str[0] == '/'); + CHECK(strlen (str) > 1); + CHECK(strstr (str, "/tmp_weechat_test")); + free (str); + str = hook_info_get (NULL, "weechat_cache_dir", NULL); CHECK(str); CHECK(str[0] == '/'); -- cgit v1.2.3