]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/strings/strings.cpp
Honour window min and max sizes in wxWindow::GetBestSize().
[wxWidgets.git] / tests / strings / strings.cpp
index af18513045d5d9e0db16715c1e28dad2baa0e7db..98e6619a80b283fff64fe6f35568fb31b1bdffd7 100644 (file)
@@ -165,6 +165,13 @@ void StringTestCase::Format()
         wxString s(wxT('Z'), len);
         CPPUNIT_ASSERT_EQUAL( len, wxString::Format(wxT("%s"), s.c_str()).length());
     }
+
+
+    CPPUNIT_ASSERT_EQUAL
+    (
+        "two one",
+        wxString::Format(wxT("%2$s %1$s"), wxT("one"), wxT("two"))
+    );
 }
 
 void StringTestCase::Constructors()
@@ -183,6 +190,20 @@ void StringTestCase::Constructors()
     CPPUNIT_ASSERT_EQUAL( L"Hello", wxString(L"Hello", 5) );
 #endif // wxUSE_UNICODE
 
+    CPPUNIT_ASSERT_EQUAL( 0, wxString(wxString(), 17).length() );
+
+#if wxUSE_UNICODE_UTF8
+    // This string has 3 characters (<h>, <e'> and <l>), not 4 when using UTF-8
+    // locale!
+    if ( wxConvLibc.IsUTF8() )
+    {
+        wxString s3("h\xc3\xa9llo", 4);
+        CPPUNIT_ASSERT_EQUAL( 3, s3.length() );
+        CPPUNIT_ASSERT_EQUAL( 'l', (char)s3[2] );
+    }
+#endif // wxUSE_UNICODE_UTF8
+
+
     static const char *s = "?really!";
     const char *start = wxStrchr(s, 'r');
     const char *end = wxStrchr(s, '!');
@@ -210,6 +231,9 @@ void StringTestCase::StaticConstructors()
     CPPUNIT_ASSERT_EQUAL( "Hello", wxString::FromUTF8("Hello", 5) );
     CPPUNIT_ASSERT_EQUAL( "Hello", wxString::FromUTF8("Hello") );
 
+    CPPUNIT_ASSERT_EQUAL( 2, wxString::FromUTF8("h\xc3\xa9llo", 3).length() );
+
+
     //CPPUNIT_ASSERT_EQUAL( 1, wxString::FromUTF8("", 1).length() );
 }
 
@@ -1039,4 +1063,18 @@ void StringTestCase::ScopedBuffers()
     wxCharBuffer buf2 = sbuf;
     CPPUNIT_ASSERT( buf2.data() != literal );
     CPPUNIT_ASSERT_EQUAL( literal, buf.data() );
+
+    // Check that extending the buffer keeps it NUL-terminated.
+    size_t len = 10;
+
+    wxCharBuffer buf3(len);
+    CPPUNIT_ASSERT_EQUAL('\0', buf3.data()[len]);
+
+    wxCharBuffer buf4;
+    buf4.extend(len);
+    CPPUNIT_ASSERT_EQUAL('\0', buf4.data()[len]);
+
+    wxCharBuffer buf5(5);
+    buf5.extend(len);
+    CPPUNIT_ASSERT_EQUAL('\0', buf5.data()[len]);
 }