pkpasstest.cpp 2.53 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
    Copyright (C) 2018 Volker Krause <vkrause@kde.org>

    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

Volker Krause's avatar
Volker Krause committed
18
#include <pass.h>
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <boardingpass.h>

#include <QLocale>
#include <QtTest/qtest.h>

class PkPassTest : public QObject
{
    Q_OBJECT
private slots:
    void initTestCase()
    {
        QLocale::setDefault(QLocale("de_DE"));
    }

    void testBoardingPass()
    {
Volker Krause's avatar
Volker Krause committed
35
        std::unique_ptr<KPkPass::Pass> pass(KPkPass::Pass::fromFile(QLatin1String(SOURCE_DIR "/data/boardingpass-v1.pkpass")));
Volker Krause's avatar
Volker Krause committed
36
        QVERIFY(pass);
37

Volker Krause's avatar
Volker Krause committed
38
39
40
        QCOMPARE(pass->type(), KPkPass::Pass::BoardingPass);
        QCOMPARE(pass->logoText(), QLatin1String("Boarding Pass"));
        QCOMPARE(pass->backgroundColor(), QColor(61, 174, 233));
41
42
        QCOMPARE(pass->relevantDate(), QDateTime(QDate(2017, 9, 17), QTime(0, 4, 0), Qt::UTC));
        QCOMPARE(pass->fields().size(), 12);
43

Volker Krause's avatar
Volker Krause committed
44
        auto headers = pass->headerFields();
45
46
47
        QCOMPARE(headers.size(), 2);
        auto field = headers.at(0);
        QCOMPARE(field.label(), QLatin1String("Sitzplatz"));
Volker Krause's avatar
Volker Krause committed
48
49
50
51
        QCOMPARE(field.value(), QVariant(QLatin1String("10E")));
        QCOMPARE(field.valueDisplayString(), QLatin1String("10E"));
        QCOMPARE(field.key(), QLatin1String("seat"));
        QCOMPARE(field.changeMessage(), QStringLiteral("Sitzplatznummer geändert in 10E"));
52

Volker Krause's avatar
Volker Krause committed
53
54
55
56
        field = pass->field(QLatin1String("boarding"));
        QCOMPARE(field.key(), QLatin1String("boarding"));
        QCOMPARE(field.value(), QLatin1String("20:25"));

Volker Krause's avatar
Volker Krause committed
57
        auto boardingPass = dynamic_cast<KPkPass::BoardingPass*>(pass.get());
58
59
60
        QVERIFY(boardingPass);
        QCOMPARE(boardingPass->transitType(), KPkPass::BoardingPass::Air);

Volker Krause's avatar
Volker Krause committed
61
        auto barcodes = pass->barcodes();
62
63
64
65
66
67
68
69
70
71
        QCOMPARE(barcodes.size(), 1);
        auto bc = barcodes.at(0);
        QCOMPARE(bc.format(), KPkPass::Barcode::QR);
        QVERIFY(!bc.message().isEmpty());
    }
};

QTEST_GUILESS_MAIN(PkPassTest)

#include "pkpasstest.moc"