summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2010-12-21 13:00:07 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2010-12-21 16:41:23 (GMT)
commitb6218123974795f1a83c42198ab7fd3ceeab8029 (patch)
treefab1ad9ba3ae68b7d9dd9952e950badcf964f0a2 /tests
parent7b626760a27579263dc894d11f10cb57a576105a (diff)
downloadQt-b6218123974795f1a83c42198ab7fd3ceeab8029.zip
Qt-b6218123974795f1a83c42198ab7fd3ceeab8029.tar.gz
Qt-b6218123974795f1a83c42198ab7fd3ceeab8029.tar.bz2
Fix qfile test errors
Fix compile error for non symbian targets Fix MSVCRT assertion failure Test file.handle() returns the right thing before and after file is closed. Reviewed-by: joao
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qfile/tst_qfile.cpp42
1 files changed, 39 insertions, 3 deletions
diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp
index d9b8283..4e18ec4 100644
--- a/tests/auto/qfile/tst_qfile.cpp
+++ b/tests/auto/qfile/tst_qfile.cpp
@@ -345,8 +345,10 @@ private:
QT_CLOSE(fd_);
if (stream_)
::fclose(stream_);
+#ifdef Q_OS_SYMBIAN
if (rfile_.SubSessionHandle())
rfile_.Close();
+#endif
fd_ = -1;
stream_ = 0;
@@ -3282,6 +3284,25 @@ void tst_QFile::caseSensitivity()
}
}
+//MSVCRT asserts when any function is called with a closed file handle.
+//This replaces the default crashing error handler with one that ignores the error (allowing EBADF to be returned)
+class AutoIgnoreInvalidParameter
+{
+public:
+#if defined(Q_OS_WIN) && defined (Q_CC_MSVC)
+ static void ignore_invalid_parameter(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t) {}
+ AutoIgnoreInvalidParameter()
+ {
+ old = _set_invalid_parameter_handler(ignore_invalid_parameter);
+ }
+ ~AutoIgnoreInvalidParameter()
+ {
+ _set_invalid_parameter_handler(old);
+ }
+ _invalid_parameter_handler old;
+#endif
+};
+
void tst_QFile::autocloseHandle()
{
#ifdef Q_OS_SYMBIAN
@@ -3318,41 +3339,56 @@ void tst_QFile::autocloseHandle()
{
QFile file("readonlyfile");
QVERIFY(openFile(file, QIODevice::ReadOnly, OpenFd, QFile::AutoCloseHandle));
+ QCOMPARE(file.handle(), fd_);
file.close();
+ QCOMPARE(file.handle(), -1);
+ AutoIgnoreInvalidParameter a;
+ Q_UNUSED(a);
//file is closed, read should fail
char buf;
- QCOMPARE(::read(fd_, &buf, 1), -1);
+ QCOMPARE(QT_READ(fd_, &buf, 1), -1);
QVERIFY(errno = EBADF);
+ fd_ = -1;
}
{
QFile file("readonlyfile");
QVERIFY(openFile(file, QIODevice::ReadOnly, OpenFd, QFile::DontCloseHandle));
+ QCOMPARE(file.handle(), fd_);
file.close();
+ QCOMPARE(file.handle(), -1);
//file is not closed, read should succeed
char buf;
- QCOMPARE(::read(fd_, &buf, 1), 1);
+ QCOMPARE(QT_READ(fd_, &buf, 1), 1);
::close(fd_);
+ fd_ = -1;
}
{
QFile file("readonlyfile");
QVERIFY(openFile(file, QIODevice::ReadOnly, OpenStream, QFile::AutoCloseHandle));
+ QCOMPARE(file.handle(), fileno(stream_));
file.close();
+ QCOMPARE(file.handle(), -1);
+ AutoIgnoreInvalidParameter a;
+ Q_UNUSED(a);
//file is closed, read should fail
char buf;
QCOMPARE(int(::fread(&buf, 1, 1, stream_)), 0);
- QVERIFY(::ferror(stream_)); //actual error seems to be OS dependent
+ stream_ = 0;
}
{
QFile file("readonlyfile");
QVERIFY(openFile(file, QIODevice::ReadOnly, OpenStream, QFile::DontCloseHandle));
+ QCOMPARE(file.handle(), fileno(stream_));
file.close();
+ QCOMPARE(file.handle(), -1);
//file is not closed, read should succeed
char buf;
QCOMPARE(int(::fread(&buf, 1, 1, stream_)), 1);
::fclose(stream_);
+ stream_ = 0;
}
}