From bc55323bc3be2d9bd668bd5887b673d0f26c8212 Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Fri, 18 Jun 2004 15:44:46 +0000 Subject: [PATCH] Charsets part moved from console sample to test unit. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27883 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/console/console.cpp | 45 ---------------------- tests/mbconv/main.cpp | 74 +++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 45 deletions(-) diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 43669bf593..d9bb332e08 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -51,7 +51,6 @@ #if TEST_ALL - #define TEST_CHARSET #define TEST_CMDLINE #define TEST_DATETIME #define TEST_DIR @@ -153,46 +152,6 @@ static wxString MakePrintable(const wxChar *s) #endif // MakePrintable() is used -// ---------------------------------------------------------------------------- -// wxFontMapper::CharsetToEncoding -// ---------------------------------------------------------------------------- - -#ifdef TEST_CHARSET - -#include "wx/fontmap.h" - -static void TestCharset() -{ - static const wxChar *charsets[] = - { - // some vali charsets - _T("us-ascii "), - _T("iso8859-1 "), - _T("iso-8859-12 "), - _T("koi8-r "), - _T("utf-7 "), - _T("cp1250 "), - _T("windows-1252"), - - // and now some bogus ones - _T(" "), - _T("cp1249 "), - _T("iso--8859-1 "), - _T("iso-8859-19 "), - }; - - for ( size_t n = 0; n < WXSIZEOF(charsets); n++ ) - { - wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(charsets[n]); - wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"), - charsets[n], - wxFontMapper::Get()->GetEncodingName(enc).c_str(), - wxFontMapper::Get()->GetEncodingDescription(enc).c_str()); - } -} - -#endif // TEST_CHARSET - // ---------------------------------------------------------------------------- // wxCmdLineParser // ---------------------------------------------------------------------------- @@ -5311,10 +5270,6 @@ int main(int argc, char **argv) } #endif // TEST_SNGLINST -#ifdef TEST_CHARSET - TestCharset(); -#endif // TEST_CHARSET - #ifdef TEST_CMDLINE TestCmdLineConvert(); diff --git a/tests/mbconv/main.cpp b/tests/mbconv/main.cpp index 5eb0ecf30f..d568962862 100644 --- a/tests/mbconv/main.cpp +++ b/tests/mbconv/main.cpp @@ -24,6 +24,10 @@ #include "wx/strconv.h" #include "wx/string.h" +#if wxUSE_FONTMAP + #include "wx/fontmap.h" +#endif // wxUSE_FONTMAP + #include "wx/cppunit.h" // ---------------------------------------------------------------------------- @@ -38,9 +42,11 @@ public: private: CPPUNIT_TEST_SUITE( MBConvTestCase ); CPPUNIT_TEST( WC2CP1250 ); + CPPUNIT_TEST( Charsets ); CPPUNIT_TEST_SUITE_END(); void WC2CP1250(); + void Charsets(); DECLARE_NO_COPY_CLASS(MBConvTestCase) }; @@ -77,3 +83,71 @@ void MBConvTestCase::WC2CP1250() } } } + +void MBConvTestCase::Charsets() +{ +#if wxUSE_FONTMAP + + static const wxChar *charsets[] = + { + // some vali charsets + _T("us-ascii" ), + _T("iso8859-1" ), + _T("iso-8859-12" ), + _T("koi8-r" ), + _T("utf-7" ), + _T("cp1250" ), + _T("windows-1252"), + + // and now some bogus ones + _T("" ), + _T("cp1249" ), + _T("iso--8859-1" ), + _T("iso-8859-19" ), + }; + + static const wxChar *names[] = + { + // some vali charsets + _T("default" ), + _T("iso-8859-1" ), + _T("iso-8859-12" ), + _T("koi8-r" ), + _T("utf-7" ), + _T("windows-1250"), + _T("windows-1252"), + + // and now some bogus ones + _T("default" ), + _T("unknown--1" ), + _T("unknown--1" ), + _T("unknown--1" ), + }; + + static const wxChar *descriptions[] = + { + // some vali charsets + _T("Default encoding" ), + _T("Western European (ISO-8859-1)" ), + _T("Indian (ISO-8859-12)" ), + _T("KOI8-R" ), + _T("Unicode 7 bit (UTF-7)" ), + _T("Windows Central European (CP 1250)"), + _T("Windows Western European (CP 1252)"), + + // and now some bogus ones + _T("Default encoding" ), + _T("Unknown encoding (-1)" ), + _T("Unknown encoding (-1)" ), + _T("Unknown encoding (-1)" ), + }; + + for ( size_t n = 0; n < WXSIZEOF(charsets); n++ ) + { + wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(charsets[n]); + CPPUNIT_ASSERT( wxFontMapper::Get()->GetEncodingName(enc) == names[n] ); + CPPUNIT_ASSERT( wxFontMapper::Get()->GetEncodingDescription(enc) == descriptions[n] ); + } + +#endif // wxUSE_FONTMAP +} -- 2.45.2