diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-04-22 04:47:24 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-04-22 04:47:24 (GMT) |
commit | 2366667fc97eb6a56203b2dd7dac776ff4164abd (patch) | |
tree | b2acb6cc6bfe475d7e619e4788973b61fff775e0 /tests/auto/declarative/layouts | |
parent | 2c762f3b8b284a7c6dc0c499b7052013bad5b707 (diff) | |
download | Qt-2366667fc97eb6a56203b2dd7dac776ff4164abd.zip Qt-2366667fc97eb6a56203b2dd7dac776ff4164abd.tar.gz Qt-2366667fc97eb6a56203b2dd7dac776ff4164abd.tar.bz2 |
Initial import of kinetic-dui branch from the old kinetic
Diffstat (limited to 'tests/auto/declarative/layouts')
14 files changed, 490 insertions, 0 deletions
diff --git a/tests/auto/declarative/layouts/data/grid-margin.xml b/tests/auto/declarative/layouts/data/grid-margin.xml new file mode 100644 index 0000000..fe58eef --- /dev/null +++ b/tests/auto/declarative/layouts/data/grid-margin.xml @@ -0,0 +1,9 @@ +<Item width="640" height="480"> + <GridLayout columns="3" margin="8"> + <Rect id="one" color="red" width="50" height="50"/> + <Rect id="two" color="green" width="20" height="50"/> + <Rect id="three" color="blue" width="50" height="20"/> + <Rect id="four" color="cyan" width="50" height="50"/> + <Rect id="five" color="magenta" width="10" height="10"/> + </GridLayout> +</Item> diff --git a/tests/auto/declarative/layouts/data/grid-spacing-margin.xml b/tests/auto/declarative/layouts/data/grid-spacing-margin.xml new file mode 100644 index 0000000..807b653 --- /dev/null +++ b/tests/auto/declarative/layouts/data/grid-spacing-margin.xml @@ -0,0 +1,9 @@ +<Item width="640" height="480"> + <GridLayout columns="3" spacing="4" margin="8"> + <Rect id="one" color="red" width="50" height="50"/> + <Rect id="two" color="green" width="20" height="50"/> + <Rect id="three" color="blue" width="50" height="20"/> + <Rect id="four" color="cyan" width="50" height="50"/> + <Rect id="five" color="magenta" width="10" height="10"/> + </GridLayout> +</Item> diff --git a/tests/auto/declarative/layouts/data/grid-spacing.xml b/tests/auto/declarative/layouts/data/grid-spacing.xml new file mode 100644 index 0000000..55ef5a5 --- /dev/null +++ b/tests/auto/declarative/layouts/data/grid-spacing.xml @@ -0,0 +1,9 @@ +<Item width="640" height="480"> + <GridLayout columns="3" spacing="4"> + <Rect id="one" color="red" width="50" height="50"/> + <Rect id="two" color="green" width="20" height="50"/> + <Rect id="three" color="blue" width="50" height="20"/> + <Rect id="four" color="cyan" width="50" height="50"/> + <Rect id="five" color="magenta" width="10" height="10"/> + </GridLayout> +</Item> diff --git a/tests/auto/declarative/layouts/data/grid.xml b/tests/auto/declarative/layouts/data/grid.xml new file mode 100644 index 0000000..abef813 --- /dev/null +++ b/tests/auto/declarative/layouts/data/grid.xml @@ -0,0 +1,9 @@ +<Item width="640" height="480"> + <GridLayout columns="3"> + <Rect id="one" color="red" width="50" height="50"/> + <Rect id="two" color="green" width="20" height="50"/> + <Rect id="three" color="blue" width="50" height="20"/> + <Rect id="four" color="cyan" width="50" height="50"/> + <Rect id="five" color="magenta" width="10" height="10"/> + </GridLayout> +</Item> diff --git a/tests/auto/declarative/layouts/data/horizontal-margin.xml b/tests/auto/declarative/layouts/data/horizontal-margin.xml new file mode 100644 index 0000000..7ee9706 --- /dev/null +++ b/tests/auto/declarative/layouts/data/horizontal-margin.xml @@ -0,0 +1,7 @@ +<Item width="640" height="480"> + <HorizontalLayout margin="10"> + <Rect id="one" color="red" width="50" height="50"/> + <Rect id="two" color="red" width="20" height="10"/> + <Rect id="three" color="red" width="40" height="20"/> + </HorizontalLayout> +</Item> diff --git a/tests/auto/declarative/layouts/data/horizontal-spacing-margin.xml b/tests/auto/declarative/layouts/data/horizontal-spacing-margin.xml new file mode 100644 index 0000000..8767818 --- /dev/null +++ b/tests/auto/declarative/layouts/data/horizontal-spacing-margin.xml @@ -0,0 +1,7 @@ +<Item width="640" height="480"> + <HorizontalLayout spacing="5" margin="10"> + <Rect id="one" color="red" width="50" height="50"/> + <Rect id="two" color="red" width="20" height="10"/> + <Rect id="three" color="red" width="40" height="20"/> + </HorizontalLayout> +</Item> diff --git a/tests/auto/declarative/layouts/data/horizontal-spacing.xml b/tests/auto/declarative/layouts/data/horizontal-spacing.xml new file mode 100644 index 0000000..cb58711 --- /dev/null +++ b/tests/auto/declarative/layouts/data/horizontal-spacing.xml @@ -0,0 +1,7 @@ +<Item width="640" height="480"> + <HorizontalLayout spacing="10"> + <Rect id="one" color="red" width="50" height="50"/> + <Rect id="two" color="red" width="20" height="10"/> + <Rect id="three" color="red" width="40" height="20"/> + </HorizontalLayout> +</Item> diff --git a/tests/auto/declarative/layouts/data/horizontal.xml b/tests/auto/declarative/layouts/data/horizontal.xml new file mode 100644 index 0000000..f9deaf1 --- /dev/null +++ b/tests/auto/declarative/layouts/data/horizontal.xml @@ -0,0 +1,7 @@ +<Item width="640" height="480"> + <HorizontalLayout> + <Rect id="one" color="red" width="50" height="50"/> + <Rect id="two" color="red" width="20" height="10"/> + <Rect id="three" color="red" width="40" height="20"/> + </HorizontalLayout> +</Item> diff --git a/tests/auto/declarative/layouts/data/vertical-margin.xml b/tests/auto/declarative/layouts/data/vertical-margin.xml new file mode 100644 index 0000000..abd7635 --- /dev/null +++ b/tests/auto/declarative/layouts/data/vertical-margin.xml @@ -0,0 +1,7 @@ +<Item width="640" height="480"> + <VerticalLayout margin="10"> + <Rect id="one" color="red" width="50" height="50"/> + <Rect id="two" color="red" width="20" height="10"/> + <Rect id="three" color="red" width="40" height="20"/> + </VerticalLayout> +</Item> diff --git a/tests/auto/declarative/layouts/data/vertical-spacing-margin.xml b/tests/auto/declarative/layouts/data/vertical-spacing-margin.xml new file mode 100644 index 0000000..3d41ca0 --- /dev/null +++ b/tests/auto/declarative/layouts/data/vertical-spacing-margin.xml @@ -0,0 +1,7 @@ +<Item width="640" height="480"> + <VerticalLayout spacing="5" margin="10"> + <Rect id="one" color="red" width="50" height="50"/> + <Rect id="two" color="red" width="20" height="10"/> + <Rect id="three" color="red" width="40" height="20"/> + </VerticalLayout> +</Item> diff --git a/tests/auto/declarative/layouts/data/vertical-spacing.xml b/tests/auto/declarative/layouts/data/vertical-spacing.xml new file mode 100644 index 0000000..e25f981 --- /dev/null +++ b/tests/auto/declarative/layouts/data/vertical-spacing.xml @@ -0,0 +1,7 @@ +<Item width="640" height="480"> + <VerticalLayout spacing="10"> + <Rect id="one" color="red" width="50" height="50"/> + <Rect id="two" color="red" width="20" height="10"/> + <Rect id="three" color="red" width="40" height="20"/> + </VerticalLayout> +</Item> diff --git a/tests/auto/declarative/layouts/data/vertical.xml b/tests/auto/declarative/layouts/data/vertical.xml new file mode 100644 index 0000000..198d99f --- /dev/null +++ b/tests/auto/declarative/layouts/data/vertical.xml @@ -0,0 +1,7 @@ +<Item width="640" height="480"> + <VerticalLayout> + <Rect id="one" color="red" width="50" height="50"/> + <Rect id="two" color="red" width="20" height="10"/> + <Rect id="three" color="red" width="40" height="20"/> + </VerticalLayout> +</Item> diff --git a/tests/auto/declarative/layouts/layouts.pro b/tests/auto/declarative/layouts/layouts.pro new file mode 100644 index 0000000..f7e7622 --- /dev/null +++ b/tests/auto/declarative/layouts/layouts.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_layouts.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp new file mode 100644 index 0000000..ad6a0b2 --- /dev/null +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -0,0 +1,392 @@ +#include <QtTest/QtTest> +#include <qlistmodelinterface.h> +#include <qfxview.h> +#include <qfxrect.h> +#include <qmlexpression.h> + +class tst_QFxLayouts : public QObject +{ + Q_OBJECT +public: + tst_QFxLayouts(); + +private slots: + void test_horizontal(); + void test_horizontal_spacing(); + void test_horizontal_margin(); + void test_horizontal_spacing_margin(); + void test_vertical(); + void test_vertical_spacing(); + void test_vertical_margin(); + void test_vertical_spacing_margin(); + void test_grid(); + void test_grid_spacing(); + void test_grid_margin(); + void test_grid_spacing_margin(); + +private: + QFxView *createView(const QString &filename); + template<typename T> + T *findItem(QFxItem *parent, const QString &id, int index=0); +}; + +tst_QFxLayouts::tst_QFxLayouts() +{ +} + +void tst_QFxLayouts::test_horizontal() +{ + QFxView *canvas = createView(SRCDIR "/data/horizontal.xml"); + + canvas->execute(); + qApp->processEvents(); + + QFxRect *one = findItem<QFxRect>(canvas->root(), "one"); + QVERIFY(one != 0); + + QFxRect *two = findItem<QFxRect>(canvas->root(), "two"); + QVERIFY(two != 0); + + QFxRect *three = findItem<QFxRect>(canvas->root(), "three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); +} + +void tst_QFxLayouts::test_horizontal_spacing() +{ + QFxView *canvas = createView(SRCDIR "/data/horizontal-spacing.xml"); + + canvas->execute(); + qApp->processEvents(); + + QFxRect *one = findItem<QFxRect>(canvas->root(), "one"); + QVERIFY(one != 0); + + QFxRect *two = findItem<QFxRect>(canvas->root(), "two"); + QVERIFY(two != 0); + + QFxRect *three = findItem<QFxRect>(canvas->root(), "three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 60.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 90.0); + QCOMPARE(three->y(), 0.0); +} + +void tst_QFxLayouts::test_horizontal_margin() +{ + QFxView *canvas = createView(SRCDIR "/data/horizontal-margin.xml"); + + canvas->execute(); + qApp->processEvents(); + + QFxRect *one = findItem<QFxRect>(canvas->root(), "one"); + QVERIFY(one != 0); + + QFxRect *two = findItem<QFxRect>(canvas->root(), "two"); + QVERIFY(two != 0); + + QFxRect *three = findItem<QFxRect>(canvas->root(), "three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 10.0); + QCOMPARE(one->y(), 10.0); + QCOMPARE(two->x(), 60.0); + QCOMPARE(two->y(), 10.0); + QCOMPARE(three->x(), 80.0); + QCOMPARE(three->y(), 10.0); +} + +void tst_QFxLayouts::test_horizontal_spacing_margin() +{ + QFxView *canvas = createView(SRCDIR "/data/horizontal-spacing-margin.xml"); + + canvas->execute(); + qApp->processEvents(); + + QFxRect *one = findItem<QFxRect>(canvas->root(), "one"); + QVERIFY(one != 0); + + QFxRect *two = findItem<QFxRect>(canvas->root(), "two"); + QVERIFY(two != 0); + + QFxRect *three = findItem<QFxRect>(canvas->root(), "three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 10.0); + QCOMPARE(one->y(), 10.0); + QCOMPARE(two->x(), 65.0); + QCOMPARE(two->y(), 10.0); + QCOMPARE(three->x(), 90.0); + QCOMPARE(three->y(), 10.0); +} + +void tst_QFxLayouts::test_vertical() +{ + QFxView *canvas = createView(SRCDIR "/data/vertical.xml"); + + canvas->execute(); + qApp->processEvents(); + + QFxRect *one = findItem<QFxRect>(canvas->root(), "one"); + QVERIFY(one != 0); + + QFxRect *two = findItem<QFxRect>(canvas->root(), "two"); + QVERIFY(two != 0); + + QFxRect *three = findItem<QFxRect>(canvas->root(), "three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 60.0); +} + +void tst_QFxLayouts::test_vertical_spacing() +{ + QFxView *canvas = createView(SRCDIR "/data/vertical-spacing.xml"); + + canvas->execute(); + qApp->processEvents(); + + QFxRect *one = findItem<QFxRect>(canvas->root(), "one"); + QVERIFY(one != 0); + + QFxRect *two = findItem<QFxRect>(canvas->root(), "two"); + QVERIFY(two != 0); + + QFxRect *three = findItem<QFxRect>(canvas->root(), "three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 60.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 80.0); +} + +void tst_QFxLayouts::test_vertical_margin() +{ + QFxView *canvas = createView(SRCDIR "/data/vertical-margin.xml"); + + canvas->execute(); + qApp->processEvents(); + + QFxRect *one = findItem<QFxRect>(canvas->root(), "one"); + QVERIFY(one != 0); + + QFxRect *two = findItem<QFxRect>(canvas->root(), "two"); + QVERIFY(two != 0); + + QFxRect *three = findItem<QFxRect>(canvas->root(), "three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 10.0); + QCOMPARE(one->y(), 10.0); + QCOMPARE(two->x(), 10.0); + QCOMPARE(two->y(), 60.0); + QCOMPARE(three->x(), 10.0); + QCOMPARE(three->y(), 70.0); +} + +void tst_QFxLayouts::test_vertical_spacing_margin() +{ + QFxView *canvas = createView(SRCDIR "/data/vertical-spacing-margin.xml"); + + canvas->execute(); + qApp->processEvents(); + + QFxRect *one = findItem<QFxRect>(canvas->root(), "one"); + QVERIFY(one != 0); + + QFxRect *two = findItem<QFxRect>(canvas->root(), "two"); + QVERIFY(two != 0); + + QFxRect *three = findItem<QFxRect>(canvas->root(), "three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 10.0); + QCOMPARE(one->y(), 10.0); + QCOMPARE(two->x(), 10.0); + QCOMPARE(two->y(), 65.0); + QCOMPARE(three->x(), 10.0); + QCOMPARE(three->y(), 80.0); +} + +void tst_QFxLayouts::test_grid() +{ + QFxView *canvas = createView("data/grid.xml"); + + canvas->execute(); + qApp->processEvents(); + + QFxRect *one = findItem<QFxRect>(canvas->root(), "one"); + QVERIFY(one != 0); + QFxRect *two = findItem<QFxRect>(canvas->root(), "two"); + QVERIFY(two != 0); + QFxRect *three = findItem<QFxRect>(canvas->root(), "three"); + QVERIFY(three != 0); + QFxRect *four = findItem<QFxRect>(canvas->root(), "four"); + QVERIFY(four != 0); + QFxRect *five = findItem<QFxRect>(canvas->root(), "five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 50.0); +} + +void tst_QFxLayouts::test_grid_spacing() +{ + QFxView *canvas = createView("data/grid-spacing.xml"); + + canvas->execute(); + qApp->processEvents(); + + QFxRect *one = findItem<QFxRect>(canvas->root(), "one"); + QVERIFY(one != 0); + QFxRect *two = findItem<QFxRect>(canvas->root(), "two"); + QVERIFY(two != 0); + QFxRect *three = findItem<QFxRect>(canvas->root(), "three"); + QVERIFY(three != 0); + QFxRect *four = findItem<QFxRect>(canvas->root(), "four"); + QVERIFY(four != 0); + QFxRect *five = findItem<QFxRect>(canvas->root(), "five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 54.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 78.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 54.0); + QCOMPARE(five->x(), 54.0); + QCOMPARE(five->y(), 54.0); +} + +void tst_QFxLayouts::test_grid_margin() +{ + QFxView *canvas = createView("data/grid-margin.xml"); + + canvas->execute(); + qApp->processEvents(); + + QFxRect *one = findItem<QFxRect>(canvas->root(), "one"); + QVERIFY(one != 0); + QFxRect *two = findItem<QFxRect>(canvas->root(), "two"); + QVERIFY(two != 0); + QFxRect *three = findItem<QFxRect>(canvas->root(), "three"); + QVERIFY(three != 0); + QFxRect *four = findItem<QFxRect>(canvas->root(), "four"); + QVERIFY(four != 0); + QFxRect *five = findItem<QFxRect>(canvas->root(), "five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 8.0); + QCOMPARE(one->y(), 8.0); + QCOMPARE(two->x(), 58.0); + QCOMPARE(two->y(), 8.0); + QCOMPARE(three->x(), 78.0); + QCOMPARE(three->y(), 8.0); + QCOMPARE(four->x(), 8.0); + QCOMPARE(four->y(), 58.0); + QCOMPARE(five->x(), 58.0); + QCOMPARE(five->y(), 58.0); +} + + +void tst_QFxLayouts::test_grid_spacing_margin() +{ + QFxView *canvas = createView("data/grid-spacing-margin.xml"); + + canvas->execute(); + qApp->processEvents(); + + QFxRect *one = findItem<QFxRect>(canvas->root(), "one"); + QVERIFY(one != 0); + QFxRect *two = findItem<QFxRect>(canvas->root(), "two"); + QVERIFY(two != 0); + QFxRect *three = findItem<QFxRect>(canvas->root(), "three"); + QVERIFY(three != 0); + QFxRect *four = findItem<QFxRect>(canvas->root(), "four"); + QVERIFY(four != 0); + QFxRect *five = findItem<QFxRect>(canvas->root(), "five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 8.0); + QCOMPARE(one->y(), 8.0); + QCOMPARE(two->x(), 62.0); + QCOMPARE(two->y(), 8.0); + QCOMPARE(three->x(), 86.0); + QCOMPARE(three->y(), 8.0); + QCOMPARE(four->x(), 8.0); + QCOMPARE(four->y(), 62.0); + QCOMPARE(five->x(), 62.0); + QCOMPARE(five->y(), 62.0); +} + +QFxView *tst_QFxLayouts::createView(const QString &filename) +{ + QFxView *canvas = new QFxView(0); + + QFile file(filename); + file.open(QFile::ReadOnly); + QString xml = file.readAll(); + canvas->setXml(xml, filename); + + return canvas; +} + +/* + Find an item with the specified id. If index is supplied then the + item must also evaluate the {index} expression equal to index +*/ +template<typename T> +T *tst_QFxLayouts::findItem(QFxItem *parent, const QString &id, int index) +{ + const QMetaObject &mo = T::staticMetaObject; + for (int i = 0; i < parent->children()->count(); ++i) { + QFxItem *item = parent->children()->at(i); + if (mo.cast(item) && (id.isEmpty() || item->id() == id)) { + if (index != -1) { + QmlExpression e(item->itemContext(), "index", item); + e.setTrackChange(false); + if (e.value().toInt() == index) + return static_cast<T*>(item); + } else { + return static_cast<T*>(item); + } + } + item = findItem<T>(item, id, index); + if (item) + return static_cast<T*>(item); + } + + return 0; +} + +QTEST_MAIN(tst_QFxLayouts) + +#include "tst_layouts.moc" |