148 void futureReservedWords(); |
148 void futureReservedWords(); |
149 void throwInsideWithStatement(); |
149 void throwInsideWithStatement(); |
150 void getSetAgent(); |
150 void getSetAgent(); |
151 void reentrancy(); |
151 void reentrancy(); |
152 void incDecNonObjectProperty(); |
152 void incDecNonObjectProperty(); |
|
153 void installTranslatorFunctions_data(); |
153 void installTranslatorFunctions(); |
154 void installTranslatorFunctions(); |
154 void functionScopes(); |
155 void functionScopes(); |
155 void nativeFunctionScopes(); |
156 void nativeFunctionScopes(); |
156 void evaluateProgram(); |
157 void evaluateProgram(); |
157 void collectGarbageAfterConnect(); |
158 void collectGarbageAfterConnect(); |
4116 QVERIFY(ret.isNumber()); |
4117 QVERIFY(ret.isNumber()); |
4117 QCOMPARE(ret.toInt32(), 3); |
4118 QCOMPARE(ret.toInt32(), 3); |
4118 } |
4119 } |
4119 } |
4120 } |
4120 |
4121 |
|
4122 void tst_QScriptEngine::installTranslatorFunctions_data() |
|
4123 { |
|
4124 QTest::addColumn<bool>("useCustomGlobalObject"); |
|
4125 |
|
4126 QTest::newRow("Default global object") << false; |
|
4127 QTest::newRow("Custom global object") << true; |
|
4128 } |
|
4129 |
4121 void tst_QScriptEngine::installTranslatorFunctions() |
4130 void tst_QScriptEngine::installTranslatorFunctions() |
4122 { |
4131 { |
4123 QScriptEngine eng; |
4132 QFETCH(bool, useCustomGlobalObject); |
4124 QScriptValue global = eng.globalObject(); |
4133 |
|
4134 QScriptEngine eng; |
|
4135 QScriptValue globalOrig = eng.globalObject(); |
|
4136 QScriptValue global; |
|
4137 if (useCustomGlobalObject) { |
|
4138 global = eng.newObject(); |
|
4139 eng.setGlobalObject(global); |
|
4140 } else { |
|
4141 global = globalOrig; |
|
4142 } |
4125 QVERIFY(!global.property("qsTranslate").isValid()); |
4143 QVERIFY(!global.property("qsTranslate").isValid()); |
4126 QVERIFY(!global.property("QT_TRANSLATE_NOOP").isValid()); |
4144 QVERIFY(!global.property("QT_TRANSLATE_NOOP").isValid()); |
4127 QVERIFY(!global.property("qsTr").isValid()); |
4145 QVERIFY(!global.property("qsTr").isValid()); |
4128 QVERIFY(!global.property("QT_TR_NOOP").isValid()); |
4146 QVERIFY(!global.property("QT_TR_NOOP").isValid()); |
4129 QVERIFY(!global.property("String").property("prototype").property("arg").isValid()); |
4147 QVERIFY(!globalOrig.property("String").property("prototype").property("arg").isValid()); |
4130 |
4148 |
4131 eng.installTranslatorFunctions(); |
4149 eng.installTranslatorFunctions(); |
4132 QVERIFY(global.property("qsTranslate").isFunction()); |
4150 QVERIFY(global.property("qsTranslate").isFunction()); |
4133 QVERIFY(global.property("QT_TRANSLATE_NOOP").isFunction()); |
4151 QVERIFY(global.property("QT_TRANSLATE_NOOP").isFunction()); |
4134 QVERIFY(global.property("qsTr").isFunction()); |
4152 QVERIFY(global.property("qsTr").isFunction()); |
4135 QVERIFY(global.property("QT_TR_NOOP").isFunction()); |
4153 QVERIFY(global.property("QT_TR_NOOP").isFunction()); |
4136 QVERIFY(global.property("String").property("prototype").property("arg").isFunction()); |
4154 QVERIFY(globalOrig.property("String").property("prototype").property("arg").isFunction()); |
|
4155 |
|
4156 if (useCustomGlobalObject) { |
|
4157 QVERIFY(!globalOrig.property("qsTranslate").isValid()); |
|
4158 QVERIFY(!globalOrig.property("QT_TRANSLATE_NOOP").isValid()); |
|
4159 QVERIFY(!globalOrig.property("qsTr").isValid()); |
|
4160 QVERIFY(!globalOrig.property("QT_TR_NOOP").isValid()); |
|
4161 } |
4137 |
4162 |
4138 { |
4163 { |
4139 QScriptValue ret = eng.evaluate("qsTr('foo')"); |
4164 QScriptValue ret = eng.evaluate("qsTr('foo')"); |
4140 QVERIFY(ret.isString()); |
4165 QVERIFY(ret.isString()); |
4141 QCOMPARE(ret.toString(), QString::fromLatin1("foo")); |
4166 QCOMPARE(ret.toString(), QString::fromLatin1("foo")); |