diff options
Diffstat (limited to 'tests/auto/declarative/anchors')
-rw-r--r-- | tests/auto/declarative/anchors/data/anchors.qml | 18 | ||||
-rw-r--r-- | tests/auto/declarative/anchors/data/illegal1.qml | 12 | ||||
-rw-r--r-- | tests/auto/declarative/anchors/data/illegal2.qml | 13 | ||||
-rw-r--r-- | tests/auto/declarative/anchors/data/illegal3.qml | 12 | ||||
-rw-r--r-- | tests/auto/declarative/anchors/tst_anchors.cpp | 96 |
5 files changed, 86 insertions, 65 deletions
diff --git a/tests/auto/declarative/anchors/data/anchors.qml b/tests/auto/declarative/anchors/data/anchors.qml index b880762..b64d0b0 100644 --- a/tests/auto/declarative/anchors/data/anchors.qml +++ b/tests/auto/declarative/anchors/data/anchors.qml @@ -130,6 +130,24 @@ Rectangle { anchors.bottom: masterRect.bottom anchors.bottomMargin: 5 } + Rectangle { + id: rect24; objectName: "rect24" + width: 10; height: 10 + anchors.horizontalCenter: masterRect.left + anchors.horizontalCenterOffset: width/2 + } + Rectangle { + id: rect25; objectName: "rect25" + width: 10; height: 10 + anchors.verticalCenter: rect12.top + anchors.verticalCenterOffset: height/2 + } + Rectangle { + id: rect26; objectName: "rect26" + width: 10; height: 10 + anchors.baseline: masterRect.top + anchors.baselineOffset: height/2 + } Text { id: text1; objectName: "text1" y: 200; diff --git a/tests/auto/declarative/anchors/data/illegal1.qml b/tests/auto/declarative/anchors/data/illegal1.qml deleted file mode 100644 index 53af443..0000000 --- a/tests/auto/declarative/anchors/data/illegal1.qml +++ /dev/null @@ -1,12 +0,0 @@ -import Qt 4.6 - -Rectangle { - id: rect - width: 120; height: 200; color: "white" - Rectangle { id: theRect; width: 100; height: 100 } - Rectangle { - anchors.left: theRect.left - anchors.right: theRect.right - anchors.horizontalCenter: theRect.horizontalCenter - } -} diff --git a/tests/auto/declarative/anchors/data/illegal2.qml b/tests/auto/declarative/anchors/data/illegal2.qml deleted file mode 100644 index 978be52..0000000 --- a/tests/auto/declarative/anchors/data/illegal2.qml +++ /dev/null @@ -1,13 +0,0 @@ -import Qt 4.6 - -Rectangle { - id: rect - width: 120; height: 200; color: "white" - Text { id: text1; text: "Hello" } - Text { - id: text2; - anchors.baseline: text1.baseline; - anchors.top: text1.top; - text: "World" - } -} diff --git a/tests/auto/declarative/anchors/data/illegal3.qml b/tests/auto/declarative/anchors/data/illegal3.qml deleted file mode 100644 index 065ceb5..0000000 --- a/tests/auto/declarative/anchors/data/illegal3.qml +++ /dev/null @@ -1,12 +0,0 @@ -import Qt 4.6 - -Rectangle { - id: rect - width: 120; height: 200; color: "white" - Item { - Rectangle { id: theRect; width: 100; height: 100 } - } - Rectangle { - anchors.left: theRect.left - } -} diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 34c1e01..22f8327 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -60,6 +60,7 @@ private slots: void basicAnchors(); void loops(); void illegalSets(); + void illegalSets_data(); void reset(); void nullItem(); void crash1(); @@ -143,6 +144,11 @@ void tst_anchors::basicAnchors() QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect23"))->width(), 86.0); QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect23"))->height(), 10.0); + // offsets + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect24"))->x(), 26.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect25"))->y(), 60.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect26"))->y(), 5.0); + //baseline QmlGraphicsText *text1 = findItem<QmlGraphicsText>(view->root(), QLatin1String("text1")); QmlGraphicsText *text2 = findItem<QmlGraphicsText>(view->root(), QLatin1String("text2")); @@ -185,44 +191,71 @@ void tst_anchors::loops() void tst_anchors::illegalSets() { - { - QmlView *view = new QmlView; + QFETCH(QString, qml); + QFETCH(QString, warning); + + QTest::ignoreMessage(QtWarningMsg, warning.toLatin1()); + + QmlEngine engine; + QmlComponent component(&engine, QByteArray("import Qt 4.6\n" + qml.toUtf8()), QUrl("file://")); + if (!component.isReady()) + qWarning() << "Test errors:" << component.errors(); + QVERIFY(component.isReady()); + QObject *o = component.create(); + delete o; +} - view->setUrl(QUrl("file://" SRCDIR "/data/illegal1.qml")); +void tst_anchors::illegalSets_data() +{ + QTest::addColumn<QString>("qml"); + QTest::addColumn<QString>("warning"); - QString expect = "QML QmlGraphicsRectangle (" + view->url().toString() + ":7:5" + ") Can't specify left, right, and hcenter anchors."; - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - view->execute(); - qApp->processEvents(); + QTest::newRow("H - too many anchors") + << "Rectangle { id: rect; Rectangle { anchors.left: rect.left; anchors.right: rect.right; anchors.horizontalCenter: rect.horizontalCenter } }" + << "QML QmlGraphicsRectangle (file::2:23) Can't specify left, right, and hcenter anchors."; - delete view; - } + QTest::newRow("H - anchor to V") + << "Rectangle { Rectangle { anchors.left: parent.top } }" + << "QML QmlGraphicsRectangle (file::2:13) Can't anchor a horizontal edge to a vertical edge."; - { - QmlView *view = new QmlView; + QTest::newRow("H - anchor to non parent/sibling") + << "Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.left: rect.left } }" + << "QML QmlGraphicsRectangle (file::2:45) Can't anchor to an item that isn't a parent or sibling."; - view->setUrl(QUrl("file://" SRCDIR "/data/illegal2.qml")); + QTest::newRow("H - anchor to self") + << "Rectangle { id: rect; anchors.left: rect.left }" + << "QML QmlGraphicsRectangle (file::2:1) Can't anchor item to self."; - QString expect = "QML QmlGraphicsText (" + view->url().toString() + ":7:5" + ") Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors."; - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - view->execute(); - //qApp->processEvents(); - delete view; - } + QTest::newRow("V - too many anchors") + << "Rectangle { id: rect; Rectangle { anchors.top: rect.top; anchors.bottom: rect.bottom; anchors.verticalCenter: rect.verticalCenter } }" + << "QML QmlGraphicsRectangle (file::2:23) Can't specify top, bottom, and vcenter anchors."; - { - QmlView *view = new QmlView; + QTest::newRow("V - too many anchors with baseline") + << "Rectangle { Text { id: text1; text: \"Hello\" } Text { anchors.baseline: text1.baseline; anchors.top: text1.top; } }" + << "QML QmlGraphicsText (file::2:47) Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors."; - view->setUrl(QUrl("file://" SRCDIR "/data/illegal3.qml")); + QTest::newRow("V - anchor to H") + << "Rectangle { Rectangle { anchors.top: parent.left } }" + << "QML QmlGraphicsRectangle (file::2:13) Can't anchor a vertical edge to a horizontal edge."; - QString expect = "QML QmlGraphicsRectangle (" + view->url().toString() + ":9:5" + ") Can't anchor to an item that isn't a parent or sibling."; - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - view->execute(); - //qApp->processEvents(); + QTest::newRow("V - anchor to non parent/sibling") + << "Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.top: rect.top } }" + << "QML QmlGraphicsRectangle (file::2:45) Can't anchor to an item that isn't a parent or sibling."; - delete view; - } + QTest::newRow("V - anchor to self") + << "Rectangle { id: rect; anchors.top: rect.top }" + << "QML QmlGraphicsRectangle (file::2:1) Can't anchor item to self."; + + + QTest::newRow("centerIn - anchor to non parent/sibling") + << "Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.centerIn: rect} }" + << "QML QmlGraphicsRectangle (file::2:45) Can't anchor to an item that isn't a parent or sibling."; + + + QTest::newRow("fill - anchor to non parent/sibling") + << "Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.fill: rect} }" + << "QML QmlGraphicsRectangle (file::2:45) Can't anchor to an item that isn't a parent or sibling."; } void tst_anchors::reset() @@ -243,10 +276,17 @@ void tst_anchors::reset() void tst_anchors::nullItem() { QmlGraphicsAnchorLine anchor; + QmlGraphicsItem *item; QTest::ignoreMessage(QtWarningMsg, "QML QmlGraphicsItem (unknown location) Can't anchor to a null item."); - QmlGraphicsItem *item = new QmlGraphicsItem; + item = new QmlGraphicsItem; + item->anchors()->setLeft(anchor); + delete item; + + QTest::ignoreMessage(QtWarningMsg, "QML QmlGraphicsItem (unknown location) Can't anchor to a null item."); + item = new QmlGraphicsItem; item->anchors()->setBottom(anchor); + delete item; } void tst_anchors::crash1() |