summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-04-20 08:42:52 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-04-20 08:45:21 (GMT)
commitaac0e0a8276b34e9193fed457b13d5832b814276 (patch)
tree03d2511efffa8684e5fdc8c1e91051a029cdaa0e
parentb07d92086464921e651005772fa793e737f1ce65 (diff)
downloadQt-aac0e0a8276b34e9193fed457b13d5832b814276.zip
Qt-aac0e0a8276b34e9193fed457b13d5832b814276.tar.gz
Qt-aac0e0a8276b34e9193fed457b13d5832b814276.tar.bz2
QtScript: Add translation context test
The context is determined from the filename passed to evaluate(), and should be equivalent to QFileInfo(fileName).baseName(). Reviewed-by: Olivier Goffart
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index 60b9112..249d270 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -157,6 +157,8 @@ private slots:
void translateScript();
void translateWithInvalidArgs_data();
void translateWithInvalidArgs();
+ void translationContext_data();
+ void translationContext();
void functionScopes();
void nativeFunctionScopes();
void evaluateProgram();
@@ -4468,6 +4470,54 @@ void tst_QScriptEngine::translateWithInvalidArgs()
QCOMPARE(result.toString(), expectedError);
}
+void tst_QScriptEngine::translationContext_data()
+{
+ QTest::addColumn<QString>("path");
+ QTest::addColumn<QString>("text");
+ QTest::addColumn<QString>("expectedTranslation");
+
+ QTest::newRow("translatable.js") << "translatable.js" << "One" << "En";
+ QTest::newRow("/translatable.js") << "/translatable.js" << "One" << "En";
+ QTest::newRow("/foo/translatable.js") << "/foo/translatable.js" << "One" << "En";
+ QTest::newRow("/foo/bar/translatable.js") << "/foo/bar/translatable.js" << "One" << "En";
+ QTest::newRow("./translatable.js") << "./translatable.js" << "One" << "En";
+ QTest::newRow("../translatable.js") << "../translatable.js" << "One" << "En";
+ QTest::newRow("foo/translatable.js") << "foo/translatable.js" << "One" << "En";
+ QTest::newRow("file:///home/qt/translatable.js") << "file:///home/qt/translatable.js" << "One" << "En";
+ QTest::newRow(":/resources/translatable.js") << ":/resources/translatable.js" << "One" << "En";
+ QTest::newRow("/translatable.js.foo") << "/translatable.js.foo" << "One" << "En";
+ QTest::newRow("/translatable.txt") << "/translatable.txt" << "One" << "En";
+ QTest::newRow("translatable") << "translatable" << "One" << "En";
+ QTest::newRow("foo/translatable") << "foo/translatable" << "One" << "En";
+
+ QTest::newRow("native separators")
+ << (QDir::toNativeSeparators(QDir::currentPath()) + QDir::separator() + "translatable.js")
+ << "One" << "En";
+
+ QTest::newRow("translatable.js/") << "translatable.js/" << "One" << "One";
+ QTest::newRow("nosuchscript.js") << "" << "One" << "One";
+ QTest::newRow("(empty)") << "" << "One" << "One";
+}
+
+void tst_QScriptEngine::translationContext()
+{
+ QTranslator translator;
+ translator.load(":/translations/translatable_la");
+ QCoreApplication::instance()->installTranslator(&translator);
+
+ QScriptEngine engine;
+ engine.installTranslatorFunctions();
+
+ QFETCH(QString, path);
+ QFETCH(QString, text);
+ QFETCH(QString, expectedTranslation);
+ QScriptValue ret = engine.evaluate(QString::fromLatin1("qsTr('%0')").arg(text), path);
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), expectedTranslation);
+
+ QCoreApplication::instance()->removeTranslator(&translator);
+}
+
void tst_QScriptEngine::functionScopes()
{
QScriptEngine eng;