summaryrefslogtreecommitdiff
path: root/tests/auto/filesearch
diff options
context:
space:
mode:
authorcon <qtc-committer@nokia.com>2010-11-01 17:39:28 +0100
committercon <qtc-committer@nokia.com>2010-11-02 11:13:43 +0100
commita031112befaee011f7355a05e6c457d2ac027e12 (patch)
tree60c2ba3465f980248377d2034b28a0441e32f2c2 /tests/auto/filesearch
parent77008bc45f52be5338d6be4abc76035ca6d40c8b (diff)
downloadqt-creator-a031112befaee011f7355a05e6c457d2ac027e12.tar.gz
Add auto test for file search.
Diffstat (limited to 'tests/auto/filesearch')
-rw-r--r--tests/auto/filesearch/filesearch.pro22
-rw-r--r--tests/auto/filesearch/testfile.txt5
-rw-r--r--tests/auto/filesearch/tst_filesearch.cpp102
-rw-r--r--tests/auto/filesearch/tst_filesearch.qrc5
4 files changed, 134 insertions, 0 deletions
diff --git a/tests/auto/filesearch/filesearch.pro b/tests/auto/filesearch/filesearch.pro
new file mode 100644
index 0000000000..251541fc63
--- /dev/null
+++ b/tests/auto/filesearch/filesearch.pro
@@ -0,0 +1,22 @@
+CONFIG += qtestlib testcase
+TEMPLATE = app
+CONFIG -= app_bundle
+DEFINES += QTCREATOR_UTILS_LIB
+
+include(../../../qtcreator.pri)
+
+UTILS_PATH = $$IDE_SOURCE_TREE/src/libs/utils
+
+INCLUDEPATH += $$UTILS_PATH
+# Input
+SOURCES += tst_filesearch.cpp \
+ $$UTILS_PATH/filesearch.cpp
+HEADERS += $$UTILS_PATH/filesearch.h \
+ $$UTILS_PATH/utils_global.h
+
+TARGET=tst_$$TARGET
+
+OTHER_FILES += testfile.txt
+
+RESOURCES += \
+ tst_filesearch.qrc
diff --git a/tests/auto/filesearch/testfile.txt b/tests/auto/filesearch/testfile.txt
new file mode 100644
index 0000000000..b131ad179b
--- /dev/null
+++ b/tests/auto/filesearch/testfile.txt
@@ -0,0 +1,5 @@
+wholeWordAtStart bla foo blubb wholeWordAtEnd
+search to find multiple find results
+search CaseSensitively for casesensitive
+here you find another result
+wholeWordAtVeryEnd
diff --git a/tests/auto/filesearch/tst_filesearch.cpp b/tests/auto/filesearch/tst_filesearch.cpp
new file mode 100644
index 0000000000..23159150d0
--- /dev/null
+++ b/tests/auto/filesearch/tst_filesearch.cpp
@@ -0,0 +1,102 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include <filesearch.h>
+
+#include <QtTest/QtTest>
+
+bool operator==(const Utils::FileSearchResult &r1, const Utils::FileSearchResult &r2)
+{
+ return r1.fileName == r2.fileName
+ && r1.lineNumber == r2.lineNumber
+ && r1.matchingLine == r2.matchingLine
+ && r1.matchStart == r2.matchStart
+ && r1.matchLength == r2.matchLength
+ && r1.regexpCapturedTexts == r2.regexpCapturedTexts;
+}
+
+class tst_FileSearch : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void multipleResults();
+ void caseSensitive();
+ void caseInSensitive();
+};
+
+namespace {
+ const char * const FILENAME = ":/tst_filesearch/testfile.txt";
+
+ void test_helper(const Utils::FileSearchResultList &expectedResults,
+ const QString &term,
+ QTextDocument::FindFlags flags)
+ {
+ Utils::FileIterator *it = new Utils::FileIterator(QStringList() << QLatin1String(FILENAME), QList<QTextCodec *>() << QTextCodec::codecForLocale());
+ QFutureWatcher<Utils::FileSearchResultList> watcher;
+ QSignalSpy ready(&watcher, SIGNAL(resultsReadyAt(int,int)));
+ watcher.setFuture(Utils::findInFiles(term, it, flags));
+ watcher.future().waitForFinished();
+ QTest::qWait(100); // process events
+ QCOMPARE(ready.count(), 1);
+ Utils::FileSearchResultList results = watcher.resultAt(0);
+ QCOMPARE(results.count(), expectedResults.count());
+ for (int i = 0; i < expectedResults.size(); ++i) {
+ QCOMPARE(results.at(i), expectedResults.at(i));
+ }
+ }
+}
+
+void tst_FileSearch::multipleResults()
+{
+ Utils::FileSearchResultList expectedResults;
+ expectedResults << Utils::FileSearchResult(QLatin1String(FILENAME), 2, QLatin1String("search to find multiple find results"), 10, 4, QStringList());
+ expectedResults << Utils::FileSearchResult(QLatin1String(FILENAME), 2, QLatin1String("search to find multiple find results"), 24, 4, QStringList());
+ expectedResults << Utils::FileSearchResult(QLatin1String(FILENAME), 4, QLatin1String("here you find another result"), 9, 4, QStringList());
+ test_helper(expectedResults, QLatin1String("find"), QTextDocument::FindFlags(0));
+}
+
+void tst_FileSearch::caseSensitive()
+{
+ Utils::FileSearchResultList expectedResults;
+ expectedResults << Utils::FileSearchResult(QLatin1String(FILENAME), 3, QLatin1String("search CaseSensitively for casesensitive"), 7, 13, QStringList());
+ test_helper(expectedResults, QLatin1String("CaseSensitive"), QTextDocument::FindCaseSensitively);
+}
+
+void tst_FileSearch::caseInSensitive()
+{
+ Utils::FileSearchResultList expectedResults;
+ expectedResults << Utils::FileSearchResult(QLatin1String(FILENAME), 3, QLatin1String("search CaseSensitively for casesensitive"), 7, 13, QStringList());
+ expectedResults << Utils::FileSearchResult(QLatin1String(FILENAME), 3, QLatin1String("search CaseSensitively for casesensitive"), 27, 13, QStringList());
+ test_helper(expectedResults, QLatin1String("CaseSensitive"), QTextDocument::FindFlags(0));
+}
+
+QTEST_MAIN(tst_FileSearch)
+
+#include "tst_filesearch.moc"
diff --git a/tests/auto/filesearch/tst_filesearch.qrc b/tests/auto/filesearch/tst_filesearch.qrc
new file mode 100644
index 0000000000..ff0a6b7cdc
--- /dev/null
+++ b/tests/auto/filesearch/tst_filesearch.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/tst_filesearch">
+ <file>testfile.txt</file>
+ </qresource>
+</RCC>