]> git.saurik.com Git - wxWidgets.git/blob - tests/strings/stdstrings.cpp
don't attempt to convert 8bit values to Unicode in ANSI build
[wxWidgets.git] / tests / strings / stdstrings.cpp
1 //////////////////////////////////////////////////////////////////////////////
2 // Name: tests/strings/stdstrings.cpp
3 // Purpose: wxString unit test
4 // Author: Vadim Zeitlin, Wlodzimierz ABX Skiba
5 // Created: 2004-05-07
6 // RCS-ID: $Id$
7 // Copyright: (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.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 // ----------------------------------------------------------------------------
25 // test class
26 // ----------------------------------------------------------------------------
27
28 class StdStringTestCase : public CppUnit::TestCase
29 {
30 public:
31 StdStringTestCase();
32
33 private:
34 CPPUNIT_TEST_SUITE( StdStringTestCase );
35 CPPUNIT_TEST( StdConstructors );
36 CPPUNIT_TEST( StdIterators );
37 CPPUNIT_TEST( StdAppend );
38 CPPUNIT_TEST( StdAssign );
39 CPPUNIT_TEST( StdCompare );
40 CPPUNIT_TEST( StdErase );
41 CPPUNIT_TEST( StdFind );
42 CPPUNIT_TEST( StdFindFirst );
43 CPPUNIT_TEST( StdFindLast );
44 CPPUNIT_TEST( StdInsert );
45 CPPUNIT_TEST( StdReplace );
46 CPPUNIT_TEST( StdRFind );
47 CPPUNIT_TEST( StdResize );
48 CPPUNIT_TEST( StdRiter );
49 CPPUNIT_TEST( StdSubstr );
50 #if wxUSE_STD_STRING
51 CPPUNIT_TEST( StdConversion );
52 #endif
53 CPPUNIT_TEST_SUITE_END();
54
55 void StdConstructors();
56 void StdIterators();
57 void StdAppend();
58 void StdAssign();
59 void StdCompare();
60 void StdErase();
61 void StdFind();
62 void StdFindFirst();
63 void StdFindLast();
64 void StdInsert();
65 void StdReplace();
66 void StdRFind();
67 void StdResize();
68 void StdRiter();
69 void StdSubstr();
70 #if wxUSE_STD_STRING
71 void StdConversion();
72 #endif
73
74 DECLARE_NO_COPY_CLASS(StdStringTestCase)
75 };
76
77 // register in the unnamed registry so that these tests are run by default
78 CPPUNIT_TEST_SUITE_REGISTRATION( StdStringTestCase );
79
80 // also include in it's own registry so that these tests can be run alone
81 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StdStringTestCase, "StdStringTestCase" );
82
83 StdStringTestCase::StdStringTestCase()
84 {
85 }
86
87 void StdStringTestCase::StdConstructors()
88 {
89 wxString s1(_T("abcdefgh")),
90 s2(_T("abcdefghijklm"), 8),
91 s3(_T("abcdefghijklm")),
92 s4(8, _T('a'));
93 wxString s5(s1),
94 s6(s3, 0, 8),
95 s7(s3.begin(), s3.begin() + 8);
96 wxString s8(s1, 4, 8);
97
98 CPPUNIT_ASSERT( s1 == _T("abcdefgh") );
99 CPPUNIT_ASSERT( s2 == s1 );
100 CPPUNIT_ASSERT( s4 == _T("aaaaaaaa") );
101 CPPUNIT_ASSERT( s5 == _T("abcdefgh") );
102 CPPUNIT_ASSERT( s6 == s1 );
103 CPPUNIT_ASSERT( s7 == s1 );
104 CPPUNIT_ASSERT( s8 == _T("efgh") );
105
106 const char *pc = s1.c_str();
107 WX_ASSERT_STR_EQUAL( "bcd", wxString(pc + 1, pc + 4) );
108
109 const wchar_t *pw = s2.c_str();
110 WX_ASSERT_STR_EQUAL( "a", wxString(pw, pw + 1) );
111 }
112
113 void StdStringTestCase::StdIterators()
114 {
115 // test compilation of default iterators ctors:
116 wxString::iterator i1;
117 wxString::const_iterator i2;
118 wxString::reverse_iterator i3;
119 wxString::const_reverse_iterator i4;
120 }
121
122 void StdStringTestCase::StdAppend()
123 {
124 wxString s1, s2, s3, s4, s5, s6, s7, s8;
125
126 s1 = s2 = s3 = s4 = s5 = s6 = _T("abc");
127 s1.append(_T("def"));
128 s2.append(_T("defgh"), 3);
129 s3.append(wxString(_T("abcdef")), 3, 6);
130 s4.append(s1);
131 s5.append(3, _T('a'));
132 s5.append(2, 'x');
133 s5.append(1, (unsigned char)'y');
134 s6.append(s1.begin() + 3, s1.end());
135
136 CPPUNIT_ASSERT( s1 == _T("abcdef") );
137 CPPUNIT_ASSERT( s2 == _T("abcdef") );
138 CPPUNIT_ASSERT( s3 == _T("abcdef") );
139 CPPUNIT_ASSERT( s4 == _T("abcabcdef") );
140 CPPUNIT_ASSERT( s5 == _T("abcaaaxxy") );
141 CPPUNIT_ASSERT( s6 == _T("abcdef") );
142
143 const char *pc = s1.c_str() + 2;
144 s7.append(pc, pc + 4);
145 WX_ASSERT_STR_EQUAL( "cdef", s7 );
146
147 const wchar_t *pw = s2.c_str() + 2;
148 s8.append(pw, pw + 4);
149 WX_ASSERT_STR_EQUAL( "cdef", s8 );
150
151 s7 = s8 = wxString(_T("null\0time"), 9);
152
153 s7.append(_T("def"));
154 s8.append(_T("defgh"), 3);
155
156 CPPUNIT_ASSERT( s7 == wxString(_T("null\0timedef"), 12) );
157 CPPUNIT_ASSERT( s8 == wxString(_T("null\0timedef"), 12) );
158 }
159
160 void StdStringTestCase::StdAssign()
161 {
162 wxString s1, s2, s3, s4, s5, s6, s7, s8;
163
164 s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = _T("abc");
165 s1.assign(_T("def"));
166 s2.assign(_T("defgh"), 3);
167 s3.assign(wxString(_T("abcdef")), 3, 6);
168 s4.assign(s1);
169 s5.assign(3, _T('a'));
170 s6.assign(s1.begin() + 1, s1.end());
171
172 CPPUNIT_ASSERT( s1 == _T("def") );
173 CPPUNIT_ASSERT( s2 == _T("def") );
174 CPPUNIT_ASSERT( s3 == _T("def") );
175 CPPUNIT_ASSERT( s4 == _T("def") );
176 CPPUNIT_ASSERT( s5 == _T("aaa") );
177 CPPUNIT_ASSERT( s6 == _T("ef") );
178
179 const char *pc = s1.c_str();
180 s7.assign(pc, pc + 2);
181 WX_ASSERT_STR_EQUAL( "de", s7 );
182
183 const wchar_t *pw = s1.c_str();
184 s8.assign(pw + 2, pw + 3);
185 WX_ASSERT_STR_EQUAL( "f", s8 );
186 }
187
188 void StdStringTestCase::StdCompare()
189 {
190 wxString s1, s2, s3, s4, s5, s6, s7, s8;
191
192 s1 = _T("abcdefgh");
193 s2 = _T("abcdefgh");
194 s3 = _T("abc");
195 s4 = _T("abcdefghi");
196 s5 = _T("aaa");
197 s6 = _T("zzz");
198
199 CPPUNIT_ASSERT( s1.compare(s2) == 0 );
200 CPPUNIT_ASSERT( s1.compare(s3) > 0 );
201 CPPUNIT_ASSERT( s1.compare(s4) < 0 );
202 CPPUNIT_ASSERT( s1.compare(s5) > 0 );
203 CPPUNIT_ASSERT( s1.compare(s6) < 0 );
204 CPPUNIT_ASSERT( s1.compare(1, 12, s1) > 0);
205 CPPUNIT_ASSERT( s1.compare(_T("abcdefgh")) == 0);
206 CPPUNIT_ASSERT( s1.compare(1, 7, _T("bcdefgh")) == 0);
207 CPPUNIT_ASSERT( s1.compare(1, 7, _T("bcdefgh"), 7) == 0);
208 }
209
210 void StdStringTestCase::StdErase()
211 {
212 wxString s1, s2, s3, s4, s5, s6, s7;
213
214 s1 = _T("abcdefgh");
215 s2 = _T("abcdefgh");
216 s3 = _T("abc");
217 s4 = _T("abcdefghi");
218 s5 = _T("aaa");
219 s6 = _T("zzz");
220 s7 = _T("zabcdefg");
221
222 s1.erase(1, 1);
223 s2.erase(4, 12);
224 wxString::iterator it = s3.erase(s3.begin() + 1);
225 wxString::iterator it2 = s4.erase(s4.begin() + 4, s4.begin() + 6);
226 wxString::iterator it3 = s7.erase(s7.begin() + 4, s7.begin() + 8);
227
228 CPPUNIT_ASSERT( s1 == _T("acdefgh") );
229 CPPUNIT_ASSERT( s2 == _T("abcd") );
230 CPPUNIT_ASSERT( s3 == _T("ac") );
231 CPPUNIT_ASSERT( s4 == _T("abcdghi") );
232 CPPUNIT_ASSERT( s7 == _T("zabc") );
233 CPPUNIT_ASSERT( *it == _T('c') );
234 CPPUNIT_ASSERT( *it2 == _T('g') );
235 CPPUNIT_ASSERT( it3 == s7.end() );
236 }
237
238 void StdStringTestCase::StdFind()
239 {
240 // 0 1 2
241 // 01234567890123456789012345
242 wxString s1 = _T("abcdefgABCDEFGabcABCabcABC");
243 wxString s2 = _T("gAB");
244
245 CPPUNIT_ASSERT( s1.find(_T('A')) == 7u );
246 CPPUNIT_ASSERT( s1.find(_T('A'), 7) == 7u );
247 CPPUNIT_ASSERT( s1.find(_T('Z')) == wxString::npos );
248 CPPUNIT_ASSERT( s1.find(_T('C'), 22) == 25u );
249
250 CPPUNIT_ASSERT( s1.find(_T("gAB")) == 6u );
251 CPPUNIT_ASSERT( s1.find(_T("gAB"), 7) == wxString::npos );
252 CPPUNIT_ASSERT( s1.find(_T("gAB"), 6) == 6u );
253
254 CPPUNIT_ASSERT( s1.find(_T("gABZZZ"), 2, 3) == 6u );
255 CPPUNIT_ASSERT( s1.find(_T("gABZZZ"), 7, 3) == wxString::npos );
256
257 CPPUNIT_ASSERT( s1.find(s2) == 6u );
258 CPPUNIT_ASSERT( s1.find(s2, 7) == wxString::npos );
259 CPPUNIT_ASSERT( s1.find(s2, 6) == 6u );
260
261 // 0 1 2
262 // 0123456 78901234567 8901234567
263 //wxString _s1 = _T("abcdefg\0ABCDEFGabc\0ABCabcABC");
264 //wxString _s2 = _T("g\0AB");
265 wxString _s1 = _T("abcdefgABCDEFGabcABCabcABC");
266 wxString _s2 = _T("gAB");
267
268 _s1.insert(7, 1, '\0');
269 _s1.insert(18, 1, '\0');
270 _s2.insert(1, 1, '\0');
271
272 CPPUNIT_ASSERT( _s1.find(_T('A')) == 8u );
273 CPPUNIT_ASSERT( _s1.find(_T('A'), 8) == 8u );
274 CPPUNIT_ASSERT( _s1.find(_T('Z')) == wxString::npos );
275 CPPUNIT_ASSERT( _s1.find(_T('C'), 22) == 27u );
276
277 CPPUNIT_ASSERT( _s1.find(_T("AB")) == 8u );
278 CPPUNIT_ASSERT( _s1.find(_T("AB"), 26) == wxString::npos );
279 CPPUNIT_ASSERT( _s1.find(_T("AB"), 23) == 25u );
280
281 CPPUNIT_ASSERT( _s1.find(_T("ABZZZ"), 2, 2) == 8u );
282 CPPUNIT_ASSERT( _s1.find(_T("ABZZZ"), 26, 2) == wxString::npos );
283
284 CPPUNIT_ASSERT( _s1.find(_s2) == 6u );
285 CPPUNIT_ASSERT( _s1.find(_s2, 7) == wxString::npos );
286 CPPUNIT_ASSERT( _s1.find(_s2, 6) == 6u );
287 }
288
289 void StdStringTestCase::StdFindFirst()
290 {
291 // 0 1 2 3
292 // 01234567890123456789012345678901234
293 wxString s1 = _T("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd");
294 wxString s2 = _T("aaaaaa");
295
296 CPPUNIT_ASSERT( s1.find_first_not_of(_T('a')) == 6u );
297 CPPUNIT_ASSERT( s1.find_first_not_of(_T('a'), 7) == 7u );
298 CPPUNIT_ASSERT( s2.find_first_not_of(_T('a')) == wxString::npos );
299
300 CPPUNIT_ASSERT( s1.find_first_not_of(_T("abde"), 4) == 7u );
301 CPPUNIT_ASSERT( s1.find_first_not_of(_T("abde"), 7) == 7u );
302 CPPUNIT_ASSERT( s1.find_first_not_of(_T("abcdefghijkl")) == wxString::npos );
303
304 CPPUNIT_ASSERT( s1.find_first_not_of(_T("abcdefghi"), 0, 4) == 9u );
305
306 CPPUNIT_ASSERT( s1.find_first_of(_T('c')) == 7u );
307 CPPUNIT_ASSERT( s1.find_first_of(_T('v')) == wxString::npos );
308 CPPUNIT_ASSERT( s1.find_first_of(_T('c'), 10) == 24u );
309
310 CPPUNIT_ASSERT( s1.find_first_of(_T("ijkl")) == 13u );
311 CPPUNIT_ASSERT( s1.find_first_of(_T("ddcfg"), 17) == 24u );
312 CPPUNIT_ASSERT( s1.find_first_of(_T("ddcfga"), 17, 5) == 24u );
313 }
314
315 void StdStringTestCase::StdFindLast()
316 {
317 // 0 1 2 3
318 // 01234567890123456789012345678901234
319 wxString s1 = _T("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd");
320 wxString s2 = _T("aaaaaa");
321
322 CPPUNIT_ASSERT( s2.find_last_not_of(_T('a')) == wxString::npos );
323 CPPUNIT_ASSERT( s1.find_last_not_of(_T('d')) == 33u );
324 CPPUNIT_ASSERT( s1.find_last_not_of(_T('d'), 25) == 24u );
325
326 CPPUNIT_ASSERT( s1.find_last_not_of(_T("bcd")) == 22u );
327 CPPUNIT_ASSERT( s1.find_last_not_of(_T("abc"), 24) == 16u );
328
329 CPPUNIT_ASSERT( s1.find_last_not_of(_T("abcdefghijklmnopqrstuv"), 24, 3) == 16u );
330
331 CPPUNIT_ASSERT( s2.find_last_of(_T('c')) == wxString::npos );
332 CPPUNIT_ASSERT( s1.find_last_of(_T('a')) == 22u );
333 CPPUNIT_ASSERT( s1.find_last_of(_T('b'), 24) == 23u );
334
335 CPPUNIT_ASSERT( s1.find_last_of(_T("ijklm")) == 16u );
336 CPPUNIT_ASSERT( s1.find_last_of(_T("ijklma"), 33, 4) == 16u );
337 CPPUNIT_ASSERT( s1.find_last_of(_T("a"), 17) == 17u );
338
339
340
341 // 0 1 2 3
342 // 012345 67890123456789 01234567890123456
343 // wxString s1 = _T("aaaaaa\0bcdefghlkjiaa\0aaaabcdbcdbcdbcd");
344 // wxString s2 = _T("aaaaaa\0");
345 s1.insert(6,1,'\0');
346 s1.insert(20,1,'\0');
347 s2.insert(6,1,'\0');
348
349 CPPUNIT_ASSERT( s2.find_last_not_of(_T('a')) == 6u );
350 CPPUNIT_ASSERT( s1.find_last_not_of(_T('d')) == 35u );
351 CPPUNIT_ASSERT( s1.find_last_not_of(_T('d'), 27) == 26u );
352
353 CPPUNIT_ASSERT( s1.find_last_not_of(_T("bcd")) == 24u );
354 CPPUNIT_ASSERT( s1.find_last_not_of(_T("abc"), 26) == 20u );
355
356 CPPUNIT_ASSERT( s1.find_last_not_of(_T("abcdefghijklmnopqrstuv"), 26, 3) == 20u );
357
358 CPPUNIT_ASSERT( s2.find_last_of(_T('c')) == wxString::npos );
359 CPPUNIT_ASSERT( s1.find_last_of(_T('a')) == 24u );
360 CPPUNIT_ASSERT( s1.find_last_of(_T('b'), 26) == 25u );
361
362 CPPUNIT_ASSERT( s1.find_last_of(_T("ijklm")) == 17u );
363 CPPUNIT_ASSERT( s1.find_last_of(_T("ijklma"), 35, 4) == 17u );
364 CPPUNIT_ASSERT( s1.find_last_of(_T("a"), 18) == 18u );
365 }
366
367 void StdStringTestCase::StdInsert()
368 {
369 wxString s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
370
371 s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = _T("aaaa");
372 s9 = s10 = _T("cdefg");
373
374 s1.insert(1, _T("cc") );
375 s2.insert(2, _T("cdef"), 3);
376 s3.insert(2, s10);
377 s4.insert(2, s10, 3, 7);
378 s5.insert(1, 2, _T('c'));
379 s6.insert(s6.begin() + 3, _T('X'));
380 s7.insert(s7.begin(), s9.begin(), s9.end() - 1);
381 s8.insert(s8.begin(), 2, _T('c'));
382
383 CPPUNIT_ASSERT( s1 == _T("accaaa") );
384 CPPUNIT_ASSERT( s2 == _T("aacdeaa") );
385 CPPUNIT_ASSERT( s3 == _T("aacdefgaa") );
386 CPPUNIT_ASSERT( s4 == _T("aafgaa") );
387 CPPUNIT_ASSERT( s5 == _T("accaaa") );
388 CPPUNIT_ASSERT( s6 == _T("aaaXa") );
389 CPPUNIT_ASSERT( s7 == _T("cdefaaaa") );
390 CPPUNIT_ASSERT( s8 == _T("ccaaaa") );
391
392 s1 = s2 = s3 = _T("aaaa");
393 s1.insert(0, _T("ccc"), 2);
394 s2.insert(4, _T("ccc"), 2);
395
396 CPPUNIT_ASSERT( s1 == _T("ccaaaa") );
397 CPPUNIT_ASSERT( s2 == _T("aaaacc") );
398 }
399
400 void StdStringTestCase::StdReplace()
401 {
402 wxString s1, s2, s3, s4, s5, s6, s7, s8, s9;
403
404 s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = _T("QWERTYUIOP");
405 s9 = _T("werty");
406
407 s1.replace(3, 4, _T("rtyu"));
408 s1.replace(8, 7, _T("opopop"));
409 s2.replace(10, 12, _T("WWWW"));
410 s3.replace(1, 5, s9);
411 s4.replace(1, 4, s9, 0, 4);
412 s5.replace(1, 2, s9, 1, 12);
413 s6.replace(0, 123, s9, 0, 123);
414 s7.replace(2, 7, s9);
415
416 CPPUNIT_ASSERT( s1 == _T("QWErtyuIopopop") );
417 CPPUNIT_ASSERT( s2 == _T("QWERTYUIOPWWWW") );
418 CPPUNIT_ASSERT( s3 == _T("QwertyUIOP") );
419 CPPUNIT_ASSERT( s4 == _T("QwertYUIOP") );
420 CPPUNIT_ASSERT( s5 == _T("QertyRTYUIOP") );
421 CPPUNIT_ASSERT( s6 == s9);
422 CPPUNIT_ASSERT( s7 == _T("QWwertyP") );
423 }
424
425 void StdStringTestCase::StdRFind()
426 {
427 // 0 1 2
428 // 01234567890123456789012345
429 wxString s1 = _T("abcdefgABCDEFGabcABCabcABC");
430 wxString s2 = _T("gAB");
431 wxString s3 = _T("ab");
432
433 CPPUNIT_ASSERT( s1.rfind(_T('A')) == 23u );
434 CPPUNIT_ASSERT( s1.rfind(_T('A'), 7) == 7u );
435 CPPUNIT_ASSERT( s1.rfind(_T('Z')) == wxString::npos );
436 CPPUNIT_ASSERT( s1.rfind(_T('C'), 22) == 19u );
437
438 CPPUNIT_ASSERT( s1.rfind(_T("cAB")) == 22u );
439 CPPUNIT_ASSERT( s1.rfind(_T("cAB"), 15) == wxString::npos );
440 CPPUNIT_ASSERT( s1.rfind(_T("cAB"), 21) == 16u );
441
442 CPPUNIT_ASSERT( s1.rfind(_T("gABZZZ"), 7, 3) == 6u );
443 CPPUNIT_ASSERT( s1.rfind(_T("gABZZZ"), 5, 3) == wxString::npos );
444
445 CPPUNIT_ASSERT( s1.rfind(s2) == 6u );
446 CPPUNIT_ASSERT( s1.rfind(s2, 5) == wxString::npos );
447 CPPUNIT_ASSERT( s1.rfind(s2, 6) == 6u );
448 CPPUNIT_ASSERT( s1.rfind(s3, 1) == 0u );
449
450
451 // 0 1 2
452 // 01234 56789012 345678901234567
453 // wxString s1 = _T("abcde\0fgABCDE\0FGabcABCabcABC");
454 // wxString s2 = _T("gAB");
455 // wxString s3 = _T("ab");
456
457 s1.insert(5,1,'\0');
458 s1.insert(13,1,'\0');
459
460 CPPUNIT_ASSERT( s1.rfind(_T('A')) == 25u );
461 CPPUNIT_ASSERT( s1.rfind(_T('A'), 8) == 8u );
462 CPPUNIT_ASSERT( s1.rfind(_T('Z')) == wxString::npos );
463 CPPUNIT_ASSERT( s1.rfind(_T('C'), 22) == 21u );
464
465 CPPUNIT_ASSERT( s1.rfind(_T("cAB")) == 24u );
466 CPPUNIT_ASSERT( s1.rfind(_T("cAB"), 15) == wxString::npos );
467 CPPUNIT_ASSERT( s1.rfind(_T("cAB"), 21) == 18u );
468
469 CPPUNIT_ASSERT( s1.rfind(_T("gABZZZ"), 8, 3) == 7u );
470 CPPUNIT_ASSERT( s1.rfind(_T("gABZZZ"), 5, 3) == wxString::npos );
471 }
472
473 void StdStringTestCase::StdResize()
474 {
475 wxString s1, s2, s3, s4;
476
477 s1 = s2 = s3 = s4 = _T("abcABCdefDEF");
478
479 s1.resize( 12 );
480 s2.resize( 10 );
481 s3.resize( 14, _T(' ') );
482 s4.resize( 14, _T('W') );
483
484 CPPUNIT_ASSERT( s1 == _T("abcABCdefDEF") );
485 CPPUNIT_ASSERT( s2 == _T("abcABCdefD") );
486 CPPUNIT_ASSERT( s3 == _T("abcABCdefDEF ") );
487 CPPUNIT_ASSERT( s4 == _T("abcABCdefDEFWW") );
488 }
489
490 void StdStringTestCase::StdRiter()
491 {
492 const wxString s(_T("fozbar"));
493
494 wxString::const_reverse_iterator ri(s.rbegin());
495 CPPUNIT_ASSERT( _T('r') == *ri );
496 CPPUNIT_ASSERT( _T('a') == *++ri );
497 CPPUNIT_ASSERT( _T('r') == *--ri );
498
499 ri = s.rend();
500 ri--;
501 CPPUNIT_ASSERT( _T('f') == *ri );
502
503 --ri;
504 CPPUNIT_ASSERT( _T('o') == *ri );
505
506 wxString::const_iterator i = ri.base();
507 CPPUNIT_ASSERT( _T('z') == *i );
508 }
509
510 void StdStringTestCase::StdSubstr()
511 {
512 wxString s1 = _T("abcdefgABCDEFG");
513
514 CPPUNIT_ASSERT( s1.substr( 0, 14 ) == s1 );
515 CPPUNIT_ASSERT( s1.substr( 1, 13 ) == _T("bcdefgABCDEFG") );
516 CPPUNIT_ASSERT( s1.substr( 1, 20 ) == _T("bcdefgABCDEFG") );
517 CPPUNIT_ASSERT( s1.substr( 14, 30 ) == _T("") );
518
519 s1.insert(3,1,'\0');
520 s1.insert(8,1,'\0');
521 s1.insert(13,1,'\0');
522
523 wxString s2 = wxT("bcdefgABCDEFG");
524 s2.insert(2,1,'\0');
525 s2.insert(7,1,'\0');
526 s2.insert(12,1,'\0');
527
528 CPPUNIT_ASSERT( s1.substr( 0, 17 ) == s1 );
529 CPPUNIT_ASSERT( s1.substr( 1, 17 ) == s2 );
530 CPPUNIT_ASSERT( s1.substr( 1, 20 ) == s2 );
531 CPPUNIT_ASSERT( s1.substr( 17, 30 ) == _T("") );
532 }
533
534 #if wxUSE_STD_STRING
535 void StdStringTestCase::StdConversion()
536 {
537 std::string strStd("std::string value");
538 wxStdWideString strStdWide(L"std::wstring value");
539
540 wxString s1(strStd);
541 CPPUNIT_ASSERT( s1 == "std::string value" );
542
543 wxString s2(strStdWide);
544 CPPUNIT_ASSERT( s2 == "std::wstring value" );
545
546 wxString s3;
547 s3 = strStd;
548 CPPUNIT_ASSERT( s3 == "std::string value" );
549 s3 = strStdWide;
550 CPPUNIT_ASSERT( s3 == "std::wstring value" );
551
552 wxString s4("hello");
553
554 // wxString -> std::string conversion is only available in wxUSE_STL case,
555 // because it conflicts with conversion to const char*/wchar_t*:
556 #if wxUSE_STL
557 std::string s5 = s4;
558 CPPUNIT_ASSERT( s5 == "hello" );
559
560 wxStdWideString s6 = s4;
561 CPPUNIT_ASSERT( s6 == "hello" );
562 #endif
563
564 std::string s7(s4);
565 CPPUNIT_ASSERT( s7 == "hello" );
566
567 wxStdWideString s8(s4);
568 CPPUNIT_ASSERT( s8 == "hello" );
569 }
570 #endif // wxUSE_STD_STRING