1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtCore module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include <QtTest/QtTest> |
30 | #include <QtCore/QString> |
31 | #include <private/qstringiterator_p.h> |
32 | |
33 | class tst_QStringIterator : public QObject |
34 | { |
35 | Q_OBJECT |
36 | private slots: |
37 | void sweep_data(); |
38 | void sweep(); |
39 | |
40 | void position(); |
41 | }; |
42 | |
43 | void tst_QStringIterator::sweep_data() |
44 | { |
45 | QTest::addColumn<QString>(name: "string" ); |
46 | QTest::addColumn<bool>(name: "valid" ); |
47 | QTest::addColumn<int>(name: "count" ); |
48 | |
49 | QTest::newRow(dataTag: "sweep_00" ) << QString::fromUtf8(str: "" , size: 0) << true << 0; |
50 | QTest::newRow(dataTag: "sweep_01" ) << QString::fromUtf8(str: "a" , size: 1) << true << 1; |
51 | QTest::newRow(dataTag: "sweep_02" ) << QString::fromUtf8(str: "a string" , size: 8) << true << 8; |
52 | QTest::newRow(dataTag: "sweep_03" ) << QString::fromUtf8(str: "\xc3\xa0\xc3\xa8\xc3\xac\xc3\xb2\xc3\xb9" , size: 10) << true << 5; |
53 | QTest::newRow(dataTag: "sweep_04" ) << QString::fromUtf8(str: "\xc3\x9f\xe2\x80\x94\xc2\xa1" , size: 7) << true << 3; |
54 | QTest::newRow(dataTag: "sweep_05" ) << QString::fromUtf8(str: "\xe6\xb0\xb4\xe6\xb0\xb5\xe6\xb0\xb6\xe6\xb0\xb7\xe6\xb0\xb8\xe6\xb0\xb9" , size: 18) << true << 6; |
55 | QTest::newRow(dataTag: "sweep_06" ) << QString::fromUtf8(str: "\xf0\x9f\x98\x81\xf0\x9f\x98\x82\x61\x62\x63\xf0\x9f\x98\x83\xc4\x91\xc3\xa8\xef\xac\x80\xf0\x9f\x98\x84\xf0\x9f\x98\x85" , size: 30) << true << 11; |
56 | QTest::newRow(dataTag: "sweep_07" ) << QString::fromUtf8(str: "\xf0\x9f\x82\xaa\xf0\x9f\x82\xab\xf0\x9f\x82\xad\xf0\x9f\x82\xae\xf0\x9f\x82\xa1\x20\x52\x4f\x59\x41\x4c\x20\x46\x4c\x55\x53\x48\x20\x4f\x46\x20\x53\x50\x41\x44\x45\x53" , size: 42) << true << 27; |
57 | QTest::newRow(dataTag: "sweep_08" ) << QString::fromUtf8(str: "abc\0def" , size: 7) << true << 7; |
58 | QTest::newRow(dataTag: "sweep_09" ) << QString::fromUtf8(str: "\xc3\xa0\xce\xb2\xc3\xa7\xf0\x9f\x80\xb9\xf0\x9f\x80\xb8\x00\xf0\x9f\x80\xb1\x00\xf0\x9f\x80\xb3\xf0\x9f\x81\x85\xe1\xb8\x8a\xc4\x99\xc6\x92" , size: 35) << true << 13; |
59 | |
60 | QTest::newRow(dataTag: "sweep_invalid_00" ) << QString(QChar(0xd800)) << false << 1; |
61 | QTest::newRow(dataTag: "sweep_invalid_01" ) << QString(QChar(0xdc00)) << false << 1; |
62 | QTest::newRow(dataTag: "sweep_invalid_02" ) << QString(QChar(0xdbff)) << false << 1; |
63 | QTest::newRow(dataTag: "sweep_invalid_03" ) << QString(QChar(0xdfff)) << false << 1; |
64 | |
65 | #define QSTRING_FROM_QCHARARRAY(x) (QString((x), sizeof(x)/sizeof((x)[0]))) |
66 | |
67 | static const QChar invalid_04[] = { |
68 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
69 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
70 | QLatin1Char('d'), QChar(0xd800) |
71 | }; |
72 | QTest::newRow(dataTag: "sweep_invalid_04" ) << QSTRING_FROM_QCHARARRAY(invalid_04) << false << 8; |
73 | |
74 | static const QChar invalid_05[] = { |
75 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
76 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
77 | QLatin1Char('d'), QChar(0xd800), QLatin1Char('x') |
78 | }; |
79 | QTest::newRow(dataTag: "sweep_invalid_05" ) << QSTRING_FROM_QCHARARRAY(invalid_05) << false << 9; |
80 | |
81 | static const QChar invalid_06[] = { |
82 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
83 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
84 | QLatin1Char('d'), QChar(0xdc00) |
85 | }; |
86 | QTest::newRow(dataTag: "sweep_invalid_06" ) << QSTRING_FROM_QCHARARRAY(invalid_06) << false << 8; |
87 | |
88 | static const QChar invalid_07[] = { |
89 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
90 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
91 | QLatin1Char('d'), QChar(0xdc00), QLatin1Char('x') |
92 | }; |
93 | QTest::newRow(dataTag: "sweep_invalid_07" ) << QSTRING_FROM_QCHARARRAY(invalid_07) << false << 9; |
94 | |
95 | static const QChar invalid_08[] = { |
96 | QChar(0xd800), |
97 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
98 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
99 | QLatin1Char('d') |
100 | }; |
101 | QTest::newRow(dataTag: "sweep_invalid_08" ) << QSTRING_FROM_QCHARARRAY(invalid_08) << false << 8; |
102 | |
103 | static const QChar invalid_09[] = { |
104 | QChar(0xdc00), |
105 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
106 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
107 | QLatin1Char('d') |
108 | }; |
109 | QTest::newRow(dataTag: "sweep_invalid_09" ) << QSTRING_FROM_QCHARARRAY(invalid_09) << false << 8; |
110 | |
111 | static const QChar invalid_10[] = { |
112 | QChar(0xd800), QChar(0xd800), |
113 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
114 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
115 | QLatin1Char('d') |
116 | }; |
117 | QTest::newRow(dataTag: "sweep_invalid_10" ) << QSTRING_FROM_QCHARARRAY(invalid_10) << false << 9; |
118 | |
119 | static const QChar invalid_11[] = { |
120 | QChar(0xdc00), QChar(0xd800), |
121 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
122 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
123 | QLatin1Char('d') |
124 | }; |
125 | QTest::newRow(dataTag: "sweep_invalid_11" ) << QSTRING_FROM_QCHARARRAY(invalid_11) << false << 9; |
126 | |
127 | static const QChar invalid_12[] = { |
128 | QChar(0xdc00), QChar(0xdc00), |
129 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
130 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
131 | QLatin1Char('d') |
132 | }; |
133 | QTest::newRow(dataTag: "sweep_invalid_12" ) << QSTRING_FROM_QCHARARRAY(invalid_12) << false << 9; |
134 | |
135 | static const QChar invalid_13[] = { |
136 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
137 | QChar(0xd800), QChar(0xdf00), // U+10300 OLD ITALIC LETTER A |
138 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
139 | QLatin1Char('d'), QChar(0xd800) |
140 | }; |
141 | QTest::newRow(dataTag: "sweep_invalid_13" ) << QSTRING_FROM_QCHARARRAY(invalid_13) << false << 9; |
142 | |
143 | static const QChar invalid_14[] = { |
144 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
145 | QChar(0xd800), QChar(0xdf00), // U+10300 OLD ITALIC LETTER A |
146 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
147 | QLatin1Char('d'), QChar(0xd800), QLatin1Char('x') |
148 | }; |
149 | QTest::newRow(dataTag: "sweep_invalid_14" ) << QSTRING_FROM_QCHARARRAY(invalid_14) << false << 10; |
150 | |
151 | static const QChar invalid_15[] = { |
152 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
153 | QChar(0xd800), QChar(0xdf00), // U+10300 OLD ITALIC LETTER A |
154 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
155 | QLatin1Char('d'), QChar(0xdc00) |
156 | }; |
157 | QTest::newRow(dataTag: "sweep_invalid_15" ) << QSTRING_FROM_QCHARARRAY(invalid_15) << false << 9; |
158 | |
159 | static const QChar invalid_16[] = { |
160 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
161 | QChar(0xd800), QChar(0xdf00), // U+10300 OLD ITALIC LETTER A |
162 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
163 | QLatin1Char('d'), QChar(0xdc00), QLatin1Char('x') |
164 | }; |
165 | QTest::newRow(dataTag: "sweep_invalid_16" ) << QSTRING_FROM_QCHARARRAY(invalid_16) << false << 10; |
166 | |
167 | static const QChar invalid_17[] = { |
168 | QChar(0xd800), |
169 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
170 | QChar(0xd800), QChar(0xdf00), // U+10300 OLD ITALIC LETTER A |
171 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
172 | QLatin1Char('d') |
173 | }; |
174 | QTest::newRow(dataTag: "sweep_invalid_17" ) << QSTRING_FROM_QCHARARRAY(invalid_17) << false << 9; |
175 | |
176 | static const QChar invalid_18[] = { |
177 | QChar(0xdc00), |
178 | QLatin1Char('i'), QLatin1Char('n'), QLatin1Char('v'), |
179 | QChar(0xd800), QChar(0xdf00), // U+10300 OLD ITALIC LETTER A |
180 | QLatin1Char('a'), QLatin1Char('l'), QLatin1Char('i'), |
181 | QLatin1Char('d') |
182 | }; |
183 | QTest::newRow(dataTag: "sweep_invalid_18" ) << QSTRING_FROM_QCHARARRAY(invalid_18) << false << 9; |
184 | |
185 | #undef QSTRING_FROM_QCHARARRAY |
186 | } |
187 | |
188 | void tst_QStringIterator::sweep() |
189 | { |
190 | QFETCH(QString, string); |
191 | QFETCH(bool, valid); |
192 | |
193 | QStringIterator i(string); |
194 | int count = 0; |
195 | QString rebuiltString; |
196 | |
197 | while (i.hasNext()) { |
198 | const uint peekedCodePoint = i.peekNext(invalidAs: ~0u); |
199 | const uint codePoint = i.next(invalidAs: ~0u); |
200 | |
201 | QVERIFY(peekedCodePoint == codePoint); |
202 | |
203 | if (codePoint == ~0u) |
204 | rebuiltString += *(i.position() - 1); |
205 | else |
206 | rebuiltString += QString::fromUcs4(&codePoint, size: 1); |
207 | |
208 | ++count; |
209 | } |
210 | |
211 | QTEST(count, "count" ); |
212 | QTEST(rebuiltString, "string" ); |
213 | rebuiltString.clear(); |
214 | |
215 | while (i.hasPrevious()) { |
216 | const uint peekedCodePoint = i.peekPrevious(invalidAs: ~0u); |
217 | const uint codePoint = i.previous(invalidAs: ~0u); |
218 | |
219 | QVERIFY(peekedCodePoint == codePoint); |
220 | |
221 | --count; |
222 | } |
223 | |
224 | QCOMPARE(count, 0); |
225 | |
226 | while (i.hasNext()) { |
227 | i.advance(); |
228 | ++count; |
229 | } |
230 | |
231 | QTEST(count, "count" ); |
232 | |
233 | while (i.hasPrevious()) { |
234 | i.recede(); |
235 | --count; |
236 | } |
237 | |
238 | QCOMPARE(count, 0); |
239 | |
240 | if (valid) { |
241 | while (i.hasNext()) { |
242 | const uint peekedCodePoint = i.peekNextUnchecked(); |
243 | const uint codePoint = i.nextUnchecked(); |
244 | |
245 | QVERIFY(peekedCodePoint == codePoint); |
246 | QVERIFY(codePoint <= 0x10FFFFu); |
247 | rebuiltString += QString::fromUcs4(&codePoint, size: 1); |
248 | ++count; |
249 | } |
250 | |
251 | QTEST(count, "count" ); |
252 | QTEST(rebuiltString, "string" ); |
253 | |
254 | while (i.hasPrevious()) { |
255 | const uint peekedCodePoint = i.peekPreviousUnchecked(); |
256 | const uint codePoint = i.previousUnchecked(); |
257 | |
258 | QVERIFY(peekedCodePoint == codePoint); |
259 | |
260 | --count; |
261 | } |
262 | |
263 | QCOMPARE(count, 0); |
264 | |
265 | while (i.hasNext()) { |
266 | i.advanceUnchecked(); |
267 | ++count; |
268 | } |
269 | |
270 | QTEST(count, "count" ); |
271 | |
272 | while (i.hasPrevious()) { |
273 | i.recedeUnchecked(); |
274 | --count; |
275 | } |
276 | |
277 | QCOMPARE(count, 0); |
278 | } |
279 | } |
280 | |
281 | void tst_QStringIterator::position() |
282 | { |
283 | static const QChar stringData[] = |
284 | { |
285 | // codeunit count: 0 |
286 | QLatin1Char('a'), QLatin1Char('b'), QLatin1Char('c'), |
287 | // codeunit count: 3 |
288 | QChar(0x00A9), // U+00A9 COPYRIGHT SIGN |
289 | // codeunit count: 4 |
290 | QChar(0x00AE), // U+00AE REGISTERED SIGN |
291 | // codeunit count: 5 |
292 | QLatin1Char('d'), QLatin1Char('e'), QLatin1Char('f'), |
293 | // codeunit count: 8 |
294 | QLatin1Char('\0'), |
295 | // codeunit count: 9 |
296 | QLatin1Char('g'), QLatin1Char('h'), QLatin1Char('i'), |
297 | // codeunit count: 12 |
298 | QChar(0xD834), QChar(0xDD1E), // U+1D11E MUSICAL SYMBOL G CLEF |
299 | // codeunit count: 14 |
300 | QChar(0xD834), QChar(0xDD21), // U+1D121 MUSICAL SYMBOL C CLEF |
301 | // codeunit count: 16 |
302 | QLatin1Char('j'), |
303 | // codeunit count: 17 |
304 | QChar(0xD800), // stray high surrogate |
305 | // codeunit count: 18 |
306 | QLatin1Char('k'), |
307 | // codeunit count: 19 |
308 | QChar(0xDC00), // stray low surrogate |
309 | // codeunit count: 20 |
310 | QLatin1Char('l'), |
311 | // codeunit count: 21 |
312 | QChar(0xD800), QChar(0xD800), // two high surrogates |
313 | // codeunit count: 23 |
314 | QLatin1Char('m'), |
315 | // codeunit count: 24 |
316 | QChar(0xDC00), QChar(0xDC00), // two low surrogates |
317 | // codeunit count: 26 |
318 | QLatin1Char('n'), |
319 | // codeunit count: 27 |
320 | QChar(0xD800), QChar(0xD800), QChar(0xDC00), // stray high surrogate followed by valid pair |
321 | // codeunit count: 30 |
322 | QLatin1Char('o'), |
323 | // codeunit count: 31 |
324 | QChar(0xDC00), QChar(0xD800), QChar(0xDC00), // stray low surrogate followed by valid pair |
325 | // codeunit count: 34 |
326 | QLatin1Char('p') |
327 | // codeunit count: 35 |
328 | }; |
329 | static const int stringDataSize = sizeof(stringData) / sizeof(stringData[0]); |
330 | |
331 | QStringIterator i(QStringView(stringData, stringDataSize)); |
332 | |
333 | QCOMPARE(i.position(), stringData); |
334 | QVERIFY(i.hasNext()); |
335 | QVERIFY(!i.hasPrevious()); |
336 | |
337 | i.setPosition(stringData + stringDataSize); |
338 | QCOMPARE(i.position(), stringData + stringDataSize); |
339 | QVERIFY(!i.hasNext()); |
340 | QVERIFY(i.hasPrevious()); |
341 | |
342 | #define QCHAR_UNICODE_VALUE(x) ((uint)(QChar(x).unicode())) |
343 | |
344 | const QChar *begin = stringData; |
345 | i.setPosition(begin); |
346 | QCOMPARE(i.position(), begin); |
347 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('a'))); |
348 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('a'))); |
349 | |
350 | QCOMPARE(i.position(), begin + 1); |
351 | |
352 | i.setPosition(begin + 2); |
353 | QCOMPARE(i.position(), begin + 2); |
354 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('c'))); |
355 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('c'))); |
356 | |
357 | QCOMPARE(i.position(), begin + 3); |
358 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(0x00A9)); |
359 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(0x00A9)); |
360 | |
361 | QCOMPARE(i.position(), begin + 4); |
362 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(0x00AE)); |
363 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(0x00AE)); |
364 | |
365 | QCOMPARE(i.position(), begin + 5); |
366 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(0x00AE)); |
367 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(0x00AE)); |
368 | |
369 | QCOMPARE(i.position(), begin + 4); |
370 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(0x00A9)); |
371 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(0x00A9)); |
372 | |
373 | QCOMPARE(i.position(), begin + 3); |
374 | |
375 | i.setPosition(begin + 8); |
376 | QCOMPARE(i.position(), begin + 8); |
377 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('\0'))); |
378 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('\0'))); |
379 | |
380 | QCOMPARE(i.position(), begin + 9); |
381 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('g'))); |
382 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('g'))); |
383 | |
384 | QCOMPARE(i.position(), begin + 10); |
385 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(QLatin1Char('g'))); |
386 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(QLatin1Char('g'))); |
387 | |
388 | QCOMPARE(i.position(), begin + 9); |
389 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(QLatin1Char('\0'))); |
390 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(QLatin1Char('\0'))); |
391 | |
392 | QCOMPARE(i.position(), begin + 8); |
393 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(QLatin1Char('f'))); |
394 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(QLatin1Char('f'))); |
395 | |
396 | QCOMPARE(i.position(), begin + 7); |
397 | |
398 | i.advanceUnchecked(); |
399 | i.advanceUnchecked(); |
400 | i.advanceUnchecked(); |
401 | i.advanceUnchecked(); |
402 | i.advanceUnchecked(); |
403 | |
404 | QCOMPARE(i.position(), begin + 12); |
405 | QCOMPARE(i.peekNext(), 0x1D11Eu); |
406 | QCOMPARE(i.next(), 0x1D11Eu); |
407 | |
408 | QCOMPARE(i.position(), begin + 14); |
409 | QCOMPARE(i.peekNext(), 0x1D121u); |
410 | QCOMPARE(i.next(), 0x1D121u); |
411 | |
412 | QCOMPARE(i.position(), begin + 16); |
413 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('j'))); |
414 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('j'))); |
415 | |
416 | QCOMPARE(i.position(), begin + 17); |
417 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(QLatin1Char('j'))); |
418 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(QLatin1Char('j'))); |
419 | |
420 | QCOMPARE(i.position(), begin + 16); |
421 | QCOMPARE(i.peekPrevious(), 0x1D121u); |
422 | QCOMPARE(i.previous(), 0x1D121u); |
423 | |
424 | QCOMPARE(i.position(), begin + 14); |
425 | QCOMPARE(i.peekPrevious(), 0x1D11Eu); |
426 | QCOMPARE(i.previous(), 0x1D11Eu); |
427 | |
428 | QCOMPARE(i.position(), begin + 12); |
429 | |
430 | |
431 | i.setPosition(begin + 13); |
432 | QCOMPARE(i.position(), begin + 13); |
433 | |
434 | QCOMPARE(i.peekNext(), 0xFFFDu); |
435 | QCOMPARE(i.next(), 0xFFFDu); |
436 | |
437 | QCOMPARE(i.position(), begin + 14); |
438 | QCOMPARE(i.peekNext(), 0x1D121u); |
439 | QCOMPARE(i.next(), 0x1D121u); |
440 | |
441 | QCOMPARE(i.position(), begin + 16); |
442 | |
443 | |
444 | i.setPosition(begin + 15); |
445 | QCOMPARE(i.position(), begin + 15); |
446 | |
447 | QCOMPARE(i.peekPrevious(), 0xFFFDu); |
448 | QCOMPARE(i.previous(), 0xFFFDu); |
449 | |
450 | QCOMPARE(i.position(), begin + 14); |
451 | QCOMPARE(i.peekPrevious(), 0x1D11Eu); |
452 | QCOMPARE(i.previous(), 0x1D11Eu); |
453 | |
454 | QCOMPARE(i.position(), begin + 12); |
455 | |
456 | i.advanceUnchecked(); |
457 | i.advanceUnchecked(); |
458 | |
459 | QCOMPARE(i.position(), begin + 16); |
460 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('j'))); |
461 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('j'))); |
462 | |
463 | QCOMPARE(i.position(), begin + 17); |
464 | QCOMPARE(i.peekNext(), 0xFFFDu); |
465 | QCOMPARE(i.next(), 0xFFFDu); |
466 | |
467 | QCOMPARE(i.position(), begin + 18); |
468 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('k'))); |
469 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('k'))); |
470 | |
471 | QCOMPARE(i.position(), begin + 19); |
472 | QCOMPARE(i.peekNext(), 0xFFFDu); |
473 | QCOMPARE(i.next(), 0xFFFDu); |
474 | |
475 | QCOMPARE(i.position(), begin + 20); |
476 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('l'))); |
477 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('l'))); |
478 | |
479 | QCOMPARE(i.position(), begin + 21); |
480 | QCOMPARE(i.peekNext(), 0xFFFDu); |
481 | QCOMPARE(i.next(), 0xFFFDu); |
482 | |
483 | QCOMPARE(i.position(), begin + 22); |
484 | QCOMPARE(i.peekNext(), 0xFFFDu); |
485 | QCOMPARE(i.next(), 0xFFFDu); |
486 | |
487 | QCOMPARE(i.position(), begin + 23); |
488 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('m'))); |
489 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('m'))); |
490 | |
491 | QCOMPARE(i.position(), begin + 24); |
492 | QCOMPARE(i.peekNext(), 0xFFFDu); |
493 | QCOMPARE(i.next(), 0xFFFDu); |
494 | |
495 | QCOMPARE(i.position(), begin + 25); |
496 | QCOMPARE(i.peekNext(), 0xFFFDu); |
497 | QCOMPARE(i.next(), 0xFFFDu); |
498 | |
499 | QCOMPARE(i.position(), begin + 26); |
500 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('n'))); |
501 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('n'))); |
502 | |
503 | QCOMPARE(i.position(), begin + 27); |
504 | QCOMPARE(i.peekNext(), 0xFFFDu); |
505 | QCOMPARE(i.next(), 0xFFFDu); |
506 | |
507 | QCOMPARE(i.position(), begin + 28); |
508 | QCOMPARE(i.peekNext(), 0x10000u); |
509 | QCOMPARE(i.next(), 0x10000u); |
510 | |
511 | QCOMPARE(i.position(), begin + 30); |
512 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('o'))); |
513 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('o'))); |
514 | |
515 | QCOMPARE(i.position(), begin + 31); |
516 | QCOMPARE(i.peekNext(), 0xFFFDu); |
517 | QCOMPARE(i.next(), 0xFFFDu); |
518 | |
519 | QCOMPARE(i.position(), begin + 32); |
520 | QCOMPARE(i.peekNext(), 0x10000u); |
521 | QCOMPARE(i.next(), 0x10000u); |
522 | |
523 | QCOMPARE(i.position(), begin + 34); |
524 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('p'))); |
525 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('p'))); |
526 | |
527 | QVERIFY(!i.hasNext()); |
528 | |
529 | QCOMPARE(i.position(), begin + 35); |
530 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(QLatin1Char('p'))); |
531 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(QLatin1Char('p'))); |
532 | |
533 | QCOMPARE(i.position(), begin + 34); |
534 | QCOMPARE(i.peekPrevious(), 0x10000u); |
535 | QCOMPARE(i.previous(), 0x10000u); |
536 | |
537 | QCOMPARE(i.position(), begin + 32); |
538 | QCOMPARE(i.peekPrevious(), 0xFFFDu); |
539 | QCOMPARE(i.previous(), 0xFFFDu); |
540 | |
541 | QCOMPARE(i.position(), begin + 31); |
542 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(QLatin1Char('o'))); |
543 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(QLatin1Char('o'))); |
544 | |
545 | QCOMPARE(i.position(), begin + 30); |
546 | QCOMPARE(i.peekPrevious(), 0x10000u); |
547 | QCOMPARE(i.previous(), 0x10000u); |
548 | |
549 | QCOMPARE(i.position(), begin + 28); |
550 | QCOMPARE(i.peekPrevious(), 0xFFFDu); |
551 | QCOMPARE(i.previous(), 0xFFFDu); |
552 | |
553 | QCOMPARE(i.position(), begin + 27); |
554 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(QLatin1Char('n'))); |
555 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(QLatin1Char('n'))); |
556 | |
557 | QCOMPARE(i.position(), begin + 26); |
558 | QCOMPARE(i.peekPrevious(), 0xFFFDu); |
559 | QCOMPARE(i.previous(), 0xFFFDu); |
560 | |
561 | QCOMPARE(i.position(), begin + 25); |
562 | QCOMPARE(i.peekPrevious(), 0xFFFDu); |
563 | QCOMPARE(i.previous(), 0xFFFDu); |
564 | |
565 | QCOMPARE(i.position(), begin + 24); |
566 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(QLatin1Char('m'))); |
567 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(QLatin1Char('m'))); |
568 | |
569 | QCOMPARE(i.position(), begin + 23); |
570 | QCOMPARE(i.peekPrevious(), 0xFFFDu); |
571 | QCOMPARE(i.previous(), 0xFFFDu); |
572 | |
573 | QCOMPARE(i.position(), begin + 22); |
574 | QCOMPARE(i.peekPrevious(), 0xFFFDu); |
575 | QCOMPARE(i.previous(), 0xFFFDu); |
576 | |
577 | QCOMPARE(i.position(), begin + 21); |
578 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(QLatin1Char('l'))); |
579 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(QLatin1Char('l'))); |
580 | |
581 | QCOMPARE(i.position(), begin + 20); |
582 | QCOMPARE(i.peekPrevious(), 0xFFFDu); |
583 | QCOMPARE(i.previous(), 0xFFFDu); |
584 | |
585 | QCOMPARE(i.position(), begin + 19); |
586 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(QLatin1Char('k'))); |
587 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(QLatin1Char('k'))); |
588 | |
589 | QCOMPARE(i.position(), begin + 18); |
590 | QCOMPARE(i.peekPrevious(), 0xFFFDu); |
591 | QCOMPARE(i.previous(), 0xFFFDu); |
592 | |
593 | QCOMPARE(i.position(), begin + 17); |
594 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(QLatin1Char('j'))); |
595 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(QLatin1Char('j'))); |
596 | |
597 | i.setPosition(begin + 29); |
598 | QCOMPARE(i.position(), begin + 29); |
599 | QCOMPARE(i.peekNext(), 0xFFFDu); |
600 | QCOMPARE(i.next(), 0xFFFDu); |
601 | |
602 | QCOMPARE(i.position(), begin + 30); |
603 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('o'))); |
604 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('o'))); |
605 | |
606 | QCOMPARE(i.position(), begin + 31); |
607 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(QLatin1Char('o'))); |
608 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(QLatin1Char('o'))); |
609 | |
610 | QCOMPARE(i.position(), begin + 30); |
611 | QCOMPARE(i.peekPrevious(), 0x10000u); |
612 | QCOMPARE(i.previous(), 0x10000u); |
613 | |
614 | QCOMPARE(i.position(), begin + 28); |
615 | |
616 | i.setPosition(begin + 33); |
617 | QCOMPARE(i.position(), begin + 33); |
618 | QCOMPARE(i.peekNext(), 0xFFFDu); |
619 | QCOMPARE(i.next(), 0xFFFDu); |
620 | |
621 | QCOMPARE(i.position(), begin + 34); |
622 | QCOMPARE(i.peekNext(), QCHAR_UNICODE_VALUE(QLatin1Char('p'))); |
623 | QCOMPARE(i.next(), QCHAR_UNICODE_VALUE(QLatin1Char('p'))); |
624 | |
625 | QCOMPARE(i.position(), begin + 35); |
626 | QCOMPARE(i.peekPrevious(), QCHAR_UNICODE_VALUE(QLatin1Char('p'))); |
627 | QCOMPARE(i.previous(), QCHAR_UNICODE_VALUE(QLatin1Char('p'))); |
628 | |
629 | QCOMPARE(i.position(), begin + 34); |
630 | QCOMPARE(i.peekPrevious(), 0x10000u); |
631 | QCOMPARE(i.previous(), 0x10000u); |
632 | |
633 | QCOMPARE(i.position(), begin + 32); |
634 | |
635 | |
636 | i.setPosition(begin + 16); |
637 | QCOMPARE(i.position(), begin + 16); |
638 | |
639 | i.recedeUnchecked(); |
640 | i.recedeUnchecked(); |
641 | QCOMPARE(i.position(), begin + 12); |
642 | |
643 | i.recedeUnchecked(); |
644 | i.recedeUnchecked(); |
645 | i.recedeUnchecked(); |
646 | i.recedeUnchecked(); |
647 | QCOMPARE(i.position(), begin + 8); |
648 | |
649 | i.recedeUnchecked(); |
650 | i.recedeUnchecked(); |
651 | i.recedeUnchecked(); |
652 | i.recedeUnchecked(); |
653 | i.recedeUnchecked(); |
654 | i.recedeUnchecked(); |
655 | QCOMPARE(i.position(), begin + 2); |
656 | |
657 | #undef QCHAR_UNICODE_VALUE |
658 | } |
659 | |
660 | QTEST_APPLESS_MAIN(tst_QStringIterator) |
661 | |
662 | #include "tst_qstringiterator.moc" |
663 | |