File: selectionratiosourcetest.cpp

package info (click to toggle)
kuserfeedback 1.3.0-9
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,496 kB
  • sloc: cpp: 13,251; php: 2,192; xml: 224; yacc: 90; lex: 82; sh: 17; makefile: 8
file content (69 lines) | stat: -rw-r--r-- 2,047 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
    SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org>

    SPDX-License-Identifier: MIT
*/

#include <selectionratiosource.h>

#include <QDebug>
#include <QItemSelectionModel>
#include <QtTest/qtest.h>
#include <QObject>
#include <QSettings>
#include <QStandardItemModel>
#include <QStandardPaths>

using namespace KUserFeedback;

class SelectionRatioSourceTest : public QObject
{
    Q_OBJECT
private slots:
    void initTestCase()
    {
        QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
        QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
        QStandardPaths::setTestModeEnabled(true);
    }

    void testPropertyRatioSource()
    {
        QStandardItemModel model;
        model.appendRow(new QStandardItem(QStringLiteral("row1")));
        model.appendRow(new QStandardItem(QStringLiteral("row2")));
        model.appendRow(new QStandardItem(QStringLiteral("row3")));

        QItemSelectionModel sel(&model);
        sel.select(model.index(1, 0), QItemSelectionModel::ClearAndSelect);

        SelectionRatioSource src(&sel, QStringLiteral("selection"));
        QTest::qWait(1);

        auto v = src.data();
        QVERIFY(v.canConvert<QVariantMap>());
        auto o = v.toMap();
        QCOMPARE(o.size(), 0); // nothing recorded

        QTest::qWait(1200);
        v = src.data();
        o = v.toMap();
        QCOMPARE(o.size(), 1);
        QVERIFY(o.contains(QLatin1String("row2")));
        v = o.value(QLatin1String("row2")).toMap().value(QLatin1String("property"));
        QCOMPARE(v.type(), QVariant::Double);

        sel.select(model.index(2, 0), QItemSelectionModel::ClearAndSelect);
        QTest::qWait(1200);
        v = src.data();
        o = v.toMap();
        QCOMPARE(o.size(), 2);
        QVERIFY(o.contains(QLatin1String("row2")));
        v = o.value(QLatin1String("row2")).toMap().value(QLatin1String("property"));
        QCOMPARE(v.type(), QVariant::Double);
    }
};

QTEST_MAIN(SelectionRatioSourceTest)

#include "selectionratiosourcetest.moc"