tests: Add test for get_expanded_path()
This commit is contained in:
@@ -327,6 +327,32 @@ strip_quotes_strips_both(void** state)
|
|||||||
free(result);
|
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
|
typedef struct
|
||||||
{
|
{
|
||||||
char* template;
|
char* template;
|
||||||
|
|||||||
@@ -34,3 +34,4 @@ void prof_whole_occurrences_tests(void** state);
|
|||||||
void prof_occurrences_of_large_message_tests(void** state);
|
void prof_occurrences_of_large_message_tests(void** state);
|
||||||
void unique_filename_from_url_td(void** state);
|
void unique_filename_from_url_td(void** state);
|
||||||
void format_call_external_argv_td(void** state);
|
void format_call_external_argv_td(void** state);
|
||||||
|
void test_get_expanded_path(void** state);
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ main(int argc, char* argv[])
|
|||||||
cmocka_unit_test(strip_quotes_strips_both),
|
cmocka_unit_test(strip_quotes_strips_both),
|
||||||
cmocka_unit_test(format_call_external_argv_td),
|
cmocka_unit_test(format_call_external_argv_td),
|
||||||
cmocka_unit_test(unique_filename_from_url_td),
|
cmocka_unit_test(unique_filename_from_url_td),
|
||||||
|
cmocka_unit_test(test_get_expanded_path),
|
||||||
|
|
||||||
cmocka_unit_test(clear_empty),
|
cmocka_unit_test(clear_empty),
|
||||||
cmocka_unit_test(reset_after_create),
|
cmocka_unit_test(reset_after_create),
|
||||||
|
|||||||
Reference in New Issue
Block a user