diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2010-12-13 17:06:19 (GMT) |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2010-12-13 17:49:11 (GMT) |
commit | 496a3f83138e807150f2ff06f5462f7f9ab519fc (patch) | |
tree | 31255a5864d477b2db87708ee1c245ba2bd1bbe2 /tests/auto | |
parent | 14f4ebce80ec7d39287b445192b25111a49fff6b (diff) | |
download | Qt-496a3f83138e807150f2ff06f5462f7f9ab519fc.zip Qt-496a3f83138e807150f2ff06f5462f7f9ab519fc.tar.gz Qt-496a3f83138e807150f2ff06f5462f7f9ab519fc.tar.bz2 |
Don't rely on uninitialized data
When we fail to get file attributes, the file times are left in an
uninitialized state, which may lead to a crash. In particular, this was
showing up in QMessageBox's autotest, where the lastModified time is
being queried on a non-existing file.
Before the refactoring, we were returning a default constructed
QDateTime to queries about different file times, with this change we
will return the time corresponding to a default constructed FILETIME
object.
Reviewed-by: Shane Kearns
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qfileinfo/tst_qfileinfo.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp index 0a61d55..4d9e80b 100644 --- a/tests/auto/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp @@ -196,6 +196,8 @@ private slots: void owner(); #endif void group(); + + void invalidState(); }; tst_QFileInfo::tst_QFileInfo() @@ -1761,5 +1763,48 @@ void tst_QFileInfo::group() QCOMPARE(fi.group(), expected); } +void tst_QFileInfo::invalidState() +{ + // Shouldn't crash; + + { + QFileInfo info; + QCOMPARE(info.size(), qint64(0)); + QVERIFY(!info.exists()); + + info.setCaching(false); + + info.created(); + info.lastRead(); + info.lastModified(); + } + + { + QFileInfo info(""); + QCOMPARE(info.size(), qint64(0)); + QVERIFY(!info.exists()); + + info.setCaching(false); + + info.created(); + info.lastRead(); + info.lastModified(); + } + + { + QFileInfo info("file-doesn't-really-exist.txt"); + QCOMPARE(info.size(), qint64(0)); + QVERIFY(!info.exists()); + + info.setCaching(false); + + info.created(); + info.lastRead(); + info.lastModified(); + } + + QVERIFY(true); +} + QTEST_MAIN(tst_QFileInfo) #include "tst_qfileinfo.moc" |