┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorIsmael Asensio <[email protected]>2019-12-21 19:14:17 +0100
committerIsmael Asensio <[email protected]>2019-12-21 19:17:18 +0100
commit616d4e6bdd707ac819707263255809df576a8c2b (patch)
tree832f183210281c002423d7cac2ea1d649824ddac /src/tests
parent8c386bdb4733fc12c5e8f411d59c79f97e412f9e (diff)
fix(search): Correctly parse filename and/or content search
Summary: Currently, the search url parsing does not detect if the search is based on Content or Filename, and it just keeps the last selection which can be inconsistent with the actual search. This patch add such detection, and since an advanced user can combine filename and content search (using the keyword `filename:`), now the parsing detects both items and handles the four possible cases: | Content | Filename | Search text | Search type | |---|---|------------------------|------------------| | T | T | abc filename:"xyz" | Content | | T | F | abc | Content | | F | T | xyz | Filename | | F | F | | do not set | Depends on: D25260 Test Plan: `bin/dolphinquerytest`: Added new test cases for searches with content text and/or filename Reviewers: elvisangelaccio, bruns, #dolphin Reviewed By: elvisangelaccio, #dolphin Subscribers: kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D25416
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/dolphinquerytest.cpp71
1 files changed, 41 insertions, 30 deletions
diff --git a/src/tests/dolphinquerytest.cpp b/src/tests/dolphinquerytest.cpp
index e3c6fb8e3..65dc7350e 100644
--- a/src/tests/dolphinquerytest.cpp
+++ b/src/tests/dolphinquerytest.cpp
@@ -41,8 +41,8 @@ private slots:
*/
void DolphinSearchBoxTest::testBalooSearchParsing_data()
{
- const QString text = QStringLiteral("xyz");
- const QString filename = QStringLiteral("filename:\"xyz\"");
+ const QString text = QStringLiteral("abc xyz");
+ const QString filename = QStringLiteral("filename:\"%1\"").arg(text);
const QString rating = QStringLiteral("rating>=2");
const QString modified = QString("modified>=2019-08-07");
const QString tagA = QString("tag:tagA");
@@ -51,51 +51,56 @@ void DolphinSearchBoxTest::testBalooSearchParsing_data()
QTest::addColumn<QString>("searchString");
QTest::addColumn<QString>("expectedText");
QTest::addColumn<QStringList>("expectedTerms");
+ QTest::addColumn<bool>("hasContent");
+ QTest::addColumn<bool>("hasFileName");
// Test for "Content"
- QTest::newRow("content") << text << text << QStringList();
- QTest::newRow("content/empty") << "" << "" << QStringList();
- QTest::newRow("content/singleQuote") << "\"" << "" << QStringList();
- QTest::newRow("content/doubleQuote") << "\"\"" << "" << QStringList();
+ QTest::newRow("content") << text << text << QStringList() << true << false;
+ QTest::newRow("content/empty") << "" << "" << QStringList() << false << false;
+ QTest::newRow("content/singleQuote") << "\"" << "" << QStringList() << false << false;
+ QTest::newRow("content/doubleQuote") << "\"\"" << "" << QStringList() << false << false;
- // Test for "Filename"
- QTest::newRow("filename") << filename << text << QStringList();
- QTest::newRow("filename/empty") << "filename:" << "" << QStringList();
- QTest::newRow("filename/singleQuote") << "filename:\"" << "" << QStringList();
- QTest::newRow("filename/doubleQuote") << "filename:\"\"" << "" << QStringList();
+ // Test for "FileName"
+ QTest::newRow("filename") << filename << text << QStringList() << false << true;
+ QTest::newRow("filename/empty") << "filename:" << "" << QStringList() << false << false;
+ QTest::newRow("filename/singleQuote") << "filename:\"" << "" << QStringList() << false << false;
+ QTest::newRow("filename/doubleQuote") << "filename:\"\"" << "" << QStringList() << false << false;
+
+ // Combined content and filename search
+ QTest::newRow("content+filename") << text + " " + filename << text + " " + filename << QStringList() << true << true;
// Test for rating
- QTest::newRow("rating") << rating << "" << QStringList({rating});
- QTest::newRow("rating+content") << rating + " " + text << text << QStringList({rating});
- QTest::newRow("rating+filename") << rating + " " + filename << text << QStringList({rating});
+ QTest::newRow("rating") << rating << "" << QStringList({rating}) << false << false;
+ QTest::newRow("rating+content") << rating + " " + text << text << QStringList({rating}) << true << false;
+ QTest::newRow("rating+filename") << rating + " " + filename << text << QStringList({rating}) << false << true;
// Test for modified date
- QTest::newRow("modified") << modified << "" << QStringList({modified});
- QTest::newRow("modified+content") << modified + " " + text << text << QStringList({modified});
- QTest::newRow("modified+filename") << modified + " " + filename << text << QStringList({modified});
+ QTest::newRow("modified") << modified << "" << QStringList({modified}) << false << false;
+ QTest::newRow("modified+content") << modified + " " + text << text << QStringList({modified}) << true << false;
+ QTest::newRow("modified+filename") << modified + " " + filename << text << QStringList({modified}) << false << true;
// Test for tags
- QTest::newRow("tag") << tagA << "" << QStringList({tagA});
- QTest::newRow("tag/double") << tagA + " " + tagB << "" << QStringList({tagA, tagB});
- QTest::newRow("tag+content") << tagA + " " + text << text << QStringList({tagA});
- QTest::newRow("tag+filename") << tagA + " " + filename << text << QStringList({tagA});
-
- // Combined tests
- QTest::newRow("rating+modified")
- << rating + " AND " + modified
- << "" << QStringList({modified, rating});
+ QTest::newRow("tag") << tagA << "" << QStringList({tagA}) << false << false;
+ QTest::newRow("tag/double") << tagA + " " + tagB << "" << QStringList({tagA, tagB}) << false << false;
+ QTest::newRow("tag+content") << tagA + " " + text << text << QStringList({tagA}) << true << false;
+ QTest::newRow("tag+filename") << tagA + " " + filename << text << QStringList({tagA}) << false << true;
+ // Combined search terms
QTest::newRow("allTerms")
<< rating + " AND " + modified + " AND " + tagA + " AND " + tagB
- << "" << QStringList({modified, rating, tagA, tagB});
+ << "" << QStringList({modified, rating, tagA, tagB}) << false << false;
QTest::newRow("allTerms+content")
<< rating + " AND " + modified + " " + text + " " + tagA + " AND " + tagB
- << text << QStringList({modified, rating, tagA, tagB});
-
+ << text << QStringList({modified, rating, tagA, tagB}) << true << false;
+
QTest::newRow("allTerms+filename")
<< rating + " AND " + modified + " " + filename + " " + tagA + " AND " + tagB
- << text << QStringList({modified, rating, tagA, tagB});
+ << text << QStringList({modified, rating, tagA, tagB}) << false << true;
+
+ QTest::newRow("allTerms+content+filename")
+ << text + " " + filename + " " + rating + " AND " + modified + " AND " + tagA + " AND " + tagB
+ << text + " " + filename << QStringList({modified, rating, tagA, tagB}) << true << true;
}
/**
@@ -130,6 +135,8 @@ void DolphinSearchBoxTest::testBalooSearchParsing()
QFETCH(QString, searchString);
QFETCH(QString, expectedText);
QFETCH(QStringList, expectedTerms);
+ QFETCH(bool, hasContent);
+ QFETCH(bool, hasFileName);
const QUrl testUrl = composeQueryUrl(searchString);
const DolphinQuery query = DolphinQuery::fromBalooSearchUrl(testUrl);
@@ -145,6 +152,10 @@ void DolphinSearchBoxTest::testBalooSearchParsing()
for (int i = 0; i < expectedTerms.count(); i++) {
QCOMPARE(searchTerms.at(i), expectedTerms.at(i));
}
+
+ // Check for filename and content detection
+ QCOMPARE(query.hasContentSearch(), hasContent);
+ QCOMPARE(query.hasFileName(), hasFileName);
}
QTEST_MAIN(DolphinSearchBoxTest)