diff options
Diffstat (limited to 'tests/auto/corelib/io/qfile/tst_qfile.cpp')
-rw-r--r-- | tests/auto/corelib/io/qfile/tst_qfile.cpp | 80 |
1 files changed, 68 insertions, 12 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index e92f6df419..cd13e2bd19 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -68,8 +68,6 @@ QT_END_NAMESPACE #elif defined(Q_OS_FREEBSD) # include <sys/param.h> # include <sys/mount.h> -#elif defined(Q_OS_IRIX) -# include <sys/statfs.h> #elif defined(Q_OS_VXWORKS) # include <fcntl.h> #if defined(_WRS_KERNEL) @@ -170,6 +168,8 @@ private slots: void getch(); void ungetChar(); void createFile(); + void createFileNewOnly(); + void openFileExistingOnly(); void append(); void permissions_data(); void permissions(); @@ -1213,6 +1213,48 @@ void tst_QFile::createFile() QVERIFY( QFile::exists( "createme.txt" ) ); } +void tst_QFile::createFileNewOnly() +{ + QFile::remove("createme.txt"); + QVERIFY(!QFile::exists("createme.txt")); + + QFile f("createme.txt"); + QVERIFY2(f.open(QIODevice::NewOnly), msgOpenFailed(f).constData()); + f.close(); + QVERIFY(QFile::exists("createme.txt")); + + QVERIFY(!f.open(QIODevice::NewOnly)); + QVERIFY(QFile::exists("createme.txt")); + QFile::remove("createme.txt"); +} + +void tst_QFile::openFileExistingOnly() +{ + QFile::remove("dontcreateme.txt"); + QVERIFY(!QFile::exists("dontcreateme.txt")); + + QFile f("dontcreateme.txt"); + QVERIFY(!f.open(QIODevice::ExistingOnly | QIODevice::ReadOnly)); + QVERIFY(!f.open(QIODevice::ExistingOnly | QIODevice::WriteOnly)); + QVERIFY(!f.open(QIODevice::ExistingOnly | QIODevice::ReadWrite)); + QVERIFY(!f.open(QIODevice::ExistingOnly)); + QVERIFY(!QFile::exists("dontcreateme.txt")); + + QVERIFY2(f.open(QIODevice::NewOnly), msgOpenFailed(f).constData()); + f.close(); + QVERIFY(QFile::exists("dontcreateme.txt")); + + QVERIFY2(f.open(QIODevice::ExistingOnly | QIODevice::ReadOnly), msgOpenFailed(f).constData()); + f.close(); + QVERIFY2(f.open(QIODevice::ExistingOnly | QIODevice::WriteOnly), msgOpenFailed(f).constData()); + f.close(); + QVERIFY2(f.open(QIODevice::ExistingOnly | QIODevice::ReadWrite), msgOpenFailed(f).constData()); + f.close(); + QVERIFY(!f.open(QIODevice::ExistingOnly)); + QVERIFY(QFile::exists("dontcreateme.txt")); + QFile::remove("dontcreateme.txt"); +} + void tst_QFile::append() { const QString name("appendme.txt"); @@ -1966,10 +2008,6 @@ void tst_QFile::largeFileSupport() if (::GetDiskFreeSpaceEx((wchar_t*)QDir::currentPath().utf16(), &free, 0, 0)) freespace = free.QuadPart; if (freespace != 0) { -#elif defined(Q_OS_IRIX) - struct statfs info; - if (statfs(QDir::currentPath().local8Bit(), &info, sizeof(struct statfs), 0) == 0) { - freespace = qlonglong(info.f_bfree * info.f_bsize); #else struct statfs info; if (statfs(const_cast<char *>(QDir::currentPath().toLocal8Bit().constData()), &info) == 0) { @@ -2147,6 +2185,7 @@ public: uint ownerId(FileOwner) const { return 0; } QString owner(FileOwner) const { return QString(); } QDateTime fileTime(FileTime) const { return QDateTime(); } + bool setFileTime(const QDateTime &newDate, FileTime time) { return false; } private: int number; @@ -3256,22 +3295,39 @@ static qint64 streamExpectedSize(int fd) QT_STATBUF sb; if (QT_FSTAT(fd, &sb) != -1) return sb.st_size; + qErrnoWarning("Could not fstat fd %d", fd); return 0; } static qint64 streamCurrentPosition(int fd) { - QT_OFF_T pos = QT_LSEEK(fd, 0, SEEK_CUR); - if (pos != -1) - return pos; + QT_STATBUF sb; + if (QT_FSTAT(fd, &sb) != -1) { + QT_OFF_T pos = -1; + if ((sb.st_mode & QT_STAT_MASK) == QT_STAT_REG) + pos = QT_LSEEK(fd, 0, SEEK_CUR); + if (pos != -1) + return pos; + // failure to lseek() is not a problem + } else { + qErrnoWarning("Could not fstat fd %d", fd); + } return 0; } static qint64 streamCurrentPosition(FILE *f) { - QT_OFF_T pos = QT_FTELL(f); - if (pos != -1) - return pos; + QT_STATBUF sb; + if (QT_FSTAT(QT_FILENO(f), &sb) != -1) { + QT_OFF_T pos = -1; + if ((sb.st_mode & QT_STAT_MASK) == QT_STAT_REG) + pos = QT_FTELL(f); + if (pos != -1) + return pos; + // failure to ftell() is not a problem + } else { + qErrnoWarning("Could not fstat fd %d", QT_FILENO(f)); + } return 0; } |