]>
git.saurik.com Git - wxWidgets.git/blob - tests/mbconv/main.cpp
d5689628629ec5375a23560a63fceb9c5d2c53a4
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/mbconv/main.cpp
3 // Purpose: wxMBConv unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2003 TT-Solutions
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
14 #include "wx/wxprec.h"
24 #include "wx/strconv.h"
25 #include "wx/string.h"
28 #include "wx/fontmap.h"
29 #endif // wxUSE_FONTMAP
31 #include "wx/cppunit.h"
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 class MBConvTestCase
: public CppUnit::TestCase
43 CPPUNIT_TEST_SUITE( MBConvTestCase
);
44 CPPUNIT_TEST( WC2CP1250
);
45 CPPUNIT_TEST( Charsets
);
46 CPPUNIT_TEST_SUITE_END();
51 DECLARE_NO_COPY_CLASS(MBConvTestCase
)
54 // register in the unnamed registry so that these tests are run by default
55 CPPUNIT_TEST_SUITE_REGISTRATION( MBConvTestCase
);
57 // also include in it's own registry so that these tests can be run alone
58 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MBConvTestCase
, "MBConvTestCase" );
60 void MBConvTestCase::WC2CP1250()
62 static const struct Data
68 { L
"hello", "hello" }, // test that it works in simplest case
69 { L
"½ of ½ is ¼", NULL
}, // this should fail as cp1250 doesn't have 1/2
72 wxCSConv
cs1250(wxFONTENCODING_CP1250
);
73 for ( size_t n
= 0; n
< WXSIZEOF(data
); n
++ )
75 const Data
& d
= data
[n
];
78 CPPUNIT_ASSERT( strcmp(cs1250
.cWC2MB(d
.wc
), d
.cp1250
) == 0 );
82 CPPUNIT_ASSERT( (const char*)cs1250
.cWC2MB(d
.wc
) == NULL
);
87 void MBConvTestCase::Charsets()
91 static const wxChar
*charsets
[] =
102 // and now some bogus ones
109 static const wxChar
*names
[] =
111 // some vali charsets
120 // and now some bogus ones
127 static const wxChar
*descriptions
[] =
129 // some vali charsets
130 _T("Default encoding" ),
131 _T("Western European (ISO-8859-1)" ),
132 _T("Indian (ISO-8859-12)" ),
134 _T("Unicode 7 bit (UTF-7)" ),
135 _T("Windows Central European (CP 1250)"),
136 _T("Windows Western European (CP 1252)"),
138 // and now some bogus ones
139 _T("Default encoding" ),
140 _T("Unknown encoding (-1)" ),
141 _T("Unknown encoding (-1)" ),
142 _T("Unknown encoding (-1)" ),
145 for ( size_t n
= 0; n
< WXSIZEOF(charsets
); n
++ )
147 wxFontEncoding enc
= wxFontMapper::Get()->CharsetToEncoding(charsets
[n
]);
148 CPPUNIT_ASSERT( wxFontMapper::Get()->GetEncodingName(enc
) == names
[n
] );
149 CPPUNIT_ASSERT( wxFontMapper::Get()->GetEncodingDescription(enc
) == descriptions
[n
] );
152 #endif // wxUSE_FONTMAP