From fdbdbbdd4ff05d1ceb7667227db5b14687a77c96 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Wed, 2 Nov 2011 10:21:37 +1000 Subject: Add support for assigning literal value to sequence property It is a language semantic that we allow clients to assign a single value to a sequence/list property (assuming that the types match). Now that we support sequence types, this commit adds support for this semantic by determining whether the built-in type of the literal corresponds to the associated sequence (eg, int for QList, qreal for QList, bool for QList, QString for QStringList etc). Similarly, some value types can be constructed from literal string values (via string converters) and these need to be handled also. Task-number: QTBUG-18062 Task-number: QTBUG-21770 Change-Id: Iacd91b2af122cd8f20b7df2fa6056a7d7c52bf53 Reviewed-by: Aaron Kennedy --- .../tst_qdeclarativeecmascript.cpp | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp') diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 3fdf1e905c..52e76614a3 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -177,8 +177,10 @@ private slots: void sequenceConversionThreads(); void sequenceConversionBindings(); void sequenceConversionCopy(); + void assignSequenceTypes(); void qtbug_22464(); void qtbug_21580(); + void bug1(); void bug2(); void dynamicCreationCrash(); @@ -4320,6 +4322,89 @@ void tst_qdeclarativeecmascript::sequenceConversionCopy() delete object; } +void tst_qdeclarativeecmascript::assignSequenceTypes() +{ + // test binding array to sequence type property + { + QDeclarativeComponent component(&engine, TEST_FILE("assignSequenceTypes.1.qml")); + MySequenceConversionObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->intListProperty(), (QList() << 1 << 2)); + QCOMPARE(object->qrealListProperty(), (QList() << 1.1 << 2.2)); + QCOMPARE(object->boolListProperty(), (QList() << false << true)); + QCOMPARE(object->urlListProperty(), (QList() << QUrl("http://www.example1.com") << QUrl("http://www.example2.com"))); + QCOMPARE(object->stringListProperty(), (QList() << QLatin1String("one") << QLatin1String("two"))); + QCOMPARE(object->qstringListProperty(), (QStringList() << QLatin1String("one") << QLatin1String("two"))); + delete object; + } + + // test binding literal to sequence type property + { + QDeclarativeComponent component(&engine, TEST_FILE("assignSequenceTypes.2.qml")); + MySequenceConversionObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->intListProperty(), (QList() << 1)); + QCOMPARE(object->qrealListProperty(), (QList() << 1.1)); + QCOMPARE(object->boolListProperty(), (QList() << false)); + QCOMPARE(object->urlListProperty(), (QList() << QUrl("http://www.example1.com"))); + QCOMPARE(object->stringListProperty(), (QList() << QLatin1String("one"))); + QCOMPARE(object->qstringListProperty(), (QStringList() << QLatin1String("two"))); + delete object; + } + + // test binding single value to sequence type property + { + QDeclarativeComponent component(&engine, TEST_FILE("assignSequenceTypes.3.qml")); + MySequenceConversionObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->intListProperty(), (QList() << 1)); + QCOMPARE(object->qrealListProperty(), (QList() << 1.1)); + QCOMPARE(object->boolListProperty(), (QList() << false)); + QCOMPARE(object->urlListProperty(), (QList() << QUrl(TEST_FILE("example.html")))); + delete object; + } + + // test assigning array to sequence type property in js function + { + QDeclarativeComponent component(&engine, TEST_FILE("assignSequenceTypes.4.qml")); + MySequenceConversionObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->intListProperty(), (QList() << 1 << 2)); + QCOMPARE(object->qrealListProperty(), (QList() << 1.1 << 2.2)); + QCOMPARE(object->boolListProperty(), (QList() << false << true)); + QCOMPARE(object->urlListProperty(), (QList() << QUrl("http://www.example1.com") << QUrl("http://www.example2.com"))); + QCOMPARE(object->stringListProperty(), (QList() << QLatin1String("one") << QLatin1String("two"))); + QCOMPARE(object->qstringListProperty(), (QStringList() << QLatin1String("one") << QLatin1String("two"))); + delete object; + } + + // test assigning literal to sequence type property in js function + { + QDeclarativeComponent component(&engine, TEST_FILE("assignSequenceTypes.5.qml")); + MySequenceConversionObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->intListProperty(), (QList() << 1)); + QCOMPARE(object->qrealListProperty(), (QList() << 1.1)); + QCOMPARE(object->boolListProperty(), (QList() << false)); + QCOMPARE(object->urlListProperty(), (QList() << QUrl("http://www.example1.com"))); + QCOMPARE(object->stringListProperty(), (QList() << QLatin1String("one"))); + QCOMPARE(object->qstringListProperty(), (QStringList() << QLatin1String("two"))); + delete object; + } + + // test assigning single value to sequence type property in js function + { + QDeclarativeComponent component(&engine, TEST_FILE("assignSequenceTypes.6.qml")); + MySequenceConversionObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->intListProperty(), (QList() << 1)); + QCOMPARE(object->qrealListProperty(), (QList() << 1.1)); + QCOMPARE(object->boolListProperty(), (QList() << false)); + QCOMPARE(object->urlListProperty(), (QList() << QUrl(TEST_FILE("example.html")))); + delete object; + } +} + // Test that assigning a null object works // Regressed with: df1788b4dbbb2826ae63f26bdf166342595343f4 void tst_qdeclarativeecmascript::nullObjectBinding() -- cgit v1.2.3