| 1 |
# Copyright (C) 2022 The Qt Company Ltd. |
| 2 |
# SPDX-License-Identifier: BSD-3-Clause |
| 3 |
|
| 4 |
# This is an automatic test for the CMake configuration files. |
| 5 |
# To run it manually, |
| 6 |
# 1) mkdir build # Create a build directory |
| 7 |
# 2) cd build |
| 8 |
# 3) # Run cmake on this directory |
| 9 |
# `$qt_prefix/bin/qt-cmake ..` or `cmake -DCMAKE_PREFIX_PATH=/path/to/qt ..` |
| 10 |
# 4) ctest # Run ctest |
| 11 |
# 5) ctest -V -R test_add_translation_macro # Run single test |
| 12 |
# |
| 13 |
# The expected output is something like: |
| 14 |
# |
| 15 |
# Start 1: test_add_translation_macro |
| 16 |
# 1/2 Test #1: test_add_translation_macro ....... Passed 3.13 sec |
| 17 |
# Start 2: test_create_translation_macro |
| 18 |
# 2/2 Test #2: test_create_translation_macro .... Passed 3.64 sec |
| 19 |
# |
| 20 |
# |
| 21 |
# Note that if Qt is not installed, or if it is installed to a |
| 22 |
# non-standard prefix, the environment variable CMAKE_PREFIX_PATH |
| 23 |
# needs to be set to the installation prefix or build prefix of Qt |
| 24 |
# before running these tests. |
| 25 |
|
| 26 |
cmake_minimum_required(VERSION 3.16) |
| 27 |
|
| 28 |
project(qttools_cmake_tests_linguist) |
| 29 |
|
| 30 |
enable_testing() |
| 31 |
|
| 32 |
set(required_packages Core LinguistTools) |
| 33 |
|
| 34 |
# Setup the test when called as a completely standalone project. |
| 35 |
if(TARGET Qt6::Core) |
| 36 |
# Tests are built as part of the qtbase build tree. |
| 37 |
# Setup paths so that the Qt packages are found, similar to examples. |
| 38 |
qt_internal_set_up_build_dir_package_paths() |
| 39 |
endif() |
| 40 |
|
| 41 |
find_package(Qt6 REQUIRED COMPONENTS ${required_packages}) |
| 42 |
|
| 43 |
# Setup common test variables which were previously set by ctest_testcase_common.prf. |
| 44 |
set(CMAKE_MODULES_UNDER_TEST "${required_packages}") |
| 45 |
foreach(qt_package ${optional_packages}) |
| 46 |
set(package_name "${QT_CMAKE_EXPORT_NAMESPACE}${qt_package}") |
| 47 |
list(APPEND CMAKE_MODULES_UNDER_TEST "${qt_package}") |
| 48 |
endforeach() |
| 49 |
|
| 50 |
foreach(qt_package ${CMAKE_MODULES_UNDER_TEST}) |
| 51 |
if(${package_name}_FOUND) |
| 52 |
set(CMAKE_${qt_package}_MODULE_MAJOR_VERSION "${${package_name}_VERSION_MAJOR}") |
| 53 |
set(CMAKE_${qt_package}_MODULE_MINOR_VERSION "${${package_name}_VERSION_MINOR}") |
| 54 |
set(CMAKE_${qt_package}_MODULE_PATCH_VERSION "${${package_name}_VERSION_PATCH}") |
| 55 |
endif() |
| 56 |
endforeach() |
| 57 |
|
| 58 |
include("${_Qt6CTestMacros}") |
| 59 |
|
| 60 |
_qt_internal_test_expect_pass(test_add_translation_macro) |
| 61 |
_qt_internal_test_expect_pass(test_create_translation_macro) |
| 62 |
_qt_internal_test_expect_pass(test_create_translation_same_base_names) |
| 63 |
_qt_internal_test_expect_pass(test_translation_api |
| 64 |
BINARY "${CMAKE_COMMAND}" |
| 65 |
BINARY_ARGS -P "${CMAKE_CURRENT_SOURCE_DIR}/test_translation_api/post_build_check.cmake" |
| 66 |
) |
| 67 |
_qt_internal_test_expect_pass(test_i18n_auto_ts_file_names) |
| 68 |
_qt_internal_test_expect_pass(test_i18n_exclusion) |
| 69 |
_qt_internal_test_expect_pass(test_i18n_filter_autogen_files) |
| 70 |
_qt_internal_test_expect_pass(test_i18n_source_language |
| 71 |
BINARY "${CMAKE_COMMAND}" |
| 72 |
BINARY_ARGS -P "${CMAKE_CURRENT_SOURCE_DIR}/test_i18n_source_language/post_build_check.cmake" |
| 73 |
) |
| 74 |
if(NOT CMAKE_CROSSCOMPILING) |
| 75 |
_qt_internal_test_expect_pass(test_i18n_find_package_in_subdir BINARY app1) |
| 76 |
_qt_internal_test_expect_pass(test_i18n_merge_qt_translations BINARY myapp) |
| 77 |
_qt_internal_test_expect_pass(test_i18n_merge_qt_translations_language_match BINARY myapp) |
| 78 |
_qt_internal_test_expect_pass(test_i18n_merge_qt_translations_select_catalogs BINARY myapp) |
| 79 |
_qt_internal_test_expect_pass(test_i18n_subdir BINARY app1) |
| 80 |
_qt_internal_test_expect_pass(test_i18n_subdir2 BINARY app1) |
| 81 |
|
| 82 |
if(APPLE) |
| 83 |
_qt_internal_test_expect_pass(test_i18n_subdir |
| 84 |
TESTNAME test_i18n_subdir_xcode |
| 85 |
GENERATOR Xcode |
| 86 |
MAKE_PROGRAM xcodebuild |
| 87 |
BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/test_i18n_subdir_xcode" |
| 88 |
) |
| 89 |
|
| 90 |
_qt_internal_test_expect_pass(test_i18n_subdir2 |
| 91 |
TESTNAME test_i18n_subdir2_xcode |
| 92 |
GENERATOR Xcode |
| 93 |
MAKE_PROGRAM xcodebuild |
| 94 |
BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/test_i18n_subdir2_xcode") |
| 95 |
endif() |
| 96 |
endif() |