]> git.saurik.com Git - wxWidgets.git/blob - tests/intl/intltest.cpp
remove sole makefile.dmc in tree
[wxWidgets.git] / tests / intl / intltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/intl/intltest.cpp
3 // Purpose: wxLocale unit test
4 // Author: Vaclav Slavik
5 // Created: 2007-03-26
6 // RCS-ID: $Id$
7 // Copyright: (c) 2007 Vaclav Slavik
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/intl.h"
25
26 #if wxUSE_INTL
27
28 // ----------------------------------------------------------------------------
29 // test class
30 // ----------------------------------------------------------------------------
31
32 class IntlTestCase : public CppUnit::TestCase
33 {
34 public:
35 IntlTestCase() {}
36
37 virtual void setUp();
38 virtual void tearDown();
39
40 private:
41 CPPUNIT_TEST_SUITE( IntlTestCase );
42 CPPUNIT_TEST( Domain );
43 CPPUNIT_TEST( Headers );
44 CPPUNIT_TEST_SUITE_END();
45
46 void Domain();
47 void Headers();
48
49 wxLocale *m_locale;
50
51 DECLARE_NO_COPY_CLASS(IntlTestCase)
52 };
53
54 // register in the unnamed registry so that these tests are run by default
55 CPPUNIT_TEST_SUITE_REGISTRATION( IntlTestCase );
56
57 // also include in it's own registry so that these tests can be run alone
58 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( IntlTestCase, "IntlTestCase" );
59
60 void IntlTestCase::setUp()
61 {
62 wxLocale::AddCatalogLookupPathPrefix("./intl");
63
64 m_locale = new wxLocale;
65 // don't load default catalog, it may be unavailable:
66 bool loaded = m_locale->Init(wxLANGUAGE_FRENCH, wxLOCALE_CONV_ENCODING);
67 CPPUNIT_ASSERT( loaded );
68
69 m_locale->AddCatalog("internat");
70 }
71
72 void IntlTestCase::tearDown()
73 {
74 delete m_locale;
75 m_locale = NULL;
76 }
77
78 void IntlTestCase::Domain()
79 {
80 // _() searches all domains by default:
81 CPPUNIT_ASSERT( _("&Open bogus file") == "&Ouvrir un fichier" );
82
83 // search in our domain only:
84 CPPUNIT_ASSERT( wxGetTranslation("&Open bogus file", "internat") ==
85 "&Ouvrir un fichier" );
86
87 // search in a domain that doesn't have this string:
88 CPPUNIT_ASSERT( wxGetTranslation("&Open bogus file", "BogusDomain") ==
89 "&Open bogus file" );
90 }
91
92 void IntlTestCase::Headers()
93 {
94 CPPUNIT_ASSERT( m_locale->GetHeaderValue("Project-Id-Version") ==
95 "wxWindows 2.0 i18n sample" );
96 CPPUNIT_ASSERT( m_locale->GetHeaderValue("POT-Creation-Date") ==
97 "1999-01-13 18:19+0100" );
98 CPPUNIT_ASSERT( m_locale->GetHeaderValue("PO-Revision-Date") ==
99 "YEAR-MO-DA HO:MI+ZONE" );
100 CPPUNIT_ASSERT( m_locale->GetHeaderValue("Last-Translator") ==
101 "Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>" );
102 CPPUNIT_ASSERT( m_locale->GetHeaderValue("MIME-Version") ==
103 "1.0" );
104 CPPUNIT_ASSERT( m_locale->GetHeaderValue("Content-Type") ==
105 "text/plain; charset=iso-8859-1" );
106 CPPUNIT_ASSERT( m_locale->GetHeaderValue("Content-Transfer-Encoding") ==
107 "8bit" );
108
109 // check that it fails with a bogus domain:
110 CPPUNIT_ASSERT( m_locale->GetHeaderValue("POT-Creation-Date", "Bogus") ==
111 "" );
112
113 // and that it fails for nonexisting header:
114 CPPUNIT_ASSERT( m_locale->GetHeaderValue("X-Not-Here") == "" );
115 }
116
117 #endif // wxUSE_INTL