File: producttest.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 (84 lines) | stat: -rw-r--r-- 2,606 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
    SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>

    SPDX-License-Identifier: MIT
*/

#include <console/core/aggregation.h>
#include <console/core/product.h>

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

using namespace KUserFeedback::Console;

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

    void testFromJson()
    {
        const auto ps = Product::fromJson(R"({
            "name": "org.kde.TestProduct",
            "schema": [{
                "name": "entry1",
                "type": "scalar",
                "elements": [{ "name": "elem11", "type": "string" }]
            }, {
                "name": "entry2",
                "type": "list",
                "elements": [{ "name": "elem21", "type": "number" }]
            }],
            "aggregation": [{
                "type": "ratio_set",
                "elements": [{ "type": "value", "schemaEntry": "entry1", "schemaEntryElement": "elem11" }]
            }, {
                "type": "numeric",
                "elements": [{ "type": "size", "schemaEntry": "entry2" }]
            }]
        })");

        QCOMPARE(ps.size(), 1);

        const auto p = ps.at(0);
        QCOMPARE(p.name(), QLatin1String("org.kde.TestProduct"));

        QCOMPARE(p.schema().size(), 2);

        const auto aggrs = p.aggregations();
        QCOMPARE(aggrs.size(), 2);
        {
            const auto a1 = aggrs.at(0);
            QCOMPARE(a1.type(), Aggregation::RatioSet);
            const auto a1elems = a1.elements();
            QCOMPARE(a1elems.size(), 1);
            QCOMPARE(a1elems.at(0).type(), AggregationElement::Value);
            QCOMPARE(a1elems.at(0).schemaEntry().name(), QLatin1String("entry1"));
            QCOMPARE(a1elems.at(0).schemaEntry().dataType(), SchemaEntry::Scalar);
            QCOMPARE(a1elems.at(0).schemaEntryElement().name(), QLatin1String("elem11"));
        }

        {
            const auto a2 = aggrs.at(1);
            QCOMPARE(a2.type(), Aggregation::Numeric);
            const auto a2elems = a2.elements();
            QCOMPARE(a2elems.size(), 1);
            QCOMPARE(a2elems.at(0).type(), AggregationElement::Size);
            QCOMPARE(a2elems.at(0).schemaEntry().name(), QLatin1String("entry2"));
            QCOMPARE(a2elems.at(0).schemaEntry().dataType(), SchemaEntry::List);
            QVERIFY(a2elems.at(0).schemaEntryElement().name().isEmpty());
        }
    }

};

QTEST_MAIN(ProductTest)

#include "producttest.moc"