|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QStringList> |
|
43 #include <QtTest> |
|
44 |
|
45 #include <sstream> |
|
46 #include <string> |
|
47 #include <vector> |
|
48 |
|
49 class tst_QStringList: public QObject |
|
50 { |
|
51 Q_OBJECT |
|
52 |
|
53 private slots: |
|
54 void join() const; |
|
55 void join_data() const; |
|
56 |
|
57 void split() const; |
|
58 void split_data() const; |
|
59 |
|
60 void split_std() const; |
|
61 void split_std_data() const { return split_data(); } |
|
62 |
|
63 void split_stdw() const; |
|
64 void split_stdw_data() const { return split_data(); } |
|
65 |
|
66 void split_ba() const; |
|
67 void split_ba_data() const { return split_data(); } |
|
68 |
|
69 private: |
|
70 static QStringList populateList(const int count, const QString &unit); |
|
71 static QString populateString(const int count, const QString &unit); |
|
72 }; |
|
73 |
|
74 QStringList tst_QStringList::populateList(const int count, const QString &unit) |
|
75 { |
|
76 QStringList retval; |
|
77 |
|
78 for (int i = 0; i < count; ++i) |
|
79 retval.append(unit); |
|
80 |
|
81 return retval; |
|
82 } |
|
83 |
|
84 QString tst_QStringList::populateString(const int count, const QString &unit) |
|
85 { |
|
86 QString retval; |
|
87 |
|
88 for (int i = 0; i < count; ++i) { |
|
89 retval.append(unit); |
|
90 retval.append(QLatin1Char(':')); |
|
91 } |
|
92 |
|
93 return retval; |
|
94 } |
|
95 |
|
96 void tst_QStringList::join() const |
|
97 { |
|
98 QFETCH(QStringList, input); |
|
99 QFETCH(QString, separator); |
|
100 |
|
101 QBENCHMARK { |
|
102 input.join(separator); |
|
103 } |
|
104 } |
|
105 |
|
106 void tst_QStringList::join_data() const |
|
107 { |
|
108 QTest::addColumn<QStringList>("input"); |
|
109 QTest::addColumn<QString>("separator"); |
|
110 |
|
111 QTest::newRow("") |
|
112 << populateList(100, QLatin1String("unit")) |
|
113 << QString(); |
|
114 |
|
115 QTest::newRow("") |
|
116 << populateList(1000, QLatin1String("unit")) |
|
117 << QString(); |
|
118 |
|
119 QTest::newRow("") |
|
120 << populateList(10000, QLatin1String("unit")) |
|
121 << QString(); |
|
122 |
|
123 QTest::newRow("") |
|
124 << populateList(100000, QLatin1String("unit")) |
|
125 << QString(); |
|
126 } |
|
127 |
|
128 void tst_QStringList::split() const |
|
129 { |
|
130 QFETCH(QString, input); |
|
131 const QChar splitChar = ':'; |
|
132 |
|
133 QBENCHMARK { |
|
134 input.split(splitChar); |
|
135 } |
|
136 } |
|
137 |
|
138 void tst_QStringList::split_data() const |
|
139 { |
|
140 QTest::addColumn<QString>("input"); |
|
141 QString unit = QLatin1String("unit"); |
|
142 QTest::newRow("") << populateString(10, unit); |
|
143 QTest::newRow("") << populateString(100, unit); |
|
144 QTest::newRow("") << populateString(1000, unit); |
|
145 QTest::newRow("") << populateString(10000, unit); |
|
146 } |
|
147 |
|
148 void tst_QStringList::split_std() const |
|
149 { |
|
150 QFETCH(QString, input); |
|
151 const char split_char = ':'; |
|
152 std::string stdinput = input.toStdString(); |
|
153 |
|
154 QBENCHMARK { |
|
155 std::istringstream split(stdinput); |
|
156 std::vector<std::string> token; |
|
157 for (std::string each; |
|
158 std::getline(split, each, split_char); |
|
159 token.push_back(each)) |
|
160 ; |
|
161 } |
|
162 } |
|
163 |
|
164 void tst_QStringList::split_stdw() const |
|
165 { |
|
166 QFETCH(QString, input); |
|
167 const wchar_t split_char = ':'; |
|
168 std::wstring stdinput = input.toStdWString(); |
|
169 |
|
170 QBENCHMARK { |
|
171 std::wistringstream split(stdinput); |
|
172 std::vector<std::wstring> token; |
|
173 for (std::wstring each; |
|
174 std::getline(split, each, split_char); |
|
175 token.push_back(each)) |
|
176 ; |
|
177 } |
|
178 } |
|
179 |
|
180 void tst_QStringList::split_ba() const |
|
181 { |
|
182 QFETCH(QString, input); |
|
183 const char splitChar = ':'; |
|
184 QByteArray ba = input.toLatin1(); |
|
185 |
|
186 QBENCHMARK { |
|
187 ba.split(splitChar); |
|
188 } |
|
189 } |
|
190 |
|
191 QTEST_MAIN(tst_QStringList) |
|
192 |
|
193 #include "main.moc" |