X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c1ce4db1dea14fb8afa70b9e826647d21b354145..5ef723747cc680b3c237053bf0e3a78f0f179694:/tests/mbconv/mbconvtest.cpp?ds=inline diff --git a/tests/mbconv/mbconvtest.cpp b/tests/mbconv/mbconvtest.cpp index d816bc855f..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 ); @@ -213,6 +213,7 @@ 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,7 +242,9 @@ void MBConvTestCase::WC2CP1250() } } -// print an unsigned character array as a C unsigned character array +// 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; @@ -390,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 @@ -399,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 @@ -412,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 @@ -422,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 ); } @@ -435,7 +438,7 @@ void MBConvTestCase::UTF8Tests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf8, sizeof(welcome_utf8), - &wxConvUTF8, + wxConvUTF8, 1 ); TestEncoder @@ -444,7 +447,7 @@ void MBConvTestCase::UTF8Tests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf8, sizeof(welcome_utf8), - &wxConvUTF8, + wxConvUTF8, 1 ); } @@ -458,7 +461,7 @@ void MBConvTestCase::UTF16LETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf16le, sizeof(welcome_utf16le), - &convUTF16LE, + convUTF16LE, 2 ); TestEncoder @@ -467,7 +470,7 @@ void MBConvTestCase::UTF16LETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf16le, sizeof(welcome_utf16le), - &convUTF16LE, + convUTF16LE, 2 ); } @@ -481,7 +484,7 @@ void MBConvTestCase::UTF16BETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf16be, sizeof(welcome_utf16be), - &convUTF16BE, + convUTF16BE, 2 ); TestEncoder @@ -490,7 +493,7 @@ void MBConvTestCase::UTF16BETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf16be, sizeof(welcome_utf16be), - &convUTF16BE, + convUTF16BE, 2 ); } @@ -504,7 +507,7 @@ void MBConvTestCase::UTF32LETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf32le, sizeof(welcome_utf32le), - &convUTF32LE, + convUTF32LE, 4 ); TestEncoder @@ -513,7 +516,7 @@ void MBConvTestCase::UTF32LETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf32le, sizeof(welcome_utf32le), - &convUTF32LE, + convUTF32LE, 4 ); } @@ -527,7 +530,7 @@ void MBConvTestCase::UTF32BETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf32be, sizeof(welcome_utf32be), - &convUTF32BE, + convUTF32BE, 4 ); TestEncoder @@ -536,7 +539,7 @@ void MBConvTestCase::UTF32BETests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_utf32be, sizeof(welcome_utf32be), - &convUTF32BE, + convUTF32BE, 4 ); } @@ -550,7 +553,7 @@ void MBConvTestCase::CP932Tests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_cp932, sizeof(welcome_cp932), - &convCP932, + convCP932, 1 ); TestEncoder @@ -559,7 +562,7 @@ void MBConvTestCase::CP932Tests() sizeof(welcome_wchar_t)/sizeof(wchar_t), (const char*)welcome_cp932, sizeof(welcome_cp932), - &convCP932, + convCP932, 1 ); } @@ -740,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 ) { @@ -774,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; @@ -789,7 +792,7 @@ void MBConvTestCase::FontmapTests() sizeof(CP1252), (const char*)CP1252_utf8, sizeof(CP1252_utf8), - converter, + *converter, 1 ); delete converter; @@ -797,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; @@ -812,7 +815,7 @@ void MBConvTestCase::IconvTests() sizeof(welcome_cp932), (const char*)welcome_utf8, sizeof(welcome_utf8), - converter, + *converter, 1 ); delete converter; @@ -827,7 +830,7 @@ void MBConvTestCase::CP1252Tests() sizeof(CP1252), (const char*)CP1252_utf8, sizeof(CP1252_utf8), - &convCP1252, + convCP1252, 1 ); } @@ -858,7 +861,7 @@ void MBConvTestCase::LibcTests() systemMB_size, (const char*)systemMB_utf8, systemMB_utf8_size, - &convLibc, + convLibc, 1 ); @@ -871,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 ) { @@ -883,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(), @@ -899,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(), @@ -931,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 ) { @@ -943,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(), @@ -958,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(), @@ -971,14 +974,16 @@ void MBConvTestCase::TestEncoder( // make sure the characters generated are correct CPPUNIT_ASSERT( 0 == memcmp( outputBuffer, multiBuffer, multiBytes ) ); + size_t i; + // the output buffer should be null terminated - for ( size_t i = multiBytes; i < multiBytes + sizeofNull; i++ ) + for ( i = multiBytes; i < multiBytes + sizeofNull; i++ ) { CPPUNIT_ASSERT( ((unsigned char*)outputBuffer.data())[i] == 0 ); } // make sure the rest of the output buffer is untouched - for ( size_t i = multiBytes + sizeofNull; i < outputBufferSize; i++ ) + for ( i = multiBytes + sizeofNull; i < outputBufferSize; i++ ) { CPPUNIT_ASSERT( ((unsigned char*)outputBuffer.data())[i] == UNINITIALIZED ); } @@ -996,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(); @@ -1022,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 @@ -1030,15 +1035,15 @@ 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] ); } - CPPUNIT_ASSERT( memoryOutputStream.TellO() == multiBytes ); + CPPUNIT_ASSERT_EQUAL( (wxFileOffset)multiBytes, memoryOutputStream.TellO() ); wxCharBuffer copy( memoryOutputStream.TellO() ); memoryOutputStream.CopyTo( copy.data(), memoryOutputStream.TellO()); - CPPUNIT_ASSERT( 0 == memcmp( copy.data(), multiBuffer, multiBytes ) ); + CPPUNIT_ASSERT_EQUAL( 0, memcmp( copy.data(), multiBuffer, multiBytes ) ); } #endif