From 68b2e06f70bc05921113cdb84d98ac8e866e4e1e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 24 Jun 2016 23:56:49 +0200 Subject: [PATCH] Improve translated mnemonics unit test Don't switch locale to Japanese, which might not be supported, but just use wxTranslations directly because we only need translations, not full locale support. Also rename the test method to a more descriptive name. --- tests/menu/menu.cpp | 59 +++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/tests/menu/menu.cpp b/tests/menu/menu.cpp index 0c53934587..1a0e48b6f2 100644 --- a/tests/menu/menu.cpp +++ b/tests/menu/menu.cpp @@ -21,6 +21,7 @@ #endif // WX_PRECOMP #include "wx/menu.h" +#include "wx/translation.h" #include "wx/uiaction.h" #include @@ -86,7 +87,9 @@ private: CPPUNIT_TEST( EnableTop ); CPPUNIT_TEST( Count ); CPPUNIT_TEST( Labels ); - CPPUNIT_TEST( i18n ); +#if wxUSE_INTL + CPPUNIT_TEST( TranslatedMnemonics ); +#endif // wxUSE_INTL CPPUNIT_TEST( RadioItems ); CPPUNIT_TEST( RemoveAdd ); CPPUNIT_TEST( ChangeBitmap ); @@ -100,7 +103,9 @@ private: void EnableTop(); void Count(); void Labels(); - void i18n(); +#if wxUSE_INTL + void TranslatedMnemonics(); +#endif // wxUSE_INTL void RadioItems(); void RemoveAdd(); void ChangeBitmap(); @@ -336,35 +341,57 @@ void MenuTestCase::Labels() CPPUNIT_ASSERT_EQUAL( "Foo", wxMenuItem::GetLabelText("&Foo\tCtrl-F") ); } -void MenuTestCase::i18n() +#if wxUSE_INTL + +static wxString +GetTranslatedString(const wxTranslations& trans, const wxString& s) +{ + const wxString* t = trans.GetTranslatedString(s); + return t ? *t : s; +} + +void MenuTestCase::TranslatedMnemonics() { // Check that appended mnemonics are correctly stripped; // see http://trac.wxwidgets.org/ticket/16736 - wxLocale::AddCatalogLookupPathPrefix("./intl"); - CPPUNIT_ASSERT( wxLocale::IsAvailable(wxLANGUAGE_JAPANESE) ); - - wxLocale locale(wxLANGUAGE_JAPANESE, wxLOCALE_DONT_LOAD_DEFAULT); - locale.AddCatalog("internat"); + wxTranslations trans; + trans.SetLanguage(wxLANGUAGE_JAPANESE); + wxFileTranslationsLoader::AddCatalogLookupPathPrefix("./intl"); + CPPUNIT_ASSERT( trans.AddCatalog("internat") ); // Check the translation is being used: - CPPUNIT_ASSERT( wxString("&File") != wxString(_("&File")) ); + CPPUNIT_ASSERT( wxString("&File") != GetTranslatedString(trans, "&File") ); wxString filemenu = m_frame->GetMenuBar()->GetMenuLabel(0); CPPUNIT_ASSERT_EQUAL - ( wxStripMenuCodes(_("&File")), - wxStripMenuCodes(wxGetTranslation(filemenu)) - ); + ( + wxStripMenuCodes(GetTranslatedString(trans, "&File")), + wxStripMenuCodes(GetTranslatedString(trans, filemenu)) + ); // Test strings that have shortcuts. Duplicate non-mnemonic translations // exist for both "Edit" and "View", for ease of comparison - CPPUNIT_ASSERT_EQUAL( _("Edit"), wxStripMenuCodes(_("E&dit\tCtrl+E")) ); + CPPUNIT_ASSERT_EQUAL + ( + GetTranslatedString(trans, "Edit"), + wxStripMenuCodes(GetTranslatedString(trans, "E&dit\tCtrl+E")) + ); - //"Vie&w" also has a space before the (&W) - CPPUNIT_ASSERT_EQUAL( _("View"), wxStripMenuCodes(_("Vie&w\tCtrl+V")) ); + // "Vie&w" also has a space before the (&W) + CPPUNIT_ASSERT_EQUAL + ( + GetTranslatedString(trans, "View"), + wxStripMenuCodes(GetTranslatedString(trans, "Vie&w\tCtrl+V")) + ); // Test a 'normal' mnemonic too: the translation is "Preten&d" - CPPUNIT_ASSERT_EQUAL( "Pretend", wxStripMenuCodes(_("B&ogus")) ); + CPPUNIT_ASSERT_EQUAL + ( + "Pretend", + wxStripMenuCodes(GetTranslatedString(trans, "B&ogus")) + ); } +#endif // wxUSE_INTL void MenuTestCase::RadioItems() {