]> git.saurik.com Git - wxWidgets.git/blame - tests/strings/unicode.cpp
added language info for Northern Sami (patch 1964036)
[wxWidgets.git] / tests / strings / unicode.cpp
CommitLineData
387f829e
VS
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/strings/unicode.cpp
3// Purpose: Unicode unit test
4// Author: Vadim Zeitlin, Wlodzimierz ABX Skiba
5// Created: 2004-04-28
6// RCS-ID: $Id$
7// Copyright: (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba
8///////////////////////////////////////////////////////////////////////////////
9
10// ----------------------------------------------------------------------------
11// headers
12// ----------------------------------------------------------------------------
13
8899b155 14#include "testprec.h"
387f829e
VS
15
16#ifdef __BORLANDC__
17 #pragma hdrstop
18#endif
19
20#ifndef WX_PRECOMP
31c06391 21 #include "wx/wx.h"
387f829e
VS
22#endif // WX_PRECOMP
23
8da7a00a
VZ
24// ----------------------------------------------------------------------------
25// local functions
26// ----------------------------------------------------------------------------
27
28#if wxUSE_WCHAR_T && !wxUSE_UNICODE
29
30// in case wcscmp is missing
31static int wx_wcscmp(const wchar_t *s1, const wchar_t *s2)
32{
33 while (*s1 == *s2 && *s1 != 0)
34 {
35 s1++;
36 s2++;
37 }
38 return *s1 - *s2;
39}
40
41#endif // wxUSE_WCHAR_T && !wxUSE_UNICODE
42
387f829e
VS
43// ----------------------------------------------------------------------------
44// test class
45// ----------------------------------------------------------------------------
46
47class UnicodeTestCase : public CppUnit::TestCase
48{
49public:
50 UnicodeTestCase();
51
52private:
53 CPPUNIT_TEST_SUITE( UnicodeTestCase );
54 CPPUNIT_TEST( ToFromAscii );
a65ca3e6
VZ
55#if wxUSE_WCHAR_T
56 CPPUNIT_TEST( ConstructorsWithConversion );
85d3e5a9 57 CPPUNIT_TEST( ConversionEmpty );
5975f198 58 CPPUNIT_TEST( ConversionWithNULs );
a65ca3e6
VZ
59 CPPUNIT_TEST( ConversionUTF7 );
60 CPPUNIT_TEST( ConversionUTF8 );
5975f198 61 CPPUNIT_TEST( ConversionUTF16 );
a7823b26 62 CPPUNIT_TEST( ConversionUTF32 );
0f0298b1 63 CPPUNIT_TEST( IsConvOk );
a65ca3e6 64#endif // wxUSE_WCHAR_T
b0c4d5d7
VS
65#if wxUSE_UNICODE
66 CPPUNIT_TEST( Iteration );
67#endif
387f829e
VS
68 CPPUNIT_TEST_SUITE_END();
69
70 void ToFromAscii();
a65ca3e6
VZ
71#if wxUSE_WCHAR_T
72 void ConstructorsWithConversion();
85d3e5a9 73 void ConversionEmpty();
5975f198 74 void ConversionWithNULs();
a65ca3e6
VZ
75 void ConversionUTF7();
76 void ConversionUTF8();
5975f198 77 void ConversionUTF16();
a7823b26 78 void ConversionUTF32();
0f0298b1 79 void IsConvOk();
b0c4d5d7
VS
80#if wxUSE_UNICODE
81 void Iteration();
82#endif
a65ca3e6
VZ
83
84 // test if converting s using the given encoding gives ws and vice versa
85 //
86 // if either of the first 2 arguments is NULL, the conversion is supposed
87 // to fail
b0441359 88 void DoTestConversion(const char *s, const wchar_t *w, wxMBConv& conv);
a65ca3e6
VZ
89#endif // wxUSE_WCHAR_T
90
387f829e
VS
91
92 DECLARE_NO_COPY_CLASS(UnicodeTestCase)
93};
94
95// register in the unnamed registry so that these tests are run by default
96CPPUNIT_TEST_SUITE_REGISTRATION( UnicodeTestCase );
97
98// also include in it's own registry so that these tests can be run alone
81e9dec6 99CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UnicodeTestCase, "UnicodeTestCase" );
387f829e
VS
100
101UnicodeTestCase::UnicodeTestCase()
102{
103}
104
105void UnicodeTestCase::ToFromAscii()
106{
107
108#define TEST_TO_FROM_ASCII(txt) \
109 { \
110 static const char *msg = txt; \
111 wxString s = wxString::FromAscii(msg); \
112 CPPUNIT_ASSERT( strcmp( s.ToAscii() , msg ) == 0 ); \
113 }
114
115 TEST_TO_FROM_ASCII( "Hello, world!" );
116 TEST_TO_FROM_ASCII( "additional \" special \t test \\ component \n :-)" );
117}
118
a65ca3e6
VZ
119#if wxUSE_WCHAR_T
120void UnicodeTestCase::ConstructorsWithConversion()
121{
122