summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-10-16 12:51:26 +0200
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-10-16 12:51:26 +0200
commite0a5d1f18d5dee85ddc312094f5bb4d49ea3d286 (patch)
treed735dcb44a164aa2e7d2b163841a5c00da56339e /tests
parent5f184a0c3485f9c8e35d3cc7c3c2f715f0f94111 (diff)
parentea52aef43acf862a51ea5b2eb65fa2ad60e5590f (diff)
Merge branch 'fixes' of git://gitorious.org/~fleury/qt/fleury-openbossa-clone into 4.6
Conflicts: src/gui/graphicsview/qgraphicsanchorlayout_p.cpp src/gui/graphicsview/qgraphicsanchorlayout_p.h tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp85
-rw-r--r--tests/benchmarks/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp236
2 files changed, 299 insertions, 22 deletions
diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
index cef56b9761..cce7b4c414 100644
--- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
+++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
@@ -49,6 +49,14 @@
class tst_QGraphicsAnchorLayout : public QObject {
Q_OBJECT;
+public:
+ tst_QGraphicsAnchorLayout() : QObject() {
+ hasSimplification = qgetenv("QT_ANCHORLAYOUT_NO_SIMPLIFICATION").isEmpty();
+ }
+
+private:
+ bool hasSimplification;
+
private slots:
void simple();
void simple_center();
@@ -185,8 +193,10 @@ void tst_QGraphicsAnchorLayout::simple()
p.setLayout(l);
p.adjustSize();
- QVERIFY(!usedSimplex(l, Qt::Horizontal));
- QVERIFY(!usedSimplex(l, Qt::Vertical));
+ if (hasSimplification) {
+ QVERIFY(!usedSimplex(l, Qt::Horizontal));
+ QVERIFY(!usedSimplex(l, Qt::Vertical));
+ }
}
void tst_QGraphicsAnchorLayout::simple_center()
@@ -226,8 +236,10 @@ void tst_QGraphicsAnchorLayout::simple_center()
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
QCOMPARE(layoutMaximumSize, QSizeF(200, 20));
- QVERIFY(usedSimplex(l, Qt::Horizontal));
- QVERIFY(!usedSimplex(l, Qt::Vertical));
+ if (hasSimplification) {
+ QVERIFY(usedSimplex(l, Qt::Horizontal));
+ QVERIFY(!usedSimplex(l, Qt::Vertical));
+ }
delete p;
}
@@ -417,8 +429,10 @@ void tst_QGraphicsAnchorLayout::diagonal()
QCOMPARE(e->geometry(), QRectF(100.0, 200.0, 75.0, 100.0));
QCOMPARE(p.size(), testA);
- QVERIFY(usedSimplex(l, Qt::Horizontal));
- QVERIFY(!usedSimplex(l, Qt::Vertical));
+ if (hasSimplification) {
+ QVERIFY(usedSimplex(l, Qt::Horizontal));
+ QVERIFY(!usedSimplex(l, Qt::Vertical));
+ }
QCOMPARE(checkReverseDirection(&p), true);
@@ -496,6 +510,9 @@ void tst_QGraphicsAnchorLayout::parallel()
QCOMPARE(f->geometry(), QRectF(350, 500, 100, 100));
QCOMPARE(p.size(), layoutMinimumSize);
+ if (!hasSimplification)
+ return;
+
p.resize(layoutPreferredSize);
QCOMPARE(a->geometry(), QRectF(0, 0, 150, 100));
QCOMPARE(b->geometry(), QRectF(150, 100, 150, 100));
@@ -565,8 +582,10 @@ void tst_QGraphicsAnchorLayout::parallel2()
p.resize(layoutMaximumSize);
QCOMPARE(p.size(), layoutMaximumSize);
- QVERIFY(!usedSimplex(l, Qt::Horizontal));
- QVERIFY(!usedSimplex(l, Qt::Vertical));
+ if (hasSimplification) {
+ QVERIFY(!usedSimplex(l, Qt::Horizontal));
+ QVERIFY(!usedSimplex(l, Qt::Vertical));
+ }
}
void tst_QGraphicsAnchorLayout::snake()
@@ -758,6 +777,8 @@ void tst_QGraphicsAnchorLayout::fairDistribution()
QCOMPARE(layoutMaximumSize, QSizeF(300.0, 400.0));
p.resize(layoutMinimumSize);
+ if (!hasSimplification)
+ QEXPECT_FAIL("", "Without simplification there is no fair distribution.", Abort);
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 20.0, 100.0));
QCOMPARE(b->geometry(), QRectF(20.0, 100.0, 20.0, 100.0));
QCOMPARE(c->geometry(), QRectF(40.0, 200.0, 20.0, 100.0));
@@ -778,8 +799,10 @@ void tst_QGraphicsAnchorLayout::fairDistribution()
QCOMPARE(d->geometry(), QRectF(0.0, 300.0, 300.0, 100.0));
QCOMPARE(p.size(), layoutMaximumSize);
- QVERIFY(!usedSimplex(l, Qt::Horizontal));
- QVERIFY(!usedSimplex(l, Qt::Vertical));
+ if (hasSimplification) {
+ QVERIFY(!usedSimplex(l, Qt::Horizontal));
+ QVERIFY(!usedSimplex(l, Qt::Vertical));
+ }
}
void tst_QGraphicsAnchorLayout::fairDistributionOppositeDirections()
@@ -836,6 +859,9 @@ void tst_QGraphicsAnchorLayout::fairDistributionOppositeDirections()
QCOMPARE(layoutPreferredSize, QSizeF(220.0, 500.0));
QCOMPARE(layoutMaximumSize, QSizeF(400.0, 500.0));
+ if (!hasSimplification)
+ return;
+
p.resize(layoutMinimumSize);
QCOMPARE(a->size(), b->size());
QCOMPARE(a->size(), c->size());
@@ -922,8 +948,10 @@ void tst_QGraphicsAnchorLayout::proportionalPreferred()
QCOMPARE(c->size().width(), 14 * factor);
QCOMPARE(p.size(), QSizeF(12, 400));
- QVERIFY(!usedSimplex(l, Qt::Horizontal));
- QVERIFY(!usedSimplex(l, Qt::Vertical));
+ if (hasSimplification) {
+ QVERIFY(!usedSimplex(l, Qt::Horizontal));
+ QVERIFY(!usedSimplex(l, Qt::Vertical));
+ }
}
void tst_QGraphicsAnchorLayout::example()
@@ -1008,8 +1036,10 @@ void tst_QGraphicsAnchorLayout::example()
QCOMPARE(b->size(), d->size());
QCOMPARE(f->size(), g->size());
- QVERIFY(usedSimplex(l, Qt::Horizontal));
- QVERIFY(usedSimplex(l, Qt::Vertical));
+ if (hasSimplification) {
+ QVERIFY(usedSimplex(l, Qt::Horizontal));
+ QVERIFY(usedSimplex(l, Qt::Vertical));
+ }
}
void tst_QGraphicsAnchorLayout::setSpacing()
@@ -1331,8 +1361,10 @@ void tst_QGraphicsAnchorLayout::sizePolicy()
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(100, 100));
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(100, 100));
- QVERIFY(!usedSimplex(l, Qt::Horizontal));
- QVERIFY(!usedSimplex(l, Qt::Vertical));
+ if (hasSimplification) {
+ QVERIFY(!usedSimplex(l, Qt::Horizontal));
+ QVERIFY(!usedSimplex(l, Qt::Vertical));
+ }
delete p;
delete view;
@@ -1425,8 +1457,10 @@ void tst_QGraphicsAnchorLayout::expandingSequence()
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
QCOMPARE(layoutMaximumSize.width(), qreal(200));
- QVERIFY(!usedSimplex(l, Qt::Horizontal));
- QVERIFY(!usedSimplex(l, Qt::Vertical));
+ if (hasSimplification) {
+ QVERIFY(!usedSimplex(l, Qt::Horizontal));
+ QVERIFY(!usedSimplex(l, Qt::Vertical));
+ }
}
void tst_QGraphicsAnchorLayout::expandingSequenceFairDistribution()
@@ -1488,8 +1522,10 @@ void tst_QGraphicsAnchorLayout::expandingSequenceFairDistribution()
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
QCOMPARE(layoutMaximumSize.width(), qreal(400));
- QVERIFY(!usedSimplex(l, Qt::Horizontal));
- QVERIFY(!usedSimplex(l, Qt::Vertical));
+ if (hasSimplification) {
+ QVERIFY(!usedSimplex(l, Qt::Horizontal));
+ QVERIFY(!usedSimplex(l, Qt::Vertical));
+ }
// Now we change D to have more "room for growth" from its preferred size
// to its maximum size. We expect a proportional fair distribution. Note that
@@ -1514,8 +1550,10 @@ void tst_QGraphicsAnchorLayout::expandingSequenceFairDistribution()
QCOMPARE(c->geometry().size(), pref);
QCOMPARE(d->geometry().size(), pref + QSizeF(50, 0));
- QVERIFY(!usedSimplex(l, Qt::Horizontal));
- QVERIFY(!usedSimplex(l, Qt::Vertical));
+ if (hasSimplification) {
+ QVERIFY(!usedSimplex(l, Qt::Horizontal));
+ QVERIFY(!usedSimplex(l, Qt::Vertical));
+ }
}
void tst_QGraphicsAnchorLayout::expandingParallel()
@@ -1672,6 +1710,9 @@ void tst_QGraphicsAnchorLayout::infiniteMaxSizes()
QCOMPARE(c->geometry(), QRectF(100, 0, 50, 10));
QCOMPARE(d->geometry(), QRectF(150, 0, 50, 10));
+ if (!hasSimplification)
+ QEXPECT_FAIL("", "Without simplification there is no fair distribution.", Abort);
+
p.resize(1000, 10);
QCOMPARE(a->geometry(), QRectF(0, 0, 450, 10));
QCOMPARE(b->geometry(), QRectF(450, 0, 50, 10));
diff --git a/tests/benchmarks/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/benchmarks/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
index 000ab6ea26..81064d7df6 100644
--- a/tests/benchmarks/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
+++ b/tests/benchmarks/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
@@ -41,6 +41,7 @@
#include <QtTest/QtTest>
#include <QtGui/qgraphicsanchorlayout.h>
+#include <QtGui/qgraphicslinearlayout.h>
#include <QtGui/qgraphicswidget.h>
#include <QtGui/qgraphicsview.h>
@@ -54,6 +55,12 @@ public:
private slots:
void s60_hard_complex_data();
void s60_hard_complex();
+ void linearVsAnchorSizeHints_data();
+ void linearVsAnchorSizeHints();
+ void linearVsAnchorSetGeometry_data();
+ void linearVsAnchorSetGeometry();
+ void linearVsAnchorNested_data();
+ void linearVsAnchorNested();
};
@@ -192,6 +199,235 @@ void tst_QGraphicsAnchorLayout::s60_hard_complex()
}
}
+static QGraphicsLayout* createLayouts(int whichLayout)
+{
+ QSizeF min(0, 10);
+ QSizeF pref(50, 10);
+ QSizeF max(100, 10);
+
+ QGraphicsWidget *a = createItem(min, pref, max, "a");
+ QGraphicsWidget *b = createItem(min, pref, max, "b");
+ QGraphicsWidget *c = createItem(min, pref, max, "c");
+ QGraphicsWidget *d = createItem(min, pref, max, "d");
+
+ QGraphicsLayout *l;
+ if (whichLayout == 0) {
+ l = new QGraphicsLinearLayout;
+ QGraphicsLinearLayout *linear = static_cast<QGraphicsLinearLayout *>(l);
+ linear->setContentsMargins(0, 0, 0, 0);
+
+ linear->addItem(a);
+ linear->addItem(b);
+ linear->addItem(c);
+ linear->addItem(d);
+ } else {
+ l = new QGraphicsAnchorLayout;
+ QGraphicsAnchorLayout *anchor = static_cast<QGraphicsAnchorLayout *>(l);
+ anchor->setContentsMargins(0, 0, 0, 0);
+
+ // Horizontal
+ setAnchor(anchor, anchor, Qt::AnchorLeft, a, Qt::AnchorLeft, 0);
+ setAnchor(anchor, a, Qt::AnchorRight, b, Qt::AnchorLeft, 0);
+ setAnchor(anchor, b, Qt::AnchorRight, c, Qt::AnchorLeft, 0);
+ setAnchor(anchor, c, Qt::AnchorRight, d, Qt::AnchorLeft, 0);
+ setAnchor(anchor, d, Qt::AnchorRight, anchor, Qt::AnchorRight, 0);
+
+ // Vertical
+ anchor->addAnchors(anchor, a, Qt::Vertical);
+ anchor->addAnchors(anchor, b, Qt::Vertical);
+ anchor->addAnchors(anchor, c, Qt::Vertical);
+ anchor->addAnchors(anchor, d, Qt::Vertical);
+ }
+
+ return l;
+}
+
+void tst_QGraphicsAnchorLayout::linearVsAnchorSizeHints_data()
+{
+ QTest::addColumn<int>("whichLayout");
+ QTest::addColumn<int>("whichSizeHint");
+
+ QTest::newRow("QGraphicsLinearLayout::minimum")
+ << 0 << int(Qt::MinimumSize);
+ QTest::newRow("QGraphicsLinearLayout::preferred")
+ << 0 << int(Qt::PreferredSize);
+ QTest::newRow("QGraphicsLinearLayout::maximum")
+ << 0 << int(Qt::MaximumSize);
+ QTest::newRow("QGraphicsLinearLayout::noSizeHint")
+ << 0 << -1;
+
+ QTest::newRow("QGraphicsAnchorLayout::minimum")
+ << 1 << int(Qt::MinimumSize);
+ QTest::newRow("QGraphicsAnchorLayout::preferred")
+ << 1 << int(Qt::PreferredSize);
+ QTest::newRow("QGraphicsAnchorLayout::maximum")
+ << 1 << int(Qt::MaximumSize);
+ QTest::newRow("QGraphicsAnchorLayout::noSizeHint")
+ << 1 << -1;
+}
+
+void tst_QGraphicsAnchorLayout::linearVsAnchorSizeHints()
+{
+ QFETCH(int, whichSizeHint);
+ QFETCH(int, whichLayout);
+
+ QGraphicsLayout *l = createLayouts(whichLayout);
+
+ QSizeF sizeHint;
+ // warm up instruction cache
+ l->invalidate();
+ sizeHint = l->effectiveSizeHint((Qt::SizeHint)whichSizeHint);
+ // ...then measure...
+
+ QBENCHMARK {
+ l->invalidate();
+ sizeHint = l->effectiveSizeHint((Qt::SizeHint)whichSizeHint);
+ }
+}
+
+void tst_QGraphicsAnchorLayout::linearVsAnchorSetGeometry_data()
+{
+ QTest::addColumn<int>("whichLayout");
+
+ QTest::newRow("QGraphicsLinearLayout")
+ << 0;
+ QTest::newRow("QGraphicsAnchorLayout")
+ << 1;
+}
+
+void tst_QGraphicsAnchorLayout::linearVsAnchorSetGeometry()
+{
+ QFETCH(int, whichLayout);
+
+ QGraphicsLayout *l = createLayouts(whichLayout);
+
+ QRectF sizeHint;
+ qreal maxWidth;
+ qreal increment;
+ // warm up instruction cache
+ l->invalidate();
+ sizeHint.setSize(l->effectiveSizeHint(Qt::MinimumSize));
+ maxWidth = l->effectiveSizeHint(Qt::MaximumSize).width();
+ increment = (maxWidth - sizeHint.width()) / 100;
+ l->setGeometry(sizeHint);
+ // ...then measure...
+
+ QBENCHMARK {
+ l->invalidate();
+ for (qreal width = sizeHint.width(); width <= maxWidth; width += increment) {
+ sizeHint.setWidth(width);
+ l->setGeometry(sizeHint);
+ }
+ }
+}
+
+void tst_QGraphicsAnchorLayout::linearVsAnchorNested_data()
+{
+ QTest::addColumn<int>("whichLayout");
+ QTest::newRow("LinearLayout")
+ << 0;
+ QTest::newRow("AnchorLayout setup with null-anchors knot")
+ << 1;
+ QTest::newRow("AnchorLayout setup easy to simplificate")
+ << 2;
+}
+
+void tst_QGraphicsAnchorLayout::linearVsAnchorNested()
+{
+ QFETCH(int, whichLayout);
+
+ QSizeF min(10, 10);
+ QSizeF pref(80, 80);
+ QSizeF max(150, 150);
+
+ QGraphicsWidget *a = createItem(min, pref, max, "a");
+ QGraphicsWidget *b = createItem(min, pref, max, "b");
+ QGraphicsWidget *c = createItem(min, pref, max, "c");
+ QGraphicsWidget *d = createItem(min, pref, max, "d");
+
+ QGraphicsLayout *layout;
+
+ if (whichLayout == 0) {
+ QGraphicsLinearLayout *linear1 = new QGraphicsLinearLayout;
+ QGraphicsLinearLayout *linear2 = new QGraphicsLinearLayout(Qt::Vertical);
+ QGraphicsLinearLayout *linear3 = new QGraphicsLinearLayout;
+
+ linear1->addItem(a);
+ linear1->addItem(linear2);
+ linear2->addItem(b);
+ linear2->addItem(linear3);
+ linear3->addItem(c);
+ linear3->addItem(d);
+
+ layout = linear1;
+ } else if (whichLayout == 1) {
+ QGraphicsAnchorLayout *anchor = new QGraphicsAnchorLayout;
+
+ // A
+ anchor->addCornerAnchors(a, Qt::TopLeftCorner, anchor, Qt::TopLeftCorner);
+ anchor->addCornerAnchors(a, Qt::TopRightCorner, b, Qt::TopLeftCorner);
+ anchor->addCornerAnchors(a, Qt::BottomLeftCorner, anchor, Qt::BottomLeftCorner);
+ anchor->addCornerAnchors(a, Qt::BottomRightCorner, c, Qt::BottomLeftCorner);
+
+ // B
+ anchor->addCornerAnchors(b, Qt::TopRightCorner, anchor, Qt::TopRightCorner);
+ anchor->addCornerAnchors(b, Qt::BottomLeftCorner, c, Qt::TopLeftCorner);
+ anchor->addCornerAnchors(b, Qt::BottomRightCorner, d, Qt::TopRightCorner);
+
+ // C
+ anchor->addCornerAnchors(c, Qt::TopRightCorner, d, Qt::TopLeftCorner);
+ anchor->addCornerAnchors(c, Qt::BottomRightCorner, d, Qt::BottomLeftCorner);
+
+ // D
+ anchor->addCornerAnchors(d, Qt::BottomRightCorner, anchor, Qt::BottomRightCorner);
+
+ layout = anchor;
+ } else {
+ QGraphicsAnchorLayout *anchor = new QGraphicsAnchorLayout;
+
+ // A
+ anchor->addAnchor(a, Qt::AnchorLeft, anchor, Qt::AnchorLeft);
+ anchor->addAnchors(a, anchor, Qt::Vertical);
+ anchor->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
+ anchor->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft);
+
+ // B
+ anchor->addAnchor(b, Qt::AnchorTop, anchor, Qt::AnchorTop);
+ anchor->addAnchor(b, Qt::AnchorRight, anchor, Qt::AnchorRight);
+ anchor->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop);
+ anchor->addAnchor(b, Qt::AnchorBottom, d, Qt::AnchorTop);
+
+ // C
+ anchor->addAnchor(c, Qt::AnchorRight, d, Qt::AnchorLeft);
+ anchor->addAnchor(c, Qt::AnchorBottom, anchor, Qt::AnchorBottom);
+
+ // D
+ anchor->addAnchor(d, Qt::AnchorRight, anchor, Qt::AnchorRight);
+ anchor->addAnchor(d, Qt::AnchorBottom, anchor, Qt::AnchorBottom);
+
+ layout = anchor;
+ }
+
+ QSizeF sizeHint;
+ // warm up instruction cache
+ layout->invalidate();
+ sizeHint = layout->effectiveSizeHint(Qt::PreferredSize);
+
+ // ...then measure...
+ QBENCHMARK {
+ // To ensure that all sizeHints caches are invalidated in
+ // the LinearLayout setup, we must call updateGeometry on the
+ // children. If we didn't, only the top level layout would be
+ // re-calculated.
+ static_cast<QGraphicsLayoutItem *>(a)->updateGeometry();
+ static_cast<QGraphicsLayoutItem *>(b)->updateGeometry();
+ static_cast<QGraphicsLayoutItem *>(c)->updateGeometry();
+ static_cast<QGraphicsLayoutItem *>(d)->updateGeometry();
+ layout->invalidate();
+ sizeHint = layout->effectiveSizeHint(Qt::PreferredSize);
+ }
+}
+
QTEST_MAIN(tst_QGraphicsAnchorLayout)
#include "tst_qgraphicsanchorlayout.moc"