diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_common.c | 61 | ||||
-rw-r--r-- | tests/unittests/test_common.h | 1 | ||||
-rw-r--r-- | tests/unittests/unittests.c | 1 |
3 files changed, 61 insertions, 2 deletions
diff --git a/tests/unittests/test_common.c b/tests/unittests/test_common.c index 2dee8722..fa5dd59e 100644 --- a/tests/unittests/test_common.c +++ b/tests/unittests/test_common.c @@ -332,6 +332,63 @@ strip_quotes_strips_both(void** state) typedef struct { + char* template; + char* url; + char* filename; + char* argv; +} format_call_external_argv_t; + +void +format_call_external_argv_td(void** state) +{ + + enum table { num_tests = 4 }; + + format_call_external_argv_t tests[num_tests] = { + (format_call_external_argv_t){ + .template = "/bin/echo %u %p", + .url = "https://example.org", + .filename = "image.jpeg", + .argv = "/bin/echo https://example.org image.jpeg", + }, + (format_call_external_argv_t){ + .template = "/bin/echo %p %u", + .url = "https://example.org", + .filename = "image.jpeg", + .argv = "/bin/echo image.jpeg https://example.org", + }, + (format_call_external_argv_t){ + .template = "/bin/echo %p", + .url = "https://example.org", + .filename = "image.jpeg", + .argv = "/bin/echo image.jpeg", + }, + (format_call_external_argv_t){ + .template = "/bin/echo %u", + .url = "https://example.org", + .filename = "image.jpeg", + .argv = "/bin/echo https://example.org", + }, + }; + + gchar** got_argv = NULL; + gchar* got_argv_str = NULL; + for (int i = 0; i < num_tests; i++) { + got_argv = format_call_external_argv( + tests[i].template, + tests[i].url, + tests[i].filename); + got_argv_str = g_strjoinv(" ", got_argv); + + assert_string_equal(got_argv_str, tests[i].argv); + + g_strfreev(got_argv); + g_free(got_argv_str); + } +} + +typedef struct +{ char* url; char* path; char* target; @@ -438,8 +495,8 @@ unique_filename_from_url_td(void** state) }, }; - char* got_filename; - char* exp_filename; + char* got_filename = NULL; + char* exp_filename = NULL; for (int i = 0; i < num_tests; i++) { got_filename = unique_filename_from_url(tests[i].url, tests[i].path); exp_filename = g_build_filename(tests[i].target, tests[i].basename, NULL); diff --git a/tests/unittests/test_common.h b/tests/unittests/test_common.h index a1ef7c6e..46d990d9 100644 --- a/tests/unittests/test_common.h +++ b/tests/unittests/test_common.h @@ -32,3 +32,4 @@ void strip_quotes_strips_both(void** state); void prof_partial_occurrences_tests(void** state); void prof_whole_occurrences_tests(void** state); void unique_filename_from_url_td(void** state); +void format_call_external_argv_td(void** state); diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c index c63a3783..7fd3b192 100644 --- a/tests/unittests/unittests.c +++ b/tests/unittests/unittests.c @@ -90,6 +90,7 @@ main(int argc, char* argv[]) unit_test(strip_quotes_strips_first), unit_test(strip_quotes_strips_last), unit_test(strip_quotes_strips_both), + unit_test(format_call_external_argv_td), unit_test(unique_filename_from_url_td), unit_test(clear_empty), |