1 | /* |
2 | Copyright (c) 2010 Volker Krause <vkrause@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #include <QtTest/QTest> |
21 | #include "../imapparser_p.h" |
22 | |
23 | using namespace Akonadi; |
24 | |
25 | Q_DECLARE_METATYPE(QList<QByteArray>) |
26 | |
27 | class ImapParserBenchmark : public QObject |
28 | { |
29 | Q_OBJECT |
30 | private Q_SLOTS: |
31 | void quote_data() |
32 | { |
33 | QTest::addColumn<QByteArray>("input" ); |
34 | QTest::newRow("empty" ) << QByteArray(); |
35 | QTest::newRow("10-idle" ) << QByteArray("ababababab" ); |
36 | QTest::newRow("10-quote" ) << QByteArray("\"abababab\"" ); |
37 | QTest::newRow("50-idle" ) << QByteArray("ababababababababababababababababababababababababab" ); |
38 | QTest::newRow("50-quote" ) << QByteArray("\"abababab\ncabababab\ncabababab\ncabababab\ncabababab\"" ); |
39 | } |
40 | |
41 | void quote() |
42 | { |
43 | QFETCH(QByteArray, input); |
44 | QBENCHMARK { |
45 | ImapParser::quote(input); |
46 | } |
47 | } |
48 | |
49 | void join_data() |
50 | { |
51 | QTest::addColumn<QList<QByteArray> >("list" ); |
52 | QTest::newRow("empty" ) << QList<QByteArray>(); |
53 | QTest::newRow("single" ) << (QList<QByteArray>() << "ababab" ); |
54 | QTest::newRow("two" ) << (QList<QByteArray>() << "ababab" << "ababab" ); |
55 | QTest::newRow("five" ) << (QList<QByteArray>() << "ababab" << "ababab" << "ababab" << "ababab" << "ababab" ); |
56 | QList<QByteArray> list; |
57 | for (int i = 0; i < 50; ++i) { |
58 | list << "ababab" ; |
59 | } |
60 | QTest::newRow("a lot" ) << list; |
61 | } |
62 | |
63 | void join() |
64 | { |
65 | QFETCH(QList<QByteArray>, list); |
66 | QBENCHMARK { |
67 | ImapParser::join(list, " " ); |
68 | } |
69 | } |
70 | |
71 | void parseParenthesizedList_data() |
72 | { |
73 | QTest::addColumn<QByteArray>("data" ); |
74 | QTest::newRow("empty" ) << QByteArray(); |
75 | QTest::newRow("unnested" ) << QByteArray("(\"Foo Bar\" NIL \"foobar\" \"test.com\")" ); |
76 | QTest::newRow("nested" ) << QByteArray("((\"Foo Bar\" NIL \"foobar\" \"test.com\"))" ); |
77 | QTest::newRow("nested-long" ) << QByteArray("(UID 86 REV 0 MIMETYPE \"message/rfc822\" COLLECTIONID 13 SIZE 6114 FLAGS (\\SEEN)" |
78 | " ANCESTORS ((13 \"/INBOX\") (12 \"imap://mail@mail.test.com/\") (0 \"\")) PLD:ENVELOPE[1] {396}" |
79 | " (\"Fri, 04 Jun 2010 09:07:54 +0200\" \"Re: [ADMIN] foobar available again!\"" |
80 | " ((\"Foo Bar\" NIL \"foobar\" \"test.com\"))" |
81 | " NIL NIL" |
82 | " ((\"Asdf Bla Blub\" NIL \"asdf.bla.blub\" \"123test.org\"))" |
83 | " ((NIL NIL \"muh.kuh\" \"lalala.com\") (\"Konqi KDE\" NIL \"konqi\" \"kde.org\") (NIL NIL \"all\" \"test.com\"))" |
84 | " NIL \"<201006040905.33367.foo.bar@test.com>\" \"<4C08A64A.9020205@123test.org>\"" |
85 | " \"<201006040142.56540.muh.kuh@lalala.com> <201006040704.39648.konqi@kde.org> <201006040905.33367.foo.bar@test.com>\"" |
86 | "))" ); |
87 | } |
88 | |
89 | void parseParenthesizedList() |
90 | { |
91 | QFETCH(QByteArray, data); |
92 | QVarLengthArray<QByteArray, 16> result; |
93 | QBENCHMARK { |
94 | ImapParser::parseParenthesizedList(data, result, 0); |
95 | } |
96 | } |
97 | }; |
98 | |
99 | #include "imapparserbenchmark.moc" |
100 | |
101 | QTEST_APPLESS_MAIN(ImapParserBenchmark) |
102 | |