CPPUNIT_TEST( StdReplace );
CPPUNIT_TEST( StdRFind );
CPPUNIT_TEST( StdResize );
+ CPPUNIT_TEST( StdRiter );
CPPUNIT_TEST( StdSubstr );
+#if wxUSE_STD_STRING
+ CPPUNIT_TEST( StdConversion );
+#endif
CPPUNIT_TEST_SUITE_END();
void StdConstructors();
void StdReplace();
void StdRFind();
void StdResize();
+ void StdRiter();
void StdSubstr();
+#if wxUSE_STD_STRING
+ void StdConversion();
+#endif
DECLARE_NO_COPY_CLASS(StdStringTestCase)
};
CPPUNIT_ASSERT( s6 == s1 );
CPPUNIT_ASSERT( s7 == s1 );
CPPUNIT_ASSERT( s8 == _T("efgh") );
+
+ const char *pc = s1;
+ WX_ASSERT_STR_EQUAL( "bcd", wxString(pc + 1, pc + 4) );
+
+ const wchar_t *pw = s2.c_str();
+ WX_ASSERT_STR_EQUAL( "a", wxString(pw, pw + 1) );
}
void StdStringTestCase::StdAppend()
s3.append(wxString(_T("abcdef")), 3, 6);
s4.append(s1);
s5.append(3, _T('a'));
+ s5.append(2, 'x');
+ s5.append(1, (unsigned char)'y');
s6.append(s1.begin() + 3, s1.end());
CPPUNIT_ASSERT( s1 == _T("abcdef") );
CPPUNIT_ASSERT( s2 == _T("abcdef") );
CPPUNIT_ASSERT( s3 == _T("abcdef") );
CPPUNIT_ASSERT( s4 == _T("abcabcdef") );
- CPPUNIT_ASSERT( s5 == _T("abcaaa") );
+ CPPUNIT_ASSERT( s5 == _T("abcaaaxxy") );
CPPUNIT_ASSERT( s6 == _T("abcdef") );
+ const char *pc = s1.c_str() + 2;
+ s7.append(pc, pc + 4);
+ WX_ASSERT_STR_EQUAL( "cdef", s7 );
+
+ const wchar_t *pw = s2.c_str() + 2;
+ s8.append(pw, pw + 4);
+ WX_ASSERT_STR_EQUAL( "cdef", s8 );
+
s7 = s8 = wxString(_T("null\0time"), 9);
s7.append(_T("def"));
CPPUNIT_ASSERT( s4 == _T("def") );
CPPUNIT_ASSERT( s5 == _T("aaa") );
CPPUNIT_ASSERT( s6 == _T("ef") );
+
+ const char *pc = s1;
+ s7.assign(pc, pc + 2);
+ WX_ASSERT_STR_EQUAL( "de", s7 );
+
+ const wchar_t *pw = s1.c_str();
+ s8.assign(pw + 2, pw + 3);
+ WX_ASSERT_STR_EQUAL( "f", s8 );
}
void StdStringTestCase::StdCompare()
CPPUNIT_ASSERT( s1.find(s2) == 6u );
CPPUNIT_ASSERT( s1.find(s2, 7) == wxString::npos );
CPPUNIT_ASSERT( s1.find(s2, 6) == 6u );
-
+
// 0 1 2
// 0123456 78901234567 8901234567
//wxString _s1 = _T("abcdefg\0ABCDEFGabc\0ABCabcABC");
//wxString _s2 = _T("g\0AB");
wxString _s1 = _T("abcdefgABCDEFGabcABCabcABC");
wxString _s2 = _T("gAB");
-
+
_s1.insert(7, 1, '\0');
_s1.insert(18, 1, '\0');
_s2.insert(1, 1, '\0');
-
+
CPPUNIT_ASSERT( _s1.find(_T('A')) == 8u );
CPPUNIT_ASSERT( _s1.find(_T('A'), 8) == 8u );
CPPUNIT_ASSERT( _s1.find(_T('Z')) == wxString::npos );
// wxString s1 = _T("abcde\0fgABCDE\0FGabcABCabcABC");
// wxString s2 = _T("gAB");
// wxString s3 = _T("ab");
-
+
s1.insert(5,1,'\0');
s1.insert(13,1,'\0');
CPPUNIT_ASSERT( s4 == _T("abcABCdefDEFWW") );
}
+void StdStringTestCase::StdRiter()
+{
+ const wxString s(_T("fozbar"));
+
+ wxString::const_reverse_iterator ri(s.rbegin());
+ CPPUNIT_ASSERT( _T('r') == *ri );
+ CPPUNIT_ASSERT( _T('a') == *++ri );
+ CPPUNIT_ASSERT( _T('r') == *--ri );
+
+ ri = s.rend();
+ ri--;
+ CPPUNIT_ASSERT( _T('f') == *ri );
+
+ --ri;
+ CPPUNIT_ASSERT( _T('o') == *ri );
+
+ wxString::const_iterator i = ri.base();
+ CPPUNIT_ASSERT( _T('z') == *i );
+}
+
void StdStringTestCase::StdSubstr()
{
wxString s1 = _T("abcdefgABCDEFG");
CPPUNIT_ASSERT( s1.substr( 1, 20 ) == _T("bcdefgABCDEFG") );
CPPUNIT_ASSERT( s1.substr( 14, 30 ) == _T("") );
-
-// 1
-// 012 34567 89012 3456
-// wxString s1 = _T("abc\0defg\0ABCD\0EFG");
-
s1.insert(3,1,'\0');
s1.insert(8,1,'\0');
s1.insert(13,1,'\0');
s2.insert(2,1,'\0');
s2.insert(7,1,'\0');
s2.insert(12,1,'\0');
-
+
CPPUNIT_ASSERT( s1.substr( 0, 17 ) == s1 );
CPPUNIT_ASSERT( s1.substr( 1, 17 ) == s2 );
CPPUNIT_ASSERT( s1.substr( 1, 20 ) == s2 );
CPPUNIT_ASSERT( s1.substr( 17, 30 ) == _T("") );
}
+#if wxUSE_STD_STRING
+void StdStringTestCase::StdConversion()
+{
+ std::string strStd("std::string value");
+ wxStdWideString strStdWide(L"std::wstring value");
+
+ wxString s1(strStd);
+ CPPUNIT_ASSERT( s1 == "std::string value" );
+
+ wxString s2(strStdWide);
+ CPPUNIT_ASSERT( s2 == "std::wstring value" );
+
+ wxString s3;
+ s3 = strStd;
+ CPPUNIT_ASSERT( s3 == "std::string value" );
+ s3 = strStdWide;
+ CPPUNIT_ASSERT( s3 == "std::wstring value" );
+
+ wxString s4("hello");
+ std::string s5 = s4;
+ CPPUNIT_ASSERT( s5 == "hello" );
+
+ wxStdWideString s6 = s4;
+ CPPUNIT_ASSERT( s6 == "hello" );
+}
+#endif // wxUSE_STD_STRING