]> git.saurik.com Git - wxWidgets.git/blob - tests/strings/strings.cpp
Tweaks for demos on MacOSX
[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 const wchar_t capital_ya[] = { 0x42f, 0 },
463 small_ya[] = { 0x44f, 0 };
464
465 wxString sUpper(wxConvLibc.cWC2MB(capital_ya)),
466 sLower(wxConvLibc.cWC2MB(small_ya));
467
468 CPPUNIT_ASSERT( sUpper.Lower() == sLower );
469 CPPUNIT_ASSERT( sLower.Upper() == sUpper );
470 }
471 #endif // !wxUSE_UNICODE
472 }
473
474 void StringTestCase::Compare()
475 {
476 wxString s1 = wxT("AHH");
477 wxString eq = wxT("AHH");
478 wxString neq1 = wxT("HAH");
479 wxString neq2 = wxT("AH");
480 wxString neq3 = wxT("AHHH");
481 wxString neq4 = wxT("AhH");
482
483 CPPUNIT_ASSERT( s1 == eq );
484 CPPUNIT_ASSERT( s1 != neq1 );
485 CPPUNIT_ASSERT( s1 != neq2 );
486 CPPUNIT_ASSERT( s1 != neq3 );
487 CPPUNIT_ASSERT( s1 != neq4 );
488
489 // wxString _s1 = wxT("A\0HH");
490 // wxString _eq = wxT("A\0HH");
491 // wxString _neq1 = wxT("H\0AH");
492 // wxString _neq2 = wxT("A\0H");
493 // wxString _neq3 = wxT("A\0HHH");
494 // wxString _neq4 = wxT("A\0hH");
495 s1.insert(1,1,'\0');
496 eq.insert(1,1,'\0');
497 neq1.insert(1,1,'\0');
498 neq2.insert(1,1,'\0');
499 neq3.insert(1,1,'\0');
500 neq4.insert(1,1,'\0');
501
502 CPPUNIT_ASSERT( s1 == eq );
503 CPPUNIT_ASSERT( s1 != neq1 );
504 CPPUNIT_ASSERT( s1 != neq2 );
505 CPPUNIT_ASSERT( s1 != neq3 );
506 CPPUNIT_ASSERT( s1 != neq4 );
507 }
508
509 void StringTestCase::CompareNoCase()
510 {
511 wxString s1 = wxT("AHH");
512 wxString eq = wxT("AHH");
513 wxString eq2 = wxT("AhH");
514 wxString eq3 = wxT("ahh");
515 wxString neq = wxT("HAH");
516 wxString neq2 = wxT("AH");
517 wxString neq3 = wxT("AHHH");
518
519 #define CPPUNIT_CNCEQ_ASSERT(s1, s2) CPPUNIT_ASSERT( s1.CmpNoCase(s2) == 0)
520 #define CPPUNIT_CNCNEQ_ASSERT(s1, s2) CPPUNIT_ASSERT( s1.CmpNoCase(s2) != 0)
521
522 CPPUNIT_CNCEQ_ASSERT( s1, eq );
523 CPPUNIT_CNCEQ_ASSERT( s1, eq2 );
524 CPPUNIT_CNCEQ_ASSERT( s1, eq3 );
525
526 CPPUNIT_CNCNEQ_ASSERT( s1, neq );
527 CPPUNIT_CNCNEQ_ASSERT( s1, neq2 );
528 CPPUNIT_CNCNEQ_ASSERT( s1, neq3 );
529
530
531 // wxString _s1 = wxT("A\0HH");
532 // wxString _eq = wxT("A\0HH");
533 // wxString _eq2 = wxT("A\0hH");
534 // wxString _eq3 = wxT("a\0hh");
535 // wxString _neq = wxT("H\0AH");
536 // wxString _neq2 = wxT("A\0H");
537 // wxString _neq3 = wxT("A\0HHH");
538
539 s1.insert(1,1,'\0');
540 eq.insert(1,1,'\0');
541 eq2.insert(1,1,'\0');
542 eq3.insert(1,1,'\0');
543 neq.insert(1,1,'\0');
544 neq2.insert(1,1,'\0');
545 neq3.insert(1,1,'\0');
546
547 CPPUNIT_CNCEQ_ASSERT( s1, eq );
548 CPPUNIT_CNCEQ_ASSERT( s1, eq2 );
549 CPPUNIT_CNCEQ_ASSERT( s1, eq3 );
550
551 CPPUNIT_CNCNEQ_ASSERT( s1, neq );
552 CPPUNIT_CNCNEQ_ASSERT( s1, neq2 );
553 CPPUNIT_CNCNEQ_ASSERT( s1, neq3 );
554 }
555
556 void StringTestCase::ToLong()
557 {
558 long l;
559 static const struct ToLongData
560 {
561 const wxChar *str;
562 long value;
563 bool ok;
564 } longData[] =
565 {
566 { _T("1"), 1, true },
567 { _T("0"), 0, true },
568 { _T("a"), 0, false },
569 { _T("12345"), 12345, true },
570 { _T("-1"), -1, true },
571 { _T("--1"), 0, false },
572 };
573
574 size_t n;
575 for ( n = 0; n < WXSIZEOF(longData); n++ )
576 {
577 const ToLongData& ld = longData[n];
578 CPPUNIT_ASSERT_EQUAL( ld.ok, wxString(ld.str).ToLong(&l) );
579 if ( ld.ok )
580 CPPUNIT_ASSERT_EQUAL( ld.value, l );
581 }
582 }
583
584 void StringTestCase::ToULong()
585 {
586 unsigned long ul;
587 static const struct ToULongData
588 {
589 const wxChar *str;
590 unsigned long value;
591 bool ok;
592 } ulongData[] =
593 {
594 { _T("1"), 1, true },
595 { _T("0"), 0, true },
596 { _T("a"), 0, false },
597 { _T("12345"), 12345, true },
598 // this is surprizing but consistent with strtoul() behaviour
599 { _T("-1"), ULONG_MAX, true },
600 };
601
602 size_t n;
603 for ( n = 0; n < WXSIZEOF(ulongData); n++ )
604 {
605 const ToULongData& uld = ulongData[n];
606 CPPUNIT_ASSERT_EQUAL( uld.ok, wxString(uld.str).ToULong(&ul) );
607 if ( uld.ok )
608 CPPUNIT_ASSERT_EQUAL( uld.value, ul );
609 }
610 }
611
612 void StringTestCase::ToDouble()
613 {
614 double d;
615 static const struct ToDoubleData
616 {
617 const wxChar *str;
618 double value;
619 bool ok;
620 } doubleData[] =
621 {
622 { _T("1"), 1, true },
623 { _T("1.23"), 1.23, true },
624 { _T(".1"), .1, true },
625 { _T("1."), 1, true },
626 { _T("1.."), 0, false },
627 { _T("0"), 0, true },
628 { _T("a"), 0, false },
629 { _T("12345"), 12345, true },
630 { _T("-1"), -1, true },
631 { _T("--1"), 0, false },
632 };
633
634 // we need to use decimal point, not comma or whatever is its value for the
635 // current locale
636 wxSetlocale(LC_ALL, _T("C"));
637
638 size_t n;
639 for ( n = 0; n < WXSIZEOF(doubleData); n++ )
640 {
641 const ToDoubleData& ld = doubleData[n];
642 CPPUNIT_ASSERT_EQUAL( ld.ok, wxString(ld.str).ToDouble(&d) );
643 if ( ld.ok )
644 CPPUNIT_ASSERT_EQUAL( ld.value, d );
645 }
646 }