From be62b446f778ba6c064d6e054dfb7b5eacb1f1ae Mon Sep 17 00:00:00 2001 From: William Wennerström Date: Tue, 21 Jul 2020 11:36:09 +0200 Subject: Add stubs --- Makefile.am | 2 ++ src/command/cmd_funcs.c | 22 ++++++++++++++-------- tests/unittests/tools/stub_aesgcm_download.c | 23 +++++++++++++++++++++++ tests/unittests/tools/stub_http_common.c | 16 ++++++++++++++++ tests/unittests/tools/stub_http_download.c | 2 -- 5 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 tests/unittests/tools/stub_aesgcm_download.c create mode 100644 tests/unittests/tools/stub_http_common.c diff --git a/Makefile.am b/Makefile.am index e6c38066..9f2a99de 100644 --- a/Makefile.am +++ b/Makefile.am @@ -126,8 +126,10 @@ 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 \ tests/unittests/helpers.c tests/unittests/helpers.h \ tests/unittests/test_form.c tests/unittests/test_form.h \ tests/unittests/test_common.c tests/unittests/test_common.h \ diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index ada53f9d..c6557159 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -69,7 +69,6 @@ #include "event/client_events.h" #include "tools/http_upload.h" #include "tools/http_download.h" -#include "tools/aesgcm_download.h" #include "tools/autocomplete.h" #include "tools/parser.h" #include "tools/bookmark_ignore.h" @@ -97,6 +96,7 @@ #ifdef HAVE_OMEMO #include "omemo/omemo.h" #include "xmpp/omemo.h" +#include "tools/aesgcm_download.h" #endif #ifdef HAVE_GTK @@ -9168,6 +9168,7 @@ _url_save_fallback_method(ProfWin* window, const char* url, const char* filename { gchar* scheme = g_uri_parse_scheme(url); +#ifdef HAVE_OMEMO if (g_strcmp0(scheme, "aesgcm") == 0) { AESGCMDownload* download = malloc(sizeof(AESGCMDownload)); download->window = window; @@ -9176,15 +9177,20 @@ _url_save_fallback_method(ProfWin* window, const char* url, const char* filename pthread_create(&(download->worker), NULL, &aesgcm_file_get, download); aesgcm_download_add_download(download); - } else { - HTTPDownload* download = malloc(sizeof(HTTPDownload)); - download->window = window; - download->url = strdup(url); - download->filename = strdup(filename); - pthread_create(&(download->worker), NULL, &http_file_get, download); - http_download_add_download(download); + free(scheme); + + return; } +#endif + + HTTPDownload* download = malloc(sizeof(HTTPDownload)); + download->window = window; + download->url = strdup(url); + download->filename = strdup(filename); + + pthread_create(&(download->worker), NULL, &http_file_get, download); + http_download_add_download(download); free(scheme); } diff --git a/tests/unittests/tools/stub_aesgcm_download.c b/tests/unittests/tools/stub_aesgcm_download.c new file mode 100644 index 00000000..58696e80 --- /dev/null +++ b/tests/unittests/tools/stub_aesgcm_download.c @@ -0,0 +1,23 @@ +#ifndef TOOLS_AESGCM_DOWNLOAD_H +#define TOOLS_AESGCM_DOWNLOAD_H + +#include + +typedef struct prof_win_t ProfWin; +typedef struct http_download_t HTTPDownload; + +typedef struct aesgcm_download_t +{ + char* url; + char* filename; + ProfWin* window; + pthread_t worker; + HTTPDownload* http_dl; +} AESGCMDownload; + +void* aesgcm_file_get(void* userdata); + +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 new file mode 100644 index 00000000..23e0a23f --- /dev/null +++ b/tests/unittests/tools/stub_http_common.c @@ -0,0 +1,16 @@ +#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 202c9cbf..fb2cb1b8 100644 --- a/tests/unittests/tools/stub_http_download.c +++ b/tests/unittests/tools/stub_http_download.c @@ -23,6 +23,4 @@ void* http_file_get(void* userdata); void http_download_cancel_processes(ProfWin* window); void http_download_add_download(HTTPDownload* download); -char* http_filename_from_url(const char* url); - #endif -- cgit 1.4.1-2-gfad0