]> git.saurik.com Git - wxWidgets.git/blob - tests/strings/unicode.cpp
Tweaks for demos on MacOSX
[wxWidgets.git] / tests / strings / unicode.cpp
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
14 #include "testprec.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/textfile.h"
25
26 // ----------------------------------------------------------------------------
27 // test class
28 // ----------------------------------------------------------------------------
29
30 class UnicodeTestCase : public CppUnit::TestCase
31 {
32 public:
33 UnicodeTestCase();
34
35 private:
36 CPPUNIT_TEST_SUITE( UnicodeTestCase );
37 CPPUNIT_TEST( ToFromAscii );
38 CPPUNIT_TEST( TextFileRead );
39 CPPUNIT_TEST_SUITE_END();
40
41 void ToFromAscii();
42 void TextFileRead();
43
44 DECLARE_NO_COPY_CLASS(UnicodeTestCase)
45 };
46
47 // register in the unnamed registry so that these tests are run by default
48 CPPUNIT_TEST_SUITE_REGISTRATION( UnicodeTestCase );
49
50 // also include in it's own registry so that these tests can be run alone
51 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UnicodeTestCase, "UnicodeTestCase" );
52
53 UnicodeTestCase::UnicodeTestCase()
54 {
55 }
56
57 void UnicodeTestCase::ToFromAscii()
58 {
59
60 #define TEST_TO_FROM_ASCII(txt) \
61 { \
62 static const char *msg = txt; \
63 wxString s = wxString::FromAscii(msg); \
64 CPPUNIT_ASSERT( strcmp( s.ToAscii() , msg ) == 0 ); \
65 }
66
67 TEST_TO_FROM_ASCII( "Hello, world!" );
68 TEST_TO_FROM_ASCII( "additional \" special \t test \\ component \n :-)" );
69 }
70
71 void UnicodeTestCase::TextFileRead()
72 {
73 wxTextFile file;
74 bool file_opened = file.Open(_T("testdata.fc"), wxConvLocal);
75
76 CPPUNIT_ASSERT( file_opened );
77
78 static const wxChar *lines[6] = {
79 _T("# this is the test data file for wxFileConfig tests"),
80 _T("value1=one"),
81 _T("# a comment here"),
82 _T("value2=two"),
83 _T("value\\ with\\ spaces\\ inside\\ it=nothing special"),
84 _T("path=$PATH")
85 };
86
87 if( file_opened )
88 {
89 const size_t count = file.GetLineCount();
90 CPPUNIT_ASSERT( count == 6 );
91 for ( size_t n = 0; n < count; n++ )
92 {
93 CPPUNIT_ASSERT( wxStrcmp( file[n].c_str() , lines[n] ) == 0 );
94 }
95 }
96 }