about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorWilliam Wennerström <william@wstrm.dev>2020-07-21 13:11:50 +0200
committerWilliam Wennerström <william@wstrm.dev>2020-11-16 21:58:10 +0100
commit1bb6cecee69d5167220a18cc4c125c215784de66 (patch)
treeb5632677f0cf1da803cb73fc3575ac34df834a5b
parentbe62b446f778ba6c064d6e054dfb7b5eacb1f1ae (diff)
downloadprofani-tty-1bb6cecee69d5167220a18cc4c125c215784de66.tar.gz
Fix stubs and move some tests to http_common
-rw-r--r--Makefile.am3
-rw-r--r--src/tools/http_common.c28
-rw-r--r--src/tools/http_common.h2
-rw-r--r--tests/unittests/test_http_common.c (renamed from tests/unittests/test_http_download.c)2
-rw-r--r--tests/unittests/test_http_common.h (renamed from tests/unittests/test_http_download.h)0
-rw-r--r--tests/unittests/tools/stub_aesgcm_download.c10
-rw-r--r--tests/unittests/tools/stub_http_common.c16
-rw-r--r--tests/unittests/tools/stub_http_download.c5
-rw-r--r--tests/unittests/tools/stub_http_upload.c3
-rw-r--r--tests/unittests/unittests.c2
10 files changed, 23 insertions, 48 deletions
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
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
index a1c62a7f..a1c62a7f 100644
--- a/tests/unittests/test_http_download.h
+++ b/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[])