diff options
author | Cidorvan Leite <cidorvan.leite@openbossa.org> | 2012-05-23 17:44:51 -0300 |
---|---|---|
committer | Luis Gabriel Lima <luis.gabriel@openbossa.org> | 2012-05-25 15:57:52 +0200 |
commit | 53dc07670b2d302f876c0f2928b9d776347a280c (patch) | |
tree | 265ed4e595d23f0cf86fbbda4ba885897a3acbd9 | |
parent | dde17d96fe30256e9332745a428d5f4f22fc5d72 (diff) |
Added UiProxyQmlModel tests
Change-Id: Ia9bef443b37f0c942447002bde7f31791718d2d8
Reviewed-by: Murilo Belluzzo <murilo.belluzzo@openbossa.org>
Reviewed-by: Luis Gabriel Lima <luis.gabriel@openbossa.org>
-rw-r--r-- | tests/auto/models/models.pro | 3 | ||||
-rw-r--r-- | tests/auto/models/uiproxyqmlmodel/models.qml | 11 | ||||
-rw-r--r-- | tests/auto/models/uiproxyqmlmodel/tst_uiproxyqmlmodel.cpp | 139 | ||||
-rw-r--r-- | tests/auto/models/uiproxyqmlmodel/uiproxyqmlmodel.pro | 6 |
4 files changed, 158 insertions, 1 deletions
diff --git a/tests/auto/models/models.pro b/tests/auto/models/models.pro index 05cc8ff..7fbebe0 100644 --- a/tests/auto/models/models.pro +++ b/tests/auto/models/models.pro @@ -2,4 +2,5 @@ TEMPLATE=subdirs SUBDIRS=\ qfilesystemmodel \ qstandarditemmodel \ - uitextfilemodel + uitextfilemodel \ + uiproxyqmlmodel diff --git a/tests/auto/models/uiproxyqmlmodel/models.qml b/tests/auto/models/uiproxyqmlmodel/models.qml new file mode 100644 index 0000000..12d55b0 --- /dev/null +++ b/tests/auto/models/uiproxyqmlmodel/models.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 + +Item { + property variant arrayList: ["Brazil", "Monaco", 1234, true] + property variant quickList: ListModel { + ListElement { name: "John"; age: 20 } + ListElement { name: "Paul"; age: 32 } + ListElement { name: "Peter"; age: 14 } + } + property variant invalidList: "Hello world!" +} diff --git a/tests/auto/models/uiproxyqmlmodel/tst_uiproxyqmlmodel.cpp b/tests/auto/models/uiproxyqmlmodel/tst_uiproxyqmlmodel.cpp new file mode 100644 index 0000000..d70f49d --- /dev/null +++ b/tests/auto/models/uiproxyqmlmodel/tst_uiproxyqmlmodel.cpp @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT) +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QtQml/QQmlEngine> +#include <QtQml/QQmlContext> +#include <QtQml/QQmlComponent> +#include <UiHelpers/UiProxyQmlModel> + +QT_USE_NAMESPACE_UIHELPERS + +class tst_UiProxyQmlModel: public QObject +{ + Q_OBJECT + +public slots: + void init(); + void cleanup(); + +private: + QObject *object; + UiProxyQmlModel arrayList; + UiProxyQmlModel quickList; + UiProxyQmlModel invalidList; + +private slots: + void type(); + void count(); + void roles(); + void data(); +}; + +void tst_UiProxyQmlModel::init() +{ + QQmlEngine *engine = new QQmlEngine; + QQmlContext *context = engine->rootContext(); + QQmlComponent *component = new QQmlComponent(engine); + + QFile file("models.qml"); + file.open(QIODevice::ReadOnly); + component->setData(file.readAll(), QUrl()); + object = component->create(context); + file.close(); +} + +void tst_UiProxyQmlModel::cleanup() +{ + delete object; +} + +void tst_UiProxyQmlModel::type() +{ + QCOMPARE(arrayList.updateSource(object->property("arrayList")), UiProxyQmlModel::ArrayList); + QCOMPARE(quickList.updateSource(object->property("quickList")), UiProxyQmlModel::QuickList); + QCOMPARE(invalidList.updateSource(object->property("invalidList")), UiProxyQmlModel::InvalidList); +} + +void tst_UiProxyQmlModel::count() +{ + QCOMPARE(arrayList.rowCount(), 4); + QCOMPARE(quickList.rowCount(), 3); + QCOMPARE(invalidList.rowCount(), 0); +} + +void tst_UiProxyQmlModel::roles() +{ + const QHash<int, QByteArray> &arrayListRoles = arrayList.roleNames(); + QCOMPARE(arrayListRoles.size(), 1); + QCOMPARE(arrayListRoles[Qt::DisplayRole], QByteArray("display")); + + const QHash<int, QByteArray> &quickListRoles = quickList.roleNames(); + QCOMPARE(quickListRoles.size(), 2); + QVERIFY(quickListRoles.key("name", -1) != -1); + QVERIFY(quickListRoles.key("age", -1) != -1); +} + +void tst_UiProxyQmlModel::data() +{ + QModelIndex index = arrayList.index(0, 0); + QCOMPARE(arrayList.data(index, Qt::DisplayRole), QVariant(QString("Brazil"))); + index = arrayList.index(1, 0); + QCOMPARE(arrayList.data(index, Qt::DisplayRole), QVariant(QString("Monaco"))); + index = arrayList.index(2, 0); + QCOMPARE(arrayList.data(index, Qt::DisplayRole), QVariant(1234)); + index = arrayList.index(3, 0); + QCOMPARE(arrayList.data(index, Qt::DisplayRole), QVariant(true)); + + const QHash<int, QByteArray> &roles = quickList.roleNames(); + index = quickList.index(0, 0); + QCOMPARE(quickList.data(index, roles.key("name")), QVariant(QString("John"))); + QCOMPARE(quickList.data(index, roles.key("age")), QVariant(20)); + index = quickList.index(1, 0); + QCOMPARE(quickList.data(index, roles.key("name")), QVariant(QString("Paul"))); + QCOMPARE(quickList.data(index, roles.key("age")), QVariant(32)); + index = quickList.index(2, 0); + QCOMPARE(quickList.data(index, roles.key("name")), QVariant(QString("Peter"))); + QCOMPARE(quickList.data(index, roles.key("age")), QVariant(14)); +} + +QTEST_MAIN(tst_UiProxyQmlModel) +#include "tst_uiproxyqmlmodel.moc" diff --git a/tests/auto/models/uiproxyqmlmodel/uiproxyqmlmodel.pro b/tests/auto/models/uiproxyqmlmodel/uiproxyqmlmodel.pro new file mode 100644 index 0000000..b8ee7d6 --- /dev/null +++ b/tests/auto/models/uiproxyqmlmodel/uiproxyqmlmodel.pro @@ -0,0 +1,6 @@ +CONFIG += testcase +TARGET = tst_uiproxyqmlmodel + +QT += testlib uihelpers core-private qml + +SOURCES += tst_uiproxyqmlmodel.cpp |