From 048bd8e656f56bc522a78f65729b681fe98a16a8 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 24 Aug 2020 09:44:41 +0200 Subject: [PATCH] Fixed #6442: Use cmake to provide source directory for test pem (cherry picked from commit 70881d39578177d3229f01011f62021b1b069cb5) --- libfreerdp/crypto/test/CMakeLists.txt | 4 ++++ libfreerdp/crypto/test/Test_x509_cert_info.c | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/libfreerdp/crypto/test/CMakeLists.txt b/libfreerdp/crypto/test/CMakeLists.txt index 3df0619..28c624a 100644 --- a/libfreerdp/crypto/test/CMakeLists.txt +++ b/libfreerdp/crypto/test/CMakeLists.txt @@ -17,6 +17,10 @@ include_directories(${OPENSSL_INCLUDE_DIR}) add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) +file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} TEST_PATH) +string(REGEX REPLACE "\\\\" "\\\\\\\\" TEST_PATH ${TEST_PATH}) + +add_definitions(-DTEST_SOURCE_DIR="${TEST_PATH}") target_link_libraries(${MODULE_NAME} freerdp winpr ${OPENSSL_LIBRARIES}) set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}") diff --git a/libfreerdp/crypto/test/Test_x509_cert_info.c b/libfreerdp/crypto/test/Test_x509_cert_info.c index 4a7d6a5..b09619f 100644 --- a/libfreerdp/crypto/test/Test_x509_cert_info.c +++ b/libfreerdp/crypto/test/Test_x509_cert_info.c @@ -33,6 +33,15 @@ static char* certificate_path(void) static const char dirsep = '/'; #endif static const char filename[] = "Test_x509_cert_info.pem"; +#ifdef TEST_SOURCE_DIR + const char* file = TEST_SOURCE_DIR; + const size_t flen = sizeof(filename) + sizeof(dirsep) + strlen(file) + sizeof(char); + char* result = calloc(1, flen); + if (!result) + return NULL; + _snprintf(result, flen - 1, "%s%c%s", file, dirsep, filename); + return result; +#else const char* file = __FILE__; const char* last_dirsep = strrchr(file, dirsep); @@ -52,6 +61,7 @@ static char* certificate_path(void) /* No dirsep => relative path in same directory */ return _strdup(filename); } +#endif } static const certificate_test_t certificate_tests[] = { -- 2.7.4