summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2010-08-31 07:56:27 (GMT)
committerJoão Abecasis <joao.abecasis@nokia.com>2010-09-07 12:17:10 (GMT)
commitb0de175aab06092932077eb1c5fb3f89691b6014 (patch)
tree234528d2f057de9e213d61f17a611836b952c366 /tests/auto
parent8e8743113f642e82bac6ecc055d2d3be8f53d7a6 (diff)
downloadQt-b0de175aab06092932077eb1c5fb3f89691b6014.zip
Qt-b0de175aab06092932077eb1c5fb3f89691b6014.tar.gz
Qt-b0de175aab06092932077eb1c5fb3f89691b6014.tar.bz2
QDir and QFileInfo shouldn't lose properties when detaching
For QFileInfo, the caching state was being lost on the different setFile overloads. QDir::cd and ::makeAbsolute were losing filters and sorting flags. QDir issues were introduced with these patches: "Simplify QDir::cd" "QDir::makeAbsolute could self-destruct on failure" Reviewed-by: Prasanth Ullattil
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qdir/tst_qdir.cpp99
-rw-r--r--tests/auto/qfileinfo/tst_qfileinfo.cpp48
2 files changed, 147 insertions, 0 deletions
diff --git a/tests/auto/qdir/tst_qdir.cpp b/tests/auto/qdir/tst_qdir.cpp
index c8c835f..fb83a5a 100644
--- a/tests/auto/qdir/tst_qdir.cpp
+++ b/tests/auto/qdir/tst_qdir.cpp
@@ -167,6 +167,8 @@ private slots:
void longFileName();
void updateFileLists();
+
+ void detachingOperations();
};
// Testing get/set functions
@@ -1541,6 +1543,103 @@ void tst_QDir::updateFileLists()
QCOMPARE(dir.entryList(), QStringList() << "sub-dir1" << "sub-dir2" << "file1.txt");
}
+void tst_QDir::detachingOperations()
+{
+ QString const defaultPath(".");
+ QStringList const defaultNameFilters = QStringList("*");
+ QDir::SortFlags const defaultSorting = QDir::Name | QDir::IgnoreCase;
+ QDir::Filters const defaultFilter = QDir::AllEntries;
+
+ QString const path1("..");
+ QString const path2("./foo");
+ QStringList const nameFilters = QStringList(QString("*.txt"));
+ QDir::SortFlags const sorting = QDir::Name | QDir::DirsLast | QDir::Reversed;
+ QDir::Filters const filter = QDir::Writable;
+
+ QDir dir1;
+
+ QCOMPARE(dir1.path(), defaultPath);
+ QCOMPARE(dir1.filter(), defaultFilter);
+ QCOMPARE(dir1.nameFilters(), defaultNameFilters);
+ QCOMPARE(dir1.sorting(), defaultSorting);
+
+ dir1.setPath(path1);
+ QCOMPARE(dir1.path(), path1);
+ QCOMPARE(dir1.filter(), defaultFilter);
+ QCOMPARE(dir1.nameFilters(), defaultNameFilters);
+ QCOMPARE(dir1.sorting(), defaultSorting);
+
+ dir1.setFilter(filter);
+ QCOMPARE(dir1.path(), path1);
+ QCOMPARE(dir1.filter(), filter);
+ QCOMPARE(dir1.nameFilters(), defaultNameFilters);
+ QCOMPARE(dir1.sorting(), defaultSorting);
+
+ dir1.setNameFilters(nameFilters);
+ QCOMPARE(dir1.path(), path1);
+ QCOMPARE(dir1.filter(), filter);
+ QCOMPARE(dir1.nameFilters(), nameFilters);
+ QCOMPARE(dir1.sorting(), defaultSorting);
+
+ dir1.setSorting(sorting);
+ QCOMPARE(dir1.path(), path1);
+ QCOMPARE(dir1.filter(), filter);
+ QCOMPARE(dir1.nameFilters(), nameFilters);
+ QCOMPARE(dir1.sorting(), sorting);
+
+ dir1.setPath(path2);
+ QCOMPARE(dir1.path(), path2);
+ QCOMPARE(dir1.filter(), filter);
+ QCOMPARE(dir1.nameFilters(), nameFilters);
+ QCOMPARE(dir1.sorting(), sorting);
+
+ {
+ QDir dir2(dir1);
+ QCOMPARE(dir2.path(), path2);
+ QCOMPARE(dir2.filter(), filter);
+ QCOMPARE(dir2.nameFilters(), nameFilters);
+ QCOMPARE(dir2.sorting(), sorting);
+ }
+
+ {
+ QDir dir2;
+ QCOMPARE(dir2.path(), defaultPath);
+ QCOMPARE(dir2.filter(), defaultFilter);
+ QCOMPARE(dir2.nameFilters(), defaultNameFilters);
+ QCOMPARE(dir2.sorting(), defaultSorting);
+
+ dir2 = dir1;
+ QCOMPARE(dir2.path(), path2);
+ QCOMPARE(dir2.filter(), filter);
+ QCOMPARE(dir2.nameFilters(), nameFilters);
+ QCOMPARE(dir2.sorting(), sorting);
+
+ dir2 = path1;
+ QCOMPARE(dir2.path(), path1);
+ QCOMPARE(dir2.filter(), filter);
+ QCOMPARE(dir2.nameFilters(), nameFilters);
+ QCOMPARE(dir2.sorting(), sorting);
+ }
+
+ dir1.refresh();
+ QCOMPARE(dir1.path(), path2);
+ QCOMPARE(dir1.filter(), filter);
+ QCOMPARE(dir1.nameFilters(), nameFilters);
+ QCOMPARE(dir1.sorting(), sorting);
+
+ QString const currentPath = QDir::currentPath();
+ QVERIFY(dir1.cd(currentPath));
+ QCOMPARE(dir1.path(), currentPath);
+ QCOMPARE(dir1.filter(), filter);
+ QCOMPARE(dir1.nameFilters(), nameFilters);
+ QCOMPARE(dir1.sorting(), sorting);
+
+ QVERIFY(dir1.cdUp());
+ QCOMPARE(dir1.filter(), filter);
+ QCOMPARE(dir1.nameFilters(), nameFilters);
+ QCOMPARE(dir1.sorting(), sorting);
+}
+
QTEST_MAIN(tst_QDir)
#include "tst_qdir.moc"
diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp
index 540a1cd..208110a 100644
--- a/tests/auto/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp
@@ -172,6 +172,8 @@ private slots:
void equalOperator() const;
void equalOperatorWithDifferentSlashes() const;
void notEqualOperator() const;
+
+ void detachingOperations();
};
tst_QFileInfo::tst_QFileInfo()
@@ -1377,5 +1379,51 @@ void tst_QFileInfo::notEqualOperator() const
QVERIFY(QFileInfo() != QFileInfo());
}
+void tst_QFileInfo::detachingOperations()
+{
+ QFileInfo info1;
+ QVERIFY(info1.caching());
+ info1.setCaching(false);
+
+ {
+ QFileInfo info2 = info1;
+
+ QVERIFY(!info1.caching());
+ QVERIFY(!info2.caching());
+
+ info2.setCaching(true);
+ QVERIFY(info2.caching());
+
+ info1.setFile("foo");
+ QVERIFY(!info1.caching());
+ }
+
+ {
+ QFile file("foo");
+ info1.setFile(file);
+ QVERIFY(!info1.caching());
+ }
+
+ info1.setFile(QDir(), "foo");
+ QVERIFY(!info1.caching());
+
+ {
+ QFileInfo info3;
+ QVERIFY(info3.caching());
+
+ info3 = info1;
+ QVERIFY(!info3.caching());
+ }
+
+ info1.refresh();
+ QVERIFY(!info1.caching());
+
+ QVERIFY(info1.makeAbsolute());
+ QVERIFY(!info1.caching());
+
+ info1.detach();
+ QVERIFY(!info1.caching());
+}
+
QTEST_MAIN(tst_QFileInfo)
#include "tst_qfileinfo.moc"