diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-04-14 08:14:40 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2010-04-14 08:14:40 (GMT) |
commit | 62cd360b3f2ef9e9787359a9105fd805b721b49f (patch) | |
tree | 8bb7dd87f0914d59d94d688c32e9244ebb79cbad /tests/auto/qscriptengine/tst_qscriptengine.cpp | |
parent | 4af9cc043370846c52ec21cf874696ee650394c1 (diff) | |
parent | 0dbd8f1b0a6df20e5502bb35e58490a9f99953a7 (diff) | |
download | Qt-62cd360b3f2ef9e9787359a9105fd805b721b49f.zip Qt-62cd360b3f2ef9e9787359a9105fd805b721b49f.tar.gz Qt-62cd360b3f2ef9e9787359a9105fd805b721b49f.tar.bz2 |
Merge remote branch 'origin/4.6' into qt-4.7-from-4.6
Conflicts:
src/script/api/qscriptengine.cpp
Diffstat (limited to 'tests/auto/qscriptengine/tst_qscriptengine.cpp')
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 25d8e3df..96043f9 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -155,6 +155,7 @@ private slots: void incDecNonObjectProperty(); void installTranslatorFunctions_data(); void installTranslatorFunctions(); + void translateScript(); void functionScopes(); void nativeFunctionScopes(); void evaluateProgram(); @@ -4335,6 +4336,45 @@ void tst_QScriptEngine::installTranslatorFunctions() } } +void tst_QScriptEngine::translateScript() +{ + QScriptEngine engine; + + QTranslator translator; + translator.load(":/translations/translatable_la"); + QCoreApplication::instance()->installTranslator(&translator); + engine.installTranslatorFunctions(); + + QString fileName = QString::fromLatin1("translatable.js"); + // Top-level + QCOMPARE(engine.evaluate("qsTr('One')", fileName).toString(), QString::fromLatin1("En")); + QCOMPARE(engine.evaluate("qsTr('Hello')", fileName).toString(), QString::fromLatin1("Hallo")); + // From function + QCOMPARE(engine.evaluate("(function() { return qsTr('One'); })()", fileName).toString(), QString::fromLatin1("En")); + QCOMPARE(engine.evaluate("(function() { return qsTr('Hello'); })()", fileName).toString(), QString::fromLatin1("Hallo")); + // From eval + QCOMPARE(engine.evaluate("eval('qsTr(\\'One\\')')", fileName).toString(), QString::fromLatin1("En")); + QCOMPARE(engine.evaluate("eval('qsTr(\\'Hello\\')')", fileName).toString(), QString::fromLatin1("Hallo")); + + QCOMPARE(engine.evaluate("qsTranslate('FooContext', 'Two')", fileName).toString(), QString::fromLatin1("To")); + QCOMPARE(engine.evaluate("qsTranslate('FooContext', 'Goodbye')", fileName).toString(), QString::fromLatin1("Farvel")); + // From eval + QCOMPARE(engine.evaluate("eval('qsTranslate(\\'FooContext\\', \\'Two\\')')", fileName).toString(), QString::fromLatin1("To")); + QCOMPARE(engine.evaluate("eval('qsTranslate(\\'FooContext\\', \\'Goodbye\\')')", fileName).toString(), QString::fromLatin1("Farvel")); + + // Don't exist in translation + QCOMPARE(engine.evaluate("qsTr('Three')", fileName).toString(), QString::fromLatin1("Three")); + QCOMPARE(engine.evaluate("qsTranslate('FooContext', 'So long')", fileName).toString(), QString::fromLatin1("So long")); + QCOMPARE(engine.evaluate("qsTranslate('BarContext', 'Goodbye')", fileName).toString(), QString::fromLatin1("Goodbye")); + + // From C++ + // There is no context, but it shouldn't crash + QCOMPARE(engine.globalObject().property("qsTr").call( + QScriptValue(), QScriptValueList() << "One").toString(), QString::fromLatin1("One")); + + QCoreApplication::instance()->removeTranslator(&translator); +} + void tst_QScriptEngine::functionScopes() { QScriptEngine eng; |