File indexing completed on 2025-04-27 13:16:05
0001 /* 0002 This file is part of LibSyndication. 0003 SPDX-FileCopyrightText: Laurent Montel <montel@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0006 */ 0007 0008 #include "syndicationtest.h" 0009 #include "documentsource.h" 0010 #include "feed.h" 0011 #include "parsercollection.h" 0012 #include "specificdocument.h" 0013 0014 #include <QByteArray> 0015 #include <QDebug> 0016 #include <QFile> 0017 0018 #include <QTest> 0019 QTEST_GUILESS_MAIN(SyndicationTest) 0020 using namespace Syndication; 0021 #ifndef Q_OS_WIN 0022 void initLocale() 0023 { 0024 setenv("LC_ALL", "en_US.utf-8", 1); 0025 } 0026 0027 Q_CONSTRUCTOR_FUNCTION(initLocale) 0028 #endif 0029 0030 SyndicationTest::SyndicationTest(QObject *parent) 0031 : QObject(parent) 0032 { 0033 } 0034 0035 void SyndicationTest::testSyncationFile_data() 0036 { 0037 QTest::addColumn<QString>("fileName"); 0038 QTest::addColumn<QString>("referenceFileName"); 0039 0040 QDir dir(QStringLiteral(SYNDICATION_DATA_DIR "/atom")); 0041 auto l = dir.entryList(QStringList(QStringLiteral("*.xml")), QDir::Files | QDir::Readable | QDir::NoSymLinks); 0042 for (const QString &file : l) { 0043 QTest::newRow(file.toLatin1().constData()) << QString(dir.path() + QLatin1Char('/') + file) 0044 << QString(dir.path() + QLatin1Char('/') + file + QLatin1String(".expected")); 0045 } 0046 QDir dirRdf(QStringLiteral(SYNDICATION_DATA_DIR "/rdf")); 0047 l = dirRdf.entryList(QStringList(QStringLiteral("*.xml")), QDir::Files | QDir::Readable | QDir::NoSymLinks); 0048 for (const QString &file : l) { 0049 QTest::newRow(file.toLatin1().constData()) << QString(dirRdf.path() + QLatin1Char('/') + file) 0050 << QString(dirRdf.path() + QLatin1Char('/') + file + QLatin1String(".expected")); 0051 } 0052 QDir dirRss2(QStringLiteral(SYNDICATION_DATA_DIR "/rss2")); 0053 l = dirRss2.entryList(QStringList(QStringLiteral("*.xml")), QDir::Files | QDir::Readable | QDir::NoSymLinks); 0054 for (const QString &file : l) { 0055 QTest::newRow(file.toLatin1().constData()) << QString(dirRss2.path() + QLatin1Char('/') + file) 0056 << QString(dirRss2.path() + QLatin1Char('/') + file + QLatin1String(".expected")); 0057 } 0058 } 0059 0060 void SyndicationTest::testSyncationFile() 0061 { 0062 QFETCH(QString, fileName); 0063 QFETCH(QString, referenceFileName); 0064 QFile f(fileName); 0065 QVERIFY(f.open(QIODevice::ReadOnly | QIODevice::Text)); 0066 0067 DocumentSource src(f.readAll(), QStringLiteral("http://libsyndicationtest")); 0068 f.close(); 0069 0070 FeedPtr ptr(Syndication::parse(src)); 0071 QVERIFY(ptr); 0072 0073 const QString result = ptr->debugInfo(); 0074 0075 QFile expFile(referenceFileName); 0076 QVERIFY(expFile.open(QIODevice::ReadOnly | QIODevice::Text)); 0077 const QByteArray expected = expFile.readAll(); 0078 expFile.close(); 0079 0080 const QByteArray baResult = result.toUtf8().trimmed(); 0081 const QByteArray baExpected = expected.trimmed(); 0082 const bool compare = (baResult == baExpected); 0083 if (!compare) { 0084 qDebug() << " result.toUtf8().trimmed()" << baResult; 0085 qDebug() << " expected " << baExpected; 0086 #if 0 0087 QFile headerFile(QStringLiteral("/tmp/bb.txt")); 0088 headerFile.open(QIODevice::WriteOnly | QIODevice::Text); 0089 QTextStream outHeaderStream(&headerFile); 0090 outHeaderStream << baResult.trimmed(); 0091 headerFile.close(); 0092 #endif 0093 QCOMPARE(QString::fromUtf8(baResult).split(QLatin1Char('\n')), QString::fromUtf8(baExpected).split(QLatin1Char('\n'))); 0094 } 0095 QVERIFY(compare); 0096 } 0097 0098 #include "moc_syndicationtest.cpp"