/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ #include "QCMakeCacheModelTest.h" #include #include #include "QCMakeCacheView.h" #include namespace { QCMakeProperty makeProperty( const QString& name, const QString& value, QCMakeProperty::PropertyType type = QCMakeProperty::STRING, bool advanced = false) { return QCMakeProperty{ /*Key=*/name, /*Value=*/value, /*Strings=*/{}, /*Help=*/"", /*Type=*/type, /*Advanced=*/advanced, }; } } void QCMakeCacheModelTest::setNewProperties() { QFETCH(QCMakePropertyList, oldList); QFETCH(QCMakePropertyList, newList); QFETCH(QVector, names); QFETCH(QVector, values); QFETCH(QVector, background); QCMakeCacheModel model; model.setViewType(QCMakeCacheModel::FlatView); model.setProperties(oldList); model.setProperties(newList); auto rows = model.rowCount(); QVector actualNames(rows); QVector actualValues(rows); QVector actualBackground1(rows); QVector actualBackground2(rows); for (int i = 0; i < rows; ++i) { auto idx1 = model.index(i, 0); auto idx2 = model.index(i, 1); auto name = model.data(idx1, Qt::DisplayRole); QVERIFY(name.canConvert()); actualNames[i] = name.value(); auto value = model.data(idx2, Qt::DisplayRole); QVERIFY(name.canConvert()); actualValues[i] = value.value(); actualBackground1[i] = model.data(idx1, Qt::BackgroundRole); actualBackground2[i] = model.data(idx2, Qt::BackgroundRole); } QCOMPARE(actualNames, names); QCOMPARE(actualValues, values); QCOMPARE(actualBackground1, background); QCOMPARE(actualBackground2, background); } void QCMakeCacheModelTest::setNewProperties_data() { QTest::addColumn("oldList"); QTest::addColumn("newList"); QTest::addColumn>("names"); QTest::addColumn>("values"); QTest::addColumn>("background"); QTest::newRow("empty") << QCMakePropertyList{} << QCMakePropertyList{} << QVector{} << QVector{} << QVector{}; QTest::newRow("noNew") << QCMakePropertyList{ makeProperty("VARIABLE_1", "Value 1") } << QCMakePropertyList{} << QVector{} << QVector{} << QVector{}; QTest::newRow("allNew") << QCMakePropertyList{} << QCMakePropertyList{ makeProperty("VARIABLE_1", "Value 1") } << QVector{ "VARIABLE_1" } << QVector{ "Value 1" } << QVector{ QBrush{ QColor{ 255, 100, 100 } } }; QTest::newRow("mixed") << QCMakePropertyList{ makeProperty("VARIABLE_1", "Value 1") } << QCMakePropertyList{ makeProperty("VARIABLE_2", "Value 2") } << QVector{ "VARIABLE_2" } << QVector{ "Value 2" } << QVector{ QBrush{ QColor{ 255, 100, 100 } } }; QTest::newRow("overridden") << QCMakePropertyList{ makeProperty("VARIABLE_1", "Value 1") } << QCMakePropertyList{ makeProperty("VARIABLE_1", "Overridden value") } << QVector{ "VARIABLE_1" } << QVector{ "Overridden value" } << QVector{ QVariant{} }; QTest::newRow("overriddenMixed") << QCMakePropertyList{ makeProperty("VARIABLE_1", "Value 1") } << QCMakePropertyList{ makeProperty("VARIABLE_1", "Overridden value"), makeProperty("VARIABLE_2", "Value 2") } << QVector{ "VARIABLE_2", "VARIABLE_1" } << QVector{ "Value 2", "Overridden value" } << QVector{ QBrush{ QColor{ 255, 100, 100 } }, QVariant{} }; } QTEST_MAIN(QCMakeCacheModelTest)