pkpasstest.cpp 3.5 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 <barcode.h>
19
#include <boardingpass.h>
Volker Krause's avatar
Volker Krause committed
20
#include <location.h>
21
22
23
24

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

Volker Krause's avatar
Volker Krause committed
25
26
#include <cmath>

27
28
29
30
31
32
33
34
35
36
37
class PkPassTest : public QObject
{
    Q_OBJECT
private slots:
    void initTestCase()
    {
        QLocale::setDefault(QLocale("de_DE"));
    }

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

Volker Krause's avatar
Volker Krause committed
41
        QCOMPARE(pass->type(), KPkPass::Pass::BoardingPass);
42
43
44
45
        QCOMPARE(pass->serialNumber(), QLatin1String("1234"));
        QCOMPARE(pass->description(), QLatin1String("description"));
        QCOMPARE(pass->organizationName(), QLatin1String("KDE"));

Volker Krause's avatar
Volker Krause committed
46
47
        QCOMPARE(pass->logoText(), QLatin1String("Boarding Pass"));
        QCOMPARE(pass->backgroundColor(), QColor(61, 174, 233));
48
        QCOMPARE(pass->relevantDate(), QDateTime(QDate(2017, 9, 17), QTime(0, 4, 0), Qt::UTC));
49
50
51
        QCOMPARE(pass->expirationDate(), QDateTime(QDate(2017, 9, 18), QTime(0, 0, 36), Qt::UTC));
        QCOMPARE(pass->isVoided(), false);
        QCOMPARE(pass->groupingIdentifier(), QLatin1String(""));
52

53
        QCOMPARE(pass->fields().size(), 12);
Volker Krause's avatar
Volker Krause committed
54
        auto headers = pass->headerFields();
55
56
57
        QCOMPARE(headers.size(), 2);
        auto field = headers.at(0);
        QCOMPARE(field.label(), QLatin1String("Sitzplatz"));
Volker Krause's avatar
Volker Krause committed
58
59
60
61
        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"));
62

Volker Krause's avatar
Volker Krause committed
63
64
65
        field = pass->field(QLatin1String("boarding"));
        QCOMPARE(field.key(), QLatin1String("boarding"));
        QCOMPARE(field.value(), QLatin1String("20:25"));
66
        QCOMPARE(field.textAlignment(), Qt::AlignLeft);
Volker Krause's avatar
Volker Krause committed
67

Volker Krause's avatar
Volker Krause committed
68
        auto boardingPass = dynamic_cast<KPkPass::BoardingPass*>(pass.get());
69
70
71
        QVERIFY(boardingPass);
        QCOMPARE(boardingPass->transitType(), KPkPass::BoardingPass::Air);

Volker Krause's avatar
Volker Krause committed
72
        auto barcodes = pass->barcodes();
73
74
75
76
        QCOMPARE(barcodes.size(), 1);
        auto bc = barcodes.at(0);
        QCOMPARE(bc.format(), KPkPass::Barcode::QR);
        QVERIFY(!bc.message().isEmpty());
77
78
        QVERIFY(bc.alternativeText().isEmpty());
        QCOMPARE(bc.messageEncoding(), QLatin1String("iso-8859-1"));
Volker Krause's avatar
Volker Krause committed
79
80
81
82
83
84
85
86

        const auto locs = pass->locations();
        QCOMPARE(locs.size(), 1);
        const auto loc = locs.at(0);
        QVERIFY(std::isnan(loc.altitude()));
        QCOMPARE((int)loc.latitude(), 47);
        QCOMPARE((int)loc.longitude(), 8);
        QCOMPARE(loc.relevantText(), QLatin1String("LX962 Boarding 20:25"));
87
        QCOMPARE(pass->maximumDistance(), 500);
88
89
90
91
92
93
    }
};

QTEST_GUILESS_MAIN(PkPassTest)

#include "pkpasstest.moc"