File: sampletest.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 (67 lines) | stat: -rw-r--r-- 2,428 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
/*
    SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>

    SPDX-License-Identifier: MIT
*/

#include <core/product.h>
#include <core/sample.h>
#include <core/schemaentrytemplates.h>

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

using namespace KUserFeedback::Console;

class SampleTest : public QObject
{
    Q_OBJECT
private slots:
    void initTestCase()
    {
        Q_INIT_RESOURCE(schematemplates);
        QStandardPaths::setTestModeEnabled(true);
    }

    void testFromJson()
    {
        Product p;
        p.setName(QStringLiteral("org.kde.UserFeedback.UnitTestProduct"));
        for (const auto &tpl : SchemaEntryTemplates::availableTemplates())
            p.addTemplate(tpl);
        QVERIFY(p.isValid());

        auto samples = Sample::fromJson("[]", p);
        QVERIFY(samples.isEmpty());

        samples = Sample::fromJson(R"([{
            "id": 42,
            "timestamp": "2016-11-27 16:09:06",
            "platform": { "os": "linux", "version": "suse" },
            "applicationVersion": { "value": "1.9.84" },
            "screens": [ { "width": 1920, "height": 1200 }, { "width": 640, "height": 480 } ],
            "newPropertyRatio": { "value1": { "property": 0.55 }, "value2": { "property": 0.45 } }
        }])", p);

        QCOMPARE(samples.size(), 1);
        auto s = samples.at(0);
        QCOMPARE(s.timestamp(), QDateTime(QDate(2016, 11, 27), QTime(16, 9, 6)));
        QCOMPARE(s.value(QLatin1String("platform.os")).toString(), QLatin1String("linux"));
        QCOMPARE(s.value(QLatin1String("platform.version")).toString(), QLatin1String("suse"));
        QCOMPARE(s.value(QLatin1String("applicationVersion.value")).toString(), QLatin1String("1.9.84"));
        auto screens = s.value(QLatin1String("screens")).toList();
        QCOMPARE(screens.size(), 2);
        QCOMPARE(screens.at(0).toMap().value(QLatin1String("width")).toInt(), 1920);
        QCOMPARE(screens.at(1).toMap().value(QLatin1String("height")).toInt(), 480);
        auto ratio = s.value(QLatin1String("newPropertyRatio")).toMap();
        QCOMPARE(ratio.size(), 2);
        QCOMPARE(ratio.value(QLatin1String("value1")).toMap().value(QLatin1String("property")).toDouble(), 0.55);
        QCOMPARE(ratio.value(QLatin1String("value2")).toMap().value(QLatin1String("property")).toDouble(), 0.45);
    }
};

QTEST_MAIN(SampleTest)

#include "sampletest.moc"