diff options
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/test_common.c | 77 | ||||
-rw-r--r-- | tests/unittests/test_common.h | 1 | ||||
-rw-r--r-- | tests/unittests/test_http_common.c | 75 | ||||
-rw-r--r-- | tests/unittests/test_http_common.h | 1 | ||||
-rw-r--r-- | tests/unittests/tools/stub_http_download.c | 9 | ||||
-rw-r--r-- | tests/unittests/unittests.c | 4 |
6 files changed, 88 insertions, 79 deletions
diff --git a/tests/unittests/test_common.c b/tests/unittests/test_common.c index b8958dda..462676cc 100644 --- a/tests/unittests/test_common.c +++ b/tests/unittests/test_common.c @@ -330,6 +330,83 @@ strip_quotes_strips_both(void** state) free(result); } +typedef struct +{ + char* url; + char* path; + char* filename; +} unique_filename_from_url_t; + +void +unique_filename_from_url_td(void** state) +{ + enum table { num_tests = 11 }; + + unique_filename_from_url_t tests[num_tests] = { + (unique_filename_from_url_t){ + .url = "https://host.test/image.jpeg", + .path = "./", + .filename = "./image.jpeg", + }, + (unique_filename_from_url_t){ + .url = "https://host.test/image.jpeg#somefragment", + .path = "./", + .filename = "./image.jpeg", + }, + (unique_filename_from_url_t){ + .url = "https://host.test/image.jpeg?query=param", + .path = "./", + .filename = "./image.jpeg", + }, + (unique_filename_from_url_t){ + .url = "https://host.test/image.jpeg?query=param&another=one", + .path = "./", + .filename = "./image.jpeg", + }, + (unique_filename_from_url_t){ + .url = "https://host.test/images/", + .path = "./", + .filename = "./images", + }, + (unique_filename_from_url_t){ + .url = "https://host.test/images/../../file", + .path = "./", + .filename = "./file", + }, + (unique_filename_from_url_t){ + .url = "https://host.test/images/../../file/..", + .path = "./", + .filename = "./index.html", + }, + (unique_filename_from_url_t){ + .url = "https://host.test/images/..//", + .path = "./", + .filename = "./index.html", + }, + (unique_filename_from_url_t){ + .url = "https://host.test/", + .path = "./", + .filename = "./index.html", + }, + (unique_filename_from_url_t){ + .url = "https://host.test", + .path = "./", + .filename = "./index.html", + }, + (unique_filename_from_url_t){ + .url = "aesgcm://host.test", + .path = "./", + .filename = "./index.html", + }, + }; + + char* filename; + for (int i = 0; i < num_tests; i++) { + filename = unique_filename_from_url(tests[i].url, tests[i].path); + assert_string_equal(filename, tests[i].filename); + } +} + gboolean _lists_equal(GSList* a, GSList* b) { diff --git a/tests/unittests/test_common.h b/tests/unittests/test_common.h index b9e7291e..a1ef7c6e 100644 --- a/tests/unittests/test_common.h +++ b/tests/unittests/test_common.h @@ -31,3 +31,4 @@ void strip_quotes_strips_last(void** state); 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); diff --git a/tests/unittests/test_http_common.c b/tests/unittests/test_http_common.c deleted file mode 100644 index 195f370b..00000000 --- a/tests/unittests/test_http_common.c +++ /dev/null @@ -1,75 +0,0 @@ -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> -#include <stdlib.h> -#include <string.h> -#include <glib.h> - -#include "config.h" - -#include "tools/http_common.c" - -typedef struct -{ - char* url; - char* basename; -} url_test_t; - -void -http_basename_from_url_td(void** state) -{ - int num_tests = 11; - url_test_t tests[] = { - (url_test_t){ - .url = "https://host.test/image.jpeg", - .basename = "image.jpeg", - }, - (url_test_t){ - .url = "https://host.test/image.jpeg#somefragment", - .basename = "image.jpeg", - }, - (url_test_t){ - .url = "https://host.test/image.jpeg?query=param", - .basename = "image.jpeg", - }, - (url_test_t){ - .url = "https://host.test/image.jpeg?query=param&another=one", - .basename = "image.jpeg", - }, - (url_test_t){ - .url = "https://host.test/images/", - .basename = "images", - }, - (url_test_t){ - .url = "https://host.test/images/../../file", - .basename = "file", - }, - (url_test_t){ - .url = "https://host.test/images/../../file/..", - .basename = "index.html", - }, - (url_test_t){ - .url = "https://host.test/images/..//", - .basename = "index.html", - }, - (url_test_t){ - .url = "https://host.test/", - .basename = "index.html", - }, - (url_test_t){ - .url = "https://host.test", - .basename = "index.html", - }, - (url_test_t){ - .url = "aesgcm://host.test", - .basename = "index.html", - }, - }; - - char* basename; - for (int i = 0; i < num_tests; i++) { - basename = http_basename_from_url(tests[i].url); - assert_string_equal(basename, tests[i].basename); - } -} diff --git a/tests/unittests/test_http_common.h b/tests/unittests/test_http_common.h deleted file mode 100644 index a1c62a7f..00000000 --- a/tests/unittests/test_http_common.h +++ /dev/null @@ -1 +0,0 @@ -void http_basename_from_url_td(void** state); diff --git a/tests/unittests/tools/stub_http_download.c b/tests/unittests/tools/stub_http_download.c index 5fa1c46e..cc7bddc5 100644 --- a/tests/unittests/tools/stub_http_download.c +++ b/tests/unittests/tools/stub_http_download.c @@ -18,4 +18,13 @@ typedef struct http_download_t int cancel; } HTTPDownload; +void* +http_file_get(void* userdata) +{ + return NULL; +} + +void http_download_cancel_processes(){}; +void http_download_add_download(){}; + #endif diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c index cab99bf5..c63a3783 100644 --- a/tests/unittests/unittests.c +++ b/tests/unittests/unittests.c @@ -38,7 +38,6 @@ #include "test_form.h" #include "test_callbacks.h" #include "test_plugins_disco.h" -#include "test_http_common.h" int main(int argc, char* argv[]) @@ -91,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(unique_filename_from_url_td), unit_test(clear_empty), unit_test(reset_after_create), @@ -627,8 +627,6 @@ main(int argc, char* argv[]) unit_test(does_not_add_duplicate_feature), unit_test(removes_plugin_features), unit_test(does_not_remove_feature_when_more_than_one_reference), - - unit_test(http_basename_from_url_td), }; return run_tests(all_tests); |