summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2015-01-23 15:32:05 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2015-01-28 12:20:54 +0000
commitce9c4915d53c9dabfa3b5a28e62ecd2bb49337d4 (patch)
treee2f0b3b6eb3c815788abc6e41481d6eb812ead94 /tests
parentb65a415e674df75821600c8ac0bcdfdfc0703a2b (diff)
Android: Don't open assets files in read/write mode
We would return true when opening assets in read/write mode despite the fact that the files are not writable. The logic now matches that of the qrc file engine. This also adds a unit test for Android-specific issues. [ChangeLog][Android][Important Behavior Changes] Opening assets with QIODevice::ReadWrite now returns false to correctly indicate that the files are not writable. Change-Id: I019cc27861fc9b000dc13c5e0a38c0fc09a08671 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com> Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com> Reviewed-by: BogDan Vatra <bogdan@kde.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/other/android/android.pro11
-rw-r--r--tests/auto/other/android/testdata/assets/test.txt1
-rw-r--r--tests/auto/other/android/tst_android.cpp69
-rw-r--r--tests/auto/other/other.pro3
4 files changed, 84 insertions, 0 deletions
diff --git a/tests/auto/other/android/android.pro b/tests/auto/other/android/android.pro
new file mode 100644
index 0000000000..60faf8050e
--- /dev/null
+++ b/tests/auto/other/android/android.pro
@@ -0,0 +1,11 @@
+CONFIG += testcase
+TARGET = tst_android
+QT = core testlib
+
+SOURCES += \
+ tst_android.cpp
+
+ANDROID_PACKAGE_SOURCE_DIR = $$PWD/testdata
+
+DISTFILES += \
+ testdata/assets/test.txt
diff --git a/tests/auto/other/android/testdata/assets/test.txt b/tests/auto/other/android/testdata/assets/test.txt
new file mode 100644
index 0000000000..61e2c47c25
--- /dev/null
+++ b/tests/auto/other/android/testdata/assets/test.txt
@@ -0,0 +1 @@
+FooBar \ No newline at end of file
diff --git a/tests/auto/other/android/tst_android.cpp b/tests/auto/other/android/tst_android.cpp
new file mode 100644
index 0000000000..245382ded3
--- /dev/null
+++ b/tests/auto/other/android/tst_android.cpp
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** 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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** 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.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+class tst_Android : public QObject
+{
+Q_OBJECT
+private slots:
+ void assetsRead();
+ void assetsNotWritable();
+};
+
+void tst_Android::assetsRead()
+{
+ {
+ QFile file("assets:/test.txt");
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QCOMPARE(file.readAll(), QByteArray("FooBar"));
+ }
+
+ {
+ QFile file("assets:/test.txt");
+ QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text));
+ QCOMPARE(file.readAll(), QByteArray("FooBar"));
+ }
+}
+
+void tst_Android::assetsNotWritable()
+{
+ QFile file("assets:/test.txt");
+ QVERIFY(!file.open(QIODevice::WriteOnly));
+ QVERIFY(!file.open(QIODevice::ReadWrite));
+ QVERIFY(!file.open(QIODevice::Append));
+}
+
+QTEST_MAIN(tst_Android)
+#include "tst_android.moc"
+
diff --git a/tests/auto/other/other.pro b/tests/auto/other/other.pro
index 9f7d45e562..c5673727be 100644
--- a/tests/auto/other/other.pro
+++ b/tests/auto/other/other.pro
@@ -71,3 +71,6 @@ wince*|!contains(QT_CONFIG, accessibility): SUBDIRS -= qaccessibility
winrt: SUBDIRS -= \
qprocess_and_guieventloop
+
+android: SUBDIRS += \
+ android