File indexing completed on 2024-04-28 12:29:22
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include <QDirIterator> 0008 #include <QFile> 0009 #include <QJsonArray> 0010 #include <QJsonDocument> 0011 #include <QJsonObject> 0012 #include <QJsonValue> 0013 #include <QTest> 0014 #include <QTimeZone> 0015 0016 class NetworkConfigTest : public QObject 0017 { 0018 Q_OBJECT 0019 private Q_SLOTS: 0020 0021 void testConfig_data() 0022 { 0023 QTest::addColumn<QString>("fileName"); 0024 QDirIterator it(QStringLiteral(SOURCE_DIR "/../src/lib/networks/"), {QStringLiteral("*.json")}); 0025 while (it.hasNext()) { 0026 it.next(); 0027 QTest::newRow(it.fileName().toLatin1().constData()) << it.fileInfo().absoluteFilePath(); 0028 } 0029 } 0030 0031 void testConfig() 0032 { 0033 QFETCH(QString, fileName); 0034 QFile f(fileName); 0035 QVERIFY(f.open(QFile::ReadOnly)); 0036 0037 QJsonParseError docError; 0038 const auto doc = QJsonDocument::fromJson(f.readAll(), &docError); 0039 if (docError.error != QJsonParseError::NoError) { 0040 qWarning() << "JSON parser error in" << fileName << docError.errorString(); 0041 } 0042 QCOMPARE(docError.error, QJsonParseError::NoError); 0043 0044 const auto top = doc.object(); 0045 QVERIFY(!top.isEmpty()); 0046 QVERIFY(!top.value(QLatin1String("type")).toObject().isEmpty()); 0047 0048 const auto tz = top.value(QLatin1String("timezone")).toString(); 0049 if (!tz.isEmpty()) { 0050 QVERIFY(QTimeZone(tz.toUtf8()).isValid()); 0051 } 0052 } 0053 }; 0054 0055 QTEST_GUILESS_MAIN(NetworkConfigTest) 0056 0057 #include "networkconfigtest.moc"