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>
This commit is contained in:
parent
b65a415e67
commit
ce9c4915d5
@ -133,9 +133,7 @@ public:
|
||||
|
||||
virtual bool open(QIODevice::OpenMode openMode)
|
||||
{
|
||||
if (m_assetFile)
|
||||
return openMode & QIODevice::ReadOnly;
|
||||
return false;
|
||||
return m_assetFile != 0 && (openMode & QIODevice::WriteOnly) == 0;
|
||||
}
|
||||
|
||||
virtual bool close()
|
||||
|
11
tests/auto/other/android/android.pro
Normal file
11
tests/auto/other/android/android.pro
Normal file
@ -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
|
1
tests/auto/other/android/testdata/assets/test.txt
vendored
Normal file
1
tests/auto/other/android/testdata/assets/test.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
FooBar
|
69
tests/auto/other/android/tst_android.cpp
Normal file
69
tests/auto/other/android/tst_android.cpp
Normal file
@ -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"
|
||||
|
@ -71,3 +71,6 @@ wince*|!contains(QT_CONFIG, accessibility): SUBDIRS -= qaccessibility
|
||||
|
||||
winrt: SUBDIRS -= \
|
||||
qprocess_and_guieventloop
|
||||
|
||||
android: SUBDIRS += \
|
||||
android
|
||||
|
Loading…
x
Reference in New Issue
Block a user