diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2012-02-27 11:08:15 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-27 02:39:41 +0100 |
commit | cd6cabc6ccd2499662ddb3b5748561557360843b (patch) | |
tree | d195874f82bf82b8fdd6b1b9fe31b5055f5a511a /tests | |
parent | 6c08b232f31430896e332b9222f3ded2b3e73c7a (diff) |
Improve test coverage for anchors.
Change-Id: I2705407b16ef678ed5b3cbfa7116ae6b18366688
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qtquick2/qquickanchors/data/stretch.qml | 39 | ||||
-rw-r--r-- | tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp | 41 |
2 files changed, 80 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qquickanchors/data/stretch.qml b/tests/auto/qtquick2/qquickanchors/data/stretch.qml new file mode 100644 index 0000000000..64e23e30b5 --- /dev/null +++ b/tests/auto/qtquick2/qquickanchors/data/stretch.qml @@ -0,0 +1,39 @@ +import QtQuick 2.0 + +Rectangle { + width: 400; height: 400 + + Rectangle { + id: rect1 + x: 20; y: 20; + height: 360; width: 360; + + Rectangle { + id: rect2; objectName: "stretcher" + anchors.verticalCenter: rect1.verticalCenter + anchors.bottom: rect3.top + anchors.horizontalCenter: rect1.horizontalCenter + anchors.left: rect3.left + } + + Rectangle { + id: rect3 + x: 160; y: 230 + width: 10 + height: 10 + } + + Rectangle { + id: rect4; objectName: "stretcher2" + anchors.verticalCenter: rect1.verticalCenter + anchors.top: rect5.top + } + + Rectangle { + id: rect5 + x: 160; y: 130 + width: 10 + height: 10 + } + } +} diff --git a/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp b/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp index 8d82abc53b..af43686e27 100644 --- a/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp +++ b/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp @@ -83,6 +83,7 @@ private slots: void fillRTL(); void margins(); void marginsRTL(); + void stretch(); }; void tst_qquickanchors::basicAnchors() @@ -472,6 +473,10 @@ void tst_qquickanchors::fill() qApp->processEvents(); QQuickRectangle* rect = findItem<QQuickRectangle>(view->rootObject(), QLatin1String("filler")); QQuickItemPrivate *rectPrivate = QQuickItemPrivate::get(rect); + QCOMPARE(rectPrivate->anchors()->leftMargin(), 10.0); + QCOMPARE(rectPrivate->anchors()->topMargin(), 30.0); + QCOMPARE(rectPrivate->anchors()->rightMargin(), 20.0); + QCOMPARE(rectPrivate->anchors()->bottomMargin(), 40.0); QCOMPARE(rect->x(), 0.0 + 10.0); QCOMPARE(rect->y(), 0.0 + 30.0); QCOMPARE(rect->width(), 200.0 - 10.0 - 20.0); @@ -481,6 +486,10 @@ void tst_qquickanchors::fill() rectPrivate->anchors()->setRightMargin(0.0); rectPrivate->anchors()->setBottomMargin(0.0); rectPrivate->anchors()->setTopMargin(10.0); + QCOMPARE(rectPrivate->anchors()->leftMargin(), 20.0); + QCOMPARE(rectPrivate->anchors()->topMargin(), 10.0); + QCOMPARE(rectPrivate->anchors()->rightMargin(), 0.0); + QCOMPARE(rectPrivate->anchors()->bottomMargin(), 0.0); QCOMPARE(rect->x(), 0.0 + 20.0); QCOMPARE(rect->y(), 0.0 + 10.0); QCOMPARE(rect->width(), 200.0 - 20.0); @@ -523,11 +532,15 @@ void tst_qquickanchors::centerIn() QQuickRectangle* rect = findItem<QQuickRectangle>(view->rootObject(), QLatin1String("centered")); QQuickItemPrivate *rectPrivate = QQuickItemPrivate::get(rect); + QCOMPARE(rectPrivate->anchors()->horizontalCenterOffset(), 10.0); + QCOMPARE(rectPrivate->anchors()->verticalCenterOffset(), 30.0); QCOMPARE(rect->x(), 75.0 + 10); QCOMPARE(rect->y(), 75.0 + 30); //Alter Offsets (tests QTBUG-6631) rectPrivate->anchors()->setHorizontalCenterOffset(-20.0); rectPrivate->anchors()->setVerticalCenterOffset(-10.0); + QCOMPARE(rectPrivate->anchors()->horizontalCenterOffset(), -20.0); + QCOMPARE(rectPrivate->anchors()->verticalCenterOffset(), -10.0); QCOMPARE(rect->x(), 75.0 - 20.0); QCOMPARE(rect->y(), 75.0 - 10.0); @@ -623,6 +636,11 @@ void tst_qquickanchors::margins() qApp->processEvents(); QQuickRectangle* rect = findItem<QQuickRectangle>(view->rootObject(), QLatin1String("filler")); QQuickItemPrivate *rectPrivate = QQuickItemPrivate::get(rect); + QCOMPARE(rectPrivate->anchors()->margins(), 10.0); + QCOMPARE(rectPrivate->anchors()->topMargin(), 6.0); + QCOMPARE(rectPrivate->anchors()->leftMargin(), 5.0); + QCOMPARE(rectPrivate->anchors()->bottomMargin(), 10.0); + QCOMPARE(rectPrivate->anchors()->rightMargin(), 10.0); QCOMPARE(rect->x(), 5.0); QCOMPARE(rect->y(), 6.0); QCOMPARE(rect->width(), 200.0 - 5.0 - 10.0); @@ -631,6 +649,12 @@ void tst_qquickanchors::margins() rectPrivate->anchors()->setTopMargin(0.0); rectPrivate->anchors()->setMargins(20.0); + QCOMPARE(rectPrivate->anchors()->margins(), 20.0); + QEXPECT_FAIL("","QTBUG-24515", Continue); + QCOMPARE(rectPrivate->anchors()->topMargin(), 0.0); + QCOMPARE(rectPrivate->anchors()->leftMargin(), 5.0); + QCOMPARE(rectPrivate->anchors()->bottomMargin(), 20.0); + QCOMPARE(rectPrivate->anchors()->rightMargin(), 20.0); QCOMPARE(rect->x(), 5.0); QCOMPARE(rect->y(), 20.0); QCOMPARE(rect->width(), 200.0 - 5.0 - 20.0); @@ -663,6 +687,23 @@ void tst_qquickanchors::marginsRTL() delete view; } +void tst_qquickanchors::stretch() +{ + QQuickView *view = new QQuickView(testFileUrl("stretch.qml")); + + qApp->processEvents(); + QQuickRectangle* rect = findItem<QQuickRectangle>(view->rootObject(), QLatin1String("stretcher")); + QCOMPARE(rect->x(), 160.0); + QCOMPARE(rect->y(), 130.0); + QCOMPARE(rect->width(), 40.0); + QCOMPARE(rect->height(), 100.0); + + QQuickRectangle* rect2 = findItem<QQuickRectangle>(view->rootObject(), QLatin1String("stretcher2")); + QCOMPARE(rect2->y(), 130.0); + QCOMPARE(rect2->height(), 100.0); + + delete view; +} QTEST_MAIN(tst_qquickanchors) |