diff options
author | João Abecasis <joao@abecasis.name> | 2009-10-23 13:02:05 (GMT) |
---|---|---|
committer | João Abecasis <joao@abecasis.name> | 2009-10-23 13:07:00 (GMT) |
commit | 45a09e31ebb25d3ad4f63ae02f0a0b464577761e (patch) | |
tree | a3b1f64a70cd03352819c582aa586c40ca6e6a39 /tests | |
parent | f808fe435dc00398775fe8040d3c811aed6332a9 (diff) | |
download | Qt-45a09e31ebb25d3ad4f63ae02f0a0b464577761e.zip Qt-45a09e31ebb25d3ad4f63ae02f0a0b464577761e.tar.gz Qt-45a09e31ebb25d3ad4f63ae02f0a0b464577761e.tar.bz2 |
Extending QFile::size test to cover files opened with fd and FILE*
Also changed tested type from int to qint64, so we'll be able to see
clipping issues, although there are no large files in this test, yet.
Reviewed-by: Markus Goetz
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qfile/tst_qfile.cpp | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp index 4971762..55cc286 100644 --- a/tests/auto/qfile/tst_qfile.cpp +++ b/tests/auto/qfile/tst_qfile.cpp @@ -117,6 +117,7 @@ private slots: void openUnbuffered(); void size_data(); void size(); + void sizeNoExist(); void seek(); void setSize(); void setSizeSeek(); @@ -452,23 +453,57 @@ void tst_QFile::openUnbuffered() void tst_QFile::size_data() { QTest::addColumn<QString>("filename"); - QTest::addColumn<int>("size"); + QTest::addColumn<qint64>("size"); - QTest::newRow( "exist01" ) << QString(SRCDIR "testfile.txt") << 245; - QTest::newRow( "nonexist01" ) << QString("foo.txt") << 0; + QTest::newRow( "exist01" ) << QString(SRCDIR "testfile.txt") << (qint64)245; #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) // Only test UNC on Windows./ - QTest::newRow("unc") << "//" + QString(QtNetworkSettings::winServerName() + "/testsharewritable/test.pri") << 34; + QTest::newRow("unc") << "//" + QString(QtNetworkSettings::winServerName() + "/testsharewritable/test.pri") << (qint64)34; #endif } void tst_QFile::size() { QFETCH( QString, filename ); - QFile f( filename ); - QTEST( (int)f.size(), "size" ); - if (f.open(QFile::ReadOnly)) - QTEST( (int)f.size(), "size" ); + QFETCH( qint64, size ); + + { + QFile f( filename ); + QCOMPARE( f.size(), size ); + + QVERIFY( f.open(QIODevice::ReadOnly) ); + QCOMPARE( f.size(), size ); + } + + { + QFile f; + 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(); + QT_CLOSE(fd); + } + + { + QFile f; + FILE* stream = QT_FOPEN(filename.toLocal8Bit().constData(), "rb"); + QVERIFY( stream ); + QVERIFY( f.open(stream, QIODevice::ReadOnly) ); + QCOMPARE( f.size(), size ); + + f.close(); + fclose(stream); + } +} + +void tst_QFile::sizeNoExist() +{ + QFile file("nonexist01"); + QVERIFY( !file.exists() ); + QCOMPARE( file.size(), (qint64)0 ); + QVERIFY( !file.open(QIODevice::ReadOnly) ); } void tst_QFile::seek() |