CPPUNIT_TEST( ToULongLong );
#endif // wxLongLong_t
CPPUNIT_TEST( ToDouble );
+ CPPUNIT_TEST( FromDouble );
CPPUNIT_TEST( StringBuf );
CPPUNIT_TEST( UTF8Buf );
CPPUNIT_TEST( CStrDataTernaryOperator );
void ToULongLong();
#endif // wxLongLong_t
void ToDouble();
+ void FromDouble();
void StringBuf();
void UTF8Buf();
void CStrDataTernaryOperator();
{ wxT("--1"), 0, Number_Invalid },
{ wxT("-1"), -1, Number_Signed | Number_Long },
- // this is surprizing but consistent with strtoul() behaviour
+ // this is surprising but consistent with strtoul() behaviour
{ wxT("-1"), ULONG_MAX, Number_Unsigned | Number_Long },
// this must overflow, even with 64 bit long
if ( ld.flags & (Number_LongLong | Number_Unsigned) )
continue;
-
+
// NOTE: unless you're using some exotic locale, ToCLong and ToLong
// should behave the same for our test data set:
if ( ld.IsOk() )
CPPUNIT_ASSERT_EQUAL( ld.LValue(), l );
}
+
+ // special case: check that the output is not modified if the parsing
+ // failed completely
+ l = 17;
+ CPPUNIT_ASSERT( !wxString("foo").ToLong(&l) );
+ CPPUNIT_ASSERT_EQUAL( 17, l );
+
+ // also check that it is modified if we did parse something successfully in
+ // the beginning of the string
+ CPPUNIT_ASSERT( !wxString("9 cats").ToLong(&l) );
+ CPPUNIT_ASSERT_EQUAL( 9, l );
}
void StringTestCase::ToULong()
CPPUNIT_ASSERT_EQUAL( ld.IsOk(), wxString(ld.str).ToCULong(&ul) );
if ( ld.IsOk() )
CPPUNIT_ASSERT_EQUAL( ld.ULValue(), ul );
-
+
CPPUNIT_ASSERT_EQUAL( ld.IsOk(), wxString(ld.str).ToULong(&ul) );
if ( ld.IsOk() )
CPPUNIT_ASSERT_EQUAL( ld.ULValue(), ul );
// test ToDouble() now:
- // NOTE: for the test to be reliable, we need to set the locale explicitely
+ // NOTE: for the test to be reliable, we need to set the locale explicitly
// so that we know the decimal point character to use
if (!wxLocale::IsAvailable(wxLANGUAGE_FRENCH))
return; // you should have french support installed to continue this test!
- wxLocale *locale = new wxLocale;
-
+ wxLocale locale;
+
// don't load default catalog, it may be unavailable:
- CPPUNIT_ASSERT( locale->Init(wxLANGUAGE_FRENCH, wxLOCALE_CONV_ENCODING) );
-
+ CPPUNIT_ASSERT( locale.Init(wxLANGUAGE_FRENCH, wxLOCALE_DONT_LOAD_DEFAULT) );
+
static const struct ToDoubleData doubleData2[] =
{
{ wxT("1"), 1, true },
if ( ld.ok )
CPPUNIT_ASSERT_EQUAL( ld.value, d );
}
-
- delete locale;
+}
+
+void StringTestCase::FromDouble()
+{
+ static const struct FromDoubleTestData
+ {
+ double value;
+ const char *str;
+ } testData[] =
+ {
+ { 1.23, "1.23" },
+ { -3e-10, "-3e-10" },
+ { -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()