]>
git.saurik.com Git - wxWidgets.git/blob - tests/intl/intltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/intl/intltest.cpp
3 // Purpose: wxLocale unit test
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2007 Vaclav Slavik
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 class IntlTestCase
: public CppUnit::TestCase
35 IntlTestCase() { m_locale
=NULL
; }
38 virtual void tearDown();
41 CPPUNIT_TEST_SUITE( IntlTestCase
);
42 CPPUNIT_TEST( Domain
);
43 CPPUNIT_TEST( Headers
);
44 CPPUNIT_TEST( DateTimeFmt
);
45 CPPUNIT_TEST_SUITE_END();
53 DECLARE_NO_COPY_CLASS(IntlTestCase
)
56 // register in the unnamed registry so that these tests are run by default
57 CPPUNIT_TEST_SUITE_REGISTRATION( IntlTestCase
);
59 // also include in it's own registry so that these tests can be run alone
60 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( IntlTestCase
, "IntlTestCase" );
62 void IntlTestCase::setUp()
64 // Check that French locale is supported, this test doesn't work without it
65 // and all the other function need to check whether m_locale is non-NULL
67 if ( !wxLocale::IsAvailable(wxLANGUAGE_FRENCH
) )
70 wxLocale::AddCatalogLookupPathPrefix("./intl");
72 m_locale
= new wxLocale
;
73 CPPUNIT_ASSERT( m_locale
);
75 // don't load default catalog, it may be unavailable:
76 bool loaded
= m_locale
->Init(wxLANGUAGE_FRENCH
, wxLOCALE_CONV_ENCODING
);
77 CPPUNIT_ASSERT( loaded
);
79 m_locale
->AddCatalog("internat");
82 void IntlTestCase::tearDown()
91 void IntlTestCase::Domain()
96 // _() searches all domains by default:
97 CPPUNIT_ASSERT_EQUAL( "&Ouvrir un fichier", _("&Open bogus file") );
99 // search in our domain only:
100 CPPUNIT_ASSERT_EQUAL( "&Ouvrir un fichier", wxGetTranslation("&Open bogus file", "internat") );
102 // search in a domain that doesn't have this string:
103 CPPUNIT_ASSERT_EQUAL( "&Open bogus file", wxGetTranslation("&Open bogus file", "BogusDomain") );
106 void IntlTestCase::Headers()
111 CPPUNIT_ASSERT_EQUAL( "wxWindows 2.0 i18n sample", m_locale
->GetHeaderValue("Project-Id-Version") );
112 CPPUNIT_ASSERT_EQUAL( "1999-01-13 18:19+0100", m_locale
->GetHeaderValue("POT-Creation-Date") );
113 CPPUNIT_ASSERT_EQUAL( "YEAR-MO-DA HO:MI+ZONE", m_locale
->GetHeaderValue("PO-Revision-Date") );
114 CPPUNIT_ASSERT_EQUAL( "Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>", m_locale
->GetHeaderValue("Last-Translator") );
115 CPPUNIT_ASSERT_EQUAL( "1.0", m_locale
->GetHeaderValue("MIME-Version") );
116 CPPUNIT_ASSERT_EQUAL( "text/plain; charset=iso-8859-1", m_locale
->GetHeaderValue("Content-Type") );
117 CPPUNIT_ASSERT_EQUAL( "8bit", m_locale
->GetHeaderValue("Content-Transfer-Encoding") );
119 // check that it fails with a bogus domain:
120 CPPUNIT_ASSERT_EQUAL( "", m_locale
->GetHeaderValue("POT-Creation-Date", "Bogus") );
122 // and that it fails for nonexisting header:
123 CPPUNIT_ASSERT_EQUAL( "", m_locale
->GetHeaderValue("X-Not-Here") );
127 CompareFormats(const char *msg
, const wxString
& expected
, wxString actual
)
129 if ( actual
.empty() )
131 // this means that GetInfo() failed which can happen, just ignore
136 // glibc uses some extensions in its formats which we need to convert to
138 actual
.Replace("%T", "%H:%M:%S");
139 actual
.Replace("%e", "%d");
142 CPPUNIT_ASSERT_EQUAL_MESSAGE( msg
, expected
, actual
);
145 void IntlTestCase::DateTimeFmt()
151 // glibc also uses dots for French locale separator for some reason (the
152 // standard format uses slashes)
153 static const char *FRENCH_DATE_FMT
= "%d.%m.%Y";
155 static const char *FRENCH_DATE_FMT
= "%d/%m/%y";
158 CompareFormats( "French short date", FRENCH_DATE_FMT
,
159 m_locale
->GetInfo(wxLOCALE_SHORT_DATE_FMT
) );
160 CompareFormats( "French long date", "%a %d %b %Y",
161 m_locale
->GetInfo(wxLOCALE_LONG_DATE_FMT
) );
162 CompareFormats( "French date and time", "%a %d %b %Y %H:%M:%S %Z",
163 m_locale
->GetInfo(wxLOCALE_DATE_TIME_FMT
) );
164 CompareFormats( "French time", "%H:%M:%S",
165 m_locale
->GetInfo(wxLOCALE_TIME_FMT
) );
167 // also test for "C" locale
168 setlocale(LC_ALL
, "C");
170 CompareFormats( "C short date", "%m/%d/%y",
171 m_locale
->GetInfo(wxLOCALE_SHORT_DATE_FMT
) );
172 CompareFormats( "C long date", "%a %b %d %Y",
173 m_locale
->GetInfo(wxLOCALE_LONG_DATE_FMT
) );
174 CompareFormats( "C date and time", "%a %b %d %H:%M:%S %Y",
175 m_locale
->GetInfo(wxLOCALE_DATE_TIME_FMT
) );
176 CompareFormats( "C time", "%H:%M:%S",
177 m_locale
->GetInfo(wxLOCALE_TIME_FMT
) );