File: benchmark.cpp

package info (click to toggle)
kdepim-runtime 4%3A20.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 25,680 kB
  • sloc: cpp: 94,670; xml: 981; sh: 101; javascript: 60; makefile: 13
file content (87 lines) | stat: -rw-r--r-- 3,147 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
80
81
82
83
84
85
86
87
/*
 * Copyright (C) 2011  Christian Mollekopf <mollekopf@kolabsys.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#include "benchmark.h"
#include "kolabformatV2/event.h"
#include "conversion/kcalconversion.h"
#include <kmime/kmime_message.h>
#include <kolabformat.h>
#include "testutils.h"
#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());

    KMime::Message *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)