diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2020-09-29 10:17:47 -0400 |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2020-10-05 09:49:59 -0400 |
commit | a4382f72d7fb924f9649ae352d70a36df2d662a8 (patch) | |
tree | 15855284a47a3f3ab4a14f945559266ebabbb0a5 /Tests | |
parent | 8617479061039e2b357b7efc922f1b88648dce42 (diff) | |
download | cmake-a4382f72d7fb924f9649ae352d70a36df2d662a8.tar.gz |
CMake GUI: Add presets functionality
Diffstat (limited to 'Tests')
17 files changed, 870 insertions, 0 deletions
diff --git a/Tests/CMakeGUI/CMakeGUITest.cmake b/Tests/CMakeGUI/CMakeGUITest.cmake index b60ec35426..2c6baf3ab1 100644 --- a/Tests/CMakeGUI/CMakeGUITest.cmake +++ b/Tests/CMakeGUI/CMakeGUITest.cmake @@ -27,6 +27,10 @@ function(run_cmake_gui_test name) if(EXISTS "${_cmakelists_in}") configure_file("${_cmakelists_in}" "${_workdir}/src/CMakeLists.txt" @ONLY) endif() + set(_cmakepresets_in "${_srcdir}/CMakePresets.json.in") + if(EXISTS "${_cmakepresets_in}") + configure_file("${_cmakepresets_in}" "${_workdir}/src/CMakePresets.json" @ONLY) + endif() if(_rcgt_DO_CONFIGURE) if(NOT _rcgt_GENERATOR) set(_rcgt_GENERATOR "${CMakeGUITest_GENERATOR}") @@ -118,3 +122,37 @@ set(ENV{KEPT_VARIABLE} "Kept variable") set(ENV{CHANGED_VARIABLE} "This variable will be changed") set(ENV{REMOVED_VARIABLE} "Removed variable") run_cmake_gui_test(environment) + +run_cmake_gui_test(presetArg:preset + ARGS + -S "${CMakeGUITest_BINARY_DIR}/presetArg-preset/src" + "--preset=ninja" + ) +run_cmake_gui_test(presetArg:presetBinary + ARGS + -S "${CMakeGUITest_BINARY_DIR}/presetArg-presetBinary/src" + -B "${CMakeGUITest_BINARY_DIR}/presetArg-presetBinary/build" + "--preset=ninja" + ) +run_cmake_gui_test(presetArg:presetBinaryChange + ARGS + -S "${CMakeGUITest_BINARY_DIR}/presetArg-presetBinaryChange/src" + -B "${CMakeGUITest_BINARY_DIR}/presetArg-presetBinaryChange/build" + "--preset=ninja" + ) +run_cmake_gui_test(presetArg:noPresetBinaryChange + ARGS + -S "${CMakeGUITest_BINARY_DIR}/presetArg-noPresetBinaryChange/src" + -B "${CMakeGUITest_BINARY_DIR}/presetArg-noPresetBinaryChange/build" + ) +run_cmake_gui_test(presetArg:presetConfigExists + ARGS + -S "${CMakeGUITest_BINARY_DIR}/presetArg-presetConfigExists/src" + "--preset=ninja" + ) +run_cmake_gui_test(presetArg:noExist + ARGS + -S "${CMakeGUITest_BINARY_DIR}/presetArg-noExist/src" + "--preset=noExist" + ) +run_cmake_gui_test(changingPresets) diff --git a/Tests/CMakeGUI/CMakeGUITest.cxx b/Tests/CMakeGUI/CMakeGUITest.cxx index 25a92a5347..5a6bec36f6 100644 --- a/Tests/CMakeGUI/CMakeGUITest.cxx +++ b/Tests/CMakeGUI/CMakeGUITest.cxx @@ -5,6 +5,10 @@ #include "QCMake.h" #include <QApplication> #include <QEventLoop> +#include <QFile> +#include <QJsonArray> +#include <QJsonDocument> +#include <QJsonObject> #include <QMessageBox> #include <QSettings> #include <QString> @@ -18,6 +22,9 @@ #include "CatchShow.h" #include "FirstConfigure.h" +using WindowSetupHelper = std::function<void(CMakeSetupDialog*)>; +Q_DECLARE_METATYPE(WindowSetupHelper) + namespace { void loopSleep(int msecs = 500) { @@ -172,6 +179,264 @@ void CMakeGUITest::environment() QCOMPARE(penv.value("REMOVED_VARIABLE"), "Removed variable"); } +void CMakeGUITest::presetArg() +{ + QFETCH(WindowSetupHelper, setupFunction); + QFETCH(QString, presetName); + QFETCH(QString, sourceDir); + QFETCH(QString, binaryDir); + QFETCH(QCMakePropertyList, properties); + + if (setupFunction) { + setupFunction(this->m_window); + } + + // Wait a bit for everything to update + loopSleep(); + + QCOMPARE(this->m_window->Preset->presetName(), presetName); + QCOMPARE(this->m_window->SourceDirectory->text(), sourceDir); + QCOMPARE(this->m_window->BinaryDirectory->currentText(), binaryDir); + + auto actualProperties = + this->m_window->CacheValues->cacheModel()->properties(); + QCOMPARE(actualProperties.size(), properties.size()); + for (int i = 0; i < actualProperties.size(); ++i) { + // operator==() only compares Key, we need to compare Value and Type too + QCOMPARE(actualProperties[i].Key, properties[i].Key); + QCOMPARE(actualProperties[i].Value, properties[i].Value); + QCOMPARE(actualProperties[i].Type, properties[i].Type); + } +} + +namespace { +QCMakePropertyList makePresetProperties(const QString& name) +{ + return QCMakePropertyList{ + QCMakeProperty{ + /*Key=*/"FALSE_VARIABLE", + /*Value=*/false, + /*Strings=*/{}, + /*Help=*/"", + /*Type=*/QCMakeProperty::BOOL, + /*Advanced=*/false, + }, + QCMakeProperty{ + /*Key=*/"FILEPATH_VARIABLE", + /*Value=*/ + QString::fromLocal8Bit(CMakeGUITest_BINARY_DIR "/%1/src/CMakeLists.txt") + .arg(name), + /*Strings=*/{}, + /*Help=*/"", + /*Type=*/QCMakeProperty::FILEPATH, + /*Advanced=*/false, + }, + QCMakeProperty{ + /*Key=*/"ON_VARIABLE", + /*Value=*/true, + /*Strings=*/{}, + /*Help=*/"", + /*Type=*/QCMakeProperty::BOOL, + /*Advanced=*/false, + }, + QCMakeProperty{ + /*Key=*/"PATH_VARIABLE", + /*Value=*/ + QString::fromLocal8Bit(CMakeGUITest_BINARY_DIR "/%1/src").arg(name), + /*Strings=*/{}, + /*Help=*/"", + /*Type=*/QCMakeProperty::PATH, + /*Advanced=*/false, + }, + QCMakeProperty{ + /*Key=*/"STRING_VARIABLE", + /*Value=*/"String value", + /*Strings=*/{}, + /*Help=*/"", + /*Type=*/QCMakeProperty::STRING, + /*Advanced=*/false, + }, + QCMakeProperty{ + /*Key=*/"UNINITIALIZED_VARIABLE", + /*Value=*/"Uninitialized value", + /*Strings=*/{}, + /*Help=*/"", + /*Type=*/QCMakeProperty::STRING, + /*Advanced=*/false, + }, + }; +} +} + +void CMakeGUITest::presetArg_data() +{ + QTest::addColumn<WindowSetupHelper>("setupFunction"); + QTest::addColumn<QString>("presetName"); + QTest::addColumn<QString>("sourceDir"); + QTest::addColumn<QString>("binaryDir"); + QTest::addColumn<QCMakePropertyList>("properties"); + + QTest::newRow("preset") << WindowSetupHelper{} << "ninja" + << CMakeGUITest_BINARY_DIR "/presetArg-preset/src" + << CMakeGUITest_BINARY_DIR + "/presetArg-preset/src/build" + << makePresetProperties("presetArg-preset"); + QTest::newRow("presetBinary") + << WindowSetupHelper{} << "ninja" + << CMakeGUITest_BINARY_DIR "/presetArg-presetBinary/src" + << CMakeGUITest_BINARY_DIR "/presetArg-presetBinary/build" + << makePresetProperties("presetArg-presetBinary"); + QTest::newRow("presetBinaryChange") + << WindowSetupHelper{ [](CMakeSetupDialog* window) { + loopSleep(); + window->Preset->setPresetName("ninja2"); + } } + << "ninja2" << CMakeGUITest_BINARY_DIR "/presetArg-presetBinaryChange/src" + << CMakeGUITest_BINARY_DIR "/presetArg-presetBinaryChange/src/build" + << makePresetProperties("presetArg-presetBinaryChange"); + QTest::newRow("noPresetBinaryChange") + << WindowSetupHelper{ [](CMakeSetupDialog* window) { + loopSleep(); + window->Preset->setPresetName("ninja"); + } } + << "ninja" << CMakeGUITest_BINARY_DIR "/presetArg-noPresetBinaryChange/src" + << CMakeGUITest_BINARY_DIR "/presetArg-noPresetBinaryChange/src/build" + << makePresetProperties("presetArg-noPresetBinaryChange"); + QTest::newRow("presetConfigExists") + << WindowSetupHelper{} << "ninja" + << CMakeGUITest_BINARY_DIR "/presetArg-presetConfigExists/src" + << CMakeGUITest_BINARY_DIR "/presetArg-presetConfigExists/src/build" + << makePresetProperties("presetArg-presetConfigExists"); + QTest::newRow("noExist") << WindowSetupHelper{} << QString{} + << CMakeGUITest_BINARY_DIR "/presetArg-noExist/src" + << "" << QCMakePropertyList{}; +} + +namespace { +void writePresets(const QString& buildDir, const QStringList& names) +{ + QJsonArray presets{ + QJsonObject{ + { "name", "base" }, + { "generator", "Ninja" }, + { "binaryDir", + QString::fromLocal8Bit("${sourceDir}/%1/${presetName}") + .arg(buildDir) }, + { "hidden", true }, + }, + }; + + for (auto const& name : names) { + presets.append(QJsonObject{ + { "name", name }, + { "inherits", QJsonArray{ "base" } }, + }); + } + + QJsonDocument doc{ QJsonObject{ + { "version", 1 }, + { "configurePresets", presets }, + } }; + + QFile presetsFile(CMakeGUITest_BINARY_DIR + "/changingPresets/src/CMakePresets.json"); + bool open = presetsFile.open(QIODevice::WriteOnly); + Q_ASSERT(open); + presetsFile.write(doc.toJson()); +} +} + +void CMakeGUITest::changingPresets() +{ + QDir::root().mkpath(CMakeGUITest_BINARY_DIR "/changingPresets/src"); + + this->m_window->SourceDirectory->setText(CMakeGUITest_BINARY_DIR + "/changingPresets/src"); + loopSleep(); + QCOMPARE(this->m_window->Preset->presetName(), QString{}); + QCOMPARE(this->m_window->Preset->presets().size(), 0); + QCOMPARE(this->m_window->BinaryDirectory->currentText(), ""); + QCOMPARE(this->m_window->Preset->isHidden(), true); + QCOMPARE(this->m_window->PresetLabel->isHidden(), true); + + writePresets("build1", { "preset" }); + loopSleep(1500); + QCOMPARE(this->m_window->Preset->presetName(), QString{}); + QCOMPARE(this->m_window->Preset->presets().size(), 1); + QCOMPARE(this->m_window->BinaryDirectory->currentText(), ""); + QCOMPARE(this->m_window->Preset->isHidden(), false); + QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + + this->m_window->Preset->setPresetName("preset"); + loopSleep(); + QCOMPARE(this->m_window->Preset->presetName(), "preset"); + QCOMPARE(this->m_window->Preset->presets().size(), 1); + QCOMPARE(this->m_window->BinaryDirectory->currentText(), + CMakeGUITest_BINARY_DIR "/changingPresets/src/build1/preset"); + QCOMPARE(this->m_window->Preset->isHidden(), false); + QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + + writePresets("build2", { "preset2", "preset" }); + loopSleep(1500); + QCOMPARE(this->m_window->Preset->presetName(), "preset"); + QCOMPARE(this->m_window->Preset->presets().size(), 2); + QCOMPARE(this->m_window->BinaryDirectory->currentText(), + CMakeGUITest_BINARY_DIR "/changingPresets/src/build1/preset"); + QCOMPARE(this->m_window->Preset->isHidden(), false); + QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + + writePresets("build3", { "preset2" }); + loopSleep(1500); + QCOMPARE(this->m_window->Preset->presetName(), QString{}); + QCOMPARE(this->m_window->Preset->presets().size(), 1); + QCOMPARE(this->m_window->BinaryDirectory->currentText(), + CMakeGUITest_BINARY_DIR "/changingPresets/src/build1/preset"); + QCOMPARE(this->m_window->Preset->isHidden(), false); + QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + + this->m_window->Preset->setPresetName("preset2"); + loopSleep(); + QCOMPARE(this->m_window->Preset->presetName(), "preset2"); + QCOMPARE(this->m_window->Preset->presets().size(), 1); + QCOMPARE(this->m_window->BinaryDirectory->currentText(), + CMakeGUITest_BINARY_DIR "/changingPresets/src/build3/preset2"); + QCOMPARE(this->m_window->Preset->isHidden(), false); + QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + + QDir::root().mkpath(CMakeGUITest_BINARY_DIR "/changingPresets/src2"); + QFile::copy(CMakeGUITest_BINARY_DIR "/changingPresets/src/CMakePresets.json", + CMakeGUITest_BINARY_DIR + "/changingPresets/src2/CMakePresets.json"); + this->m_window->SourceDirectory->setText(CMakeGUITest_BINARY_DIR + "/changingPresets/src2"); + loopSleep(); + QCOMPARE(this->m_window->Preset->presetName(), QString{}); + QCOMPARE(this->m_window->Preset->presets().size(), 1); + QCOMPARE(this->m_window->BinaryDirectory->currentText(), + CMakeGUITest_BINARY_DIR "/changingPresets/src/build3/preset2"); + QCOMPARE(this->m_window->Preset->isHidden(), false); + QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + + this->m_window->Preset->setPresetName("preset2"); + loopSleep(); + QCOMPARE(this->m_window->Preset->presetName(), "preset2"); + QCOMPARE(this->m_window->Preset->presets().size(), 1); + QCOMPARE(this->m_window->BinaryDirectory->currentText(), + CMakeGUITest_BINARY_DIR "/changingPresets/src2/build3/preset2"); + QCOMPARE(this->m_window->Preset->isHidden(), false); + QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + + QFile(CMakeGUITest_BINARY_DIR "/changingPresets/src2/CMakePresets.json") + .remove(); + loopSleep(1500); + QCOMPARE(this->m_window->Preset->presetName(), QString{}); + QCOMPARE(this->m_window->Preset->presets().size(), 0); + QCOMPARE(this->m_window->BinaryDirectory->currentText(), + CMakeGUITest_BINARY_DIR "/changingPresets/src2/build3/preset2"); + QCOMPARE(this->m_window->Preset->isHidden(), true); + QCOMPARE(this->m_window->PresetLabel->isHidden(), true); +} + void SetupDefaultQSettings() { QSettings::setDefaultFormat(QSettings::IniFormat); diff --git a/Tests/CMakeGUI/CMakeGUITest.h b/Tests/CMakeGUI/CMakeGUITest.h index 891cf624ba..e6293a4d81 100644 --- a/Tests/CMakeGUI/CMakeGUITest.h +++ b/Tests/CMakeGUI/CMakeGUITest.h @@ -23,4 +23,7 @@ private slots: void simpleConfigure(); void simpleConfigure_data(); void environment(); + void presetArg(); + void presetArg_data(); + void changingPresets(); }; diff --git a/Tests/CMakeGUI/CMakeLists.txt b/Tests/CMakeGUI/CMakeLists.txt index c6bc88a5a4..4e8609b854 100644 --- a/Tests/CMakeGUI/CMakeLists.txt +++ b/Tests/CMakeGUI/CMakeLists.txt @@ -72,3 +72,24 @@ add_cmake_gui_lib_test(QCMakeCacheModel MOC_SOURCES QCMakeCacheModelTest.h ) +add_cmake_gui_lib_test(QCMakePreset + SOURCES + QCMakePresetTest.cxx + QCMakePresetTest.h + MOC_SOURCES + QCMakePresetTest.h + ) +add_cmake_gui_lib_test(QCMakePresetItemModel + SOURCES + QCMakePresetItemModelTest.cxx + QCMakePresetItemModelTest.h + MOC_SOURCES + QCMakePresetItemModelTest.h + ) +add_cmake_gui_lib_test(QCMakePresetComboBox + SOURCES + QCMakePresetComboBoxTest.cxx + QCMakePresetComboBoxTest.h + MOC_SOURCES + QCMakePresetComboBoxTest.h + ) diff --git a/Tests/CMakeGUI/QCMakePresetComboBoxTest.cxx b/Tests/CMakeGUI/QCMakePresetComboBoxTest.cxx new file mode 100644 index 0000000000..6ee55c3e32 --- /dev/null +++ b/Tests/CMakeGUI/QCMakePresetComboBoxTest.cxx @@ -0,0 +1,80 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "QCMakePresetComboBoxTest.h" + +#include <QtTest> + +void QCMakePresetComboBoxTest::changePresets() +{ + QCMakePresetComboBox box; + QSignalSpy presetChanged(&box, &QCMakePresetComboBox::presetChanged); + + QCOMPARE(presetChanged.size(), 0); + + box.setPresets({}); + QCOMPARE(presetChanged.size(), 0); + + box.setPresetName(QString{}); + QCOMPARE(presetChanged.size(), 0); + + box.setPresets({ + { + /*name=*/"preset", + /*description=*/"", + /*description=*/"", + /*generator=*/"Ninja", + /*architecture=*/"", + /*toolset=*/"", + /*setGenConfig=*/true, + /*enabled=*/true, + }, + }); + QCOMPARE(presetChanged.size(), 0); + + box.setPresetName(QString{}); + QCOMPARE(presetChanged.size(), 0); + + box.setPresetName("noexist"); + QCOMPARE(presetChanged.size(), 0); + + box.setPresetName("preset"); + QCOMPARE(presetChanged.size(), 1); + QCOMPARE(presetChanged.last(), QList<QVariant>{ "preset" }); + + box.setPresets({ + { + /*name=*/"preset", + /*description=*/"", + /*description=*/"", + /*generator=*/"Ninja Multi-Config", + /*architecture=*/"", + /*toolset=*/"", + /*setGenConfig=*/true, + /*enabled=*/true, + }, + }); + QCOMPARE(presetChanged.size(), 1); + + box.setPresetName("noexist"); + QCOMPARE(presetChanged.size(), 2); + QCOMPARE(presetChanged.last(), QList<QVariant>{ QString{} }); + + box.setPresetName("preset"); + QCOMPARE(presetChanged.size(), 3); + QCOMPARE(presetChanged.last(), QList<QVariant>{ "preset" }); + + box.blockSignals(true); + box.setPresetName(QString{}); + box.blockSignals(false); + QCOMPARE(presetChanged.size(), 3); + + box.setPresetName("preset"); + QCOMPARE(presetChanged.size(), 4); + QCOMPARE(presetChanged.last(), QList<QVariant>{ "preset" }); + + box.setPresets({}); + QCOMPARE(presetChanged.size(), 5); + QCOMPARE(presetChanged.last(), QList<QVariant>{ QString{} }); +} + +QTEST_MAIN(QCMakePresetComboBoxTest) diff --git a/Tests/CMakeGUI/QCMakePresetComboBoxTest.h b/Tests/CMakeGUI/QCMakePresetComboBoxTest.h new file mode 100644 index 0000000000..433adbb42e --- /dev/null +++ b/Tests/CMakeGUI/QCMakePresetComboBoxTest.h @@ -0,0 +1,13 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include "QCMakePresetComboBox.h" +#include <QObject> + +class QCMakePresetComboBoxTest : public QObject +{ + Q_OBJECT +private slots: + void changePresets(); +}; diff --git a/Tests/CMakeGUI/QCMakePresetItemModelTest.cxx b/Tests/CMakeGUI/QCMakePresetItemModelTest.cxx new file mode 100644 index 0000000000..ee45d39230 --- /dev/null +++ b/Tests/CMakeGUI/QCMakePresetItemModelTest.cxx @@ -0,0 +1,162 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "QCMakePresetItemModelTest.h" + +#include <utility> + +#include "QCMakePreset.h" +#include "QCMakePresetItemModel.h" +#include <QHash> +#include <QMetaType> +#include <QSignalSpy> +#include <QVariant> +#include <QVector> +#include <QtTest> + +using QItemDataHash = QHash<Qt::ItemDataRole, QVariant>; + +void QCMakePresetItemModelTest::initTestCase() +{ + QMetaType::registerComparators<QCMakePreset>(); +} + +void QCMakePresetItemModelTest::initTestCase_data() +{ + QTest::addColumn<QVector<QCMakePreset>>("presets"); + QTest::addColumn<QVector<QItemDataHash>>("data"); + + QVector<QCMakePreset> presets{ + QCMakePreset{ + /*name=*/"no-description", + /*description=*/"", + /*description=*/"", + /*generator=*/"", + /*architecture=*/"", + /*toolset=*/"", + /*setGenConfig=*/true, + /*enabled=*/true, + }, + QCMakePreset{ + /*name=*/"short-description", + /*description=*/"Short Description", + /*description=*/"", + /*generator=*/"", + /*architecture=*/"", + /*toolset=*/"", + /*setGenConfig=*/true, + /*enabled=*/true, + }, + QCMakePreset{ + /*name=*/"long-description", + /*description=*/"", + /*description=*/"Long Description", + /*generator=*/"", + /*architecture=*/"", + /*toolset=*/"", + /*setGenConfig=*/true, + /*enabled=*/true, + }, + QCMakePreset{ + /*name=*/"disabled", + /*description=*/"", + /*description=*/"", + /*generator=*/"", + /*architecture=*/"", + /*toolset=*/"", + /*setGenConfig=*/true, + /*enabled=*/false, + }, + }; + QVector<QItemDataHash> data{ + QItemDataHash{ + { Qt::AccessibleDescriptionRole, "" }, + { Qt::DisplayRole, "no-description" }, + { Qt::ToolTipRole, "" }, + { Qt::UserRole, QVariant::fromValue(presets[0]) }, + { Qt::FontRole, QFont{} }, + }, + QItemDataHash{ + { Qt::AccessibleDescriptionRole, "" }, + { Qt::DisplayRole, "Short Description" }, + { Qt::ToolTipRole, "" }, + { Qt::UserRole, QVariant::fromValue(presets[1]) }, + { Qt::FontRole, QFont{} }, + }, + QItemDataHash{ + { Qt::AccessibleDescriptionRole, "" }, + { Qt::DisplayRole, "long-description" }, + { Qt::ToolTipRole, "Long Description" }, + { Qt::UserRole, QVariant::fromValue(presets[2]) }, + { Qt::FontRole, QFont{} }, + }, + QItemDataHash{ + { Qt::AccessibleDescriptionRole, "" }, + { Qt::DisplayRole, "disabled" }, + { Qt::ToolTipRole, "" }, + { Qt::UserRole, QVariant::fromValue(presets[3]) }, + { Qt::FontRole, QFont{} }, + }, + QItemDataHash{ + { Qt::AccessibleDescriptionRole, "separator" }, + { Qt::DisplayRole, QVariant{} }, + { Qt::ToolTipRole, QVariant{} }, + { Qt::UserRole, QVariant{} }, + { Qt::FontRole, QFont{} }, + }, + QItemDataHash{ + { Qt::AccessibleDescriptionRole, "" }, + { Qt::DisplayRole, "<custom>" }, + { Qt::ToolTipRole, "Specify all settings manually" }, + { Qt::UserRole, QVariant{} }, + { Qt::FontRole, + []() { + QFont f; + f.setItalic(true); + return f; + }() }, + }, + }; + QTest::newRow("many") << presets << data; + QTest::newRow("none") << QVector<QCMakePreset>{} + << QVector<QItemDataHash>{ data.last() }; +} + +void QCMakePresetItemModelTest::data() +{ + QFETCH_GLOBAL(QVector<QCMakePreset>, presets); + QFETCH_GLOBAL(QVector<QItemDataHash>, data); + QFETCH(Qt::ItemDataRole, role); + + QCMakePresetItemModel model; + QSignalSpy spy1(&model, &QCMakePresetItemModel::modelAboutToBeReset); + QSignalSpy spy2(&model, &QCMakePresetItemModel::modelReset); + model.setPresets(presets); + QCOMPARE(spy1.size(), 1); + QCOMPARE(spy2.size(), 1); + + QVector<QVariant> expectedData(data.size()); + for (int i = 0; i < data.size(); ++i) { + expectedData[i] = data[i][role]; + } + + auto rows = model.rowCount(); + QVector<QVariant> actualData(rows); + for (int i = 0; i < rows; ++i) { + actualData[i] = model.data(model.index(i, 0), role); + } + + QCOMPARE(actualData, expectedData); +} + +void QCMakePresetItemModelTest::data_data() +{ + QTest::addColumn<Qt::ItemDataRole>("role"); + + QTest::newRow("accessible") << Qt::AccessibleDescriptionRole; + QTest::newRow("display") << Qt::DisplayRole; + QTest::newRow("tooltip") << Qt::ToolTipRole; + QTest::newRow("user") << Qt::UserRole; + QTest::newRow("font") << Qt::FontRole; +} + +QTEST_MAIN(QCMakePresetItemModelTest) diff --git a/Tests/CMakeGUI/QCMakePresetItemModelTest.h b/Tests/CMakeGUI/QCMakePresetItemModelTest.h new file mode 100644 index 0000000000..ff6efae279 --- /dev/null +++ b/Tests/CMakeGUI/QCMakePresetItemModelTest.h @@ -0,0 +1,17 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include "QCMakePresetItemModel.h" +#include <QObject> + +class QCMakePresetItemModelTest : public QObject +{ + Q_OBJECT +private slots: + void initTestCase(); + void initTestCase_data(); + + void data(); + void data_data(); +}; diff --git a/Tests/CMakeGUI/QCMakePresetTest.cxx b/Tests/CMakeGUI/QCMakePresetTest.cxx new file mode 100644 index 0000000000..8fd07e73bb --- /dev/null +++ b/Tests/CMakeGUI/QCMakePresetTest.cxx @@ -0,0 +1,82 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "QCMakePresetTest.h" + +#include <utility> + +#include "QCMakePreset.h" +#include <QtTest> + +namespace { +QCMakePreset makePreset() +{ + return QCMakePreset{ + /*name=*/"name", + /*displayName=*/"displayName", + /*description=*/"description", + /*generator=*/"generator", + /*architecture=*/"architecture", + /*toolset=*/"toolset", + /*setGenConfig=*/true, + /*enabled=*/true, + }; +} + +template <typename T, typename U> +QCMakePreset makePreset(T QCMakePreset::*field, U&& value) +{ + auto preset = makePreset(); + preset.*field = std::forward<U>(value); + return preset; +} +} + +void QCMakePresetTest::equality() +{ + QFETCH(QCMakePreset, rhs); + QFETCH(bool, equal); + QFETCH(bool, lt); + QFETCH(bool, gt); + + auto lhs = makePreset(); + QVERIFY((lhs == rhs) == equal); + QVERIFY((lhs != rhs) == !equal); + QVERIFY((lhs < rhs) == lt); + QVERIFY((lhs >= rhs) == !lt); + QVERIFY((lhs > rhs) == gt); + QVERIFY((lhs <= rhs) == !gt); +} + +void QCMakePresetTest::equality_data() +{ + QTest::addColumn<QCMakePreset>("rhs"); + QTest::addColumn<bool>("equal"); + QTest::addColumn<bool>("lt"); + QTest::addColumn<bool>("gt"); + + QTest::newRow("equal") << makePreset() << true << false << false; + QTest::newRow("name") << makePreset(&QCMakePreset::name, "other-name") + << false << true << false; + QTest::newRow("displayName") + << makePreset(&QCMakePreset::displayName, "other-displayName") << false + << true << false; + QTest::newRow("description") + << makePreset(&QCMakePreset::description, "other-description") << false + << true << false; + QTest::newRow("generator") + << makePreset(&QCMakePreset::generator, "other-generator") << false << true + << false; + QTest::newRow("architecture") + << makePreset(&QCMakePreset::architecture, "other-architecture") << false + << true << false; + QTest::newRow("toolset") << makePreset(&QCMakePreset::toolset, + "other-toolset") + << false << false << true; + QTest::newRow("setGenConfig") + << makePreset(&QCMakePreset::setGenConfig, false) << false << false + << true; + QTest::newRow("enabled") << makePreset(&QCMakePreset::enabled, false) + << false << false << true; +} + +QTEST_MAIN(QCMakePresetTest) diff --git a/Tests/CMakeGUI/QCMakePresetTest.h b/Tests/CMakeGUI/QCMakePresetTest.h new file mode 100644 index 0000000000..5eac88d8c3 --- /dev/null +++ b/Tests/CMakeGUI/QCMakePresetTest.h @@ -0,0 +1,14 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include "QCMakePreset.h" +#include <QObject> + +class QCMakePresetTest : public QObject +{ + Q_OBJECT +private slots: + void equality(); + void equality_data(); +}; diff --git a/Tests/CMakeGUI/presetArg-noPresetBinaryChange/CMakePresets.json.in b/Tests/CMakeGUI/presetArg-noPresetBinaryChange/CMakePresets.json.in new file mode 100644 index 0000000000..d78d69dc0e --- /dev/null +++ b/Tests/CMakeGUI/presetArg-noPresetBinaryChange/CMakePresets.json.in @@ -0,0 +1,33 @@ +{ + "version": 1, + "configurePresets": [ + { + "name": "ninja", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "STRING_VARIABLE": { + "type": "STRING", + "value": "String value" + }, + "PATH_VARIABLE": { + "type": "PATH", + "value": "${sourceDir}" + }, + "FILEPATH_VARIABLE": { + "type": "FILEPATH", + "value": "${sourceDir}/CMakeLists.txt" + }, + "ON_VARIABLE": { + "type": "BOOL", + "value": "ON" + }, + "FALSE_VARIABLE": { + "type": "BOOL", + "value": "FALSE" + }, + "UNINITIALIZED_VARIABLE": "Uninitialized value" + } + } + ] +} diff --git a/Tests/CMakeGUI/presetArg-preset/CMakePresets.json.in b/Tests/CMakeGUI/presetArg-preset/CMakePresets.json.in new file mode 100644 index 0000000000..d78d69dc0e --- /dev/null +++ b/Tests/CMakeGUI/presetArg-preset/CMakePresets.json.in @@ -0,0 +1,33 @@ +{ + "version": 1, + "configurePresets": [ + { + "name": "ninja", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "STRING_VARIABLE": { + "type": "STRING", + "value": "String value" + }, + "PATH_VARIABLE": { + "type": "PATH", + "value": "${sourceDir}" + }, + "FILEPATH_VARIABLE": { + "type": "FILEPATH", + "value": "${sourceDir}/CMakeLists.txt" + }, + "ON_VARIABLE": { + "type": "BOOL", + "value": "ON" + }, + "FALSE_VARIABLE": { + "type": "BOOL", + "value": "FALSE" + }, + "UNINITIALIZED_VARIABLE": "Uninitialized value" + } + } + ] +} diff --git a/Tests/CMakeGUI/presetArg-presetBinary/CMakePresets.json.in b/Tests/CMakeGUI/presetArg-presetBinary/CMakePresets.json.in new file mode 100644 index 0000000000..d78d69dc0e --- /dev/null +++ b/Tests/CMakeGUI/presetArg-presetBinary/CMakePresets.json.in @@ -0,0 +1,33 @@ +{ + "version": 1, + "configurePresets": [ + { + "name": "ninja", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "STRING_VARIABLE": { + "type": "STRING", + "value": "String value" + }, + "PATH_VARIABLE": { + "type": "PATH", + "value": "${sourceDir}" + }, + "FILEPATH_VARIABLE": { + "type": "FILEPATH", + "value": "${sourceDir}/CMakeLists.txt" + }, + "ON_VARIABLE": { + "type": "BOOL", + "value": "ON" + }, + "FALSE_VARIABLE": { + "type": "BOOL", + "value": "FALSE" + }, + "UNINITIALIZED_VARIABLE": "Uninitialized value" + } + } + ] +} diff --git a/Tests/CMakeGUI/presetArg-presetBinaryChange/CMakePresets.json.in b/Tests/CMakeGUI/presetArg-presetBinaryChange/CMakePresets.json.in new file mode 100644 index 0000000000..6fe20d68b8 --- /dev/null +++ b/Tests/CMakeGUI/presetArg-presetBinaryChange/CMakePresets.json.in @@ -0,0 +1,39 @@ +{ + "version": 1, + "configurePresets": [ + { + "name": "ninja", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "STRING_VARIABLE": { + "type": "STRING", + "value": "String value" + }, + "PATH_VARIABLE": { + "type": "PATH", + "value": "${sourceDir}" + }, + "FILEPATH_VARIABLE": { + "type": "FILEPATH", + "value": "${sourceDir}/CMakeLists.txt" + }, + "ON_VARIABLE": { + "type": "BOOL", + "value": "ON" + }, + "FALSE_VARIABLE": { + "type": "BOOL", + "value": "FALSE" + }, + "UNINITIALIZED_VARIABLE": "Uninitialized value" + } + }, + { + "name": "ninja2", + "inherits": [ + "ninja" + ] + } + ] +} diff --git a/Tests/CMakeGUI/presetArg-presetConfigExists/CMakeLists.txt.in b/Tests/CMakeGUI/presetArg-presetConfigExists/CMakeLists.txt.in new file mode 100644 index 0000000000..2ae4a5714c --- /dev/null +++ b/Tests/CMakeGUI/presetArg-presetConfigExists/CMakeLists.txt.in @@ -0,0 +1,2 @@ +cmake_minimum_required(VERSION 3.18) +project(sourceBinaryArgs-sourceDir NONE) diff --git a/Tests/CMakeGUI/presetArg-presetConfigExists/CMakePresets.json.in b/Tests/CMakeGUI/presetArg-presetConfigExists/CMakePresets.json.in new file mode 100644 index 0000000000..d78d69dc0e --- /dev/null +++ b/Tests/CMakeGUI/presetArg-presetConfigExists/CMakePresets.json.in @@ -0,0 +1,33 @@ +{ + "version": 1, + "configurePresets": [ + { + "name": "ninja", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "STRING_VARIABLE": { + "type": "STRING", + "value": "String value" + }, + "PATH_VARIABLE": { + "type": "PATH", + "value": "${sourceDir}" + }, + "FILEPATH_VARIABLE": { + "type": "FILEPATH", + "value": "${sourceDir}/CMakeLists.txt" + }, + "ON_VARIABLE": { + "type": "BOOL", + "value": "ON" + }, + "FALSE_VARIABLE": { + "type": "BOOL", + "value": "FALSE" + }, + "UNINITIALIZED_VARIABLE": "Uninitialized value" + } + } + ] +} diff --git a/Tests/CMakeGUI/presetArg-presetConfigExists/CMakeSetup.ini.in b/Tests/CMakeGUI/presetArg-presetConfigExists/CMakeSetup.ini.in new file mode 100644 index 0000000000..a5d0c71856 --- /dev/null +++ b/Tests/CMakeGUI/presetArg-presetConfigExists/CMakeSetup.ini.in @@ -0,0 +1,2 @@ +[Settings] +StartPath\WhereBuild0=@CMake_BINARY_DIR@ |