X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0cdb0b966651b0934aa3932cf3037b22e04527b4..7c71eb6a2607235a29ffb29e3c39bb4f1a74fff7:/tests/mbconv/mbconvtest.cpp diff --git a/tests/mbconv/mbconvtest.cpp b/tests/mbconv/mbconvtest.cpp index 7109ffb223..6d385495ef 100644 --- a/tests/mbconv/mbconvtest.cpp +++ b/tests/mbconv/mbconvtest.cpp @@ -120,7 +120,7 @@ private: size_t wideChars, // the number of wide characters at wideBuffer const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" - wxMBConv* converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence + wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence int sizeofNull // number of bytes occupied by terminating null in this encoding ); @@ -130,7 +130,7 @@ private: size_t wideChars, // the number of wide characters at wideBuffer const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" - wxMBConv* converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence + wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence int sizeofNull // number of bytes occupied by terminating null in this encoding ); @@ -142,7 +142,7 @@ private: size_t wideChars, // the number of wide characters at wideBuffer const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" - wxMBConv* converter // the wxMBConv object that can decode multiBuffer into a wide character sequence + wxMBConv& converter // the wxMBConv object that can decode multiBuffer into a wide character sequence ); // use wxTextOutputStream to exercise wxMBConv interface @@ -152,7 +152,7 @@ private: size_t wideChars, // the number of wide characters at wideBuffer const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" - wxMBConv* converter // the wxMBConv object that can decode multiBuffer into a wide character sequence + wxMBConv& converter // the wxMBConv object that can decode multiBuffer into a wide character sequence ); #endif @@ -167,7 +167,7 @@ private: size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" const char* utf8Buffer, // the same character sequence as multiBuffer, encoded as UTF-8 size_t utf8Bytes, // the byte length of the UTF-8 encoded character sequence - wxMBConv* converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence + wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence int sizeofNull // the number of bytes occupied by a terminating null in the converter's encoding ); @@ -212,6 +212,7 @@ private: CPPUNIT_TEST_SUITE_REGISTRATION( MBConvTestCase ); // also include in it's own registry so that these tests can be run alone +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MBConvTestCase, "MBConvTestCase" ); CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MBConvTestCase, "MBConv" ); void MBConvTestCase::WC2CP1250() @@ -241,6 +242,33 @@ void MBConvTestCase::WC2CP1250() } } +// Print an unsigned character array as a C unsigned character array. +// NB: Please don't remove this function even though it's not used anywhere, +// it's very useful when debugging a failed test. +wxString CByteArrayFormat( const void* data, size_t len, const wxChar* name ) +{ + const unsigned char* bytes = (unsigned char*)data; + wxString result; + + result.Printf( _T("const static unsigned char %s[%i] = \n{"), name, (int)len ); + + for ( size_t i = 0; i < len; i++ ) + { + if ( i != 0 ) + { + result.append( _T(",") ); + } + if ((i%16)==0) + { + result.append( _T("\n ") ); + } + wxString byte = wxString::Format( _T("0x%02x"), bytes[i] ); + result.append(byte); + } + result.append( _T("\n};\n") ); + return result; +} + // The following bytes represent the same string, containing Japanese and English // characters, encoded in several different formats. @@ -365,7 +393,7 @@ void MBConvTestCase::UTF7Tests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf7_iconv, sizeof(welcome_utf7_iconv), - &wxConvUTF7, + wxConvUTF7, 1 ); TestDecoder @@ -374,7 +402,7 @@ void MBConvTestCase::UTF7Tests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf7_wx, sizeof(welcome_utf7_wx), - &wxConvUTF7, + wxConvUTF7, 1 ); #if 0 @@ -387,7 +415,7 @@ void MBConvTestCase::UTF7Tests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf7_iconv, sizeof(welcome_utf7_iconv), - &wxConvUTF7, + wxConvUTF7, 1 ); #endif @@ -397,7 +425,7 @@ void MBConvTestCase::UTF7Tests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf7_wx, sizeof(welcome_utf7_wx), - &wxConvUTF7, + wxConvUTF7, 1 ); } @@ -410,7 +438,7 @@ void MBConvTestCase::UTF8Tests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf8, sizeof(welcome_utf8), - &wxConvUTF8, + wxConvUTF8, 1 ); TestEncoder @@ -419,7 +447,7 @@ void MBConvTestCase::UTF8Tests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf8, sizeof(welcome_utf8), - &wxConvUTF8, + wxConvUTF8, 1 ); } @@ -433,7 +461,7 @@ void MBConvTestCase::UTF16LETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf16le, sizeof(welcome_utf16le), - &convUTF16LE, + convUTF16LE, 2 ); TestEncoder @@ -442,7 +470,7 @@ void MBConvTestCase::UTF16LETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf16le, sizeof(welcome_utf16le), - &convUTF16LE, + convUTF16LE, 2 ); } @@ -456,7 +484,7 @@ void MBConvTestCase::UTF16BETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf16be, sizeof(welcome_utf16be), - &convUTF16BE, + convUTF16BE, 2 ); TestEncoder @@ -465,7 +493,7 @@ void MBConvTestCase::UTF16BETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf16be, sizeof(welcome_utf16be), - &convUTF16BE, + convUTF16BE, 2 ); } @@ -479,7 +507,7 @@ void MBConvTestCase::UTF32LETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf32le, sizeof(welcome_utf32le), - &convUTF32LE, + convUTF32LE, 4 ); TestEncoder @@ -488,7 +516,7 @@ void MBConvTestCase::UTF32LETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf32le, sizeof(welcome_utf32le), - &convUTF32LE, + convUTF32LE, 4 ); } @@ -502,7 +530,7 @@ void MBConvTestCase::UTF32BETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf32be, sizeof(welcome_utf32be), - &convUTF32BE, + convUTF32BE, 4 ); TestEncoder @@ -511,7 +539,7 @@ void MBConvTestCase::UTF32BETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf32be, sizeof(welcome_utf32be), - &convUTF32BE, + convUTF32BE, 4 ); } @@ -525,7 +553,7 @@ void MBConvTestCase::CP932Tests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_cp932, sizeof(welcome_cp932), - &convCP932, + convCP932, 1 ); TestEncoder @@ -534,7 +562,7 @@ void MBConvTestCase::CP932Tests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_cp932, sizeof(welcome_cp932), - &convCP932, + convCP932, 1 ); } @@ -715,7 +743,7 @@ void MBConvTestCase::TestCoder( size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" const char* utf8Buffer, // the same character sequence as multiBuffer, encoded as UTF-8 size_t utf8Bytes, // the byte length of the UTF-8 encoded character sequence - wxMBConv* converter, // the wxMBConv object thta can decode multiBuffer into a wide character sequence + wxMBConv& converter, // the wxMBConv object thta can decode multiBuffer into a wide character sequence int sizeofNull // the number of bytes occupied by a terminating null in the converter's encoding ) { @@ -749,12 +777,12 @@ void MBConvTestCase::TestCoder( } -WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_wxwin( const wxChar* name ); +WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_wxwin( const char* name ); void MBConvTestCase::FontmapTests() { #ifdef wxUSE_FONTMAP - wxMBConv* converter = new_wxMBConv_wxwin( _T("CP1252") ); + wxMBConv* converter = new_wxMBConv_wxwin("CP1252"); if ( !converter ) { return; @@ -764,7 +792,7 @@ void MBConvTestCase::FontmapTests() sizeof(CP1252), (const char*)CP1252_utf8, sizeof(CP1252_utf8), - converter, + *converter, 1 ); delete converter; @@ -772,12 +800,12 @@ void MBConvTestCase::FontmapTests() } -WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_iconv( const wxChar* name ); +WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_iconv( const char* name ); void MBConvTestCase::IconvTests() { #ifdef HAVE_ICONV - wxMBConv* converter = new_wxMBConv_iconv( _T("CP932") ); + wxMBConv* converter = new_wxMBConv_iconv("CP932"); if ( !converter ) { return; @@ -787,7 +815,7 @@ void MBConvTestCase::IconvTests() sizeof(welcome_cp932), (const char*)welcome_utf8, sizeof(welcome_utf8), - converter, + *converter, 1 ); delete converter; @@ -802,7 +830,7 @@ void MBConvTestCase::CP1252Tests() sizeof(CP1252), (const char*)CP1252_utf8, sizeof(CP1252_utf8), - &convCP1252, + convCP1252, 1 ); } @@ -833,7 +861,7 @@ void MBConvTestCase::LibcTests() systemMB_size, (const char*)systemMB_utf8, systemMB_utf8_size, - &convLibc, + convLibc, 1 ); @@ -846,7 +874,7 @@ void MBConvTestCase::TestDecoder( size_t wideChars, // the number of wide characters at wideBuffer const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" - wxMBConv* converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence + wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence int sizeofNull // number of bytes occupied by terminating null in this encoding ) { @@ -858,7 +886,7 @@ void MBConvTestCase::TestDecoder( memset( &inputCopy.data()[multiBytes], 0, sizeofNull ); // calculate the output size - size_t outputWritten = converter->MB2WC + size_t outputWritten = converter.MB2WC ( 0, (const char*)inputCopy.data(), @@ -874,7 +902,7 @@ void MBConvTestCase::TestDecoder( wxWCharBuffer outputBuffer(outputBufferChars); memset( outputBuffer.data(), UNINITIALIZED, outputBufferChars*sizeof(wchar_t) ); - outputWritten = converter->MB2WC + outputWritten = converter.MB2WC ( outputBuffer.data(), (const char*)inputCopy.data(), @@ -906,7 +934,7 @@ void MBConvTestCase::TestEncoder( size_t wideChars, // the number of wide characters at wideBuffer const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" - wxMBConv* converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence + wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence int sizeofNull // number of bytes occupied by terminating null in this encoding ) { @@ -918,7 +946,7 @@ void MBConvTestCase::TestEncoder( inputCopy.data()[wideChars] = 0; // calculate the output size - size_t outputWritten = converter->WC2MB + size_t outputWritten = converter.WC2MB ( 0, (const wchar_t*)inputCopy.data(), @@ -933,7 +961,7 @@ void MBConvTestCase::TestEncoder( wxCharBuffer outputBuffer(outputBufferSize); memset( outputBuffer.data(), UNINITIALIZED, outputBufferSize ); - outputWritten = converter->WC2MB + outputWritten = converter.WC2MB ( outputBuffer.data(), (const wchar_t*)inputCopy.data(), @@ -973,14 +1001,14 @@ void MBConvTestCase::TestStreamDecoder( size_t wideChars, // the number of wide characters at wideBuffer const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" - wxMBConv* converter // the wxMBConv object that can decode multiBuffer into a wide character sequence + wxMBConv& converter // the wxMBConv object that can decode multiBuffer into a wide character sequence ) { // this isn't meant to test wxMemoryInputStream or wxTextInputStream // it's meant to test the way wxTextInputStream uses wxMBConv // (which has exposed some problems with wxMBConv) wxMemoryInputStream memoryInputStream( multiBuffer, multiBytes ); - wxTextInputStream textInputStream( memoryInputStream, wxT(""), *converter ); + wxTextInputStream textInputStream( memoryInputStream, wxT(""), converter ); for ( size_t i = 0; i < wideChars; i++ ) { wxChar wc = textInputStream.GetChar(); @@ -999,7 +1027,7 @@ void MBConvTestCase::TestStreamEncoder( size_t wideChars, // the number of wide characters at wideBuffer const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" - wxMBConv* converter // the wxMBConv object that can decode multiBuffer into a wide character sequence + wxMBConv& converter // the wxMBConv object that can decode multiBuffer into a wide character sequence ) { // this isn't meant to test wxMemoryOutputStream or wxTextOutputStream @@ -1007,7 +1035,7 @@ void MBConvTestCase::TestStreamEncoder( // (which has exposed some problems with wxMBConv) wxMemoryOutputStream memoryOutputStream; // wxEOL_UNIX will pass \n \r unchanged - wxTextOutputStream textOutputStream( memoryOutputStream, wxEOL_UNIX, *converter ); + wxTextOutputStream textOutputStream( memoryOutputStream, wxEOL_UNIX, converter ); for ( size_t i = 0; i < wideChars; i++ ) { textOutputStream.PutChar( wideBuffer[i] );