1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/strings/strings.cpp
3 // Purpose: wxString unit test
4 // Author: Vadim Zeitlin, Wlodzimierz ABX Skiba
7 // Copyright: (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 class StringTestCase
: public CppUnit::TestCase
34 CPPUNIT_TEST_SUITE( StringTestCase
);
35 CPPUNIT_TEST( String
);
36 CPPUNIT_TEST( PChar
);
37 CPPUNIT_TEST( Format
);
38 CPPUNIT_TEST( Constructors
);
39 CPPUNIT_TEST( Extraction
);
42 CPPUNIT_TEST( Replace
);
43 CPPUNIT_TEST( Match
);
44 CPPUNIT_TEST( CaseChanges
);
45 CPPUNIT_TEST( Compare
);
46 CPPUNIT_TEST( CompareNoCase
);
47 CPPUNIT_TEST( Contains
);
48 CPPUNIT_TEST( ToLong
);
49 CPPUNIT_TEST( ToULong
);
51 CPPUNIT_TEST( ToLongLong
);
52 CPPUNIT_TEST( ToULongLong
);
53 #endif // wxLongLong_t
54 CPPUNIT_TEST( ToDouble
);
55 CPPUNIT_TEST( WriteBuf
);
56 CPPUNIT_TEST( CStrDataTernaryOperator
);
57 CPPUNIT_TEST( CStrDataOperators
);
58 CPPUNIT_TEST( CStrDataImplicitConversion
);
59 CPPUNIT_TEST( ExplicitConversion
);
60 CPPUNIT_TEST_SUITE_END();
80 #endif // wxLongLong_t
83 void CStrDataTernaryOperator();
84 void DoCStrDataTernaryOperator(bool cond
);
85 void CStrDataOperators();
86 void CStrDataImplicitConversion();
87 void ExplicitConversion();
89 DECLARE_NO_COPY_CLASS(StringTestCase
)
92 // register in the unnamed registry so that these tests are run by default
93 CPPUNIT_TEST_SUITE_REGISTRATION( StringTestCase
);
95 // also include in it's own registry so that these tests can be run alone
96 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringTestCase
, "StringTestCase" );
98 StringTestCase::StringTestCase()
102 void StringTestCase::String()
110 for (int i
= 0; i
< 2; ++i
)
114 c
= _T("! How'ya doin'?");
117 c
= _T("Hello world! What's up?");
118 CPPUNIT_ASSERT( c
!= a
);
122 void StringTestCase::PChar()
128 for (int i
= 0; i
< 2; ++i
)
130 wxStrcpy (a
, _T("Hello"));
131 wxStrcpy (b
, _T(" world"));
132 wxStrcpy (c
, _T("! How'ya doin'?"));
135 wxStrcpy (c
, _T("Hello world! What's up?"));
136 CPPUNIT_ASSERT( wxStrcmp (c
, a
) != 0 );
140 void StringTestCase::Format()
143 s1
.Printf(_T("%03d"), 18);
144 CPPUNIT_ASSERT( s1
== wxString::Format(_T("%03d"), 18) );
145 s2
.Printf(_T("Number 18: %s\n"), s1
.c_str());
146 CPPUNIT_ASSERT( s2
== wxString::Format(_T("Number 18: %s\n"), s1
.c_str()) );
148 static const size_t lengths
[] = { 1, 512, 1024, 1025, 2048, 4096, 4097 };
149 for ( size_t n
= 0; n
< WXSIZEOF(lengths
); n
++ )
151 const size_t len
= lengths
[n
];
153 wxString
s(_T('Z'), len
);
154 CPPUNIT_ASSERT_EQUAL( len
, wxString::Format(_T("%s"), s
.c_str()).length());
158 void StringTestCase::Constructors()
160 #define TEST_CTOR(args, res) \
163 CPPUNIT_ASSERT( s == res ); \
166 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
167 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
168 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
170 static const wxChar
*s
= _T("?really!");
171 const wxChar
*start
= wxStrchr(s
, _T('r'));
172 const wxChar
*end
= wxStrchr(s
, _T('!'));
173 TEST_CTOR((start
, end
), _T("really"));
177 void StringTestCase::Extraction()
179 wxString
s(_T("Hello, world!"));
181 CPPUNIT_ASSERT( wxStrcmp( s
.c_str() , _T("Hello, world!") ) == 0 );
182 CPPUNIT_ASSERT( wxStrcmp( s
.Left(5).c_str() , _T("Hello") ) == 0 );
183 CPPUNIT_ASSERT( wxStrcmp( s
.Right(6).c_str() , _T("world!") ) == 0 );
184 CPPUNIT_ASSERT( wxStrcmp( s(3, 5).c_str() , _T("lo, w") ) == 0 );
185 CPPUNIT_ASSERT( wxStrcmp( s
.Mid(3).c_str() , _T("lo, world!") ) == 0 );
186 CPPUNIT_ASSERT( wxStrcmp( s
.substr(3, 5).c_str() , _T("lo, w") ) == 0 );
187 CPPUNIT_ASSERT( wxStrcmp( s
.substr(3).c_str() , _T("lo, world!") ) == 0 );
190 static const char *germanUTF8
= "Oberfl\303\244che";
191 wxString
strUnicode(wxString::FromUTF8(germanUTF8
));
193 CPPUNIT_ASSERT( strUnicode
.Mid(0, 10) == strUnicode
);
194 CPPUNIT_ASSERT( strUnicode
.Mid(7, 2) == "ch" );
195 #endif // wxUSE_UNICODE
199 #define TEST_STARTS_WITH(prefix, correct_rest, result) \
200 CPPUNIT_ASSERT_EQUAL(result, s.StartsWith(prefix, &rest)); \
202 CPPUNIT_ASSERT_EQUAL(wxString(correct_rest), rest)
204 TEST_STARTS_WITH( _T("Hello"), _T(", world!"), true );
205 TEST_STARTS_WITH( _T("Hello, "), _T("world!"), true );
206 TEST_STARTS_WITH( _T("Hello, world!"), _T(""), true );
207 TEST_STARTS_WITH( _T("Hello, world!!!"), _T(""), false );
208 TEST_STARTS_WITH( _T(""), _T("Hello, world!"), true );
209 TEST_STARTS_WITH( _T("Goodbye"), _T(""), false );
210 TEST_STARTS_WITH( _T("Hi"), _T(""), false );
212 #undef TEST_STARTS_WITH
214 #define TEST_ENDS_WITH(suffix, correct_rest, result) \
215 CPPUNIT_ASSERT_EQUAL(result, s.EndsWith(suffix, &rest)); \
217 CPPUNIT_ASSERT_EQUAL(wxString(correct_rest), rest)
219 TEST_ENDS_WITH( _T(""), _T("Hello, world!"), true );
220 TEST_ENDS_WITH( _T("!"), _T("Hello, world"), true );
221 TEST_ENDS_WITH( _T(", world!"), _T("Hello"), true );
222 TEST_ENDS_WITH( _T("ello, world!"), _T("H"), true );
223 TEST_ENDS_WITH( _T("Hello, world!"), _T(""), true );
224 TEST_ENDS_WITH( _T("very long string"), _T(""), false );
225 TEST_ENDS_WITH( _T("?"), _T(""), false );
226 TEST_ENDS_WITH( _T("Hello, world"), _T(""), false );
227 TEST_ENDS_WITH( _T("Gello, world!"), _T(""), false );
229 #undef TEST_ENDS_WITH
232 void StringTestCase::Trim()
234 #define TEST_TRIM( str , dir , result ) \
235 CPPUNIT_ASSERT( wxString(str).Trim(dir) == result )
237 TEST_TRIM( _T(" Test "), true, _T(" Test") );
238 TEST_TRIM( _T(" "), true, _T("") );
239 TEST_TRIM( _T(" "), true, _T("") );
240 TEST_TRIM( _T(""), true, _T("") );
242 TEST_TRIM( _T(" Test "), false, _T("Test ") );
243 TEST_TRIM( _T(" "), false, _T("") );
244 TEST_TRIM( _T(" "), false, _T("") );
245 TEST_TRIM( _T(""), false, _T("") );
250 void StringTestCase::Find()
252 #define TEST_FIND( str , start , result ) \
253 CPPUNIT_ASSERT( wxString(str).find(_T("ell"), start) == result );
255 TEST_FIND( _T("Well, hello world"), 0, 1 );
256 TEST_FIND( _T("Well, hello world"), 6, 7 );
257 TEST_FIND( _T("Well, hello world"), 9, wxString::npos
);
262 void StringTestCase::Replace()
264 #define TEST_REPLACE( original , pos , len , replacement , result ) \
266 wxString s = original; \
267 s.replace( pos , len , replacement ); \
268 CPPUNIT_ASSERT( s == result ); \
271 TEST_REPLACE( _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") );
272 TEST_REPLACE( _T("increase"), 0, 2, _T("de"), _T("decrease") );
273 TEST_REPLACE( _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") );
274 TEST_REPLACE( _T("foobar"), 3, 0, _T("-"), _T("foo-bar") );
275 TEST_REPLACE( _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") );
278 #define TEST_NULLCHARREPLACE( o , olen, pos , len , replacement , r, rlen ) \
280 wxString s(o,olen); \
281 s.replace( pos , len , replacement ); \
282 CPPUNIT_ASSERT( s == wxString(r,rlen) ); \
285 TEST_NULLCHARREPLACE( _T("null\0char"), 9, 5, 1, _T("d"),
286 _T("null\0dhar"), 9 );
288 #define TEST_WXREPLACE( o , olen, olds, news, all, r, rlen ) \
290 wxString s(o,olen); \
291 s.Replace( olds, news, all ); \
292 CPPUNIT_ASSERT( s == wxString(r,rlen) ); \
295 TEST_WXREPLACE( _T("null\0char"), 9, _T("c"), _T("de"), true,
296 _T("null\0dehar"), 10 );
298 TEST_WXREPLACE( _T("null\0dehar"), 10, _T("de"), _T("c"), true,
299 _T("null\0char"), 9 );
301 #undef TEST_WXREPLACE
302 #undef TEST_NULLCHARREPLACE
306 void StringTestCase::Match()
308 #define TEST_MATCH( s1 , s2 , result ) \
309 CPPUNIT_ASSERT( wxString(s1).Matches(s2) == result )
311 TEST_MATCH( _T("foobar"), _T("foo*"), true );
312 TEST_MATCH( _T("foobar"), _T("*oo*"), true );
313 TEST_MATCH( _T("foobar"), _T("*bar"), true );
314 TEST_MATCH( _T("foobar"), _T("??????"), true );
315 TEST_MATCH( _T("foobar"), _T("f??b*"), true );
316 TEST_MATCH( _T("foobar"), _T("f?b*"), false );
317 TEST_MATCH( _T("foobar"), _T("*goo*"), false );
318 TEST_MATCH( _T("foobar"), _T("*foo"), false );
319 TEST_MATCH( _T("foobarfoo"), _T("*foo"), true );
320 TEST_MATCH( _T(""), _T("*"), true );
321 TEST_MATCH( _T(""), _T("?"), false );
327 void StringTestCase::CaseChanges()
329 wxString
s1(_T("Hello!"));
338 CPPUNIT_ASSERT( s1u
== _T("HELLO!") );
339 CPPUNIT_ASSERT( s1l
== _T("hello!") );
340 CPPUNIT_ASSERT( s2u
== wxEmptyString
);
341 CPPUNIT_ASSERT( s2l
== wxEmptyString
);
344 wxLocale
locRu(wxLANGUAGE_RUSSIAN
, 0 /* flags */);
347 // try upper casing 8bit strings
348 const wchar_t capital_ya
[] = { 0x42f, 0 },
349 small_ya
[] = { 0x44f, 0 };
351 wxString
sUpper(wxConvLibc
.cWC2MB(capital_ya
)),
352 sLower(wxConvLibc
.cWC2MB(small_ya
));
354 CPPUNIT_ASSERT( sUpper
.Lower() == sLower
);
355 CPPUNIT_ASSERT( sLower
.Upper() == sUpper
);
357 #endif // !wxUSE_UNICODE
360 void StringTestCase::Compare()
362 wxString s1
= wxT("AHH");
363 wxString eq
= wxT("AHH");
364 wxString neq1
= wxT("HAH");
365 wxString neq2
= wxT("AH");
366 wxString neq3
= wxT("AHHH");
367 wxString neq4
= wxT("AhH");
369 CPPUNIT_ASSERT( s1
== eq
);
370 CPPUNIT_ASSERT( s1
!= neq1
);
371 CPPUNIT_ASSERT( s1
!= neq2
);
372 CPPUNIT_ASSERT( s1
!= neq3
);
373 CPPUNIT_ASSERT( s1
!= neq4
);
375 CPPUNIT_ASSERT( s1
== wxT("AHH") );
376 CPPUNIT_ASSERT( s1
!= wxT("no") );
377 CPPUNIT_ASSERT( s1
< wxT("AZ") );
378 CPPUNIT_ASSERT( s1
<= wxT("AZ") );
379 CPPUNIT_ASSERT( s1
<= wxT("AHH") );
380 CPPUNIT_ASSERT( s1
> wxT("AA") );
381 CPPUNIT_ASSERT( s1
>= wxT("AA") );
382 CPPUNIT_ASSERT( s1
>= wxT("AHH") );
384 // test comparison with C strings in Unicode build (must work in ANSI as
386 CPPUNIT_ASSERT( s1
== "AHH" );
387 CPPUNIT_ASSERT( s1
!= "no" );
388 CPPUNIT_ASSERT( s1
< "AZ" );
389 CPPUNIT_ASSERT( s1
<= "AZ" );
390 CPPUNIT_ASSERT( s1
<= "AHH" );
391 CPPUNIT_ASSERT( s1
> "AA" );
392 CPPUNIT_ASSERT( s1
>= "AA" );
393 CPPUNIT_ASSERT( s1
>= "AHH" );
395 // wxString _s1 = wxT("A\0HH");
396 // wxString _eq = wxT("A\0HH");
397 // wxString _neq1 = wxT("H\0AH");
398 // wxString _neq2 = wxT("A\0H");
399 // wxString _neq3 = wxT("A\0HHH");
400 // wxString _neq4 = wxT("A\0hH");
403 neq1
.insert(1,1,'\0');
404 neq2
.insert(1,1,'\0');
405 neq3
.insert(1,1,'\0');
406 neq4
.insert(1,1,'\0');
408 CPPUNIT_ASSERT( s1
== eq
);
409 CPPUNIT_ASSERT( s1
!= neq1
);
410 CPPUNIT_ASSERT( s1
!= neq2
);
411 CPPUNIT_ASSERT( s1
!= neq3
);
412 CPPUNIT_ASSERT( s1
!= neq4
);
415 void StringTestCase::CompareNoCase()
417 wxString s1
= wxT("AHH");
418 wxString eq
= wxT("AHH");
419 wxString eq2
= wxT("AhH");
420 wxString eq3
= wxT("ahh");
421 wxString neq
= wxT("HAH");
422 wxString neq2
= wxT("AH");
423 wxString neq3
= wxT("AHHH");
425 #define CPPUNIT_CNCEQ_ASSERT(s1, s2) CPPUNIT_ASSERT( s1.CmpNoCase(s2) == 0)
426 #define CPPUNIT_CNCNEQ_ASSERT(s1, s2) CPPUNIT_ASSERT( s1.CmpNoCase(s2) != 0)
428 CPPUNIT_CNCEQ_ASSERT( s1
, eq
);
429 CPPUNIT_CNCEQ_ASSERT( s1
, eq2
);
430 CPPUNIT_CNCEQ_ASSERT( s1
, eq3
);
432 CPPUNIT_CNCNEQ_ASSERT( s1
, neq
);
433 CPPUNIT_CNCNEQ_ASSERT( s1
, neq2
);
434 CPPUNIT_CNCNEQ_ASSERT( s1
, neq3
);
437 // wxString _s1 = wxT("A\0HH");
438 // wxString _eq = wxT("A\0HH");
439 // wxString _eq2 = wxT("A\0hH");
440 // wxString _eq3 = wxT("a\0hh");
441 // wxString _neq = wxT("H\0AH");
442 // wxString _neq2 = wxT("A\0H");
443 // wxString _neq3 = wxT("A\0HHH");
447 eq2
.insert(1,1,'\0');
448 eq3
.insert(1,1,'\0');
449 neq
.insert(1,1,'\0');
450 neq2
.insert(1,1,'\0');
451 neq3
.insert(1,1,'\0');
453 CPPUNIT_CNCEQ_ASSERT( s1
, eq
);
454 CPPUNIT_CNCEQ_ASSERT( s1
, eq2
);
455 CPPUNIT_CNCEQ_ASSERT( s1
, eq3
);
457 CPPUNIT_CNCNEQ_ASSERT( s1
, neq
);
458 CPPUNIT_CNCNEQ_ASSERT( s1
, neq2
);
459 CPPUNIT_CNCNEQ_ASSERT( s1
, neq3
);
462 void StringTestCase::Contains()
464 static const struct ContainsData
467 const wxChar
*needle
;
471 { _T(""), _T(""), true },
472 { _T(""), _T("foo"), false },
473 { _T("foo"), _T(""), true },
474 { _T("foo"), _T("f"), true },
475 { _T("foo"), _T("o"), true },
476 { _T("foo"), _T("oo"), true },
477 { _T("foo"), _T("ooo"), false },
478 { _T("foo"), _T("oooo"), false },
479 { _T("foo"), _T("fooo"), false },
482 for ( size_t n
= 0; n
< WXSIZEOF(containsData
); n
++ )
484 const ContainsData
& cd
= containsData
[n
];
485 CPPUNIT_ASSERT_EQUAL( cd
.contains
, wxString(cd
.hay
).Contains(cd
.needle
) );
489 // flags used in ToLongData.flags
494 Number_Unsigned
= 2, // if not specified, works for signed conversion
495 Number_Signed
= 4, // if not specified, works for unsigned
496 Number_LongLong
= 8, // only for long long tests
497 Number_Long
= 16, // only for long tests
500 static const struct ToLongData
507 #endif // wxLongLong_t
510 long LValue() const { return value
; }
511 unsigned long ULValue() const { return value
; }
513 wxLongLong_t
LLValue() const { return value
; }
514 wxULongLong_t
ULLValue() const { return (wxULongLong_t
)value
; }
515 #endif // wxLongLong_t
517 bool IsOk() const { return !(flags
& Number_Invalid
); }
520 { _T("1"), 1, Number_Ok
},
521 { _T("0"), 0, Number_Ok
},
522 { _T("a"), 0, Number_Invalid
},
523 { _T("12345"), 12345, Number_Ok
},
524 { _T("--1"), 0, Number_Invalid
},
526 { _T("-1"), -1, Number_Signed
| Number_Long
},
527 // this is surprizing but consistent with strtoul() behaviour
528 { _T("-1"), ULONG_MAX
, Number_Unsigned
| Number_Long
},
530 // this must overflow, even with 64 bit long
531 { _T("922337203685477580711"), 0, Number_Invalid
},
534 { _T("2147483648"), wxLL(2147483648), Number_LongLong
},
535 { _T("-2147483648"), wxLL(-2147483648), Number_LongLong
| Number_Signed
},
536 { _T("9223372036854775808"), wxULL(9223372036854775808), Number_LongLong
|
538 #endif // wxLongLong_t
541 void StringTestCase::ToLong()
544 for ( size_t n
= 0; n
< WXSIZEOF(longData
); n
++ )
546 const ToLongData
& ld
= longData
[n
];
548 if ( ld
.flags
& (Number_LongLong
| Number_Unsigned
) )
551 CPPUNIT_ASSERT_EQUAL( ld
.IsOk(), wxString(ld
.str
).ToLong(&l
) );
553 CPPUNIT_ASSERT_EQUAL( ld
.LValue(), l
);
557 void StringTestCase::ToULong()
560 for ( size_t n
= 0; n
< WXSIZEOF(longData
); n
++ )
562 const ToLongData
& ld
= longData
[n
];
564 if ( ld
.flags
& (Number_LongLong
| Number_Signed
) )
567 CPPUNIT_ASSERT_EQUAL( ld
.IsOk(), wxString(ld
.str
).ToULong(&ul
) );
569 CPPUNIT_ASSERT_EQUAL( ld
.ULValue(), ul
);
575 void StringTestCase::ToLongLong()
578 for ( size_t n
= 0; n
< WXSIZEOF(longData
); n
++ )
580 const ToLongData
& ld
= longData
[n
];
582 if ( ld
.flags
& (Number_Long
| Number_Unsigned
) )
585 CPPUNIT_ASSERT_EQUAL( ld
.IsOk(), wxString(ld
.str
).ToLongLong(&l
) );
587 CPPUNIT_ASSERT_EQUAL( ld
.LLValue(), l
);
591 void StringTestCase::ToULongLong()
594 for ( size_t n
= 0; n
< WXSIZEOF(longData
); n
++ )
596 const ToLongData
& ld
= longData
[n
];
598 if ( ld
.flags
& (Number_Long
| Number_Signed
) )
601 CPPUNIT_ASSERT_EQUAL( ld
.IsOk(), wxString(ld
.str
).ToULongLong(&ul
) );
603 CPPUNIT_ASSERT_EQUAL( ld
.ULLValue(), ul
);
607 #endif // wxLongLong_t
609 void StringTestCase::ToDouble()
612 static const struct ToDoubleData
619 { _T("1"), 1, true },
620 { _T("1.23"), 1.23, true },
621 { _T(".1"), .1, true },
622 { _T("1."), 1, true },
623 { _T("1.."), 0, false },
624 { _T("0"), 0, true },
625 { _T("a"), 0, false },
626 { _T("12345"), 12345, true },
627 { _T("-1"), -1, true },
628 { _T("--1"), 0, false },
631 // we need to use decimal point, not comma or whatever is its value for the
633 wxSetlocale(LC_ALL
, _T("C"));
636 for ( n
= 0; n
< WXSIZEOF(doubleData
); n
++ )
638 const ToDoubleData
& ld
= doubleData
[n
];
639 CPPUNIT_ASSERT_EQUAL( ld
.ok
, wxString(ld
.str
).ToDouble(&d
) );
641 CPPUNIT_ASSERT_EQUAL( ld
.value
, d
);
645 void StringTestCase::WriteBuf()
648 wxStrcpy(wxStringBuffer(s
, 10), _T("foo"));
650 CPPUNIT_ASSERT(s
[0u] == _T('f') );
651 CPPUNIT_ASSERT(_T('f') == s
[0u]);
652 CPPUNIT_ASSERT(_T('o') == s
[1]);
653 CPPUNIT_ASSERT(_T('o') == s
[2]);
654 CPPUNIT_ASSERT_EQUAL((size_t)3, s
.length());
658 wxStringBufferLength
buf(s
, 10);
659 wxStrcpy(buf
, _T("barrbaz"));
663 CPPUNIT_ASSERT(_T('b') == s
[0u]);
664 CPPUNIT_ASSERT(_T('a') == s
[1]);
665 CPPUNIT_ASSERT(_T('r') == s
[2]);
666 CPPUNIT_ASSERT(_T('r') == s
[3]);
667 CPPUNIT_ASSERT_EQUAL((size_t)4, s
.length());
669 CPPUNIT_ASSERT_EQUAL( 0, wxStrcmp(_T("barr"), s
) );
674 void StringTestCase::CStrDataTernaryOperator()
676 DoCStrDataTernaryOperator(true);
677 DoCStrDataTernaryOperator(false);
680 template<typename T
> bool CheckStr(const wxString
& expected
, T s
)
682 return expected
== wxString(s
);
685 void StringTestCase::DoCStrDataTernaryOperator(bool cond
)
687 // test compilation of wxCStrData when used with operator?: (the asserts
688 // are not very important, we're testing if the code compiles at all):
692 const wchar_t *wcStr
= L
"foo";
693 CPPUNIT_ASSERT( CheckStr(s
, (cond
? s
.c_str() : wcStr
)) );
694 CPPUNIT_ASSERT( CheckStr(s
, (cond
? s
.c_str() : L
"foo")) );
695 CPPUNIT_ASSERT( CheckStr(s
, (cond
? wcStr
: s
.c_str())) );
696 CPPUNIT_ASSERT( CheckStr(s
, (cond
? L
"foo" : s
.c_str())) );
698 const char *mbStr
= "foo";
699 CPPUNIT_ASSERT( CheckStr(s
, (cond
? s
.c_str() : mbStr
)) );
700 CPPUNIT_ASSERT( CheckStr(s
, (cond
? s
.c_str() : "foo")) );
701 CPPUNIT_ASSERT( CheckStr(s
, (cond
? mbStr
: s
.c_str())) );
702 CPPUNIT_ASSERT( CheckStr(s
, (cond
? "foo" : s
.c_str())) );
705 CPPUNIT_ASSERT( CheckStr(empty
, (cond
? empty
.c_str() : wxEmptyString
)) );
706 CPPUNIT_ASSERT( CheckStr(empty
, (cond
? wxEmptyString
: empty
.c_str())) );
709 void StringTestCase::CStrDataOperators()
713 CPPUNIT_ASSERT( s
.c_str()[0] == 'h' );
714 CPPUNIT_ASSERT( s
.c_str()[1] == 'e' );
715 CPPUNIT_ASSERT( s
.c_str()[5] == '\0' );
717 CPPUNIT_ASSERT( *s
.c_str() == 'h' );
718 CPPUNIT_ASSERT( *(s
.c_str() + 2) == 'l' );
719 CPPUNIT_ASSERT( *(s
.c_str() + 5) == '\0' );
722 bool CheckStrChar(const wxString
& expected
, char *s
)
723 { return CheckStr(expected
, s
); }
724 bool CheckStrWChar(const wxString
& expected
, wchar_t *s
)
725 { return CheckStr(expected
, s
); }
726 bool CheckStrConstChar(const wxString
& expected
, const char *s
)
727 { return CheckStr(expected
, s
); }
728 bool CheckStrConstWChar(const wxString
& expected
, const wchar_t *s
)
729 { return CheckStr(expected
, s
); }
731 void StringTestCase::CStrDataImplicitConversion()
735 CPPUNIT_ASSERT( CheckStrConstWChar(s
, s
.c_str()) );
736 CPPUNIT_ASSERT( CheckStrConstWChar(s
, s
) );
738 CPPUNIT_ASSERT( CheckStrConstChar(s
, s
.c_str()) );
739 CPPUNIT_ASSERT( CheckStrConstChar(s
, s
) );
742 void StringTestCase::ExplicitConversion()
746 CPPUNIT_ASSERT( CheckStr(s
, s
.mb_str()) );
747 CPPUNIT_ASSERT( CheckStrConstChar(s
, s
.mb_str()) );
748 CPPUNIT_ASSERT( CheckStrChar(s
, s
.char_str()) );
750 CPPUNIT_ASSERT( CheckStr(s
, s
.wc_str()) );
751 CPPUNIT_ASSERT( CheckStrConstWChar(s
, s
.wc_str()) );
752 CPPUNIT_ASSERT( CheckStrWChar(s
, s
.wchar_str()) );