| 1 |
# Copyright (C) 2024 The Qt Company Ltd. |
| 2 |
# SPDX-License-Identifier: BSD-3-Clause |
| 3 |
|
| 4 |
cmake_minimum_required(VERSION 3.16) |
| 5 |
project(test) |
| 6 |
|
| 7 |
include(../test_qt_add_ui_common/RunCMake.cmake) |
| 8 |
include(../test_qt_add_ui_common/functions.cmake) |
| 9 |
|
| 10 |
get_generators(generators) |
| 11 |
|
| 12 |
foreach(generator IN ITEMS ${generators}) |
| 13 |
message(STATUS "Running tests for generator: ${generator}") |
| 14 |
is_multi_config(${generator} multi_config_out) |
| 15 |
if(multi_config_out) |
| 16 |
set(configs "Debug" "Release") |
| 17 |
else() |
| 18 |
set(configs "single_config") |
| 19 |
endif() |
| 20 |
|
| 21 |
foreach(config IN ITEMS ${configs}) |
| 22 |
if("${config}" STREQUAL "single_config") |
| 23 |
set(config_path "") |
| 24 |
set(config_arg "") |
| 25 |
else() |
| 26 |
set(config_path "_${config}") |
| 27 |
set(config_arg "${config}") |
| 28 |
endif() |
| 29 |
|
| 30 |
# Test case: Check whether api sets warning against AUTOUIC activation. |
| 31 |
# Expect 1: Printing of the error message and failure of the build. |
| 32 |
string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" |
| 33 |
"test_qt_add_ui_common/uic_test") |
| 34 |
string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" |
| 35 |
"uic_warning_test${config_path}-build") |
| 36 |
run_cmake_configure(SOURCE_DIR "${test_source_dir}" |
| 37 |
BUILD_DIR "${test_build_dir}" |
| 38 |
GENERATOR "${generator}" |
| 39 |
CLEAN_FIRST |
| 40 |
ADDITIONAL_ARGS "-DCMAKE_AUTOUIC=ON" |
| 41 |
OUTPUT_VARIABLE cmake_output |
| 42 |
ERROR_VARIABLE cmake_error |
| 43 |
RESULT_VARIABLE cmake_result) |
| 44 |
if(NOT cmake_result EQUAL 0) |
| 45 |
message(FATAL_ERROR "cmake_output: ${cmake_output}\ncmake_error: " |
| 46 |
"${cmake_error}\nFAIL: \"uic_warning_test\" test in " |
| 47 |
"${CMAKE_CURRENT_BINARY_DIR}/uic_warning_test${config_path}-" |
| 48 |
"build failed to configure") |
| 49 |
else() |
| 50 |
message(STATUS "PASS: \"uic_warning_test\" test in " |
| 51 |
"${CMAKE_CURRENT_BINARY_DIR}/uic_warning_test${config_path}-" |
| 52 |
"build was configured successfully") |
| 53 |
endif() |
| 54 |
|
| 55 |
string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" |
| 56 |
"uic_warning_test${config_path}-build") |
| 57 |
run_cmake_build( |
| 58 |
BUILD_DIR "${test_build_dir}" |
| 59 |
VERBOSE ON |
| 60 |
CONFIG "${config_arg}" |
| 61 |
OUTPUT_VARIABLE cmake_build_output |
| 62 |
RESULT_VARIABLE cmake_build_result) |
| 63 |
if(NOT cmake_build_result EQUAL 0) |
| 64 |
message(STATUS "PASS: \"uic_warning_test\" test in " |
| 65 |
"${CMAKE_CURRENT_BINARY_DIR}/uic_warning_test${config_path}" |
| 66 |
"-build failed to build") |
| 67 |
else() |
| 68 |
message(FATAL_ERROR "FAIL: \"uic_warning_test\" test in " |
| 69 |
"${CMAKE_CURRENT_BINARY_DIR}/uic_warning_test${config_path}-" |
| 70 |
"build was built successfully") |
| 71 |
endif() |
| 72 |
expect_string_contains("${cmake_build_output}" "has \"AUTOUIC\" enabled" |
| 73 |
SUCCESS_MESSAGE "\"uic_warning_test\" test in \ |
| 74 |
${CMAKE_CURRENT_BINARY_DIR}/uic_warning_test${config_path}-build \ |
| 75 |
has \"has AUTOUIC enabled\"" |
| 76 |
FAILURE_MESSAGE "\"uic_warning_test\" test in \ |
| 77 |
${CMAKE_CURRENT_BINARY_DIR}/uic_warning_test${config_path}-build \ |
| 78 |
does not have \"has AUTOUIC enabled\"") |
| 79 |
|
| 80 |
|
| 81 |
if("${generator}" MATCHES "Ninja") |
| 82 |
# Test case: If INCLUDE_PREFIX is changed without changing the |
| 83 |
# corresponding include path in the source file and Ninja generator |
| 84 |
# is used, this casues the double build issue. |
| 85 |
# Note: Only happens in Ninja generator. |
| 86 |
# Expect 1: Failure of the build in the first build. |
| 87 |
string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" |
| 88 |
"test_qt_add_ui_common/uic_test") |
| 89 |
string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" |
| 90 |
"uic_double_build_test${config_path}-build") |
| 91 |
run_cmake_configure(SOURCE_DIR "${test_source_dir}" |
| 92 |
BUILD_DIR "${test_build_dir}" |
| 93 |
GENERATOR "${generator}" |
| 94 |
CLEAN_FIRST |
| 95 |
ADDITIONAL_ARGS "-DMAINWINDOW_UI_PATH=sub1/sub2/sub3/" |
| 96 |
"-DDO_NOT_GENERATE_FILE=ON" |
| 97 |
OUTPUT_VARIABLE cmake_output |
| 98 |
ERROR_VARIABLE cmake_error |
| 99 |
RESULT_VARIABLE cmake_result) |
| 100 |
|
| 101 |
if(NOT cmake_result EQUAL 0) |
| 102 |
message(FATAL_ERROR "cmake_output: ${cmake_output}\ncmake_error" |
| 103 |
": ${cmake_error}\nFAIL: \"uic_double_build_test\" test in " |
| 104 |
"${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" |
| 105 |
"${config_path}-build failed to configure") |
| 106 |
else() |
| 107 |
message(STATUS "PASS: \"uic_double_build_test\" test in " |
| 108 |
"${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" |
| 109 |
"${config_path}-build was configured successfully") |
| 110 |
endif() |
| 111 |
|
| 112 |
string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" |
| 113 |
"uic_double_build_test${config_path}-build") |
| 114 |
run_cmake_build( |
| 115 |
BUILD_DIR "${test_build_dir}" |
| 116 |
VERBOSE ON |
| 117 |
CONFIG "${config_arg}" |
| 118 |
OUTPUT_VARIABLE cmake_build_output |
| 119 |
RESULT_VARIABLE cmake_build_result) |
| 120 |
|
| 121 |
if(NOT cmake_build_result EQUAL 0) |
| 122 |
message(FATAL_ERROR "cmake_build_output: ${cmake_build_output}" |
| 123 |
"FAIL: \"uic_double_build_test\" test in " |
| 124 |
"${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" |
| 125 |
"${config_path}-build failed to build in the first build") |
| 126 |
else() |
| 127 |
message(STATUS "PASS: \"uic_double_build_test\" test in " |
| 128 |
"${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" |
| 129 |
"${config_path}-build was built successfully in the first " |
| 130 |
"build") |
| 131 |
endif() |
| 132 |
|
| 133 |
string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" |
| 134 |
"test_qt_add_ui_common/uic_test") |
| 135 |
string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" |
| 136 |
"uic_double_build_test${config_path}-build") |
| 137 |
run_cmake_configure(SOURCE_DIR "${test_source_dir}" |
| 138 |
BUILD_DIR "${test_build_dir}" |
| 139 |
GENERATOR "${generator}" |
| 140 |
# We change the INCLUDE_PREFIX here. |
| 141 |
ADDITIONAL_ARGS "-DMAINWINDOW_UI_PATH=sub1/sub2/sub/" |
| 142 |
"-DDO_NOT_GENERATE_FILE=ON" |
| 143 |
OUTPUT_VARIABLE cmake_output |
| 144 |
ERROR_VARIABLE cmake_error |
| 145 |
RESULT_VARIABLE cmake_result) |
| 146 |
|
| 147 |
if(NOT cmake_result EQUAL 0) |
| 148 |
message(FATAL_ERROR "cmake_output: ${cmake_output}\ncmake_error" |
| 149 |
":${cmake_error}\nFAIL: \"uic_double_build_test\" test in " |
| 150 |
"${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" |
| 151 |
"${config_path}-build failed to configure in the second " |
| 152 |
"build") |
| 153 |
else() |
| 154 |
message(STATUS "PASS: \"uic_double_build_test\" test in " |
| 155 |
"${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" |
| 156 |
"${config_path}-build was configured successfully in the " |
| 157 |
"second build") |
| 158 |
endif() |
| 159 |
|
| 160 |
string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" |
| 161 |
"uic_double_build_test${config_path}-build") |
| 162 |
run_cmake_build( |
| 163 |
BUILD_DIR "${test_build_dir}" |
| 164 |
VERBOSE ON |
| 165 |
CONFIG "${config_arg}" |
| 166 |
OUTPUT_VARIABLE cmake_build_output |
| 167 |
ERROR_VARIABLE cmake_build_error |
| 168 |
RESULT_VARIABLE cmake_build_result) |
| 169 |
|
| 170 |
if(NOT cmake_build_result EQUAL 0) |
| 171 |
message(STATUS "PASS: \"uic_double_build_test\" test in" |
| 172 |
"${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" |
| 173 |
"${config_path}-build failed to build in the first build " |
| 174 |
"after changing INCLUDE_PREFIX") |
| 175 |
else() |
| 176 |
message(FATAL_ERROR "cmake_build_output: ${cmake_build_output}" |
| 177 |
"\ncmake_build_error: ${cmake_build_error}\n" |
| 178 |
"FAIL: \"uic_double_build_test\" test in " |
| 179 |
"${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" |
| 180 |
"${config_path}-build was built successfully in the first " |
| 181 |
"build after changing INCLUDE_PREFIX") |
| 182 |
endif() |
| 183 |
|
| 184 |
set(expected_fail_string "No such file or directory|file not found") |
| 185 |
expect_string_contains(${cmake_build_output} |
| 186 |
"${expected_fail_string}" |
| 187 |
SUCCESS_MESSAGE "\"uic_double_build_test\" test in \ |
| 188 |
${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test${config_path}\ |
| 189 |
-build has \"ui_mainwindow.h: No such file or directory\" in \ |
| 190 |
the first build after changing INCLUDE_PREFIX" |
| 191 |
FAILURE_MESSAGE "\"uic_double_build_test\" test in \ |
| 192 |
${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test${config_path}\ |
| 193 |
-build does not have \"ui_mainwindow.h: No such file or \ |
| 194 |
directory\" in the first build after changing INCLUDE_PREFIX") |
| 195 |
|
| 196 |
endif() |
| 197 |
endforeach() |
| 198 |
endforeach() |
| 199 |
|