diff options
Diffstat (limited to 'tests/auto/cmake')
6 files changed, 83 insertions, 2 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 4fb6c24d8d..a94f1a51fe 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -112,6 +112,10 @@ if (CMAKE_GENERATOR STREQUAL Ninja AND UNIX AND NOT WIN32) BINARY "tests/test_QFINDTESTDATA" SIMULATE_IN_SOURCE ) + _qt_internal_test_expect_pass(test_QT_TESTCASE_BUILDDIR + BINARY "test_qt_testcase_builddir" + SIMULATE_IN_SOURCE + ) endif() if (NOT NO_DBUS) diff --git a/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt b/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt index 6515aa8020..df91a7d84b 100644 --- a/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt +++ b/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt @@ -2,5 +2,3 @@ add_executable(test_QFINDTESTDATA WIN32 main.cpp) target_link_libraries(test_QFINDTESTDATA Qt::Test) -target_compile_definitions(test_QFINDTESTDATA PRIVATE QT_TESTCASE_BUILDDIR="${CMAKE_CURRENT_BINARY_DIR}") -target_compile_definitions(test_QFINDTESTDATA PRIVATE QT_TESTCASE_SOURCEDIR="${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/CMakeLists.txt b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/CMakeLists.txt new file mode 100644 index 0000000000..f6fe597def --- /dev/null +++ b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/CMakeLists.txt @@ -0,0 +1,20 @@ +# The test is simply testing that manual specification of QT_TESTCASE_BUILDDIR works, +# despite the weird paths. +cmake_minimum_required(VERSION 3.14) + +project(test_qt_testcase_builddir) + +find_package(Qt6Test REQUIRED) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) +add_executable(test_qt_testcase_builddir WIN32 main.cpp) + +target_link_libraries(test_qt_testcase_builddir Qt::Test) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/testdata.txt" + "${CMAKE_CURRENT_BINARY_DIR}/level1/level2/testdata_build.txt" + COPYONLY +) +set_target_properties(test_qt_testcase_builddir PROPERTIES + QT_TESTCASE_BUILDDIR "${CMAKE_CURRENT_BINARY_DIR}/level1/level2" +) diff --git a/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/data/testdata.txt b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/data/testdata.txt new file mode 100644 index 0000000000..e846386066 --- /dev/null +++ b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/data/testdata.txt @@ -0,0 +1 @@ +This is the test data found in QT_TESTCASE_SOURCEDIR. diff --git a/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/main.cpp b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/main.cpp new file mode 100644 index 0000000000..8965e0dac3 --- /dev/null +++ b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/main.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QCoreApplication> +#include <QtTest/QTest> +#include <QDebug> + +class TestClass : public QObject +{ + Q_OBJECT +public: + TestClass(QObject *parent = nullptr) { } + +private slots: + void doTest(); +}; + +void TestClass::doTest() +{ + QFile fsrc(QFINDTESTDATA("data/testdata.txt")); + QVERIFY(fsrc.open(QFile::ReadOnly)); + QCOMPARE(fsrc.readAll().trimmed(), + QByteArrayLiteral("This is the test data found in QT_TESTCASE_SOURCEDIR.")); + + QFile fbuild(QFINDTESTDATA("level2/testdata_build.txt")); + QVERIFY(fbuild.open(QFile::ReadOnly)); + QCOMPARE(fbuild.readAll().trimmed(), + QByteArrayLiteral("This is the test data found in custom QT_TESTCASE_BUILDDIR.")); +} + +QTEST_MAIN(TestClass) +#include "main.moc" diff --git a/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/testdata.txt b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/testdata.txt new file mode 100644 index 0000000000..96a369071b --- /dev/null +++ b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/testdata.txt @@ -0,0 +1 @@ +This is the test data found in custom QT_TESTCASE_BUILDDIR. |