mirror of
https://github.com/darlinghq/lzfse.git
synced 2024-11-26 21:50:22 +00:00
Add some tests to verify the build.
This will just compress then decompress each file in src/, so it's hardly an exhaustive test, but it should at least verify that LZFSE basically works on the platform in question.
This commit is contained in:
parent
4a1bb533ef
commit
5ed60dd670
@ -95,3 +95,37 @@ if(NOT LZFSE_BUNDLE_MODE)
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
||||
install(FILES src/lzfse.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
endif()
|
||||
|
||||
# Tests
|
||||
|
||||
# If we're targeting Windows but not running on Windows, we need Wine
|
||||
# to run the tests...
|
||||
if(NOT LZFSE_DISABLE_TESTS)
|
||||
if(WIN32 AND NOT CMAKE_HOST_WIN32)
|
||||
find_program(LZFSE_WINE NAMES wine)
|
||||
|
||||
if(NOT LZFSE_WINE)
|
||||
message(STATUS "wine not found, disabling tests")
|
||||
set(LZFSE_DISABLE_TESTS TRUE)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT LZFSE_DISABLE_TESTS)
|
||||
include(CTest)
|
||||
enable_testing()
|
||||
|
||||
file(GLOB_RECURSE
|
||||
ROUNDTRIP_INPUTS
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
src/*)
|
||||
|
||||
foreach(INPUT ${ROUNDTRIP_INPUTS})
|
||||
add_test(NAME "${LZFSE_TEST_PREFIX}roundtrip/${INPUT}"
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
-DLZFSE_WRAPPER=${LZFSE_WINE}
|
||||
-DLZFSE_CLI=$<TARGET_FILE:lzfse_cli>
|
||||
-DINPUT=${CMAKE_CURRENT_SOURCE_DIR}/${INPUT}
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/tests/round-trip.cmake)
|
||||
endforeach()
|
||||
endif()
|
||||
|
53
tests/round-trip.cmake
Normal file
53
tests/round-trip.cmake
Normal file
@ -0,0 +1,53 @@
|
||||
get_filename_component(INPUT_NAME "${INPUT}" NAME)
|
||||
|
||||
set(LZFSE_TMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/test-tmp")
|
||||
set(COMPRESSED_FILE "${LZFSE_TMP_DIR}/${INPUT_NAME}.lzfse")
|
||||
set(DECOMPRESSED_FILE "${LZFSE_TMP_DIR}/${INPUT_NAME}")
|
||||
|
||||
file(MAKE_DIRECTORY "${LZFSE_TMP_DIR}")
|
||||
|
||||
if(EXISTS COMPRESSED_FILE)
|
||||
message(FATAL_ERROR "${COMPRESSED_FILE} exists")
|
||||
file(REMOVE ${COMPRESSED_FILE})
|
||||
endif()
|
||||
if(EXISTS DECOMPRESSED_FILE)
|
||||
message(FATAL_ERROR "${DECOMPRESSED_FILE} exists")
|
||||
file(REMOVE ${DECOMPRESSED_FILE})
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.."
|
||||
COMMAND ${LZFSE_WRAPPER} ${LZFSE_CLI} -encode -i ${INPUT} -o ${COMPRESSED_FILE}
|
||||
RESULT_VARIABLE result
|
||||
ERROR_VARIABLE result_stderr)
|
||||
if(result)
|
||||
message(FATAL_ERROR "Compression failed: ${result_stderr}")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.."
|
||||
COMMAND ${LZFSE_WRAPPER} ${LZFSE_CLI} -decode -i ${COMPRESSED_FILE} -o ${DECOMPRESSED_FILE}
|
||||
RESULT_VARIABLE result)
|
||||
if(result)
|
||||
message(FATAL_ERROR "Decompression failed")
|
||||
endif()
|
||||
|
||||
function(test_file_equality f1 f2)
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 2.8.7)
|
||||
file(SHA512 "${f1}" f1_cs)
|
||||
file(SHA512 "${f2}" f2_cs)
|
||||
if(NOT "${f1_cs}" STREQUAL "${f2_cs}")
|
||||
message(FATAL_ERROR "Files do not match")
|
||||
endif()
|
||||
else()
|
||||
file(READ "${f1}" f1_contents)
|
||||
file(READ "${f2}" f2_contents)
|
||||
if(NOT "${f1_contents}" STREQUAL "${f2_contents}")
|
||||
message(FATAL_ERROR "Files do not match")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
test_file_equality("${INPUT}" "${DECOMPRESSED_FILE}")
|
||||
file(REMOVE ${COMPRESSED_FILE})
|
||||
file(REMOVE ${DECOMPRESSED_FILE})
|
Loading…
Reference in New Issue
Block a user