diff options
Diffstat (limited to 'tests/auto/qml')
18 files changed, 543 insertions, 277 deletions
diff --git a/tests/auto/qml/animation/qpauseanimationjob/tst_qpauseanimationjob.cpp b/tests/auto/qml/animation/qpauseanimationjob/tst_qpauseanimationjob.cpp index a832c58ae3..5a1148e92e 100644 --- a/tests/auto/qml/animation/qpauseanimationjob/tst_qpauseanimationjob.cpp +++ b/tests/auto/qml/animation/qpauseanimationjob/tst_qpauseanimationjob.cpp @@ -211,19 +211,8 @@ void tst_QPauseAnimationJob::multiplePauseAnimations() #endif QCOMPARE(animation2.m_updateCurrentTimeCount, 2); - QTest::qWait(550); - -#ifdef Q_OS_WIN - if (animation2.state() != QAbstractAnimationJob::Stopped) - QEXPECT_FAIL("", winTimerError, Abort); -#endif - QVERIFY(animation2.state() == QAbstractAnimationJob::Stopped); - -#ifdef Q_OS_WIN - if (animation2.m_updateCurrentTimeCount != 3) - QEXPECT_FAIL("", winTimerError, Abort); -#endif - QCOMPARE(animation2.m_updateCurrentTimeCount, 3); + QTRY_COMPARE(animation2.state(), QAbstractAnimationJob::Stopped); + QVERIFY(animation2.m_updateCurrentTimeCount >= 3); } void tst_QPauseAnimationJob::pauseAndPropertyAnimations() @@ -240,19 +229,17 @@ void tst_QPauseAnimationJob::pauseAndPropertyAnimations() QTest::qWait(100); animation.start(); - QVERIFY(animation.state() == QAbstractAnimationJob::Running); - QVERIFY(pause.state() == QAbstractAnimationJob::Running); - QCOMPARE(pause.m_updateCurrentTimeCount, 2); + QCOMPARE(animation.state(), QAbstractAnimationJob::Running); - QTest::qWait(animation.totalDuration() + 100); + QTRY_COMPARE(animation.state(), QAbstractAnimationJob::Running); + QVERIFY(pause.state() == QAbstractAnimationJob::Running); + QVERIFY2(pause.m_updateCurrentTimeCount >= 2, + QByteArrayLiteral("pause.m_updateCurrentTimeCount=") + QByteArray::number(pause.m_updateCurrentTimeCount)); -#ifdef Q_OS_WIN - if (animation.state() != QAbstractAnimationJob::Stopped) - QEXPECT_FAIL("", winTimerError, Abort); -#endif - QVERIFY(animation.state() == QAbstractAnimationJob::Stopped); - QVERIFY(pause.state() == QAbstractAnimationJob::Stopped); - QVERIFY(pause.m_updateCurrentTimeCount > 3); + QTRY_COMPARE(animation.state(), QAbstractAnimationJob::Stopped); + QCOMPARE(pause.state(), QAbstractAnimationJob::Stopped); + QVERIFY2(pause.m_updateCurrentTimeCount > 3, + QByteArrayLiteral("pause.m_updateCurrentTimeCount=") + QByteArray::number(pause.m_updateCurrentTimeCount)); } void tst_QPauseAnimationJob::pauseResume() @@ -260,19 +247,15 @@ void tst_QPauseAnimationJob::pauseResume() TestablePauseAnimation animation; animation.setDuration(400); animation.start(); - QVERIFY(animation.state() == QAbstractAnimationJob::Running); + QCOMPARE(animation.state(), QAbstractAnimationJob::Running); QTest::qWait(200); animation.pause(); - QVERIFY(animation.state() == QAbstractAnimationJob::Paused); + QCOMPARE(animation.state(), QAbstractAnimationJob::Paused); animation.start(); QTest::qWait(300); - QVERIFY(animation.state() == QAbstractAnimationJob::Stopped); - -#ifdef Q_OS_WIN - if (animation.m_updateCurrentTimeCount != 3) - QEXPECT_FAIL("", winTimerError, Abort); -#endif - QCOMPARE(animation.m_updateCurrentTimeCount, 3); + QTRY_VERIFY(animation.state() == QAbstractAnimationJob::Stopped); + QVERIFY2(animation.m_updateCurrentTimeCount >= 3, + QByteArrayLiteral("animation.m_updateCurrentTimeCount=") + QByteArray::number(animation.m_updateCurrentTimeCount)); } void tst_QPauseAnimationJob::sequentialPauseGroup() @@ -423,7 +406,7 @@ void tst_QPauseAnimationJob::multipleSequentialGroups() if (group.state() != QAbstractAnimationJob::Stopped) QEXPECT_FAIL("", winTimerError, Abort); #endif - QVERIFY(group.state() == QAbstractAnimationJob::Stopped); + QTRY_VERIFY(group.state() == QAbstractAnimationJob::Stopped); #ifdef Q_OS_WIN if (subgroup1.state() != QAbstractAnimationJob::Stopped) diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp index f2b82db630..929b079a51 100644 --- a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp +++ b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp @@ -418,22 +418,22 @@ void tst_QQmlProfilerService::pixmapCacheData() QCOMPARE(m_client->traceMessages.first().detailType, (int)QQmlProfilerClient::StartTrace); // image starting to load - QCOMPARE(m_client->traceMessages[8].messageType, (int)QQmlProfilerClient::PixmapCacheEvent); - QCOMPARE(m_client->traceMessages[8].detailType, (int)QQmlProfilerClient::PixmapLoadingStarted); + QCOMPARE(m_client->traceMessages[16].messageType, (int)QQmlProfilerClient::PixmapCacheEvent); + QCOMPARE(m_client->traceMessages[16].detailType, (int)QQmlProfilerClient::PixmapLoadingStarted); // image loaded - QCOMPARE(m_client->traceMessages[9].messageType, (int)QQmlProfilerClient::PixmapCacheEvent); - QCOMPARE(m_client->traceMessages[9].detailType, (int)QQmlProfilerClient::PixmapLoadingFinished); + QCOMPARE(m_client->traceMessages[17].messageType, (int)QQmlProfilerClient::PixmapCacheEvent); + QCOMPARE(m_client->traceMessages[17].detailType, (int)QQmlProfilerClient::PixmapLoadingFinished); // image size - QCOMPARE(m_client->traceMessages[10].messageType, (int)QQmlProfilerClient::PixmapCacheEvent); - QCOMPARE(m_client->traceMessages[10].detailType, (int)QQmlProfilerClient::PixmapSizeKnown); - QCOMPARE(m_client->traceMessages[10].line, 2); // width - QCOMPARE(m_client->traceMessages[10].column, 2); // height + QCOMPARE(m_client->traceMessages[18].messageType, (int)QQmlProfilerClient::PixmapCacheEvent); + QCOMPARE(m_client->traceMessages[18].detailType, (int)QQmlProfilerClient::PixmapSizeKnown); + QCOMPARE(m_client->traceMessages[18].line, 2); // width + QCOMPARE(m_client->traceMessages[18].column, 2); // height // cache size - QCOMPARE(m_client->traceMessages[11].messageType, (int)QQmlProfilerClient::PixmapCacheEvent); - QCOMPARE(m_client->traceMessages[11].detailType, (int)QQmlProfilerClient::PixmapCacheCountChanged); + QCOMPARE(m_client->traceMessages[19].messageType, (int)QQmlProfilerClient::PixmapCacheEvent); + QCOMPARE(m_client->traceMessages[19].detailType, (int)QQmlProfilerClient::PixmapCacheCountChanged); // must end with "EndTrace" QCOMPARE(m_client->traceMessages.last().messageType, (int)QQmlProfilerClient::Event); diff --git a/tests/auto/qml/debugger/shared/qqmldebugclient.cpp b/tests/auto/qml/debugger/shared/qqmldebugclient.cpp index 95674ce6d7..6474a04796 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugclient.cpp +++ b/tests/auto/qml/debugger/shared/qqmldebugclient.cpp @@ -449,6 +449,7 @@ QString QQmlDebugClient::stateString() const case Unavailable: return QLatin1String("Unavailable"); case Enabled: return QLatin1String("Enabled"); } + return QLatin1String("Invalid"); } void QQmlDebugClient::sendMessage(const QByteArray &message) diff --git a/tests/auto/qml/qqmlecmascript/data/misctypetest.qml b/tests/auto/qml/qqmlecmascript/data/misctypetest.qml index 60ff53a2b4..088ede67ec 100644 --- a/tests/auto/qml/qqmlecmascript/data/misctypetest.qml +++ b/tests/auto/qml/qqmlecmascript/data/misctypetest.qml @@ -11,7 +11,7 @@ Item { return mtt.invalidUrl() == mtt.invalidUrl(); } - function test_invalid_url_refequal() + function test_invalid_url_strictequal() { return mtt.invalidUrl() === mtt.invalidUrl(); } @@ -21,7 +21,7 @@ Item { return mtt.validUrl() == mtt.validUrl(); } - function test_valid_url_refequal() + function test_valid_url_strictequal() { return mtt.validUrl() === mtt.validUrl(); } diff --git a/tests/auto/qml/qqmlecmascript/data/noCaptureWhenWritingProperty.qml b/tests/auto/qml/qqmlecmascript/data/noCaptureWhenWritingProperty.qml new file mode 100644 index 0000000000..8b8601692d --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/noCaptureWhenWritingProperty.qml @@ -0,0 +1,14 @@ +import QtQml 2.0 +QtObject { + property bool somePropertyEvaluated: false; + + property int someProperty: { + // It's sort of evil to set the property here, but that doesn't mean that + // this expression should get re-evaluated when unrelatedProperty changes later. + somePropertyEvaluated = true + return 20; + } + Component.onCompleted: { + somePropertyEvaluated = false + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml index 52abda1e55..8d08cc5559 100644 --- a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml @@ -140,6 +140,22 @@ Item { if (msco.intListProperty.toString() != expected.toString()) success = false; expected = 7; if (poppedVal != expected) success = false; + + // concat + msco.stringListProperty = [ "one", "two" ] + stringList = [ "hello", "world" ] + stringList = stringList.concat(msco.stringListProperty) + expected = [ "hello", "world", "one", "two" ] + if (stringList.length != expected.length) { + success = false; + } else { + for (var i = 0; i < stringList.length; ++i) { + if (stringList[i] != expected[i]) { + success = false; + break; + } + } + } } property variant variantList: [ 1, 2, 3, 4, 5 ]; diff --git a/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml b/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml index 975be1b2ad..7e85312692 100644 --- a/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml +++ b/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml @@ -57,4 +57,38 @@ QtObject { if (onTestSignal !== undefined) definedHandlerResult = true; } + + property QtObject objWithAlias: QtObject { + id: testObjectWithAlias + + property int count: 0; + property alias countAlias: testObjectWithAlias.count + } + + function testConnectionOnAlias() { + var called = false; + + testObjectWithAlias.onCountAliasChanged.connect(function() { + called = true + }) + + testObjectWithAlias.count++; + return called; + } + + property QtObject objWithAliasHandler: QtObject { + id: testObjectWithAliasHandler + + property bool testSuccess: false + + property int count: 0 + property alias countAlias: testObjectWithAliasHandler.count + onCountAliasChanged: testSuccess = true + } + + function testAliasSignalHandler() { + testObjectWithAliasHandler.testSuccess = false + testObjectWithAliasHandler.count++ + return testObjectWithAliasHandler.testSuccess + } } diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp index 41fa3672bd..22fac2013e 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.cpp +++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp @@ -106,7 +106,7 @@ public: void MyQmlObject::v8function(QQmlV4Function *function) { - QV8Engine::getV4(function->engine())->current->throwError(QStringLiteral("Exception thrown from within QObject slot")); + QV8Engine::getV4(function->engine())->currentContext()->throwError(QStringLiteral("Exception thrown from within QObject slot")); } static QJSValue script_api(QQmlEngine *engine, QJSEngine *scriptEngine) diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 6b19c13109..7b89709923 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -319,6 +319,7 @@ private slots: void stackLimits(); void idsAsLValues(); void qtbug_34792(); + void noCaptureWhenWritingProperty(); private: // static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter); @@ -2267,7 +2268,7 @@ static inline bool evaluate_error(QV8Engine *engine, const QV4::ValueRef o, cons QV4::Script program(QV8Engine::getV4(engine)->rootContext, functionSource); program.inheritContext = true; - QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->current; + QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->currentContext(); QV4::Scope scope(ctx); QV4::Scoped<QV4::FunctionObject> function(scope, program.run()); @@ -2295,7 +2296,7 @@ static inline bool evaluate_value(QV8Engine *engine, const QV4::ValueRef o, QV4::Script program(QV8Engine::getV4(engine)->rootContext, functionSource); program.inheritContext = true; - QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->current; + QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->currentContext(); QV4::Scope scope(ctx); QV4::Scoped<QV4::FunctionObject> function(scope, program.run()); @@ -2324,7 +2325,7 @@ static inline QV4::ReturnedValue evaluate(QV8Engine *engine, const QV4::ValueRef QString functionSource = QLatin1String("(function(object) { return ") + QLatin1String(source) + QLatin1String(" })"); - QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->current; + QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->currentContext(); QV4::Scope scope(ctx); QV4::Script program(QV8Engine::getV4(engine)->rootContext, functionSource); @@ -6060,6 +6061,13 @@ void tst_qqmlecmascript::signalHandlers() QMetaObject::invokeMethod(o, "testSignalHandlerDefined"); QCOMPARE(o->property("definedHandlerResult").toBool(), true); + QVariant result; + QMetaObject::invokeMethod(o, "testConnectionOnAlias", Q_RETURN_ARG(QVariant, result)); + QCOMPARE(result.toBool(), true); + + QMetaObject::invokeMethod(o, "testAliasSignalHandler", Q_RETURN_ARG(QVariant, result)); + QCOMPARE(result.toBool(), true); + delete o; } @@ -7491,6 +7499,14 @@ void tst_qqmlecmascript::qtbug_34792() delete object; } +void tst_qqmlecmascript::noCaptureWhenWritingProperty() +{ + QQmlComponent component(&engine, testFileUrl("noCaptureWhenWritingProperty.qml")); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + QCOMPARE(obj->property("somePropertyEvaluated").toBool(), false); +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" diff --git a/tests/auto/qml/qqmllanguage/data/customParserBindingScopes.qml b/tests/auto/qml/qqmllanguage/data/customParserBindingScopes.qml new file mode 100644 index 0000000000..2efc199f32 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/customParserBindingScopes.qml @@ -0,0 +1,19 @@ +import Test 1.0 +import QtQml 2.0 +QtObject { + id: root + + property int otherProperty: 10 + + property QtObject child: QtObject { + id: child + + property int testProperty; + property int otherProperty: 41 + + property QtObject customBinder: CustomBinding { + target: child + testProperty: otherProperty + 1 + } + } +} diff --git a/tests/auto/qml/qqmllanguage/testtypes.cpp b/tests/auto/qml/qqmllanguage/testtypes.cpp index 3957f9d872..4a4ab3b81a 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.cpp +++ b/tests/auto/qml/qqmllanguage/testtypes.cpp @@ -89,6 +89,8 @@ void registerTypes() qmlRegisterUncreatableType<MyUncreateableBaseClass,1>("Test", 1, 1, "MyUncreateableBaseClass", "Cannot create MyUncreateableBaseClass"); qmlRegisterType<MyCreateableDerivedClass,1>("Test", 1, 1, "MyCreateableDerivedClass"); + + qmlRegisterCustomType<CustomBinding>("Test", 1, 0, "CustomBinding", new CustomBindingParser); } QVariant myCustomVariantTypeConverter(const QString &data) @@ -97,3 +99,61 @@ QVariant myCustomVariantTypeConverter(const QString &data) rv.a = data.toInt(); return QVariant::fromValue(rv); } + + +QByteArray CustomBindingParser::compile(const QList<QQmlCustomParserProperty> &properties) +{ + QByteArray result; + QDataStream ds(&result, QIODevice::WriteOnly); + + ds << properties.count(); + for (int i = 0; i < properties.count(); ++i) { + const QQmlCustomParserProperty &prop = properties.at(i); + ds << prop.name(); + + Q_ASSERT(prop.assignedValues().count() == 1); + QVariant value = prop.assignedValues().first(); + + Q_ASSERT(value.userType() == qMetaTypeId<QQmlScript::Variant>()); + QQmlScript::Variant v = qvariant_cast<QQmlScript::Variant>(value); + Q_ASSERT(v.type() == QQmlScript::Variant::Script); + int bindingId = bindingIdentifier(v, prop.name()); + ds << bindingId; + + ds << prop.location().line; + } + + return result; +} + +void CustomBindingParser::setCustomData(QObject *object, const QByteArray &data) +{ + CustomBinding *customBinding = qobject_cast<CustomBinding*>(object); + Q_ASSERT(customBinding); + customBinding->m_bindingData = data; +} + +void CustomBinding::componentComplete() +{ + Q_ASSERT(m_target); + + QDataStream ds(m_bindingData); + int count; + ds >> count; + for (int i = 0; i < count; ++i) { + QString name; + ds >> name; + + int bindingId; + ds >> bindingId; + + int line; + ds >> line; + + QQmlBinding *binding = QQmlBinding::createBinding(QQmlBinding::Identifier(bindingId), m_target, qmlContext(this), QString(), line); + + QQmlProperty property(m_target, name, qmlContext(this)); + binding->setTarget(property); + QQmlPropertyPrivate::setBinding(property, binding); + } +} diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h index 703b26a73c..a968d9a25a 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.h +++ b/tests/auto/qml/qqmllanguage/testtypes.h @@ -1070,6 +1070,29 @@ QML_DECLARE_TYPE(MyRevisionedSubclass) QML_DECLARE_TYPE(MySubclass) QML_DECLARE_TYPE(MyReceiversTestObject) +class CustomBinding : public QObject, public QQmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QQmlParserStatus) + Q_PROPERTY(QObject* target READ target WRITE setTarget) +public: + + virtual void classBegin() {} + virtual void componentComplete(); + + QObject *target() const { return m_target; } + void setTarget(QObject *newTarget) { m_target = newTarget; } + + QPointer<QObject> m_target; + QByteArray m_bindingData; +}; + +class CustomBindingParser : public QQmlCustomParser +{ + virtual QByteArray compile(const QList<QQmlCustomParserProperty> &properties); + virtual void setCustomData(QObject *object, const QByteArray &data); +}; + void registerTypes(); #endif // TESTTYPES_H diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 621061ab6a..6a577ec91c 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -214,6 +214,8 @@ private slots: void compositeSingletonSelectors(); void compositeSingletonRegistered(); + void customParserBindingScopes(); + private: QQmlEngine engine; QStringList defaultImportPathList; @@ -3534,6 +3536,17 @@ void tst_qqmllanguage::compositeSingletonRegistered() verifyCompositeSingletonPropertyValues(o, "value1", 925, "value2", 755); } +void tst_qqmllanguage::customParserBindingScopes() +{ + QQmlComponent component(&engine, testFile("customParserBindingScopes.qml")); + VERIFY_ERRORS(0); + QScopedPointer<QObject> o(component.create()); + QVERIFY(!o.isNull()); + QPointer<QObject> child = qvariant_cast<QObject*>(o->property("child")); + QVERIFY(!child.isNull()); + QCOMPARE(child->property("testProperty").toInt(), 42); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp index ca212d333b..17f54508a3 100644 --- a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp +++ b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp @@ -55,6 +55,8 @@ public: tst_QQmlPropertyMap() {} private slots: + void initTestCase(); + void insert(); void operatorInsert(); void operatorValue(); @@ -68,8 +70,39 @@ private slots: void metaObjectAccessibility(); void QTBUG_31226(); void QTBUG_29836(); + void QTBUG_35233(); + void disallowExtending(); +}; + +class LazyPropertyMap : public QQmlPropertyMap, public QQmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QQmlParserStatus) + + Q_PROPERTY(int someFixedProperty READ someFixedProperty WRITE setSomeFixedProperty) +public: + LazyPropertyMap() + : QQmlPropertyMap(this, /*parent*/0) + , value(0) + {} + + virtual void classBegin() {} + virtual void componentComplete() { + insert(QStringLiteral("lateProperty"), QStringLiteral("lateValue")); + } + + int someFixedProperty() const { return value; } + void setSomeFixedProperty(int v) { value = v; } + +private: + int value; }; +void tst_QQmlPropertyMap::initTestCase() +{ + qmlRegisterType<LazyPropertyMap>("QTBUG_35233", 1, 0, "LazyPropertyMap"); +} + void tst_QQmlPropertyMap::insert() { QQmlPropertyMap map; @@ -369,6 +402,54 @@ void tst_QQmlPropertyMap::QTBUG_29836() } +void tst_QQmlPropertyMap::QTBUG_35233() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import QtQml 2.0\n" + "import QTBUG_35233 1.0\n" + "QtObject {\n" + " property QtObject testMap: LazyPropertyMap {\n" + " id: map\n" + " }\n" + " property QtObject sibling: QtObject {\n" + " objectName: \"sibling\"\n" + " property string testValue: map.lateProperty\n" + " }\n" + "}", QUrl()); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + + QObject *sibling = obj->findChild<QObject*>("sibling"); + QVERIFY(sibling); + QCOMPARE(sibling->property("testValue").toString(), QString("lateValue")); +} + +void tst_QQmlPropertyMap::disallowExtending() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import QtQml 2.0\n" + "import QTBUG_35233 1.0\n" + "LazyPropertyMap {\n" + " id: blah\n" + " someFixedProperty: 42\n" + "}\n", QUrl()); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + + component.setData("import QtQml 2.0\n" + "import QTBUG_35233 1.0\n" + "LazyPropertyMap {\n" + " id: blah\n" + " property int someNewProperty;\n" + "}\n", QUrl()); + obj.reset(component.create()); + QVERIFY(obj.isNull()); + QCOMPARE(component.errors().count(), 1); + QCOMPARE(component.errors().at(0).toString(), QStringLiteral("<Unknown File>: Fully dynamic types cannot declare new properties.")); +} + QTEST_MAIN(tst_QQmlPropertyMap) #include "tst_qqmlpropertymap.moc" diff --git a/tests/auto/qml/qqmltranslation/data/jstranslation.qml b/tests/auto/qml/qqmltranslation/data/jstranslation.qml new file mode 100644 index 0000000000..7adde019fa --- /dev/null +++ b/tests/auto/qml/qqmltranslation/data/jstranslation.qml @@ -0,0 +1,20 @@ +import QtQuick 2.0 +import "translation.js" as Js + +QtObject { + property string basic: Js.basic() + property string basic2: Js.basic2() + property string basic3: Js.basic3() + + property string disambiguation: Js.disambiguation() + property string disambiguation2: Js.disambiguation2() + property string disambiguation3: Js.disambiguation3() + + property string noop: Js.noop() + property string noop2: Js.noop2() + + property string singular: Js.singular() + property string singular2: Js.singular2() + property string plural: Js.plural() + property string plural2: Js.plural2() +} diff --git a/tests/auto/qml/qqmltranslation/data/translation.js b/tests/auto/qml/qqmltranslation/data/translation.js new file mode 100644 index 0000000000..c1e25dcd2f --- /dev/null +++ b/tests/auto/qml/qqmltranslation/data/translation.js @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +function basic() { + return qsTr("hello") +} + +function basic2() { + return qsTranslate("CustomContext", "goodbye") +} + +function basic3() { + if (1) + return qsTr("hello") + return ""; +} + +function disambiguation() { + return qsTr("hi", "informal 'hello'") +} + +function disambiguation2() { + return qsTranslate("CustomContext", "see ya", "informal 'goodbye'") +} + +function disambiguation3() { + if (1) + return qsTr("hi", "informal 'hello'") + return ""; +} + +function noop() { + var _noop = QT_TR_NOOP("hello") + return qsTr(_noop) +} + +function noop2() { + var _noop2 = QT_TRANSLATE_NOOP("CustomContext", "goodbye") + return qsTranslate("CustomContext", _noop2) +} + +function singular() { + return qsTr("%n duck(s)", "", 1) +} + +function singular2() { + if (1) + return qsTr("%n duck(s)", "", 1) + return ""; +} + +function plural() { + return qsTr("%n duck(s)", "", 2) +} + +function plural2() { + if (1) + return qsTr("%n duck(s)", "", 2) + return ""; +} diff --git a/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp b/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp index 0e22d3cfca..01e1cf85fb 100644 --- a/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp +++ b/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp @@ -52,19 +52,32 @@ public: tst_qqmltranslation() {} private slots: + void translation_data(); void translation(); void idTranslation(); - void translationInQrc(); }; +void tst_qqmltranslation::translation_data() +{ + QTest::addColumn<QString>("translation"); + QTest::addColumn<QUrl>("testFile"); + + QTest::newRow("qml") << QStringLiteral("qml_fr") << testFileUrl("translation.qml"); + QTest::newRow("qrc") << QStringLiteral(":/qml_fr.qm") << QUrl("qrc:/translation.qml"); + QTest::newRow("js") << QStringLiteral("qml_fr") << testFileUrl("jstranslation.qml"); +} + void tst_qqmltranslation::translation() { + QFETCH(QString, translation); + QFETCH(QUrl, testFile); + QTranslator translator; - translator.load(QLatin1String("qml_fr"), dataDirectory()); + translator.load(translation, dataDirectory()); QCoreApplication::installTranslator(&translator); QQmlEngine engine; - QQmlComponent component(&engine, testFileUrl("translation.qml")); + QQmlComponent component(&engine, testFile); QObject *object = component.create(); QVERIFY(object != 0); @@ -104,34 +117,6 @@ void tst_qqmltranslation::idTranslation() delete object; } -void tst_qqmltranslation::translationInQrc() -{ - QTranslator translator; - translator.load(":/qml_fr.qm"); - QCoreApplication::installTranslator(&translator); - - QQmlEngine engine; - QQmlComponent component(&engine, QUrl("qrc:/translation.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("basic").toString(), QLatin1String("bonjour")); - QCOMPARE(object->property("basic2").toString(), QLatin1String("au revoir")); - QCOMPARE(object->property("basic3").toString(), QLatin1String("bonjour")); - QCOMPARE(object->property("disambiguation").toString(), QLatin1String("salut")); - QCOMPARE(object->property("disambiguation2").toString(), QString::fromUtf8("\xc3\xa0 plus tard")); - QCOMPARE(object->property("disambiguation3").toString(), QLatin1String("salut")); - QCOMPARE(object->property("noop").toString(), QLatin1String("bonjour")); - QCOMPARE(object->property("noop2").toString(), QLatin1String("au revoir")); - QCOMPARE(object->property("singular").toString(), QLatin1String("1 canard")); - QCOMPARE(object->property("singular2").toString(), QLatin1String("1 canard")); - QCOMPARE(object->property("plural").toString(), QLatin1String("2 canards")); - QCOMPARE(object->property("plural2").toString(), QLatin1String("2 canards")); - - QCoreApplication::removeTranslator(&translator); - delete object; -} - QTEST_MAIN(tst_qqmltranslation) #include "tst_qqmltranslation.moc" diff --git a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp index 3ae27fe9c3..9c67e6e2e9 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp +++ b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp @@ -127,8 +127,8 @@ private: void tst_qqmlxmlhttprequest::domExceptionCodes() { QQmlComponent component(&engine, testFileUrl("domExceptionCodes.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("index_size_err").toInt(), 1); QCOMPARE(object->property("domstring_size_err").toInt(), 2); @@ -147,8 +147,6 @@ void tst_qqmlxmlhttprequest::domExceptionCodes() QCOMPARE(object->property("invalid_access_err").toInt(), 15); QCOMPARE(object->property("validation_err").toInt(), 16); QCOMPARE(object->property("type_mismatch_err").toInt(), 17); - - delete object; } void tst_qqmlxmlhttprequest::callbackException_data() @@ -172,15 +170,13 @@ void tst_qqmlxmlhttprequest::callbackException() QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); QQmlComponent component(&engine, testFileUrl("callbackException.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "testdocument.html"); object->setProperty("which", which); component.completeCreate(); QTRY_VERIFY(object->property("threw").toBool() == true); - - delete object; } // Test that the state value properties on the XMLHttpRequest constructor have the correct values. @@ -188,61 +184,53 @@ void tst_qqmlxmlhttprequest::callbackException() void tst_qqmlxmlhttprequest::staticStateValues() { QQmlComponent component(&engine, testFileUrl("staticStateValues.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("unsent").toInt(), 0); QCOMPARE(object->property("opened").toInt(), 1); QCOMPARE(object->property("headers_received").toInt(), 2); QCOMPARE(object->property("loading").toInt(), 3); QCOMPARE(object->property("done").toInt(), 4); - - delete object; } // Test that the state value properties on instances have the correct values. void tst_qqmlxmlhttprequest::instanceStateValues() { QQmlComponent component(&engine, testFileUrl("instanceStateValues.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("unsent").toInt(), 0); QCOMPARE(object->property("opened").toInt(), 1); QCOMPARE(object->property("headers_received").toInt(), 2); QCOMPARE(object->property("loading").toInt(), 3); QCOMPARE(object->property("done").toInt(), 4); - - delete object; } // Test calling constructor void tst_qqmlxmlhttprequest::constructor() { QQmlComponent component(&engine, testFileUrl("constructor.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("calledAsConstructor").toBool(), true); QCOMPARE(object->property("calledAsFunction").toBool(), true); - - delete object; } // Test that all the properties are set correctly before any request is sent void tst_qqmlxmlhttprequest::defaultState() { QQmlComponent component(&engine, testFileUrl("defaultState.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("readState").toInt(), 0); QCOMPARE(object->property("statusIsException").toBool(), true); QCOMPARE(object->property("statusTextIsException").toBool(), true); QCOMPARE(object->property("responseText").toString(), QString()); QCOMPARE(object->property("responseXMLIsNull").toBool(), true); - - delete object; } // Test valid XMLHttpRequest.open() calls @@ -262,8 +250,8 @@ void tst_qqmlxmlhttprequest::open() } QQmlComponent component(&engine, qmlFile); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", url); component.completeCreate(); @@ -275,8 +263,6 @@ void tst_qqmlxmlhttprequest::open() QCOMPARE(object->property("responseXML").toBool(), true); QTRY_VERIFY(object->property("dataOK").toBool() == true); - - delete object; } void tst_qqmlxmlhttprequest::open_data() @@ -297,24 +283,20 @@ void tst_qqmlxmlhttprequest::open_data() void tst_qqmlxmlhttprequest::open_invalid_method() { QQmlComponent component(&engine, testFileUrl("open_invalid_method.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("exceptionThrown").toBool(), true); - - delete object; } // Test that calling XMLHttpRequest.open() with sync raises an exception void tst_qqmlxmlhttprequest::open_sync() { QQmlComponent component(&engine, testFileUrl("open_sync.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("exceptionThrown").toBool(), true); - - delete object; } // Calling with incorrect arg count raises an exception @@ -322,22 +304,18 @@ void tst_qqmlxmlhttprequest::open_arg_count() { { QQmlComponent component(&engine, testFileUrl("open_arg_count.1.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("exceptionThrown").toBool(), true); - - delete object; } { QQmlComponent component(&engine, testFileUrl("open_arg_count.2.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("exceptionThrown").toBool(), true); - - delete object; } } @@ -351,14 +329,12 @@ void tst_qqmlxmlhttprequest::setRequestHeader() testFileUrl("testdocument.html"))); QQmlComponent component(&engine, testFileUrl("setRequestHeader.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); component.completeCreate(); QTRY_VERIFY(object->property("dataOK").toBool() == true); - - delete object; } // Test valid setRequestHeader() calls with different header cases @@ -371,25 +347,21 @@ void tst_qqmlxmlhttprequest::setRequestHeader_caseInsensitive() testFileUrl("testdocument.html"))); QQmlComponent component(&engine, testFileUrl("setRequestHeader_caseInsensitive.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); component.completeCreate(); QTRY_VERIFY(object->property("dataOK").toBool() == true); - - delete object; } // Test setting headers before open() throws exception void tst_qqmlxmlhttprequest::setRequestHeader_unsent() { QQmlComponent component(&engine, testFileUrl("setRequestHeader_unsent.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("test").toBool(), true); - - delete object; } void tst_qqmlxmlhttprequest::setRequestHeader_illegalName_data() @@ -432,8 +404,8 @@ void tst_qqmlxmlhttprequest::setRequestHeader_illegalName() testFileUrl("testdocument.html"))); QQmlComponent component(&engine, testFileUrl("setRequestHeader_illegalName.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); object->setProperty("header", name); component.completeCreate(); @@ -446,8 +418,6 @@ void tst_qqmlxmlhttprequest::setRequestHeader_illegalName() QCOMPARE(object->property("responseXML").toBool(), true); QTRY_VERIFY(object->property("dataOK").toBool() == true); - - delete object; } // Test that attempting to set a header after a request is sent throws an exception @@ -460,53 +430,45 @@ void tst_qqmlxmlhttprequest::setRequestHeader_sent() testFileUrl("testdocument.html"))); QQmlComponent component(&engine, testFileUrl("setRequestHeader_sent.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); component.completeCreate(); QCOMPARE(object->property("test").toBool(), true); QTRY_VERIFY(object->property("dataOK").toBool() == true); - - delete object; } // Invalid arg count throws exception void tst_qqmlxmlhttprequest::setRequestHeader_args() { QQmlComponent component(&engine, testFileUrl("setRequestHeader_args.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("exceptionThrown").toBool(), true); - - delete object; } // Test that calling send() in UNSENT state throws an exception void tst_qqmlxmlhttprequest::send_unsent() { QQmlComponent component(&engine, testFileUrl("send_unsent.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("test").toBool(), true); - - delete object; } // Test attempting to resend a sent request throws an exception void tst_qqmlxmlhttprequest::send_alreadySent() { QQmlComponent component(&engine, testFileUrl("send_alreadySent.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("test").toBool(), true); QTRY_VERIFY(object->property("dataOK").toBool() == true); - - delete object; } // Test that sends for GET, HEAD and DELETE ignore data @@ -520,15 +482,13 @@ void tst_qqmlxmlhttprequest::send_ignoreData() testFileUrl("testdocument.html"))); QQmlComponent component(&engine, testFileUrl("send_ignoreData.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("reqType", "GET"); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); component.completeCreate(); QTRY_VERIFY(object->property("dataOK").toBool() == true); - - delete object; } { @@ -539,15 +499,13 @@ void tst_qqmlxmlhttprequest::send_ignoreData() QUrl())); QQmlComponent component(&engine, testFileUrl("send_ignoreData.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("reqType", "HEAD"); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); component.completeCreate(); QTRY_VERIFY(object->property("dataOK").toBool() == true); - - delete object; } { @@ -558,15 +516,13 @@ void tst_qqmlxmlhttprequest::send_ignoreData() QUrl())); QQmlComponent component(&engine, testFileUrl("send_ignoreData.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("reqType", "DELETE"); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); component.completeCreate(); QTRY_VERIFY(object->property("dataOK").toBool() == true); - - delete object; } } @@ -583,14 +539,12 @@ void tst_qqmlxmlhttprequest::send_withdata() testFileUrl("testdocument.html"))); QQmlComponent component(&engine, testFileUrl(file_qml)); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); component.completeCreate(); QTRY_VERIFY(object->property("dataOK").toBool() == true); - - delete object; } void tst_qqmlxmlhttprequest::send_withdata_data() @@ -611,8 +565,8 @@ void tst_qqmlxmlhttprequest::send_withdata_data() void tst_qqmlxmlhttprequest::abort_unsent() { QQmlComponent component(&engine, testFileUrl("abort_unsent.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "testdocument.html"); component.completeCreate(); @@ -624,16 +578,14 @@ void tst_qqmlxmlhttprequest::abort_unsent() QCOMPARE(object->property("responseXML").toBool(), true); QTRY_VERIFY(object->property("dataOK").toBool() == true); - - delete object; } // Test abort() cancels an open (but unsent) request void tst_qqmlxmlhttprequest::abort_opened() { QQmlComponent component(&engine, testFileUrl("abort_opened.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "testdocument.html"); component.completeCreate(); @@ -645,8 +597,6 @@ void tst_qqmlxmlhttprequest::abort_opened() QCOMPARE(object->property("responseXML").toBool(), true); QTRY_VERIFY(object->property("dataOK").toBool() == true); - - delete object; } // Test abort() aborts in progress send @@ -659,8 +609,8 @@ void tst_qqmlxmlhttprequest::abort() testFileUrl("testdocument.html"))); QQmlComponent component(&engine, testFileUrl("abort.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("urlDummy", "http://127.0.0.1:14449/testdocument.html"); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); component.completeCreate(); @@ -670,8 +620,6 @@ void tst_qqmlxmlhttprequest::abort() QCOMPARE(object->property("endStateUnsent").toBool(), true); QTRY_VERIFY(object->property("dataOK").toBool() == true); - - delete object; } void tst_qqmlxmlhttprequest::getResponseHeader() @@ -686,8 +634,8 @@ void tst_qqmlxmlhttprequest::getResponseHeader() QQmlComponent component(&engine, testFileUrl("getResponseHeader.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); component.completeCreate(); @@ -709,44 +657,36 @@ void tst_qqmlxmlhttprequest::getResponseHeader() QCOMPARE(object->property("doneValidHeader").toBool(), true); QCOMPARE(object->property("doneMultiValidHeader").toBool(), true); QCOMPARE(object->property("doneCookieHeader").toBool(), true); - - delete object; } // Test getResponseHeader throws an exception in an invalid state void tst_qqmlxmlhttprequest::getResponseHeader_unsent() { QQmlComponent component(&engine, testFileUrl("getResponseHeader_unsent.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("test").toBool(), true); - - delete object; } // Test getResponseHeader throws an exception in an invalid state void tst_qqmlxmlhttprequest::getResponseHeader_sent() { QQmlComponent component(&engine, testFileUrl("getResponseHeader_sent.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("test").toBool(), true); - - delete object; } // Invalid arg count throws exception void tst_qqmlxmlhttprequest::getResponseHeader_args() { QQmlComponent component(&engine, testFileUrl("getResponseHeader_args.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QTRY_VERIFY(object->property("exceptionThrown").toBool() == true); - - delete object; } void tst_qqmlxmlhttprequest::getAllResponseHeaders() @@ -760,8 +700,8 @@ void tst_qqmlxmlhttprequest::getAllResponseHeaders() testFileUrl("testdocument.html"))); QQmlComponent component(&engine, testFileUrl("getAllResponseHeaders.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); component.completeCreate(); @@ -777,44 +717,36 @@ void tst_qqmlxmlhttprequest::getAllResponseHeaders() QCOMPARE(object->property("doneState").toBool(), true); QCOMPARE(object->property("doneHeader").toBool(), true); - - delete object; } // Test getAllResponseHeaders throws an exception in an invalid state void tst_qqmlxmlhttprequest::getAllResponseHeaders_unsent() { QQmlComponent component(&engine, testFileUrl("getAllResponseHeaders_unsent.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("test").toBool(), true); - - delete object; } // Test getAllResponseHeaders throws an exception in an invalid state void tst_qqmlxmlhttprequest::getAllResponseHeaders_sent() { QQmlComponent component(&engine, testFileUrl("getAllResponseHeaders_sent.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("test").toBool(), true); - - delete object; } // Invalid arg count throws exception void tst_qqmlxmlhttprequest::getAllResponseHeaders_args() { QQmlComponent component(&engine, testFileUrl("getAllResponseHeaders_args.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QTRY_VERIFY(object->property("exceptionThrown").toBool() == true); - - delete object; } void tst_qqmlxmlhttprequest::status() @@ -829,8 +761,8 @@ void tst_qqmlxmlhttprequest::status() testFileUrl("testdocument.html"))); QQmlComponent component(&engine, testFileUrl("status.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); object->setProperty("expectedStatus", status); component.completeCreate(); @@ -844,8 +776,6 @@ void tst_qqmlxmlhttprequest::status() QCOMPARE(object->property("loading").toBool(), true); QCOMPARE(object->property("done").toBool(), true); QCOMPARE(object->property("resetException").toBool(), true); - - delete object; } void tst_qqmlxmlhttprequest::status_data() @@ -870,8 +800,8 @@ void tst_qqmlxmlhttprequest::statusText() testFileUrl("testdocument.html"))); QQmlComponent component(&engine, testFileUrl("statusText.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); object->setProperty("expectedStatus", statusText); component.completeCreate(); @@ -885,8 +815,6 @@ void tst_qqmlxmlhttprequest::statusText() QCOMPARE(object->property("loading").toBool(), true); QCOMPARE(object->property("done").toBool(), true); QCOMPARE(object->property("resetException").toBool(), true); - - delete object; } void tst_qqmlxmlhttprequest::statusText_data() @@ -912,8 +840,8 @@ void tst_qqmlxmlhttprequest::responseText() bodyUrl)); QQmlComponent component(&engine, testFileUrl("responseText.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); object->setProperty("expectedText", responseText); component.completeCreate(); @@ -927,8 +855,6 @@ void tst_qqmlxmlhttprequest::responseText() QCOMPARE(object->property("loading").toBool(), true); QCOMPARE(object->property("done").toBool(), true); QCOMPARE(object->property("reset").toBool(), true); - - delete object; } void tst_qqmlxmlhttprequest::responseText_data() @@ -950,11 +876,11 @@ void tst_qqmlxmlhttprequest::nonUtf8() QFETCH(QString, xmlRootNodeValue); QQmlComponent component(&engine, testFileUrl("utf16.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); object->setProperty("fileName", fileName); - QMetaObject::invokeMethod(object, "startRequest"); + QMetaObject::invokeMethod(object.data(), "startRequest"); QTRY_VERIFY(object->property("dataOK").toBool() == true); @@ -964,8 +890,6 @@ void tst_qqmlxmlhttprequest::nonUtf8() QString rootNodeValue = object->property("responseXmlRootNodeValue").toString(); QCOMPARE(rootNodeValue, xmlRootNodeValue); } - - delete object; } void tst_qqmlxmlhttprequest::nonUtf8_data() @@ -989,8 +913,8 @@ void tst_qqmlxmlhttprequest::nonUtf8_data() void tst_qqmlxmlhttprequest::invalidMethodUsage() { QQmlComponent component(&engine, testFileUrl("invalidMethodUsage.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QCOMPARE(object->property("readyState").toBool(), true); QCOMPARE(object->property("status").toBool(), true); @@ -1004,8 +928,6 @@ void tst_qqmlxmlhttprequest::invalidMethodUsage() QCOMPARE(object->property("abort").toBool(), true); QCOMPARE(object->property("getResponseHeader").toBool(), true); QCOMPARE(object->property("getAllResponseHeaders").toBool(), true); - - delete object; } // Test that XMLHttpRequest transparently redirects @@ -1018,16 +940,14 @@ void tst_qqmlxmlhttprequest::redirects() server.serveDirectory(dataDirectory()); QQmlComponent component(&engine, testFileUrl("redirects.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "http://127.0.0.1:14445/redirect.html"); object->setProperty("expectedText", ""); component.completeCreate(); QTRY_VERIFY(object->property("done").toBool() == true); QCOMPARE(object->property("dataOK").toBool(), true); - - delete object; } { @@ -1037,16 +957,14 @@ void tst_qqmlxmlhttprequest::redirects() server.serveDirectory(dataDirectory()); QQmlComponent component(&engine, testFileUrl("redirectError.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "http://127.0.0.1:14445/redirect.html"); object->setProperty("expectedText", ""); component.completeCreate(); QTRY_VERIFY(object->property("done").toBool() == true); QCOMPARE(object->property("dataOK").toBool(), true); - - delete object; } { @@ -1056,8 +974,8 @@ void tst_qqmlxmlhttprequest::redirects() server.serveDirectory(dataDirectory()); QQmlComponent component(&engine, testFileUrl("redirectRecur.qml")); - QObject *object = component.beginCreate(engine.rootContext()); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QVERIFY(!object.isNull()); object->setProperty("url", "http://127.0.0.1:14445/redirect.html"); object->setProperty("expectedText", ""); component.completeCreate(); @@ -1069,92 +987,78 @@ void tst_qqmlxmlhttprequest::redirects() QVERIFY(object->property("done").toBool() == true); QCOMPARE(object->property("dataOK").toBool(), true); - - delete object; } } void tst_qqmlxmlhttprequest::responseXML_invalid() { QQmlComponent component(&engine, testFileUrl("responseXML_invalid.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QTRY_VERIFY(object->property("dataOK").toBool() == true); QCOMPARE(object->property("xmlNull").toBool(), true); - - delete object; } // Test the Document DOM element void tst_qqmlxmlhttprequest::document() { QQmlComponent component(&engine, testFileUrl("document.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QTRY_VERIFY(object->property("dataOK").toBool() == true); QCOMPARE(object->property("xmlTest").toBool(), true); - - delete object; } // Test the Element DOM element void tst_qqmlxmlhttprequest::element() { QQmlComponent component(&engine, testFileUrl("element.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QTRY_VERIFY(object->property("dataOK").toBool() == true); QCOMPARE(object->property("xmlTest").toBool(), true); - - delete object; } // Test the Attr DOM element void tst_qqmlxmlhttprequest::attr() { QQmlComponent component(&engine, testFileUrl("attr.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QTRY_VERIFY(object->property("dataOK").toBool() == true); QCOMPARE(object->property("xmlTest").toBool(), true); - - delete object; } // Test the Text DOM element void tst_qqmlxmlhttprequest::text() { QQmlComponent component(&engine, testFileUrl("text.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QTRY_VERIFY(object->property("dataOK").toBool() == true); QCOMPARE(object->property("xmlTest").toBool(), true); - - delete object; } // Test the CDataSection DOM element void tst_qqmlxmlhttprequest::cdata() { QQmlComponent component(&engine, testFileUrl("cdata.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); QTRY_VERIFY(object->property("dataOK").toBool() == true); QCOMPARE(object->property("xmlTest").toBool(), true); - - delete object; } void tst_qqmlxmlhttprequest::stateChangeCallingContext() @@ -1171,11 +1075,10 @@ void tst_qqmlxmlhttprequest::stateChangeCallingContext() server.serveDirectory(dataDirectory(), TestHTTPServer::Delay); QQmlComponent component(&engine, testFileUrl("stateChangeCallingContext.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); server.sendDelayedItem(); QTRY_VERIFY(object->property("success").toBool() == true); - delete object; } QTEST_MAIN(tst_qqmlxmlhttprequest) |