summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2010-11-29 16:48:17 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2010-11-30 11:55:57 (GMT)
commitf417baad9235e90b5e9aae2fd06d664635c68bec (patch)
treeeeb489429b38c39c393c4e488620662c9fab10c2 /tests
parentcd3e03f5e70fa6d973949516f50ea05f201aac20 (diff)
downloadQt-f417baad9235e90b5e9aae2fd06d664635c68bec.zip
Qt-f417baad9235e90b5e9aae2fd06d664635c68bec.tar.gz
Qt-f417baad9235e90b5e9aae2fd06d664635c68bec.tar.bz2
Add symbian platform security and case sensitivity test cases
On symbian, check that opening files in protected locations either succeeds or fails cleanly as expected by the capabilities the test is compiled with. This acts as a regression test for opening files in /resource, and also checks the other locations behave as expected. On all platforms, check file created with a mixed case filename can be accessed by it's aliases that differ only in case (or not) depending on the OS case sensitivity. For Windows/Symbian, file should be accessible by altered case aliases For other OS, it should not (other OS supported by Qt are unix like) Reviewed-by: mread
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qfile/tst_qfile.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp
index 1bbf230..4421f0d 100644
--- a/tests/auto/qfile/tst_qfile.cpp
+++ b/tests/auto/qfile/tst_qfile.cpp
@@ -215,6 +215,11 @@ private slots:
void resize();
void objectConstructors();
+#ifdef Q_OS_SYMBIAN
+ void platformSecurity_data();
+ void platformSecurity();
+#endif
+ void caseSensitivity();
// --- Task related tests below this line
void task167217();
@@ -400,6 +405,7 @@ void tst_QFile::cleanupTestCase()
QFile::remove("qfile_map_testfile");
QFile::remove("readAllBuffer.txt");
QFile::remove("qt_file.tmp");
+ QFile::remove("File.txt");
}
//------------------------------------------
@@ -3135,5 +3141,91 @@ void tst_QFile::objectConstructors()
QVERIFY(!file2->exists());
}
+#ifdef Q_OS_SYMBIAN
+void tst_QFile::platformSecurity_data()
+{
+ QTest::addColumn<QString>("file");
+ QTest::addColumn<bool>("readable");
+ QTest::addColumn<bool>("writable");
+
+ QString selfname = QCoreApplication::applicationFilePath();
+ QString ownprivate = QCoreApplication::applicationDirPath();
+ QString owndrive = selfname.left(2);
+ bool amiprivileged = RProcess().HasCapability(ECapabilityAllFiles);
+ QTest::newRow("resource") << owndrive + "/resource/apps/tst_qfile.rsc" << true << amiprivileged;
+ QTest::newRow("sys") << selfname << amiprivileged << false;
+ QTest::newRow("own private") << ownprivate + "/testfile.txt" << true << true;
+ QTest::newRow("other private") << owndrive + "/private/10003a3f/import/apps/tst_qfile_reg.rsc" << amiprivileged << amiprivileged;
+}
+
+void tst_QFile::platformSecurity()
+{
+ QFETCH(QString,file);
+ QFETCH(bool,readable);
+ QFETCH(bool,writable);
+
+ {
+ QFile f(file);
+ QCOMPARE(f.open(QIODevice::ReadOnly), readable);
+ }
+
+ {
+ QFile f(file);
+ QCOMPARE(f.open(QIODevice::ReadOnly | QIODevice::Unbuffered), readable);
+ }
+
+ //append mode used to avoid truncating the files.
+ {
+ QFile f(file);
+ QCOMPARE(f.open(QIODevice::WriteOnly | QIODevice::Append), writable);
+ }
+
+ {
+ QFile f(file);
+ QCOMPARE(f.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Unbuffered), writable);
+ }
+
+ {
+ QFile f(file);
+ QCOMPARE(f.open(QIODevice::ReadWrite), writable);
+ }
+
+ {
+ QFile f(file);
+ QCOMPARE(f.open(QIODevice::ReadWrite | QIODevice::Unbuffered), writable);
+ }
+}
+#endif
+
+void tst_QFile::caseSensitivity()
+{
+#if defined(Q_OS_SYMBIAN) || defined(Q_OS_WIN)
+ const bool caseSensitive = false;
+#else
+ const bool caseSensitive = true;
+#endif
+ QByteArray testData("a little test");
+ QString filename("File.txt");
+ {
+ QFile f(filename);
+ QVERIFY(f.open(QIODevice::WriteOnly));
+ QVERIFY(f.write(testData));
+ f.close();
+ }
+ QStringList alternates;
+ QFileInfo fi(filename);
+ QVERIFY(fi.exists());
+ alternates << "file.txt" << "File.TXT" << "fIlE.TxT" << fi.absoluteFilePath().toUpper() << fi.absoluteFilePath().toLower();
+ foreach (QString alt, alternates) {
+ QFileInfo fi2(alt);
+ QCOMPARE(fi2.exists(), !caseSensitive);
+ QCOMPARE(fi.size() == fi2.size(), !caseSensitive);
+ QFile f2(alt);
+ QCOMPARE(f2.open(QIODevice::ReadOnly), !caseSensitive);
+ if (caseSensitive)
+ QCOMPARE(f2.readAll(), testData);
+ }
+}
+
QTEST_MAIN(tst_QFile)
#include "tst_qfile.moc"