summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-10-16 16:08:30 (GMT)
committerSamuli Piippo <samuli.piippo@digia.com>2011-06-09 10:05:28 (GMT)
commit7f093666e2e6c122750c428271b97dd39217f2b1 (patch)
tree417c41a97ae7fac2be392db759265eafe111834d /tests
parentd451dfaeee0d1a770c95cb11b963b496d235df8b (diff)
downloadQt-7f093666e2e6c122750c428271b97dd39217f2b1.zip
Qt-7f093666e2e6c122750c428271b97dd39217f2b1.tar.gz
Qt-7f093666e2e6c122750c428271b97dd39217f2b1.tar.bz2
_close(fd) closes the associated handle and not the other way around
... according to the online MSDN documentation. Hid the cachedFd member in private data under WinCE, since it's never used there. Task-number: QTBUG-9085 Reviewed-by: Zeno Albisser (cherry picked from commit 7986ab58b9a5d0828291c857d3ce86bfa1af4e6e)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qfile/tst_qfile.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp
index 1b5f03f..4d87aaa 100644
--- a/tests/auto/qfile/tst_qfile.cpp
+++ b/tests/auto/qfile/tst_qfile.cpp
@@ -196,6 +196,7 @@ private slots:
void miscWithUncPathAsCurrentDir();
void standarderror();
void handle();
+ void nativeHandleLeaks();
void readEof_data();
void readEof();
@@ -392,6 +393,7 @@ void tst_QFile::cleanupTestCase()
QFile::remove("resources");
QFile::remove("qfile_map_testfile");
QFile::remove("readAllBuffer.txt");
+ QFile::remove("qt_file.tmp");
}
//------------------------------------------
@@ -2538,6 +2540,51 @@ void tst_QFile::handle()
#endif
}
+void tst_QFile::nativeHandleLeaks()
+{
+ int fd1, fd2;
+
+#ifdef Q_OS_WIN
+ HANDLE handle1, handle2;
+#endif
+
+ {
+ QFile file("qt_file.tmp");
+ QVERIFY( file.open(QIODevice::ReadWrite) );
+
+ fd1 = file.handle();
+ QVERIFY( -1 != fd1 );
+ }
+
+#ifdef Q_OS_WIN
+ handle1 = ::CreateFileA("qt_file.tmp", GENERIC_READ, 0, NULL,
+ OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ QVERIFY( INVALID_HANDLE_VALUE != handle1 );
+ QVERIFY( ::CloseHandle(handle1) );
+#endif
+
+ {
+ QFile file("qt_file.tmp");
+ QVERIFY( file.open(QIODevice::ReadOnly) );
+
+ fd2 = file.handle();
+ QVERIFY( -1 != fd2 );
+ }
+
+#ifdef Q_OS_WIN
+ handle2 = ::CreateFileA("qt_file.tmp", GENERIC_READ, 0, NULL,
+ OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ QVERIFY( INVALID_HANDLE_VALUE != handle2 );
+ QVERIFY( ::CloseHandle(handle2) );
+#endif
+
+ QCOMPARE( fd2, fd1 );
+
+#ifdef Q_OS_WIN
+ QCOMPARE( handle2, handle1 );
+#endif
+}
+
void tst_QFile::readEof_data()
{
QTest::addColumn<QString>("filename");