CMake/Tests/CMakeTests/FileUploadTest.cmake.in
Brad King 14c771530a Tests: Fix file:// URLs given to curl
Since upstream curl commit curl-7_52_0~131 (URL-parser: for
file://[host]/ URLs, the [host] must be localhost, 2016-11-11) we can no
longer use URLs of the form `file://c:/...` on Windows.  These worked
only accidentally before.  Use `file:///c:/...` instead.
2017-02-10 13:10:07 -05:00

53 lines
1.5 KiB
CMake

file(REMOVE_RECURSE "@CMAKE_CURRENT_BINARY_DIR@/uploads")
if(EXISTS "@CMAKE_CURRENT_BINARY_DIR@/uploads/file1.png")
message(FATAL_ERROR "error: file1.png exists - should have been deleted")
endif()
if(EXISTS "@CMAKE_CURRENT_BINARY_DIR@/uploads/file2.png")
message(FATAL_ERROR "error: file2.png exists - should have been deleted")
endif()
file(MAKE_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@/uploads")
set(filename "@CMAKE_CURRENT_SOURCE_DIR@/FileDownloadInput.png")
if(NOT "@CMAKE_CURRENT_BINARY_DIR@" MATCHES "^/")
set(slash /)
endif()
set(urlbase "file://${slash}@CMAKE_CURRENT_BINARY_DIR@/uploads")
message(STATUS "FileUpload:1")
file(UPLOAD
${filename}
${urlbase}/file1.png
TIMEOUT 2
)
message(STATUS "FileUpload:2")
file(UPLOAD
${filename}
${urlbase}/file2.png
STATUS status
LOG log
SHOW_PROGRESS
)
execute_process(COMMAND ${CMAKE_COMMAND} -E md5sum
"@CMAKE_CURRENT_BINARY_DIR@/uploads/file1.png"
OUTPUT_VARIABLE sum1
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT sum1 MATCHES "^d16778650db435bda3a8c3435c3ff5d1 .*/uploads/file1.png$")
message(FATAL_ERROR "file1.png did not upload correctly (sum1='${sum1}')")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E md5sum
"@CMAKE_CURRENT_BINARY_DIR@/uploads/file2.png"
OUTPUT_VARIABLE sum2
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT sum2 MATCHES "^d16778650db435bda3a8c3435c3ff5d1 .*/uploads/file2.png$")
message(FATAL_ERROR "file2.png did not upload correctly (sum2='${sum2}')")
endif()
message(STATUS "log='${log}'")
message(STATUS "status='${status}'")
message(STATUS "DONE")