X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1a39b0131f93b24c1fb89668170b212430a42c3a..3d9bff2f13c7fe6a61b99de92c8283dcbb59b147:/tests/strings/strings.cpp diff --git a/tests/strings/strings.cpp b/tests/strings/strings.cpp index d27644b565..4d7664115e 100644 --- a/tests/strings/strings.cpp +++ b/tests/strings/strings.cpp @@ -53,6 +53,7 @@ private: CPPUNIT_TEST( ToULongLong ); #endif // wxLongLong_t CPPUNIT_TEST( ToDouble ); + CPPUNIT_TEST( FromDouble ); CPPUNIT_TEST( StringBuf ); CPPUNIT_TEST( UTF8Buf ); CPPUNIT_TEST( CStrDataTernaryOperator ); @@ -85,6 +86,7 @@ private: void ToULongLong(); #endif // wxLongLong_t void ToDouble(); + void FromDouble(); void StringBuf(); void UTF8Buf(); void CStrDataTernaryOperator(); @@ -453,6 +455,10 @@ void StringTestCase::Compare() CPPUNIT_ASSERT( s1 != neq2 ); CPPUNIT_ASSERT( s1 != neq3 ); CPPUNIT_ASSERT( s1 != neq4 ); + + CPPUNIT_ASSERT( wxString("\n").Cmp(" ") < 0 ); + CPPUNIT_ASSERT( wxString("'").Cmp("!") > 0 ); + CPPUNIT_ASSERT( wxString("!").Cmp("z") < 0 ); } void StringTestCase::CompareNoCase() @@ -500,6 +506,10 @@ void StringTestCase::CompareNoCase() CPPUNIT_CNCNEQ_ASSERT( s1, neq ); CPPUNIT_CNCNEQ_ASSERT( s1, neq2 ); CPPUNIT_CNCNEQ_ASSERT( s1, neq3 ); + + CPPUNIT_ASSERT( wxString("\n").CmpNoCase(" ") < 0 ); + CPPUNIT_ASSERT( wxString("'").CmpNoCase("!") > 0); + CPPUNIT_ASSERT( wxString("!").Cmp("Z") < 0 ); } void StringTestCase::Contains() @@ -747,6 +757,48 @@ void StringTestCase::ToDouble() } } +void StringTestCase::FromDouble() +{ + static const struct FromDoubleTestData + { + double value; + const char *str; + } testData[] = + { + { 1.23, "1.23" }, + // NB: there are no standards about the minimum exponent width + // and newer MSVC versions use 3 digits as minimum exponent + // width while GNU libc uses 2 digits as minimum width... +#ifdef wxUSING_VC_CRT_IO + { -3e-10, "-3e-010" }, +#else + { -3e-10, "-3e-10" }, +#endif + { -0.45678, "-0.45678" }, + }; + + for ( unsigned n = 0; n < WXSIZEOF(testData); n++ ) + { + const FromDoubleTestData& td = testData[n]; + CPPUNIT_ASSERT_EQUAL( td.str, wxString::FromCDouble(td.value) ); + } + + if ( !wxLocale::IsAvailable(wxLANGUAGE_FRENCH) ) + return; + + wxLocale locale; + CPPUNIT_ASSERT( locale.Init(wxLANGUAGE_FRENCH, wxLOCALE_DONT_LOAD_DEFAULT) ); + + for ( unsigned m = 0; m < WXSIZEOF(testData); m++ ) + { + const FromDoubleTestData& td = testData[m]; + + wxString str(td.str); + str.Replace(".", ","); + CPPUNIT_ASSERT_EQUAL( str, wxString::FromDouble(td.value) ); + } +} + void StringTestCase::StringBuf() { // check that buffer can be used to write into the string @@ -918,18 +970,33 @@ void StringTestCase::BeforeAndAfter() { const wxString s(L"letter=\xe9;\xe7a=l\xe0"); - CPPUNIT_ASSERT_EQUAL( "letter", s.BeforeFirst('=') ); - CPPUNIT_ASSERT_EQUAL( s, s.BeforeFirst('!') ); - CPPUNIT_ASSERT_EQUAL( L"letter=\xe9", s.BeforeFirst(';') ); + wxString r; + + CPPUNIT_ASSERT_EQUAL( "letter", s.BeforeFirst('=', &r) ); + CPPUNIT_ASSERT_EQUAL( L"\xe9;\xe7a=l\xe0", r ); + + CPPUNIT_ASSERT_EQUAL( s, s.BeforeFirst('!', &r) ); + CPPUNIT_ASSERT_EQUAL( "", r ); + + CPPUNIT_ASSERT_EQUAL( L"letter=\xe9", s.BeforeFirst(';', &r) ); + CPPUNIT_ASSERT_EQUAL( L"\xe7a=l\xe0", r ); + + + CPPUNIT_ASSERT_EQUAL( L"letter=\xe9;\xe7a", s.BeforeLast('=', &r) ); + CPPUNIT_ASSERT_EQUAL( L"l\xe0", r ); + + CPPUNIT_ASSERT_EQUAL( "", s.BeforeLast('!', &r) ); + CPPUNIT_ASSERT_EQUAL( s, r ); + + CPPUNIT_ASSERT_EQUAL( L"letter=\xe9", s.BeforeLast(';', &r) ); + CPPUNIT_ASSERT_EQUAL( L"\xe7a=l\xe0", r ); - CPPUNIT_ASSERT_EQUAL( L"letter=\xe9;\xe7a", s.BeforeLast('=') ); - CPPUNIT_ASSERT_EQUAL( "", s.BeforeLast('!') ); - CPPUNIT_ASSERT_EQUAL( L"letter=\xe9", s.BeforeLast(';') ); CPPUNIT_ASSERT_EQUAL( L"\xe9;\xe7a=l\xe0", s.AfterFirst('=') ); CPPUNIT_ASSERT_EQUAL( "", s.AfterFirst('!') ); CPPUNIT_ASSERT_EQUAL( L"\xe7a=l\xe0", s.AfterFirst(';') ); + CPPUNIT_ASSERT_EQUAL( L"l\xe0", s.AfterLast('=') ); CPPUNIT_ASSERT_EQUAL( s, s.AfterLast('!') ); CPPUNIT_ASSERT_EQUAL( L"\xe7a=l\xe0", s.AfterLast(';') );