]>
git.saurik.com Git - wxWidgets.git/blob - tests/strings/unicode.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/strings/unicode.cpp
3 // Purpose: Unicode unit test
4 // Author: Vadim Zeitlin, Wlodzimierz ABX Skiba
7 // Copyright: (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
14 #include "wx/wxprec.h"
24 #include "wx/textfile.h"
26 #include "wx/cppunit.h"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 class UnicodeTestCase
: public CppUnit::TestCase
38 CPPUNIT_TEST_SUITE( UnicodeTestCase
);
39 CPPUNIT_TEST( ToFromAscii
);
40 CPPUNIT_TEST( TextFileRead
);
41 CPPUNIT_TEST_SUITE_END();
46 DECLARE_NO_COPY_CLASS(UnicodeTestCase
)
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( UnicodeTestCase
);
52 // also include in it's own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UnicodeTestCase
, "UnicodeTestCase" );
55 UnicodeTestCase::UnicodeTestCase()
59 void UnicodeTestCase::ToFromAscii()
62 #define TEST_TO_FROM_ASCII(txt) \
64 static const char *msg = txt; \
65 wxString s = wxString::FromAscii(msg); \
66 CPPUNIT_ASSERT( strcmp( s.ToAscii() , msg ) == 0 ); \
69 TEST_TO_FROM_ASCII( "Hello, world!" );
70 TEST_TO_FROM_ASCII( "additional \" special \t test \\ component \n :-)" );
73 void UnicodeTestCase::TextFileRead()
76 bool file_opened
= file
.Open(_T("testdata.fc"), wxConvLocal
);
78 CPPUNIT_ASSERT( file_opened
);
80 static const wxChar
*lines
[6] = {
81 _T("# this is the test data file for wxFileConfig tests"),
83 _T("# a comment here"),
85 _T("value\\ with\\ spaces\\ inside\\ it=nothing special"),
91 const size_t count
= file
.GetLineCount();
92 CPPUNIT_ASSERT( count
== 6 );
93 for ( size_t n
= 0; n
< count
; n
++ )
95 CPPUNIT_ASSERT( wxStrcmp( file
[n
].c_str() , lines
[n
] ) == 0 );