X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c9f7896861f734ce044ee8601ba2d8a6959c9d9e..dd9f8b6bb6935360a8271dc3e8749fb026b601a8:/tests/strings/stdstrings.cpp?ds=sidebyside diff --git a/tests/strings/stdstrings.cpp b/tests/strings/stdstrings.cpp index 0e706ca6e8..585d65c6e4 100644 --- a/tests/strings/stdstrings.cpp +++ b/tests/strings/stdstrings.cpp @@ -1,4 +1,4 @@ -/////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// // Name: tests/strings/stdstrings.cpp // Purpose: wxString unit test // Author: Vadim Zeitlin, Wlodzimierz ABX Skiba @@ -33,6 +33,7 @@ public: private: CPPUNIT_TEST_SUITE( StdStringTestCase ); CPPUNIT_TEST( StdConstructors ); + CPPUNIT_TEST( StdIterators ); CPPUNIT_TEST( StdAppend ); CPPUNIT_TEST( StdAssign ); CPPUNIT_TEST( StdCompare ); @@ -46,9 +47,13 @@ private: CPPUNIT_TEST( StdResize ); CPPUNIT_TEST( StdRiter ); CPPUNIT_TEST( StdSubstr ); +#if wxUSE_STD_STRING + CPPUNIT_TEST( StdConversion ); +#endif CPPUNIT_TEST_SUITE_END(); void StdConstructors(); + void StdIterators(); void StdAppend(); void StdAssign(); void StdCompare(); @@ -62,6 +67,9 @@ private: void StdResize(); void StdRiter(); void StdSubstr(); +#if wxUSE_STD_STRING + void StdConversion(); +#endif DECLARE_NO_COPY_CLASS(StdStringTestCase) }; @@ -94,6 +102,21 @@ void StdStringTestCase::StdConstructors() CPPUNIT_ASSERT( s6 == s1 ); CPPUNIT_ASSERT( s7 == s1 ); CPPUNIT_ASSERT( s8 == _T("efgh") ); + + const char *pc = s1.c_str(); + 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::StdIterators() +{ + // test compilation of default iterators ctors: + wxString::iterator i1; + wxString::const_iterator i2; + wxString::reverse_iterator i3; + wxString::const_reverse_iterator i4; } void StdStringTestCase::StdAppend() @@ -106,15 +129,25 @@ 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")); @@ -142,6 +175,17 @@ void StdStringTestCase::StdAssign() CPPUNIT_ASSERT( s4 == _T("def") ); CPPUNIT_ASSERT( s5 == _T("aaa") ); CPPUNIT_ASSERT( s6 == _T("ef") ); + + const char *pc = s1.c_str(); + 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 ); + + s1.assign(s1, 1, 1); + WX_ASSERT_STR_EQUAL("e", s1); } void StdStringTestCase::StdCompare() @@ -444,6 +488,11 @@ void StdStringTestCase::StdResize() CPPUNIT_ASSERT( s2 == _T("abcABCdefD") ); CPPUNIT_ASSERT( s3 == _T("abcABCdefDEF ") ); CPPUNIT_ASSERT( s4 == _T("abcABCdefDEFWW") ); + + wxString s = + wxString::FromUTF8("\xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82"); + s.resize(3); + WX_ASSERT_STR_EQUAL("\xd0\x9f\xd1\x80\xd0\xb8", s); } void StdStringTestCase::StdRiter() @@ -490,3 +539,40 @@ void StdStringTestCase::StdSubstr() 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"); + + // wxString -> std::string conversion is only available in wxUSE_STL case, + // because it conflicts with conversion to const char*/wchar_t*: +#if wxUSE_STL + std::string s5 = s4; + CPPUNIT_ASSERT( s5 == "hello" ); + + wxStdWideString s6 = s4; + CPPUNIT_ASSERT( s6 == "hello" ); +#endif + + std::string s7(s4); + CPPUNIT_ASSERT( s7 == "hello" ); + + wxStdWideString s8(s4); + CPPUNIT_ASSERT( s8 == "hello" ); +} +#endif // wxUSE_STD_STRING