diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2020-09-14 18:48:07 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2020-09-23 18:10:40 (GMT) |
commit | 4c6e5cd0fae57684411d6bf814b4fcc4434c1f50 (patch) | |
tree | 64307ab060a02102e6861008fba72340ad2ba3ea /Tests/CMakeGUI/CMakeGUITest.cxx | |
parent | 41e223deb37767d9beb8c4462b8b8df88ba2dedf (diff) | |
download | CMake-4c6e5cd0fae57684411d6bf814b4fcc4434c1f50.zip CMake-4c6e5cd0fae57684411d6bf814b4fcc4434c1f50.tar.gz CMake-4c6e5cd0fae57684411d6bf814b4fcc4434c1f50.tar.bz2 |
Tests: Add some basic tests for CMake GUI
Diffstat (limited to 'Tests/CMakeGUI/CMakeGUITest.cxx')
-rw-r--r-- | Tests/CMakeGUI/CMakeGUITest.cxx | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/Tests/CMakeGUI/CMakeGUITest.cxx b/Tests/CMakeGUI/CMakeGUITest.cxx new file mode 100644 index 0000000..a7a5d17 --- /dev/null +++ b/Tests/CMakeGUI/CMakeGUITest.cxx @@ -0,0 +1,89 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "CMakeGUITest.h" + +#include <QApplication> +#include <QEventLoop> +#include <QSettings> +#include <QString> +#include <QStringList> +#include <QTimer> +#include <QtGlobal> +#include <QtTest> + +#include "CMakeSetupDialog.h" + +namespace { +void loopSleep(int msecs = 100) +{ + QEventLoop loop; + QTimer::singleShot(msecs, &loop, &QEventLoop::quit); + loop.exec(); +} +} + +CMakeGUITest::CMakeGUITest(CMakeSetupDialog* window, QObject* parent) + : QObject(parent) + , m_window(window) +{ +} + +void CMakeGUITest::sourceBinaryArgs() +{ + QFETCH(QString, sourceDir); + QFETCH(QString, binaryDir); + + // Wait a bit for everything to update + loopSleep(); + + QCOMPARE(this->m_window->SourceDirectory->text(), sourceDir); + QCOMPARE(this->m_window->BinaryDirectory->currentText(), binaryDir); +} + +void CMakeGUITest::sourceBinaryArgs_data() +{ + QTest::addColumn<QString>("sourceDir"); + QTest::addColumn<QString>("binaryDir"); + + QTest::newRow("sourceAndBinaryDir") + << CMakeGUITest_BINARY_DIR "/sourceBinaryArgs-sourceAndBinaryDir/src" + << CMakeGUITest_BINARY_DIR "/sourceBinaryArgs-sourceAndBinaryDir/build"; + QTest::newRow("sourceAndBinaryDirRelative") << CMakeGUITest_BINARY_DIR + "/sourceBinaryArgs-sourceAndBinaryDirRelative/src" + << CMakeGUITest_BINARY_DIR + "/sourceBinaryArgs-sourceAndBinaryDirRelative/build"; + QTest::newRow("sourceDir") + << CMakeGUITest_BINARY_DIR "/sourceBinaryArgs-sourceDir/src" + << CMakeGUITest_BINARY_DIR "/sourceBinaryArgs-sourceDir"; + QTest::newRow("binaryDir") + << CMakeGUITest_BINARY_DIR "/sourceBinaryArgs-binaryDir/src" + << CMakeGUITest_BINARY_DIR "/sourceBinaryArgs-binaryDir/build"; + QTest::newRow("noExist") << "" + << ""; + QTest::newRow("noExistConfig") + << "" + << CMakeGUITest_BINARY_DIR "/sourceBinaryArgs-noExistConfig/oldbuild"; + QTest::newRow("noExistConfigExists") + << CMakeGUITest_BINARY_DIR "/sourceBinaryArgs-noExistConfigExists/src" + << CMakeGUITest_BINARY_DIR "/sourceBinaryArgs-noExistConfigExists/build"; +} + +void SetupDefaultQSettings() +{ + QSettings::setDefaultFormat(QSettings::IniFormat); + QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, + QString::fromLocal8Bit(qgetenv("CMake_GUI_CONFIG_DIR"))); +} + +int CMakeGUIExec(CMakeSetupDialog* window) +{ + auto nameArray = qgetenv("CMake_GUI_TEST_NAME"); + auto name = QString::fromLocal8Bit(nameArray); + if (name.isEmpty()) { + return QApplication::exec(); + } + + QStringList args{ "CMakeGUITest", name }; + CMakeGUITest obj(window); + return QTest::qExec(&obj, args); +} |