File indexing completed on 2024-04-14 03:51:32

0001 /*
0002     SPDX-FileCopyrightText: 2005 Ingo Kloecker <kloecker@kde.org>
0003     SPDX-FileCopyrightText: 2007 Allen Winter <winter@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #include "../src/lib/text/ktexttohtml.h"
0009 #include "../src/lib/text/ktexttohtml_p.h"
0010 
0011 #include <QDebug>
0012 #include <QTest>
0013 #include <QUrl>
0014 
0015 Q_DECLARE_METATYPE(KTextToHTML::Options)
0016 
0017 class KTextToHTMLTest : public QObject
0018 {
0019     Q_OBJECT
0020 private Q_SLOTS:
0021     void benchHtmlConvert_data()
0022     {
0023         QTest::addColumn<QString>("text");
0024         QTest::addColumn<KTextToHTML::Options>("options");
0025 
0026         auto text = QStringLiteral("foo bar asdf :)").repeated(1000);
0027         QTest::newRow("plain") << text << KTextToHTML::Options();
0028         QTest::newRow("preserve-spaces") << text << KTextToHTML::Options(KTextToHTML::PreserveSpaces);
0029         QTest::newRow("highlight-text") << text << KTextToHTML::Options(KTextToHTML::HighlightText);
0030         QTest::newRow("replace-smileys") << text << KTextToHTML::Options(KTextToHTML::ReplaceSmileys);
0031         QTest::newRow("preserve-spaces+highlight-text") << text << KTextToHTML::Options(KTextToHTML::PreserveSpaces | KTextToHTML::HighlightText);
0032         QTest::newRow("preserve-spaces+highlight-text+replace-smileys")
0033             << text << KTextToHTML::Options(KTextToHTML::PreserveSpaces | KTextToHTML::HighlightText | KTextToHTML::ReplaceSmileys);
0034     }
0035 
0036     void benchHtmlConvert()
0037     {
0038         QFETCH(QString, text);
0039         QFETCH(KTextToHTML::Options, options);
0040 
0041         QBENCHMARK {
0042             const QString html = KTextToHTML::convertToHtml(text, options);
0043             Q_UNUSED(html);
0044         }
0045     }
0046 };
0047 
0048 QTEST_MAIN(KTextToHTMLTest)
0049 
0050 #include "ktexttohtmlbenchmarktest.moc"