File indexing completed on 2024-11-24 04:44:08
0001 /* 0002 * SPDX-FileCopyrightText: 2011 Christian Mollekopf <mollekopf@kolabsys.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-3.0-or-later 0005 */ 0006 0007 #include "benchmark.h" 0008 #include "conversion/kcalconversion.h" 0009 #include "kolabformatV2/event.h" 0010 #include "testutils.h" 0011 #include <kolabformat.h> 0012 0013 #include <KMime/Message> 0014 0015 #include <QTest> 0016 0017 KMime::Message::Ptr readMimeFile(const QString &fileName) 0018 { 0019 QFile file(fileName); 0020 file.open(QFile::ReadOnly); 0021 const QByteArray data = file.readAll(); 0022 Q_ASSERT(!data.isEmpty()); 0023 0024 auto msg = new KMime::Message; 0025 msg->setContent(data); 0026 msg->parse(); 0027 return KMime::Message::Ptr(msg); 0028 } 0029 0030 KMime::Content *findContentByType(const KMime::Message::Ptr &data, const QByteArray &type) 0031 { 0032 const KMime::Content::List list = data->contents(); 0033 for (KMime::Content *c : list) { 0034 if (c->contentType()->mimeType() == type) { 0035 return c; 0036 } 0037 } 0038 return nullptr; 0039 } 0040 0041 void BenchmarkTests::parsingBenchmarkComparison_data() 0042 { 0043 QTest::addColumn<bool>("v2Parser"); 0044 QTest::newRow("v2") << true; 0045 QTest::newRow("v3") << false; 0046 } 0047 0048 void BenchmarkTests::parsingBenchmarkComparison() 0049 { 0050 const KMime::Message::Ptr kolabItem = readMimeFile(TESTFILEDIR + QLatin1StringView("/v2/event/complex.ics.mime")); 0051 KMime::Content *xmlContent = findContentByType(kolabItem, "application/x-vnd.kolab.event"); 0052 QVERIFY(xmlContent); 0053 const QByteArray xmlData = xmlContent->decodedContent(); 0054 // qDebug() << xmlData; 0055 const QDomDocument xmlDoc = KolabV2::Event::loadDocument(QString::fromUtf8(xmlData)); 0056 QVERIFY(!xmlDoc.isNull()); 0057 const KCalendarCore::Event::Ptr i = KolabV2::Event::fromXml(xmlDoc, QStringLiteral("Europe/Berlin")); 0058 QVERIFY(i); 0059 const Kolab::Event &event = Kolab::Conversion::fromKCalendarCore(*i); 0060 const std::string &v3String = Kolab::writeEvent(event); 0061 0062 QFETCH(bool, v2Parser); 0063 0064 // Kolab::readEvent(v3String, false); //init parser (doesn't really change the results it seems) 0065 // qDebug() << QString::fromUtf8(xmlData); 0066 // qDebug() << "------------------------------------------------------------------------------------"; 0067 // qDebug() << QString::fromStdString(v3String); 0068 if (v2Parser) { 0069 QBENCHMARK { 0070 KolabV2::Event::fromXml(KolabV2::Event::loadDocument(QString::fromUtf8(xmlData)), QStringLiteral("Europe/Berlin")); 0071 } 0072 } else { 0073 QBENCHMARK { 0074 Kolab::readEvent(v3String, false); 0075 } 0076 } 0077 } 0078 0079 QTEST_MAIN(BenchmarkTests) 0080 0081 #include "moc_benchmark.cpp"