]>
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") );
126 static void CompareFormats(const wxString
& expected
, wxString actual
)
128 if ( actual
.empty() )
130 // this means that GetInfo() failed which can happen, just ignore
135 // glibc uses some extensions in its formats which we need to convert to
137 actual
.Replace("%T", "%H:%M:%S");
138 actual
.Replace("%e", "%d");
141 CPPUNIT_ASSERT_EQUAL( expected
, actual
);
144 void IntlTestCase::DateTimeFmt()
149 CompareFormats( "%d.%m.%Y", m_locale
->GetInfo(wxLOCALE_SHORT_DATE_FMT
) );
150 CompareFormats( "%a %d %b %Y", m_locale
->GetInfo(wxLOCALE_LONG_DATE_FMT
) );
151 CompareFormats( "%a %d %b %Y %H:%M:%S %Z",
152 m_locale
->GetInfo(wxLOCALE_DATE_TIME_FMT
) );
153 CompareFormats( "%H:%M:%S", m_locale
->GetInfo(wxLOCALE_TIME_FMT
) );
155 // also test for "C" locale
156 setlocale(LC_ALL
, "C");
158 CompareFormats( "%m/%d/%y", m_locale
->GetInfo(wxLOCALE_SHORT_DATE_FMT
) );
159 CompareFormats( "%a %b %d %Y", m_locale
->GetInfo(wxLOCALE_LONG_DATE_FMT
) );
160 CompareFormats( "%a %b %d %H:%M:%S %Y",
161 m_locale
->GetInfo(wxLOCALE_DATE_TIME_FMT
) );
162 CompareFormats( "%H:%M:%S", m_locale
->GetInfo(wxLOCALE_TIME_FMT
) );