summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-05-18 03:10:33 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-05-18 03:10:33 (GMT)
commit300a259e13906e8dde204e3f33dab88ea80f8302 (patch)
tree5e77c5fd49e0ced7476c60ef3b5127342a48b64b /tests/auto
parente6dcb15ca670ac9a01ac7c4c96a7de2959f98498 (diff)
downloadQt-300a259e13906e8dde204e3f33dab88ea80f8302.zip
Qt-300a259e13906e8dde204e3f33dab88ea80f8302.tar.gz
Qt-300a259e13906e8dde204e3f33dab88ea80f8302.tar.bz2
Test Qt.labs.folderlistmodel plugin
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qdeclarativefolderlistmodel/data/basic.qml5
-rw-r--r--tests/auto/declarative/qdeclarativefolderlistmodel/data/dummy.qml1
-rw-r--r--tests/auto/declarative/qdeclarativefolderlistmodel/qdeclarativefolderlistmodel.pro17
-rw-r--r--tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp113
4 files changed, 136 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativefolderlistmodel/data/basic.qml b/tests/auto/declarative/qdeclarativefolderlistmodel/data/basic.qml
new file mode 100644
index 0000000..2c4977d
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativefolderlistmodel/data/basic.qml
@@ -0,0 +1,5 @@
+import Qt.labs.folderlistmodel 1.0
+
+FolderListModel {
+ nameFilters: [ "*.qml" ]
+}
diff --git a/tests/auto/declarative/qdeclarativefolderlistmodel/data/dummy.qml b/tests/auto/declarative/qdeclarativefolderlistmodel/data/dummy.qml
new file mode 100644
index 0000000..609638b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativefolderlistmodel/data/dummy.qml
@@ -0,0 +1 @@
+// This file is not used, it is just content for QDirModel
diff --git a/tests/auto/declarative/qdeclarativefolderlistmodel/qdeclarativefolderlistmodel.pro b/tests/auto/declarative/qdeclarativefolderlistmodel/qdeclarativefolderlistmodel.pro
new file mode 100644
index 0000000..487d0e1
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativefolderlistmodel/qdeclarativefolderlistmodel.pro
@@ -0,0 +1,17 @@
+load(qttest_p4)
+contains(QT_CONFIG,declarative): QT += declarative
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qdeclarativefolderlistmodel.cpp
+
+# Define SRCDIR equal to test's source directory
+symbian: {
+ DEFINES += SRCDIR=\".\"
+ importFiles.sources = data
+ importFiles.path =
+ DEPLOYMENT = importFiles
+} else {
+ DEFINES += SRCDIR=\\\"$$PWD\\\"
+}
+
+CONFIG += parallel_test
diff --git a/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp b/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp
new file mode 100644
index 0000000..8a8bfe7
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qtest.h>
+#include <QtTest/QSignalSpy>
+#include "../../../shared/util.h"
+#include <QtDeclarative/qdeclarativeengine.h>
+#include <QtDeclarative/qdeclarativecomponent.h>
+#include <QtCore/qdir.h>
+#include <QtCore/qfile.h>
+#include <QtCore/qabstractitemmodel.h>
+#include <QDebug>
+
+// From qdeclarastivefolderlistmodel.h
+const int FileNameRole = Qt::UserRole+1;
+const int FilePathRole = Qt::UserRole+2;
+enum SortField { Unsorted, Name, Time, Size, Type };
+
+class tst_qdeclarativefolderlistmodel : public QObject
+{
+ Q_OBJECT
+public:
+ tst_qdeclarativefolderlistmodel() {}
+
+private slots:
+ void basicProperties();
+
+private:
+ void checkNoErrors(const QDeclarativeComponent& component);
+ QDeclarativeEngine engine;
+};
+
+void tst_qdeclarativefolderlistmodel::checkNoErrors(const QDeclarativeComponent& component)
+{
+ // Wait until the component is ready
+ QTRY_VERIFY(component.isReady() || component.isError());
+
+ if (component.isError()) {
+ QList<QDeclarativeError> errors = component.errors();
+ for (int ii = 0; ii < errors.count(); ++ii) {
+ const QDeclarativeError &error = errors.at(ii);
+ QByteArray errorStr = QByteArray::number(error.line()) + ":" +
+ QByteArray::number(error.column()) + ":" +
+ error.description().toUtf8();
+ qWarning() << errorStr;
+ }
+ }
+ QVERIFY(!component.isError());
+}
+
+void tst_qdeclarativefolderlistmodel::basicProperties()
+{
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/basic.qml"));
+ checkNoErrors(component);
+
+ QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create());
+ QVERIFY(flm != 0);
+
+
+ flm->setProperty("folder",QUrl::fromLocalFile(SRCDIR "/data"));
+ QTRY_COMPARE(flm->property("count").toInt(),2); // wait for refresh
+ QCOMPARE(flm->property("folder").toUrl(), QUrl::fromLocalFile(SRCDIR "/data"));
+ QCOMPARE(flm->property("parentFolder").toUrl(), QUrl::fromLocalFile(SRCDIR));
+ QCOMPARE(flm->property("sortField").toInt(), int(Name));
+ QCOMPARE(flm->property("nameFilters").toStringList(), QStringList() << "*.qml");
+ QCOMPARE(flm->property("sortReversed").toBool(), false);
+ QCOMPARE(flm->property("showDirs").toBool(), true);
+ QCOMPARE(flm->property("showDotAndDotDot").toBool(), false);
+ QCOMPARE(flm->property("showOnlyReadable").toBool(), false);
+ QCOMPARE(flm->data(flm->index(0),FileNameRole).toString(), QLatin1String("basic.qml"));
+ QCOMPARE(flm->data(flm->index(1),FileNameRole).toString(), QLatin1String("dummy.qml"));
+}
+
+QTEST_MAIN(tst_qdeclarativefolderlistmodel)
+
+#include "tst_qdeclarativefolderlistmodel.moc"