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