From a479e0cfae967f8320acba4773b3b44e18bd08ec Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 8 Dec 2011 12:38:48 +0100 Subject: [PATCH] Tests: Fix the language change test. - Use correct overload for QTranslator::translate() - Fix LTR source text - Use QDir::TempDir correctly (check for slash). - Do not copy executable on Windows (which is locked), use arbitrary data instead. - Use Q_OS_MAC Task-number: QTBUG-21402 Change-Id: I6ba1c7c764d4c847278eaff9a96c8cd312ac204d Reviewed-by: Bradley T. Hughes Reviewed-by: Sergio Ahumada Reviewed-by: Rohan McGovern --- .../other/languagechange/languagechange.pro | 2 -- .../languagechange/tst_languagechange.cpp | 34 ++++++++++++------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/auto/other/languagechange/languagechange.pro b/tests/auto/other/languagechange/languagechange.pro index 541a2f05fd..efbc524556 100644 --- a/tests/auto/other/languagechange/languagechange.pro +++ b/tests/auto/other/languagechange/languagechange.pro @@ -2,5 +2,3 @@ CONFIG += testcase TARGET = tst_languagechange QT += widgets core-private testlib SOURCES += tst_languagechange.cpp - -CONFIG += insignificant_test # QTBUG-21402 diff --git a/tests/auto/other/languagechange/tst_languagechange.cpp b/tests/auto/other/languagechange/tst_languagechange.cpp index 97a2683a75..3b77b13275 100644 --- a/tests/auto/other/languagechange/tst_languagechange.cpp +++ b/tests/auto/other/languagechange/tst_languagechange.cpp @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -88,14 +89,15 @@ class TransformTranslator : public QTranslator public: TransformTranslator() : QTranslator() {} TransformTranslator(QObject *parent) : QTranslator(parent) {} - virtual QString translate(const char *context, const char *sourceText, const char *comment = 0) const + QString translate(const char *context, const char *sourceText, + const char *disambiguation = 0, int = -1) const { QByteArray total(context); total.append("::"); total.append(sourceText); - if (comment) { + if (disambiguation) { total.append("::"); - total.append(comment); + total.append(disambiguation); } m_translations.insert(total); QString res; @@ -201,9 +203,10 @@ void tst_languageChange::retranslatability() QFETCH( TranslationSet, expected); // This will always be queried for when a language changes - expected.insert("QApplication::QT_LAYOUT_DIRECTION::Translate this string to the string 'LTR' in left-to-right " - "languages or to 'RTL' in right-to-left languages (such as Hebrew and Arabic) to " - "get proper widget layout."); + expected.insert("QCoreApplication::QT_LAYOUT_DIRECTION::Translate this string to the string 'LTR' in left-to-right " + "languages or to 'RTL' in right-to-left languages (such as Hebrew and Arabic) to " + "get proper widget layout."); + TransformTranslator translator; QTimer::singleShot(500, &translator, SLOT(install())); switch (dialogType) { @@ -212,25 +215,30 @@ void tst_languageChange::retranslatability() break; case ColorDialog: -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC QSKIP("The native color dialog is used on Mac OS"); #else (void)QColorDialog::getColor(); #endif break; case FileDialog: { -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC QSKIP("The native file dialog is used on Mac OS"); #endif QFileDialog dlg; dlg.setOption(QFileDialog::DontUseNativeDialog); - QString tmpParentDir = QDir::tempPath() + "/languagechangetestdir"; - QString tmpDir = tmpParentDir + "/finaldir"; - QString fooName = tmpParentDir + "/foo"; + QString tmpParentDir = QDir::tempPath(); + if (!tmpParentDir.endsWith(QLatin1Char('/'))) + tmpParentDir += QLatin1Char('/'); + tmpParentDir += QStringLiteral("languagechangetestdir"); + const QString tmpDir = tmpParentDir + QStringLiteral("/finaldir"); + const QString fooName = tmpParentDir + QStringLiteral("/foo"); QDir dir; QCOMPARE(dir.mkpath(tmpDir), true); - QCOMPARE(QFile::copy(QApplication::applicationFilePath(), fooName), true); - + QFile fooFile(fooName); + QVERIFY(fooFile.open(QIODevice::WriteOnly|QIODevice::Text)); + fooFile.write("test"); + fooFile.close(); dlg.setDirectory(tmpParentDir); #ifdef Q_OS_WINCE dlg.setDirectory("\\Windows");