diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-03-27 16:43:26 +0200 |
---|---|---|
committer | Kent Hansen <kent.hansen@nokia.com> | 2012-03-27 16:56:14 +0200 |
commit | 24fb8dc27eddfdd62bd2c3a6e863cbf433762cd6 (patch) | |
tree | 917eff8c50fe4699547b9de852ee53257c1585cf /tests | |
parent | 3e6a8eca00334df344a45f09afbcf8fd8e2b7c54 (diff) | |
parent | ffdbf216dc80b3d781307bb6b4b7150281c874a3 (diff) |
Merge master into api_changes
Conflicts:
src/qml/debugger/qqmlenginedebugservice.cpp
src/qml/debugger/qqmlprofilerservice_p.h
src/qml/qml/qqmlboundsignal.cpp
src/qml/qml/qqmlpropertycache.cpp
src/quick/util/qquickimageprovider.cpp
Change-Id: I0609aa5ed54c7769f1e2773a96a7cd43a69f133c
Diffstat (limited to 'tests')
24 files changed, 614 insertions, 62 deletions
diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp index e84e6623c1..b66ba289ce 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp @@ -202,18 +202,11 @@ void tst_QQmlEngineDebugService::recursiveObjectTest( foreach (const QmlDebugPropertyReference &p, oref.properties) { QCOMPARE(p.objectDebugId, QQmlDebugService::idForObject(o)); - // signal properties are fake - they are generated from QQmlBoundSignal children + // signal properties are fake - they are generated from QQmlAbstractBoundSignal children if (p.name.startsWith("on") && p.name.length() > 2 && p.name[2].isUpper()) { - QList<QQmlBoundSignal*> signalHandlers = - o->findChildren<QQmlBoundSignal*>(); QString signal = p.value.toString(); - bool found = false; - for (int i = 0; i < signalHandlers.count(); ++i) - if (signalHandlers.at(i)->expression()->expression() == signal) { - found = true; - break; - } - QVERIFY(found); + QQmlExpression *expr = QQmlPropertyPrivate::signalExpression(QQmlProperty(o, p.name)); + QVERIFY(expr && expr->expression() == signal); QVERIFY(p.valueTypeName.isEmpty()); QVERIFY(p.binding.isEmpty()); QVERIFY(!p.hasNotifySignal); diff --git a/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApiLegacy.qml b/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApiLegacy.qml new file mode 100644 index 0000000000..e282ad64f2 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApiLegacy.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +import Qt.test.legacyModuleApi 1.0 as ModApi // was registered with non-templated function + +QtObject { + property int legacyModulePropertyTest: ModApi.qobjectTestProperty + property int legacyModuleMethodTest + + Component.onCompleted: { + legacyModuleMethodTest = ModApi.qobjectTestMethod(); + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/registeredFlagMethod.qml b/tests/auto/qml/qqmlecmascript/data/registeredFlagMethod.qml new file mode 100644 index 0000000000..b323b49662 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/registeredFlagMethod.qml @@ -0,0 +1,5 @@ +import Qt.test 1.0 + +MyQmlObject { + onBasicSignal: registeredFlagMethod(Qt.RightButton) +} diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp index a79207a1c8..d674fa3eb6 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.cpp +++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp @@ -187,14 +187,15 @@ void registerTypes() qRegisterMetaType<MyQmlObject::MyType>("MyQmlObject::MyType"); - qmlRegisterModuleApi("Qt.test",1,0,script_api); // register (script) module API for an existing uri which contains elements - qmlRegisterModuleApi("Qt.test",1,0,qobject_api); // register (qobject) for an existing uri for which another module API was previously regd. Should replace! - qmlRegisterModuleApi("Qt.test.scriptApi",1,0,script_api); // register (script) module API for a uri which doesn't contain elements - qmlRegisterModuleApi("Qt.test.scriptApi",2,0,readonly_script_api); // register (script) module API for a uri which doesn't contain elements - will be made read-only - qmlRegisterModuleApi("Qt.test.qobjectApi",1,0,qobject_api); // register (qobject) module API for a uri which doesn't contain elements - qmlRegisterModuleApi("Qt.test.qobjectApi",1,3,qobject_api); // register (qobject) module API for a uri which doesn't contain elements, minor version set - qmlRegisterModuleApi("Qt.test.qobjectApi",2,0,qobject_api); // register (qobject) module API for a uri which doesn't contain elements, major version set - qmlRegisterModuleApi("Qt.test.qobjectApiParented",1,0,qobject_api_engine_parent); // register (parented qobject) module API for a uri which doesn't contain elements + qmlRegisterModuleApi("Qt.test",1,0,script_api); // register (script) module API for an existing uri which contains elements + qmlRegisterModuleApi<testQObjectApi>("Qt.test",1,0,qobject_api); // register (qobject) for an existing uri for which another module API was previously regd. Should replace! + qmlRegisterModuleApi("Qt.test.scriptApi",1,0,script_api); // register (script) module API for a uri which doesn't contain elements + qmlRegisterModuleApi("Qt.test.scriptApi",2,0,readonly_script_api); // register (script) module API for a uri which doesn't contain elements - will be made read-only + qmlRegisterModuleApi<testQObjectApi>("Qt.test.qobjectApi",1,0,qobject_api); // register (qobject) module API for a uri which doesn't contain elements + qmlRegisterModuleApi<testQObjectApi>("Qt.test.qobjectApi",1,3,qobject_api); // register (qobject) module API for a uri which doesn't contain elements, minor version set + qmlRegisterModuleApi<testQObjectApi>("Qt.test.qobjectApi",2,0,qobject_api); // register (qobject) module API for a uri which doesn't contain elements, major version set + qmlRegisterModuleApi<testQObjectApi>("Qt.test.qobjectApiParented",1,0,qobject_api_engine_parent); // register (parented qobject) module API for a uri which doesn't contain elements + qmlRegisterModuleApi("Qt.test.legacyModuleApi", 1, 0, qobject_api); // this registration function doesn't provide type information. qRegisterMetaType<MyQmlObject::MyEnum2>("MyEnum2"); qRegisterMetaType<Qt::MouseButtons>("Qt::MouseButtons"); diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index ab8f85baa3..167e944aa6 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -103,7 +103,7 @@ class MyQmlObject : public QObject Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty NOTIFY intChanged) public: - MyQmlObject(): myinvokableObject(0), m_methodCalled(false), m_methodIntCalled(false), m_object(0), m_value(0), m_resetProperty(13), m_intProperty(0) {} + MyQmlObject(): myinvokableObject(0), m_methodCalled(false), m_methodIntCalled(false), m_object(0), m_value(0), m_resetProperty(13), m_intProperty(0), m_buttons(0) {} enum MyEnum { EnumValue1 = 0, EnumValue2 = 1 }; enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3 }; @@ -174,6 +174,7 @@ public: }; QVariant variant() const { return m_variant; } QJSValue qjsvalue() const { return m_qjsvalue; } + Qt::MouseButtons buttons() const { return m_buttons; } int intProperty() const { return m_intProperty; } void setIntProperty(int i) { m_intProperty = i; emit intChanged(); } @@ -202,6 +203,7 @@ public slots: void variantMethod(const QVariant &v) { m_variant = v; } void qjsvalueMethod(const QJSValue &v) { m_qjsvalue = v; } void v8function(QQmlV8Function*); + void registeredFlagMethod(Qt::MouseButtons v) { m_buttons = v; } private: friend class tst_qqmlecmascript; @@ -218,6 +220,7 @@ private: QVariant m_variant; QJSValue m_qjsvalue; int m_intProperty; + Qt::MouseButtons m_buttons; }; QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES) diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index d932bc6d09..b3bf92fe81 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -245,6 +245,7 @@ private slots: void revision(); void invokableWithQObjectDerived(); void realTypePrecision(); + void registeredFlagMethod(); void automaticSemicolon(); void unaryExpression(); @@ -3372,6 +3373,17 @@ void tst_qqmlecmascript::moduleApi_data() << QVariantList() << QStringList() << QVariantList(); + + QTest::newRow("legacy module api registration") + << testFileUrl("moduleapi/qobjectModuleApiLegacy.qml") + << QString() + << QStringList() // warning doesn't occur in the test, but in registerTypes() + << (QStringList() << "legacyModulePropertyTest" << "legacyModuleMethodTest") + << (QVariantList() << 20 << 2) + << QStringList() + << QVariantList() + << QStringList() + << QVariantList(); } void tst_qqmlecmascript::moduleApi() @@ -6382,6 +6394,20 @@ void tst_qqmlecmascript::realTypePrecision() QCOMPARE(object->property("test6").toDouble(), 1234567890.*2); } +void tst_qqmlecmascript::registeredFlagMethod() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("registeredFlagMethod.qml")); + MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->buttons(), 0); + emit object->basicSignal(); + QCOMPARE(object->buttons(), Qt::RightButton); + + delete object; +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" diff --git a/tests/auto/qml/qquickconnection/tst_qquickconnection.cpp b/tests/auto/qml/qquickconnection/tst_qquickconnection.cpp index ad687dd085..1167281eb0 100644 --- a/tests/auto/qml/qquickconnection/tst_qquickconnection.cpp +++ b/tests/auto/qml/qquickconnection/tst_qquickconnection.cpp @@ -263,7 +263,7 @@ static QObject *module_api_factory(QQmlEngine *engine, QJSEngine *scriptEngine) // QTBUG-20937 void tst_qquickconnection::moduleApiTarget() { - qmlRegisterModuleApi("MyTestModuleApi", 1, 0, module_api_factory); + qmlRegisterModuleApi<MyTestModuleApi>("MyTestModuleApi", 1, 0, module_api_factory); QQmlComponent component(&engine, testFileUrl("moduleapi-target.qml")); QObject *object = component.create(); QVERIFY(object != 0); diff --git a/tests/auto/qml/v4/data/moduleApi.qml b/tests/auto/qml/v4/data/moduleApi.qml new file mode 100644 index 0000000000..9f3bf0ca8c --- /dev/null +++ b/tests/auto/qml/v4/data/moduleApi.qml @@ -0,0 +1,12 @@ +import Qt.test 1.0 as ModApi +import QtQuick 2.0 + +Item { + property int testProp: ModApi.ip + property int testProp2: 2 + + function getRandom() { + testProp2 = ModApi.random(); + // testProp should also have changed. + } +} diff --git a/tests/auto/qml/v4/tst_v4.cpp b/tests/auto/qml/v4/tst_v4.cpp index 8c811f230e..47fa10b595 100644 --- a/tests/auto/qml/v4/tst_v4.cpp +++ b/tests/auto/qml/v4/tst_v4.cpp @@ -81,6 +81,7 @@ private slots: void mathCeil(); void mathMax(); void mathMin(); + void moduleApi(); private: QQmlEngine engine; @@ -589,6 +590,46 @@ void tst_v4::mathMin() delete o; } +class V4ModuleApi : public QObject +{ + Q_OBJECT + Q_PROPERTY(int ip READ ip WRITE setIp NOTIFY ipChanged FINAL) +public: + V4ModuleApi() : m_ip(12) {} + ~V4ModuleApi() {} + + Q_INVOKABLE int random() { static int prng = 3; prng++; m_ip++; emit ipChanged(); return prng; } + + int ip() const { return m_ip; } + void setIp(int v) { m_ip = v; emit ipChanged(); } + +signals: + void ipChanged(); + +private: + int m_ip; +}; + +static QObject *v4_module_api_factory(QQmlEngine*, QJSEngine*) +{ + return new V4ModuleApi; +} + +void tst_v4::moduleApi() +{ + // register module api, providing typeinfo via template + qmlRegisterModuleApi<V4ModuleApi>("Qt.test", 1, 0, v4_module_api_factory); + QQmlComponent component(&engine, testFileUrl("moduleApi.qml")); + QObject *o = component.create(); + QVERIFY(o != 0); + QCOMPARE(o->property("testProp").toInt(), 12); + QCOMPARE(o->property("testProp2").toInt(), 2); + QMetaObject::invokeMethod(o, "getRandom"); + QCOMPARE(o->property("testProp").toInt(), 13); + QCOMPARE(o->property("testProp2").toInt(), 4); + delete o; +} + QTEST_MAIN(tst_v4) #include "tst_v4.moc" diff --git a/tests/auto/quick/qquickanchors/data/baselineOffset.qml b/tests/auto/quick/qquickanchors/data/baselineOffset.qml new file mode 100644 index 0000000000..8bae61d16d --- /dev/null +++ b/tests/auto/quick/qquickanchors/data/baselineOffset.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 + +Item { + width: 200 + height: 200 + + Item { + objectName: "baselineAnchored" + + width: 200 + height: 10 + + anchors.baseline: parent.verticalCenter + } +} diff --git a/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp b/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp index dd1f9f77ae..7b748f6191 100644 --- a/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp +++ b/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp @@ -84,6 +84,7 @@ private slots: void margins(); void marginsRTL(); void stretch(); + void baselineOffset(); }; void tst_qquickanchors::basicAnchors() @@ -705,6 +706,29 @@ void tst_qquickanchors::stretch() delete view; } +void tst_qquickanchors::baselineOffset() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("baselineOffset.qml")); + QScopedPointer<QObject> object(component.create()); + + QQuickItem *item = qobject_cast<QQuickItem *>(object.data()); + QVERIFY(item); + + QQuickItem *anchoredItem = findItem<QQuickItem>(item, QLatin1String("baselineAnchored")); + + QCOMPARE(anchoredItem->baselineOffset(), 0.0); + QCOMPARE(anchoredItem->y(), 100.0); + + anchoredItem->setBaselineOffset(5); + QCOMPARE(anchoredItem->baselineOffset(), 5.0); + QCOMPARE(anchoredItem->y(), 95.0); + + anchoredItem->setBaselineOffset(10); + QCOMPARE(anchoredItem->baselineOffset(), 10.0); + QCOMPARE(anchoredItem->y(), 90.0); +} + QTEST_MAIN(tst_qquickanchors) #include "tst_qquickanchors.moc" diff --git a/tests/auto/quick/qquickfontloader/qquickfontloader.pro b/tests/auto/quick/qquickfontloader/qquickfontloader.pro index 3e52b6fe7b..2eeb286e61 100644 --- a/tests/auto/quick/qquickfontloader/qquickfontloader.pro +++ b/tests/auto/quick/qquickfontloader/qquickfontloader.pro @@ -13,5 +13,3 @@ TESTDATA = data/* CONFIG += parallel_test QT += core-private gui-private qml-private quick-private network testlib - -win32:CONFIG += insignificant_test # QTBUG-24782 diff --git a/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro b/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro index 20fddb9410..fee91fb0d5 100644 --- a/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro +++ b/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro @@ -26,5 +26,3 @@ OTHER_FILES += \ data/SamplerNameChange.qml \ data/ItemEffect.qml \ data/RectangleEffect.qml - -win32:CONFIG += insignificant_test # QTBUG-24787 diff --git a/tests/auto/quick/qquicklistview/data/destroyItemOnCreation.qml b/tests/auto/quick/qquicklistview/data/destroyItemOnCreation.qml new file mode 100644 index 0000000000..12f43b029a --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/destroyItemOnCreation.qml @@ -0,0 +1,37 @@ +import QtQuick 2.0 + +Rectangle { + id: root + + width: 240 + height: 320 + + property int createdIndex: -1 + + Component { + id: myDelegate + + Rectangle { + id: wrapper + width: 240; height: 20 + objectName: "wrapper" + + Text { text: index } + + Component.onCompleted: { + root.createdIndex = index + ListView.view.model.removeItem(index) + } + } + } + + ListView { + id: list + objectName: "list" + focus: true + width: 240 + height: 320 + delegate: myDelegate + model: testModel + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 461a6b6750..1218d3cfcb 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -189,6 +189,7 @@ private slots: void multipleDisplaced(); void flickBeyondBounds(); + void destroyItemOnCreation(); private: template <class T> void items(const QUrl &source, bool forceLayout); @@ -6245,6 +6246,32 @@ void tst_QQuickListView::flickBeyondBounds() delete canvas; } +void tst_QQuickListView::destroyItemOnCreation() +{ + QmlListModel model; + QQuickView *canvas = createView(); + canvas->rootContext()->setContextProperty("testModel", &model); + + canvas->setSource(testFileUrl("destroyItemOnCreation.qml")); + canvas->show(); + qApp->processEvents(); + + QQuickListView *listview = findItem<QQuickListView>(canvas->rootObject(), "list"); + QVERIFY(listview != 0); + + QQuickItem *contentItem = listview->contentItem(); + QVERIFY(contentItem != 0); + QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + + QCOMPARE(canvas->rootObject()->property("createdIndex").toInt(), -1); + model.addItem("new item", ""); + QTRY_COMPARE(canvas->rootObject()->property("createdIndex").toInt(), 0); + + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").count(), 0); + QCOMPARE(model.count(), 0); + + delete canvas; +} QTEST_MAIN(tst_QQuickListView) diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index 613156b2f5..85d2c3b6ea 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -124,6 +124,7 @@ private slots: void currentOffsetOnInsertion(); void asynchronous(); void cancelDrag(); + void maximumFlickVelocity(); }; class TestObject : public QObject @@ -944,6 +945,13 @@ void tst_QQuickPathView::propertyChanges() QCOMPARE(snapPositionSpy.count(), 1); QCOMPARE(dragMarginSpy.count(), 1); + + QSignalSpy maximumFlickVelocitySpy(pathView, SIGNAL(maximumFlickVelocityChanged())); + pathView->setMaximumFlickVelocity(1000); + QCOMPARE(maximumFlickVelocitySpy.count(), 1); + pathView->setMaximumFlickVelocity(1000); + QCOMPARE(maximumFlickVelocitySpy.count(), 1); + delete canvas; } @@ -1488,6 +1496,52 @@ void tst_QQuickPathView::cancelDrag() delete canvas; } +void tst_QQuickPathView::maximumFlickVelocity() +{ + QQuickView *canvas = createView(); + canvas->setSource(testFileUrl("dragpath.qml")); + canvas->show(); + canvas->requestActivateWindow(); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(canvas, qGuiApp->focusWindow()); + + QQuickPathView *pathview = qobject_cast<QQuickPathView*>(canvas->rootObject()); + QVERIFY(pathview != 0); + + pathview->setMaximumFlickVelocity(700); + flick(canvas, QPoint(200,10), QPoint(10,10), 180); + QVERIFY(pathview->isMoving()); + QVERIFY(pathview->isFlicking()); + QTRY_VERIFY(!pathview->isMoving()); + + double dist1 = 100 - pathview->offset(); + + pathview->setOffset(0.); + pathview->setMaximumFlickVelocity(300); + flick(canvas, QPoint(200,10), QPoint(10,10), 180); + QVERIFY(pathview->isMoving()); + QVERIFY(pathview->isFlicking()); + QTRY_VERIFY(!pathview->isMoving()); + + double dist2 = 100 - pathview->offset(); + + pathview->setOffset(0.); + pathview->setMaximumFlickVelocity(500); + flick(canvas, QPoint(200,10), QPoint(10,10), 180); + QVERIFY(pathview->isMoving()); + QVERIFY(pathview->isFlicking()); + QTRY_VERIFY(!pathview->isMoving()); + + double dist3 = 100 - pathview->offset(); + + QVERIFY(dist1 > dist2); + QVERIFY(dist3 > dist2); + QVERIFY(dist2 < dist1); + + delete canvas; +} + + QTEST_MAIN(tst_QQuickPathView) diff --git a/tests/auto/quick/qquicktext/qquicktext.pro b/tests/auto/quick/qquicktext/qquicktext.pro index daa7bed97b..8932664fa3 100644 --- a/tests/auto/quick/qquicktext/qquicktext.pro +++ b/tests/auto/quick/qquicktext/qquicktext.pro @@ -15,5 +15,3 @@ TESTDATA = data/* CONFIG += parallel_test QT += core-private gui-private v8-private qml-private quick-private network testlib - -win32:CONFIG += insignificant_test # QTBUG-24789 diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index affb355837..f4ba0864e5 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -110,6 +110,8 @@ private slots: void implicitSizeBinding_data(); void implicitSizeBinding(); + void boundingRect_data(); + void boundingRect(); void lineLaidOut(); void imgTagsBaseUrl_data(); @@ -1669,6 +1671,80 @@ void tst_qquicktext::implicitSizeBinding() QCOMPARE(textObject->height(), textObject->implicitHeight()); } +void tst_qquicktext::boundingRect_data() +{ + QTest::addColumn<QString>("format"); + QTest::newRow("PlainText") << "Text.PlainText"; + QTest::newRow("StyledText") << "Text.StyledText"; + QTest::newRow("RichText") << "Text.RichText"; +} + +void tst_qquicktext::boundingRect() +{ + QFETCH(QString, format); + + QDeclarativeComponent component(&engine); + component.setData("import QtQuick 2.0\n Text { textFormat:" + format.toUtf8() + "}", QUrl()); + QScopedPointer<QObject> object(component.create()); + QQuickText *text = qobject_cast<QQuickText *>(object.data()); + QVERIFY(text); + + QCOMPARE(text->boundingRect().x(), qreal(0)); + QCOMPARE(text->boundingRect().y(), qreal(0)); + QCOMPARE(text->boundingRect().width(), qreal(0)); + QCOMPARE(text->boundingRect().height(), QFontMetricsF(text->font()).height()); + + text->setText("Hello World"); + + QTextLayout layout(text->text()); + layout.setFont(text->font()); + + if (!qmlDisableDistanceField()) { + QTextOption option; + option.setUseDesignMetrics(true); + layout.setTextOption(option); + } + layout.beginLayout(); + QTextLine line = layout.createLine(); + layout.endLayout(); + + QCOMPARE(text->boundingRect().x(), qreal(0)); + QCOMPARE(text->boundingRect().y(), qreal(0)); + QCOMPARE(text->boundingRect().width(), line.naturalTextWidth()); + QCOMPARE(text->boundingRect().height(), line.height()); + + // the size of the bounding rect shouldn't be bounded by the size of item. + text->setWidth(text->width() / 2); + QCOMPARE(text->boundingRect().x(), qreal(0)); + QCOMPARE(text->boundingRect().y(), qreal(0)); + QCOMPARE(text->boundingRect().width(), line.naturalTextWidth()); + QCOMPARE(text->boundingRect().height(), line.height()); + + text->setHeight(text->height() * 2); + QCOMPARE(text->boundingRect().x(), qreal(0)); + QCOMPARE(text->boundingRect().y(), qreal(0)); + QCOMPARE(text->boundingRect().width(), line.naturalTextWidth()); + QCOMPARE(text->boundingRect().height(), line.height()); + + text->setHAlign(QQuickText::AlignRight); + QCOMPARE(text->boundingRect().x(), text->width() - line.naturalTextWidth()); + QCOMPARE(text->boundingRect().y(), qreal(0)); + QCOMPARE(text->boundingRect().width(), line.naturalTextWidth()); + QCOMPARE(text->boundingRect().height(), line.height()); + + text->setWrapMode(QQuickText::Wrap); + QCOMPARE(text->boundingRect().right(), text->width()); + QCOMPARE(text->boundingRect().y(), qreal(0)); + QVERIFY(text->boundingRect().width() < line.naturalTextWidth()); + QVERIFY(text->boundingRect().height() > line.height()); + + text->setVAlign(QQuickText::AlignBottom); + QCOMPARE(text->boundingRect().right(), text->width()); + QCOMPARE(text->boundingRect().bottom(), text->height()); + QVERIFY(text->boundingRect().width() < line.naturalTextWidth()); + QVERIFY(text->boundingRect().height() > line.height()); +} + void tst_qquicktext::lineLaidOut() { QQuickView *canvas = createView(testFile("lineLayout.qml")); diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 83e7e78866..ab21f3bc54 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -2287,16 +2287,6 @@ void tst_qquicktextedit::textInput() QQuickTextEditPrivate *editPrivate = static_cast<QQuickTextEditPrivate*>(QQuickItemPrivate::get(edit)); QCOMPARE(editPrivate->text, QString("Hello world!")); - // test that tentative commit is included in text property - edit->setText(""); - spy.clear(); - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent event2("preedit", attributes); - event2.setTentativeCommitString("string"); - QGuiApplication::sendEvent(qGuiApp->focusObject(), &event2); - QCOMPARE(spy.count(), 1); - QCOMPARE(edit->text(), QString("string")); - QInputMethodQueryEvent queryEvent(Qt::ImEnabled); QGuiApplication::sendEvent(qGuiApp->focusObject(), &queryEvent); QCOMPARE(queryEvent.value(Qt::ImEnabled).toBool(), true); diff --git a/tests/auto/quick/qquicktextinput/qquicktextinput.pro b/tests/auto/quick/qquicktextinput/qquicktextinput.pro index 336338f500..13b087eef5 100644 --- a/tests/auto/quick/qquicktextinput/qquicktextinput.pro +++ b/tests/auto/quick/qquicktextinput/qquicktextinput.pro @@ -9,5 +9,3 @@ include (../../shared/util.pri) TESTDATA = data/* QT += core-private gui-private v8-private qml-private quick-private testlib - -win32:CONFIG += insignificant_test # QTBUG-24790 diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index afe102aa4c..1c8bff9d69 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -2022,28 +2022,6 @@ void tst_qquicktextinput::inputMethods() QCOMPARE(input->text(), QString("Our Goodbye world!")); QCOMPARE(input->cursorPosition(), 7); - // test that basic tentative commit gets to text property on preedit state - input->setText(""); - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent preeditEvent("test", attributes); - preeditEvent.setTentativeCommitString("test"); - QGuiApplication::sendEvent(input, &preeditEvent); - QCOMPARE(input->text(), QString("test")); - - // tentative commit not allowed present in surrounding text - QInputMethodQueryEvent queryEvent(Qt::ImSurroundingText); - QGuiApplication::sendEvent(input, &queryEvent); - QCOMPARE(queryEvent.value(Qt::ImSurroundingText).toString(), QString("")); - - // if text with tentative commit does not validate, not allowed to be part of text property - input->setText(""); // ensure input state is reset - QValidator *validator = new QIntValidator(0, 100); - input->setValidator(validator); - QGuiApplication::sendEvent(input, &preeditEvent); - QCOMPARE(input->text(), QString("")); - input->setValidator(0); - delete validator; - // input should reset selection even if replacement parameters are out of bounds input->setText("text"); input->setCursorPosition(0); diff --git a/tests/auto/quick/shared/viewtestutil.h b/tests/auto/quick/shared/viewtestutil.h index 6ab754cff6..06efd9c28e 100644 --- a/tests/auto/quick/shared/viewtestutil.h +++ b/tests/auto/quick/shared/viewtestutil.h @@ -97,8 +97,8 @@ namespace QQuickViewTestUtil void insertItem(int index, const QString &name, const QString &number); void insertItems(int index, const QList<QPair<QString, QString> > &items); - void removeItem(int index); - void removeItems(int index, int count); + Q_INVOKABLE void removeItem(int index); + Q_INVOKABLE void removeItems(int index, int count); void moveItem(int from, int to); void moveItems(int from, int to, int count); diff --git a/tests/system/sys_listview.qtt b/tests/system/sys_listview.qtt index efd116fa92..ca10e1a0df 100644 --- a/tests/system/sys_listview.qtt +++ b/tests/system/sys_listview.qtt @@ -43,6 +43,74 @@ testcase = { + using_section_delegates: function() + { + // Test Meta-data + testTitle = "Using and changing section delegate properties"; + testBinary = "sections.qml"; + testSource: "$QTDIR/qtdeclarative/tests/system/listview"; + testGoal = "Verify that a Component can be set as a section header, using various properties for different collections."; + testPreconditions = "None"; + testGroups = "BAT,QtQuick 2.0"; + + // Test Steps + prompt(twiki('---+++ ' + testTitle + '<br><br> + *Goal:* ' + testGoal + '<br> + *Pre-Requisites:* ' + testPreconditions + '<br> + *Tested Binary:* ' + testBinary + '<br> + | *Step* | *Verification* | + | Run '+testBinary+' | Application has started, showing a ListView | + | | The view shows a single character section header for each element | + | Press the Criteria button | The section headers now show the full name of each item | + | Press Property | The section headers now show the id value for the items | + | Press Criteria | The section headers now only show i - the first character of id | + | Press Property | The section headers show the first character of the item names |')); + }, + + updating_sections: function() + { + // Test Meta-data + testTitle = "Updating Collected Sections"; + testBinary = "sections.qml"; + testSource: "$QTDIR/qtdeclarative/tests/system/listview"; + testGoal = "Verify that a section is updated when items are added."; + testPreconditions = "None"; + testGroups = "BAT,QtQuick 2.0"; + + // Test Steps + prompt(twiki('---+++ ' + testTitle + '<br><br> + *Goal:* ' + testGoal + '<br> + *Pre-Requisites:* ' + testPreconditions + '<br> + *Tested Binary:* ' + testBinary + '<br> + | *Step* | *Verification* | + | Run '+testBinary+' | Application has started, showing a ListView | + | | The view shows a single character section header for each element | + | Press the + button | A duplicate of every name is added | + | | Each duplicate is place in the same section as the original |')); + }, + + changing_section_delegates: function() + { + // Test Meta-data + testTitle = "Changing Section Delegates"; + testBinary = "sections.qml"; + testSource: "$QTDIR/qtdeclarative/tests/system/listview"; + testGoal = "Verify that a section delegate can be changed."; + testPreconditions = "None"; + testGroups = "BAT,QtQuick 2.0"; + + // Test Steps + prompt(twiki('---+++ ' + testTitle + '<br><br> + *Goal:* ' + testGoal + '<br> + *Pre-Requisites:* ' + testPreconditions + '<br> + *Tested Binary:* ' + testBinary + '<br> + | *Step* | *Verification* | + | Run '+testBinary+' | Application has started, showing a ListView | + | | The view shows a single character section header for each element | + | Press the Delegate button | The section headers now show as light blue rectangles | + | Press the Criteria button | The headers show as full names, still within light blue rectangles |')); + }, + altering_listview_primary_properties: function() { // Test Meta-data diff --git a/tests/testapplications/listview/sections.qml b/tests/testapplications/listview/sections.qml new file mode 100644 index 0000000000..1251e8eef1 --- /dev/null +++ b/tests/testapplications/listview/sections.qml @@ -0,0 +1,197 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + height: 400 + width: 300 + property int sets: 1 + + ListModel { + id: listmodel + Component.onCompleted: addNames() + } + + ListView { + id: listview + model: listmodel + height: 300 + width: 200 + clip: true + anchors.centerIn: parent + + section.delegate: del1 + section.criteria: ViewSection.FirstCharacter + section.property: "name" + delegate: Rectangle { + height: 50 + width: 200 + color: "gold" + border.color: "black" + Text { + anchors.centerIn: parent + text: model.name+" ["+model.id+"]" + color: "black" + font.bold: true + } + } + } + + function addNames() { + var names = ["Alpha","Bravo","Charlie","Delta","Echo","Foxtrot", + "Golf","Hotel","India","Juliet","Kilo","Lima","Mike", + "November","Oscar","Papa","Quebec","Romeo","Sierra","Tango", + "Uniform","Victor","Whiskey","XRay","Yankee","Zulu"]; + for (var i=0;i<names.length;++i) + listmodel.insert(sets*i, {"name":names[i], "id": "id"+i}); + sets++; + } + + Component { + id: del1 + Rectangle { + height: 50 + width: 200 + color: "white" + border.color: "black" + border.width: 3 + Text { + anchors.centerIn: parent + text: section + } + } + } + + Component { + id: del2 + Rectangle { + height: 50 + width: 200 + color: "lightsteelblue" + border.color: "orange" + Text { + anchors.centerIn: parent + text: section + } + } + } + + Rectangle { + anchors.fill: listview + color: "transparent" + border.color: "green" + border.width: 3 + } + + Row { + spacing: 3 + Rectangle { + height: 40 + width: 70 + color: "blue" + Text { + color: "white" + anchors.centerIn: parent + text: "Criteria" + } + radius: 5 + MouseArea { + anchors.fill: parent + onClicked: { + listview.section.criteria = listview.section.criteria == ViewSection.FirstCharacter ? + ViewSection.FullString : ViewSection.FirstCharacter + } + } + } + Rectangle { + height: 40 + width: 70 + color: "blue" + Text { + color: "white" + anchors.centerIn: parent + text: "Property" + } + radius: 5 + MouseArea { + anchors.fill: parent + onClicked: { + listview.section.property = listview.section.property == "name" ? "id" : "name"; + console.log(listview.section.property) + } + } + } + Rectangle { + height: 40 + width: 75 + color: "blue" + Text { + color: "white" + anchors.centerIn: parent + text: "Delegate" + } + radius: 5 + MouseArea { + anchors.fill: parent + onClicked: { + console.log("Change delegate") + listview.section.delegate = listview.section.delegate == del1 ? del2 : del1 + } + } + } + Rectangle { + height: 40 + width: 40 + color: "blue" + Text { + color: "white" + anchors.centerIn: parent + text: "+" + font.bold: true + } + radius: 5 + MouseArea { + anchors.fill: parent + onClicked: { addNames(); } + } + } + } +} |