aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2021-12-23 20:52:20 +0100
committerJan200101 <sentrycraft123@gmail.com>2021-12-23 20:52:20 +0100
commit60f28e2ca03bf4db8c939a4709ff2f5b0840c901 (patch)
tree33aac9abdd6a2d60acee13c8a8c8b9090430700d /src
parent170353856b4999f4987314080daa53466ca58583 (diff)
downloadpolecat-60f28e2ca03bf4db8c939a4709ff2f5b0840c901.tar.gz
polecat-60f28e2ca03bf4db8c939a4709ff2f5b0840c901.zip
clean up mock logic, improve names, allow mock without wine
Diffstat (limited to 'src')
-rw-r--r--src/mock/CMakeLists.txt35
-rw-r--r--src/mock/libcurl.c4
-rw-r--r--src/mock/wine/CMakeLists.txt1
3 files changed, 26 insertions, 14 deletions
diff --git a/src/mock/CMakeLists.txt b/src/mock/CMakeLists.txt
index 80f2eac..1b23c63 100644
--- a/src/mock/CMakeLists.txt
+++ b/src/mock/CMakeLists.txt
@@ -1,18 +1,23 @@
-add_subdirectory(wine)
-
+list(APPEND
+ MOCK_SOURCES
+ ${CMAKE_CURRENT_SOURCE_DIR}/libcurl.c
+)
-set(WINE_JSON_INFILE "${CMAKE_CURRENT_SOURCE_DIR}/runners/wine.json")
-set(WINE_JSON_OUTFILE "${CMAKE_CURRENT_BINARY_DIR}/wine_json")
+if (ENABLE_WINE)
+add_subdirectory(wine)
+include_directories(${WINE_MOCK_ARCHIVE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
+set(WINE_MOCK_JSON_INFILE "${CMAKE_CURRENT_SOURCE_DIR}/runners/wine.json")
+set(WINE_MOCK_JSON_OUTFILE "${CMAKE_CURRENT_BINARY_DIR}/wine_json")
add_custom_command(
- OUTPUT ${WINE_JSON_OUTFILE}.c ${WINE_JSON_OUTFILE}.h
+ OUTPUT ${WINE_MOCK_JSON_OUTFILE}.c ${WINE_MOCK_JSON_OUTFILE}.h
COMMAND ${CMAKE_COMMAND}
- "-Dbin_in=${WINE_JSON_INFILE}"
+ "-Dbin_in=${WINE_MOCK_JSON_INFILE}"
-P ${CMAKE_SOURCE_DIR}/cmake/FileEmbed.cmake
)
-add_custom_target(wine_json ALL DEPENDS ${WINE_JSON_OUTFILE}.c ${WINE_JSON_OUTFILE}.h)
+add_custom_target(wine_mock_json ALL DEPENDS ${WINE_MOCK_JSON_OUTFILE}.c ${WINE_MOCK_JSON_OUTFILE}.h)
set(WINE_MOCK
${WINE_MOCK_ARCHIVE_OUT}.c
@@ -21,18 +26,22 @@ set(WINE_MOCK
file(TOUCH ${WINE_MOCK})
-SET(MOCK_SOURCES
- ${CMAKE_CURRENT_SOURCE_DIR}/libcurl.c
+list(APPEND
+ MOCK_SOURCES
${WINE_MOCK}
- ${WINE_JSON_OUTFILE}.c
- ${WINE_JSON_OUTFILE}.h
+ ${WINE_MOCK_JSON_OUTFILE}.c
+ ${WINE_MOCK_JSON_OUTFILE}.h
)
+endif()
+
add_library(mock STATIC ${MOCK_SOURCES})
target_compile_options(mock PUBLIC ${CFLAGS})
target_include_directories(mock PUBLIC ${LIBCURL_INCLUDE_DIRS})
-add_dependencies(mock wine_mock_archive wine_json)
-target_include_directories(mock PRIVATE ${WINE_MOCK_ARCHIVE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
+
+if (ENABLE_WINE)
+add_dependencies(mock wine_mock_archive wine_mock_json)
+endif()
set(NAME ${CMAKE_PROJECT_NAME}_mock)
add_executable(${NAME} ${SOURCES})
diff --git a/src/mock/libcurl.c b/src/mock/libcurl.c
index 359b15c..308e5e1 100644
--- a/src/mock/libcurl.c
+++ b/src/mock/libcurl.c
@@ -5,8 +5,10 @@
#include "../defines.h"
+#ifdef WINE_ENABLED
#include "wine_mock_tar_xz.h"
#include "wine_json.h"
+#endif
typedef size_t (*callback_t)(const void*, size_t, size_t, void*);
typedef int (*xfercallback_t)(void*, curl_off_t, curl_off_t, curl_off_t, curl_off_t);
@@ -89,6 +91,7 @@ CURLcode curl_easy_perform(UNUSED CURL *easy_handle)
size_t output_size = 0;
debug_printf("[MOCK] %s(...)\n", __func__);
+#ifdef WINE_ENABLED
if (!strcmp(url, WINE_API))
{
output = wine_json;
@@ -99,6 +102,7 @@ CURLcode curl_easy_perform(UNUSED CURL *easy_handle)
output = wine_mock_tar_xz;
output_size = wine_mock_tar_xz_size;
}
+#endif
if (output && data && callbackfunc)
{
diff --git a/src/mock/wine/CMakeLists.txt b/src/mock/wine/CMakeLists.txt
index 3418089..dab4d77 100644
--- a/src/mock/wine/CMakeLists.txt
+++ b/src/mock/wine/CMakeLists.txt
@@ -12,7 +12,6 @@ add_executable(wine_mock ${WINE_SOURCES})
set_target_properties(wine_mock PROPERTIES OUTPUT_NAME "wine")
target_compile_options(wine_mock PUBLIC ${CFLAGS})
-
set(WINE_MOCK_ARCHIVE_FILE_NAME "wine-mock.tar.xz")
set(WINE_MOCK_ARCHIVE_FILE "${WINE_MOCK_ARCHIVE_DIR}/${WINE_MOCK_ARCHIVE_FILE_NAME}")
string(REGEX REPLACE "\\.| |-" "_" WINE_MOCK_ARCHIVE_FILE_NAME ${WINE_MOCK_ARCHIVE_FILE_NAME})