From df1df2929646abd77955b80e3ded3574ac005179 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Thu, 27 May 2021 23:37:23 +0200 Subject: allow flags to exit prematurely, move defines, add no networking flag --- src/mock/CMakeLists.txt | 3 +- src/mock/libcurl.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++ src/mock/libcurl/libcurl.c | 93 --------------------------------------------- 3 files changed, 97 insertions(+), 94 deletions(-) create mode 100644 src/mock/libcurl.c delete mode 100644 src/mock/libcurl/libcurl.c (limited to 'src/mock') diff --git a/src/mock/CMakeLists.txt b/src/mock/CMakeLists.txt index c2634d5..8b48c04 100644 --- a/src/mock/CMakeLists.txt +++ b/src/mock/CMakeLists.txt @@ -1,8 +1,9 @@ SET(CURL_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/libcurl/libcurl.c + ${CMAKE_CURRENT_SOURCE_DIR}/libcurl.c ) add_library(mockcurl STATIC ${CURL_SOURCES}) +target_compile_options(mockcurl PUBLIC ${CFLAGS}) target_include_directories(mockcurl PUBLIC ${LIBCURL_INCLUDE_DIRS}) set(NAME ${CMAKE_PROJECT_NAME}_mock) diff --git a/src/mock/libcurl.c b/src/mock/libcurl.c new file mode 100644 index 0000000..95901be --- /dev/null +++ b/src/mock/libcurl.c @@ -0,0 +1,95 @@ +#include +#include +#include + +#include "../defines.h" + +char* url = NULL; +void* data = NULL; + +#ifdef curl_easy_setopt +#undef curl_easy_setopt +#endif + +CURLcode curl_global_init(UNUSED 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(UNUSED 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(UNUSED CURL *easy_handle) +{ + puts("[MOCK] curl_easy_perform(...)"); + return CURLE_OK; +} + +#ifdef curl_easy_getinfo +#undef curl_easy_getinfo +#endif + +CURLcode curl_easy_getinfo(UNUSED 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(UNUSED 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 diff --git a/src/mock/libcurl/libcurl.c b/src/mock/libcurl/libcurl.c deleted file mode 100644 index b4f332c..0000000 --- a/src/mock/libcurl/libcurl.c +++ /dev/null @@ -1,93 +0,0 @@ -#include -#include -#include - -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 -- cgit v1.2.3