]> git.saurik.com Git - wxWidgets.git/blob - tests/mbconv/main.cpp
d5689628629ec5375a23560a63fceb9c5d2c53a4
[wxWidgets.git] / tests / mbconv / main.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/mbconv/main.cpp
3 // Purpose: wxMBConv unit test
4 // Author: Vadim Zeitlin
5 // Created: 14.02.04
6 // RCS-ID: $Id$
7 // Copyright: (c) 2003 TT-Solutions
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "wx/wxprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WX_PRECOMP
21 #include "wx/wx.h"
22 #endif // WX_PRECOMP
23
24 #include "wx/strconv.h"
25 #include "wx/string.h"
26
27 #if wxUSE_FONTMAP
28 #include "wx/fontmap.h"
29 #endif // wxUSE_FONTMAP
30
31 #include "wx/cppunit.h"
32
33 // ----------------------------------------------------------------------------
34 // test class
35 // ----------------------------------------------------------------------------
36
37 class MBConvTestCase : public CppUnit::TestCase
38 {
39 public:
40 MBConvTestCase() { }
41
42 private:
43 CPPUNIT_TEST_SUITE( MBConvTestCase );
44 CPPUNIT_TEST( WC2CP1250 );
45 CPPUNIT_TEST( Charsets );
46 CPPUNIT_TEST_SUITE_END();
47
48 void WC2CP1250();
49 void Charsets();
50
51 DECLARE_NO_COPY_CLASS(MBConvTestCase)
52 };
53
54 // register in the unnamed registry so that these tests are run by default
55 CPPUNIT_TEST_SUITE_REGISTRATION( MBConvTestCase );
56
57 // also include in it's own registry so that these tests can be run alone
58 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MBConvTestCase, "MBConvTestCase" );
59
60 void MBConvTestCase::WC2CP1250()
61 {
62 static const struct Data
63 {
64 const wchar_t *wc;
65 const char *cp1250;
66 } data[] =
67 {
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
70 };
71
72 wxCSConv cs1250(wxFONTENCODING_CP1250);
73 for ( size_t n = 0; n < WXSIZEOF(data); n++ )
74 {
75 const Data& d = data[n];
76 if (d.cp1250)
77 {
78 CPPUNIT_ASSERT( strcmp(cs1250.cWC2MB(d.wc), d.cp1250) == 0 );
79 }
80 else
81 {
82 CPPUNIT_ASSERT( (const char*)cs1250.cWC2MB(d.wc) == NULL );
83 }
84 }
85 }
86
87 void MBConvTestCase::Charsets()
88 {
89 #if wxUSE_FONTMAP
90
91 static const wxChar *charsets[] =
92 {
93 // some vali charsets
94 _T("us-ascii" ),
95 _T("iso8859-1" ),
96 _T("iso-8859-12" ),
97 _T("koi8-r" ),
98 _T("utf-7" ),
99 _T("cp1250" ),
100 _T("windows-1252"),
101
102 // and now some bogus ones
103 _T("" ),
104 _T("cp1249" ),
105 _T("iso--8859-1" ),
106 _T("iso-8859-19" ),
107 };
108
109 static const wxChar *names[] =
110 {
111 // some vali charsets
112 _T("default" ),
113 _T("iso-8859-1" ),
114 _T("iso-8859-12" ),
115 _T("koi8-r" ),
116 _T("utf-7" ),
117 _T("windows-1250"),
118 _T("windows-1252"),
119
120 // and now some bogus ones
121 _T("default" ),
122 _T("unknown--1" ),
123 _T("unknown--1" ),
124 _T("unknown--1" ),
125 };
126
127 static const wxChar *descriptions[] =
128 {
129 // some vali charsets
130 _T("Default encoding" ),
131 _T("Western European (ISO-8859-1)" ),
132 _T("Indian (ISO-8859-12)" ),
133 _T("KOI8-R" ),
134 _T("Unicode 7 bit (UTF-7)" ),
135 _T("Windows Central European (CP 1250)"),
136 _T("Windows Western European (CP 1252)"),
137
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)" ),
143 };
144
145 for ( size_t n = 0; n < WXSIZEOF(charsets); n++ )
146 {
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] );
150 }
151
152 #endif // wxUSE_FONTMAP
153 }