File indexing completed on 2024-04-14 04:35:56

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include <map/style/mapcssparser.h>
0008 #include <map/style/mapcssstyle.h>
0009 
0010 #include <QFile>
0011 #include <QProcess>
0012 #include <QTest>
0013 
0014 using namespace KOSMIndoorMap;
0015 
0016 class MapCSSParserTest : public QObject
0017 {
0018     Q_OBJECT
0019 private Q_SLOTS:
0020     void testParse()
0021     {
0022         MapCSSParser p;
0023         const auto style = p.parse(QStringLiteral(SOURCE_DIR "/data/mapcss/parser-test.mapcss"));
0024         QVERIFY(!p.hasError());
0025 
0026         QFile outFile(QStringLiteral("parser-test.mapcss.out"));
0027         QVERIFY(outFile.open(QFile::WriteOnly | QFile::Text));
0028         style.write(&outFile);
0029         outFile.close();
0030         QVERIFY(outFile.open(QFile::ReadOnly | QFile::Text));
0031         const auto b1 = outFile.readAll();
0032 
0033         QFile refFile(QStringLiteral(SOURCE_DIR "/data/mapcss/parser-test.mapcss.ref"));
0034         QVERIFY(refFile.open(QFile::ReadOnly | QFile::Text));
0035         const auto b2 = refFile.readAll();
0036 
0037         if (b1 != b2) {
0038             QProcess proc;
0039             proc.setProcessChannelMode(QProcess::ForwardedChannels);
0040             proc.start(QStringLiteral("diff"), {QStringLiteral("-u"), outFile.fileName(), refFile.fileName()});
0041             proc.waitForFinished();
0042         }
0043         QVERIFY(b1 == b2);
0044     }
0045 
0046     void testBuiltInStyles_data()
0047     {
0048         QTest::addColumn<QString>("style");
0049 
0050         QTest::newRow("common") << QStringLiteral(SOURCE_DIR "/../src/map/assets/css/breeze-common.mapcss");
0051         QTest::newRow("light") << QStringLiteral(SOURCE_DIR "/../src/map/assets/css/breeze-light.mapcss");
0052         QTest::newRow("dark") << QStringLiteral(SOURCE_DIR "/../src/map/assets/css/breeze-dark.mapcss");
0053         QTest::newRow("diagnostic") << QStringLiteral(SOURCE_DIR "/../src/map/assets/css/diagnostic.mapcss");
0054     }
0055     void testBuiltInStyles()
0056     {
0057         QFETCH(QString, style);
0058         MapCSSParser p;
0059         const auto s = p.parse(style);
0060         QVERIFY(!p.hasError());
0061         QVERIFY(p.errorMessage().isEmpty());
0062     }
0063 };
0064 
0065 QTEST_GUILESS_MAIN(MapCSSParserTest)
0066 
0067 #include "mapcssparsertest.moc"