diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-05-11 17:20:40 +1000 |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-06-06 11:50:48 +1000 |
commit | 6b54de600ce74025bc8ada20bea95ad183a6cd8d (patch) | |
tree | 6736888525cd8cd8c2d30bb7b87b3249b74839a5 /tests | |
parent | 6dbd4286eb19e9ac45665046a43342bcdc8b127e (diff) |
Initial V8 integration
Diffstat (limited to 'tests')
15 files changed, 431 insertions, 133 deletions
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 20fa8548fd..bc694669b6 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -94,7 +94,8 @@ contains(QT_CONFIG, private_tests) { qsgtext \ qsgtextedit \ qsgtextinput \ - qsgvisualdatamodel + qsgvisualdatamodel \ + v8 } diff --git a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp index 1762ff7874..973d3a8d22 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/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 b2859b5b5b..4142c88ea5 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" @@ -1199,7 +1198,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 +1217,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 +1277,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 +1490,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 +1611,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 +1640,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 +1724,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 +1782,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 +1790,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 +1919,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 +1927,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 +1935,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 +1965,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 +1987,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 +1995,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 +2010,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 +2305,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 +2323,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 +2408,7 @@ void tst_qdeclarativeecmascript::ownershipCustomReturnValue() delete object; } + engine.collectGarbage(); QCoreApplication::instance()->processEvents(QEventLoop::DeferredDeletion); QVERIFY(source.value == 0); @@ -2638,7 +2710,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 +2720,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 +2729,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 +2741,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 +2751,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 +2761,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 +2770,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 +2788,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 +2811,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 +2830,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 +2840,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 +3133,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); 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/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 fc8939f297..c15c079f37 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 330bd4fdf2..874c3229f9 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/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp index b64e10c50d..e76ba9596f 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 "." @@ -191,13 +189,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 +258,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(); 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 7f158fce67..9622b19004 100644 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp @@ -958,7 +958,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/v8/tst_v8.cpp b/tests/auto/declarative/v8/tst_v8.cpp new file mode 100644 index 0000000000..a40638034c --- /dev/null +++ b/tests/auto/declarative/v8/tst_v8.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <qtest.h> +#include "../../../../src/3rdparty/v8/include/v8.h" + +using namespace v8; + +class tst_v8 : public QObject +{ + Q_OBJECT +public: + tst_v8() {} + +private slots: + void initTestCase() {} + void cleanupTestCase(); + + void eval(); + +private: + Persistent<Context> context; +}; + +void tst_v8::eval() +{ + HandleScope handle_scope; + 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); + + QVERIFY(!tc.HasCaught()); + QCOMPARE(result->Int32Value(), 1922); +} + +void tst_v8::cleanupTestCase() +{ + context.Dispose(); + context = Persistent<Context>(); +} + +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..0fc27d80b4 --- /dev/null +++ b/tests/auto/declarative/v8/v8.pro @@ -0,0 +1,14 @@ +load(qttest_p4) +macx:CONFIG -= app_bundle + +SOURCES += tst_v8.cpp + +CONFIG += parallel_test + +LIBS += -L../../../../src/v8/ +macx:CONFIG(debug, debug|release) { + LIBS += -lv8_debug +} else { + LIBS += -lv8 +} + |