+void StringTestCase::Contains()
+{
+ static const struct ContainsData
+ {
+ const wxChar *hay;
+ const wxChar *needle;
+ bool contains;
+ } containsData[] =
+ {
+ { _T(""), _T(""), true },
+ { _T(""), _T("foo"), false },
+ { _T("foo"), _T(""), true },
+ { _T("foo"), _T("f"), true },
+ { _T("foo"), _T("o"), true },
+ { _T("foo"), _T("oo"), true },
+ { _T("foo"), _T("ooo"), false },
+ { _T("foo"), _T("oooo"), false },
+ { _T("foo"), _T("fooo"), false },
+ };
+
+ for ( size_t n = 0; n < WXSIZEOF(containsData); n++ )
+ {
+ const ContainsData& cd = containsData[n];
+ CPPUNIT_ASSERT_EQUAL( cd.contains, wxString(cd.hay).Contains(cd.needle) );
+ }
+}
+
+void StringTestCase::ToLong()
+{
+ static const struct ToLongData
+ {
+ const wxChar *str;
+ long value;
+ bool ok;
+ } longData[] =
+ {
+ { _T("1"), 1, true },
+ { _T("0"), 0, true },
+ { _T("a"), 0, false },
+ { _T("12345"), 12345, true },
+ { _T("-1"), -1, true },
+ { _T("--1"), 0, false },
+ };
+
+ long l;
+ for ( size_t n = 0; n < WXSIZEOF(longData); n++ )
+ {
+ const ToLongData& ld = longData[n];
+ CPPUNIT_ASSERT_EQUAL( ld.ok, wxString(ld.str).ToLong(&l) );
+ if ( ld.ok )
+ CPPUNIT_ASSERT_EQUAL( ld.value, l );
+ }
+}
+
+void StringTestCase::ToULong()
+{
+ unsigned long ul;
+ static const struct ToULongData
+ {
+ const wxChar *str;
+ unsigned long value;
+ bool ok;
+ } ulongData[] =
+ {
+ { _T("1"), 1, true },
+ { _T("0"), 0, true },
+ { _T("a"), 0, false },
+ { _T("12345"), 12345, true },
+ // this is surprizing but consistent with strtoul() behaviour
+ { _T("-1"), ULONG_MAX, true },
+ };
+
+ size_t n;
+ for ( n = 0; n < WXSIZEOF(ulongData); n++ )
+ {
+ const ToULongData& uld = ulongData[n];
+ CPPUNIT_ASSERT_EQUAL( uld.ok, wxString(uld.str).ToULong(&ul) );
+ if ( uld.ok )
+ CPPUNIT_ASSERT_EQUAL( uld.value, ul );
+ }
+}
+
+void StringTestCase::ToDouble()
+{
+ double d;
+ static const struct ToDoubleData
+ {
+ const wxChar *str;
+ double value;
+ bool ok;
+ } doubleData[] =
+ {
+ { _T("1"), 1, true },
+ { _T("1.23"), 1.23, true },
+ { _T(".1"), .1, true },
+ { _T("1."), 1, true },
+ { _T("1.."), 0, false },
+ { _T("0"), 0, true },
+ { _T("a"), 0, false },
+ { _T("12345"), 12345, true },
+ { _T("-1"), -1, true },
+ { _T("--1"), 0, false },
+ };
+
+ // we need to use decimal point, not comma or whatever is its value for the
+ // current locale
+ wxSetlocale(LC_ALL, _T("C"));
+
+ size_t n;
+ for ( n = 0; n < WXSIZEOF(doubleData); n++ )
+ {
+ const ToDoubleData& ld = doubleData[n];
+ CPPUNIT_ASSERT_EQUAL( ld.ok, wxString(ld.str).ToDouble(&d) );
+ if ( ld.ok )
+ CPPUNIT_ASSERT_EQUAL( ld.value, d );
+ }
+}