From 1bb6cecee69d5167220a18cc4c125c215784de66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Wennerstr=C3=B6m?= Date: Tue, 21 Jul 2020 13:11:50 +0200 Subject: [PATCH] Fix stubs and move some tests to http_common --- Makefile.am | 3 +- src/tools/http_common.c | 28 ++++++++----------- src/tools/http_common.h | 2 -- ...est_http_download.c => test_http_common.c} | 2 +- ...est_http_download.h => test_http_common.h} | 0 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 +- 10 files changed, 23 insertions(+), 48 deletions(-) rename tests/unittests/{test_http_download.c => test_http_common.c} (98%) rename tests/unittests/{test_http_download.h => test_http_common.h} (100%) delete mode 100644 tests/unittests/tools/stub_http_common.c diff --git a/Makefile.am b/Makefile.am index 9f2a99de..aeb52abd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -126,7 +126,6 @@ unittest_sources = \ tests/unittests/log/stub_log.c \ tests/unittests/database/stub_database.c \ tests/unittests/config/stub_accounts.c \ - tests/unittests/tools/stub_http_common.c \ tests/unittests/tools/stub_http_upload.c \ tests/unittests/tools/stub_http_download.c \ tests/unittests/tools/stub_aesgcm_download.c \ @@ -156,7 +155,7 @@ unittest_sources = \ tests/unittests/test_cmd_disconnect.c tests/unittests/test_cmd_disconnect.h \ tests/unittests/test_callbacks.c tests/unittests/test_callbacks.h \ tests/unittests/test_plugins_disco.c tests/unittests/test_plugins_disco.h \ - tests/unittests/test_http_download.c tests/unittests/test_http_download.h \ + tests/unittests/test_http_common.c tests/unittests/test_http_common.h \ tests/unittests/unittests.c functionaltest_sources = \ diff --git a/src/tools/http_common.c b/src/tools/http_common.c index df6f9a64..dfd0aa87 100644 --- a/src/tools/http_common.c +++ b/src/tools/http_common.c @@ -64,35 +64,31 @@ http_basename_from_url(const char* url) } void -http_print_transfer_update(ProfWin* window, char* url, - const char* fmt, ...) +http_print_transfer_update(ProfWin* window, char* url, const char* fmt, ...) { va_list args; va_start(args, fmt); - char* msg; - if (vasprintf(&msg, fmt, args) == -1) { - msg = strdup(FALLBACK_MSG); - } + GString* msg = g_string_new(FALLBACK_MSG); + g_string_vprintf(msg, fmt, args); va_end(args); - win_update_entry_message(window, url, msg); - free(msg); + win_update_entry_message(window, url, msg->str); + + g_string_free(msg, TRUE); } void -http_print_transfer(ProfWin* window, char* url, - const char* fmt, ...) +http_print_transfer(ProfWin* window, char* url, const char* fmt, ...) { va_list args; va_start(args, fmt); - char* msg; - if (vasprintf(&msg, fmt, args) == -1) { - msg = strdup(FALLBACK_MSG); - } + GString* msg = g_string_new(FALLBACK_MSG); + g_string_vprintf(msg, fmt, args); va_end(args); - win_print_http_transfer(window, msg, url); - free(msg); + win_print_http_transfer(window, msg->str, url); + + g_string_free(msg, TRUE); } diff --git a/src/tools/http_common.h b/src/tools/http_common.h index 41f16200..3fbc6fcd 100644 --- a/src/tools/http_common.h +++ b/src/tools/http_common.h @@ -36,8 +36,6 @@ #ifndef TOOLS_HTTP_COMMON_H #define TOOLS_HTTP_COMMON_H -#define _GNU_SOURCE 1 - #include "ui/window.h" char* http_basename_from_url(const char* url); diff --git a/tests/unittests/test_http_download.c b/tests/unittests/test_http_common.c similarity index 98% rename from tests/unittests/test_http_download.c rename to tests/unittests/test_http_common.c index 96d45d03..195f370b 100644 --- a/tests/unittests/test_http_download.c +++ b/tests/unittests/test_http_common.c @@ -8,7 +8,7 @@ #include "config.h" -#include "tools/http_download.h" +#include "tools/http_common.c" typedef struct { diff --git a/tests/unittests/test_http_download.h b/tests/unittests/test_http_common.h similarity index 100% rename from tests/unittests/test_http_download.h rename to tests/unittests/test_http_common.h 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[])