File: benchmark.cpp

package info (click to toggle)
kdepim-runtime 4%3A22.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 27,092 kB
  • sloc: cpp: 93,545; xml: 1,000; sh: 99; javascript: 60; makefile: 13
file content (79 lines) | stat: -rw-r--r-- 2,520 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * SPDX-FileCopyrightText: 2011 Christian Mollekopf <mollekopf@kolabsys.com>
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include "benchmark.h"
#include "conversion/kcalconversion.h"
#include "kolabformatV2/event.h"
#include "testutils.h"
#include <kolabformat.h>

#include <KMime/Message>

#include <QTest>

KMime::Message::Ptr readMimeFile(const QString &fileName)
{
    QFile file(fileName);
    file.open(QFile::ReadOnly);
    const QByteArray data = file.readAll();
    Q_ASSERT(!data.isEmpty());

    auto msg = new KMime::Message;
    msg->setContent(data);
    msg->parse();
    return KMime::Message::Ptr(msg);
}

KMime::Content *findContentByType(const KMime::Message::Ptr &data, const QByteArray &type)
{
    const KMime::Content::List list = data->contents();
    for (KMime::Content *c : list) {
        if (c->contentType()->mimeType() == type) {
            return c;
        }
    }
    return nullptr;
}

void BenchmarkTests::parsingBenchmarkComparison_data()
{
    QTest::addColumn<bool>("v2Parser");
    QTest::newRow("v2") << true;
    QTest::newRow("v3") << false;
}

void BenchmarkTests::parsingBenchmarkComparison()
{
    const KMime::Message::Ptr kolabItem = readMimeFile(TESTFILEDIR + QLatin1String("/v2/event/complex.ics.mime"));
    KMime::Content *xmlContent = findContentByType(kolabItem, "application/x-vnd.kolab.event");
    QVERIFY(xmlContent);
    const QByteArray xmlData = xmlContent->decodedContent();
    //     qDebug() << xmlData;
    const QDomDocument xmlDoc = KolabV2::Event::loadDocument(QString::fromUtf8(xmlData));
    QVERIFY(!xmlDoc.isNull());
    const KCalendarCore::Event::Ptr i = KolabV2::Event::fromXml(xmlDoc, QStringLiteral("Europe/Berlin"));
    QVERIFY(i);
    const Kolab::Event &event = Kolab::Conversion::fromKCalendarCore(*i);
    const std::string &v3String = Kolab::writeEvent(event);

    QFETCH(bool, v2Parser);

    //     Kolab::readEvent(v3String, false); //init parser (doesn't really change the results it seems)
    //     qDebug() << QString::fromUtf8(xmlData);
    //     qDebug() << "------------------------------------------------------------------------------------";
    //     qDebug() << QString::fromStdString(v3String);
    if (v2Parser) {
        QBENCHMARK {
            KolabV2::Event::fromXml(KolabV2::Event::loadDocument(QString::fromUtf8(xmlData)), QStringLiteral("Europe/Berlin"));
        }
    } else {
        QBENCHMARK {
            Kolab::readEvent(v3String, false);
        }
    }
}

QTEST_MAIN(BenchmarkTests)