diff options
Diffstat (limited to 'tests')
32 files changed, 919 insertions, 454 deletions
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 9ef9ce8a16..d72f745d25 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -1,103 +1,118 @@ TEMPLATE = subdirs + +METATYPETESTS += \ + qdeclarativemetatype \ + qmetaobjectbuilder + +PUBLICTESTS += \ + examples \ + geometry \ + nodes \ + parserstress \ + qdeclarativecomponent \ + qdeclarativecontext \ + qdeclarativeengine \ + qdeclarativeerror \ + qdeclarativefolderlistmodel \ + qdeclarativeinfo \ + qdeclarativelayoutitem \ + qdeclarativelistreference \ + qdeclarativemoduleplugin \ + qdeclarativeparticles \ + qdeclarativepixmapcache \ + qdeclarativeqt \ + qdeclarativeview \ + qdeclarativeviewer \ + qdeclarativexmlhttprequest \ + moduleqt47 + +PRIVATETESTS += \ + qdeclarativeanchors \ + qdeclarativeanimatedimage \ + qdeclarativeanimations \ + qdeclarativeapplication \ + qdeclarativebehaviors \ + qdeclarativebinding \ + qdeclarativeborderimage \ + qdeclarativeconnection \ + qdeclarativedebug \ + qdeclarativedebugclient \ + qdeclarativedebughelper \ + qdeclarativedebugservice \ + qdeclarativeecmascript \ + qdeclarativeflickable \ + qdeclarativeflipable \ + qdeclarativefocusscope \ + qdeclarativefontloader \ + qdeclarativegridview \ + qdeclarativeimage \ + qdeclarativeimageprovider \ + qdeclarativeinstruction \ + qdeclarativeitem \ + qdeclarativelanguage \ + qdeclarativelistmodel \ + qdeclarativelistview \ + qdeclarativeloader \ + qdeclarativemousearea \ + qdeclarativepathview \ + qdeclarativepincharea \ + qdeclarativepositioners \ + qdeclarativeproperty \ + qdeclarativepropertymap \ + qdeclarativerepeater \ + # qdeclarativescriptdebugging \ + qdeclarativesmoothedanimation \ + qdeclarativespringanimation \ + qdeclarativestyledtext \ + qdeclarativesqldatabase \ + qdeclarativestates \ + qdeclarativesystempalette \ + qdeclarativetext \ + qdeclarativetextedit \ + qdeclarativetextinput \ + qdeclarativetimer \ + qdeclarativevaluetypes \ + qdeclarativevisualdatamodel \ + qdeclarativeworkerscript \ + qdeclarativexmllistmodel \ + qpacketprotocol \ + qdeclarativev4 \ + v8 + +SGTESTS = \ + qsganimatedimage \ + qsgborderimage \ + qsgcanvas \ + qsgflickable \ + qsgflipable \ + qsgfocusscope \ + qsggridview \ + qsgimage \ + qsgitem \ + qsglistview \ + qsgloader \ + qsgmousearea \ + qsgpathview \ + qsgpincharea \ + qsgpositioners \ + qsgrepeater \ + qsgtext \ + qsgtextedit \ + qsgtextinput \ + qsgvisualdatamodel \ + + +SUBDIRS += $$PUBLICTESTS + !symbian: { -SUBDIRS += \ - qdeclarativemetatype \ - qmetaobjectbuilder + SUBDIRS += $$METATYPETESTS } -SUBDIRS += \ - examples \ - parserstress \ - qdeclarativecomponent \ - qdeclarativecontext \ - qdeclarativeengine \ - qdeclarativeerror \ - qdeclarativefolderlistmodel \ - qdeclarativeinfo \ - qdeclarativelayoutitem \ - qdeclarativelistreference \ - qdeclarativemoduleplugin \ - qdeclarativeparticles \ - qdeclarativepixmapcache \ - qdeclarativeqt \ - qdeclarativeview \ - qdeclarativeviewer \ - qdeclarativexmlhttprequest \ - moduleqt47 - contains(QT_CONFIG, private_tests) { - SUBDIRS += \ - qdeclarativeanchors \ - qdeclarativeanimatedimage \ - qdeclarativeanimations \ - qdeclarativeapplication \ - qdeclarativebehaviors \ - qdeclarativebinding \ - qdeclarativeborderimage \ - qdeclarativechangeset \ - qdeclarativeconnection \ - qdeclarativedebug \ - qdeclarativedebugclient \ - qdeclarativedebugservice \ - qdeclarativeecmascript \ - qdeclarativeflickable \ - qdeclarativeflipable \ - qdeclarativefocusscope \ - qdeclarativefontloader \ - qdeclarativegridview \ - qdeclarativeimage \ - qdeclarativeimageprovider \ - qdeclarativeinstruction \ - qdeclarativeitem \ - qdeclarativelanguage \ - qdeclarativelistmodel \ - qdeclarativelistview \ - qdeclarativeloader \ - qdeclarativemousearea \ - qdeclarativepathview \ - qdeclarativepincharea \ - qdeclarativepositioners \ - qdeclarativeproperty \ - qdeclarativepropertymap \ - qdeclarativerepeater \ - qdeclarativesmoothedanimation \ - qdeclarativespringanimation \ - qdeclarativestyledtext \ - qdeclarativesqldatabase \ - qdeclarativestates \ - qdeclarativesystempalette \ - qdeclarativetext \ - qdeclarativetextedit \ - qdeclarativetextinput \ - qdeclarativetimer \ - qdeclarativevaluetypes \ - qdeclarativevisualdatamodel \ - qdeclarativeworkerscript \ - qdeclarativexmllistmodel \ - qpacketprotocol \ - qdeclarativev4 \ - qsganimatedimage \ - qsgborderimage \ - qsgcanvas \ - qsgflickable \ - qsgflipable \ - qsgfocusscope \ - qsggridview \ - qsgimage \ - qsgitem \ - qsglistview \ - qsgloader \ - qsgmousearea \ - qsgpathview \ - qsgpincharea \ - qsgpositioners \ - qsgrepeater \ - qsgtext \ - qsgtextedit \ - qsgtextinput \ - qsgvisualdatamodel - + SUBDIRS += $$PRIVATETESTS + SUBDIRS += $$SGTESTS } # Tests which should run in Pulse PULSE_TESTS = $$SUBDIRS + diff --git a/tests/auto/declarative/node/nodes.pro b/tests/auto/declarative/nodes/nodes.pro index 19d3b09a43..19d3b09a43 100644 --- a/tests/auto/declarative/node/nodes.pro +++ b/tests/auto/declarative/nodes/nodes.pro diff --git a/tests/auto/declarative/node/tst_nodestest.cpp b/tests/auto/declarative/nodes/tst_nodestest.cpp index a1b0a6ac91..a1b0a6ac91 100644 --- a/tests/auto/declarative/node/tst_nodestest.cpp +++ b/tests/auto/declarative/nodes/tst_nodestest.cpp diff --git a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp index 97cd0c9ea5..fdb8ff7dc2 100644 --- a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp +++ b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp @@ -342,7 +342,7 @@ void tst_qdeclarativecontext::setContextProperty() QDeclarativeContext ctxt(engine.rootContext()); ctxt.setContextProperty("ctxtProp", QVariant()); - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>:1: TypeError: Result of expression 'ctxtProp' [undefined] is not an object."); + QTest::ignoreMessage(QtWarningMsg, "<Unknown File>:1: TypeError: Cannot read property 'a' of undefined"); QObject *obj = component.create(&ctxt); QVariant v = obj->property("obj"); diff --git a/tests/auto/declarative/qdeclarativedebughelper/tst_qdeclarativedebughelper.cpp b/tests/auto/declarative/qdeclarativedebughelper/tst_qdeclarativedebughelper.cpp index 5fecd29c51..505361bc27 100644 --- a/tests/auto/declarative/qdeclarativedebughelper/tst_qdeclarativedebughelper.cpp +++ b/tests/auto/declarative/qdeclarativedebughelper/tst_qdeclarativedebughelper.cpp @@ -52,7 +52,6 @@ class tst_qdeclarativedebughelper : public QObject { Q_OBJECT private slots: - void getScriptEngine(); void setAnimationSlowDownFactor(); void enableDebugging(); }; @@ -71,15 +70,6 @@ public: } }; -void tst_qdeclarativedebughelper::getScriptEngine() -{ - QDeclarativeEngine engine; - - QScriptEngine *scriptEngine = QDeclarativeDebugHelper::getScriptEngine(&engine); - QVERIFY(scriptEngine); - QCOMPARE(scriptEngine, QDeclarativeEnginePrivate::getScriptEngine(&engine)); -} - void tst_qdeclarativedebughelper::setAnimationSlowDownFactor() { TestAnimation animation; diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/propertyAssignmentErrors.qml b/tests/auto/declarative/qdeclarativeecmascript/data/propertyAssignmentErrors.qml index a778dcc8b6..0455271dac 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/propertyAssignmentErrors.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/propertyAssignmentErrors.qml @@ -6,17 +6,24 @@ QtObject { property int a property variant b + property bool test1: false; + property bool test2: false; + Component.onCompleted: { try { root.a = undefined; } catch(e) { - console.log (e.fileName + ":" + e.lineNumber + ":" + e); + if (e.message == "Cannot assign [undefined] to int" && + e.stack.indexOf("propertyAssignmentErrors.qml:14") != -1) + root.test1 = true; } try { root.a = "Hello"; } catch(e) { - console.log (e.fileName + ":" + e.lineNumber + ":" + e); + if (e.message == "Cannot assign QString to int" && + e.stack.indexOf("propertyAssignmentErrors.qml:22") != -1) + root.test2 = true; } } } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml index b7bb366698..7fcf2bebd7 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml @@ -4,5 +4,5 @@ import "qtbug_11600.js" as Test QtObject { id: goo - property bool test: undefined == goo.Test.foo + property bool test: undefined == goo.Test } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunctionFail.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunctionFail.qml index b1342fea90..9b07080054 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunctionFail.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunctionFail.qml @@ -11,6 +11,7 @@ QtObject { id: root property MyScarceResourceObject a: MyScarceResourceObject { id: scarceResourceProvider } property variant scarceResourceCopy; + property string srp_name: a.toString(); function retrieveScarceResource() { root.scarceResourceCopy = scarceResourceProvider.scarceResource(); // common syntax error, should throw exception diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index cabaddeeb7..1ed22532e6 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -49,7 +49,6 @@ #include <QtCore/qdir.h> #include <QtCore/qnumeric.h> #include <private/qdeclarativeengine_p.h> -#include <private/qdeclarativeglobalscriptclass_p.h> #include <private/qscriptdeclarativeclass_p.h> #include "testtypes.h" #include "testhttpserver.h" @@ -179,7 +178,6 @@ private slots: void aliasBindingsAssignCorrectly(); void aliasBindingsOverrideTarget(); void aliasWritesOverrideBindings(); - void pushCleanContext(); void realToInt(); void include(); @@ -1199,7 +1197,11 @@ void tst_qdeclarativeecmascript::functionErrors() url = componentTwo.url().toString(); object = componentTwo.create(); QVERIFY(object != 0); - warning = url + QLatin1String(":16: TypeError: Result of expression 'scarceResourceProvider.scarceResource' [[object Object]] is not a function."); + + QString srpname = object->property("srp_name").toString(); + + warning = url + QLatin1String(":17: TypeError: Property 'scarceResource' of object ") + srpname + + QLatin1String(" is not a function"); QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); // we expect a meaningful warning to be printed. QMetaObject::invokeMethod(object, "retrieveScarceResource"); delete object; @@ -1214,15 +1216,12 @@ void tst_qdeclarativeecmascript::propertyAssignmentErrors() QString url = component.url().toString(); - QString warning1 = url + ":11:Error: Cannot assign [undefined] to int"; - QString warning2 = url + ":17:Error: Cannot assign QString to int"; - - QTest::ignoreMessage(QtDebugMsg, warning1.toLatin1().constData()); - QTest::ignoreMessage(QtDebugMsg, warning2.toLatin1().constData()); - QObject *object = component.create(); QVERIFY(object != 0); + QCOMPARE(object->property("test1").toBool(), true); + QCOMPARE(object->property("test2").toBool(), true); + delete object; } @@ -1277,7 +1276,7 @@ void tst_qdeclarativeecmascript::exceptionClearsOnReeval() QDeclarativeComponent component(&engine, TEST_FILE("exceptionClearsOnReeval.qml")); QString url = component.url().toString(); - QString warning = url + ":4: TypeError: Result of expression 'objectProperty' [null] is not an object."; + QString warning = url + ":4: TypeError: Cannot read property 'objectProperty' of null"; QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); @@ -1490,56 +1489,119 @@ void tst_qdeclarativeecmascript::regExpBug() delete object; } +static inline bool evaluate_error(QV8Engine *engine, v8::Handle<v8::Object> o, const char *source) +{ + QString functionSource = QLatin1String("(function(object) { return ") + + QLatin1String(source) + QLatin1String(" })"); + v8::TryCatch tc; + v8::Local<v8::Script> program = v8::Script::Compile(engine->toString(functionSource)); + if (tc.HasCaught()) + return false; + v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(program->Run()); + if (function.IsEmpty()) + return false; + v8::Handle<v8::Value> args[] = { o }; + function->Call(engine->global(), 1, args); + return tc.HasCaught(); +} + +static inline bool evaluate_value(QV8Engine *engine, v8::Handle<v8::Object> o, + const char *source, v8::Handle<v8::Value> result) +{ + QString functionSource = QLatin1String("(function(object) { return ") + + QLatin1String(source) + QLatin1String(" })"); + v8::TryCatch tc; + v8::Local<v8::Script> program = v8::Script::Compile(engine->toString(functionSource)); + if (tc.HasCaught()) + return false; + v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(program->Run()); + if (function.IsEmpty()) + return false; + v8::Handle<v8::Value> args[] = { o }; + + v8::Handle<v8::Value> value = function->Call(engine->global(), 1, args); + + if (tc.HasCaught()) + return false; + + return value->StrictEquals(result); +} + +static inline v8::Handle<v8::Value> evaluate(QV8Engine *engine, v8::Handle<v8::Object> o, + const char *source) +{ + QString functionSource = QLatin1String("(function(object) { return ") + + QLatin1String(source) + QLatin1String(" })"); + v8::TryCatch tc; + v8::Local<v8::Script> program = v8::Script::Compile(engine->toString(functionSource)); + if (tc.HasCaught()) + return v8::Handle<v8::Value>(); + v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(program->Run()); + if (function.IsEmpty()) + return v8::Handle<v8::Value>(); + v8::Handle<v8::Value> args[] = { o }; + + v8::Handle<v8::Value> value = function->Call(engine->global(), 1, args); + + if (tc.HasCaught()) + return v8::Handle<v8::Value>(); + return value; +} + +#define EVALUATE_ERROR(source) evaluate_error(engine, object, source) +#define EVALUATE_VALUE(source, result) evaluate_value(engine, object, source, result) +#define EVALUATE(source) evaluate(engine, object, source) + void tst_qdeclarativeecmascript::callQtInvokables() { MyInvokableObject o; QDeclarativeEngine qmlengine; QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(&qmlengine); - QScriptEngine *engine = &ep->scriptEngine; + + QV8Engine *engine = &ep->v8engine; - QStringList names; QList<QScriptValue> values; - names << QLatin1String("object"); values << ep->objectClass->newQObject(&o); - names << QLatin1String("undefined"); values << engine->undefinedValue(); + v8::HandleScope handle_scope; + v8::Context::Scope scope(engine->context()); - ep->globalClass->explicitSetProperty(names, values); + v8::Local<v8::Object> object = engine->newQObject(&o)->ToObject(); // Non-existent methods o.reset(); - QCOMPARE(engine->evaluate("object.method_nonexistent()").isError(), true); + QVERIFY(EVALUATE_ERROR("object.method_nonexistent()")); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), -1); QCOMPARE(o.actuals().count(), 0); o.reset(); - QCOMPARE(engine->evaluate("object.method_nonexistent(10, 11)").isError(), true); + QVERIFY(EVALUATE_ERROR("object.method_nonexistent(10, 11)")); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), -1); QCOMPARE(o.actuals().count(), 0); // Insufficient arguments o.reset(); - QCOMPARE(engine->evaluate("object.method_int()").isError(), true); + QVERIFY(EVALUATE_ERROR("object.method_int()")); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), -1); QCOMPARE(o.actuals().count(), 0); o.reset(); - QCOMPARE(engine->evaluate("object.method_intint(10)").isError(), true); + QVERIFY(EVALUATE_ERROR("object.method_intint(10)")); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), -1); QCOMPARE(o.actuals().count(), 0); // Excessive arguments o.reset(); - QCOMPARE(engine->evaluate("object.method_int(10, 11)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_int(10, 11)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 8); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(10)); o.reset(); - QCOMPARE(engine->evaluate("object.method_intint(10, 11, 12)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_intint(10, 11, 12)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 9); QCOMPARE(o.actuals().count(), 2); @@ -1548,27 +1610,28 @@ void tst_qdeclarativeecmascript::callQtInvokables() // Test return types o.reset(); - QCOMPARE(engine->evaluate("object.method_NoArgs()").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_NoArgs()", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 0); QCOMPARE(o.actuals().count(), 0); o.reset(); - QVERIFY(engine->evaluate("object.method_NoArgs_int()").strictlyEquals(QScriptValue(engine, 6))); + QVERIFY(EVALUATE_VALUE("object.method_NoArgs_int()", v8::Integer::New(6))); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 1); QCOMPARE(o.actuals().count(), 0); o.reset(); - QVERIFY(engine->evaluate("object.method_NoArgs_real()").strictlyEquals(QScriptValue(engine, 19.75))); + QVERIFY(EVALUATE_VALUE("object.method_NoArgs_real()", v8::Number::New(19.75))); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 2); QCOMPARE(o.actuals().count(), 0); o.reset(); { - QScriptValue ret = engine->evaluate("object.method_NoArgs_QPointF()"); - QCOMPARE(ret.toVariant(), QVariant(QPointF(123, 4.5))); + v8::Handle<v8::Value> ret = EVALUATE("object.method_NoArgs_QPointF()"); + QVERIFY(!ret.IsEmpty()); + QCOMPARE(engine->toVariant(ret, -1), QVariant(QPointF(123, 4.5))); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 3); QCOMPARE(o.actuals().count(), 0); @@ -1576,81 +1639,83 @@ void tst_qdeclarativeecmascript::callQtInvokables() o.reset(); { - QScriptValue ret = engine->evaluate("object.method_NoArgs_QObject()"); - QVERIFY(ret.isQObject()); - QCOMPARE(ret.toQObject(), (QObject *)&o); + v8::Handle<v8::Value> ret = EVALUATE("object.method_NoArgs_QObject()"); + QCOMPARE(engine->toQObject(ret), (QObject *)&o); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 4); QCOMPARE(o.actuals().count(), 0); } o.reset(); - QCOMPARE(engine->evaluate("object.method_NoArgs_unknown()").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_NoArgs_unknown()", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 5); QCOMPARE(o.actuals().count(), 0); + // XXX enable once qml/qtscript integration is implemented +#if 0 o.reset(); { - QScriptValue ret = engine->evaluate("object.method_NoArgs_QScriptValue()"); - QVERIFY(ret.isString()); - QCOMPARE(ret.toString(), QString("Hello world")); + v8::Handle<v8::Value> ret = EVALUATE("object.method_NoArgs_QScriptValue()"); + QVERIFY(ret->IsString()); + QCOMPARE(engine->toString(ret), QString("Hello world")); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 6); QCOMPARE(o.actuals().count(), 0); } +#endif o.reset(); - QVERIFY(engine->evaluate("object.method_NoArgs_QVariant()").strictlyEquals(QScriptValue(engine, "QML rocks"))); + QVERIFY(EVALUATE_VALUE("object.method_NoArgs_QVariant()", engine->toString("QML rocks"))); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 7); QCOMPARE(o.actuals().count(), 0); // Test arg types o.reset(); - QCOMPARE(engine->evaluate("object.method_int(94)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_int(94)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 8); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(94)); o.reset(); - QCOMPARE(engine->evaluate("object.method_int(\"94\")").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_int(\"94\")", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 8); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(94)); o.reset(); - QCOMPARE(engine->evaluate("object.method_int(\"not a number\")").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_int(\"not a number\")", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 8); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(0)); o.reset(); - QCOMPARE(engine->evaluate("object.method_int(null)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_int(null)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 8); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(0)); o.reset(); - QCOMPARE(engine->evaluate("object.method_int(undefined)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_int(undefined)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 8); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(0)); o.reset(); - QCOMPARE(engine->evaluate("object.method_int(object)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_int(object)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 8); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(0)); o.reset(); - QCOMPARE(engine->evaluate("object.method_intint(122, 9)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_intint(122, 9)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 9); QCOMPARE(o.actuals().count(), 2); @@ -1658,56 +1723,56 @@ void tst_qdeclarativeecmascript::callQtInvokables() QCOMPARE(o.actuals().at(1), QVariant(9)); o.reset(); - QCOMPARE(engine->evaluate("object.method_real(94.3)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_real(94.3)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 10); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(94.3)); o.reset(); - QCOMPARE(engine->evaluate("object.method_real(\"94.3\")").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_real(\"94.3\")", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 10); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(94.3)); o.reset(); - QCOMPARE(engine->evaluate("object.method_real(\"not a number\")").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_real(\"not a number\")", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 10); QCOMPARE(o.actuals().count(), 1); QVERIFY(qIsNaN(o.actuals().at(0).toDouble())); o.reset(); - QCOMPARE(engine->evaluate("object.method_real(null)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_real(null)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 10); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(0)); o.reset(); - QCOMPARE(engine->evaluate("object.method_real(undefined)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_real(undefined)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 10); QCOMPARE(o.actuals().count(), 1); QVERIFY(qIsNaN(o.actuals().at(0).toDouble())); o.reset(); - QCOMPARE(engine->evaluate("object.method_real(object)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_real(object)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 10); QCOMPARE(o.actuals().count(), 1); QVERIFY(qIsNaN(o.actuals().at(0).toDouble())); o.reset(); - QCOMPARE(engine->evaluate("object.method_QString(\"Hello world\")").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QString(\"Hello world\")", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 11); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant("Hello world")); o.reset(); - QCOMPARE(engine->evaluate("object.method_QString(19)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QString(19)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 11); QCOMPARE(o.actuals().count(), 1); @@ -1716,7 +1781,7 @@ void tst_qdeclarativeecmascript::callQtInvokables() o.reset(); { QString expected = "MyInvokableObject(0x" + QString::number((quintptr)&o, 16) + ")"; - QCOMPARE(engine->evaluate("object.method_QString(object)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QString(object)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 11); QCOMPARE(o.actuals().count(), 1); @@ -1724,126 +1789,128 @@ void tst_qdeclarativeecmascript::callQtInvokables() } o.reset(); - QCOMPARE(engine->evaluate("object.method_QString(null)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QString(null)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 11); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(QString())); o.reset(); - QCOMPARE(engine->evaluate("object.method_QString(undefined)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QString(undefined)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 11); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(QString())); o.reset(); - QCOMPARE(engine->evaluate("object.method_QPointF(0)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QPointF(0)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 12); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(QPointF())); o.reset(); - QCOMPARE(engine->evaluate("object.method_QPointF(null)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QPointF(null)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 12); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(QPointF())); o.reset(); - QCOMPARE(engine->evaluate("object.method_QPointF(undefined)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QPointF(undefined)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 12); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(QPointF())); o.reset(); - QCOMPARE(engine->evaluate("object.method_QPointF(object)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QPointF(object)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 12); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(QPointF())); o.reset(); - QCOMPARE(engine->evaluate("object.method_QPointF(object.method_get_QPointF())").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QPointF(object.method_get_QPointF())", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 12); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(QPointF(99.3, -10.2))); o.reset(); - QCOMPARE(engine->evaluate("object.method_QPointF(object.method_get_QPoint())").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QPointF(object.method_get_QPoint())", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 12); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(QPointF(9, 12))); o.reset(); - QCOMPARE(engine->evaluate("object.method_QObject(0)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QObject(0)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 13); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)0)); o.reset(); - QCOMPARE(engine->evaluate("object.method_QObject(\"Hello world\")").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QObject(\"Hello world\")", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 13); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)0)); o.reset(); - QCOMPARE(engine->evaluate("object.method_QObject(null)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QObject(null)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 13); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)0)); o.reset(); - QCOMPARE(engine->evaluate("object.method_QObject(undefined)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QObject(undefined)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 13); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)0)); o.reset(); - QCOMPARE(engine->evaluate("object.method_QObject(object)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QObject(object)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 13); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)&o)); + // XXX enable once qml/qtscript integration is implemented +#if 0 o.reset(); - QCOMPARE(engine->evaluate("object.method_QScriptValue(null)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QScriptValue(null)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 14); QCOMPARE(o.actuals().count(), 1); QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(0)).isNull()); o.reset(); - QCOMPARE(engine->evaluate("object.method_QScriptValue(undefined)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QScriptValue(undefined)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 14); QCOMPARE(o.actuals().count(), 1); QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(0)).isUndefined()); o.reset(); - QCOMPARE(engine->evaluate("object.method_QScriptValue(19)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QScriptValue(19)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 14); QCOMPARE(o.actuals().count(), 1); QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(0)).strictlyEquals(QScriptValue(engine, 19))); o.reset(); - QCOMPARE(engine->evaluate("object.method_QScriptValue([19, 20])").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QScriptValue([19, 20])", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 14); QCOMPARE(o.actuals().count(), 1); QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(0)).isArray()); o.reset(); - QCOMPARE(engine->evaluate("object.method_intQScriptValue(4, null)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_intQScriptValue(4, null)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 15); QCOMPARE(o.actuals().count(), 2); @@ -1851,7 +1918,7 @@ void tst_qdeclarativeecmascript::callQtInvokables() QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(1)).isNull()); o.reset(); - QCOMPARE(engine->evaluate("object.method_intQScriptValue(8, undefined)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_intQScriptValue(8, undefined)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 15); QCOMPARE(o.actuals().count(), 2); @@ -1859,7 +1926,7 @@ void tst_qdeclarativeecmascript::callQtInvokables() QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(1)).isUndefined()); o.reset(); - QCOMPARE(engine->evaluate("object.method_intQScriptValue(3, 19)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_intQScriptValue(3, 19)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 15); QCOMPARE(o.actuals().count(), 2); @@ -1867,28 +1934,29 @@ void tst_qdeclarativeecmascript::callQtInvokables() QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(1)).strictlyEquals(QScriptValue(engine, 19))); o.reset(); - QCOMPARE(engine->evaluate("object.method_intQScriptValue(44, [19, 20])").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_intQScriptValue(44, [19, 20])", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 15); QCOMPARE(o.actuals().count(), 2); QCOMPARE(o.actuals().at(0), QVariant(44)); QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(1)).isArray()); +#endif o.reset(); - QCOMPARE(engine->evaluate("object.method_overload()").isError(), true); + QVERIFY(EVALUATE_ERROR("object.method_overload()")); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), -1); QCOMPARE(o.actuals().count(), 0); o.reset(); - QCOMPARE(engine->evaluate("object.method_overload(10)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_overload(10)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 16); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(10)); o.reset(); - QCOMPARE(engine->evaluate("object.method_overload(10, 11)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_overload(10, 11)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 17); QCOMPARE(o.actuals().count(), 2); @@ -1896,21 +1964,21 @@ void tst_qdeclarativeecmascript::callQtInvokables() QCOMPARE(o.actuals().at(1), QVariant(11)); o.reset(); - QCOMPARE(engine->evaluate("object.method_overload(\"Hello\")").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_overload(\"Hello\")", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 18); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(QString("Hello"))); o.reset(); - QCOMPARE(engine->evaluate("object.method_with_enum(9)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_with_enum(9)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 19); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(9)); o.reset(); - QVERIFY(engine->evaluate("object.method_default(10)").strictlyEquals(QScriptValue(19))); + QVERIFY(EVALUATE_VALUE("object.method_default(10)", v8::Integer::New(19))); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 20); QCOMPARE(o.actuals().count(), 2); @@ -1918,7 +1986,7 @@ void tst_qdeclarativeecmascript::callQtInvokables() QCOMPARE(o.actuals().at(1), QVariant(19)); o.reset(); - QVERIFY(engine->evaluate("object.method_default(10, 13)").strictlyEquals(QScriptValue(13))); + QVERIFY(EVALUATE_VALUE("object.method_default(10, 13)", v8::Integer::New(13))); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 20); QCOMPARE(o.actuals().count(), 2); @@ -1926,14 +1994,14 @@ void tst_qdeclarativeecmascript::callQtInvokables() QCOMPARE(o.actuals().at(1), QVariant(13)); o.reset(); - QCOMPARE(engine->evaluate("object.method_inherited(9)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_inherited(9)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), -3); QCOMPARE(o.actuals().count(), 1); QCOMPARE(o.actuals().at(0), QVariant(9)); o.reset(); - QCOMPARE(engine->evaluate("object.method_QVariant(9)").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QVariant(9)", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 21); QCOMPARE(o.actuals().count(), 2); @@ -1941,7 +2009,7 @@ void tst_qdeclarativeecmascript::callQtInvokables() QCOMPARE(o.actuals().at(1), QVariant()); o.reset(); - QCOMPARE(engine->evaluate("object.method_QVariant(\"Hello\", \"World\")").isUndefined(), true); + QVERIFY(EVALUATE_VALUE("object.method_QVariant(\"Hello\", \"World\")", v8::Undefined())); QCOMPARE(o.error(), false); QCOMPARE(o.invoked(), 21); QCOMPARE(o.actuals().count(), 2); @@ -2236,7 +2304,8 @@ void tst_qdeclarativeecmascript::ownership() QVERIFY(own.object != 0); QObject *object = component.create(context); - QDeclarativeEnginePrivate::getScriptEngine(&engine)->collectGarbage(); + + engine.collectGarbage(); QCoreApplication::processEvents(QEventLoop::DeferredDeletion); @@ -2253,7 +2322,8 @@ void tst_qdeclarativeecmascript::ownership() QVERIFY(own.object != 0); QObject *object = component.create(context); - QDeclarativeEnginePrivate::getScriptEngine(&engine)->collectGarbage(); + + engine.collectGarbage(); QCoreApplication::processEvents(QEventLoop::DeferredDeletion); @@ -2337,6 +2407,7 @@ void tst_qdeclarativeecmascript::ownershipCustomReturnValue() delete object; } + engine.collectGarbage(); QCoreApplication::instance()->processEvents(QEventLoop::DeferredDeletion); QVERIFY(source.value == 0); @@ -2500,6 +2571,8 @@ void tst_qdeclarativeecmascript::signalWithUnknownTypes() void tst_qdeclarativeecmascript::moduleApi() { + QSKIP("Module API not supported with V8", SkipAll); + QDeclarativeComponent component(&engine, TEST_FILE("moduleApi.qml")); QObject *object = component.create(); QVERIFY(object != 0); @@ -2568,7 +2641,7 @@ void tst_qdeclarativeecmascript::importScripts() // then, ensure that unintended behaviour does not work. QDeclarativeComponent failOneComponent(&engine, TEST_FILE("jsimportfail/failOne.qml")); - QString expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failOne.qml").toLocalFile() + QLatin1String(":6: TypeError: Result of expression 'TestScriptImport.ImportOneJs' [undefined] is not an object."); + QString expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failOne.qml").toLocalFile() + QLatin1String(":6: TypeError: Cannot call method 'greetingString' of undefined"); QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData()); object = failOneComponent.create(); QVERIFY(object != 0); @@ -2582,7 +2655,7 @@ void tst_qdeclarativeecmascript::importScripts() QVERIFY(object->property("importScriptFunctionValue").toString().isEmpty()); delete object; QDeclarativeComponent failThreeComponent(&engine, TEST_FILE("jsimportfail/failThree.qml")); - expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failThree.qml").toLocalFile() + QLatin1String(":7: TypeError: Result of expression 'testQtObject.TestModuleImport.JsQtTest' [undefined] is not an object."); + expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failThree.qml").toLocalFile() + QLatin1String(":7: TypeError: Cannot read property 'JsQtTest' of undefined"); QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData()); object = failThreeComponent.create(); QVERIFY(object != 0); @@ -2638,7 +2711,7 @@ void tst_qdeclarativeecmascript::scarceResources() QVERIFY(object != 0); QVERIFY(object->property("scarceResourceCopy").isValid()); QCOMPARE(object->property("scarceResourceCopy").value<QPixmap>(), origPixmap); - QVERIFY(ep->scarceResources == 0); // should have been released by this point. + QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point. eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>()); QVERIFY(!eo->scarceResourceIsDetached()); // there are two copies of it in existence: the property of object, and the property of eo. delete object; @@ -2648,7 +2721,7 @@ void tst_qdeclarativeecmascript::scarceResources() QVERIFY(object != 0); QVERIFY(object->property("scarceResourceCopy").isValid()); QCOMPARE(object->property("scarceResourceCopy").value<QPixmap>(), origPixmap); - QVERIFY(ep->scarceResources == 0); // should have been released by this point. + QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point. eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>()); QVERIFY(!eo->scarceResourceIsDetached()); // there are two copies of it in existence: the property of object, and the property of eo. delete object; @@ -2657,7 +2730,7 @@ void tst_qdeclarativeecmascript::scarceResources() object = componentThree.create(); QVERIFY(object != 0); QVERIFY(!(object->property("scarceResourceCopy").isValid())); // was manually released prior to being returned. - QVERIFY(ep->scarceResources == 0); // should have been released by this point. + QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point. eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>()); QVERIFY(eo->scarceResourceIsDetached()); // should have explicitly been released during the evaluation of the binding. delete object; @@ -2669,7 +2742,7 @@ void tst_qdeclarativeecmascript::scarceResources() QVERIFY(object != 0); QVERIFY(object->property("scarceResourceTest").isValid()); QCOMPARE(object->property("scarceResourceTest").toInt(), 100); - QVERIFY(ep->scarceResources == 0); // should have been released by this point. + QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point. eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>()); QVERIFY(eo->scarceResourceIsDetached()); // the resource should have been released after the binding was evaluated. delete object; @@ -2679,7 +2752,7 @@ void tst_qdeclarativeecmascript::scarceResources() QVERIFY(object != 0); QVERIFY(object->property("scarceResourceTest").isValid()); QCOMPARE(object->property("scarceResourceTest").toInt(), 100); - QVERIFY(ep->scarceResources == 0); // should have been released by this point. + QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point. eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>()); QVERIFY(!eo->scarceResourceIsDetached()); // this won't be detached since we explicitly preserved it. delete object; @@ -2689,7 +2762,7 @@ void tst_qdeclarativeecmascript::scarceResources() QVERIFY(object != 0); QVERIFY(object->property("scarceResourceTest").isValid()); QCOMPARE(object->property("scarceResourceTest").toInt(), 100); - QVERIFY(ep->scarceResources == 0); // should have been released by this point. + QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point. eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>()); QVERIFY(eo->scarceResourceIsDetached()); // all resources were released manually or automatically released. delete object; @@ -2698,14 +2771,14 @@ void tst_qdeclarativeecmascript::scarceResources() QDeclarativeComponent componentSeven(&engine, TEST_FILE("scarceresources/scarceResourceCopyImportNoBinding.qml")); object = componentSeven.create(); QVERIFY(object != 0); // the import should have caused the addition of a resource to the ScarceResources list - QVERIFY(ep->scarceResources == 0); // but they should have been released by this point. + QVERIFY(ep->scarceResources.isEmpty()); // but they should have been released by this point. delete object; QDeclarativeComponent componentEight(&engine, TEST_FILE("scarceresources/scarceResourceCopyImportFail.qml")); object = componentEight.create(); QVERIFY(object != 0); QVERIFY(!object->property("scarceResourceCopy").isValid()); // wasn't preserved, so shouldn't be valid. - QVERIFY(ep->scarceResources == 0); // should have been released by this point. + QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point. delete object; QDeclarativeComponent componentNine(&engine, TEST_FILE("scarceresources/scarceResourceCopyImport.qml")); @@ -2716,7 +2789,7 @@ void tst_qdeclarativeecmascript::scarceResources() QVERIFY(object->property("scarceResourceAssignedCopyOne").isValid()); // assigned before destroy(), so should be valid. QCOMPARE(object->property("scarceResourceAssignedCopyOne").value<QPixmap>(), origPixmap); QVERIFY(!object->property("scarceResourceAssignedCopyTwo").isValid()); // assigned after destroy(), so should be invalid. - QVERIFY(ep->scarceResources == 0); // this will still be zero, because "preserve()" REMOVES it from this list. + QVERIFY(ep->scarceResources.isEmpty()); // this will still be zero, because "preserve()" REMOVES it from this list. delete object; // test that scarce resources are handled properly in signal invocation @@ -2739,7 +2812,7 @@ void tst_qdeclarativeecmascript::scarceResources() QCOMPARE(srsc->property("scarceResourceCopy").value<QPixmap>(), origPixmap); eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>()); QVERIFY(!(eo->scarceResourceIsDetached())); // should be another copy of the resource now. - QVERIFY(ep->scarceResources == 0); // should have been released by this point. + QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point. delete object; // test that scarce resources are handled properly from js functions in qml files @@ -2758,7 +2831,7 @@ void tst_qdeclarativeecmascript::scarceResources() QVERIFY(!object->property("scarceResourceCopy").isValid()); // just released, so should not be valid eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>()); QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage. - QVERIFY(ep->scarceResources == 0); // should have been released by this point. + QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point. delete object; // test that if an exception occurs while invoking js function from cpp, that the resources are released. @@ -2768,13 +2841,14 @@ void tst_qdeclarativeecmascript::scarceResources() QVERIFY(!object->property("scarceResourceCopy").isValid()); // not yet assigned, so should not be valid eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>()); QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage. - QString expectedWarning = QLatin1String("file://") + TEST_FILE("scarceresources/scarceResourceFunctionFail.qml").toLocalFile() + QLatin1String(":16: TypeError: Result of expression 'scarceResourceProvider.scarceResource' [[object Object]] is not a function."); - QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData()); // we expect a meaningful warning to be printed. + QString srp_name = object->property("srp_name").toString(); + QString expectedWarning = componentTwelve.url().toString() + QLatin1String(":17: TypeError: Property 'scarceResource' of object ") + srp_name + QLatin1String(" is not a function"); + QTest::ignoreMessage(QtWarningMsg, qPrintable(expectedWarning)); // we expect a meaningful warning to be printed. QMetaObject::invokeMethod(object, "retrieveScarceResource"); QVERIFY(!object->property("scarceResourceCopy").isValid()); // due to exception, assignment will NOT have occurred. eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>()); QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage. - QVERIFY(ep->scarceResources == 0); // should have been released by this point. + QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point. delete object; } @@ -3060,11 +3134,11 @@ void tst_qdeclarativeecmascript::functionAssignmentfromJS_invalid() QVERIFY(!o->property("a").isValid()); QString url = component.url().toString(); - QString warning = url + ":63: Unable to assign QString to int"; + QString warning = url + ":67: Unable to assign QString to int"; QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); o->setProperty("assignWrongType", true); - warning = url + ":70: Unable to assign QString to int"; + warning = url + ":71: Unable to assign QString to int"; QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); o->setProperty("assignWrongTypeToValueType", true); @@ -3480,44 +3554,6 @@ void tst_qdeclarativeecmascript::revision() } } -// Test for QScriptDeclarativeClass::pushCleanContext() -void tst_qdeclarativeecmascript::pushCleanContext() -{ - QScriptEngine engine; - engine.globalObject().setProperty("a", 6); - QCOMPARE(engine.evaluate("a").toInt32(), 6); - - // First confirm pushContext() behaves as we expect - QScriptValue object = engine.newObject(); - object.setProperty("a", 15); - QScriptContext *context1 = engine.pushContext(); - context1->pushScope(object); - QCOMPARE(engine.evaluate("a").toInt32(), 15); - - QScriptContext *context2 = engine.pushContext(); - Q_UNUSED(context2); - QCOMPARE(engine.evaluate("a").toInt32(), 15); - QScriptValue func1 = engine.evaluate("(function() { return a; })"); - - // Now check that pushCleanContext() works - QScriptDeclarativeClass::pushCleanContext(&engine); - QCOMPARE(engine.evaluate("a").toInt32(), 6); - QScriptValue func2 = engine.evaluate("(function() { return a; })"); - - engine.popContext(); - QCOMPARE(engine.evaluate("a").toInt32(), 15); - - engine.popContext(); - QCOMPARE(engine.evaluate("a").toInt32(), 15); - - engine.popContext(); - QCOMPARE(engine.evaluate("a").toInt32(), 6); - - // Check that function objects created in these contexts work - QCOMPARE(func1.call().toInt32(), 15); - QCOMPARE(func2.call().toInt32(), 6); -} - void tst_qdeclarativeecmascript::realToInt() { QDeclarativeComponent component(&engine, TEST_FILE("realToInt.qml")); diff --git a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp index 1aa9a5d5b1..e6e87d1bbd 100644 --- a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp +++ b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp @@ -332,7 +332,7 @@ void tst_qdeclarativeinstruction::dump() i.storeScriptString.propertyIndex = 24; i.storeScriptString.value = 3; i.storeScriptString.scope = 1; - i.storeScriptString.bindingId = 3; + i.storeScriptString.bindingId = 4; data->addInstruction(i); } @@ -366,7 +366,7 @@ void tst_qdeclarativeinstruction::dump() { QDeclarativeInstruction i; - i.setType(QDeclarativeInstruction::StoreCompiledBinding); + i.setType(QDeclarativeInstruction::StoreV4Binding); i.assignBinding.property = 27; i.assignBinding.value = 2; i.assignBinding.context = 4; @@ -536,7 +536,7 @@ void tst_qdeclarativeinstruction::dump() << "25\t\tSTORE_VARIANT_OBJECT\t22" << "26\t\tSTORE_INTERFACE\t\t23" << "27\t\tSTORE_SIGNAL\t\t2\t3\t\t\"console.log(1921)\"" - << "28\t\tSTORE_SCRIPT_STRING\t24\t3\t1\t3" + << "28\t\tSTORE_SCRIPT_STRING\t24\t3\t1\t4" << "29\t\tASSIGN_SIGNAL_OBJECT\t0\t\t\t\"mySignal\"" << "30\t\tASSIGN_CUSTOMTYPE\t25\t6\t9" << "31\t\tSTORE_BINDING\t26\t3\t2" diff --git a/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml b/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml index bb20ecc8f6..48fb38da2b 100644 --- a/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml +++ b/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml @@ -33,11 +33,11 @@ Item { function checkMapAToInvalid(x, y) { var pos = itemA.mapToItem(1122, x, y) - return pos.x == undefined && pos.y == undefined + return pos == undefined; } function checkMapAFromInvalid(x, y) { var pos = itemA.mapFromItem(1122, x, y) - return pos.x == undefined && pos.y == undefined + return pos == undefined; } } diff --git a/tests/auto/declarative/qdeclarativelistmodel/data/model.qml b/tests/auto/declarative/qdeclarativelistmodel/data/model.qml index bfd547ed32..a1a599c9a5 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/data/model.qml +++ b/tests/auto/declarative/qdeclarativelistmodel/data/model.qml @@ -19,4 +19,8 @@ Item { item.done = true } } + + function runEval(js) { + eval(js); + } } diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index d923a7a7cb..07a6d82752 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -69,7 +69,6 @@ public: private: int roleFromName(const QDeclarativeListModel *model, const QString &roleName); - QScriptValue nestedListValue(QScriptEngine *eng) const; QDeclarativeItem *createWorkerTest(QDeclarativeEngine *eng, QDeclarativeComponent *component, QDeclarativeListModel *model); void waitForWorker(QDeclarativeItem *item); @@ -108,6 +107,7 @@ private slots: void property_changes_worker_data(); void clear(); }; + int tst_qdeclarativelistmodel::roleFromName(const QDeclarativeListModel *model, const QString &roleName) { QList<int> roles = model->roles(); @@ -118,16 +118,6 @@ int tst_qdeclarativelistmodel::roleFromName(const QDeclarativeListModel *model, return -1; } -QScriptValue tst_qdeclarativelistmodel::nestedListValue(QScriptEngine *eng) const -{ - QScriptValue list = eng->newArray(); - list.setProperty(0, eng->newObject()); - list.setProperty(1, eng->newObject()); - QScriptValue sv = eng->newObject(); - sv.setProperty("foo", list); - return sv; -} - QDeclarativeItem *tst_qdeclarativelistmodel::createWorkerTest(QDeclarativeEngine *eng, QDeclarativeComponent *component, QDeclarativeListModel *model) { QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component->create()); @@ -152,19 +142,74 @@ void tst_qdeclarativelistmodel::waitForWorker(QDeclarativeItem *item) QVERIFY(timer.isActive()); } +void tst_qdeclarativelistmodel::static_types_data() +{ + QTest::addColumn<QString>("qml"); + QTest::addColumn<QVariant>("value"); + + QTest::newRow("string") + << "ListElement { foo: \"bar\" }" + << QVariant(QString("bar")); + + QTest::newRow("real") + << "ListElement { foo: 10.5 }" + << QVariant(10.5); + + QTest::newRow("real0") + << "ListElement { foo: 0 }" + << QVariant(double(0)); + + QTest::newRow("bool") + << "ListElement { foo: false }" + << QVariant(false); + + QTest::newRow("bool") + << "ListElement { foo: true }" + << QVariant(true); + + QTest::newRow("enum") + << "ListElement { foo: Text.AlignHCenter }" + << QVariant(double(QDeclarativeText::AlignHCenter)); +} + +void tst_qdeclarativelistmodel::static_types() +{ + QFETCH(QString, qml); + QFETCH(QVariant, value); + + qml = "import QtQuick 1.0\nItem { property variant test: model.get(0).foo; ListModel { id: model; " + qml + " } }"; + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine); + component.setData(qml.toUtf8(), + QUrl::fromLocalFile(QString("dummy.qml"))); + + QVERIFY(!component.isError()); + + QObject *obj = component.create(); + QVERIFY(obj != 0); + + QVariant actual = obj->property("test"); + + QCOMPARE(actual, value); + QCOMPARE(actual.toString(), value.toString()); + + delete obj; +} + void tst_qdeclarativelistmodel::static_i18n() { QString expect = QString::fromUtf8("na\303\257ve"); - QString componentStr = "import QtQuick 1.0\nListModel { ListElement { prop1: \""+expect+"\"; prop2: QT_TR_NOOP(\""+expect+"\") } }"; + QString componentStr = "import QtQuick 1.0\nItem { property string prop1: model.get(0).prop1; property string prop2: model.get(0).prop2; ListModel { id: model; ListElement { prop1: \""+expect+"\"; prop2: QT_TR_NOOP(\""+expect+"\") } } }"; QDeclarativeEngine engine; QDeclarativeComponent component(&engine); component.setData(componentStr.toUtf8(), QUrl::fromLocalFile("")); - QDeclarativeListModel *obj = qobject_cast<QDeclarativeListModel*>(component.create()); + QObject *obj = component.create(); QVERIFY(obj != 0); - QString prop1 = obj->get(0).property(QLatin1String("prop1")).toString(); + QString prop1 = obj->property("prop1").toString(); QCOMPARE(prop1,expect); - QString prop2 = obj->get(0).property(QLatin1String("prop2")).toString(); + QString prop2 = obj->property("prop2").toString(); QCOMPARE(prop2,expect); // (no, not translated, QT_TR_NOOP is a no-op) delete obj; } @@ -180,25 +225,29 @@ void tst_qdeclarativelistmodel::static_nestedElements() QString componentStr = "import QtQuick 1.0\n" - "ListModel {\n" - " ListElement {\n" - " attributes: [\n"; + "Item {\n" + " property variant count: model.get(0).attributes.count\n" + " ListModel {\n" + " id: model\n" + " ListElement {\n" + " attributes: [\n"; componentStr += elementsStr.toUtf8().constData(); componentStr += - " ]\n" - " }\n" + " ]\n" + " }\n" + " }\n" "}"; QDeclarativeEngine engine; QDeclarativeComponent component(&engine); component.setData(componentStr.toUtf8(), QUrl::fromLocalFile("")); - QDeclarativeListModel *obj = qobject_cast<QDeclarativeListModel*>(component.create()); + QObject *obj = component.create(); QVERIFY(obj != 0); - QScriptValue prop = obj->get(0).property(QLatin1String("attributes")).property(QLatin1String("count")); - QVERIFY(prop.isNumber()); - QCOMPARE(prop.toInt32(), qint32(elementCount)); + QVariant count = obj->property("count"); + QCOMPARE(count.type(), QVariant::Int); + QCOMPARE(count.toInt(), elementCount); delete obj; } @@ -384,8 +433,6 @@ void tst_qdeclarativelistmodel::dynamic_worker() qApp->processEvents(); } - - void tst_qdeclarativelistmodel::dynamic_worker_sync_data() { dynamic_data(); @@ -438,6 +485,17 @@ void tst_qdeclarativelistmodel::dynamic_worker_sync() qApp->processEvents(); } +#define RUNEVAL(object, string) \ + QVERIFY(QMetaObject::invokeMethod(object, "runEval", Q_ARG(QVariant, QString(string)))); + +inline QVariant runexpr(QDeclarativeEngine *engine, const QString &str) +{ + QDeclarativeExpression expr(engine->rootContext(), 0, str); + return expr.evaluate(); +} + +#define RUNEXPR(string) runexpr(&engine, QString(string)) + void tst_qdeclarativelistmodel::convertNestedToFlat_fail() { // If a model has nested data, it cannot be used at all from a worker script @@ -450,11 +508,9 @@ void tst_qdeclarativelistmodel::convertNestedToFlat_fail() QDeclarativeItem *item = createWorkerTest(&eng, &component, &model); QVERIFY(item != 0); - QScriptEngine s_eng; - QScriptValue plainData = s_eng.newObject(); - plainData.setProperty("foo", QScriptValue(123)); - model.append(plainData); - model.append(nestedListValue(&s_eng)); + RUNEVAL(item, "model.append({foo: 123})"); + RUNEVAL(item, "model.append({foo: [{}, {}]})"); + QCOMPARE(model.count(), 2); QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML ListModel: List contains list-type data and cannot be used from a worker script"); @@ -482,6 +538,7 @@ void tst_qdeclarativelistmodel::convertNestedToFlat_fail_data() } void tst_qdeclarativelistmodel::convertNestedToFlat_ok() + { // If a model only has plain data, it can be modified from a worker script. However, // once the model is used from a worker script, it no longer accepts nested data @@ -494,10 +551,8 @@ void tst_qdeclarativelistmodel::convertNestedToFlat_ok() QDeclarativeItem *item = createWorkerTest(&eng, &component, &model); QVERIFY(item != 0); - QScriptEngine s_eng; - QScriptValue plainData = s_eng.newObject(); - plainData.setProperty("foo", QScriptValue(123)); - model.append(plainData); + RUNEVAL(item, "model.append({foo: 123})"); + QCOMPARE(model.count(), 1); QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker", Q_ARG(QVariant, script))); @@ -505,20 +560,21 @@ void tst_qdeclarativelistmodel::convertNestedToFlat_ok() // can still add plain data int count = model.count(); - model.append(plainData); + + RUNEVAL(item, "model.append({foo: 123})"); + QCOMPARE(model.count(), count+1); - QScriptValue nested = nestedListValue(&s_eng); const char *warning = "<Unknown File>: QML ListModel: Cannot add list-type data when modifying or after modification from a worker script"; QTest::ignoreMessage(QtWarningMsg, warning); - model.append(nested); + RUNEVAL(item, "model.append({foo: [{}, {}]})"); QTest::ignoreMessage(QtWarningMsg, warning); - model.insert(0, nested); + RUNEVAL(item, "model.insert(0, {foo: [{}, {}]})"); QTest::ignoreMessage(QtWarningMsg, warning); - model.set(0, nested); + RUNEVAL(item, "model.set(0, {foo: [{}, {}]})"); QCOMPARE(model.count(), count+1); @@ -531,67 +587,6 @@ void tst_qdeclarativelistmodel::convertNestedToFlat_ok_data() convertNestedToFlat_fail_data(); } -void tst_qdeclarativelistmodel::static_types_data() -{ - QTest::addColumn<QString>("qml"); - QTest::addColumn<QVariant>("value"); - - QTest::newRow("string") - << "ListElement { foo: \"bar\" }" - << QVariant(QString("bar")); - - QTest::newRow("real") - << "ListElement { foo: 10.5 }" - << QVariant(10.5); - - QTest::newRow("real0") - << "ListElement { foo: 0 }" - << QVariant(double(0)); - - QTest::newRow("bool") - << "ListElement { foo: false }" - << QVariant(false); - - QTest::newRow("bool") - << "ListElement { foo: true }" - << QVariant(true); - - QTest::newRow("enum") - << "ListElement { foo: Text.AlignHCenter }" - << QVariant(double(QDeclarativeText::AlignHCenter)); -} - -void tst_qdeclarativelistmodel::static_types() -{ - QFETCH(QString, qml); - QFETCH(QVariant, value); - - qml = "import QtQuick 1.0\nListModel { " + qml + " }"; - - QDeclarativeEngine engine; - QDeclarativeComponent component(&engine); - component.setData(qml.toUtf8(), - QUrl::fromLocalFile(QString("dummy.qml"))); - - if (value.toString().startsWith("QTBUG-")) - QEXPECT_FAIL("",value.toString().toLatin1(),Abort); - - QVERIFY(!component.isError()); - - QDeclarativeListModel *obj = qobject_cast<QDeclarativeListModel*>(component.create()); - QVERIFY(obj != 0); - - QScriptValue actual = obj->get(0).property(QLatin1String("foo")); - - QCOMPARE(actual.isString(), value.type() == QVariant::String); - QCOMPARE(actual.isBoolean(), value.type() == QVariant::Bool); - QCOMPARE(actual.isNumber(), value.type() == QVariant::Double); - - QCOMPARE(actual.toString(), value.toString()); - - delete obj; -} - void tst_qdeclarativelistmodel::enumerate() { QDeclarativeEngine eng; @@ -608,7 +603,6 @@ void tst_qdeclarativelistmodel::enumerate() delete item; } - void tst_qdeclarativelistmodel::error_data() { QTest::addColumn<QString>("qml"); @@ -701,21 +695,16 @@ void tst_qdeclarativelistmodel::set() QDeclarativeEngine engine; QDeclarativeListModel model; QDeclarativeEngine::setContextForObject(&model,engine.rootContext()); - engine.rootContext()->setContextObject(&model); - QScriptEngine *seng = QDeclarativeEnginePrivate::getScriptEngine(&engine); + engine.rootContext()->setContextProperty("model", &model); - QScriptValue sv = seng->newObject(); - sv.setProperty("test", QScriptValue(false)); - model.append(sv); + RUNEXPR("model.append({test:false})"); + RUNEXPR("model.set(0, {test:true})"); - sv.setProperty("test", QScriptValue(true)); - model.set(0, sv); - QCOMPARE(model.get(0).property("test").toBool(), true); // triggers creation of model cache + QCOMPARE(RUNEXPR("model.get(0).test").toBool(), true); // triggers creation of model cache QCOMPARE(model.data(0, model.roles()[0]), qVariantFromValue(true)); - sv.setProperty("test", QScriptValue(false)); - model.set(0, sv); - QCOMPARE(model.get(0).property("test").toBool(), false); // tests model cache is updated + RUNEXPR("model.set(0, {test:false})"); + QCOMPARE(RUNEXPR("model.get(0).test").toBool(), false); // tests model cache is updated QCOMPARE(model.data(0, model.roles()[0]), qVariantFromValue(false)); } @@ -729,8 +718,8 @@ void tst_qdeclarativelistmodel::get() QFETCH(QString, roleName); QFETCH(QVariant, roleValue); - QDeclarativeEngine eng; - QDeclarativeComponent component(&eng); + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine); component.setData( "import QtQuick 1.0\n" "ListModel { \n" @@ -743,7 +732,7 @@ void tst_qdeclarativelistmodel::get() QVERIFY(role >= 0); QSignalSpy spy(model, SIGNAL(itemsChanged(int, int, QList<int>))); - QDeclarativeExpression expr(eng.rootContext(), model, expression); + QDeclarativeExpression expr(engine.rootContext(), model, expression); expr.evaluate(); QVERIFY(!expr.hasError()); @@ -792,17 +781,12 @@ void tst_qdeclarativelistmodel::get_worker() QDeclarativeComponent component(&eng, QUrl::fromLocalFile(SRCDIR "/data/model.qml")); QDeclarativeItem *item = createWorkerTest(&eng, &component, &model); QVERIFY(item != 0); - QScriptEngine *seng = QDeclarativeEnginePrivate::getScriptEngine(&eng); // Add some values like get() test - QScriptValue sv = seng->newObject(); - sv.setProperty(QLatin1String("roleA"), seng->newVariant(QVariant::fromValue(100))); - model.append(sv); - sv = seng->newObject(); - sv.setProperty(QLatin1String("roleA"), seng->newVariant(QVariant::fromValue(200))); - sv.setProperty(QLatin1String("roleB"), seng->newVariant(QVariant::fromValue(400))); - model.append(sv); - model.append(sv); + RUNEVAL(item, "model.append({roleA: 100})"); + RUNEVAL(item, "model.append({roleA: 200, roleB: 400})"); + RUNEVAL(item, "model.append({roleA: 200, roleB: 400})"); + int role = roleFromName(&model, roleName); QVERIFY(role >= 0); @@ -1055,7 +1039,6 @@ void tst_qdeclarativelistmodel::property_changes_data() << "b" << 0 << true << "get(0).b.count == 0"; } - void tst_qdeclarativelistmodel::property_changes_worker() { // nested models are not supported when WorkerScript is involved @@ -1108,33 +1091,26 @@ void tst_qdeclarativelistmodel::clear() QDeclarativeEngine engine; QDeclarativeListModel model; QDeclarativeEngine::setContextForObject(&model, engine.rootContext()); - engine.rootContext()->setContextObject(&model); - - QScriptEngine *seng = QDeclarativeEnginePrivate::getScriptEngine(&engine); - QScriptValue sv = seng->newObject(); - QVariant result; + engine.rootContext()->setContextProperty("model", &model); model.clear(); QCOMPARE(model.count(), 0); - sv.setProperty("propertyA", "value a"); - sv.setProperty("propertyB", "value b"); - model.append(sv); + RUNEXPR("model.append({propertyA: \"value a\", propertyB: \"value b\"})"); QCOMPARE(model.count(), 1); model.clear(); QCOMPARE(model.count(), 0); - model.append(sv); - model.append(sv); + RUNEXPR("model.append({propertyA: \"value a\", propertyB: \"value b\"})"); + RUNEXPR("model.append({propertyA: \"value a\", propertyB: \"value b\"})"); QCOMPARE(model.count(), 2); model.clear(); QCOMPARE(model.count(), 0); // clearing does not remove the roles - sv.setProperty("propertyC", "value c"); - model.append(sv); + RUNEXPR("model.append({propertyA: \"value a\", propertyB: \"value b\", propertyC: \"value c\"})"); QList<int> roles = model.roles(); model.clear(); QCOMPARE(model.count(), 0); diff --git a/tests/auto/declarative/qdeclarativeqt/data/dateTimeConversion.qml b/tests/auto/declarative/qdeclarativeqt/data/dateTimeConversion.qml new file mode 100644 index 0000000000..06203285a9 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeqt/data/dateTimeConversion.qml @@ -0,0 +1,14 @@ +import QtQuick 1.0 + +QtObject { + // months are 0-based - so January = 0, December = 11. + property variant qtime: new Date(0,0,0,14,15,38,200) // yyyy/MM/dd 14:15:38.200 + property variant qdate: new Date(2008,11,24) // 2008/12/24 hh:mm:ss.zzz + property variant qdatetime: new Date(2008,11,24,14,15,38,200) // 2008/12/24 14:15:38.200 + + property variant qdatetime2: new Date(2852,11,31,23,59,59,500) // 2852/12/31 23:59:59.500 + property variant qdatetime3: new Date(1970,0,1,0,0,0,0) // 1970/01/01 00:00:00.000 + property variant qdatetime4: new Date(1586,1,2) // 1586/02/02 hh:mm:ss.zzz + property variant qdatetime5: new Date(955,0,1,0,0,0,0) // 955/01/01 00:00:00.000 + property variant qdatetime6: new Date(113,1,24,14,15,38,200) // 113/02/24 14:15:38.200 +} diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp index 960616294f..948307d955 100644 --- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp +++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp @@ -82,8 +82,11 @@ private slots: void createComponent_pragmaLibrary(); void createQmlObject(); void consoleLog(); + void dateTimeConversion(); void dateTimeFormatting(); void dateTimeFormatting_data(); + void dateTimeFormattingVariants(); + void dateTimeFormattingVariants_data(); void isQtObject(); void btoa(); void atob(); @@ -412,11 +415,11 @@ void tst_qdeclarativeqt::createQmlObject() QDeclarativeComponent component(&engine, TEST_FILE("createQmlObject.qml")); QString warning1 = component.url().toString() + ":7: Error: Qt.createQmlObject(): Invalid arguments"; - QString warning2 = component.url().toString()+ ":10: Error: Qt.createQmlObject() failed to create object: \n " + TEST_FILE("inline").toString() + ":2:10: Blah is not a type"; - QString warning3 = component.url().toString()+ ":11: Error: Qt.createQmlObject() failed to create object: \n " + TEST_FILE("main.qml").toString() + ":4:1: Duplicate property name"; + QString warning2 = component.url().toString()+ ":10: Error: Qt.createQmlObject(): failed to create object: \n " + TEST_FILE("inline").toString() + ":2:10: Blah is not a type"; + QString warning3 = component.url().toString()+ ":11: Error: Qt.createQmlObject(): failed to create object: \n " + TEST_FILE("main.qml").toString() + ":4:1: Duplicate property name"; QString warning4 = component.url().toString()+ ":9: Error: Qt.createQmlObject(): Missing parent object"; QString warning5 = component.url().toString()+ ":8: Error: Qt.createQmlObject(): Invalid arguments"; - QString warning6 = "RunTimeError: Qt.createQmlObject() failed to create object: \n " + TEST_FILE("inline").toString() + ":3: Cannot assign object type QObject with no default method"; + QString warning6 = "RunTimeError: Qt.createQmlObject(): failed to create object: \n " + TEST_FILE("inline").toString() + ":3: Cannot assign object type QObject with no default method"; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2)); @@ -448,6 +451,31 @@ void tst_qdeclarativeqt::consoleLog() delete object; } +void tst_qdeclarativeqt::dateTimeConversion() +{ + QDate date(2008,12,24); + QTime time(14,15,38,200); + QDateTime dateTime(date, time); + QDateTime dateTime2(QDate(2852,12,31), QTime(23,59,59,500)); + QDateTime dateTime3(QDate(1970,1,1), QTime(0,0,0,0)); + QDateTime dateTime4(QDate(1586,2,2), QTime(0,0,0,0)); + QDateTime dateTime5(QDate(955,1,1), QTime(0,0,0,0)); + QDateTime dateTime6(QDate(113,2,24), QTime(14,15,38,200)); + + QDeclarativeEngine eng; + QDeclarativeComponent component(&eng, TEST_FILE("dateTimeConversion.qml")); + QObject *obj = component.create(); + + QCOMPARE(obj->property("qdate").toDate(), date); + QCOMPARE(obj->property("qtime").toTime(), time); + QCOMPARE(obj->property("qdatetime").toDateTime(), dateTime); + QCOMPARE(obj->property("qdatetime2").toDateTime(), dateTime2); + QCOMPARE(obj->property("qdatetime3").toDateTime(), dateTime3); + QCOMPARE(obj->property("qdatetime4").toDateTime(), dateTime4); + QCOMPARE(obj->property("qdatetime5").toDateTime(), dateTime5); + QCOMPARE(obj->property("qdatetime6").toDateTime(), dateTime6); +} + void tst_qdeclarativeqt::dateTimeFormatting() { QFETCH(QString, method); @@ -482,14 +510,13 @@ void tst_qdeclarativeqt::dateTimeFormatting() QVERIFY(object != 0); QVERIFY(inputProperties.count() > 0); - QVariant result; foreach(const QString &prop, inputProperties) { QVERIFY(QMetaObject::invokeMethod(object, method.toUtf8().constData(), Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, prop))); - QStringList output = result.toStringList(); + QCOMPARE(output.size(), expectedResults.size()); for (int i=0; i<output.count(); i++) QCOMPARE(output[i], expectedResults[i]); } @@ -530,6 +557,86 @@ void tst_qdeclarativeqt::dateTimeFormatting_data() << dateTime.toString("M/d/yy H:m:s a")); } +void tst_qdeclarativeqt::dateTimeFormattingVariants() +{ + QFETCH(QString, method); + QFETCH(QVariant, variant); + QFETCH(QStringList, expectedResults); + + QDeclarativeEngine eng; + eng.rootContext()->setContextProperty("qvariant", variant); + QDeclarativeComponent component(&eng, TEST_FILE("formatting.qml")); + + QStringList warnings; + warnings << component.url().toString() + ":37: Error: Qt.formatDate(): Invalid date format" + << component.url().toString() + ":36: Error: Qt.formatDate(): Invalid arguments" + << component.url().toString() + ":40: Error: Qt.formatTime(): Invalid time format" + << component.url().toString() + ":39: Error: Qt.formatTime(): Invalid arguments" + << component.url().toString() + ":43: Error: Qt.formatDateTime(): Invalid datetime format" + << component.url().toString() + ":42: Error: Qt.formatDateTime(): Invalid arguments"; + + foreach (const QString &warning, warnings) + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); + + QObject *object = component.create(); + QVERIFY2(component.errorString().isEmpty(), qPrintable(component.errorString())); + QVERIFY(object != 0); + + QVariant result; + QVERIFY(QMetaObject::invokeMethod(object, method.toUtf8().constData(), + Q_RETURN_ARG(QVariant, result), + Q_ARG(QVariant, QString(QLatin1String("qvariant"))))); + QStringList output = result.toStringList(); + QCOMPARE(output, expectedResults); + + delete object; +} + +void tst_qdeclarativeqt::dateTimeFormattingVariants_data() +{ + QTest::addColumn<QString>("method"); + QTest::addColumn<QVariant>("variant"); + QTest::addColumn<QStringList>("expectedResults"); + + QDateTime temporary; + + QTime time(11, 16, 39, 755); + temporary = QDateTime(QDate(1970,1,1), time); + QTest::newRow("formatDate, qtime") << "formatDate" << QVariant::fromValue(time) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy")); + QTest::newRow("formatDateTime, qtime") << "formatDateTime" << QVariant::fromValue(time) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a")); + QTest::newRow("formatTime, qtime") << "formatTime" << QVariant::fromValue(time) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz")); + + QDate date(2011,5,31); + temporary = QDateTime(date); + QTest::newRow("formatDate, qdate") << "formatDate" << QVariant::fromValue(date) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy")); + QTest::newRow("formatDateTime, qdate") << "formatDateTime" << QVariant::fromValue(date) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a")); + QTest::newRow("formatTime, qdate") << "formatTime" << QVariant::fromValue(date) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz")); + + QDateTime dateTime(date, time); + temporary = dateTime; + QTest::newRow("formatDate, qdatetime") << "formatDate" << QVariant::fromValue(dateTime) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy")); + QTest::newRow("formatDateTime, qdatetime") << "formatDateTime" << QVariant::fromValue(dateTime) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a")); + QTest::newRow("formatTime, qdatetime") << "formatTime" << QVariant::fromValue(dateTime) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz")); + + QString string(QLatin1String("2011/05/31 11:16:39.755")); + temporary = QDateTime::fromString(string, "yyyy/MM/dd HH:mm:ss.zzz"); + QTest::newRow("formatDate, qstring") << "formatDate" << QVariant::fromValue(string) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy")); + QTest::newRow("formatDateTime, qstring") << "formatDateTime" << QVariant::fromValue(string) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a")); + QTest::newRow("formatTime, qstring") << "formatTime" << QVariant::fromValue(string) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz")); + + QColor color(Qt::red); + temporary = QVariant::fromValue(color).toDateTime(); + QTest::newRow("formatDate, qcolor") << "formatDate" << QVariant::fromValue(color) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy")); + QTest::newRow("formatDateTime, qcolor") << "formatDateTime" << QVariant::fromValue(color) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a")); + QTest::newRow("formatTime, qcolor") << "formatTime" << QVariant::fromValue(color) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz")); + + int integer(4); + temporary = QVariant::fromValue(integer).toDateTime(); + QTest::newRow("formatDate, int") << "formatDate" << QVariant::fromValue(integer) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy")); + QTest::newRow("formatDateTime, int") << "formatDateTime" << QVariant::fromValue(integer) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a")); + QTest::newRow("formatTime, int") << "formatTime" << QVariant::fromValue(integer) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz")); +} + void tst_qdeclarativeqt::isQtObject() { QDeclarativeComponent component(&engine, TEST_FILE("isQtObject.qml")); diff --git a/tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp b/tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp index 37755a9929..94b1cd630a 100644 --- a/tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp +++ b/tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp @@ -230,7 +230,8 @@ void tst_qdeclarativesqldatabase::testQml_cleanopen() // making it more like the tests are running in new processes. testQml(); - QDeclarativeEnginePrivate::getScriptEngine(engine)->collectGarbage(); // close databases + engine->collectGarbage(); + foreach (QString dbname, QSqlDatabase::connectionNames()) { QSqlDatabase::removeDatabase(dbname); } diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp index 39c3a9419c..ee787e2923 100644 --- a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp +++ b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp @@ -451,9 +451,9 @@ void tst_qdeclarativevisualdatamodel::modelProperties() QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":9: ReferenceError: Can't find variable: modelData"); QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":9: ReferenceError: Can't find variable: modelData"); QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":9: ReferenceError: Can't find variable: modelData"); - QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Result of expression 'model.modelData' [undefined] is not an object."); - QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Result of expression 'model.modelData' [undefined] is not an object."); - QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Result of expression 'model.modelData' [undefined] is not an object."); + QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Cannot read property 'display' of undefined"); + QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Cannot read property 'display' of undefined"); + QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Cannot read property 'display' of undefined"); view.setSource(source); diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.js b/tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.js new file mode 100644 index 0000000000..5c4c5ec906 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.js @@ -0,0 +1,6 @@ +WorkerScript.onMessage = function() { +} +for (var ii = 0; ii < 100; ++ii) { + var a = "HELLO WORLD"; +} + diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.qml new file mode 100644 index 0000000000..d05918a074 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.qml @@ -0,0 +1,13 @@ +import QtQuick 1.0 + +Item { + WorkerScript { + id: worker + source: "stressDispose.js" + } + + Component.onCompleted: { + worker.sendMessage(10); + } +} + diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp index 66090ce7ff..2c85040f5f 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp +++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp @@ -53,8 +53,6 @@ #include <private/qdeclarativeengine_p.h> #include "../../../shared/util.h" -Q_DECLARE_METATYPE(QScriptValue) - #ifdef Q_OS_SYMBIAN // In Symbian OS test data is located in applications private dir #define SRCDIR "." @@ -82,6 +80,7 @@ private slots: void script_included(); void scriptError_onLoad(); void scriptError_onCall(); + void stressDispose(); private: void waitForEchoMessage(QDeclarativeWorkerScript *worker) { @@ -191,13 +190,12 @@ void tst_QDeclarativeWorkerScript::messaging_sendJsObject() // QVariant roundtrip, since the properties will be stored in a QVariantMap. QString jsObject = "{'haste': 1125, 'name': 'zyz', 'spell power': 3101}"; - QScriptEngine *engine = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(worker)); - QScriptValue sv = engine->newObject(); - sv.setProperty("haste", 1125); - sv.setProperty("name", "zyz"); - sv.setProperty("spell power", 3101); + QVariantMap map; + map.insert("haste", 1125); + map.insert("name", "zyz"); + map.insert("spell power", 3101); - QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, qVariantFromValue(sv)))); + QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, qVariantFromValue(map)))); waitForEchoMessage(worker); QVariant result = qVariantFromValue(false); @@ -261,7 +259,7 @@ void tst_QDeclarativeWorkerScript::scriptError_onLoad() QVERIFY(worker != 0); QTRY_COMPARE(qdeclarativeworkerscript_lastWarning, - TEST_FILE("data/script_error_onLoad.js").toString() + QLatin1String(":3: SyntaxError: Parse error")); + TEST_FILE("data/script_error_onLoad.js").toString() + QLatin1String(":3: SyntaxError: Unexpected identifier")); qInstallMsgHandler(previousMsgHandler); qApp->processEvents(); @@ -286,6 +284,18 @@ void tst_QDeclarativeWorkerScript::scriptError_onCall() delete worker; } +// Rapidly create and destroy worker scripts to test resources are being disposed +// in the correct isolate +void tst_QDeclarativeWorkerScript::stressDispose() +{ + for (int ii = 0; ii < 100; ++ii) { + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, SRCDIR "/data/stressDispose.qml"); + QObject *o = component.create(); + QVERIFY(o); + delete o; + } +} QTEST_MAIN(tst_QDeclarativeWorkerScript) diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/invalidMethodUsage.qml b/tests/auto/declarative/qdeclarativexmlhttprequest/data/invalidMethodUsage.qml index 68f22f5f33..312292deaf 100644 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/data/invalidMethodUsage.qml +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/invalidMethodUsage.qml @@ -1,7 +1,6 @@ import QtQuick 1.0 QtObject { - property bool onreadystatechange: false property bool readyState: false property bool status: false property bool statusText: false @@ -19,17 +18,6 @@ QtObject { var o = 10; try { - XMLHttpRequest.prototype.onreadystatechange - } catch (e) { - if (!(e instanceof ReferenceError)) - return; - - if (e.message != "Not an XMLHttpRequest object") - return; - - onreadystatechange = true; - } - try { XMLHttpRequest.prototype.readyState } catch (e) { if (!(e instanceof ReferenceError)) diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp index aad68c5926..d2b7d5b50e 100644 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp @@ -977,7 +977,6 @@ void tst_qdeclarativexmlhttprequest::invalidMethodUsage() QObject *object = component.create(); QVERIFY(object != 0); - QCOMPARE(object->property("onreadystatechange").toBool(), true); QCOMPARE(object->property("readyState").toBool(), true); QCOMPARE(object->property("status").toBool(), true); QCOMPARE(object->property("statusText").toBool(), true); diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/data/get.qml b/tests/auto/declarative/qdeclarativexmllistmodel/data/get.qml new file mode 100644 index 0000000000..4e03503f90 --- /dev/null +++ b/tests/auto/declarative/qdeclarativexmllistmodel/data/get.qml @@ -0,0 +1,61 @@ +import QtQuick 1.0 + +XmlListModel { + source: "model.xml" + query: "/Pets/Pet" + XmlRole { name: "name"; query: "name/string()" } + XmlRole { name: "type"; query: "type/string()" } + XmlRole { name: "age"; query: "age/number()" } + XmlRole { name: "size"; query: "size/string()" } + + id: root + + property bool preTest: false + property bool postTest: false + + function runPreTest() { + if (root.get(0) != undefined) + return; + + preTest = true; + } + + function runPostTest() { + if (root.get(-1) != undefined) + return; + + var row = root.get(0); + if (row.name != "Polly" || + row.type != "Parrot" || + row.age != 12 || + row.size != "Small") + return; + + row = root.get(1); + if (row.name != "Penny" || + row.type != "Turtle" || + row.age != 4 || + row.size != "Small") + return; + + row = root.get(7); + if (row.name != "Rover" || + row.type != "Dog" || + row.age != 0 || + row.size != "Large") + return; + + row = root.get(8); + if (row.name != "Tiny" || + row.type != "Elephant" || + row.age != 15 || + row.size != "Large") + return; + + if (root.get(9) != undefined) + return; + + postTest = true; + } +} + diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index 7df2dc340d..37bafebdc4 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -520,40 +520,17 @@ void tst_qdeclarativexmllistmodel::data() void tst_qdeclarativexmllistmodel::get() { - QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model.qml")); + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/get.qml")); QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create()); QVERIFY(model != 0); - QVERIFY(model->get(0).isUndefined()); + + QVERIFY(QMetaObject::invokeMethod(model, "runPreTest")); + QCOMPARE(model->property("preTest").toBool(), true); QTRY_COMPARE(model->count(), 9); - QVERIFY(model->get(-1).isUndefined()); - - QScriptValue sv = model->get(0); - QCOMPARE(sv.property("name").toString(), QLatin1String("Polly")); - QCOMPARE(sv.property("type").toString(), QLatin1String("Parrot")); - QCOMPARE(sv.property("age").toNumber(), qsreal(12)); - QCOMPARE(sv.property("size").toString(), QLatin1String("Small")); - - sv = model->get(1); - QCOMPARE(sv.property("name").toString(), QLatin1String("Penny")); - QCOMPARE(sv.property("type").toString(), QLatin1String("Turtle")); - QCOMPARE(sv.property("age").toNumber(), qsreal(4)); - QCOMPARE(sv.property("size").toString(), QLatin1String("Small")); - - sv = model->get(7); - QCOMPARE(sv.property("name").toString(), QLatin1String("Rover")); - QCOMPARE(sv.property("type").toString(), QLatin1String("Dog")); - QCOMPARE(sv.property("age").toNumber(), qsreal(0)); - QCOMPARE(sv.property("size").toString(), QLatin1String("Large")); - - sv = model->get(8); - QCOMPARE(sv.property("name").toString(), QLatin1String("Tiny")); - QCOMPARE(sv.property("type").toString(), QLatin1String("Elephant")); - QCOMPARE(sv.property("age").toNumber(), qsreal(15)); - QCOMPARE(sv.property("size").toString(), QLatin1String("Large")); - - sv = model->get(9); - QVERIFY(sv.isUndefined()); + + QVERIFY(QMetaObject::invokeMethod(model, "runPostTest")); + QCOMPARE(model->property("postTest").toBool(), true); delete model; } diff --git a/tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp b/tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp index 078c9976ed..d12d285d39 100644 --- a/tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp +++ b/tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp @@ -466,9 +466,9 @@ void tst_qsgvisualdatamodel::modelProperties() QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: Can't find variable: modelData"); QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: Can't find variable: modelData"); QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: Can't find variable: modelData"); - QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Result of expression 'model.modelData' [undefined] is not an object."); - QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Result of expression 'model.modelData' [undefined] is not an object."); - QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Result of expression 'model.modelData' [undefined] is not an object."); + QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Cannot read property 'display' of undefined"); + QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Cannot read property 'display' of undefined"); + QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Cannot read property 'display' of undefined"); view.setSource(source); diff --git a/tests/auto/declarative/v8/Makefile.nonqt b/tests/auto/declarative/v8/Makefile.nonqt new file mode 100644 index 0000000000..20be72ea9b --- /dev/null +++ b/tests/auto/declarative/v8/Makefile.nonqt @@ -0,0 +1,11 @@ +release-m32: + g++ -o v8test_release_m32 -m32 -O2 v8main.cpp v8test.cpp -L../../../../src/3rdparty/v8/ -lv8 + +debug-m32: + g++ -o v8test_debug_m32 -m32 -g v8main.cpp v8test.cpp -L../../../../src/3rdparty/v8/ -lv8_g + +release: + g++ -o v8test_release -O2 v8main.cpp v8test.cpp -L../../../../src/3rdparty/v8/ -lv8 + +debug: + g++ -o v8test_debug -g v8main.cpp v8test.cpp -L../../../../src/3rdparty/v8/ -lv8_g diff --git a/tests/auto/declarative/v8/README.txt b/tests/auto/declarative/v8/README.txt new file mode 100644 index 0000000000..a5df6201be --- /dev/null +++ b/tests/auto/declarative/v8/README.txt @@ -0,0 +1,13 @@ +The v8 tests are actually implemented in v8test.[h|cpp]. There are also QtTest +(tst_v8.cpp) and non-Qt (v8main.cpp) stubs provided to run these tests. This +is done to allow the tests to be run both in the Qt CI system, and manually +without a build of Qt. The latter is necessary to run them against more exotic +build of V8, like the ARM simulator. + +To build the non-Qt version of the tests, first build a debug or release V8 +library under src/3rdparty/v8 using scons, and then use the Makefile.nonqt +makefile selecting one of the following targets: + release: Build the tests with -O2 and link against libv8 + debug: Build the tests with -g and link against libv8_g + release-m32: Build the tests with -O2 -m32 and link against libv8 + debug-m32: Build the tests with -g -m32 and link against libv8_g diff --git a/tests/auto/declarative/v8/tst_v8.cpp b/tests/auto/declarative/v8/tst_v8.cpp new file mode 100644 index 0000000000..4749da02f0 --- /dev/null +++ b/tests/auto/declarative/v8/tst_v8.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <qtest.h> +#include "v8test.h" + +using namespace v8; + +class tst_v8 : public QObject +{ + Q_OBJECT +public: + tst_v8() {} + +private slots: + void initTestCase() {} + void cleanupTestCase() {} + + void eval(); +}; + +void tst_v8::eval() +{ + QVERIFY(v8test_eval()); +} + +int main(int argc, char *argv[]) +{ + V8::SetFlagsFromCommandLine(&argc, argv, true); + + QCoreApplication app(argc, argv); + tst_v8 tc; + return QTest::qExec(&tc, argc, argv); +} + +#include "tst_v8.moc" diff --git a/tests/auto/declarative/v8/v8.pro b/tests/auto/declarative/v8/v8.pro new file mode 100644 index 0000000000..1030d174b6 --- /dev/null +++ b/tests/auto/declarative/v8/v8.pro @@ -0,0 +1,15 @@ +load(qttest_p4) +macx:CONFIG -= app_bundle + +SOURCES += tst_v8.cpp v8test.cpp +HEADERS += v8test.h + +CONFIG += parallel_test + +LIBS += -L../../../../src/v8/ +macx:CONFIG(debug, debug|release) { + LIBS += -lv8_debug +} else { + LIBS += -lv8 +} + diff --git a/tests/auto/declarative/v8/v8main.cpp b/tests/auto/declarative/v8/v8main.cpp new file mode 100644 index 0000000000..bf37e2d3a5 --- /dev/null +++ b/tests/auto/declarative/v8/v8main.cpp @@ -0,0 +1,16 @@ +#include "v8test.h" +#include <stdio.h> + +#define RUN_TEST(testname) { \ + if (!v8test_ ## testname()) \ + printf ("Test %s FAILED\n", # testname); \ +} + +int main(int argc, char *argv[]) +{ + v8::V8::SetFlagsFromCommandLine(&argc, argv, true); + + RUN_TEST(eval); + + return -1; +} diff --git a/tests/auto/declarative/v8/v8test.cpp b/tests/auto/declarative/v8/v8test.cpp new file mode 100644 index 0000000000..9b80b08550 --- /dev/null +++ b/tests/auto/declarative/v8/v8test.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "v8test.h" + +using namespace v8; + +#define BEGINTEST() bool _testPassed = true; +#define ENDTEST() return _testPassed; + +#define VERIFY(expr) { \ + if (!(expr)) { \ + _testPassed = false; \ + goto cleanup; \ + } \ +} + + +bool v8test_eval() +{ + BEGINTEST(); + + HandleScope handle_scope; + v8::Persistent<v8::Context> context = Context::New(); + Context::Scope context_scope(context); + + Local<Object> qmlglobal = Object::New(); + qmlglobal->Set(String::New("a"), v8::Integer::New(1922)); + + Local<Script> script = Script::Compile(String::New("eval(\"a\")"), NULL, NULL, + Handle<String>(), Script::QmlMode); + + TryCatch tc; + Local<Value> result = script->Run(qmlglobal); + + VERIFY(!tc.HasCaught()); + VERIFY(result->Int32Value() == 1922); + +cleanup: + context.Dispose(); + + ENDTEST(); +} + diff --git a/tests/auto/declarative/v8/v8test.h b/tests/auto/declarative/v8/v8test.h new file mode 100644 index 0000000000..f8878467ed --- /dev/null +++ b/tests/auto/declarative/v8/v8test.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef V8TEST_H +#define V8TEST_H + +#include "../../../../src/3rdparty/v8/include/v8.h" + +bool v8test_eval(); + +#endif // V8TEST_H + |