summaryrefslogtreecommitdiffstats
path: root/tests/auto/qfile/tst_qfile.cpp
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-12-14 20:14:18 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-12-14 20:14:18 (GMT)
commit62e2f0b44c92a0f59416bcd4d9bc87e35cb6d80a (patch)
treef934fb50d74f91763806bc0afecbacd980279aa2 /tests/auto/qfile/tst_qfile.cpp
parentd6dace9bebd8a8ad8caaecb69dd24dd1ddf96f4a (diff)
parentaa10afea34995c262156d26957455b698e630953 (diff)
downloadQt-62e2f0b44c92a0f59416bcd4d9bc87e35cb6d80a.zip
Qt-62e2f0b44c92a0f59416bcd4d9bc87e35cb6d80a.tar.gz
Qt-62e2f0b44c92a0f59416bcd4d9bc87e35cb6d80a.tar.bz2
Merge branch 'earth/file-engine-refactor' of scm.dev.nokia.troll.no:qt/qt-file-engines-refactor into master-integration
* 'earth/file-engine-refactor' of scm.dev.nokia.troll.no:qt/qt-file-engines-refactor: (224 commits) Fix warnings, whitespace cleanup Don't rely on uninitialized data Doc: Fixing typo Doc: Fixing typo Skip failing tests Use effective user id instead of getlogin Fix compile error in tst_qfileinfo on Mac/Linux Fix tst_QFileInfo owner() & group() failure on Windows. Fix tst_QFileInfo::canonicalFilePath failure on Windows Fix QDir::relativeFilePath Fix spelling in comments Add missing license header to test case Define _WIN32_WINNT before any includes New attempt at fixing compilation failure Removing unused duplicate definitions No symbolic links in Windows CE Set minimum target Windows version to 2000 More missing includes Add missing include Fix compile error ...
Diffstat (limited to 'tests/auto/qfile/tst_qfile.cpp')
-rw-r--r--tests/auto/qfile/tst_qfile.cpp206
1 files changed, 198 insertions, 8 deletions
diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp
index ee799f3..c19079f 100644
--- a/tests/auto/qfile/tst_qfile.cpp
+++ b/tests/auto/qfile/tst_qfile.cpp
@@ -170,6 +170,7 @@ private slots:
void encodeName();
void truncate();
void seekToPos();
+ void seekAfterEndOfFile();
void FILEReadWrite();
void i18nFileName_data();
void i18nFileName();
@@ -210,6 +211,16 @@ private slots:
void openStandardStreams();
+ void resize_data();
+ void resize();
+
+ void objectConstructors();
+#ifdef Q_OS_SYMBIAN
+ void platformSecurity_data();
+ void platformSecurity();
+#endif
+ void caseSensitivity();
+
// --- Task related tests below this line
void task167217();
@@ -394,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");
}
//------------------------------------------
@@ -402,7 +414,7 @@ void tst_QFile::cleanupTestCase()
// attributes and the contents itself
// will be changed as far as we have a
// proper way to handle files in the
-// testing enviroment.
+// testing environment.
//------------------------------------------
void tst_QFile::exists()
@@ -1108,6 +1120,7 @@ void tst_QFile::permissions()
QFETCH(bool, expected);
QFile f(file);
QCOMPARE(((f.permissions() & perms) == QFile::Permissions(perms)), expected);
+ QCOMPARE(((QFile::permissions(file) & perms) == QFile::Permissions(perms)), expected);
}
void tst_QFile::setPermissions()
@@ -1285,17 +1298,32 @@ static QString getWorkingDirectoryForLink(const QString &linkFileName)
void tst_QFile::link()
{
+#if defined(Q_OS_SYMBIAN)
+ QSKIP("Symbian does not support links", SkipAll);
+#endif
QFile::remove("myLink.lnk");
- QFileInfo info1("tst_qfile.cpp");
- QVERIFY(QFile::link("tst_qfile.cpp", "myLink.lnk"));
+
+ QFileInfo info1(SRCDIR "tst_qfile.cpp");
+ QString referenceTarget = QDir::cleanPath(info1.absoluteFilePath());
+
+ QVERIFY(QFile::link(SRCDIR "tst_qfile.cpp", "myLink.lnk"));
+
QFileInfo info2("myLink.lnk");
QVERIFY(info2.isSymLink());
- QCOMPARE(info2.symLinkTarget(), info1.absoluteFilePath());
+ QCOMPARE(info2.symLinkTarget(), referenceTarget);
+
+ QFile link("myLink.lnk");
+ QVERIFY(link.open(QIODevice::ReadOnly));
+ QCOMPARE(link.symLinkTarget(), referenceTarget);
+ link.close();
+
+ QCOMPARE(QFile::symLinkTarget("myLink.lnk"), referenceTarget);
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
QString wd = getWorkingDirectoryForLink(info2.absoluteFilePath());
- QCOMPARE(QDir::fromNativeSeparators(wd), info1.absolutePath());
+ QCOMPARE(QDir::fromNativeSeparators(wd), QDir::cleanPath(info1.absolutePath()));
#endif
+
QVERIFY(QFile::remove(info2.absoluteFilePath()));
}
@@ -1324,6 +1352,9 @@ void tst_QFile::linkToDir()
void tst_QFile::absolutePathLinkToRelativePath()
{
+#if defined(Q_OS_SYMBIAN)
+ QSKIP("Symbian does not support links", SkipAll);
+#endif
QFile::remove("myDir/test.txt");
QFile::remove("myDir/myLink.lnk");
QDir dir;
@@ -1346,6 +1377,9 @@ void tst_QFile::absolutePathLinkToRelativePath()
void tst_QFile::readBrokenLink()
{
+#if defined(Q_OS_SYMBIAN)
+ QSKIP("Symbian does not support links", SkipAll);
+#endif
QFile::remove("myLink2.lnk");
QFileInfo info1("file12");
#if defined(Q_OS_SYMBIAN)
@@ -1635,10 +1669,40 @@ void tst_QFile::seekToPos()
}
+void tst_QFile::seekAfterEndOfFile()
+{
+ QLatin1String filename("seekAfterEof.dat");
+ QFile::remove(filename);
+ {
+ QFile file(filename);
+ QVERIFY(file.open(QFile::WriteOnly));
+ file.write("abcd");
+ QCOMPARE(file.size(), qint64(4));
+ file.seek(8);
+ file.write("ijkl");
+ QCOMPARE(file.size(), qint64(12));
+ file.seek(4);
+ file.write("efgh");
+ QCOMPARE(file.size(), qint64(12));
+ file.seek(16);
+ file.write("----");
+ QCOMPARE(file.size(), qint64(20));
+ file.flush();
+ }
+
+ QFile file(filename);
+ QVERIFY(file.open(QFile::ReadOnly));
+ QByteArray contents = file.readAll();
+ QCOMPARE(contents.left(12), QByteArray("abcdefghijkl", 12));
+ //bytes 12-15 are uninitialised so we don't care what they read as.
+ QCOMPARE(contents.mid(16), QByteArray("----", 4));
+ file.close();
+ QFile::remove(filename);
+}
void tst_QFile::FILEReadWrite()
{
- // Tests modifing a file. First creates it then reads in 4 bytes and then overwrites these
+ // Tests modifying a file. First creates it then reads in 4 bytes and then overwrites these
// 4 bytes with new values. At the end check to see the file contains the new values.
QFile::remove("FILEReadWrite.txt");
@@ -2494,10 +2558,11 @@ void tst_QFile::standarderror()
void tst_QFile::handle()
{
-#ifndef Q_OS_WINCE
+ int fd;
+#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
QFile file(SRCDIR "tst_qfile.cpp");
QVERIFY(file.open(QIODevice::ReadOnly));
- int fd = int(file.handle());
+ fd = int(file.handle());
QVERIFY(fd > 2);
QCOMPARE(int(file.handle()), fd);
char c = '\0';
@@ -2524,6 +2589,7 @@ void tst_QFile::handle()
QCOMPARE(c, '*');
#endif
+ //test round trip of adopted stdio file handle
QFile file2;
FILE *fp = fopen(SRCDIR "tst_qfile.cpp", "r");
file2.open(fp, QIODevice::ReadOnly);
@@ -2531,6 +2597,7 @@ void tst_QFile::handle()
QCOMPARE(int(file2.handle()), int(fileno(fp)));
fclose(fp);
+ //test round trip of adopted posix file handle
#ifdef Q_OS_UNIX
QFile file3;
fd = QT_OPEN(SRCDIR "tst_qfile.cpp", QT_OPEN_RDONLY);
@@ -2542,6 +2609,9 @@ void tst_QFile::handle()
void tst_QFile::nativeHandleLeaks()
{
+#ifdef Q_OS_SYMBIAN
+ QSKIP("test assumptions invalid for symbian", SkipAll);
+#else
int fd1, fd2;
#ifdef Q_OS_WIN
@@ -2583,6 +2653,7 @@ void tst_QFile::nativeHandleLeaks()
#ifdef Q_OS_WIN
QCOMPARE( handle2, handle1 );
#endif
+#endif
}
void tst_QFile::readEof_data()
@@ -2898,6 +2969,7 @@ void tst_QFile::mapOpenMode()
{
QFETCH(int, openMode);
static const qint64 fileSize = 4096;
+
QByteArray pattern(fileSize, 'A');
QString fileName = QDir::currentPath() + '/' + "qfile_map_testfile";
@@ -3037,5 +3109,123 @@ void tst_QFile::writeNothing()
}
}
+void tst_QFile::resize_data()
+{
+ QTest::addColumn<int>("filetype");
+
+ QTest::newRow("native") << int(OpenQFile);
+ QTest::newRow("fileno") << int(OpenFd);
+ QTest::newRow("stream") << int(OpenStream);
+}
+
+void tst_QFile::resize()
+{
+ QFETCH(int, filetype);
+ QString filename(QLatin1String("file.txt"));
+ QFile file(filename);
+ QVERIFY(openFile(file, QIODevice::ReadWrite, FileType(filetype)));
+ QVERIFY(file.resize(8));
+ QCOMPARE(file.size(), qint64(8));
+ closeFile(file);
+ QFile::resize(filename, 4);
+ QCOMPARE(QFileInfo(filename).size(), qint64(4));
+ QVERIFY(QFile::remove(filename));
+}
+
+void tst_QFile::objectConstructors()
+{
+ QObject ob;
+ QFile* file1 = new QFile(SRCDIR "testfile.txt", &ob);
+ QFile* file2 = new QFile(&ob);
+ QVERIFY(file1->exists());
+ 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) || defined(Q_OS_MAC)
+ 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"