diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2023-05-05 14:05:10 +0200 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2023-05-09 11:03:48 +0000 |
commit | 936086745ab826932f6559cc51f49ba20718f56a (patch) | |
tree | 5acc6d4a5043b8c1ff6e5f80465db5d1f08403f8 /tests | |
parent | 1d4228dfda8137920523c242c17e59451bcb937b (diff) | |
download | qt-creator-936086745ab826932f6559cc51f49ba20718f56a.tar.gz |
FileSearch: Get rid of FileSearchResult
Use SearchResultItem instead.
This change should reduce the remaining freeze described in
a9eb732ce6763e22badd92fc8523cebe84b09a84 even more.
Change-Id: I102b82ed5677360ccd9e425dd0bdd941d87116f0
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/filesearch/tst_filesearch.cpp | 103 | ||||
-rw-r--r-- | tests/unit/unittest/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/unit/unittest/compare-operators.h | 25 | ||||
-rw-r--r-- | tests/unit/unittest/googletest.h | 2 |
4 files changed, 61 insertions, 70 deletions
diff --git a/tests/auto/filesearch/tst_filesearch.cpp b/tests/auto/filesearch/tst_filesearch.cpp index 2532f7a313..95bec53e09 100644 --- a/tests/auto/filesearch/tst_filesearch.cpp +++ b/tests/auto/filesearch/tst_filesearch.cpp @@ -22,66 +22,85 @@ private slots: void caseSensitive(); void caseInSensitive(); void matchCaseReplacement(); + +private: + const FilePath m_filePath = FilePath::fromString(":/tst_filesearch/testfile.txt"); }; -namespace { - const char * const FILENAME = ":/tst_filesearch/testfile.txt"; - - void test_helper(const Utils::FileSearchResultList &expectedResults, - const QString &term, - QTextDocument::FindFlags flags, tst_FileSearch::RegExpFlag regexp = tst_FileSearch::NoRegExp) - { - Utils::FileIterator *it = new Utils::FileListIterator({FilePath::fromString(FILENAME)}, - {QTextCodec::codecForLocale()}); - QFutureWatcher<Utils::FileSearchResultList> watcher; - QSignalSpy ready(&watcher, &QFutureWatcherBase::resultsReadyAt); - if (regexp == tst_FileSearch::NoRegExp) - watcher.setFuture(Utils::findInFiles(term, it, flags)); - else - watcher.setFuture(Utils::findInFilesRegExp(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)); - } - } +SearchResultItem searchResult(const FilePath &fileName, const QString &matchingLine, + int lineNumber, int matchStart, int matchLength, + const QStringList ®expCapturedTexts = {}) +{ + SearchResultItem result; + result.setFilePath(fileName); + result.setLineText(matchingLine); + result.setMainRange(lineNumber, matchStart, matchLength); + result.setUserData(regexpCapturedTexts); + result.setUseTextEditorFont(true); + return result; +} + +void test_helper(const FilePath &filePath, const SearchResultItems &expectedResults, + const QString &term, QTextDocument::FindFlags flags = {}, + tst_FileSearch::RegExpFlag regexp = tst_FileSearch::NoRegExp) +{ + FileIterator *it = new FileListIterator({filePath}, {QTextCodec::codecForLocale()}); + QFutureWatcher<SearchResultItems> watcher; + QSignalSpy ready(&watcher, &QFutureWatcherBase::resultsReadyAt); + if (regexp == tst_FileSearch::NoRegExp) + watcher.setFuture(Utils::findInFiles(term, it, flags)); + else + watcher.setFuture(Utils::findInFilesRegExp(term, it, flags)); + watcher.future().waitForFinished(); + QTest::qWait(100); // process events + QCOMPARE(ready.count(), 1); + SearchResultItems 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 << FileSearchResult(FilePath::fromString(FILENAME), 2, QLatin1String("search to find multiple find results"), 10, 4, QStringList()); - expectedResults << FileSearchResult(FilePath::fromString(FILENAME), 2, QLatin1String("search to find multiple find results"), 24, 4, QStringList()); - expectedResults << FileSearchResult(FilePath::fromString(FILENAME), 4, QLatin1String("here you find another result"), 9, 4, QStringList()); - test_helper(expectedResults, QLatin1String("find"), QTextDocument::FindFlags()); + SearchResultItems expectedResults; + expectedResults << searchResult(m_filePath, "search to find multiple find results", 2, 10, 4); + expectedResults << searchResult(m_filePath, "search to find multiple find results", 2, 24, 4); + expectedResults << searchResult(m_filePath, "here you find another result", 4, 9, 4); + test_helper(m_filePath, expectedResults, "find"); expectedResults.clear(); - expectedResults << FileSearchResult(FilePath::fromString(FILENAME), 5, QLatin1String("aaaaaaaa this line has 2 results for four a in a row"), 0, 4, QStringList()); - expectedResults << FileSearchResult(FilePath::fromString(FILENAME), 5, QLatin1String("aaaaaaaa this line has 2 results for four a in a row"), 4, 4, QStringList()); - test_helper(expectedResults, QLatin1String("aaaa"), QTextDocument::FindFlags()); + expectedResults << searchResult(m_filePath, + "aaaaaaaa this line has 2 results for four a in a row", + 5, 0, 4); + expectedResults << searchResult(m_filePath, + "aaaaaaaa this line has 2 results for four a in a row", + 5, 4, 4); + test_helper(m_filePath, expectedResults, "aaaa"); expectedResults.clear(); - expectedResults << FileSearchResult(FilePath::fromString(FILENAME), 5, QLatin1String("aaaaaaaa this line has 2 results for four a in a row"), 0, 4, QStringList() << QLatin1String("aaaa")); - expectedResults << FileSearchResult(FilePath::fromString(FILENAME), 5, QLatin1String("aaaaaaaa this line has 2 results for four a in a row"), 4, 4, QStringList() << QLatin1String("aaaa")); - test_helper(expectedResults, QLatin1String("aaaa"), QTextDocument::FindFlags(), RegExp); + expectedResults << searchResult(m_filePath, + "aaaaaaaa this line has 2 results for four a in a row", + 5, 0, 4, {"aaaa"}); + expectedResults << searchResult(m_filePath, + "aaaaaaaa this line has 2 results for four a in a row", + 5, 4, 4, {"aaaa"}); + test_helper(m_filePath, expectedResults, "aaaa", {}, RegExp); } void tst_FileSearch::caseSensitive() { - Utils::FileSearchResultList expectedResults; - expectedResults << FileSearchResult(FilePath::fromString(FILENAME), 3, QLatin1String("search CaseSensitively for casesensitive"), 7, 13, QStringList()); - test_helper(expectedResults, QLatin1String("CaseSensitive"), QTextDocument::FindCaseSensitively); + SearchResultItems expectedResults; + expectedResults << searchResult(m_filePath, "search CaseSensitively for casesensitive", + 3, 7, 13); + test_helper(m_filePath, expectedResults, "CaseSensitive", QTextDocument::FindCaseSensitively); } void tst_FileSearch::caseInSensitive() { - Utils::FileSearchResultList expectedResults; - expectedResults << FileSearchResult(FilePath::fromString(FILENAME), 3, QLatin1String("search CaseSensitively for casesensitive"), 7, 13, QStringList()); - expectedResults << FileSearchResult(FilePath::fromString(FILENAME), 3, QLatin1String("search CaseSensitively for casesensitive"), 27, 13, QStringList()); - test_helper(expectedResults, QLatin1String("CaseSensitive"), QTextDocument::FindFlags()); + SearchResultItems expectedResults; + expectedResults << searchResult(m_filePath, "search CaseSensitively for casesensitive", 3, 7, 13); + expectedResults << searchResult(m_filePath, "search CaseSensitively for casesensitive", 3, 27, 13); + test_helper(m_filePath, expectedResults, "CaseSensitive"); } void tst_FileSearch::matchCaseReplacement() diff --git a/tests/unit/unittest/CMakeLists.txt b/tests/unit/unittest/CMakeLists.txt index f220087daf..7522a8e180 100644 --- a/tests/unit/unittest/CMakeLists.txt +++ b/tests/unit/unittest/CMakeLists.txt @@ -38,7 +38,6 @@ add_qtc_test(unittest GTEST TEST_RELATIVE_LIBEXEC_PATH="${TEST_RELATIVE_LIBEXEC_PATH}" SOURCES abstractviewmock.h - compare-operators.h conditionally-disabled-tests.h dynamicastmatcherdiagnosticcontainer-matcher.h eventspy.cpp eventspy.h diff --git a/tests/unit/unittest/compare-operators.h b/tests/unit/unittest/compare-operators.h deleted file mode 100644 index 891fdfec03..0000000000 --- a/tests/unit/unittest/compare-operators.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#pragma once - -#include <utils/searchresultitem.h> - -namespace Utils { -namespace Search { - -inline -bool operator==(const TextPosition first, class TextPosition second) -{ - return first.line == second.line - && first.column == second.column; -} - -inline -bool operator==(const TextRange first, class TextRange second) -{ - return first.begin == second.begin - && first.end == second.end; -} -} -} diff --git a/tests/unit/unittest/googletest.h b/tests/unit/unittest/googletest.h index 72ece6a602..a3d3012a09 100644 --- a/tests/unit/unittest/googletest.h +++ b/tests/unit/unittest/googletest.h @@ -13,8 +13,6 @@ #include <gtest/gtest-printers.h> #include <gtest/gtest-typed-test.h> -#include "compare-operators.h" - #include "conditionally-disabled-tests.h" #include "gtest-creator-printing.h" #include "gtest-llvm-printing.h" |