]> git.saurik.com Git - wxWidgets.git/blame - tests/strings/strings.cpp
OS/2 PM does not yet support toggle button.
[wxWidgets.git] / tests / strings / strings.cpp
CommitLineData
1cd53e88
VS
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/strings/strings.cpp
3// Purpose: wxString unit test
4// Author: Vadim Zeitlin, Wlodzimierz ABX Skiba
5// Created: 2004-04-19
6// RCS-ID: $Id$
7// Copyright: (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba
8///////////////////////////////////////////////////////////////////////////////
9
10// ----------------------------------------------------------------------------
11// headers
12// ----------------------------------------------------------------------------
13
14#include "wx/wxprec.h"
15
16#ifdef __BORLANDC__
17 #pragma hdrstop
18#endif
19
20#ifndef WX_PRECOMP
21 #include "wx/wx.h"
22#endif // WX_PRECOMP
23
24#include "wx/tokenzr.h"
25
26#include "wx/cppunit.h"
27
28// ----------------------------------------------------------------------------
29// test class
30// ----------------------------------------------------------------------------
31
32class StringTestCase : public CppUnit::TestCase
33{
34public:
35 StringTestCase();
36
37private:
38 CPPUNIT_TEST_SUITE( StringTestCase );
39 CPPUNIT_TEST( String );
40 CPPUNIT_TEST( PChar );
41 CPPUNIT_TEST( Format );
42 CPPUNIT_TEST( Constructors );
43 CPPUNIT_TEST( Extraction );
44 CPPUNIT_TEST( Find );
45 CPPUNIT_TEST( Tokenizer );
46 CPPUNIT_TEST( Replace );
47 CPPUNIT_TEST( Match );
48 CPPUNIT_TEST( Std );
49 CPPUNIT_TEST_SUITE_END();
50
51 void String();
52 void PChar();
53 void Format();
54 void Constructors();
55 void Extraction();
56 void Find();
57 void Tokenizer();
58 void Replace();
59 void Match();
60 void Std();
61
62 DECLARE_NO_COPY_CLASS(StringTestCase)
63};
64
65// register in the unnamed registry so that these tests are run by default
66CPPUNIT_TEST_SUITE_REGISTRATION( StringTestCase );
67
68// also include in it's own registry so that these tests can be run alone
69CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringTestCase, "StringTestCase" );
70
71StringTestCase::StringTestCase()
72{
73}
74
75void StringTestCase::String()
76{
77 wxString a, b, c;
78
79 a.reserve (128);
80 b.reserve (128);
81 c.reserve (128);
82
83 for (int i = 0; i < 2; ++i)
84 {
85 a = _T("Hello");
86 b = _T(" world");
87 c = _T("! How'ya doin'?");
88 a += b;
89 a += c;
90 c = _T("Hello world! What's up?");
91 CPPUNIT_ASSERT( c != a );
92 }
93}
94
95void StringTestCase::PChar()
96{
97 wxChar a [128];
98 wxChar b [128];
99 wxChar c [128];
100
101 for (int i = 0; i < 2; ++i)
102 {
103 wxStrcpy (a, _T("Hello"));
104 wxStrcpy (b, _T(" world"));
105 wxStrcpy (c, _T("! How'ya doin'?"));
106 wxStrcat (a, b);
107 wxStrcat (a, c);
108 wxStrcpy (c, _T("Hello world! What's up?"));
109 CPPUNIT_ASSERT( wxStrcmp (c, a) != 0 );
110 }
111}
112
113void StringTestCase::Format()
114{
115 wxString s1,s2;
116 s1.Printf(_T("%03d"), 18);
117 CPPUNIT_ASSERT( s1 == wxString::Format(_T("%03d"), 18) );
118 s2.Printf(_T("Number 18: %s\n"), s1.c_str());
119 CPPUNIT_ASSERT( s2 == wxString::Format(_T("Number 18: %s\n"), s1.c_str()) );
120}
121
122void StringTestCase::Constructors()
123{
124 #define TEST_CTOR(args, res) \
125 { \
126 wxString s args ; \
127 CPPUNIT_ASSERT( s == res ); \
128 }
129
130 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
131 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
132 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
133
134 static const wxChar *s = _T("?really!");
135 const wxChar *start = wxStrchr(s, _T('r'));
136 const wxChar *end = wxStrchr(s, _T('!'));
137 TEST_CTOR((start, end), _T("really"));
138}
139
140void StringTestCase::Extraction()
141{
142 wxString s(_T("Hello, world!"));
143
144 CPPUNIT_ASSERT( wxStrcmp( s.c_str() , _T("Hello, world!") ) == 0 );
145 CPPUNIT_ASSERT( wxStrcmp( s.Left(5).c_str() , _T("Hello") ) == 0 );
146 CPPUNIT_ASSERT( wxStrcmp( s.Right(6).c_str() , _T("world!") ) == 0 );
147 CPPUNIT_ASSERT( wxStrcmp( s(3, 5).c_str() , _T("lo, w") ) == 0 );
148 CPPUNIT_ASSERT( wxStrcmp( s.Mid(3).c_str() , _T("lo, world!") ) == 0 );
149 CPPUNIT_ASSERT( wxStrcmp( s.substr(3, 5).c_str() , _T("lo, w") ) == 0 );
150 CPPUNIT_ASSERT( wxStrcmp( s.substr(3).c_str() , _T("lo, world!") ) == 0 );
151
152 wxString rest;
153
154 #define TEST_STARTS_WITH( prefix , correct_rest, result ) \
155 CPPUNIT_ASSERT( \
156 ( s.StartsWith( prefix, &rest ) == result ) && \
157 ( ( result == false ) || ( wxStrcmp( correct_rest , rest ) == 0 ) ) \
158 )
159
160 TEST_STARTS_WITH( _T("Hello"), _T(", world!"), true );
161 TEST_STARTS_WITH( _T("Hello, "), _T("world!"), true );
162 TEST_STARTS_WITH( _T("Hello, world!"), _T(""), true );
163 TEST_STARTS_WITH( _T("Hello, world!!!"), _T(""), false );
164 TEST_STARTS_WITH( _T(""), _T("Hello, world!"), true );
165 TEST_STARTS_WITH( _T("Goodbye"), _T(""), false );
166 TEST_STARTS_WITH( _T("Hi"), _T(""), false );
167
168 #undef TEST_STARTS_WITH
169}
170
171void StringTestCase::Find()
172{
173 #define TEST_FIND( str , start , result ) \
174 CPPUNIT_ASSERT( wxString(str).find(_T("ell"), start) == result );
175
176 TEST_FIND( _T("Well, hello world"), 0, 1 );
177 TEST_FIND( _T("Well, hello world"), 6, 7 );
178 TEST_FIND( _T("Well, hello world"), 9, wxString::npos );
179
180 #undef TEST_FIND
181}
182
183void StringTestCase::Tokenizer()
184{
185 #define TEST_TOKENIZER( str , delims, count , mode ) \
186 { \
187 wxStringTokenizer tkz( str, delims, mode); \
188 CPPUNIT_ASSERT( tkz.CountTokens() == count ); \
189 \
190 wxChar *buf, *s = NULL, *last; \
191 \
192 if ( tkz.GetMode() == wxTOKEN_STRTOK ) \
193 { \
194 buf = new wxChar[wxStrlen(str) + 1]; \
195 wxStrcpy(buf, str); \
196 s = wxStrtok(buf, delims, &last); \
197 } \
198 else \
199 { \
200 buf = NULL; \
201 } \
202 \
203 size_t count2 = 0; \
204 while ( tkz.HasMoreTokens() ) \
205 { \
206 wxString token = tkz.GetNextToken(); \
207 if ( buf ) \
208 { \
209 CPPUNIT_ASSERT( token == s ); \
210 s = wxStrtok(NULL, delims, &last); \
211 } \
212 count2++; \
213 } \
214 \
215 CPPUNIT_ASSERT( count2 == count ); \
216 if ( buf ) \
217 { \
218 delete [] buf; \
219 } \
220 }
221
222 TEST_TOKENIZER( _T(""), _T(" "), 0, wxTOKEN_DEFAULT );
223 TEST_TOKENIZER( _T("Hello, world"), _T(" "), 2, wxTOKEN_DEFAULT );
224 TEST_TOKENIZER( _T("Hello, world "), _T(" "), 2, wxTOKEN_DEFAULT );
225 TEST_TOKENIZER( _T("Hello, world"), _T(","), 2, wxTOKEN_DEFAULT );
226 TEST_TOKENIZER( _T("Hello, world!"), _T(",!"), 2, wxTOKEN_DEFAULT );
227 TEST_TOKENIZER( _T("Hello,, world!"), _T(",!"), 3, wxTOKEN_DEFAULT );
228 TEST_TOKENIZER( _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL );
229 TEST_TOKENIZER( _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7, wxTOKEN_DEFAULT );
230 TEST_TOKENIZER( _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS, 4, wxTOKEN_DEFAULT );
231 TEST_TOKENIZER( _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS, 6, wxTOKEN_RET_EMPTY );
232 TEST_TOKENIZER( _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS, 9, wxTOKEN_RET_EMPTY_ALL );
233 TEST_TOKENIZER( _T("01/02/99"), _T("/-"), 3, wxTOKEN_DEFAULT );
234 TEST_TOKENIZER( _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS );
235
236 #undef TEST_TOKENIZER
237}
238
239void StringTestCase::Replace()
240{
241 #define TEST_REPLACE( original , pos , len , replacement , result ) \
242 { \
243 wxString s = original; \
244 s.replace( pos , len , replacement ); \
245 CPPUNIT_ASSERT( s == result ); \
246 }
247
248 TEST_REPLACE( _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") );
249 TEST_REPLACE( _T("increase"), 0, 2, _T("de"), _T("decrease") );
250 TEST_REPLACE( _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") );
251 TEST_REPLACE( _T("foobar"), 3, 0, _T("-"), _T("foo-bar") );
252 TEST_REPLACE( _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") );
253
254 #undef TEST_REPLACE
255}
256
257void StringTestCase::Match()
258{
259 #define TEST_MATCH( s1 , s2 , result ) \
260 CPPUNIT_ASSERT( wxString(s1).Matches(s2) == result )
261
262 TEST_MATCH( _T("foobar"), _T("foo*"), true );
263 TEST_MATCH( _T("foobar"), _T("*oo*"), true );
264 TEST_MATCH( _T("foobar"), _T("*bar"), true );
265 TEST_MATCH( _T("foobar"), _T("??????"), true );
266 TEST_MATCH( _T("foobar"), _T("f??b*"), true );
267 TEST_MATCH( _T("foobar"), _T("f?b*"), false );
268 TEST_MATCH( _T("foobar"), _T("*goo*"), false );
269 TEST_MATCH( _T("foobar"), _T("*foo"), false );
270 TEST_MATCH( _T("foobarfoo"), _T("*foo"), true );
271 TEST_MATCH( _T(""), _T("*"), true );
272 TEST_MATCH( _T(""), _T("?"), false );
273
274 #undef TEST_MATCH
275}
276
277void StringTestCase::Std()
278{
279 wxString s1(_T("abcdefgh")),
280 s2(_T("abcdefghijklm"), 8),
281 s3(_T("abcdefghijklm")),
282 s4(8, _T('a'));
283 wxString s5(s1),
284 s6(s3, 0, 8),
285 s7(s3.begin(), s3.begin() + 8);
286 wxString s8(s1, 4, 8), s9, s10, s11;
287
288 CPPUNIT_ASSERT( s1 == _T("abcdefgh") );
289 CPPUNIT_ASSERT( s2 == s1 );
290 CPPUNIT_ASSERT( s4 == _T("aaaaaaaa") );
291 CPPUNIT_ASSERT( s5 == _T("abcdefgh") );
292 CPPUNIT_ASSERT( s6 == s1 );
293 CPPUNIT_ASSERT( s7 == s1 );
294 CPPUNIT_ASSERT( s8 == _T("efgh") );
295
296 // test append
297 s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = _T("abc");
298 s1.append(_T("def"));
299 s2.append(_T("defgh"), 3);
300 s3.append(wxString(_T("abcdef")), 3, 6);
301 s4.append(s1);
302 s5.append(3, _T('a'));
303 s6.append(s1.begin() + 3, s1.end());
304
305 CPPUNIT_ASSERT( s1 == _T("abcdef") );
306 CPPUNIT_ASSERT( s2 == _T("abcdef") );
307 CPPUNIT_ASSERT( s3 == _T("abcdef") );
308 CPPUNIT_ASSERT( s4 == _T("abcabcdef") );
309 CPPUNIT_ASSERT( s5 == _T("abcaaa") );
310 CPPUNIT_ASSERT( s6 == _T("abcdef") );
311
312 // test assign
313 s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = _T("abc");
314 s1.assign(_T("def"));
315 s2.assign(_T("defgh"), 3);
316 s3.assign(wxString(_T("abcdef")), 3, 6);
317 s4.assign(s1);
318 s5.assign(3, _T('a'));
319 s6.assign(s1.begin() + 1, s1.end());
320
321 CPPUNIT_ASSERT( s1 == _T("def") );
322 CPPUNIT_ASSERT( s2 == _T("def") );
323 CPPUNIT_ASSERT( s3 == _T("def") );
324 CPPUNIT_ASSERT( s4 == _T("def") );
325 CPPUNIT_ASSERT( s5 == _T("aaa") );
326 CPPUNIT_ASSERT( s6 == _T("ef") );
327
328 // test compare
329 s1 = _T("abcdefgh");
330 s2 = _T("abcdefgh");
331 s3 = _T("abc");
332 s4 = _T("abcdefghi");
333 s5 = _T("aaa");
334 s6 = _T("zzz");
335 s7 = _T("zabcdefg");
336
337 CPPUNIT_ASSERT( s1.compare(s2) == 0 );
338 CPPUNIT_ASSERT( s1.compare(s3) > 0 );
339 CPPUNIT_ASSERT( s1.compare(s4) < 0 );
340 CPPUNIT_ASSERT( s1.compare(s5) > 0 );
341 CPPUNIT_ASSERT( s1.compare(s6) < 0 );
342 CPPUNIT_ASSERT( s1.compare(1, 12, s1) > 0);
343 CPPUNIT_ASSERT( s1.compare(_T("abcdefgh")) == 0);
344 CPPUNIT_ASSERT( s1.compare(1, 7, _T("bcdefgh")) == 0);
345 CPPUNIT_ASSERT( s1.compare(1, 7, _T("bcdefgh"), 7) == 0);
346
347 // test erase
348 s1.erase(1, 1);
349 s2.erase(4, 12);
350 wxString::iterator it = s3.erase(s3.begin() + 1);
351 wxString::iterator it2 = s4.erase(s4.begin() + 4, s4.begin() + 6);
352 wxString::iterator it3 = s7.erase(s7.begin() + 4, s7.begin() + 8);
353
354 CPPUNIT_ASSERT( s1 == _T("acdefgh") );
355 CPPUNIT_ASSERT( s2 == _T("abcd") );
356 CPPUNIT_ASSERT( s3 == _T("ac") );
357 CPPUNIT_ASSERT( s4 == _T("abcdghi") );
358 CPPUNIT_ASSERT( s7 == _T("zabc") );
359 CPPUNIT_ASSERT( *it == _T('c') );
360 CPPUNIT_ASSERT( *it2 == _T('g') );
361 CPPUNIT_ASSERT( it3 == s7.end() );
362
363 // find
364 // 0 1 2
365 // 01234567890123456789012345
366 s1 = _T("abcdefgABCDEFGabcABCabcABC");
367 s2 = _T("gAB");
368
369 CPPUNIT_ASSERT( s1.find(_T('A')) == 7u );
370 CPPUNIT_ASSERT( s1.find(_T('A'), 7) == 7u );
371 CPPUNIT_ASSERT( s1.find(_T('Z')) == wxString::npos );
372 CPPUNIT_ASSERT( s1.find(_T('C'), 22) == 25u );
373
374 CPPUNIT_ASSERT( s1.find(_T("gAB")) == 6u );
375 CPPUNIT_ASSERT( s1.find(_T("gAB"), 7) == wxString::npos );
376 CPPUNIT_ASSERT( s1.find(_T("gAB"), 6) == 6u );
377
378 CPPUNIT_ASSERT( s1.find(_T("gABZZZ"), 2, 3) == 6u );
379 CPPUNIT_ASSERT( s1.find(_T("gABZZZ"), 7, 3) == wxString::npos );
380
381 CPPUNIT_ASSERT( s1.find(s2) == 6u );
382 CPPUNIT_ASSERT( s1.find(s2, 7) == wxString::npos );
383 CPPUNIT_ASSERT( s1.find(s2, 6) == 6u );
384
385 // find_first_not_of
386 // 0 1 2 3
387 // 01234567890123456789012345678901234
388 s1 = _T("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd");
389 s2 = _T("aaaaaa");
390
391 CPPUNIT_ASSERT( s1.find_first_not_of(_T('a')) == 6u );
392 CPPUNIT_ASSERT( s1.find_first_not_of(_T('a'), 7) == 7u );
393 CPPUNIT_ASSERT( s2.find_first_not_of(_T('a')) == wxString::npos );
394
395 CPPUNIT_ASSERT( s1.find_first_not_of(_T("abde"), 4) == 7u );
396 CPPUNIT_ASSERT( s1.find_first_not_of(_T("abde"), 7) == 7u );
397 CPPUNIT_ASSERT( s1.find_first_not_of(_T("abcdefghijkl")) == wxString::npos );
398
399 CPPUNIT_ASSERT( s1.find_first_not_of(_T("abcdefghi"), 0, 4) == 9u );
400
401 // find_first_of
402 CPPUNIT_ASSERT( s1.find_first_of(_T('c')) == 7u );
403 CPPUNIT_ASSERT( s1.find_first_of(_T('v')) == wxString::npos );
404 CPPUNIT_ASSERT( s1.find_first_of(_T('c'), 10) == 24u );
405
406 CPPUNIT_ASSERT( s1.find_first_of(_T("ijkl")) == 13u );
407 CPPUNIT_ASSERT( s1.find_first_of(_T("ddcfg"), 17) == 24u );
408 CPPUNIT_ASSERT( s1.find_first_of(_T("ddcfga"), 17, 5) == 24u );
409
410 // find_last_not_of
411 // 0 1 2 3
412 // 01234567890123456789012345678901234
413 s1 = _T("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd");
414 s2 = _T("aaaaaa");
415
416 CPPUNIT_ASSERT( s2.find_last_not_of(_T('a')) == wxString::npos );
417 CPPUNIT_ASSERT( s1.find_last_not_of(_T('d')) == 33u );
418 CPPUNIT_ASSERT( s1.find_last_not_of(_T('d'), 25) == 24u );
419
420 CPPUNIT_ASSERT( s1.find_last_not_of(_T("bcd")) == 22u );
421 CPPUNIT_ASSERT( s1.find_last_not_of(_T("abc"), 24) == 16u );
422
423 CPPUNIT_ASSERT( s1.find_last_not_of(_T("abcdefghijklmnopqrstuv"), 24, 3) == 16u );
424
425 // find_last_of
426 CPPUNIT_ASSERT( s2.find_last_of(_T('c')) == wxString::npos );
427 CPPUNIT_ASSERT( s1.find_last_of(_T('a')) == 22u );
428 CPPUNIT_ASSERT( s1.find_last_of(_T('b'), 24) == 23u );
429
430 CPPUNIT_ASSERT( s1.find_last_of(_T("ijklm")) == 16u );
431 CPPUNIT_ASSERT( s1.find_last_of(_T("ijklma"), 33, 4) == 16u );
432 CPPUNIT_ASSERT( s1.find_last_of(_T("a"), 17) == 17u );
433
434 // test insert
435 s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = _T("aaaa");
436 s9 = s10 = _T("cdefg");
437
438 s1.insert(1, _T("cc") );
439 s2.insert(2, _T("cdef"), 3);
440 s3.insert(2, s10);
441 s4.insert(2, s10, 3, 7);
442 s5.insert(1, 2, _T('c'));
443 it = s6.insert(s6.begin() + 3, _T('X'));
444 s7.insert(s7.begin(), s9.begin(), s9.end() - 1);
445 s8.insert(s8.begin(), 2, _T('c'));
446
447 CPPUNIT_ASSERT( s1 == _T("accaaa") );
448 CPPUNIT_ASSERT( s2 == _T("aacdeaa") );
449 CPPUNIT_ASSERT( s3 == _T("aacdefgaa") );
450 CPPUNIT_ASSERT( s4 == _T("aafgaa") );
451 CPPUNIT_ASSERT( s5 == _T("accaaa") );
452 CPPUNIT_ASSERT( s6 == _T("aaaXa") );
453 CPPUNIT_ASSERT( s7 == _T("cdefaaaa") );
454 CPPUNIT_ASSERT( s8 == _T("ccaaaa") );
455
456 s1 = s2 = s3 = _T("aaaa");
457 s1.insert(0, _T("ccc"), 2);
458 s2.insert(4, _T("ccc"), 2);
459
460 CPPUNIT_ASSERT( s1 == _T("ccaaaa") );
461 CPPUNIT_ASSERT( s2 == _T("aaaacc") );
462
463 // test replace
464 s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = _T("QWERTYUIOP");
465 s9 = s10 = _T("werty");
466
467 s1.replace(3, 4, _T("rtyu"));
468 s1.replace(8, 7, _T("opopop"));
469 s2.replace(10, 12, _T("WWWW"));
470 s3.replace(1, 5, s9);
471 s4.replace(1, 4, s9, 0, 4);
472 s5.replace(1, 2, s9, 1, 12);
473 s6.replace(0, 123, s9, 0, 123);
474 s7.replace(2, 7, s9);
475
476 CPPUNIT_ASSERT( s1 == _T("QWErtyuIopopop") );
477 CPPUNIT_ASSERT( s2 == _T("QWERTYUIOPWWWW") );
478 CPPUNIT_ASSERT( s3 == _T("QwertyUIOP") );
479 CPPUNIT_ASSERT( s4 == _T("QwertYUIOP") );
480 CPPUNIT_ASSERT( s5 == _T("QertyRTYUIOP") );
481 CPPUNIT_ASSERT( s6 == s9);
482 CPPUNIT_ASSERT( s7 == _T("QWwertyP") );
483
484 // rfind
485 // 0 1 2
486 // 01234567890123456789012345
487 s1 = _T("abcdefgABCDEFGabcABCabcABC");
488 s2 = _T("gAB");
489 s3 = _T("ab");
490
491 CPPUNIT_ASSERT( s1.rfind(_T('A')) == 23u );
492 CPPUNIT_ASSERT( s1.rfind(_T('A'), 7) == 7u );
493 CPPUNIT_ASSERT( s1.rfind(_T('Z')) == wxString::npos );
494 CPPUNIT_ASSERT( s1.rfind(_T('C'), 22) == 19u );
495
496 CPPUNIT_ASSERT( s1.rfind(_T("cAB")) == 22u );
497 CPPUNIT_ASSERT( s1.rfind(_T("cAB"), 15) == wxString::npos );
498 CPPUNIT_ASSERT( s1.rfind(_T("cAB"), 21) == 16u );
499
500 CPPUNIT_ASSERT( s1.rfind(_T("gABZZZ"), 7, 3) == 6u );
501 CPPUNIT_ASSERT( s1.rfind(_T("gABZZZ"), 5, 3) == wxString::npos );
502
503 CPPUNIT_ASSERT( s1.rfind(s2) == 6u );
504 CPPUNIT_ASSERT( s1.rfind(s2, 5) == wxString::npos );
505 CPPUNIT_ASSERT( s1.rfind(s2, 6) == 6u );
506 CPPUNIT_ASSERT( s1.rfind(s3, 1) == 0u );
507
508 // resize
509 s1 = s2 = s3 = s4 = _T("abcABCdefDEF");
510
511 s1.resize( 12 );
512 s2.resize( 10 );
513 s3.resize( 14, _T(' ') );
514 s4.resize( 14, _T('W') );
515
516 CPPUNIT_ASSERT( s1 == _T("abcABCdefDEF") );
517 CPPUNIT_ASSERT( s2 == _T("abcABCdefD") );
518 CPPUNIT_ASSERT( s3 == _T("abcABCdefDEF ") );
519 CPPUNIT_ASSERT( s4 == _T("abcABCdefDEFWW") );
520
521 // substr
522 s1 = _T("abcdefgABCDEFG");
523
524 CPPUNIT_ASSERT( s1.substr( 0, 14 ) == s1 );
525 CPPUNIT_ASSERT( s1.substr( 1, 13 ) == _T("bcdefgABCDEFG") );
526 CPPUNIT_ASSERT( s1.substr( 1, 20 ) == _T("bcdefgABCDEFG") );
527 CPPUNIT_ASSERT( s1.substr( 14, 30 ) == _T("") );
528}
529