summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptengine
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-04-17 11:24:09 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-04-17 11:24:09 (GMT)
commitfd36b47e8758562fc9ff350f292fc9ae9ed91d4e (patch)
tree139e2fc6ee4e1c52bb7f283250d5d72c58617a42 /tests/auto/qscriptengine
parent140a96d0b860b045c18d53c1ac96e77b3893d31c (diff)
parent0ab8fabe3d36f752ce7fdcc0d7e9fe9a4f03e928 (diff)
downloadQt-fd36b47e8758562fc9ff350f292fc9ae9ed91d4e.zip
Qt-fd36b47e8758562fc9ff350f292fc9ae9ed91d4e.tar.gz
Qt-fd36b47e8758562fc9ff350f292fc9ae9ed91d4e.tar.bz2
Merge branch 'qt-4.7-from-4.6' of scm.dev.nokia.troll.no:qt/qt-integration into 4.7-integration
* 'qt-4.7-from-4.6' of scm.dev.nokia.troll.no:qt/qt-integration: (50 commits) Fix mismatched import declarations Doc create magic comment messages in "finished" state make QT_TR_NOOP work in static initializers make HashString and HashStringList objects smaller remove pointless manual assignments from token type enum Update EABI and BWINS DEF files for Symbian Update WebKit DEF files on Symbian Add translation context to qsTr() benchmark QtScript: Add autotest for enumeration of QMetaObject properties Symbol visibility fixes for RVCT4 on Symbian Symbol visibility fixes for RVCT4 on Symbian Symbol visibility fixes for RVCT4 on Symbian Fixes auto-test failure for 9da13ea53aec6d841ba7f416531d6c52d4368df4. QNAM HTTP: Pipelining changes '#' gets inserted to editor when changing FEP modes ComboBox popuplist is not correctly layouted in fullscreen mode Dialogs in landscape mode are not correctly positioned Slider graphics does not look correct in N95 (part2) Fixes tooltips for QGraphicsProxyWidget. ...
Diffstat (limited to 'tests/auto/qscriptengine')
-rw-r--r--tests/auto/qscriptengine/translatable.js2
-rw-r--r--tests/auto/qscriptengine/translatable2.js9
-rw-r--r--tests/auto/qscriptengine/translations/translatable_la.qmbin241 -> 678 bytes
-rw-r--r--tests/auto/qscriptengine/translations/translatable_la.ts38
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp84
5 files changed, 133 insertions, 0 deletions
diff --git a/tests/auto/qscriptengine/translatable.js b/tests/auto/qscriptengine/translatable.js
index 0c948e7..30e139a 100644
--- a/tests/auto/qscriptengine/translatable.js
+++ b/tests/auto/qscriptengine/translatable.js
@@ -5,3 +5,5 @@ var greeting_strings = [
QT_TR_NOOP("Hello"),
QT_TRANSLATE_NOOP("FooContext", "Goodbye")
];
+
+qsTr("One", "not the same one");
diff --git a/tests/auto/qscriptengine/translatable2.js b/tests/auto/qscriptengine/translatable2.js
new file mode 100644
index 0000000..eee66f1
--- /dev/null
+++ b/tests/auto/qscriptengine/translatable2.js
@@ -0,0 +1,9 @@
+qsTr("Three");
+qsTranslate("BarContext", "Four");
+
+var celebration_strings = [
+ QT_TR_NOOP("Happy birthday!"),
+ QT_TRANSLATE_NOOP("BarContext", "Congratulations!")
+];
+
+qsTr("Three", "not the same three");
diff --git a/tests/auto/qscriptengine/translations/translatable_la.qm b/tests/auto/qscriptengine/translations/translatable_la.qm
index 03fcc52..703d0f1 100644
--- a/tests/auto/qscriptengine/translations/translatable_la.qm
+++ b/tests/auto/qscriptengine/translations/translatable_la.qm
Binary files differ
diff --git a/tests/auto/qscriptengine/translations/translatable_la.ts b/tests/auto/qscriptengine/translations/translatable_la.ts
index 3f631de..1598f39 100644
--- a/tests/auto/qscriptengine/translations/translatable_la.ts
+++ b/tests/auto/qscriptengine/translations/translatable_la.ts
@@ -2,6 +2,19 @@
<!DOCTYPE TS>
<TS version="2.0" language="nb_NO">
<context>
+ <name>BarContext</name>
+ <message>
+ <location filename="translatable2.js" line="2"/>
+ <source>Four</source>
+ <translation>Fire</translation>
+ </message>
+ <message>
+ <location filename="translatable2.js" line="6"/>
+ <source>Congratulations!</source>
+ <translation>Gratulerer!</translation>
+ </message>
+</context>
+<context>
<name>FooContext</name>
<message>
<location filename="translatable.js" line="2"/>
@@ -27,8 +40,33 @@
<translation>Hallo</translation>
</message>
<message>
+ <location filename="translatable.js" line="9"/>
+ <source>One</source>
+ <comment>not the same one</comment>
+ <translation>Enda en</translation>
+ </message>
+ <message>
<source>Goodbye</source>
<translation type="obsolete">Farvel</translation>
</message>
</context>
+<context>
+ <name>translatable2</name>
+ <message>
+ <location filename="translatable2.js" line="1"/>
+ <source>Three</source>
+ <translation>Tre</translation>
+ </message>
+ <message>
+ <location filename="translatable2.js" line="5"/>
+ <source>Happy birthday!</source>
+ <translation>Gratulerer med dagen!</translation>
+ </message>
+ <message>
+ <location filename="translatable2.js" line="9"/>
+ <source>Three</source>
+ <comment>not the same three</comment>
+ <translation>Tre andre</translation>
+ </message>
+</context>
</TS>
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index 96043f9..89ea1db 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -156,6 +156,8 @@ private slots:
void installTranslatorFunctions_data();
void installTranslatorFunctions();
void translateScript();
+ void translateWithInvalidArgs_data();
+ void translateWithInvalidArgs();
void functionScopes();
void nativeFunctionScopes();
void evaluateProgram();
@@ -4336,6 +4338,11 @@ void tst_QScriptEngine::installTranslatorFunctions()
}
}
+static QScriptValue callQsTr(QScriptContext *ctx, QScriptEngine *eng)
+{
+ return eng->globalObject().property("qsTr").call(ctx->thisObject(), ctx->argumentsObject());
+}
+
void tst_QScriptEngine::translateScript()
{
QScriptEngine engine;
@@ -4362,6 +4369,17 @@ void tst_QScriptEngine::translateScript()
QCOMPARE(engine.evaluate("eval('qsTranslate(\\'FooContext\\', \\'Two\\')')", fileName).toString(), QString::fromLatin1("To"));
QCOMPARE(engine.evaluate("eval('qsTranslate(\\'FooContext\\', \\'Goodbye\\')')", fileName).toString(), QString::fromLatin1("Farvel"));
+ QCOMPARE(engine.evaluate("qsTranslate('FooContext', 'Goodbye', '', 'UnicodeUTF8')", fileName).toString(), QString::fromLatin1("Farvel"));
+
+ QCOMPARE(engine.evaluate("qsTr('One', 'not the same one')", fileName).toString(), QString::fromLatin1("Enda en"));
+
+ QVERIFY(engine.evaluate("QT_TR_NOOP()").isUndefined());
+ QCOMPARE(engine.evaluate("QT_TR_NOOP('One')").toString(), QString::fromLatin1("One"));
+
+ QVERIFY(engine.evaluate("QT_TRANSLATE_NOOP()").isUndefined());
+ QVERIFY(engine.evaluate("QT_TRANSLATE_NOOP('FooContext')").isUndefined());
+ QCOMPARE(engine.evaluate("QT_TRANSLATE_NOOP('FooContext', 'Two')").toString(), QString::fromLatin1("Two"));
+
// 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"));
@@ -4372,9 +4390,75 @@ void tst_QScriptEngine::translateScript()
QCOMPARE(engine.globalObject().property("qsTr").call(
QScriptValue(), QScriptValueList() << "One").toString(), QString::fromLatin1("One"));
+ // Translate strings from the second script (translatable2.js)
+
+ QString fileName2 = QString::fromLatin1("translatable2.js");
+
+ QCOMPARE(engine.evaluate("qsTr('Three')", fileName2).toString(), QString::fromLatin1("Tre"));
+ QCOMPARE(engine.evaluate("qsTr('Happy birthday!')", fileName2).toString(), QString::fromLatin1("Gratulerer med dagen!"));
+
+ // Not translated because translation is only in translatable.js
+ QCOMPARE(engine.evaluate("qsTr('One')", fileName2).toString(), QString::fromLatin1("One"));
+ QCOMPARE(engine.evaluate("(function() { return qsTr('One'); })()", fileName2).toString(), QString::fromLatin1("One"));
+
+ // For qsTranslate() the filename shouldn't matter
+ QCOMPARE(engine.evaluate("qsTranslate('FooContext', 'Two')", fileName2).toString(), QString::fromLatin1("To"));
+ QCOMPARE(engine.evaluate("qsTranslate('BarContext', 'Congratulations!')", fileName).toString(), QString::fromLatin1("Gratulerer!"));
+
+ // qsTr() should use the innermost filename as context
+ engine.evaluate("function foo(s) { return bar(s); }", fileName);
+ engine.evaluate("function bar(s) { return qsTr(s); }", fileName2);
+ QCOMPARE(engine.evaluate("bar('Three')", fileName2).toString(), QString::fromLatin1("Tre"));
+ QCOMPARE(engine.evaluate("bar('Three')", fileName).toString(), QString::fromLatin1("Tre"));
+ QCOMPARE(engine.evaluate("bar('One')", fileName2).toString(), QString::fromLatin1("One"));
+
+ engine.evaluate("function foo(s) { return bar(s); }", fileName2);
+ engine.evaluate("function bar(s) { return qsTr(s); }", fileName);
+ QCOMPARE(engine.evaluate("bar('Three')", fileName2).toString(), QString::fromLatin1("Three"));
+ QCOMPARE(engine.evaluate("bar('One')", fileName).toString(), QString::fromLatin1("En"));
+ QCOMPARE(engine.evaluate("bar('One')", fileName2).toString(), QString::fromLatin1("En"));
+
+ // Calling qsTr() from a native function
+ engine.globalObject().setProperty("qsTrProxy", engine.newFunction(callQsTr));
+ QCOMPARE(engine.evaluate("qsTrProxy('One')", fileName).toString(), QString::fromLatin1("En"));
+ QCOMPARE(engine.evaluate("qsTrProxy('One')", fileName2).toString(), QString::fromLatin1("One"));
+ QCOMPARE(engine.evaluate("qsTrProxy('Three')", fileName).toString(), QString::fromLatin1("Three"));
+ QCOMPARE(engine.evaluate("qsTrProxy('Three')", fileName2).toString(), QString::fromLatin1("Tre"));
+
QCoreApplication::instance()->removeTranslator(&translator);
}
+void tst_QScriptEngine::translateWithInvalidArgs_data()
+{
+ QTest::addColumn<QString>("expression");
+ QTest::addColumn<QString>("expectedError");
+
+ QTest::newRow("qsTr()") << "qsTr()" << "Error: qsTr() requires at least one argument";
+ QTest::newRow("qsTr(123)") << "qsTr(123)" << "Error: qsTr(): first argument (text) must be a string";
+ QTest::newRow("qsTr('foo', 123)") << "qsTr('foo', 123)" << "Error: qsTr(): second argument (comment) must be a string";
+ QTest::newRow("qsTr('foo', 'bar', 'baz')") << "qsTr('foo', 'bar', 'baz')" << "Error: qsTr(): third argument (n) must be a number";
+ QTest::newRow("qsTr('foo', 'bar', true)") << "qsTr('foo', 'bar', true)" << "Error: qsTr(): third argument (n) must be a number";
+
+ QTest::newRow("qsTranslate()") << "qsTranslate()" << "Error: qsTranslate() requires at least two arguments";
+ QTest::newRow("qsTranslate('foo')") << "qsTranslate('foo')" << "Error: qsTranslate() requires at least two arguments";
+ QTest::newRow("qsTranslate('foo', 123)") << "qsTranslate('foo', 123)" << "Error: qsTranslate(): second argument (text) must be a string";
+ QTest::newRow("qsTranslate('foo', 'bar', 123)") << "qsTranslate('foo', 'bar', 123)" << "Error: qsTranslate(): third argument (comment) must be a string";
+ QTest::newRow("qsTranslate('foo', 'bar', 'baz', 123)") << "qsTranslate('foo', 'bar', 'baz', 123)" << "Error: qsTranslate(): fourth argument (encoding) must be a string";
+ QTest::newRow("qsTranslate('foo', 'bar', 'baz', 'zab', 'rab')") << "qsTranslate('foo', 'bar', 'baz', 'zab', 'rab')" << "Error: qsTranslate(): fifth argument (n) must be a number";
+ QTest::newRow("qsTranslate('foo', 'bar', 'baz', 'zab', 123)") << "qsTranslate('foo', 'bar', 'baz', 'zab', 123)" << "Error: qsTranslate(): invalid encoding 'zab'";
+}
+
+void tst_QScriptEngine::translateWithInvalidArgs()
+{
+ QFETCH(QString, expression);
+ QFETCH(QString, expectedError);
+ QScriptEngine engine;
+ engine.installTranslatorFunctions();
+ QScriptValue result = engine.evaluate(expression);
+ QVERIFY(result.isError());
+ QCOMPARE(result.toString(), expectedError);
+}
+
void tst_QScriptEngine::functionScopes()
{
QScriptEngine eng;