author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <q3cstring.h> |
|
45 |
#include <qregexp.h> |
|
46 |
#include <qtextstream.h> |
|
47 |
||
48 |
||
49 |
//TESTED_CLASS= |
|
50 |
//TESTED_FILES= |
|
51 |
||
52 |
class tst_Q3CString : public QObject |
|
53 |
{ |
|
54 |
Q_OBJECT |
|
55 |
||
56 |
public: |
|
57 |
tst_Q3CString(); |
|
58 |
virtual ~tst_Q3CString(); |
|
59 |
||
60 |
||
61 |
public slots: |
|
62 |
void init(); |
|
63 |
void cleanup(); |
|
64 |
private slots: |
|
65 |
void setExpand(); |
|
66 |
void check_QTextStream(); |
|
67 |
void check_QDataStream(); |
|
68 |
void replace_uint_uint_data(); |
|
69 |
void replace_uint_uint(); |
|
70 |
void replace_string_data(); |
|
71 |
void replace_string(); |
|
72 |
void remove_uint_uint_data(); |
|
73 |
void remove_uint_uint(); |
|
74 |
void prepend(); |
|
75 |
void append(); |
|
76 |
void insert(); |
|
77 |
void simplifyWhiteSpace(); |
|
78 |
void stripWhiteSpace(); |
|
79 |
void lower(); |
|
80 |
void upper(); |
|
81 |
void rightJustify(); |
|
82 |
void leftJustify(); |
|
83 |
void mid(); |
|
84 |
void right(); |
|
85 |
void left(); |
|
86 |
void contains(); |
|
87 |
void findRev(); |
|
88 |
void find(); |
|
89 |
void sprintf(); |
|
90 |
void copy(); |
|
91 |
void fill(); |
|
92 |
void truncate(); |
|
93 |
void constructor(); |
|
94 |
void isEmpty(); |
|
95 |
void isNull(); |
|
96 |
void acc_01(); |
|
97 |
void length_data(); |
|
98 |
void length(); |
|
99 |
||
100 |
// testfunctions? |
|
101 |
void remove_string_data(); |
|
102 |
void remove_regexp_data(); |
|
103 |
}; |
|
104 |
||
105 |
Q_DECLARE_METATYPE(Q3CString) |
|
106 |
||
107 |
tst_Q3CString::tst_Q3CString() |
|
108 |
{ |
|
109 |
} |
|
110 |
||
111 |
tst_Q3CString::~tst_Q3CString() |
|
112 |
{ |
|
113 |
} |
|
114 |
||
115 |
void tst_Q3CString::init() |
|
116 |
{ |
|
117 |
} |
|
118 |
||
119 |
void tst_Q3CString::cleanup() |
|
120 |
{ |
|
121 |
} |
|
122 |
||
123 |
void tst_Q3CString::remove_uint_uint_data() |
|
124 |
{ |
|
125 |
replace_uint_uint_data(); |
|
126 |
} |
|
127 |
||
128 |
void tst_Q3CString::remove_string_data() |
|
129 |
{ |
|
130 |
replace_string_data(); |
|
131 |
} |
|
132 |
||
133 |
void tst_Q3CString::length_data() |
|
134 |
{ |
|
135 |
QTest::addColumn<Q3CString>("s1"); |
|
136 |
QTest::addColumn<int>("res"); |
|
137 |
||
138 |
QTest::newRow( "data0" ) << Q3CString("Test") << 4; |
|
139 |
QTest::newRow( "data1" ) << Q3CString("The quick brown fox jumps over the lazy dog") << 43; |
|
140 |
QTest::newRow( "data2" ) << Q3CString(0) << 0; |
|
141 |
QTest::newRow( "data3" ) << Q3CString("A") << 1; |
|
142 |
QTest::newRow( "data4" ) << Q3CString("AB") << 2; |
|
143 |
QTest::newRow( "data5" ) << Q3CString("AB\n") << 3; |
|
144 |
QTest::newRow( "data6" ) << Q3CString("AB\nC") << 4; |
|
145 |
QTest::newRow( "data7" ) << Q3CString("\n") << 1; |
|
146 |
QTest::newRow( "data8" ) << Q3CString("\nA") << 2; |
|
147 |
QTest::newRow( "data9" ) << Q3CString("\nAB") << 3; |
|
148 |
QTest::newRow( "data10" ) << Q3CString("\nAB\nCDE") << 7; |
|
149 |
QTest::newRow( "data11" ) << Q3CString("shdnftrheid fhgnt gjvnfmd chfugkh bnfhg thgjf vnghturkf chfnguh bjgnfhvygh hnbhgutjfv dhdnjds dcjs d") << 100; |
|
150 |
} |
|
151 |
||
152 |
void tst_Q3CString::replace_uint_uint_data() |
|
153 |
{ |
|
154 |
QTest::addColumn<Q3CString>("string"); |
|
155 |
QTest::addColumn<int>("index"); |
|
156 |
QTest::addColumn<int>("len"); |
|
157 |
QTest::addColumn<Q3CString>("after"); |
|
158 |
QTest::addColumn<Q3CString>("result"); |
|
159 |
||
160 |
QTest::newRow( "rem00" ) << Q3CString("-<>ABCABCABCABC>") << 0 << 3 << Q3CString("") << Q3CString("ABCABCABCABC>"); |
|
161 |
QTest::newRow( "rem01" ) << Q3CString("ABCABCABCABC>") << 1 << 4 <<Q3CString("") <<Q3CString("ACABCABC>"); |
|
162 |
QTest::newRow( "rem02" ) << Q3CString("ACABCABC>") << 999 << 4 << Q3CString("") << Q3CString("ACABCABC>"); |
|
163 |
QTest::newRow( "rem03" ) << Q3CString("ACABCABC>") << 9 << 4 << Q3CString("") << Q3CString("ACABCABC>"); |
|
164 |
QTest::newRow( "rem04" ) << Q3CString("ACABCABC>") << 8 << 4 << Q3CString("") << Q3CString("ACABCABC"); |
|
165 |
QTest::newRow( "rem05" ) << Q3CString("ACABCABC") << 7 << 1 << Q3CString("") << Q3CString("ACABCAB"); |
|
166 |
QTest::newRow( "rem06" ) << Q3CString("ACABCAB") << 4 << 0 << Q3CString("") << Q3CString("ACABCAB"); |
|
167 |
||
168 |
QTest::newRow( "rep00" ) << Q3CString("ACABCAB") << 4 << 0 << Q3CString("X") << Q3CString("ACABXCAB"); |
|
169 |
QTest::newRow( "rep01" ) << Q3CString("ACABXCAB") << 4 << 1 << Q3CString("Y") << Q3CString("ACABYCAB"); |
|
170 |
QTest::newRow( "rep02" ) << Q3CString("ACABYCAB") << 4 << 1 << Q3CString("") << Q3CString("ACABCAB"); |
|
171 |
QTest::newRow( "rep03" ) << Q3CString("ACABCAB") << 0 << 9999 << Q3CString("XX") << Q3CString("XX"); |
|
172 |
QTest::newRow( "rep04" ) << Q3CString("XX") << 0 << 9999 << Q3CString("") << Q3CString(""); |
|
173 |
} |
|
174 |
||
175 |
void tst_Q3CString::replace_string_data() |
|
176 |
{ |
|
177 |
QTest::addColumn<Q3CString>("string"); |
|
178 |
QTest::addColumn<Q3CString>("before"); |
|
179 |
QTest::addColumn<Q3CString>("after"); |
|
180 |
QTest::addColumn<Q3CString>("result"); |
|
181 |
||
182 |
QTest::newRow( "rem00" ) << Q3CString("") << Q3CString("") << Q3CString("") << Q3CString(""); |
|
183 |
QTest::newRow( "rem01" ) << Q3CString("A") << Q3CString("") << Q3CString("") << Q3CString("A"); |
|
184 |
QTest::newRow( "rem02" ) << Q3CString("A") << Q3CString("A") << Q3CString("") << Q3CString(""); |
|
185 |
QTest::newRow( "rem03" ) << Q3CString("A") << Q3CString("B") << Q3CString("") << Q3CString("A"); |
|
186 |
QTest::newRow( "rem04" ) << Q3CString("AA") << Q3CString("A") << Q3CString("") << Q3CString(""); |
|
187 |
QTest::newRow( "rem05" ) << Q3CString("AB") << Q3CString("A") << Q3CString("") << Q3CString("B"); |
|
188 |
QTest::newRow( "rem06" ) << Q3CString("AB") << Q3CString("B") << Q3CString("") << Q3CString("A"); |
|
189 |
QTest::newRow( "rem07" ) << Q3CString("AB") << Q3CString("C") << Q3CString("") << Q3CString("AB"); |
|
190 |
QTest::newRow( "rem08" ) << Q3CString("ABA") << Q3CString("A") << Q3CString("") << Q3CString("B"); |
|
191 |
QTest::newRow( "rem09" ) << Q3CString("ABA") << Q3CString("B") << Q3CString("") << Q3CString("AA"); |
|
192 |
QTest::newRow( "rem10" ) << Q3CString("ABA") << Q3CString("C") << Q3CString("") << Q3CString("ABA"); |
|
193 |
QTest::newRow( "rem11" ) << Q3CString("banana") << Q3CString("an") << Q3CString("") << Q3CString("ba"); |
|
194 |
QTest::newRow( "rem12" ) << Q3CString("") << Q3CString("A") << Q3CString("") << Q3CString(""); |
|
195 |
QTest::newRow( "rem13" ) << Q3CString("") << Q3CString("A") << Q3CString(0) << Q3CString(""); |
|
196 |
QTest::newRow( "rem14" ) << Q3CString(0) << Q3CString("A") << Q3CString("") << Q3CString(0); |
|
197 |
QTest::newRow( "rem15" ) << Q3CString(0) << Q3CString("A") << Q3CString(0) << Q3CString(0); |
|
198 |
QTest::newRow( "rem17" ) << Q3CString(0) << Q3CString("") << Q3CString("") << Q3CString(0); |
|
199 |
// ### how should the one below behave in Q3CString???? |
|
200 |
// QTest::newRow( "rem18" ) << Q3CString("") << Q3CString(0) << Q3CString("A") << Q3CString("A"); |
|
201 |
QTest::newRow( "rem19" ) << Q3CString("") << Q3CString(0) << Q3CString("") << Q3CString(""); |
|
202 |
||
203 |
QTest::newRow( "rep00" ) << Q3CString("ABC") << Q3CString("B") << Q3CString("-") << Q3CString("A-C"); |
|
204 |
QTest::newRow( "rep01" ) << Q3CString("$()*+.?[\\]^{|}") << Q3CString("$()*+.?[\\]^{|}") << Q3CString("X") << Q3CString("X"); |
|
205 |
QTest::newRow( "rep02" ) << Q3CString("ABCDEF") << Q3CString("") << Q3CString("X") << Q3CString("XAXBXCXDXEXFX"); |
|
206 |
QTest::newRow( "rep03" ) << Q3CString("") << Q3CString("") << Q3CString("X") << Q3CString("X"); |
|
207 |
} |
|
208 |
||
209 |
void tst_Q3CString::remove_regexp_data() |
|
210 |
{ |
|
211 |
QTest::addColumn<Q3CString>("string"); |
|
212 |
QTest::addColumn<Q3CString>("regexp"); |
|
213 |
QTest::addColumn<Q3CString>("after"); |
|
214 |
QTest::addColumn<Q3CString>("result"); |
|
215 |
||
216 |
QTest::newRow( "rem00" ) << Q3CString("alpha") << Q3CString("a+") << Q3CString("") << Q3CString("lph"); |
|
217 |
QTest::newRow( "rem01" ) << Q3CString("banana") << Q3CString("^.a") << Q3CString("") << Q3CString("nana"); |
|
218 |
QTest::newRow( "rem02" ) << Q3CString("") << Q3CString("^.a") << Q3CString("") << Q3CString(""); |
|
219 |
QTest::newRow( "rem03" ) << Q3CString("") << Q3CString("^.a") << Q3CString(0) << Q3CString(""); |
|
220 |
QTest::newRow( "rem04" ) << Q3CString(0) << Q3CString("^.a") << Q3CString("") << Q3CString(0); |
|
221 |
QTest::newRow( "rem05" ) << Q3CString(0) << Q3CString("^.a") << Q3CString(0) << Q3CString(0); |
|
222 |
||
223 |
QTest::newRow( "rep00" ) << Q3CString("A <i>bon mot</i>.") << Q3CString("<i>([^<]*)</i>") << Q3CString("\\emph{\\1}") << Q3CString("A \\emph{bon mot}."); |
|
224 |
QTest::newRow( "rep01" ) << Q3CString("banana") << Q3CString("^.a()") << Q3CString("\\1") << Q3CString("nana"); |
|
225 |
QTest::newRow( "rep02" ) << Q3CString("banana") << Q3CString("(ba)") << Q3CString("\\1X\\1") << Q3CString("baXbanana"); |
|
226 |
QTest::newRow( "rep03" ) << Q3CString("banana") << Q3CString("(ba)(na)na") << Q3CString("\\2X\\1") << Q3CString("naXba"); |
|
227 |
} |
|
228 |
||
229 |
void tst_Q3CString::length() |
|
230 |
{ |
|
231 |
QFETCH( Q3CString, s1 ); |
|
232 |
QTEST( (int)s1.length(), "res" ); |
|
233 |
} |
|
234 |
||
235 |
#include <qfile.h> |
|
236 |
||
237 |
void tst_Q3CString::acc_01() |
|
238 |
{ |
|
239 |
Q3CString a; |
|
240 |
Q3CString b; //b(10); |
|
241 |
Q3CString bb; //bb((int)0); |
|
242 |
Q3CString c("String C"); |
|
243 |
char tmp[10]; |
|
244 |
tmp[0] = 'S'; |
|
245 |
tmp[1] = 't'; |
|
246 |
tmp[2] = 'r'; |
|
247 |
tmp[3] = 'i'; |
|
248 |
tmp[4] = 'n'; |
|
249 |
tmp[5] = 'g'; |
|
250 |
tmp[6] = ' '; |
|
251 |
tmp[7] = 'D'; |
|
252 |
tmp[8] = 'X'; |
|
253 |
tmp[9] = '\0'; |
|
254 |
Q3CString d(tmp,8); |
|
255 |
Q3CString ca(a); |
|
256 |
Q3CString cb(b); |
|
257 |
Q3CString cc(c); |
|
258 |
Q3CString n; |
|
259 |
Q3CString e("String E"); |
|
260 |
Q3CString f; |
|
261 |
f = e; |
|
262 |
f.detach(); |
|
263 |
f[7]='F'; |
|
264 |
QCOMPARE(e,(Q3CString)"String E"); |
|
265 |
char text[]="String f"; |
|
266 |
f = text; |
|
267 |
text[7]='!'; |
|
268 |
QCOMPARE(f,(Q3CString)"String f"); |
|
269 |
f[7]='F'; |
|
270 |
QCOMPARE(text[7],'!'); |
|
271 |
||
272 |
#if 0 |
|
273 |
a=""; |
|
274 |
a[0]='A'; |
|
275 |
Q3CString res = "A"; |
|
276 |
QCOMPARE(a,res); |
|
277 |
QCOMPARE(a.length(),(uint)1); |
|
278 |
compare(a.length(),(uint)1); |
|
279 |
a[1]='B'; |
|
280 |
QCOMPARE(a,(Q3CString)"AB"); |
|
281 |
QCOMPARE(a.length(),(uint)2); |
|
282 |
a[2]='C'; |
|
283 |
QCOMPARE(a,(Q3CString)"ABC"); |
|
284 |
QCOMPARE(a.length(),(uint)3); |
|
285 |
a = Q3CString(); |
|
286 |
QVERIFY(a.isNull()); |
|
287 |
a[0]='A'; |
|
288 |
QCOMPARE(a,(Q3CString)"A"); |
|
289 |
QCOMPARE(a.length(),(uint)1); |
|
290 |
a[1]='B'; |
|
291 |
QCOMPARE(a,(Q3CString)"AB"); |
|
292 |
QCOMPARE(a.length(),(uint)2); |
|
293 |
a[2]='C'; |
|
294 |
QCOMPARE(a,(Q3CString)"ABC"); |
|
295 |
QCOMPARE(a.length(),(uint)3); |
|
296 |
#endif |
|
297 |
a="123"; |
|
298 |
b="456"; |
|
299 |
a[0]=a[1]; |
|
300 |
QCOMPARE(a,(Q3CString)"223"); |
|
301 |
a[1]=b[1]; |
|
302 |
QCOMPARE(b,(Q3CString)"456"); |
|
303 |
QCOMPARE(a,(Q3CString)"253"); |
|
304 |
||
305 |
char t[]="TEXT"; |
|
306 |
a="A"; |
|
307 |
a=t; |
|
308 |
QCOMPARE(a,(Q3CString)"TEXT"); |
|
309 |
QCOMPARE(a,(Q3CString)t); |
|
310 |
a[0]='X'; |
|
311 |
QCOMPARE(a,(Q3CString)"XEXT"); |
|
312 |
QCOMPARE(t[0],'T'); |
|
313 |
t[0]='Z'; |
|
314 |
QCOMPARE(a,(Q3CString)"XEXT"); |
|
315 |
||
316 |
a="ABC"; |
|
317 |
QCOMPARE(((const char*)a)[1],'B'); |
|
318 |
QCOMPARE(strcmp(a,(Q3CString)"ABC"),0); |
|
319 |
a += "DEF"; |
|
320 |
QCOMPARE(a, (Q3CString)"ABCDEF"); |
|
321 |
a += 'G'; |
|
322 |
QCOMPARE(a, (Q3CString)"ABCDEFG"); |
|
323 |
a += ((const char*)(0)); |
|
324 |
QCOMPARE(a, (Q3CString)"ABCDEFG"); |
|
325 |
||
326 |
// non-member operators |
|
327 |
||
328 |
a="ABC"; |
|
329 |
b="ABC"; |
|
330 |
c="ACB"; |
|
331 |
d="ABCD"; |
|
332 |
QVERIFY(a==b); |
|
333 |
QVERIFY(!(a==d)); |
|
334 |
QVERIFY(!(a!=b)); |
|
335 |
QVERIFY(a!=d); |
|
336 |
QVERIFY(!(a<b)); |
|
337 |
QVERIFY(a<c); |
|
338 |
QVERIFY(a<d); |
|
339 |
QVERIFY(!(d<a)); |
|
340 |
QVERIFY(!(c<a)); |
|
341 |
QVERIFY(a<=b); |
|
342 |
QVERIFY(a<=d); |
|
343 |
QVERIFY(a<=c); |
|
344 |
QVERIFY(!(c<=a)); |
|
345 |
QVERIFY(!(d<=a)); |
|
346 |
QCOMPARE(a+b,(Q3CString)"ABCABC"); |
|
347 |
QCOMPARE(a +"XXXX",(Q3CString)"ABCXXXX"); |
|
348 |
QCOMPARE(a+'X',(Q3CString)"ABCX"); |
|
349 |
QCOMPARE("XXXX"+a,(Q3CString)"XXXXABC"); |
|
350 |
QCOMPARE('X'+a,(Q3CString)"XABC"); |
|
351 |
a = (const char*)0; |
|
352 |
QVERIFY(a.isNull()); |
|
353 |
QVERIFY(*((const char *)a) == 0); |
|
354 |
||
355 |
{ |
|
356 |
QFile f("COMPARE.txt"); |
|
357 |
f.open( QIODevice::WriteOnly ); |
|
358 |
QTextStream ts( &f ); |
|
359 |
ts.setEncoding(QTextStream::Unicode); |
|
360 |
ts << "Abc"; |
|
361 |
} |
|
362 |
} |
|
363 |
||
364 |
void tst_Q3CString::isNull() |
|
365 |
{ |
|
366 |
Q3CString a; |
|
367 |
QVERIFY( a.isNull() ); |
|
368 |
||
369 |
const char *str = "foo"; |
|
370 |
a.sprintf( str ); |
|
371 |
QVERIFY( !a.isNull() ); |
|
372 |
} |
|
373 |
||
374 |
void tst_Q3CString::isEmpty() |
|
375 |
{ |
|
376 |
Q3CString a; |
|
377 |
QVERIFY(a.isEmpty()); |
|
378 |
Q3CString c("Not empty"); |
|
379 |
QVERIFY(!c.isEmpty()); |
|
380 |
} |
|
381 |
||
382 |
void tst_Q3CString::constructor() |
|
383 |
{ |
|
384 |
Q3CString a; |
|
385 |
Q3CString b; //b(10); |
|
386 |
Q3CString c("String C"); |
|
387 |
char tmp[10]; |
|
388 |
tmp[0] = 'S'; |
|
389 |
tmp[1] = 't'; |
|
390 |
tmp[2] = 'r'; |
|
391 |
tmp[3] = 'i'; |
|
392 |
tmp[4] = 'n'; |
|
393 |
tmp[5] = 'g'; |
|
394 |
tmp[6] = ' '; |
|
395 |
tmp[7] = 'D'; |
|
396 |
tmp[8] = 'X'; |
|
397 |
tmp[9] = '\0'; |
|
398 |
Q3CString d(tmp,9); |
|
399 |
Q3CString ca(a); |
|
400 |
Q3CString cb(b); |
|
401 |
Q3CString cc(c); |
|
402 |
||
403 |
QCOMPARE(a,ca); |
|
404 |
QVERIFY(a.isNull()); |
|
405 |
QVERIFY(a == Q3CString("")); |
|
406 |
QCOMPARE(b,cb); |
|
407 |
QCOMPARE(c,cc); |
|
408 |
QCOMPARE(d,(Q3CString)"String D"); |
|
409 |
||
410 |
Q3CString null(0); |
|
411 |
QVERIFY( null.isNull() ); |
|
412 |
QVERIFY( null.isEmpty() ); |
|
413 |
Q3CString empty(""); |
|
414 |
QVERIFY( !empty.isNull() ); |
|
415 |
QVERIFY( empty.isEmpty() ); |
|
416 |
} |
|
417 |
||
418 |
void tst_Q3CString::truncate() |
|
419 |
{ |
|
420 |
Q3CString e("String E"); |
|
421 |
e.truncate(4); |
|
422 |
QCOMPARE(e,(Q3CString)"Stri"); |
|
423 |
||
424 |
e = "String E"; |
|
425 |
e.truncate(0); |
|
426 |
QCOMPARE(e,(Q3CString)""); |
|
427 |
QVERIFY(e.isEmpty()); |
|
428 |
QVERIFY(!e.isNull()); |
|
429 |
||
430 |
} |
|
431 |
||
432 |
void tst_Q3CString::fill() |
|
433 |
{ |
|
434 |
Q3CString e; |
|
435 |
e.fill('e',1); |
|
436 |
QCOMPARE(e,(Q3CString)"e"); |
|
437 |
Q3CString f; |
|
438 |
f.fill('f',3); |
|
439 |
QCOMPARE(f,(Q3CString)"fff"); |
|
440 |
f.fill('F'); |
|
441 |
QCOMPARE(f,(Q3CString)"FFF"); |
|
442 |
} |
|
443 |
||
444 |
void tst_Q3CString::copy() |
|
445 |
{ |
|
446 |
Q3CString e; |
|
447 |
e = "String E"; |
|
448 |
Q3CString ce = e.copy(); |
|
449 |
QCOMPARE(ce,(Q3CString)"String E"); |
|
450 |
e = "XXX"; |
|
451 |
QCOMPARE(ce,(Q3CString)"String E"); |
|
452 |
QCOMPARE(e,(Q3CString)"XXX"); |
|
453 |
} |
|
454 |
||
455 |
void tst_Q3CString::sprintf() |
|
456 |
{ |
|
457 |
Q3CString a; |
|
458 |
a.sprintf("COMPARE"); |
|
459 |
QCOMPARE(a,(Q3CString)"COMPARE"); |
|
460 |
a.sprintf("%%%d",1); |
|
461 |
QCOMPARE(a,(Q3CString)"%1"); |
|
462 |
QCOMPARE(a.sprintf("X%dY",2),(Q3CString)"X2Y"); |
|
463 |
//QCOMPARE(a.sprintf("X%sY",(Q3CString)"hello"),"XhelloY"); |
|
464 |
// QCOMPARE(a.sprintf("X%9sY","hello"),(Q3CString)"X helloY"); |
|
465 |
QCOMPARE(a.sprintf("X%9iY", 50000 ),(Q3CString)"X 50000Y"); |
|
466 |
QCOMPARE(a.sprintf("X%-9sY","hello"),(Q3CString)"Xhello Y"); |
|
467 |
QCOMPARE(a.sprintf("X%-9iY", 50000 ),(Q3CString)"X50000 Y"); |
|
468 |
//Q3CString fmt("X%-10SY"); |
|
469 |
//Q3CString txt("hello"); |
|
470 |
//QCOMPARE(a.sprintf(fmt,(Q3CString)&txt),"X helloY"); |
|
471 |
} |
|
472 |
||
473 |
void tst_Q3CString::find() |
|
474 |
{ |
|
475 |
Q3CString a; |
|
476 |
a=""; |
|
477 |
QCOMPARE(a.find('A'),-1); |
|
478 |
a=Q3CString(); |
|
479 |
QCOMPARE(a.find('A'),-1); |
|
480 |
a="ABCDEFGHIEfGEFG"; // 15 chars |
|
481 |
QCOMPARE(a.find('A'),0); |
|
482 |
QCOMPARE(a.find('C'),2); |
|
483 |
QCOMPARE(a.find('Z'),-1); |
|
484 |
QCOMPARE(a.find('E'),4); |
|
485 |
QCOMPARE(a.find('E',4),4); |
|
486 |
QCOMPARE(a.find('E',5),9); |
|
487 |
//QCOMPARE(a.find('G',-1),14); // -ve does what? Parameter should be uint? |
|
488 |
//QCOMPARE(a.find('G',-2),11); // -ve does what? Parameter should be uint? |
|
489 |
QCOMPARE(a.find('f'),10); |
|
490 |
// QCOMPARE(a.find("efg",-1,FALSE),12); // -ve does what? Parameter should be uint? |
|
491 |
// QCOMPARE(a.find("efg",-2,FALSE),12); // -ve does what? Parameter should be uint? |
|
492 |
// QCOMPARE(a.find("efg",-3,FALSE),12); // -ve does what? Parameter should be uint? |
|
493 |
// QCOMPARE(a.find("efg",-4,FALSE),9); // -ve does what? Parameter should be uint? |
|
494 |
// QCOMPARE(a.find(QRegExp("[EFG][EFG]"),0),4); |
|
495 |
// QCOMPARE(a.find(QRegExp("[EFG][EFG]"),4),4); |
|
496 |
// QCOMPARE(a.find(QRegExp("[EFG][EFG]"),5),5); |
|
497 |
// QCOMPARE(a.find(QRegExp("[EFG][EFG]"),6),11); |
|
498 |
// QCOMPARE(a.find(QRegExp("G"),14),14); |
|
499 |
} |
|
500 |
||
501 |
void tst_Q3CString::findRev() |
|
502 |
{ |
|
503 |
Q3CString a; |
|
504 |
a="ABCDEFGHIEfGEFG"; // 15 chars |
|
505 |
QCOMPARE(a.findRev('G'),14); |
|
506 |
// QCOMPARE(a.findRev('G',-3),11); |
|
507 |
// QCOMPARE(a.findRev('G',-5),6); |
|
508 |
QCOMPARE(a.findRev('G',14),14); |
|
509 |
QCOMPARE(a.findRev('G',13),11); |
|
510 |
QCOMPARE(a.findRev('B'),1); |
|
511 |
QCOMPARE(a.findRev('B',1),1); |
|
512 |
QCOMPARE(a.findRev('B',0),-1); |
|
513 |
// QCOMPARE(a.findRev(QRegExp("[EFG][EFG]"),14),13); |
|
514 |
// QCOMPARE(a.findRev(QRegExp("[EFG][EFG]"),11),11); |
|
515 |
} |
|
516 |
||
517 |
void tst_Q3CString::contains() |
|
518 |
{ |
|
519 |
Q3CString a; |
|
520 |
a="ABCDEFGHIEfGEFG"; // 15 chars |
|
521 |
QVERIFY(a.contains('A')); |
|
522 |
QVERIFY(!a.contains('Z')); |
|
523 |
QVERIFY(a.contains('E')); |
|
524 |
QVERIFY(a.contains('F')); |
|
525 |
QVERIFY(a.contains("FG")); |
|
526 |
QCOMPARE(a.count('A'),1); |
|
527 |
QCOMPARE(a.count('Z'),0); |
|
528 |
QCOMPARE(a.count('E'),3); |
|
529 |
QCOMPARE(a.count('F'),2); |
|
530 |
QCOMPARE(a.count("FG"),2); |
|
531 |
// QCOMPARE(a.contains(QRegExp("[FG][HI]")),1); |
|
532 |
// QCOMPARE(a.contains(QRegExp("[G][HE]")),2); |
|
533 |
} |
|
534 |
||
535 |
void tst_Q3CString::left() |
|
536 |
{ |
|
537 |
Q3CString a; |
|
538 |
a="ABCDEFGHIEfGEFG"; // 15 chars |
|
539 |
QCOMPARE(a.left(3),(Q3CString)"ABC"); |
|
540 |
QVERIFY(!a.left(0).isNull()); |
|
541 |
QCOMPARE(a.left(0),(Q3CString)""); |
|
542 |
||
543 |
Q3CString n; |
|
544 |
QVERIFY(n.left(3).isNull()); |
|
545 |
QVERIFY(n.left(0).isNull()); |
|
546 |
QVERIFY(n.left(0).isNull()); |
|
547 |
} |
|
548 |
||
549 |
void tst_Q3CString::right() |
|
550 |
{ |
|
551 |
Q3CString a; |
|
552 |
a="ABCDEFGHIEfGEFG"; // 15 chars |
|
553 |
QCOMPARE(a.right(3),(Q3CString)"EFG"); |
|
554 |
QCOMPARE(a.right(0),(Q3CString)""); |
|
555 |
||
556 |
Q3CString n; |
|
557 |
QVERIFY(n.right(3).isNull()); |
|
558 |
QVERIFY(n.right(0).isNull()); |
|
559 |
} |
|
560 |
||
561 |
void tst_Q3CString::mid() |
|
562 |
{ |
|
563 |
Q3CString a; |
|
564 |
a="ABCDEFGHIEfGEFG"; // 15 chars |
|
565 |
||
566 |
QCOMPARE(a.mid(3,3),(Q3CString)"DEF"); |
|
567 |
QCOMPARE(a.mid(0,0),(Q3CString)""); |
|
568 |
QVERIFY(a.mid(9999).isNull()); |
|
569 |
QVERIFY(a.mid(9999,1).isNull()); |
|
570 |
||
571 |
Q3CString n; |
|
572 |
QVERIFY(n.mid(3,3).isNull()); |
|
573 |
QVERIFY(n.mid(0,0).isNull()); |
|
574 |
QVERIFY(n.mid(9999,0).isNull()); |
|
575 |
QVERIFY(n.mid(9999,1).isNull()); |
|
576 |
} |
|
577 |
||
578 |
void tst_Q3CString::leftJustify() |
|
579 |
{ |
|
580 |
Q3CString a; |
|
581 |
a="ABC"; |
|
582 |
QCOMPARE(a.leftJustify(5,'-'),(Q3CString)"ABC--"); |
|
583 |
QCOMPARE(a.leftJustify(4,'-'),(Q3CString)"ABC-"); |
|
584 |
QCOMPARE(a.leftJustify(4),(Q3CString)"ABC "); |
|
585 |
QCOMPARE(a.leftJustify(3),(Q3CString)"ABC"); |
|
586 |
QCOMPARE(a.leftJustify(2),(Q3CString)"ABC"); |
|
587 |
QCOMPARE(a.leftJustify(1),(Q3CString)"ABC"); |
|
588 |
QCOMPARE(a.leftJustify(0),(Q3CString)"ABC"); |
|
589 |
||
590 |
Q3CString n; |
|
591 |
QVERIFY(!n.leftJustify(3).isNull()); // I expected TRUE |
|
592 |
QCOMPARE(a.leftJustify(4,' ',TRUE),(Q3CString)"ABC "); |
|
593 |
QCOMPARE(a.leftJustify(3,' ',TRUE),(Q3CString)"ABC"); |
|
594 |
QCOMPARE(a.leftJustify(2,' ',TRUE),(Q3CString)"AB"); |
|
595 |
QCOMPARE(a.leftJustify(1,' ',TRUE),(Q3CString)"A"); |
|
596 |
QCOMPARE(a.leftJustify(0,' ',TRUE),(Q3CString)""); |
|
597 |
} |
|
598 |
||
599 |
void tst_Q3CString::rightJustify() |
|
600 |
{ |
|
601 |
Q3CString a; |
|
602 |
a="ABC"; |
|
603 |
QCOMPARE(a.rightJustify(5,'-'),(Q3CString)"--ABC"); |
|
604 |
QCOMPARE(a.rightJustify(4,'-'),(Q3CString)"-ABC"); |
|
605 |
QCOMPARE(a.rightJustify(4),(Q3CString)" ABC"); |
|
606 |
QCOMPARE(a.rightJustify(3),(Q3CString)"ABC"); |
|
607 |
QCOMPARE(a.rightJustify(2),(Q3CString)"ABC"); |
|
608 |
QCOMPARE(a.rightJustify(1),(Q3CString)"ABC"); |
|
609 |
QCOMPARE(a.rightJustify(0),(Q3CString)"ABC"); |
|
610 |
||
611 |
Q3CString n; |
|
612 |
QVERIFY(!n.rightJustify(3).isNull()); // I expected TRUE |
|
613 |
QCOMPARE(a.rightJustify(4,'-',TRUE),(Q3CString)"-ABC"); |
|
614 |
QCOMPARE(a.rightJustify(4,' ',TRUE),(Q3CString)" ABC"); |
|
615 |
QCOMPARE(a.rightJustify(3,' ',TRUE),(Q3CString)"ABC"); |
|
616 |
QCOMPARE(a.rightJustify(2,' ',TRUE),(Q3CString)"AB"); |
|
617 |
QCOMPARE(a.rightJustify(1,' ',TRUE),(Q3CString)"A"); |
|
618 |
QCOMPARE(a.rightJustify(0,' ',TRUE),(Q3CString)""); |
|
619 |
QCOMPARE(a,(Q3CString)"ABC"); |
|
620 |
} |
|
621 |
||
622 |
void tst_Q3CString::upper() |
|
623 |
{ |
|
624 |
Q3CString a; |
|
625 |
a="Text"; |
|
626 |
QCOMPARE(a.upper(),(Q3CString)"TEXT"); |
|
627 |
} |
|
628 |
||
629 |
void tst_Q3CString::lower() |
|
630 |
{ |
|
631 |
Q3CString a; |
|
632 |
a="Text"; |
|
633 |
QCOMPARE(a.lower(),(Q3CString)"text"); |
|
634 |
} |
|
635 |
||
636 |
void tst_Q3CString::stripWhiteSpace() |
|
637 |
{ |
|
638 |
Q3CString a; |
|
639 |
a="Text"; |
|
640 |
QCOMPARE(a,(Q3CString)"Text"); |
|
641 |
QCOMPARE(a.stripWhiteSpace(),(Q3CString)"Text"); |
|
642 |
QCOMPARE(a,(Q3CString)"Text"); |
|
643 |
a=" "; |
|
644 |
QCOMPARE(a.stripWhiteSpace(),(Q3CString)""); |
|
645 |
QCOMPARE(a,(Q3CString)" "); |
|
646 |
a=" a "; |
|
647 |
QCOMPARE(a.stripWhiteSpace(),(Q3CString)"a"); |
|
648 |
} |
|
649 |
||
650 |
void tst_Q3CString::simplifyWhiteSpace() |
|
651 |
{ |
|
652 |
Q3CString j; |
|
653 |
j.simplifyWhiteSpace(); |
|
654 |
||
655 |
Q3CString a; |
|
656 |
a = "a "; |
|
657 |
QCOMPARE(a.simplifyWhiteSpace(),(Q3CString)"a"); |
|
658 |
a=" a b "; |
|
659 |
QCOMPARE(a.simplifyWhiteSpace(),(Q3CString)"a b"); |
|
660 |
} |
|
661 |
||
662 |
void tst_Q3CString::insert() |
|
663 |
{ |
|
664 |
Q3CString a; |
|
665 |
a = "Ys"; |
|
666 |
QCOMPARE(a.insert(1,'e'),(Q3CString)"Yes"); |
|
667 |
QCOMPARE(a.insert(3,'!'),(Q3CString)"Yes!"); |
|
668 |
QCOMPARE(a.insert(5,'?'),(Q3CString)"Yes! ?"); |
|
669 |
||
670 |
a="ABC"; |
|
671 |
QCOMPARE(a.insert(5,"DEF"),(Q3CString)"ABC DEF"); |
|
672 |
a="ABC"; |
|
673 |
QCOMPARE(a.insert(0,"ABC"),(Q3CString)"ABCABC"); |
|
674 |
QCOMPARE(a,(Q3CString)"ABCABC"); |
|
675 |
||
676 |
// ######### Q3CString::insert is not safe against self insertion... |
|
677 |
// Q3CString res = "ABCABCABCABC"; |
|
678 |
// QCOMPARE(a.insert(0,a),res); |
|
679 |
a += "ABCABC"; |
|
680 |
Q3CString res = "ABCABCABCABC"; |
|
681 |
QCOMPARE(a, res); |
|
682 |
res = "<ABCABCABCABC"; |
|
683 |
QCOMPARE(a.insert(0,'<'),res ); |
|
684 |
res = "<>ABCABCABCABC"; |
|
685 |
QCOMPARE(a.insert(1,'>'),res ); |
|
686 |
} |
|
687 |
||
688 |
void tst_Q3CString::append() |
|
689 |
{ |
|
690 |
Q3CString a; |
|
691 |
a = "<>ABCABCABCABC"; |
|
692 |
QCOMPARE(a.append(">"),(Q3CString)"<>ABCABCABCABC>"); |
|
693 |
} |
|
694 |
||
695 |
void tst_Q3CString::prepend() |
|
696 |
{ |
|
697 |
Q3CString a; |
|
698 |
a = "<>ABCABCABCABC>"; |
|
699 |
QCOMPARE(a.prepend("-"),(Q3CString)"-<>ABCABCABCABC>"); |
|
700 |
} |
|
701 |
||
702 |
void tst_Q3CString::replace_uint_uint() |
|
703 |
{ |
|
704 |
QFETCH( Q3CString, string ); |
|
705 |
QFETCH( int, index ); |
|
706 |
QFETCH( int, len ); |
|
707 |
QFETCH( Q3CString, after ); |
|
708 |
||
709 |
Q3CString s1 = string; |
|
710 |
s1.replace( (uint) index, (int) len, after ); |
|
711 |
QFETCH( Q3CString, result ); |
|
712 |
QVERIFY( s1 == result ); |
|
713 |
||
714 |
Q3CString s2 = string; |
|
715 |
s2.replace( (uint) index, (uint) len, after ); |
|
716 |
QVERIFY( s2 == result ); |
|
717 |
||
718 |
} |
|
719 |
||
720 |
void tst_Q3CString::replace_string() |
|
721 |
{ |
|
722 |
QFETCH( Q3CString, string ); |
|
723 |
QFETCH( Q3CString, before ); |
|
724 |
QFETCH( Q3CString, after ); |
|
725 |
QFETCH( Q3CString, result ); |
|
726 |
||
727 |
if ( before.length() == 1 ) { |
|
728 |
char ch = before[0]; |
|
729 |
||
730 |
Q3CString s1 = string; |
|
731 |
s1.replace( ch, after ); |
|
732 |
QCOMPARE( s1, result ); |
|
733 |
} |
|
734 |
||
735 |
Q3CString s3 = string; |
|
736 |
s3.replace( before, after ); |
|
737 |
QCOMPARE( s3, result ); |
|
738 |
} |
|
739 |
||
740 |
void tst_Q3CString::remove_uint_uint() |
|
741 |
{ |
|
742 |
QFETCH( Q3CString, string ); |
|
743 |
QFETCH( int, index ); |
|
744 |
QFETCH( int, len ); |
|
745 |
QFETCH( Q3CString, after ); |
|
746 |
QFETCH( Q3CString, result ); |
|
747 |
||
748 |
if ( after.length() == 0 ) { |
|
749 |
Q3CString s1 = string; |
|
750 |
s1.remove( (uint) index, (uint) len ); |
|
751 |
QVERIFY( s1 == result ); |
|
752 |
} else { |
|
753 |
QSKIP("Test data applies only to replace_uint_uint(), not remove_uint_uint()", SkipSingle); |
|
754 |
} |
|
755 |
} |
|
756 |
||
757 |
void tst_Q3CString::check_QDataStream() |
|
758 |
{ |
|
759 |
Q3CString a; |
|
760 |
QByteArray ar; |
|
761 |
{ |
|
762 |
QDataStream out(&ar,QIODevice::WriteOnly); |
|
763 |
out << Q3CString("COMPARE Text"); |
|
764 |
} |
|
765 |
{ |
|
766 |
QDataStream in(&ar,QIODevice::ReadOnly); |
|
767 |
in >> a; |
|
768 |
QCOMPARE(a,(Q3CString)"COMPARE Text"); |
|
769 |
} |
|
770 |
} |
|
771 |
||
772 |
void tst_Q3CString::check_QTextStream() |
|
773 |
{ |
|
774 |
Q3CString a; |
|
775 |
QByteArray ar; |
|
776 |
{ |
|
777 |
QTextStream out(&ar,QIODevice::WriteOnly); |
|
778 |
out << Q3CString("This is COMPARE Text"); |
|
779 |
} |
|
780 |
{ |
|
781 |
QTextStream in(&ar,QIODevice::ReadOnly); |
|
782 |
in >> a; |
|
783 |
QCOMPARE(a,(Q3CString)"This"); |
|
784 |
} |
|
785 |
} |
|
786 |
||
787 |
void tst_Q3CString::setExpand() |
|
788 |
{ |
|
789 |
Q3CString a; |
|
790 |
a="ABC"; |
|
791 |
a.setExpand(0,'X'); |
|
792 |
QCOMPARE(a,(Q3CString)"XBC"); |
|
793 |
a.setExpand(4,'Z'); |
|
794 |
QCOMPARE(a,(Q3CString)"XBC Z"); |
|
795 |
a.setExpand(3,'Y'); |
|
796 |
QCOMPARE(a,(Q3CString)"XBCYZ"); |
|
797 |
} |
|
798 |
||
799 |
||
800 |
QTEST_APPLESS_MAIN(tst_Q3CString) |
|
801 |
#include "tst_q3cstring.moc" |