summaryrefslogtreecommitdiffstats
path: root/tests/auto/qfile
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2010-01-08 11:55:25 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2010-01-08 11:55:25 (GMT)
commit30d45394f59c25fc2c3e7e30da4e49bf9744de76 (patch)
tree8483a7b767bb36023f90bca39f8512dc11553f22 /tests/auto/qfile
parentd170179f00effe691de23167e02ff5aeecaeb054 (diff)
parent2e62227f950aac8205f2b67e4d7d046836b2c799 (diff)
downloadQt-30d45394f59c25fc2c3e7e30da4e49bf9744de76.zip
Qt-30d45394f59c25fc2c3e7e30da4e49bf9744de76.tar.gz
Qt-30d45394f59c25fc2c3e7e30da4e49bf9744de76.tar.bz2
Merge remote branch 'origin/master'
Diffstat (limited to 'tests/auto/qfile')
-rw-r--r--tests/auto/qfile/tst_qfile.cpp116
1 files changed, 103 insertions, 13 deletions
diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp
index 7ee5665..e88c222 100644
--- a/tests/auto/qfile/tst_qfile.cpp
+++ b/tests/auto/qfile/tst_qfile.cpp
@@ -129,6 +129,8 @@ private slots:
void readLine();
void readLine2();
void readLineNullInLine();
+ void readAll_data();
+ void readAll();
void readAllStdin();
void readLineStdin();
void readLineStdin_lineByLine();
@@ -220,6 +222,9 @@ public:
private:
enum FileType { OpenQFile, OpenFd, OpenStream };
+ void openStandardStreamsFileDescriptors();
+ void openStandardStreamsBufferedStreams();
+
bool openFd(QFile &file, QIODevice::OpenMode mode)
{
int fdMode = QT_OPEN_LARGEFILE | QT_OPEN_BINARY;
@@ -554,6 +559,10 @@ void tst_QFile::size()
QFETCH( QString, filename );
QFETCH( qint64, size );
+#ifdef Q_WS_WINCE
+ filename = QFileInfo(filename).absoluteFilePath();
+#endif
+
{
QFile f( filename );
QCOMPARE( f.size(), size );
@@ -564,24 +573,29 @@ void tst_QFile::size()
{
QFile f;
- int fd = QT_OPEN(filename.toLocal8Bit().constData(), QT_OPEN_RDONLY);
- QVERIFY( fd != -1 );
- QVERIFY( f.open(fd, QIODevice::ReadOnly) );
+ FILE* stream = QT_FOPEN(filename.toLocal8Bit().constData(), "rb");
+ QVERIFY( stream );
+ QVERIFY( f.open(stream, QIODevice::ReadOnly) );
QCOMPARE( f.size(), size );
f.close();
- QT_CLOSE(fd);
+ fclose(stream);
}
{
+#ifdef Q_WS_WINCE
+ QSKIP("Currently low level file I/O not well supported on Windows CE", SkipSingle);
+#endif
QFile f;
- FILE* stream = QT_FOPEN(filename.toLocal8Bit().constData(), "rb");
- QVERIFY( stream );
- QVERIFY( f.open(stream, QIODevice::ReadOnly) );
+
+ int fd = QT_OPEN(filename.toLocal8Bit().constData(), QT_OPEN_RDONLY);
+
+ QVERIFY( fd != -1 );
+ QVERIFY( f.open(fd, QIODevice::ReadOnly) );
QCOMPARE( f.size(), size );
f.close();
- fclose(stream);
+ QT_CLOSE(fd);
}
}
@@ -603,6 +617,7 @@ void tst_QFile::seek()
QVERIFY(file.seek(10));
QCOMPARE(file.pos(), qint64(10));
QCOMPARE(file.size(), qint64(0));
+ file.close();
QFile::remove("newfile.txt");
}
@@ -739,6 +754,45 @@ void tst_QFile::readLineNullInLine()
QCOMPARE(file.readLine(), QByteArray());
}
+void tst_QFile::readAll_data()
+{
+ QTest::addColumn<bool>("textMode");
+ QTest::addColumn<QString>("fileName");
+ QTest::newRow( "TextMode unixfile" ) << true << SRCDIR "testfile.txt";
+ QTest::newRow( "BinaryMode unixfile" ) << false << SRCDIR "testfile.txt";
+ QTest::newRow( "TextMode dosfile" ) << true << SRCDIR "dosfile.txt";
+ QTest::newRow( "BinaryMode dosfile" ) << false << SRCDIR "dosfile.txt";
+ QTest::newRow( "TextMode bigfile" ) << true << SRCDIR "tst_qfile.cpp";
+ QTest::newRow( "BinaryMode bigfile" ) << false << SRCDIR "tst_qfile.cpp";
+ QVERIFY(QFile(SRCDIR "tst_qfile.cpp").size() > 64*1024);
+}
+
+void tst_QFile::readAll()
+{
+ QFETCH( bool, textMode );
+ QFETCH( QString, fileName );
+
+ QFile file(fileName);
+ if (textMode)
+ QVERIFY(file.open(QFile::Text | QFile::ReadOnly));
+ else
+ QVERIFY(file.open(QFile::ReadOnly));
+
+ QByteArray a = file.readAll();
+ file.reset();
+ QVERIFY(file.pos() == 0);
+
+ QVERIFY(file.bytesAvailable() > 7);
+ QByteArray b = file.read(1);
+ char x;
+ file.getChar(&x);
+ b.append(x);
+ b.append(file.read(5));
+ b.append(file.readAll());
+
+ QCOMPARE(a, b);
+}
+
void tst_QFile::readAllStdin()
{
#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
@@ -1128,9 +1182,15 @@ void tst_QFile::copyFallback()
QVERIFY(QFile::exists("file-copy-destination.txt"));
QVERIFY(!file.isOpen());
+#ifdef Q_WS_WINCE
// Need to reset permissions on Windows to be able to delete
QVERIFY(QFile::setPermissions("file-copy-destination.txt",
- QFile::ReadOwner | QFile::WriteOwner));
+ QFile::WriteOther));
+#else
+ // Need to reset permissions on Windows to be able to delete
+ QVERIFY(QFile::setPermissions("file-copy-destination.txt",
+ QFile::ReadOwner | QFile::WriteOwner));
+#endif
QVERIFY(QFile::remove("file-copy-destination.txt"));
// Fallback copy of open file.
@@ -1139,6 +1199,7 @@ void tst_QFile::copyFallback()
QVERIFY(QFile::exists("file-copy-destination.txt"));
QVERIFY(!file.isOpen());
+ file.close();
QFile::remove("file-copy-destination.txt");
}
@@ -2239,6 +2300,7 @@ void tst_QFile::rename()
QFile file(source);
QCOMPARE(file.rename(destination), result);
+
if (result)
QCOMPARE(file.error(), QFile::NoError);
else
@@ -2367,6 +2429,7 @@ void tst_QFile::appendAndRead()
QCOMPARE(readFile.read(1 << j).size(), 1 << j);
}
+ readFile.close();
QFile::remove(QLatin1String("appendfile.txt"));
}
@@ -2608,10 +2671,15 @@ void tst_QFile::map()
QFETCH(QFile::FileError, error);
QString fileName = QDir::currentPath() + '/' + "qfile_map_testfile";
+
+#ifdef Q_WS_WINCE
+ fileName = QFileInfo(fileName).absoluteFilePath();
+#endif
+
if (QFile::exists(fileName)) {
QVERIFY(QFile::setPermissions(fileName,
QFile::WriteOwner | QFile::ReadOwner | QFile::WriteUser | QFile::ReadUser));
- QFile::remove(fileName);
+ QFile::remove(fileName);
}
QFile file(fileName);
@@ -2650,8 +2718,13 @@ void tst_QFile::map()
QCOMPARE(file.error(), QFile::NoError);
// hpux wont let you map multiple times.
-#if !defined(Q_OS_HPUX) && !defined(Q_USE_DEPRECATED_MAP_API)
+#if !defined(Q_OS_HPUX) && !defined(Q_USE_DEPRECATED_MAP_API) && !defined(Q_OS_WINCE)
// exotic test to make sure that multiple maps work
+
+ // note: windows ce does not reference count mutliple maps
+ // it's essentially just the same reference but it
+ // cause a resource lock on the file which prevents it
+ // from being removed uchar *memory1 = file.map(0, file.size());
uchar *memory1 = file.map(0, file.size());
QCOMPARE(file.error(), QFile::NoError);
uchar *memory2 = file.map(0, file.size());
@@ -2687,7 +2760,6 @@ void tst_QFile::map()
QVERIFY(!memory);
QVERIFY(file.setPermissions(originalPermissions));
}
-
QVERIFY(file.remove());
}
@@ -2800,8 +2872,14 @@ void tst_QFile::openDirectory()
f1.close();
}
-void tst_QFile::openStandardStreams()
+void tst_QFile::openStandardStreamsFileDescriptors()
{
+#ifdef Q_WS_WINCE
+ //allthough Windows CE (not mobile!) has functions that allow redirecting
+ //the standard file descriptors to a file (see SetStdioPathW/GetStdioPathW)
+ //it does not have functions to simply open them like below .
+ QSKIP("Opening standard streams on Windows CE via descriptor not implemented", SkipAll);
+#endif
// Using file descriptors
{
QFile in;
@@ -2826,7 +2904,13 @@ void tst_QFile::openStandardStreams()
QCOMPARE( err.size(), (qint64)0 );
QVERIFY( err.isSequential() );
}
+}
+void tst_QFile::openStandardStreamsBufferedStreams()
+{
+#if defined (Q_OS_WIN) || defined(Q_OS_SYMBIAN)
+ QSKIP("Unix only test.", SkipAll);
+#endif
// Using streams
{
QFile in;
@@ -2853,6 +2937,12 @@ void tst_QFile::openStandardStreams()
}
}
+void tst_QFile::openStandardStreams()
+{
+ openStandardStreamsFileDescriptors();
+ openStandardStreamsBufferedStreams();
+}
+
void tst_QFile::writeNothing()
{
for (int i = 0; i < 3; ++i) {