summaryrefslogtreecommitdiffstats
path: root/tests/auto/qcompleter/tst_qcompleter.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-10-12 14:38:30 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-10-13 09:28:41 (GMT)
commit40b5c05b9921b5fa3ceae7f723c0b26c4861bda7 (patch)
treea6a0d22304d38239621fe627619a4895507e36f0 /tests/auto/qcompleter/tst_qcompleter.cpp
parent1a9037333214a898588d39fd2ae087bca5ff3b53 (diff)
downloadQt-40b5c05b9921b5fa3ceae7f723c0b26c4861bda7.zip
Qt-40b5c05b9921b5fa3ceae7f723c0b26c4861bda7.tar.gz
Qt-40b5c05b9921b5fa3ceae7f723c0b26c4861bda7.tar.bz2
tst_qcompleter: Add a test for QFileSystemModel
Copied from the test for QDirModel Reviewed-by: Thierry
Diffstat (limited to 'tests/auto/qcompleter/tst_qcompleter.cpp')
-rw-r--r--tests/auto/qcompleter/tst_qcompleter.cpp82
1 files changed, 76 insertions, 6 deletions
diff --git a/tests/auto/qcompleter/tst_qcompleter.cpp b/tests/auto/qcompleter/tst_qcompleter.cpp
index 1590528..3e05fbc 100644
--- a/tests/auto/qcompleter/tst_qcompleter.cpp
+++ b/tests/auto/qcompleter/tst_qcompleter.cpp
@@ -119,6 +119,8 @@ private slots:
void directoryModel_data();
void directoryModel();
+ void fileSystemModel_data();
+ void fileSystemModel();
void changingModel_data();
void changingModel();
@@ -151,13 +153,14 @@ private slots:
void task247560_keyboardNavigation();
private:
- void filter();
+ void filter(bool assync = false);
void testRowCount();
enum ModelType {
CASE_SENSITIVELY_SORTED_MODEL,
CASE_INSENSITIVELY_SORTED_MODEL,
DIRECTORY_MODEL,
- HISTORY_MODEL
+ HISTORY_MODEL,
+ FILESYSTEM_MODEL
};
void setSourceModel(ModelType);
@@ -233,12 +236,21 @@ void tst_QCompleter::setSourceModel(ModelType type)
completer->setModel(new QDirModel(completer));
completer->setCompletionColumn(0);
break;
+ case FILESYSTEM_MODEL:
+ completer->setCsvCompletion(false);
+ {
+ QFileSystemModel *m = new QFileSystemModel(completer);
+ m->setRootPath("/");
+ completer->setModel(m);
+ }
+ completer->setCompletionColumn(0);
+ break;
default:
qDebug() << "Invalid type";
}
}
-void tst_QCompleter::filter()
+void tst_QCompleter::filter(bool assync)
{
QFETCH(QString, filterText);
QFETCH(QString, step);
@@ -250,6 +262,9 @@ void tst_QCompleter::filter()
return;
}
+ int times = 0;
+retry:
+
completer->setCompletionPrefix(filterText);
for (int i = 0; i < step.length(); i++) {
@@ -265,9 +280,13 @@ void tst_QCompleter::filter()
completer->setCurrentRow(row);
}
- //QModelIndex si = completer->currentIndex();
- //QCOMPARE(completer->model()->data(si).toString(), completion);
- QVERIFY(0 == QString::compare(completer->currentCompletion(), completionText, completer->caseSensitivity()));
+ int r = QString::compare(completer->currentCompletion(), completionText, completer->caseSensitivity());
+ if (assync && r && times < 10) {
+ times++;
+ QTest::qWait(50*times);
+ goto retry;
+ }
+ QVERIFY(!r);
}
// Testing get/set functions
@@ -598,6 +617,57 @@ void tst_QCompleter::directoryModel()
filter();
}
+void tst_QCompleter::fileSystemModel_data()
+{
+ delete completer;
+ completer = new CsvCompleter;
+ completer->setModelSorting(QCompleter::CaseSensitivelySortedModel);
+ setSourceModel(FILESYSTEM_MODEL);
+ completer->setCaseSensitivity(Qt::CaseInsensitive);
+
+ QTest::addColumn<QString>("filterText");
+ QTest::addColumn<QString>("step");
+ QTest::addColumn<QString>("completion");
+ QTest::addColumn<QString>("completionText");
+
+ // NOTE: Add tests carefully, ensurely the paths exist on all systems
+ // Output is the sourceText; currentCompletionText()
+
+ for (int i = 0; i < 2; i++) {
+ if (i == 1)
+ QTest::newRow("FILTERING_OFF") << "FILTERING_OFF" << "" << "" << "";
+
+#if defined(Q_OS_WINCE)
+ QTest::newRow("()") << "" << "" << "/" << "/";
+ QTest::newRow("()") << "\\Program" << "" << "Program Files" << "\\Program Files";
+#elif defined(Q_OS_WIN)
+ QTest::newRow("()") << "C" << "" << "C:" << "C:";
+ QTest::newRow("()") << "C:\\Program" << "" << "Program Files" << "C:\\Program Files";
+#elif defined(Q_OS_SYMBIAN)
+ QTest::newRow("()") << "C" << "" << "C:" << "C:";
+ QTest::newRow("()") << "C:\\re" << "" << "resource" << "C:\\resource";
+#elif defined (Q_OS_MAC)
+ QTest::newRow("()") << "" << "" << "/" << "/";
+ QTest::newRow("(/a)") << "/a" << "" << "Applications" << "/Applications";
+ QTest::newRow("(/d)") << "/d" << "" << "Developer" << "/Developer";
+#else
+ QTest::newRow("()") << "" << "" << "/" << "/";
+#if !defined(Q_OS_IRIX) && !defined(Q_OS_AIX) && !defined(Q_OS_HPUX)
+ QTest::newRow("(/h)") << "/h" << "" << "home" << "/home";
+#endif
+ QTest::newRow("(/et)") << "/et" << "" << "etc" << "/etc";
+ QTest::newRow("(/etc/passw)") << "/etc/passw" << "" << "passwd" << "/etc/passwd";
+#endif
+ }
+}
+
+void tst_QCompleter::fileSystemModel()
+{
+ //QFileSystemModel is assync.
+ filter(true);
+}
+
+
void tst_QCompleter::changingModel_data()
{
}