summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qfileselector
diff options
context:
space:
mode:
authorAlan Alpert <aalpert@rim.com>2013-02-18 20:06:09 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-16 19:42:22 +0200
commitb674b15dfffa25164379b0b632e3350b9da53895 (patch)
tree463eaa551c872fa6950ca688effa2be77680a875 /tests/auto/corelib/io/qfileselector
parent4b02585f302ee6cad2041d5bee6cbf46d02e21db (diff)
Add QFileSelector API
For easy cross-platform and cross-device UIs, automatic asset swapping based on filename is being developed. This API provides the logic for the swapping, so that applications can use it themselves with the same logic as any automatic swapping done in application templates. Selector set is initially minimal, aiming for just platform selection and enabling a common selection mechanism for Qt platforms to use. Change-Id: I219517d740fa7385e923a9e09cb7e241378f857a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/io/qfileselector')
-rw-r--r--tests/auto/corelib/io/qfileselector/extras/+custom1/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/extras/+custom1/test30
-rw-r--r--tests/auto/corelib/io/qfileselector/extras/+custom2/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/extras/+custom3/+custom2/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/extras/+custom3/+custom4/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/extras/+custom3/+custom5/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/extras/+custom3/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/extras/+custom5/+custom3/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/extras/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/extras/test20
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+android/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+blackberry/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+generic_unix/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+ios/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+linux/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+mac/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+wince/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+windows/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/qfileselector.pro6
-rw-r--r--tests/auto/corelib/io/qfileselector/qfileselector.qrc23
-rw-r--r--tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp199
22 files changed, 228 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qfileselector/extras/+custom1/test b/tests/auto/corelib/io/qfileselector/extras/+custom1/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/extras/+custom1/test
diff --git a/tests/auto/corelib/io/qfileselector/extras/+custom1/test3 b/tests/auto/corelib/io/qfileselector/extras/+custom1/test3
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/extras/+custom1/test3
diff --git a/tests/auto/corelib/io/qfileselector/extras/+custom2/test b/tests/auto/corelib/io/qfileselector/extras/+custom2/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/extras/+custom2/test
diff --git a/tests/auto/corelib/io/qfileselector/extras/+custom3/+custom2/test b/tests/auto/corelib/io/qfileselector/extras/+custom3/+custom2/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/extras/+custom3/+custom2/test
diff --git a/tests/auto/corelib/io/qfileselector/extras/+custom3/+custom4/test b/tests/auto/corelib/io/qfileselector/extras/+custom3/+custom4/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/extras/+custom3/+custom4/test
diff --git a/tests/auto/corelib/io/qfileselector/extras/+custom3/+custom5/test b/tests/auto/corelib/io/qfileselector/extras/+custom3/+custom5/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/extras/+custom3/+custom5/test
diff --git a/tests/auto/corelib/io/qfileselector/extras/+custom3/test b/tests/auto/corelib/io/qfileselector/extras/+custom3/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/extras/+custom3/test
diff --git a/tests/auto/corelib/io/qfileselector/extras/+custom5/+custom3/test b/tests/auto/corelib/io/qfileselector/extras/+custom5/+custom3/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/extras/+custom5/+custom3/test
diff --git a/tests/auto/corelib/io/qfileselector/extras/test b/tests/auto/corelib/io/qfileselector/extras/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/extras/test
diff --git a/tests/auto/corelib/io/qfileselector/extras/test2 b/tests/auto/corelib/io/qfileselector/extras/test2
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/extras/test2
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+android/test b/tests/auto/corelib/io/qfileselector/platforms/+android/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+android/test
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+blackberry/test b/tests/auto/corelib/io/qfileselector/platforms/+blackberry/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+blackberry/test
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+generic_unix/test b/tests/auto/corelib/io/qfileselector/platforms/+generic_unix/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+generic_unix/test
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+ios/test b/tests/auto/corelib/io/qfileselector/platforms/+ios/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+ios/test
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+linux/test b/tests/auto/corelib/io/qfileselector/platforms/+linux/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+linux/test
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+mac/test b/tests/auto/corelib/io/qfileselector/platforms/+mac/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+mac/test
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+wince/test b/tests/auto/corelib/io/qfileselector/platforms/+wince/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+wince/test
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+windows/test b/tests/auto/corelib/io/qfileselector/platforms/+windows/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+windows/test
diff --git a/tests/auto/corelib/io/qfileselector/platforms/test b/tests/auto/corelib/io/qfileselector/platforms/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/test
diff --git a/tests/auto/corelib/io/qfileselector/qfileselector.pro b/tests/auto/corelib/io/qfileselector/qfileselector.pro
new file mode 100644
index 0000000000..ded3d6502e
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/qfileselector.pro
@@ -0,0 +1,6 @@
+CONFIG += parallel_test
+CONFIG += testcase
+TARGET = tst_qfileselectors
+QT = core-private testlib
+SOURCES = tst_qfileselector.cpp
+RESOURCES = qfileselector.qrc
diff --git a/tests/auto/corelib/io/qfileselector/qfileselector.qrc b/tests/auto/corelib/io/qfileselector/qfileselector.qrc
new file mode 100644
index 0000000000..cc8affafca
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/qfileselector.qrc
@@ -0,0 +1,23 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>extras/test</file>
+ <file>extras/test2</file>
+ <file>extras/+custom1/test</file>
+ <file>extras/+custom1/test3</file>
+ <file>extras/+custom2/test</file>
+ <file>extras/+custom3/test</file>
+ <file>extras/+custom3/+custom2/test</file>
+ <file>extras/+custom3/+custom4/test</file>
+ <file>extras/+custom3/+custom5/test</file>
+ <file>extras/+custom5/+custom3/test</file>
+ <file>platforms/test</file>
+ <file>platforms/+android/test</file>
+ <file>platforms/+blackberry/test</file>
+ <file>platforms/+ios/test</file>
+ <file>platforms/+mac/test</file>
+ <file>platforms/+wince/test</file>
+ <file>platforms/+windows/test</file>
+ <file>platforms/+linux/test</file>
+ <file>platforms/+generic_unix/test</file>
+</qresource>
+</RCC>
diff --git a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp
new file mode 100644
index 0000000000..2baebd0296
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp
@@ -0,0 +1,199 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <qplatformdefs.h>
+
+#include <QCoreApplication>
+#include <QDebug>
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+#include <QString>
+
+#include <private/qfileselector_p.h>
+#include <private/qabstractfileengine_p.h>
+#include <private/qfsfileengine_p.h>
+#include <private/qfilesystemengine_p.h>
+
+const ushort selectorIndicator = '+';
+
+class tst_QFileSelector : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QFileSelector() {}
+
+private slots:
+ void basicTest_data();
+ void basicTest();
+
+ void urlConvenience_data();
+ void urlConvenience();
+};
+
+void tst_QFileSelector::basicTest_data()
+{
+ /* Files existing for this test
+ * platform/test
+ * platform/+<platform>/test for all <platform> in QFileSelectorPrivate::platformSelectors()
+ * extras/test
+ * extras/test2 to test for when selector directories exist, but don't have the files
+ * extras/+custom1/test
+ * extras/+custom1/test3 to test for when base file doesn't exist
+ * extras/+custom2/test
+ * extras/+custom3/test
+ * extras/+custom3/+custom2/test
+ * extras/+custom3/+custom4/test
+ * extras/+custom3/+custom5/test
+ * extras/+custom5/+custom3/test
+ */
+ QTest::addColumn<QString>("testPath");
+ QTest::addColumn<QStringList>("customSelectors");
+ QTest::addColumn<QString>("expectedPath");
+
+ QString test("/test");// '/' is here so dir string can also be selector string
+ QTest::newRow("platform") << QString(":/platforms/test") << QStringList()
+ << QString(":/platforms/") + QLatin1Char(selectorIndicator)
+ + QFileSelectorPrivate::platformSelectors().first() + test;
+
+ QString resourceTestPath(":/extras/test");
+ QString custom1("custom1");
+ QTest::newRow("custom1-noselector") << resourceTestPath << QStringList()
+ << QString(":/extras") + test;
+
+ QTest::newRow("custom1-withselector") << resourceTestPath << (QStringList() << custom1)
+ << QString(":/extras/") + QLatin1Char(selectorIndicator) + custom1 + test;
+
+ QTest::newRow("customX-withselector-nofile") << QString(":/extras/test2") << (QStringList() << custom1)
+ << QString(":/extras/test2");
+
+ QTest::newRow("custom1-withselector-nobasefile") << QString(":/extras/test3") << (QStringList() << custom1)
+ << QString(":/extras/test3");
+
+ QString custom2("custom2");
+ QString custom3("custom3");
+ QString custom4("custom4");
+ QString custom5("custom5");
+ QString slash("/");
+ QTest::newRow("custom12") << resourceTestPath << (QStringList() << custom1 << custom2)
+ << QString(":/extras/") + QLatin1Char(selectorIndicator) + custom1 + test;
+
+ QTest::newRow("custom21") << resourceTestPath << (QStringList() << custom2 << custom1)
+ << QString(":/extras/") + QLatin1Char(selectorIndicator) + custom2 + test;
+
+ QTest::newRow("custom213") << resourceTestPath << (QStringList() << custom2 << custom1 << custom3)
+ << QString(":/extras/") + QLatin1Char(selectorIndicator) + custom2 + test;
+
+ QTest::newRow("custom23") << resourceTestPath << (QStringList() << custom2 << custom3)
+ << QString(":/extras/") + QLatin1Char(selectorIndicator) + custom2 + test;
+
+ QTest::newRow("custom34nested") << resourceTestPath << (QStringList() << custom3 << custom4)
+ << QString(":/extras/") + QLatin1Char(selectorIndicator) + custom3 + slash
+ + QLatin1Char(selectorIndicator) + custom4 + test;
+
+ QTest::newRow("custom43nested") << resourceTestPath << (QStringList() << custom4 << custom3)
+ << QString(":/extras/") + QLatin1Char(selectorIndicator) + custom3 + slash
+ + QLatin1Char(selectorIndicator) + custom4 + test;
+
+ QTest::newRow("custom35conflict") << resourceTestPath << (QStringList() << custom3 << custom5)
+ << QString(":/extras/") + QLatin1Char(selectorIndicator) + custom3 + slash
+ + QLatin1Char(selectorIndicator) + custom5 + test;
+
+ QTest::newRow("relativePaths") << QFINDTESTDATA("extras/test") << (QStringList() << custom1)
+ << QFINDTESTDATA(QString("extras/") + QLatin1Char(selectorIndicator) + custom1
+ + QString("/test"));
+}
+
+void tst_QFileSelector::basicTest()
+{
+ QFETCH(QString, testPath);
+ QFETCH(QStringList, customSelectors);
+ QFETCH(QString, expectedPath);
+
+ QFileSelector fs;
+ fs.setExtraSelectors(customSelectors);
+ QCOMPARE(fs.select(testPath), expectedPath);
+}
+
+void tst_QFileSelector::urlConvenience_data()
+{
+ /* Files existing for this test
+ * extras/test
+ * extras/+custom1/test
+ */
+ QTest::addColumn<QUrl>("testUrl");
+ QTest::addColumn<QStringList>("customSelectors");
+ QTest::addColumn<QUrl>("expectedUrl");
+
+ QString test("/test");// '/' is here so dir string can also be selector string
+ QString custom1("custom1");
+
+ QTest::newRow("qrc") << QUrl("qrc:///extras/test") << (QStringList() << custom1)
+ << QUrl(QString("qrc:///extras/") + QLatin1Char(selectorIndicator) + custom1 + test);
+
+ QString fileBasePath = QFINDTESTDATA("extras/test");
+ QString fileSelectedPath = QFINDTESTDATA(QString("extras/") + QLatin1Char(selectorIndicator)
+ + custom1 + QString("/test"));
+ QTest::newRow("file") << QUrl::fromLocalFile(fileBasePath) << (QStringList() << custom1)
+ << QUrl::fromLocalFile(fileSelectedPath);
+
+ // http://qt-project.org/images/qtdn/sprites-combined-latest.png is chosen as a representative real world URL
+ // But note that this test is checking that http urls are NOT selected so it shouldn't be checked
+ QUrl testHttpUrl("http://qt-project.org/images/sprites-combined-latest.png");
+ QTest::newRow("http") << testHttpUrl << (QStringList() << QString("qtdn")) << testHttpUrl;
+}
+
+void tst_QFileSelector::urlConvenience()
+{
+ QFETCH(QUrl, testUrl);
+ QFETCH(QStringList, customSelectors);
+ QFETCH(QUrl, expectedUrl);
+
+ QFileSelector fs;
+ //All rows of this test use only custom selectors, so should not select before the setExtra call
+ QCOMPARE(fs.select(testUrl), testUrl);
+ fs.setExtraSelectors(customSelectors);
+ QCOMPARE(fs.select(testUrl), expectedUrl);
+}
+
+QTEST_MAIN(tst_QFileSelector)
+#include "tst_qfileselector.moc"