File indexing completed on 2024-05-19 04:01:09
0001 /* 0002 SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #include <selectionratiosource.h> 0008 0009 #include <QDebug> 0010 #include <QItemSelectionModel> 0011 #include <QtTest/qtest.h> 0012 #include <QObject> 0013 #include <QSettings> 0014 #include <QStandardItemModel> 0015 #include <QStandardPaths> 0016 0017 using namespace KUserFeedback; 0018 0019 class SelectionRatioSourceTest : public QObject 0020 { 0021 Q_OBJECT 0022 private Q_SLOTS: 0023 void initTestCase() 0024 { 0025 QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); 0026 QCoreApplication::setOrganizationName(QStringLiteral("KDE")); 0027 QStandardPaths::setTestModeEnabled(true); 0028 } 0029 0030 void testPropertyRatioSource() 0031 { 0032 QStandardItemModel model; 0033 model.appendRow(new QStandardItem(QStringLiteral("row1"))); 0034 model.appendRow(new QStandardItem(QStringLiteral("row2"))); 0035 model.appendRow(new QStandardItem(QStringLiteral("row3"))); 0036 0037 QItemSelectionModel sel(&model); 0038 sel.select(model.index(1, 0), QItemSelectionModel::ClearAndSelect); 0039 0040 SelectionRatioSource src(&sel, QStringLiteral("selection")); 0041 QTest::qWait(1); 0042 0043 auto v = src.data(); 0044 QVERIFY(v.canConvert<QVariantMap>()); 0045 auto o = v.toMap(); 0046 QCOMPARE(o.size(), 0); // nothing recorded 0047 0048 QTest::qWait(1200); 0049 v = src.data(); 0050 o = v.toMap(); 0051 QCOMPARE(o.size(), 1); 0052 QVERIFY(o.contains(QLatin1String("row2"))); 0053 v = o.value(QLatin1String("row2")).toMap().value(QLatin1String("property")); 0054 QCOMPARE(v.type(), QVariant::Double); 0055 0056 sel.select(model.index(2, 0), QItemSelectionModel::ClearAndSelect); 0057 QTest::qWait(1200); 0058 v = src.data(); 0059 o = v.toMap(); 0060 QCOMPARE(o.size(), 2); 0061 QVERIFY(o.contains(QLatin1String("row2"))); 0062 v = o.value(QLatin1String("row2")).toMap().value(QLatin1String("property")); 0063 QCOMPARE(v.type(), QVariant::Double); 0064 } 0065 }; 0066 0067 QTEST_MAIN(SelectionRatioSourceTest) 0068 0069 #include "selectionratiosourcetest.moc"