From 1bb6cecee69d5167220a18cc4c125c215784de66 Mon Sep 17 00:00:00 2001 From: William Wennerström Date: Tue, 21 Jul 2020 13:11:50 +0200 Subject: Fix stubs and move some tests to http_common --- tests/unittests/test_http_common.c | 75 ++++++++++++++++++++++++++++ tests/unittests/test_http_common.h | 1 + tests/unittests/test_http_download.c | 75 ---------------------------- tests/unittests/test_http_download.h | 1 - tests/unittests/tools/stub_aesgcm_download.c | 10 ++-- tests/unittests/tools/stub_http_common.c | 16 ------ tests/unittests/tools/stub_http_download.c | 5 -- tests/unittests/tools/stub_http_upload.c | 3 +- tests/unittests/unittests.c | 2 +- 9 files changed, 85 insertions(+), 103 deletions(-) create mode 100644 tests/unittests/test_http_common.c create mode 100644 tests/unittests/test_http_common.h delete mode 100644 tests/unittests/test_http_download.c delete mode 100644 tests/unittests/test_http_download.h delete mode 100644 tests/unittests/tools/stub_http_common.c (limited to 'tests') diff --git a/tests/unittests/test_http_common.c b/tests/unittests/test_http_common.c new file mode 100644 index 00000000..195f370b --- /dev/null +++ b/tests/unittests/test_http_common.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include +#include +#include + +#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 new file mode 100644 index 00000000..a1c62a7f --- /dev/null +++ b/tests/unittests/test_http_common.h @@ -0,0 +1 @@ +void http_basename_from_url_td(void** state); diff --git a/tests/unittests/test_http_download.c b/tests/unittests/test_http_download.c deleted file mode 100644 index 96d45d03..00000000 --- a/tests/unittests/test_http_download.c +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "config.h" - -#include "tools/http_download.h" - -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_download.h b/tests/unittests/test_http_download.h deleted file mode 100644 index a1c62a7f..00000000 --- a/tests/unittests/test_http_download.h +++ /dev/null @@ -1 +0,0 @@ -void http_basename_from_url_td(void** state); diff --git a/tests/unittests/tools/stub_aesgcm_download.c b/tests/unittests/tools/stub_aesgcm_download.c index 58696e80..6f4cc0ce 100644 --- a/tests/unittests/tools/stub_aesgcm_download.c +++ b/tests/unittests/tools/stub_aesgcm_download.c @@ -15,9 +15,13 @@ typedef struct aesgcm_download_t HTTPDownload* http_dl; } AESGCMDownload; -void* aesgcm_file_get(void* userdata); +void* +aesgcm_file_get(void* userdata) +{ + return NULL; +}; -void aesgcm_download_cancel_processes(ProfWin* window); -void aesgcm_download_add_download(AESGCMDownload* download); +void aesgcm_download_cancel_processes(ProfWin* window){}; +void aesgcm_download_add_download(AESGCMDownload* download){}; #endif diff --git a/tests/unittests/tools/stub_http_common.c b/tests/unittests/tools/stub_http_common.c deleted file mode 100644 index 23e0a23f..00000000 --- a/tests/unittests/tools/stub_http_common.c +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef TOOLS_HTTP_COMMON_H -#define TOOLS_HTTP_COMMON_H - -typedef struct prof_win_t ProfWin; - -char* -http_basename_from_url(const char* url) -{ - return ""; -} - -void http_print_transfer(ProfWin* window, char* url, const char* fmt, ...); -void http_print_transfer_update(ProfWin* window, char* url, - const char* fmt, ...); - -#endif diff --git a/tests/unittests/tools/stub_http_download.c b/tests/unittests/tools/stub_http_download.c index fb2cb1b8..5fa1c46e 100644 --- a/tests/unittests/tools/stub_http_download.c +++ b/tests/unittests/tools/stub_http_download.c @@ -18,9 +18,4 @@ typedef struct http_download_t int cancel; } HTTPDownload; -void* http_file_get(void* userdata); - -void http_download_cancel_processes(ProfWin* window); -void http_download_add_download(HTTPDownload* download); - #endif diff --git a/tests/unittests/tools/stub_http_upload.c b/tests/unittests/tools/stub_http_upload.c index 25a81708..1b79e02d 100644 --- a/tests/unittests/tools/stub_http_upload.c +++ b/tests/unittests/tools/stub_http_upload.c @@ -20,8 +20,6 @@ typedef struct http_upload_t int cancel; } HTTPUpload; -//GSList *upload_processes; - void* http_file_put(void* userdata) { @@ -33,6 +31,7 @@ file_mime_type(const char* const file_name) { return NULL; } + off_t file_size(const char* const file_name) { diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c index 06c1b307..cab99bf5 100644 --- a/tests/unittests/unittests.c +++ b/tests/unittests/unittests.c @@ -38,7 +38,7 @@ #include "test_form.h" #include "test_callbacks.h" #include "test_plugins_disco.h" -#include "test_http_download.h" +#include "test_http_common.h" int main(int argc, char* argv[]) -- cgit 1.4.1-2-gfad0