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( CStrDataImplicitConversion
);
58 CPPUNIT_TEST( ExplicitConversion
);
59 CPPUNIT_TEST_SUITE_END();
79 #endif // wxLongLong_t
82 void CStrDataTernaryOperator();
83 void DoCStrDataTernaryOperator(bool cond
);
84 void CStrDataImplicitConversion();
85 void ExplicitConversion();
87 DECLARE_NO_COPY_CLASS(StringTestCase
)
90 // register in the unnamed registry so that these tests are run by default
91 CPPUNIT_TEST_SUITE_REGISTRATION( StringTestCase
);
93 // also include in it's own registry so that these tests can be run alone
94 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringTestCase
, "StringTestCase" );
96 StringTestCase::StringTestCase()
100 void StringTestCase::String()
108 for (int i
= 0; i
< 2; ++i
)
112 c
= _T("! How'ya doin'?");
115 c
= _T("Hello world! What's up?");
116 CPPUNIT_ASSERT( c
!= a
);
120 void StringTestCase::PChar()
126 for (int i
= 0; i
< 2; ++i
)
128 wxStrcpy (a
, _T("Hello"));
129 wxStrcpy (b
, _T(" world"));
130 wxStrcpy (c
, _T("! How'ya doin'?"));
133 wxStrcpy (c
, _T("Hello world! What's up?"));
134 CPPUNIT_ASSERT( wxStrcmp (c
, a
) != 0 );
138 void StringTestCase::Format()
141 s1
.Printf(_T("%03d"), 18);
142 CPPUNIT_ASSERT( s1
== wxString::Format(_T("%03d"), 18) );
143 s2
.Printf(_T("Number 18: %s\n"), s1
.c_str());
144 CPPUNIT_ASSERT( s2
== wxString::Format(_T("Number 18: %s\n"), s1
.c_str()) );
146 static const size_t lengths
[] = { 1, 512, 1024, 1025, 2048, 4096, 4097 };
147 for ( size_t n
= 0; n
< WXSIZEOF(lengths
); n
++ )
149 const size_t len
= lengths
[n
];
151 wxString
s(_T('Z'), len
);
152 CPPUNIT_ASSERT_EQUAL( len
, wxString::Format(_T("%s"), s
.c_str()).length());
156 void StringTestCase::Constructors()
158 #define TEST_CTOR(args, res) \
161 CPPUNIT_ASSERT( s == res ); \
164 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
165 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
166 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
168 static const wxChar
*s
= _T("?really!");
169 const wxChar
*start
= wxStrchr(s
, _T('r'));
170 const wxChar
*end
= wxStrchr(s
, _T('!'));
171 TEST_CTOR((start
, end
), _T("really"));
175 void StringTestCase::Extraction()
177 wxString
s(_T("Hello, world!"));
179 CPPUNIT_ASSERT( wxStrcmp( s
.c_str() , _T("Hello, world!") ) == 0 );
180 CPPUNIT_ASSERT( wxStrcmp( s
.Left(5).c_str() , _T("Hello") ) == 0 );
181 CPPUNIT_ASSERT( wxStrcmp( s
.Right(6).c_str() , _T("world!") ) == 0 );
182 CPPUNIT_ASSERT( wxStrcmp( s(3, 5).c_str() , _T("lo, w") ) == 0 );
183 CPPUNIT_ASSERT( wxStrcmp( s
.Mid(3).c_str() , _T("lo, world!") ) == 0 );
184 CPPUNIT_ASSERT( wxStrcmp( s
.substr(3, 5).c_str() , _T("lo, w") ) == 0 );
185 CPPUNIT_ASSERT( wxStrcmp( s
.substr(3).c_str() , _T("lo, world!") ) == 0 );
189 #define TEST_STARTS_WITH(prefix, correct_rest, result) \
190 CPPUNIT_ASSERT_EQUAL(result, s.StartsWith(prefix, &rest)); \
192 CPPUNIT_ASSERT_EQUAL(wxString(correct_rest), rest)
194 TEST_STARTS_WITH( _T("Hello"), _T(", world!"), true );
195 TEST_STARTS_WITH( _T("Hello, "), _T("world!"), true );
196 TEST_STARTS_WITH( _T("Hello, world!"), _T(""), true );
197 TEST_STARTS_WITH( _T("Hello, world!!!"), _T(""), false );
198 TEST_STARTS_WITH( _T(""), _T("Hello, world!"), true );
199 TEST_STARTS_WITH( _T("Goodbye"), _T(""), false );
200 TEST_STARTS_WITH( _T("Hi"), _T(""), false );
202 #undef TEST_STARTS_WITH
204 #define TEST_ENDS_WITH(suffix, correct_rest, result) \
205 CPPUNIT_ASSERT_EQUAL(result, s.EndsWith(suffix, &rest)); \
207 CPPUNIT_ASSERT_EQUAL(wxString(correct_rest), rest)
209 TEST_ENDS_WITH( _T(""), _T("Hello, world!"), true );
210 TEST_ENDS_WITH( _T("!"), _T("Hello, world"), true );
211 TEST_ENDS_WITH( _T(", world!"), _T("Hello"), true );
212 TEST_ENDS_WITH( _T("ello, world!"), _T("H"), true );
213 TEST_ENDS_WITH( _T("Hello, world!"), _T(""), true );
214 TEST_ENDS_WITH( _T("very long string"), _T(""), false );
215 TEST_ENDS_WITH( _T("?"), _T(""), false );
216 TEST_ENDS_WITH( _T("Hello, world"), _T(""), false );
217 TEST_ENDS_WITH( _T("Gello, world!"), _T(""), false );
219 #undef TEST_ENDS_WITH
222 void StringTestCase::Trim()
224 #define TEST_TRIM( str , dir , result ) \
225 CPPUNIT_ASSERT( wxString(str).Trim(dir) == result )
227 TEST_TRIM( _T(" Test "), true, _T(" Test") );
228 TEST_TRIM( _T(" "), true, _T("") );
229 TEST_TRIM( _T(" "), true, _T("") );
230 TEST_TRIM( _T(""), true, _T("") );
232 TEST_TRIM( _T(" Test "), false, _T("Test ") );
233 TEST_TRIM( _T(" "), false, _T("") );
234 TEST_TRIM( _T(" "), false, _T("") );
235 TEST_TRIM( _T(""), false, _T("") );
240 void StringTestCase::Find()
242 #define TEST_FIND( str , start , result ) \
243 CPPUNIT_ASSERT( wxString(str).find(_T("ell"), start) == result );
245 TEST_FIND( _T("Well, hello world"), 0, 1 );
246 TEST_FIND( _T("Well, hello world"), 6, 7 );
247 TEST_FIND( _T("Well, hello world"), 9, wxString::npos
);
252 void StringTestCase::Replace()
254 #define TEST_REPLACE( original , pos , len , replacement , result ) \
256 wxString s = original; \
257 s.replace( pos , len , replacement ); \
258 CPPUNIT_ASSERT( s == result ); \
261 TEST_REPLACE( _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") );
262 TEST_REPLACE( _T("increase"), 0, 2, _T("de"), _T("decrease") );
263 TEST_REPLACE( _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") );
264 TEST_REPLACE( _T("foobar"), 3, 0, _T("-"), _T("foo-bar") );
265 TEST_REPLACE( _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") );
268 #define TEST_NULLCHARREPLACE( o , olen, pos , len , replacement , r, rlen ) \
270 wxString s(o,olen); \
271 s.replace( pos , len , replacement ); \
272 CPPUNIT_ASSERT( s == wxString(r,rlen) ); \
275 TEST_NULLCHARREPLACE( _T("null\0char"), 9, 5, 1, _T("d"),
276 _T("null\0dhar"), 9 );
278 #define TEST_WXREPLACE( o , olen, olds, news, all, r, rlen ) \
280 wxString s(o,olen); \
281 s.Replace( olds, news, all ); \
282 CPPUNIT_ASSERT( s == wxString(r,rlen) ); \
285 TEST_WXREPLACE( _T("null\0char"), 9, _T("c"), _T("de"), true,
286 _T("null\0dehar"), 10 );
288 TEST_WXREPLACE( _T("null\0dehar"), 10, _T("de"), _T("c"), true,
289 _T("null\0char"), 9 );
291 #undef TEST_WXREPLACE
292 #undef TEST_NULLCHARREPLACE
296 void StringTestCase::Match()
298 #define TEST_MATCH( s1 , s2 , result ) \
299 CPPUNIT_ASSERT( wxString(s1).Matches(s2) == result )
301 TEST_MATCH( _T("foobar"), _T("foo*"), true );
302 TEST_MATCH( _T("foobar"), _T("*oo*"), true );
303 TEST_MATCH( _T("foobar"), _T("*bar"), true );
304 TEST_MATCH( _T("foobar"), _T("??????"), true );
305 TEST_MATCH( _T("foobar"), _T("f??b*"), true );
306 TEST_MATCH( _T("foobar"), _T("f?b*"), false );
307 TEST_MATCH( _T("foobar"), _T("*goo*"), false );
308 TEST_MATCH( _T("foobar"), _T("*foo"), false );
309 TEST_MATCH( _T("foobarfoo"), _T("*foo"), true );
310 TEST_MATCH( _T(""), _T("*"), true );
311 TEST_MATCH( _T(""), _T("?"), false );
317 void StringTestCase::CaseChanges()
319 wxString
s1(_T("Hello!"));
328 CPPUNIT_ASSERT( s1u
== _T("HELLO!") );
329 CPPUNIT_ASSERT( s1l
== _T("hello!") );
330 CPPUNIT_ASSERT( s2u
== wxEmptyString
);
331 CPPUNIT_ASSERT( s2l
== wxEmptyString
);
334 wxLocale
locRu(wxLANGUAGE_RUSSIAN
, 0 /* flags */);
337 // try upper casing 8bit strings
338 const wchar_t capital_ya
[] = { 0x42f, 0 },
339 small_ya
[] = { 0x44f, 0 };
341 wxString
sUpper(wxConvLibc
.cWC2MB(capital_ya
)),
342 sLower(wxConvLibc
.cWC2MB(small_ya
));
344 CPPUNIT_ASSERT( sUpper
.Lower() == sLower
);
345 CPPUNIT_ASSERT( sLower
.Upper() == sUpper
);
347 #endif // !wxUSE_UNICODE
350 void StringTestCase::Compare()
352 wxString s1
= wxT("AHH");
353 wxString eq
= wxT("AHH");
354 wxString neq1
= wxT("HAH");
355 wxString neq2
= wxT("AH");
356 wxString neq3
= wxT("AHHH");
357 wxString neq4
= wxT("AhH");
359 CPPUNIT_ASSERT( s1
== eq
);
360 CPPUNIT_ASSERT( s1
!= neq1
);
361 CPPUNIT_ASSERT( s1
!= neq2
);
362 CPPUNIT_ASSERT( s1
!= neq3
);
363 CPPUNIT_ASSERT( s1
!= neq4
);
365 CPPUNIT_ASSERT( s1
== wxT("AHH") );
366 CPPUNIT_ASSERT( s1
!= wxT("no") );
367 CPPUNIT_ASSERT( s1
< wxT("AZ") );
368 CPPUNIT_ASSERT( s1
<= wxT("AZ") );
369 CPPUNIT_ASSERT( s1
<= wxT("AHH") );
370 CPPUNIT_ASSERT( s1
> wxT("AA") );
371 CPPUNIT_ASSERT( s1
>= wxT("AA") );
372 CPPUNIT_ASSERT( s1
>= wxT("AHH") );
374 // test comparison with C strings in Unicode build (must work in ANSI as
376 CPPUNIT_ASSERT( s1
== "AHH" );
377 CPPUNIT_ASSERT( s1
!= "no" );
378 CPPUNIT_ASSERT( s1
< "AZ" );
379 CPPUNIT_ASSERT( s1
<= "AZ" );
380 CPPUNIT_ASSERT( s1
<= "AHH" );
381 CPPUNIT_ASSERT( s1
> "AA" );
382 CPPUNIT_ASSERT( s1
>= "AA" );
383 CPPUNIT_ASSERT( s1
>= "AHH" );
385 // wxString _s1 = wxT("A\0HH");
386 // wxString _eq = wxT("A\0HH");
387 // wxString _neq1 = wxT("H\0AH");
388 // wxString _neq2 = wxT("A\0H");
389 // wxString _neq3 = wxT("A\0HHH");
390 // wxString _neq4 = wxT("A\0hH");
393 neq1
.insert(1,1,'\0');
394 neq2
.insert(1,1,'\0');
395 neq3
.insert(1,1,'\0');
396 neq4
.insert(1,1,'\0');
398 CPPUNIT_ASSERT( s1
== eq
);
399 CPPUNIT_ASSERT( s1
!= neq1
);
400 CPPUNIT_ASSERT( s1
!= neq2
);
401 CPPUNIT_ASSERT( s1
!= neq3
);
402 CPPUNIT_ASSERT( s1
!= neq4
);
405 void StringTestCase::CompareNoCase()
407 wxString s1
= wxT("AHH");
408 wxString eq
= wxT("AHH");
409 wxString eq2
= wxT("AhH");
410 wxString eq3
= wxT("ahh");
411 wxString neq
= wxT("HAH");
412 wxString neq2
= wxT("AH");
413 wxString neq3
= wxT("AHHH");
415 #define CPPUNIT_CNCEQ_ASSERT(s1, s2) CPPUNIT_ASSERT( s1.CmpNoCase(s2) == 0)
416 #define CPPUNIT_CNCNEQ_ASSERT(s1, s2) CPPUNIT_ASSERT( s1.CmpNoCase(s2) != 0)
418 CPPUNIT_CNCEQ_ASSERT( s1
, eq
);
419 CPPUNIT_CNCEQ_ASSERT( s1
, eq2
);
420 CPPUNIT_CNCEQ_ASSERT( s1
, eq3
);
422 CPPUNIT_CNCNEQ_ASSERT( s1
, neq
);
423 CPPUNIT_CNCNEQ_ASSERT( s1
, neq2
);
424 CPPUNIT_CNCNEQ_ASSERT( s1
, neq3
);
427 // wxString _s1 = wxT("A\0HH");
428 // wxString _eq = wxT("A\0HH");
429 // wxString _eq2 = wxT("A\0hH");
430 // wxString _eq3 = wxT("a\0hh");
431 // wxString _neq = wxT("H\0AH");
432 // wxString _neq2 = wxT("A\0H");
433 // wxString _neq3 = wxT("A\0HHH");
437 eq2
.insert(1,1,'\0');
438 eq3
.insert(1,1,'\0');
439 neq
.insert(1,1,'\0');
440 neq2
.insert(1,1,'\0');
441 neq3
.insert(1,1,'\0');
443 CPPUNIT_CNCEQ_ASSERT( s1
, eq
);
444 CPPUNIT_CNCEQ_ASSERT( s1
, eq2
);
445 CPPUNIT_CNCEQ_ASSERT( s1
, eq3
);
447 CPPUNIT_CNCNEQ_ASSERT( s1
, neq
);
448 CPPUNIT_CNCNEQ_ASSERT( s1
, neq2
);
449 CPPUNIT_CNCNEQ_ASSERT( s1
, neq3
);
452 void StringTestCase::Contains()
454 static const struct ContainsData
457 const wxChar
*needle
;
461 { _T(""), _T(""), true },
462 { _T(""), _T("foo"), false },
463 { _T("foo"), _T(""), true },
464 { _T("foo"), _T("f"), true },
465 { _T("foo"), _T("o"), true },
466 { _T("foo"), _T("oo"), true },
467 { _T("foo"), _T("ooo"), false },
468 { _T("foo"), _T("oooo"), false },
469 { _T("foo"), _T("fooo"), false },
472 for ( size_t n
= 0; n
< WXSIZEOF(containsData
); n
++ )
474 const ContainsData
& cd
= containsData
[n
];
475 CPPUNIT_ASSERT_EQUAL( cd
.contains
, wxString(cd
.hay
).Contains(cd
.needle
) );
479 // flags used in ToLongData.flags
484 Number_Unsigned
= 2, // if not specified, works for signed conversion
485 Number_Signed
= 4, // if not specified, works for unsigned
486 Number_LongLong
= 8, // only for long long tests
487 Number_Long
= 16, // only for long tests
490 static const struct ToLongData
497 #endif // wxLongLong_t
500 long LValue() const { return value
; }
501 unsigned long ULValue() const { return value
; }
503 wxLongLong_t
LLValue() const { return value
; }
504 wxULongLong_t
ULLValue() const { return (wxULongLong_t
)value
; }
505 #endif // wxLongLong_t
507 bool IsOk() const { return !(flags
& Number_Invalid
); }
510 { _T("1"), 1, Number_Ok
},
511 { _T("0"), 0, Number_Ok
},
512 { _T("a"), 0, Number_Invalid
},
513 { _T("12345"), 12345, Number_Ok
},
514 { _T("--1"), 0, Number_Invalid
},
516 { _T("-1"), -1, Number_Signed
| Number_Long
},
517 // this is surprizing but consistent with strtoul() behaviour
518 { _T("-1"), ULONG_MAX
, Number_Unsigned
| Number_Long
},
520 // this must overflow, even with 64 bit long
521 { _T("922337203685477580711"), 0, Number_Invalid
},
524 { _T("2147483648"), wxLL(2147483648), Number_LongLong
},
525 { _T("-2147483648"), wxLL(-2147483648), Number_LongLong
| Number_Signed
},
526 { _T("9223372036854775808"), wxULL(9223372036854775808), Number_LongLong
|
528 #endif // wxLongLong_t
531 void StringTestCase::ToLong()
534 for ( size_t n
= 0; n
< WXSIZEOF(longData
); n
++ )
536 const ToLongData
& ld
= longData
[n
];
538 if ( ld
.flags
& (Number_LongLong
| Number_Unsigned
) )
541 CPPUNIT_ASSERT_EQUAL( ld
.IsOk(), wxString(ld
.str
).ToLong(&l
) );
543 CPPUNIT_ASSERT_EQUAL( ld
.LValue(), l
);
547 void StringTestCase::ToULong()
550 for ( size_t n
= 0; n
< WXSIZEOF(longData
); n
++ )
552 const ToLongData
& ld
= longData
[n
];
554 if ( ld
.flags
& (Number_LongLong
| Number_Signed
) )
557 CPPUNIT_ASSERT_EQUAL( ld
.IsOk(), wxString(ld
.str
).ToULong(&ul
) );
559 CPPUNIT_ASSERT_EQUAL( ld
.ULValue(), ul
);
565 void StringTestCase::ToLongLong()
568 for ( size_t n
= 0; n
< WXSIZEOF(longData
); n
++ )
570 const ToLongData
& ld
= longData
[n
];
572 if ( ld
.flags
& (Number_Long
| Number_Unsigned
) )
575 CPPUNIT_ASSERT_EQUAL( ld
.IsOk(), wxString(ld
.str
).ToLongLong(&l
) );
577 CPPUNIT_ASSERT_EQUAL( ld
.LLValue(), l
);
581 void StringTestCase::ToULongLong()
584 for ( size_t n
= 0; n
< WXSIZEOF(longData
); n
++ )
586 const ToLongData
& ld
= longData
[n
];
588 if ( ld
.flags
& (Number_Long
| Number_Signed
) )
591 CPPUNIT_ASSERT_EQUAL( ld
.IsOk(), wxString(ld
.str
).ToULongLong(&ul
) );
593 CPPUNIT_ASSERT_EQUAL( ld
.ULLValue(), ul
);
597 #endif // wxLongLong_t
599 void StringTestCase::ToDouble()
602 static const struct ToDoubleData
609 { _T("1"), 1, true },
610 { _T("1.23"), 1.23, true },
611 { _T(".1"), .1, true },
612 { _T("1."), 1, true },
613 { _T("1.."), 0, false },
614 { _T("0"), 0, true },
615 { _T("a"), 0, false },
616 { _T("12345"), 12345, true },
617 { _T("-1"), -1, true },
618 { _T("--1"), 0, false },
621 // we need to use decimal point, not comma or whatever is its value for the
623 wxSetlocale(LC_ALL
, _T("C"));
626 for ( n
= 0; n
< WXSIZEOF(doubleData
); n
++ )
628 const ToDoubleData
& ld
= doubleData
[n
];
629 CPPUNIT_ASSERT_EQUAL( ld
.ok
, wxString(ld
.str
).ToDouble(&d
) );
631 CPPUNIT_ASSERT_EQUAL( ld
.value
, d
);
635 void StringTestCase::WriteBuf()
638 wxStrcpy(wxStringBuffer(s
, 10), _T("foo"));
640 CPPUNIT_ASSERT(s
[0u] == _T('f') );
641 CPPUNIT_ASSERT(_T('f') == s
[0u]);
642 CPPUNIT_ASSERT(_T('o') == s
[1]);
643 CPPUNIT_ASSERT(_T('o') == s
[2]);
644 CPPUNIT_ASSERT_EQUAL((size_t)3, s
.length());
648 wxStringBufferLength
buf(s
, 10);
649 wxStrcpy(buf
, _T("barrbaz"));
653 CPPUNIT_ASSERT(_T('b') == s
[0u]);
654 CPPUNIT_ASSERT(_T('a') == s
[1]);
655 CPPUNIT_ASSERT(_T('r') == s
[2]);
656 CPPUNIT_ASSERT(_T('r') == s
[3]);
657 CPPUNIT_ASSERT_EQUAL((size_t)4, s
.length());
659 CPPUNIT_ASSERT_EQUAL( 0, wxStrcmp(_T("barr"), s
) );
664 void StringTestCase::CStrDataTernaryOperator()
666 DoCStrDataTernaryOperator(true);
667 DoCStrDataTernaryOperator(false);
670 template<typename T
> bool CheckStr(const wxString
& expected
, T s
)
672 return expected
== wxString(s
);
675 void StringTestCase::DoCStrDataTernaryOperator(bool cond
)
677 // test compilation of wxCStrData when used with operator?: (the asserts
678 // are not very important, we're testing if the code compiles at all):
681 const char *mbStr
= "foo";
682 const wchar_t *wcStr
= L
"foo";
684 // FIXME-UTF8: when wxCStrData can handle both conversions, this should
685 // be changed to always test all versions, both MB and WC
687 CPPUNIT_ASSERT( CheckStr(s
, (cond
? s
.c_str() : wcStr
)) );
688 CPPUNIT_ASSERT( CheckStr(s
, (cond
? s
.c_str() : L
"bar")) );
689 CPPUNIT_ASSERT( CheckStr(s
, (cond
? wcStr
: s
.c_str())) );
690 CPPUNIT_ASSERT( CheckStr(s
, (cond
? L
"bar" : s
.c_str())) );
692 CPPUNIT_ASSERT( CheckStr(s
, (cond
? s
.c_str() : mbStr
)) );
693 CPPUNIT_ASSERT( CheckStr(s
, (cond
? s
.c_str() : "foo")) );
694 CPPUNIT_ASSERT( CheckStr(s
, (cond
? mbStr
: s
.c_str())) );
695 CPPUNIT_ASSERT( CheckStr(s
, (cond
? "foo" : s
.c_str())) );
699 CPPUNIT_ASSERT( CheckStr(empty
, (cond
? empty
.c_str() : wxEmptyString
)) );
700 CPPUNIT_ASSERT( CheckStr(empty
, (cond
? wxEmptyString
: empty
.c_str())) );
703 bool CheckStrChar(const wxString
& expected
, char *s
)
704 { return CheckStr(expected
, s
); }
705 bool CheckStrWChar(const wxString
& expected
, wchar_t *s
)
706 { return CheckStr(expected
, s
); }
707 bool CheckStrConstChar(const wxString
& expected
, const char *s
)
708 { return CheckStr(expected
, s
); }
709 bool CheckStrConstWChar(const wxString
& expected
, const wchar_t *s
)
710 { return CheckStr(expected
, s
); }
712 void StringTestCase::CStrDataImplicitConversion()
716 // FIXME-UTF8: when wxCStrData can handle both conversions, this should
717 // be changed to always test all versions, both MB and WC
719 CPPUNIT_ASSERT( CheckStrConstWChar(s
, s
.c_str()) );
720 CPPUNIT_ASSERT( CheckStrConstWChar(s
, s
) );
722 CPPUNIT_ASSERT( CheckStrConstChar(s
, s
.c_str()) );
723 CPPUNIT_ASSERT( CheckStrConstChar(s
, s
) );
727 void StringTestCase::ExplicitConversion()
731 CPPUNIT_ASSERT( CheckStr(s
, s
.mb_str()) );
732 CPPUNIT_ASSERT( CheckStrConstChar(s
, s
.mb_str()) );
733 CPPUNIT_ASSERT( CheckStrChar(s
, s
.char_str()) );
735 CPPUNIT_ASSERT( CheckStr(s
, s
.wc_str()) );
736 CPPUNIT_ASSERT( CheckStrConstWChar(s
, s
.wc_str()) );
737 CPPUNIT_ASSERT( CheckStrWChar(s
, s
.wchar_str()) );