aboutsummaryrefslogtreecommitdiff
path: root/src/mock/libcurl/libcurl.c
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2021-05-18 11:42:27 +0200
committerJan200101 <sentrycraft123@gmail.com>2021-05-18 11:44:22 +0200
commit8e7d62f14bd401e4cc8737c06f16e6978b0b9e57 (patch)
tree94a3352969e287e5ac6040d2d2829e9656f4d492 /src/mock/libcurl/libcurl.c
parent52f8abc09b0d97608ba9d5b57ea96c48a1390384 (diff)
downloadpolecat-8e7d62f14bd401e4cc8737c06f16e6978b0b9e57.tar.gz
polecat-8e7d62f14bd401e4cc8737c06f16e6978b0b9e57.zip
improve cmake files, add simple curl mock, clean up on download error
Diffstat (limited to 'src/mock/libcurl/libcurl.c')
-rw-r--r--src/mock/libcurl/libcurl.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/mock/libcurl/libcurl.c b/src/mock/libcurl/libcurl.c
new file mode 100644
index 0000000..b4f332c
--- /dev/null
+++ b/src/mock/libcurl/libcurl.c
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <stdarg.h>
+#include <curl/curl.h>
+
+char* url = NULL;
+void* data = NULL;
+
+#ifdef curl_easy_setopt
+#undef curl_easy_setopt
+#endif
+
+CURLcode curl_global_init(long flags)
+{
+ puts("[MOCK] curl_global_init(...)");
+ return CURLE_OK;
+}
+
+CURL* curl_easy_init()
+{
+ puts("[MOCK] curl_easy_init(...)");
+ return NULL;
+}
+
+CURLcode curl_easy_setopt(CURL *handle, CURLoption option, ...)
+{
+ puts("[MOCK] curl_easy_setopt(...)");
+
+ va_list arg;
+ va_start(arg, option);
+
+ switch (option)
+ {
+ case CURLOPT_URL:
+ url = va_arg(arg, char*);
+ printf("CURLOPT_URL\t%s\n", url);
+ break;
+
+ case CURLOPT_WRITEDATA:
+ data = va_arg(arg, void*);
+ printf("CURLOPT_WRITEDATA\t%p\n", data);
+ break;
+
+ default:
+ break;
+ }
+
+ va_end(arg);
+
+ return CURLE_OK;
+}
+
+CURLcode curl_easy_perform(CURL *easy_handle)
+{
+ puts("[MOCK] curl_easy_perform(...)");
+ return CURLE_OK;
+}
+
+#ifdef curl_easy_getinfo
+#undef curl_easy_getinfo
+#endif
+
+CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...)
+{
+ puts("[MOCK] curl_easy_getinfo(...)");
+
+ if (info == CURLINFO_RESPONSE_CODE)
+ {
+ va_list arg;
+ va_start(arg, info);
+ long* http_code = va_arg(arg, long*);
+ *http_code = 200;
+ va_end(arg);
+ }
+
+
+ return CURLE_OK;
+}
+
+const char* curl_easy_strerror(CURLcode error)
+{
+ puts("[MOCK] curl_easy_strerror(...)");
+ return "error";
+}
+
+void curl_easy_cleanup(CURL *handle)
+{
+ puts("[MOCK] curl_easy_cleanup(...)");
+}
+
+void curl_global_cleanup()
+{
+ puts("[MOCK] curl_global_cleanup(...)");
+} \ No newline at end of file