]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/mbconv/mbconvtest.cpp
implement wxTreeCtrl::GetFocusedItem() for wxMSW too (see #10859)
[wxWidgets.git] / tests / mbconv / mbconvtest.cpp
index 718f87607ed0ed23787327997627cfe7244ba00e..5260887d7c4a1059bde966b3cd79f8e4514a2578 100644 (file)
@@ -254,7 +254,7 @@ wxString CByteArrayFormat( const void* data, size_t len, const wxChar* name )
     const unsigned char* bytes = (unsigned char*)data;
     wxString result;
 
     const unsigned char* bytes = (unsigned char*)data;
     wxString result;
 
-    result.Printf( _T("const static unsigned char %s[%i] = \n{"), name, (int)len );
+    result.Printf( _T("static const unsigned char %s[%i] = \n{"), name, (int)len );
 
     for ( size_t i = 0; i < len; i++ )
     {
 
     for ( size_t i = 0; i < len; i++ )
     {
@@ -277,7 +277,7 @@ wxString CByteArrayFormat( const void* data, size_t len, const wxChar* name )
 // characters, encoded in several different formats.
 
 // encoded by iconv
 // characters, encoded in several different formats.
 
 // encoded by iconv
-const static unsigned char welcome_utf7_iconv[84] =
+static const unsigned char welcome_utf7_iconv[84] =
 {
     0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20,0x74,0x6f,0x20,0x6f,0x75,0x72,0x20,0x63,
     0x79,0x62,0x65,0x72,0x20,0x73,0x70,0x61,0x63,0x65,0x20,0x66,0x6f,0x72,0x63,0x65,
 {
     0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20,0x74,0x6f,0x20,0x6f,0x75,0x72,0x20,0x63,
     0x79,0x62,0x65,0x72,0x20,0x73,0x70,0x61,0x63,0x65,0x20,0x66,0x6f,0x72,0x63,0x65,
@@ -287,7 +287,7 @@ const static unsigned char welcome_utf7_iconv[84] =
     0x57,0x54,0x41,0x43
 };
 // encoded by wxWindows (iconv can decode this successfully)
     0x57,0x54,0x41,0x43
 };
 // encoded by wxWindows (iconv can decode this successfully)
-const static unsigned char welcome_utf7_wx[109] =
+static const unsigned char welcome_utf7_wx[109] =
 {
     0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x2b,0x41,0x43,0x41,0x2d,0x74,0x6f,0x2b,0x41,
     0x43,0x41,0x2d,0x6f,0x75,0x72,0x2b,0x41,0x43,0x41,0x2d,0x63,0x79,0x62,0x65,0x72,
 {
     0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x2b,0x41,0x43,0x41,0x2d,0x74,0x6f,0x2b,0x41,
     0x43,0x41,0x2d,0x6f,0x75,0x72,0x2b,0x41,0x43,0x41,0x2d,0x63,0x79,0x62,0x65,0x72,
@@ -298,7 +298,7 @@ const static unsigned char welcome_utf7_wx[109] =
     0x51,0x77,0x52,0x44,0x42,0x6e,0x4d,0x46,0x6b,0x77,0x41,0x67,0x2d
 };
 // encoded by iconv
     0x51,0x77,0x52,0x44,0x42,0x6e,0x4d,0x46,0x6b,0x77,0x41,0x67,0x2d
 };
 // encoded by iconv
-const static unsigned char welcome_utf8[89] =
+static const unsigned char welcome_utf8[89] =
 {
     0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20,0x74,0x6f,0x20,0x6f,0x75,0x72,0x20,0x63,
     0x79,0x62,0x65,0x72,0x20,0x73,0x70,0x61,0x63,0x65,0x20,0x66,0x6f,0x72,0x63,0x65,
 {
     0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20,0x74,0x6f,0x20,0x6f,0x75,0x72,0x20,0x63,
     0x79,0x62,0x65,0x72,0x20,0x73,0x70,0x61,0x63,0x65,0x20,0x66,0x6f,0x72,0x63,0x65,
@@ -308,7 +308,7 @@ const static unsigned char welcome_utf8[89] =
     0xe3,0x81,0xa7,0xe3,0x81,0x99,0xe3,0x80,0x82
 };
 // encoded by iconv
     0xe3,0x81,0xa7,0xe3,0x81,0x99,0xe3,0x80,0x82
 };
 // encoded by iconv
-const static unsigned char welcome_utf16le[106] =
+static const unsigned char welcome_utf16le[106] =
 {
     0x57,0x00,0x65,0x00,0x6c,0x00,0x63,0x00,0x6f,0x00,0x6d,0x00,0x65,0x00,0x20,0x00,
     0x74,0x00,0x6f,0x00,0x20,0x00,0x6f,0x00,0x75,0x00,0x72,0x00,0x20,0x00,0x63,0x00,
 {
     0x57,0x00,0x65,0x00,0x6c,0x00,0x63,0x00,0x6f,0x00,0x6d,0x00,0x65,0x00,0x20,0x00,
     0x74,0x00,0x6f,0x00,0x20,0x00,0x6f,0x00,0x75,0x00,0x72,0x00,0x20,0x00,0x63,0x00,
@@ -319,7 +319,7 @@ const static unsigned char welcome_utf16le[106] =
     0x44,0x30,0x44,0x30,0x67,0x30,0x59,0x30,0x02,0x30
 };
 // encoded by iconv
     0x44,0x30,0x44,0x30,0x67,0x30,0x59,0x30,0x02,0x30
 };
 // encoded by iconv
-const static unsigned char welcome_utf16be[106] =
+static const unsigned char welcome_utf16be[106] =
 {
     0x00,0x57,0x00,0x65,0x00,0x6c,0x00,0x63,0x00,0x6f,0x00,0x6d,0x00,0x65,0x00,0x20,
     0x00,0x74,0x00,0x6f,0x00,0x20,0x00,0x6f,0x00,0x75,0x00,0x72,0x00,0x20,0x00,0x63,
 {
     0x00,0x57,0x00,0x65,0x00,0x6c,0x00,0x63,0x00,0x6f,0x00,0x6d,0x00,0x65,0x00,0x20,
     0x00,0x74,0x00,0x6f,0x00,0x20,0x00,0x6f,0x00,0x75,0x00,0x72,0x00,0x20,0x00,0x63,
@@ -330,7 +330,7 @@ const static unsigned char welcome_utf16be[106] =
     0x30,0x44,0x30,0x44,0x30,0x67,0x30,0x59,0x30,0x02
 };
 // encoded by iconv
     0x30,0x44,0x30,0x44,0x30,0x67,0x30,0x59,0x30,0x02
 };
 // encoded by iconv
-const static unsigned char welcome_utf32le[212] =
+static const unsigned char welcome_utf32le[212] =
 {
     0x57,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x63,0x00,0x00,0x00,
     0x6f,0x00,0x00,0x00,0x6d,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
 {
     0x57,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x63,0x00,0x00,0x00,
     0x6f,0x00,0x00,0x00,0x6d,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
@@ -348,7 +348,7 @@ const static unsigned char welcome_utf32le[212] =
     0x02,0x30,0x00,0x00
 };
 // encoded by iconv
     0x02,0x30,0x00,0x00
 };
 // encoded by iconv
-const static unsigned char welcome_utf32be[212] =
+static const unsigned char welcome_utf32be[212] =
 {
     0x00,0x00,0x00,0x57,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x63,
     0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x6d,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x20,
 {
     0x00,0x00,0x00,0x57,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x63,
     0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x6d,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x20,
@@ -366,7 +366,7 @@ const static unsigned char welcome_utf32be[212] =
     0x00,0x00,0x30,0x02
 };
 // encoded by iconv
     0x00,0x00,0x30,0x02
 };
 // encoded by iconv
-const static unsigned char welcome_cp932[71] =
+static const unsigned char welcome_cp932[71] =
 {
     0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20,0x74,0x6f,0x20,0x6f,0x75,0x72,0x20,0x63,
     0x79,0x62,0x65,0x72,0x20,0x73,0x70,0x61,0x63,0x65,0x20,0x66,0x6f,0x72,0x63,0x65,
 {
     0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20,0x74,0x6f,0x20,0x6f,0x75,0x72,0x20,0x63,
     0x79,0x62,0x65,0x72,0x20,0x73,0x70,0x61,0x63,0x65,0x20,0x66,0x6f,0x72,0x63,0x65,
@@ -676,6 +676,9 @@ static const unsigned char CP1252_utf8[386] =
     0x84,0xa2
 };
 
     0x84,0xa2
 };
 
+// this is unused currently so avoid warnings about this
+#if 0
+
 // a character sequence encoded as iso8859-5 (iconv)
 static const unsigned char iso8859_5[251] =
 {
 // a character sequence encoded as iso8859-5 (iconv)
 static const unsigned char iso8859_5[251] =
 {
@@ -724,6 +727,7 @@ static const unsigned char iso8859_5_utf8[380] =
     0x92,0xd1,0x93,0xd1,0x94,0xd1,0x95,0xd1,0x96,0xd1,0x97,0xd1,0x98,0xd1,0x99,0xd1,
     0x9a,0xd1,0x9b,0xd1,0x9c,0xd1,0x9e,0xd1,0x9f,0xe2,0x84,0x96
 };
     0x92,0xd1,0x93,0xd1,0x94,0xd1,0x95,0xd1,0x96,0xd1,0x97,0xd1,0x98,0xd1,0x99,0xd1,
     0x9a,0xd1,0x9b,0xd1,0x9c,0xd1,0x9e,0xd1,0x9f,0xe2,0x84,0x96
 };
+#endif // 0
 
 // DecodeUTF8
 // decodes the specified *unterminated* UTF-8 byte array
 
 // DecodeUTF8
 // decodes the specified *unterminated* UTF-8 byte array
@@ -815,41 +819,48 @@ void MBConvTestCase::BufSize()
     CPPUNIT_ASSERT( conv1251.IsOk() );
     const char *cp1251text =
         "\313\301\326\305\324\323\321 \325\304\301\336\316\331\315";
     CPPUNIT_ASSERT( conv1251.IsOk() );
     const char *cp1251text =
         "\313\301\326\305\324\323\321 \325\304\301\336\316\331\315";
-    const size_t cp1251textLen = strlen(cp1251text);
 
 
-    const size_t lenW = conv1251.MB2WC(NULL, cp1251text, cp1251textLen);
-    CPPUNIT_ASSERT( lenW != wxCONV_FAILED );
-    wxWCharBuffer wbuf(lenW);
+    const size_t lenW = conv1251.MB2WC(NULL, cp1251text, 0);
+    CPPUNIT_ASSERT_EQUAL( strlen(cp1251text), lenW );
+    wxWCharBuffer wbuf(lenW + 1); // allocates lenW + 2 characters
+    wbuf.data()[lenW + 1] = L'!';
 
 
-    // lenW-1 is not enough
+    // lenW is not enough because it's the length and we need the size
     CPPUNIT_ASSERT_EQUAL(
     CPPUNIT_ASSERT_EQUAL(
-        wxCONV_FAILED, conv1251.MB2WC(wbuf.data(), cp1251text, lenW - 1) );
+        wxCONV_FAILED, conv1251.MB2WC(wbuf.data(), cp1251text, lenW) );
 
 
-    // lenW is just fine
+    // lenW+1 is just fine
     CPPUNIT_ASSERT(
     CPPUNIT_ASSERT(
-        conv1251.MB2WC(wbuf.data(), cp1251text, lenW) != wxCONV_FAILED );
+        conv1251.MB2WC(wbuf.data(), cp1251text, lenW + 1) != wxCONV_FAILED );
 
     // of course, greater values work too
     CPPUNIT_ASSERT(
 
     // of course, greater values work too
     CPPUNIT_ASSERT(
-        conv1251.MB2WC(wbuf.data(), cp1251text, lenW + 1) != wxCONV_FAILED );
+        conv1251.MB2WC(wbuf.data(), cp1251text, lenW + 2) != wxCONV_FAILED );
+
+    // but they shouldn't write more stuff to the buffer
+    CPPUNIT_ASSERT_EQUAL( L'!', wbuf[lenW + 1] );
 
 
     // test in the other direction too, using an encoding with multibyte NUL
 
 
     // test in the other direction too, using an encoding with multibyte NUL
-    wxCSConv convUTF16(_T("UTF-16"));
+    wxCSConv convUTF16(_T("UTF-16LE"));
     CPPUNIT_ASSERT( convUTF16.IsOk() );
     const wchar_t *utf16text = L"Hello";
     CPPUNIT_ASSERT( convUTF16.IsOk() );
     const wchar_t *utf16text = L"Hello";
-    const size_t utf16textLen = wcslen(utf16text);
 
 
-    const size_t lenMB = convUTF16.WC2MB(NULL, utf16text, utf16textLen);
-    CPPUNIT_ASSERT( lenMB != wxCONV_FAILED );
-    wxCharBuffer buf(lenMB + 1); // it only adds 1 for NUL on its own, we need 2
+    const size_t lenMB = convUTF16.WC2MB(NULL, utf16text, 0);
+    CPPUNIT_ASSERT_EQUAL( wcslen(utf16text)*2, lenMB );
+    wxCharBuffer buf(lenMB + 2); // it only adds 1 for NUL on its own, we need 2
+                                 // for NUL and an extra one for the guard byte
+    buf.data()[lenMB + 2] = '?';
 
     CPPUNIT_ASSERT_EQUAL(
 
     CPPUNIT_ASSERT_EQUAL(
-        wxCONV_FAILED, convUTF16.WC2MB(buf.data(), utf16text, lenMB - 1) );
+        wxCONV_FAILED, convUTF16.WC2MB(buf.data(), utf16text, lenMB) );
+    CPPUNIT_ASSERT_EQUAL(
+        wxCONV_FAILED, convUTF16.WC2MB(buf.data(), utf16text, lenMB + 1) );
     CPPUNIT_ASSERT(
     CPPUNIT_ASSERT(
-        convUTF16.WC2MB(buf.data(), utf16text, lenMB) != wxCONV_FAILED );
+        convUTF16.WC2MB(buf.data(), utf16text, lenMB + 2) != wxCONV_FAILED );
     CPPUNIT_ASSERT(
     CPPUNIT_ASSERT(
-        convUTF16.WC2MB(buf.data(), utf16text, lenMB + 1) != wxCONV_FAILED );
+        convUTF16.WC2MB(buf.data(), utf16text, lenMB + 3) != wxCONV_FAILED );
+    CPPUNIT_ASSERT_EQUAL( '?', buf[lenMB + 2] );
 }
 
 
 }
 
 
@@ -889,7 +900,7 @@ void MBConvTestCase::Latin1Tests()
     static const char nulstr[] = "foo\0bar\0";
     static const size_t mbLen = WXSIZEOF(nulstr) - 1;
     size_t wcLen;
     static const char nulstr[] = "foo\0bar\0";
     static const size_t mbLen = WXSIZEOF(nulstr) - 1;
     size_t wcLen;
-    wxWCharBuffer wbuf(wxConvISO8859_1.cMB2WC(nulstr, mbLen, &wcLen));
+    wxConvISO8859_1.cMB2WC(nulstr, mbLen, &wcLen);
     CPPUNIT_ASSERT_EQUAL( mbLen, wcLen );
 }
 
     CPPUNIT_ASSERT_EQUAL( mbLen, wcLen );
 }
 
@@ -1118,7 +1129,7 @@ void MBConvTestCase::TestStreamEncoder(
 
     textOutputStream.Flush();
 
 
     textOutputStream.Flush();
 
-    CPPUNIT_ASSERT_EQUAL( (wxFileOffset)multiBytes, memoryOutputStream.TellO() );
+    CPPUNIT_ASSERT_EQUAL( multiBytes, size_t(memoryOutputStream.TellO()) );
     wxCharBuffer copy( memoryOutputStream.TellO() );
     memoryOutputStream.CopyTo( copy.data(), memoryOutputStream.TellO());
     CPPUNIT_ASSERT_EQUAL( 0, memcmp( copy.data(), multiBuffer, multiBytes ) );
     wxCharBuffer copy( memoryOutputStream.TellO() );
     memoryOutputStream.CopyTo( copy.data(), memoryOutputStream.TellO());
     CPPUNIT_ASSERT_EQUAL( 0, memcmp( copy.data(), multiBuffer, multiBytes ) );