tests: Add test for get_expanded_path()

This commit is contained in:
Michael Vetter
2026-02-23 17:43:22 +01:00
parent 1be326911c
commit 74bf33e727
3 changed files with 28 additions and 0 deletions

View File

@@ -327,6 +327,32 @@ strip_quotes_strips_both(void** state)
free(result);
}
void test_get_expanded_path(void** state) {
gchar* expanded_path;
// `file://` prefix
expanded_path = get_expanded_path("file:///tmp/test.txt");
assert_string_equal("/tmp/test.txt", expanded_path);
g_free(expanded_path);
// `~/"` prefix
setenv("HOME", "/home/test", 1);
expanded_path = get_expanded_path("~/folder/file.txt");
assert_string_equal("/home/test/folder/file.txt", expanded_path);
g_free(expanded_path);
unsetenv("HOME");
// regular path
expanded_path = get_expanded_path("/home/test/file.pdf");
assert_string_equal("/home/test/file.pdf", expanded_path);
g_free(expanded_path);
// empty path
expanded_path = get_expanded_path("");
assert_string_equal("", expanded_path);
g_free(expanded_path);
}
typedef struct
{
char* template;

View File

@@ -34,3 +34,4 @@ void prof_whole_occurrences_tests(void** state);
void prof_occurrences_of_large_message_tests(void** state);
void unique_filename_from_url_td(void** state);
void format_call_external_argv_td(void** state);
void test_get_expanded_path(void** state);

View File

@@ -94,6 +94,7 @@ main(int argc, char* argv[])
cmocka_unit_test(strip_quotes_strips_both),
cmocka_unit_test(format_call_external_argv_td),
cmocka_unit_test(unique_filename_from_url_td),
cmocka_unit_test(test_get_expanded_path),
cmocka_unit_test(clear_empty),
cmocka_unit_test(reset_after_create),