]> git.saurik.com Git - wxWidgets.git/blame - tests/strings/unicode.cpp
Remove malloc.h
[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
387f829e
VS
21#endif // WX_PRECOMP
22
8da7a00a
VZ
23// ----------------------------------------------------------------------------
24// local functions
25// ----------------------------------------------------------------------------
26
27#if wxUSE_WCHAR_T && !wxUSE_UNICODE
28
29// in case wcscmp is missing
30static int wx_wcscmp(const wchar_t *s1, const wchar_t *s2)
31{
32 while (*s1 == *s2 && *s1 != 0)
33 {
34 s1++;
35 s2++;
36 }
37 return *s1 - *s2;
38}
39
40#endif // wxUSE_WCHAR_T && !wxUSE_UNICODE
41
387f829e
VS
42// ----------------------------------------------------------------------------
43// test class
44// ----------------------------------------------------------------------------
45
46class UnicodeTestCase : public CppUnit::TestCase
47{
48public:
49 UnicodeTestCase();
50
51private:
52 CPPUNIT_TEST_SUITE( UnicodeTestCase );
53 CPPUNIT_TEST( ToFromAscii );
a65ca3e6
VZ
54#if wxUSE_WCHAR_T
55 CPPUNIT_TEST( ConstructorsWithConversion );
85d3e5a9 56 CPPUNIT_TEST( ConversionEmpty );
5975f198 57 CPPUNIT_TEST( ConversionWithNULs );
a65ca3e6
VZ
58 CPPUNIT_TEST( ConversionUTF7 );
59 CPPUNIT_TEST( ConversionUTF8 );
5975f198 60 CPPUNIT_TEST( ConversionUTF16 );
a7823b26 61 CPPUNIT_TEST( ConversionUTF32 );
a65ca3e6 62#endif // wxUSE_WCHAR_T
387f829e
VS
63 CPPUNIT_TEST_SUITE_END();
64
65 void ToFromAscii();
a65ca3e6
VZ
66#if wxUSE_WCHAR_T
67 void ConstructorsWithConversion();
85d3e5a9 68 void ConversionEmpty();
5975f198 69 void ConversionWithNULs();
a65ca3e6
VZ
70 void ConversionUTF7();
71 void ConversionUTF8();
5975f198 72 void ConversionUTF16();
a7823b26 73 void ConversionUTF32();
a65ca3e6
VZ
74
75 // test if converting s using the given encoding gives ws and vice versa
76 //
77 // if either of the first 2 arguments is NULL, the conversion is supposed
78 // to fail
b0441359 79 void DoTestConversion(const char *s, const wchar_t *w, wxMBConv& conv);
a65ca3e6
VZ
80#endif // wxUSE_WCHAR_T
81
387f829e
VS
82
83 DECLARE_NO_COPY_CLASS(UnicodeTestCase)
84};
85
86// register in the unnamed registry so that these tests are run by default
87CPPUNIT_TEST_SUITE_REGISTRATION( UnicodeTestCase );
88
89// also include in it's own registry so that these tests can be run alone
1fc9e0d3 90CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UnicodeTestCase, "Unicode" );
387f829e
VS
91
92UnicodeTestCase::UnicodeTestCase()
93{
94}
95
96void UnicodeTestCase::ToFromAscii()
97{
98
99#define TEST_TO_FROM_ASCII(txt) \
100 { \
101 static const char *msg = txt; \
102 wxString s = wxString::FromAscii(msg); \
103 CPPUNIT_ASSERT( strcmp( s.ToAscii() , msg ) == 0 ); \
104 }
105
106 TEST_TO_FROM_ASCII( "Hello, world!" );
107 TEST_TO_FROM_ASCII( "additional \" special \t test \\ component \n :-)" );
108}
109
a65ca3e6
VZ
110#if wxUSE_WCHAR_T
111void UnicodeTestCase::ConstructorsWithConversion()
112{
113