]> git.saurik.com Git - wxWidgets.git/blob - tests/strings/strings.cpp
trick the sizer code into thinking that the wizard pages are shown so that it takes...
[wxWidgets.git] / tests / strings / strings.cpp
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 "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 StringTestCase : public CppUnit::TestCase
29 {
30 public:
31 StringTestCase();
32
33 private:
34 CPPUNIT_TEST_SUITE( StringTestCase );
35 CPPUNIT_TEST( String );
36 CPPUNIT_TEST( PChar );
37 CPPUNIT_TEST( Format );
38 CPPUNIT_TEST( Constructors );
39 #if wxUSE_WCHAR_T
40 CPPUNIT_TEST( ConstructorsWithConversion );
41 CPPUNIT_TEST( Conversion );
42 CPPUNIT_TEST( ConversionUTF7 );
43 CPPUNIT_TEST( ConversionUTF8 );
44 #endif // wxUSE_WCHAR_T
45 CPPUNIT_TEST( Extraction );
46 CPPUNIT_TEST( Find );
47 CPPUNIT_TEST( Replace );
48 CPPUNIT_TEST( Match );
49 CPPUNIT_TEST( CaseChanges );
50 CPPUNIT_TEST( Compare );
51 CPPUNIT_TEST( CompareNoCase );
52 CPPUNIT_TEST( ToLong );
53 CPPUNIT_TEST( ToULong );
54 CPPUNIT_TEST( ToDouble );
55 CPPUNIT_TEST_SUITE_END();
56
57 void String();
58 void PChar();
59 void Format();
60 void Constructors();
61 #if wxUSE_WCHAR_T
62 void ConstructorsWithConversion();
63 void Conversion();
64 void ConversionUTF7();
65 void ConversionUTF8();
66 #endif // wxUSE_WCHAR_T
67 void Extraction();
68 void Find();
69 void Replace();
70 void Match();
71 void CaseChanges();
72 void Compare();
73 void CompareNoCase();
74 void ToLong();
75 void ToULong();
76 void ToDouble();
77
78 #if wxUSE_WCHAR_T
79 // test if converting s using the given encoding gives ws and vice versa
80 //
81 // if either of the first 2 arguments is NULL, the conversion is supposed
82 // to fail
83 void DoTestConversion(const char *s, const wchar_t *w, wxCSConv& conv);
84 #endif // wxUSE_WCHAR_T
85
86 DECLARE_NO_COPY_CLASS(StringTestCase)
87 };
88
89 // register in the unnamed registry so that these tests are run by default
90 CPPUNIT_TEST_SUITE_REGISTRATION( StringTestCase );
91
92 // also include in it's own registry so that these tests can be run alone
93 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringTestCase, "StringTestCase" );
94
95 StringTestCase::StringTestCase()
96 {
97 }
98
99 void StringTestCase::String()
100 {
101 wxString a, b, c;
102
103 a.reserve (128);
104 b.reserve (128);
105 c.reserve (128);
106
107 for (int i = 0; i < 2; ++i)
108 {
109 a = _T("Hello");
110 b = _T(" world");
111 c = _T("! How'ya doin'?");
112 a += b;
113 a += c;
114 c = _T("Hello world! What's up?");
115 CPPUNIT_ASSERT( c != a );
116 }
117 }
118
119 void StringTestCase::PChar()
120 {
121 wxChar a [128];
122 wxChar b [128];
123 wxChar c [128];
124
125 for (int i = 0; i < 2; ++i)
126 {
127 wxStrcpy (a, _T("Hello"));
128 wxStrcpy (b, _T(" world"));
129 wxStrcpy (c, _T("! How'ya doin'?"));
130 wxStrcat (a, b);
131 wxStrcat (a, c);
132 wxStrcpy (c, _T("Hello world! What's up?"));
133 CPPUNIT_ASSERT( wxStrcmp (c, a) != 0 );
134 }
135 }
136
137 void StringTestCase::Format()
138 {
139 wxString s1,s2;
140 s1.Printf(_T("%03d"), 18);
141 CPPUNIT_ASSERT( s1 == wxString::Format(_T("%03d"), 18) );
142 s2.Printf(_T("Number 18: %s\n"), s1.c_str());
143 CPPUNIT_ASSERT( s2 == wxString::Format(_T("Number 18: %s\n"), s1.c_str()) );
144
145 static const size_t lengths[] = { 1, 512, 1024, 1025, 2048, 4096, 4097 };
146 for ( size_t n = 0; n < WXSIZEOF(lengths); n++ )
147 {
148 const size_t len = lengths[n];
149
150 wxString s(_T('Z'), len);
151 CPPUNIT_ASSERT_EQUAL( len, wxString::Format(_T("%s"), s.c_str()).length());
152 }
153 }
154
155 void StringTestCase::Constructors()
156 {
157 #define TEST_CTOR(args, res) \
158 { \
159 wxString s args ; \
160 CPPUNIT_ASSERT( s == res ); \
161 }
162
163 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
164 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
165 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
166
167 static const wxChar *s = _T("?really!");
168 const wxChar *start = wxStrchr(s, _T('r'));
169 const wxChar *end = wxStrchr(s, _T('!'));
170 TEST_CTOR((start, end), _T("really"));
171 }
172
173 #if wxUSE_WCHAR_T
174 void StringTestCase::ConstructorsWithConversion()
175 {
176 // the string "Déjà" in UTF-8 and wchar_t:
177 const unsigned char utf8Buf[] = {0x44,0xC3,0xA9,0x6A,0xC3,0xA0,0};
178 const wchar_t wchar[] = {0x44,0xE9,0x6A,0xE0,0};
179 const unsigned char utf8subBuf[] = {0x44,0xC3,0xA9,0x6A,0}; // just "Déj"
180 const char *utf8 = (char *)utf8Buf;
181 const char *utf8sub = (char *)utf8subBuf;
182
183 wxString s1(utf8, wxConvUTF8);
184 wxString s2(wchar, wxConvUTF8);
185
186 #if wxUSE_UNICODE
187 CPPUNIT_ASSERT( s1 == wchar );
188 CPPUNIT_ASSERT( s2 == wchar );
189 #else
190 CPPUNIT_ASSERT( s1 == utf8 );
191 CPPUNIT_ASSERT( s2 == utf8 );
192 #endif
193
194 wxString sub(utf8sub, wxConvUTF8); // "Dej" substring
195 wxString s3(utf8, wxConvUTF8, 4);
196 wxString s4(wchar, wxConvUTF8, 3);
197
198 CPPUNIT_ASSERT( s3 == sub );
199 CPPUNIT_ASSERT( s4 == sub );
200
201 #if wxUSE_UNICODE
202 CPPUNIT_ASSERT ( wxString("\t[pl]open.format.Sformatuj dyskietkê=gfloppy %f",
203 wxConvUTF8) == wxT("") ); //should stop at pos 35
204 #endif
205 }
206
207 void StringTestCase::Conversion()
208 {
209 #if wxUSE_UNICODE
210 wxString szTheString(L"The\0String", wxConvLibc, 10);
211 wxCharBuffer theBuffer = szTheString.mb_str();
212
213 CPPUNIT_ASSERT( memcmp(theBuffer.data(), "The\0String", 11) == 0 );
214
215 wxString szTheString2("The\0String", wxConvLocal, 10);
216 CPPUNIT_ASSERT( szTheString2.length() == 11 );
217 CPPUNIT_ASSERT( wxTmemcmp(szTheString2.c_str(), L"The\0String", 11) == 0 );
218 #else
219 wxString szTheString(wxT("TheString"));
220 szTheString.insert(3, 1, '\0');
221 wxWCharBuffer theBuffer = szTheString.wc_str(wxConvLibc);
222
223 CPPUNIT_ASSERT( memcmp(theBuffer.data(), L"The\0String", 11 * sizeof(wchar_t)) == 0 );
224
225 wxString szLocalTheString(wxT("TheString"));
226 szLocalTheString.insert(3, 1, '\0');
227 wxWCharBuffer theLocalBuffer = szLocalTheString.wc_str(wxConvLocal);
228
229 CPPUNIT_ASSERT( memcmp(theLocalBuffer.data(), L"The\0String", 11 * sizeof(wchar_t)) == 0 );
230 #endif
231 }
232
233 #if !wxUSE_UNICODE
234 // in case wcscmp is missing
235 //
236 static int wx_wcscmp(const wchar_t *s1, const wchar_t *s2)
237 {
238 while (*s1 == *s2 && *s1 != 0)
239 {
240 s1++;
241 s2++;
242 }
243 return *s1 - *s2;
244 }
245 #endif
246
247 void
248 StringTestCase::DoTestConversion(const char *s,
249 const wchar_t *ws,
250 wxCSConv& conv)
251 {
252 #if wxUSE_UNICODE
253 if ( ws )
254 {
255 wxCharBuffer buf(wxString(ws).mb_str(conv));
256
257 CPPUNIT_ASSERT( strcmp(buf, s) == 0 );
258 }
259 #else // wxUSE_UNICODE
260 if ( s )
261 {
262 wxWCharBuffer wbuf(wxString(s).wc_str(conv));
263
264 if ( ws )
265 CPPUNIT_ASSERT( wx_wcscmp(wbuf, ws) == 0 );
266 else
267 CPPUNIT_ASSERT( !*wbuf );
268 }
269 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
270 }
271
272 struct StringConversionData
273 {
274 const char *str;
275 const wchar_t *wcs;
276 };
277
278 void StringTestCase::ConversionUTF7()
279 {
280 static const StringConversionData utf7data[] =
281 {
282 { "+-", L"+" },
283 { "+--", L"+-" },
284 //\u isn't recognized on MSVC 6
285 #if !defined(_MSC_VER)
286 #if !defined(__GNUC__) || (__GNUC__ >= 3)
287 { "+AKM-", L"\u00a3" },
288 #endif
289 #endif
290 // Windows accepts invalid UTF-7 strings and so does our UTF-7
291 // conversion code -- this is wrong IMO but the way it is for now
292 //
293 // notice that converting "+" still behaves as expected because the
294 // result is just an empty string, i.e. the same as if there were an
295 // error, but converting "a+" results in "a" while it really should
296 // fail
297 { "+", NULL },
298 { "a+", L"a" },
299 };
300
301 wxCSConv conv(_T("utf-7"));
302 for ( size_t n = 0; n < WXSIZEOF(utf7data); n++ )
303 {
304 const StringConversionData& d = utf7data[n];
305 DoTestConversion(d.str, d.wcs, conv);
306 }
307 }
308
309 void StringTestCase::ConversionUTF8()
310 {
311 static const StringConversionData utf8data[] =
312 {
313 //\u isn't recognized on MSVC 6
314 #if !defined(_MSC_VER)
315 #if !defined(__GNUC__) || (__GNUC__ >= 3)
316 { "\xc2\xa3", L"\u00a3" },
317 #endif
318 #endif
319 { "\xc2", NULL },
320 };
321
322 wxCSConv conv(_T("utf-8"));
323 for ( size_t n = 0; n < WXSIZEOF(utf8data); n++ )
324 {
325 const StringConversionData& d = utf8data[n];
326 DoTestConversion(d.str, d.wcs, conv);
327 }
328 }
329
330 #endif // wxUSE_WCHAR_T
331
332
333 void StringTestCase::Extraction()
334 {
335 wxString s(_T("Hello, world!"));
336
337 CPPUNIT_ASSERT( wxStrcmp( s.c_str() , _T("Hello, world!") ) == 0 );
338 CPPUNIT_ASSERT( wxStrcmp( s.Left(5).c_str() , _T("Hello") ) == 0 );
339 CPPUNIT_ASSERT( wxStrcmp( s.Right(6).c_str() , _T("world!") ) == 0 );
340 CPPUNIT_ASSERT( wxStrcmp( s(3, 5).c_str() , _T("lo, w") ) == 0 );
341 CPPUNIT_ASSERT( wxStrcmp( s.Mid(3).c_str() , _T("lo, world!") ) == 0 );
342 CPPUNIT_ASSERT( wxStrcmp( s.substr(3, 5).c_str() , _T("lo, w") ) == 0 );
343 CPPUNIT_ASSERT( wxStrcmp( s.substr(3).c_str() , _T("lo, world!") ) == 0 );
344
345 wxString rest;
346
347 #define TEST_STARTS_WITH( prefix , correct_rest, result ) \
348 CPPUNIT_ASSERT( \
349 ( s.StartsWith( prefix, &rest ) == result ) && \
350 ( ( result == false ) || ( wxStrcmp( correct_rest , rest ) == 0 ) ) \
351 )
352
353 TEST_STARTS_WITH( _T("Hello"), _T(", world!"), true );
354 TEST_STARTS_WITH( _T("Hello, "), _T("world!"), true );
355 TEST_STARTS_WITH( _T("Hello, world!"), _T(""), true );
356 TEST_STARTS_WITH( _T("Hello, world!!!"), _T(""), false );
357 TEST_STARTS_WITH( _T(""), _T("Hello, world!"), true );
358 TEST_STARTS_WITH( _T("Goodbye"), _T(""), false );
359 TEST_STARTS_WITH( _T("Hi"), _T(""), false );
360
361 #undef TEST_STARTS_WITH
362 }
363
364 void StringTestCase::Find()
365 {
366 #define TEST_FIND( str , start , result ) \
367 CPPUNIT_ASSERT( wxString(str).find(_T("ell"), start) == result );
368
369 TEST_FIND( _T("Well, hello world"), 0, 1 );
370 TEST_FIND( _T("Well, hello world"), 6, 7 );
371 TEST_FIND( _T("Well, hello world"), 9, wxString::npos );
372
373 #undef TEST_FIND
374 }
375
376 void StringTestCase::Replace()
377 {
378 #define TEST_REPLACE( original , pos , len , replacement , result ) \
379 { \
380 wxString s = original; \
381 s.replace( pos , len , replacement ); \
382 CPPUNIT_ASSERT( s == result ); \
383 }
384
385 TEST_REPLACE( _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") );
386 TEST_REPLACE( _T("increase"), 0, 2, _T("de"), _T("decrease") );
387 TEST_REPLACE( _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") );
388 TEST_REPLACE( _T("foobar"), 3, 0, _T("-"), _T("foo-bar") );
389 TEST_REPLACE( _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") );
390
391
392 #define TEST_NULLCHARREPLACE( o , olen, pos , len , replacement , r, rlen ) \
393 { \
394 wxString s(o,olen); \
395 s.replace( pos , len , replacement ); \
396 CPPUNIT_ASSERT( s == wxString(r,rlen) ); \
397 }
398
399 TEST_NULLCHARREPLACE( _T("null\0char"), 9, 5, 1, _T("d"),
400 _T("null\0dhar"), 9 );
401
402 #define TEST_WXREPLACE( o , olen, olds, news, all, r, rlen ) \
403 { \
404 wxString s(o,olen); \
405 s.Replace( olds, news, all ); \
406 CPPUNIT_ASSERT( s == wxString(r,rlen) ); \
407 }
408
409 TEST_WXREPLACE( _T("null\0char"), 9, _T("c"), _T("de"), true,
410 _T("null\0dehar"), 10 );
411
412 TEST_WXREPLACE( _T("null\0dehar"), 10, _T("de"), _T("c"), true,
413 _T("null\0char"), 9 );
414
415 #undef TEST_WXREPLACE
416 #undef TEST_NULLCHARREPLACE
417 #undef TEST_REPLACE
418 }
419
420 void StringTestCase::Match()
421 {
422 #define TEST_MATCH( s1 , s2 , result ) \
423 CPPUNIT_ASSERT( wxString(s1).Matches(s2) == result )
424
425 TEST_MATCH( _T("foobar"), _T("foo*"), true );
426 TEST_MATCH( _T("foobar"), _T("*oo*"), true );
427 TEST_MATCH( _T("foobar"), _T("*bar"), true );
428 TEST_MATCH( _T("foobar"), _T("??????"), true );
429 TEST_MATCH( _T("foobar"), _T("f??b*"), true );
430 TEST_MATCH( _T("foobar"), _T("f?b*"), false );
431 TEST_MATCH( _T("foobar"), _T("*goo*"), false );
432 TEST_MATCH( _T("foobar"), _T("*foo"), false );
433 TEST_MATCH( _T("foobarfoo"), _T("*foo"), true );
434 TEST_MATCH( _T(""), _T("*"), true );
435 TEST_MATCH( _T(""), _T("?"), false );
436
437 #undef TEST_MATCH
438 }
439
440
441 void StringTestCase::CaseChanges()
442 {
443 wxString s1(_T("Hello!"));
444 wxString s1u(s1);
445 wxString s1l(s1);
446 s1u.MakeUpper();
447 s1l.MakeLower();
448 wxString s2u, s2l;
449 s2u.MakeUpper();
450 s2l.MakeLower();
451
452 CPPUNIT_ASSERT( s1u == _T("HELLO!") );
453 CPPUNIT_ASSERT( s1l == _T("hello!") );
454 CPPUNIT_ASSERT( s2u == wxEmptyString );
455 CPPUNIT_ASSERT( s2l == wxEmptyString );
456
457 #if !wxUSE_UNICODE
458 wxLocale locRu(wxLANGUAGE_RUSSIAN, 0 /* flags */);
459 if ( locRu.IsOk() )
460 {
461 // try upper casing 8bit strings
462 wxString sUpper("\xdf"),
463 sLower("\xff");
464
465 CPPUNIT_ASSERT( sUpper.Lower() == sLower );
466 CPPUNIT_ASSERT( sLower.Upper() == sUpper );
467 }
468 #endif // !wxUSE_UNICODE
469 }
470
471 void StringTestCase::Compare()
472 {
473 wxString s1 = wxT("AHH");
474 wxString eq = wxT("AHH");
475 wxString neq1 = wxT("HAH");
476 wxString neq2 = wxT("AH");
477 wxString neq3 = wxT("AHHH");
478 wxString neq4 = wxT("AhH");
479
480 CPPUNIT_ASSERT( s1 == eq );
481 CPPUNIT_ASSERT( s1 != neq1 );
482 CPPUNIT_ASSERT( s1 != neq2 );
483 CPPUNIT_ASSERT( s1 != neq3 );
484 CPPUNIT_ASSERT( s1 != neq4 );
485
486 // wxString _s1 = wxT("A\0HH");
487 // wxString _eq = wxT("A\0HH");
488 // wxString _neq1 = wxT("H\0AH");
489 // wxString _neq2 = wxT("A\0H");
490 // wxString _neq3 = wxT("A\0HHH");
491 // wxString _neq4 = wxT("A\0hH");
492 s1.insert(1,1,'\0');
493 eq.insert(1,1,'\0');
494 neq1.insert(1,1,'\0');
495 neq2.insert(1,1,'\0');
496 neq3.insert(1,1,'\0');
497 neq4.insert(1,1,'\0');
498
499 CPPUNIT_ASSERT( s1 == eq );
500 CPPUNIT_ASSERT( s1 != neq1 );
501 CPPUNIT_ASSERT( s1 != neq2 );
502 CPPUNIT_ASSERT( s1 != neq3 );
503 CPPUNIT_ASSERT( s1 != neq4 );
504 }
505
506 void StringTestCase::CompareNoCase()
507 {
508 wxString s1 = wxT("AHH");
509 wxString eq = wxT("AHH");
510 wxString eq2 = wxT("AhH");
511 wxString eq3 = wxT("ahh");
512 wxString neq = wxT("HAH");
513 wxString neq2 = wxT("AH");
514 wxString neq3 = wxT("AHHH");
515
516 #define CPPUNIT_CNCEQ_ASSERT(s1, s2) CPPUNIT_ASSERT( s1.CmpNoCase(s2) == 0)
517 #define CPPUNIT_CNCNEQ_ASSERT(s1, s2) CPPUNIT_ASSERT( s1.CmpNoCase(s2) != 0)
518
519 CPPUNIT_CNCEQ_ASSERT( s1, eq );
520 CPPUNIT_CNCEQ_ASSERT( s1, eq2 );
521 CPPUNIT_CNCEQ_ASSERT( s1, eq3 );
522
523 CPPUNIT_CNCNEQ_ASSERT( s1, neq );
524 CPPUNIT_CNCNEQ_ASSERT( s1, neq2 );
525 CPPUNIT_CNCNEQ_ASSERT( s1, neq3 );
526
527
528 // wxString _s1 = wxT("A\0HH");
529 // wxString _eq = wxT("A\0HH");
530 // wxString _eq2 = wxT("A\0hH");
531 // wxString _eq3 = wxT("a\0hh");
532 // wxString _neq = wxT("H\0AH");
533 // wxString _neq2 = wxT("A\0H");
534 // wxString _neq3 = wxT("A\0HHH");
535
536 s1.insert(1,1,'\0');
537 eq.insert(1,1,'\0');
538 eq2.insert(1,1,'\0');
539 eq3.insert(1,1,'\0');
540 neq.insert(1,1,'\0');
541 neq2.insert(1,1,'\0');
542 neq3.insert(1,1,'\0');
543
544 CPPUNIT_CNCEQ_ASSERT( s1, eq );
545 CPPUNIT_CNCEQ_ASSERT( s1, eq2 );
546 CPPUNIT_CNCEQ_ASSERT( s1, eq3 );
547
548 CPPUNIT_CNCNEQ_ASSERT( s1, neq );
549 CPPUNIT_CNCNEQ_ASSERT( s1, neq2 );
550 CPPUNIT_CNCNEQ_ASSERT( s1, neq3 );
551 }
552
553 void StringTestCase::ToLong()
554 {
555 long l;
556 static const struct ToLongData
557 {
558 const wxChar *str;
559 long value;
560 bool ok;
561 } longData[] =
562 {
563 { _T("1"), 1, true },
564 { _T("0"), 0, true },
565 { _T("a"), 0, false },
566 { _T("12345"), 12345, true },
567 { _T("-1"), -1, true },
568 { _T("--1"), 0, false },
569 };
570
571 size_t n;
572 for ( n = 0; n < WXSIZEOF(longData); n++ )
573 {
574 const ToLongData& ld = longData[n];
575 CPPUNIT_ASSERT_EQUAL( ld.ok, wxString(ld.str).ToLong(&l) );
576 if ( ld.ok )
577 CPPUNIT_ASSERT_EQUAL( ld.value, l );
578 }
579 }
580
581 void StringTestCase::ToULong()
582 {
583 unsigned long ul;
584 static const struct ToULongData
585 {
586 const wxChar *str;
587 unsigned long value;
588 bool ok;
589 } ulongData[] =
590 {
591 { _T("1"), 1, true },
592 { _T("0"), 0, true },
593 { _T("a"), 0, false },
594 { _T("12345"), 12345, true },
595 // this is surprizing but consistent with strtoul() behaviour
596 { _T("-1"), ULONG_MAX, true },
597 };
598
599 size_t n;
600 for ( n = 0; n < WXSIZEOF(ulongData); n++ )
601 {
602 const ToULongData& uld = ulongData[n];
603 CPPUNIT_ASSERT_EQUAL( uld.ok, wxString(uld.str).ToULong(&ul) );
604 if ( uld.ok )
605 CPPUNIT_ASSERT_EQUAL( uld.value, ul );
606 }
607 }
608
609 void StringTestCase::ToDouble()
610 {
611 double d;
612 static const struct ToDoubleData
613 {
614 const wxChar *str;
615 double value;
616 bool ok;
617 } doubleData[] =
618 {
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 },
629 };
630
631 // we need to use decimal point, not comma or whatever is its value for the
632 // current locale
633 wxSetlocale(LC_ALL, _T("C"));
634
635 size_t n;
636 for ( n = 0; n < WXSIZEOF(doubleData); n++ )
637 {
638 const ToDoubleData& ld = doubleData[n];
639 CPPUNIT_ASSERT_EQUAL( ld.ok, wxString(ld.str).ToDouble(&d) );
640 if ( ld.ok )
641 CPPUNIT_ASSERT_EQUAL( ld.value, d );
642 }
643 }