diff options
author | João Abecasis <joao@abecasis.name> | 2009-10-20 13:39:06 (GMT) |
---|---|---|
committer | João Abecasis <joao@abecasis.name> | 2009-10-21 11:46:08 (GMT) |
commit | 6f52892206b155451e7b24cdbb1b4ab6569153e9 (patch) | |
tree | a48982ca819dbc06d07d3dbb40dd00a4578377bb /tests | |
parent | badfa3435f740ec7120b2ed3367fa2be50382136 (diff) | |
download | Qt-6f52892206b155451e7b24cdbb1b4ab6569153e9.zip Qt-6f52892206b155451e7b24cdbb1b4ab6569153e9.tar.gz Qt-6f52892206b155451e7b24cdbb1b4ab6569153e9.tar.bz2 |
Get file position when attaching an open file descriptor to QFile
This was already being done when attaching to FILE* streams. Doing the
same here makes the API consistent and more usable. Namely, one can use
QFile::pos() to obtain the file position.
Test case verifies this doesn't break support for sequential files. More
thorough test case included in large file support test.
Reviewed-by: Thiago Macieira
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qfile/tst_qfile.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp index 19fbecd..bbb6280 100644 --- a/tests/auto/qfile/tst_qfile.cpp +++ b/tests/auto/qfile/tst_qfile.cpp @@ -187,6 +187,8 @@ private slots: void mapOpenMode_data(); void mapOpenMode(); + void openStandardStreams(); + // --- Task related tests below this line void task167217(); @@ -2634,5 +2636,58 @@ void tst_QFile::openDirectory() QVERIFY(!f1.open(QIODevice::ReadOnly|QIODevice::Unbuffered)); } +void tst_QFile::openStandardStreams() +{ + // Using file descriptors + { + QFile in; + in.open(STDIN_FILENO, QIODevice::ReadOnly); + QCOMPARE( in.pos(), (qint64)0 ); + QCOMPARE( in.size(), (qint64)0 ); + QVERIFY( in.isSequential() ); + } + + { + QFile out; + out.open(STDOUT_FILENO, QIODevice::WriteOnly); + QCOMPARE( out.pos(), (qint64)0 ); + QCOMPARE( out.size(), (qint64)0 ); + QVERIFY( out.isSequential() ); + } + + { + QFile err; + err.open(STDERR_FILENO, QIODevice::WriteOnly); + QCOMPARE( err.pos(), (qint64)0 ); + QCOMPARE( err.size(), (qint64)0 ); + QVERIFY( err.isSequential() ); + } + + // Using streams + { + QFile in; + in.open(stdin, QIODevice::ReadOnly); + QCOMPARE( in.pos(), (qint64)0 ); + QCOMPARE( in.size(), (qint64)0 ); + QVERIFY( in.isSequential() ); + } + + { + QFile out; + out.open(stdout, QIODevice::WriteOnly); + QCOMPARE( out.pos(), (qint64)0 ); + QCOMPARE( out.size(), (qint64)0 ); + QVERIFY( out.isSequential() ); + } + + { + QFile err; + err.open(stderr, QIODevice::WriteOnly); + QCOMPARE( err.pos(), (qint64)0 ); + QCOMPARE( err.size(), (qint64)0 ); + QVERIFY( err.isSequential() ); + } +} + QTEST_MAIN(tst_QFile) #include "tst_qfile.moc" |