summaryrefslogtreecommitdiffstats
path: root/tests/auto/qfileinfo
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2010-12-13 18:06:19 +0100
committerJoão Abecasis <joao.abecasis@nokia.com>2010-12-13 18:49:11 +0100
commit496a3f83138e807150f2ff06f5462f7f9ab519fc (patch)
tree31255a5864d477b2db87708ee1c245ba2bd1bbe2 /tests/auto/qfileinfo
parent14f4ebce80ec7d39287b445192b25111a49fff6b (diff)
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/qfileinfo')
-rw-r--r--tests/auto/qfileinfo/tst_qfileinfo.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp
index 0a61d55566..4d9e80b689 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"