summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
diff options
context:
space:
mode:
authorGeir Vattekar <geir.vattekar@trolltech.com>2009-05-15 13:23:00 (GMT)
committerGeir Vattekar <geir.vattekar@trolltech.com>2009-05-15 13:23:00 (GMT)
commitfe7040348d82c5e5d302e7ec674fc0e3f68f06e1 (patch)
tree6b40b8c1e69a044aebd23f7b137d9abb4720b5e8 /tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
parenta830e5f22a42d00b0b92544cfcb56c79b2c3b6cd (diff)
parent3875cd2b0a81c190939ea2803a2efbe890ae38ec (diff)
downloadQt-fe7040348d82c5e5d302e7ec674fc0e3f68f06e1.zip
Qt-fe7040348d82c5e5d302e7ec674fc0e3f68f06e1.tar.gz
Qt-fe7040348d82c5e5d302e7ec674fc0e3f68f06e1.tar.bz2
Merge branch '4.5' of git@scm.dev.nokia.troll.no:qt/qt into 4.5
Diffstat (limited to 'tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp')
-rw-r--r--tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
index f5155ae..2daa0f6 100644
--- a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -51,6 +51,13 @@
#if defined(Q_OS_WIN)
# include <windows.h>
#endif
+#if defined(Q_OS_UNIX)
+# include <sys/types.h>
+# include <sys/stat.h>
+# include <errno.h>
+# include <fcntl.h> // open(2)
+# include <unistd.h> // close(2)
+#endif
//TESTED_CLASS=
//TESTED_FILES=
@@ -78,6 +85,7 @@ private slots:
void openOnRootDrives();
void stressTest();
void rename();
+ void renameFdLeak();
public:
};
@@ -356,5 +364,42 @@ void tst_QTemporaryFile::rename()
QVERIFY(!dir.exists("temporary-file.txt"));
}
+void tst_QTemporaryFile::renameFdLeak()
+{
+#ifdef Q_OS_UNIX
+ // Test this on Unix only
+
+ // Open a bunch of files to force the fd count to go up
+ static const int count = 10;
+ int bunch_of_files[count];
+ for (int i = 0; i < count; ++i) {
+ bunch_of_files[i] = ::open(SRCDIR "tst_qtemporaryfile.cpp", O_RDONLY);
+ QVERIFY(bunch_of_files[i] != -1);
+ }
+
+ int fd;
+ {
+ QTemporaryFile file;
+ file.setAutoRemove(false);
+ QVERIFY(file.open());
+
+ // close the bunch of files
+ for (int i = 0; i < count; ++i)
+ ::close(bunch_of_files[i]);
+
+ // save the file descriptor for later
+ fd = file.handle();
+
+ // rename the file to something
+ QString newPath = QDir::tempPath() + "/tst_qtemporaryfile-renameFdLeak-" + QString::number(getpid());
+ file.rename(newPath);
+ QFile::remove(newPath);
+ }
+
+ // check if QTemporaryFile closed the file
+ QVERIFY(::close(fd) == -1 && errno == EBADF);
+#endif
+}
+
QTEST_MAIN(tst_QTemporaryFile)
#include "tst_qtemporaryfile.moc"