+
+void StringTestCase::ExplicitConversion()
+{
+ wxString s("foo");
+
+ CPPUNIT_ASSERT( CheckStr(s, s.mb_str()) );
+ CPPUNIT_ASSERT( CheckStrConstChar(s, s.mb_str()) );
+ CPPUNIT_ASSERT( CheckStrChar(s, s.char_str()) );
+
+ CPPUNIT_ASSERT( CheckStr(s, s.wc_str()) );
+ CPPUNIT_ASSERT( CheckStrConstWChar(s, s.wc_str()) );
+ CPPUNIT_ASSERT( CheckStrWChar(s, s.wchar_str()) );
+}
+
+void StringTestCase::IndexedAccess()
+{
+ wxString s("bar");
+ CPPUNIT_ASSERT_EQUAL( 'r', (char)s[2] );
+
+ // this tests for a possible bug in UTF-8 based wxString implementation:
+ // the 3rd character of the underlying byte string is going to change, but
+ // the 3rd character of wxString should remain the same
+ s[0] = L'\xe9';
+ CPPUNIT_ASSERT_EQUAL( 'r', (char)s[2] );
+}
+
+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(';') );
+
+ 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(';') );
+}
+
+void StringTestCase::ScopedBuffers()
+{
+ // wxString relies on efficient buffers, verify they work as they should
+
+ const char *literal = "Hello World!";
+
+ // non-owned buffer points to the string passed to it
+ wxScopedCharBuffer sbuf = wxScopedCharBuffer::CreateNonOwned(literal);
+ CPPUNIT_ASSERT( sbuf.data() == literal );
+
+ // a copy of scoped non-owned buffer still points to the same string
+ wxScopedCharBuffer sbuf2(sbuf);
+ CPPUNIT_ASSERT( sbuf.data() == sbuf2.data() );
+
+ // but assigning it to wxCharBuffer makes a full copy
+ wxCharBuffer buf(sbuf);
+ CPPUNIT_ASSERT( buf.data() != literal );
+ CPPUNIT_ASSERT_EQUAL( literal, buf.data() );
+
+ wxCharBuffer buf2 = sbuf;
+ CPPUNIT_ASSERT( buf2.data() != literal );
+ CPPUNIT_ASSERT_EQUAL( literal, buf.data() );
+}