summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2009-11-17 06:02:09 (GMT)
committerBea Lam <bea.lam@nokia.com>2009-11-17 06:02:09 (GMT)
commit400565d14a8c7a6a668a8db75de5ddff2a0061c9 (patch)
tree715a137b5316279f49e5492c9599fe67a026ac55 /tests/auto/declarative
parentf2cb8e0ec8b34044b41e3a2389edbd45f1828b8f (diff)
downloadQt-400565d14a8c7a6a668a8db75de5ddff2a0061c9.zip
Qt-400565d14a8c7a6a668a8db75de5ddff2a0061c9.tar.gz
Qt-400565d14a8c7a6a668a8db75de5ddff2a0061c9.tar.bz2
More tests
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/anchors/tst_anchors.cpp116
1 files changed, 84 insertions, 32 deletions
diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp
index 22f8327..d340a7d 100644
--- a/tests/auto/declarative/anchors/tst_anchors.cpp
+++ b/tests/auto/declarative/anchors/tst_anchors.cpp
@@ -46,6 +46,9 @@
#include <private/qmlgraphicstext_p.h>
#include <QtDeclarative/private/qmlgraphicsanchors_p_p.h>
+Q_DECLARE_METATYPE(QmlGraphicsAnchors::UsedAnchor)
+Q_DECLARE_METATYPE(QmlGraphicsAnchorLine::AnchorLine)
+
class tst_anchors : public QObject
{
@@ -62,7 +65,9 @@ private slots:
void illegalSets();
void illegalSets_data();
void reset();
+ void reset_data();
void nullItem();
+ void nullItem_data();
void crash1();
};
@@ -214,17 +219,19 @@ void tst_anchors::illegalSets_data()
<< "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.";
- 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.";
+ foreach (const QString &side, QStringList() << "left" << "right") {
+ QTest::newRow("H - anchor to V")
+ << QString("Rectangle { Rectangle { anchors.%1: parent.top } }").arg(side)
+ << "QML QmlGraphicsRectangle (file::2:13) Can't anchor a horizontal edge to a vertical edge.";
- 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.";
+ QTest::newRow("H - anchor to non parent/sibling")
+ << QString("Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.%1: rect.%1 } }").arg(side)
+ << "QML QmlGraphicsRectangle (file::2:45) Can't anchor to an item that isn't a parent or sibling.";
- QTest::newRow("H - anchor to self")
- << "Rectangle { id: rect; anchors.left: rect.left }"
- << "QML QmlGraphicsRectangle (file::2:1) Can't anchor item to self.";
+ QTest::newRow("H - anchor to self")
+ << QString("Rectangle { id: rect; anchors.%1: rect.%1 }").arg(side)
+ << "QML QmlGraphicsRectangle (file::2:1) Can't anchor item to self.";
+ }
QTest::newRow("V - too many anchors")
@@ -235,17 +242,20 @@ void tst_anchors::illegalSets_data()
<< "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.";
- 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.";
+ foreach (const QString &side, QStringList() << "top" << "bottom" << "baseline") {
- 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.";
+ QTest::newRow("V - anchor to H")
+ << QString("Rectangle { Rectangle { anchors.%1: parent.left } }").arg(side)
+ << "QML QmlGraphicsRectangle (file::2:13) Can't anchor a vertical edge to a horizontal edge.";
- 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("V - anchor to non parent/sibling")
+ << QString("Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.%1: rect.%1 } }").arg(side)
+ << "QML QmlGraphicsRectangle (file::2:45) Can't anchor to an item that isn't a parent or sibling.";
+
+ QTest::newRow("V - anchor to self")
+ << QString("Rectangle { id: rect; anchors.%1: rect.%1 }").arg(side)
+ << "QML QmlGraphicsRectangle (file::2:1) Can't anchor item to self.";
+ }
QTest::newRow("centerIn - anchor to non parent/sibling")
@@ -260,35 +270,77 @@ void tst_anchors::illegalSets_data()
void tst_anchors::reset()
{
- QmlGraphicsItem *aItem = new QmlGraphicsItem;
+ QFETCH(QString, side);
+ QFETCH(QmlGraphicsAnchorLine::AnchorLine, anchorLine);
+ QFETCH(QmlGraphicsAnchors::UsedAnchor, usedAnchor);
+
+ QmlGraphicsItem *baseItem = new QmlGraphicsItem;
+
QmlGraphicsAnchorLine anchor;
- anchor.item = aItem;
- anchor.anchorLine = QmlGraphicsAnchorLine::Top;
+ anchor.item = baseItem;
+ anchor.anchorLine = anchorLine;
QmlGraphicsItem *item = new QmlGraphicsItem;
- item->anchors()->setBottom(anchor);
- QCOMPARE(item->anchors()->usedAnchors().testFlag(QmlGraphicsAnchors::HasBottomAnchor), true);
- item->anchors()->resetBottom();
- QCOMPARE(item->anchors()->usedAnchors().testFlag(QmlGraphicsAnchors::HasBottomAnchor), false);
+ const QMetaObject *meta = item->anchors()->metaObject();
+ QMetaProperty p = meta->property(meta->indexOfProperty(side.toUtf8().constData()));
+
+ QVERIFY(p.write(item->anchors(), qVariantFromValue(anchor)));
+ QCOMPARE(item->anchors()->usedAnchors().testFlag(usedAnchor), true);
+
+ QVERIFY(p.reset(item->anchors()));
+ QCOMPARE(item->anchors()->usedAnchors().testFlag(usedAnchor), false);
+
+ delete item;
+ delete baseItem;
+}
+
+void tst_anchors::reset_data()
+{
+ QTest::addColumn<QString>("side");
+ QTest::addColumn<QmlGraphicsAnchorLine::AnchorLine>("anchorLine");
+ QTest::addColumn<QmlGraphicsAnchors::UsedAnchor>("usedAnchor");
+
+ QTest::newRow("left") << "left" << QmlGraphicsAnchorLine::Left << QmlGraphicsAnchors::HasLeftAnchor;
+ QTest::newRow("top") << "top" << QmlGraphicsAnchorLine::Top << QmlGraphicsAnchors::HasTopAnchor;
+ QTest::newRow("right") << "right" << QmlGraphicsAnchorLine::Right << QmlGraphicsAnchors::HasRightAnchor;
+ QTest::newRow("bottom") << "bottom" << QmlGraphicsAnchorLine::Bottom << QmlGraphicsAnchors::HasBottomAnchor;
+
+ QTest::newRow("hcenter") << "horizontalCenter" << QmlGraphicsAnchorLine::HCenter << QmlGraphicsAnchors::HasHCenterAnchor;
+ QTest::newRow("vcenter") << "verticalCenter" << QmlGraphicsAnchorLine::VCenter << QmlGraphicsAnchors::HasVCenterAnchor;
+ QTest::newRow("baseline") << "baseline" << QmlGraphicsAnchorLine::Baseline << QmlGraphicsAnchors::HasBaselineAnchor;
}
void tst_anchors::nullItem()
{
+ QFETCH(QString, side);
+
QmlGraphicsAnchorLine anchor;
- QmlGraphicsItem *item;
+ QmlGraphicsItem *item = new QmlGraphicsItem;
- QTest::ignoreMessage(QtWarningMsg, "QML QmlGraphicsItem (unknown location) Can't anchor to a null item.");
- item = new QmlGraphicsItem;
- item->anchors()->setLeft(anchor);
- delete item;
+ const QMetaObject *meta = item->anchors()->metaObject();
+ QMetaProperty p = meta->property(meta->indexOfProperty(side.toUtf8().constData()));
QTest::ignoreMessage(QtWarningMsg, "QML QmlGraphicsItem (unknown location) Can't anchor to a null item.");
- item = new QmlGraphicsItem;
- item->anchors()->setBottom(anchor);
+ QVERIFY(p.write(item->anchors(), qVariantFromValue(anchor)));
+
delete item;
}
+void tst_anchors::nullItem_data()
+{
+ QTest::addColumn<QString>("side");
+
+ QTest::newRow("left") << "left";
+ QTest::newRow("top") << "top";
+ QTest::newRow("right") << "right";
+ QTest::newRow("bottom") << "bottom";
+
+ QTest::newRow("hcenter") << "horizontalCenter";
+ QTest::newRow("vcenter") << "verticalCenter";
+ QTest::newRow("baseline") << "baseline";
+}
+
void tst_anchors::crash1()
{
QmlView *view = new QmlView;