diff options
Diffstat (limited to 'tests/manual/cmake')
-rw-r--r-- | tests/manual/cmake/test_copy_file_if_different_command/CMakeLists.txt | 76 | ||||
-rw-r--r-- | tests/manual/cmake/test_copy_file_if_different_command/main.cpp | 36 |
2 files changed, 112 insertions, 0 deletions
diff --git a/tests/manual/cmake/test_copy_file_if_different_command/CMakeLists.txt b/tests/manual/cmake/test_copy_file_if_different_command/CMakeLists.txt new file mode 100644 index 0000000000..7e00b98888 --- /dev/null +++ b/tests/manual/cmake/test_copy_file_if_different_command/CMakeLists.txt @@ -0,0 +1,76 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +# How to run the test: +# 1. Create the build directory, e.g. /home/user/build_test_copy_file_if_different +# 2. cd /home/user/build_test_copy_file_if_different +# 3. /path/to/Qt/bin/qt-cmake /path/to/Qt/Sources/qtbase/tests/manual/cmake/test_copy_file_if_different_command +# 4. cmake --build . --parallel +# 5. ctest +cmake_minimum_required(VERSION 3.16) + +project(test_copy_file_if_different_command + LANGUAGES CXX +) + +if(NOT CMAKE_HOST_WIN32) + message("Test only applicable for WIN32 platform. Nothing to do.") + return() +endif() + +if(CMAKE_CROSSCOMPILING) + message("Test should only be run on host system. Crosscompiling is not supported.") + return() +endif() + +find_program(fsutil NAMES fsutil fsutil.exe) +if(NOT fsutil) + message(WARNING "Unable to find 'fsutil' executable. Skipping the test") + return() +endif() + +find_package(Qt6 REQUIRED COMPONENTS Core) + +function(test_copy_file_command output_file test_data_base_name size) + set(testdatasrc1 "${CMAKE_CURRENT_BINARY_DIR}/${test_data_base_name}1.bin") + set(testdatasrc2 "${CMAKE_CURRENT_BINARY_DIR}/${test_data_base_name}2.bin") + set(testdatadst "${CMAKE_CURRENT_BINARY_DIR}/${test_data_base_name}.bin") + + # Remove existing data first + file(REMOVE "${testdatasrc1}" "${testdatasrc2}" "${testdatadst}") + + file(TO_NATIVE_PATH "${testdatasrc1}" native_testdatasrc) + execute_process(COMMAND ${fsutil} file createNew "${native_testdatasrc}" ${size} + RESULT_VARIABLE result) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Unable to allocate file ${native_testdatasrc}" + " of size ${size} for test" + ) + endif() + + execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${testdatasrc1}" "${testdatasrc2}" + RESULT_VARIABLE result) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Unable to copy test data from ${testdatasrc1} to ${testdatasrc2}") + endif() + + foreach(src_file_num RANGE 1 2) + set(src_file "${testdatasrc${src_file_num}}") + file(APPEND "${src_file}" "${src_file_num}") + _qt_internal_copy_file_if_different_command(copy_command "${src_file}" "${testdatadst}") + execute_process(COMMAND ${copy_command} RESULT_VARIABLE result) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Unable to execute the copy command ${copy_command}") + endif() + endforeach() + + set(${output_file} "${testdatadst}" PARENT_SCOPE) +endfunction() + +test_copy_file_command(output_file1K testdata1K 1024) +test_copy_file_command(output_file2GB testdata2GB 2147483648) + +add_executable(test_copy_if_different_command main.cpp) + +enable_testing() +add_test(NAME "test_copy_if_different_command" COMMAND test_copy_if_different_command "${output_file1K}" "${output_file2GB}") diff --git a/tests/manual/cmake/test_copy_file_if_different_command/main.cpp b/tests/manual/cmake/test_copy_file_if_different_command/main.cpp new file mode 100644 index 0000000000..eeb641a36b --- /dev/null +++ b/tests/manual/cmake/test_copy_file_if_different_command/main.cpp @@ -0,0 +1,36 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <fstream> +#include <iostream> + +int checkFileLastByte(const std::string &filename, std::fstream::off_type offset) +{ + std::ifstream file(filename, std::ios_base::in); + if (!file.is_open()) { + std::cerr << "Unable to open test data file: " << filename << std::endl; + return 1; + } + file.seekg(offset, std::ios_base::beg); + char data = 0; + file.read(&data, sizeof(data)); + if (data != '2') { // We always expect it's the second copy of the file + std::cerr << "Invalid data inside the file: " << filename << std::endl; + return 2; + } + + return 0; +}; + +int main(int argc, char *argv[]) +{ + if (argc != 3) { + std::cerr << "Test requires exact 2 arguments that point to the test data" << std::endl; + return 1; + } + + int result = checkFileLastByte(argv[1], 1024); + if (result != 0) + return result; + return checkFileLastByte(argv[2], 2147483648); +} |