Changeset View
Changeset View
Standalone View
Standalone View
src/tests/dolphinquerytest.cpp
Show All 35 Lines | 34 | private slots: | |||
---|---|---|---|---|---|
36 | void testBalooSearchParsing(); | 36 | void testBalooSearchParsing(); | ||
37 | }; | 37 | }; | ||
38 | 38 | | |||
39 | /** | 39 | /** | ||
40 | * Defines the parameters for the test cases in testBalooSearchParsing() | 40 | * Defines the parameters for the test cases in testBalooSearchParsing() | ||
41 | */ | 41 | */ | ||
42 | void DolphinSearchBoxTest::testBalooSearchParsing_data() | 42 | void DolphinSearchBoxTest::testBalooSearchParsing_data() | ||
43 | { | 43 | { | ||
44 | const QString text = QStringLiteral("xyz"); | 44 | const QString text = QStringLiteral("abc xyz"); | ||
45 | const QString filename = QStringLiteral("filename:\"xyz\""); | 45 | const QString filename = QStringLiteral("filename:\"%1\"").arg(text); | ||
46 | const QString rating = QStringLiteral("rating>=2"); | 46 | const QString rating = QStringLiteral("rating>=2"); | ||
47 | const QString modified = QString("modified>=2019-08-07"); | 47 | const QString modified = QString("modified>=2019-08-07"); | ||
48 | 48 | | |||
49 | QTest::addColumn<QString>("searchString"); | 49 | QTest::addColumn<QString>("searchString"); | ||
50 | QTest::addColumn<QString>("expectedText"); | 50 | QTest::addColumn<QString>("expectedText"); | ||
51 | QTest::addColumn<QStringList>("expectedTerms"); | 51 | QTest::addColumn<QStringList>("expectedTerms"); | ||
52 | QTest::addColumn<bool>("hasContent"); | ||||
53 | QTest::addColumn<bool>("hasFileName"); | ||||
52 | 54 | | |||
53 | // Test for "Content" | 55 | // Test for "Content" | ||
54 | QTest::newRow("content") << text << text << QStringList(); | 56 | QTest::newRow("content") << text << text << QStringList() << true << false; | ||
55 | QTest::newRow("content/empty") << "" << "" << QStringList(); | 57 | QTest::newRow("content/empty") << "" << "" << QStringList() << false << false; | ||
56 | QTest::newRow("content/singleQuote") << "\"" << "" << QStringList(); | 58 | QTest::newRow("content/singleQuote") << "\"" << "" << QStringList() << false << false; | ||
57 | QTest::newRow("content/doubleQuote") << "\"\"" << "" << QStringList(); | 59 | QTest::newRow("content/doubleQuote") << "\"\"" << "" << QStringList() << false << false; | ||
58 | // Test for empty `filename` | 60 | | ||
59 | QTest::newRow("filename") << filename << text << QStringList(); | 61 | // Test for "FileName" | ||
60 | QTest::newRow("filename/empty") << "filename:" << "" << QStringList(); | 62 | QTest::newRow("filename") << filename << text << QStringList() << false << true; | ||
61 | QTest::newRow("filename/singleQuote") << "filename:\"" << "" << QStringList(); | 63 | QTest::newRow("filename/empty") << "filename:" << "" << QStringList() << false << false; | ||
62 | QTest::newRow("filename/doubleQuote") << "filename:\"\"" << "" << QStringList(); | 64 | QTest::newRow("filename/singleQuote") << "filename:\"" << "" << QStringList() << false << false; | ||
65 | QTest::newRow("filename/doubleQuote") << "filename:\"\"" << "" << QStringList() << false << false; | ||||
63 | 66 | | |||
64 | // Test for rating | 67 | // Test for rating | ||
65 | QTest::newRow("rating") << rating << "" << QStringList({rating}); | 68 | QTest::newRow("rating") << rating << "" << QStringList({rating}) << false << false; | ||
66 | QTest::newRow("rating+content") << rating + " " + text << text << QStringList({rating}); | 69 | QTest::newRow("rating+content") << rating + " " + text << text << QStringList({rating}) << true << false; | ||
67 | QTest::newRow("rating+filename") << rating + " " + filename << text << QStringList({rating}); | 70 | QTest::newRow("rating+filename") << rating + " " + filename << text << QStringList({rating}) << false << true; | ||
71 | | ||||
68 | // Test for modified date | 72 | // Test for modified date | ||
69 | QTest::newRow("modified") << modified << "" << QStringList({modified}); | 73 | QTest::newRow("modified") << modified << "" << QStringList({modified}) << false << false; | ||
70 | QTest::newRow("modified+content") << modified + " " + text << text << QStringList({modified}); | 74 | QTest::newRow("modified+content") << modified + " " + text << text << QStringList({modified}) << true << false; | ||
71 | QTest::newRow("modified+filename") << modified + " " + filename << text << QStringList({modified}); | 75 | QTest::newRow("modified+filename") << modified + " " + filename << text << QStringList({modified}) << false << true; | ||
72 | // Combined tests | 76 | | ||
73 | QTest::newRow("rating+modified") << rating + " AND " + modified << "" << QStringList({modified, rating}); | 77 | // Combined search terms | ||
74 | QTest::newRow("rating+modified+content") << rating + " AND " + modified + " " + text << text << QStringList({modified, rating}); | 78 | QTest::newRow("rating+modified") << rating + " AND " + modified << "" << QStringList({modified, rating}) << false << false; | ||
75 | QTest::newRow("rating+modified+filename") << rating + " AND " + modified + " " + filename << text << QStringList({modified, rating}); | 79 | QTest::newRow("rating+modified+content") << rating + " AND " + modified + " " + text << text << QStringList({modified, rating}) << true << false; | ||
80 | QTest::newRow("rating+modified+filename") << rating + " AND " + modified + " " + filename << text << QStringList({modified, rating}) << false << true; | ||||
81 | | ||||
82 | // Combined content and filename search | ||||
83 | QTest::newRow("content+filename") << text + " " + filename << text + " " + filename << QStringList() << true << true; | ||||
84 | QTest::newRow("all_terms") << text + " " + filename + " " + rating + " AND " + modified << text + " " + filename << QStringList({modified, rating}) << true << true; | ||||
76 | } | 85 | } | ||
77 | 86 | | |||
78 | /** | 87 | /** | ||
79 | * Helper function to compose the baloo query URL used for searching | 88 | * Helper function to compose the baloo query URL used for searching | ||
80 | */ | 89 | */ | ||
81 | QUrl composeQueryUrl(const QString& searchString) | 90 | QUrl composeQueryUrl(const QString& searchString) | ||
82 | { | 91 | { | ||
83 | const QJsonObject jsonObject { | 92 | const QJsonObject jsonObject { | ||
Show All 18 Lines | |||||
102 | * properly handled by the searchbox, and only "user" or filename terms are added to the | 111 | * properly handled by the searchbox, and only "user" or filename terms are added to the | ||
103 | * text bar of the searchbox. | 112 | * text bar of the searchbox. | ||
104 | */ | 113 | */ | ||
105 | void DolphinSearchBoxTest::testBalooSearchParsing() | 114 | void DolphinSearchBoxTest::testBalooSearchParsing() | ||
106 | { | 115 | { | ||
107 | QFETCH(QString, searchString); | 116 | QFETCH(QString, searchString); | ||
108 | QFETCH(QString, expectedText); | 117 | QFETCH(QString, expectedText); | ||
109 | QFETCH(QStringList, expectedTerms); | 118 | QFETCH(QStringList, expectedTerms); | ||
119 | QFETCH(bool, hasContent); | ||||
120 | QFETCH(bool, hasFileName); | ||||
110 | 121 | | |||
111 | const QUrl testUrl = composeQueryUrl(searchString); | 122 | const QUrl testUrl = composeQueryUrl(searchString); | ||
112 | const DolphinQuery query = DolphinQuery::fromBalooSearchUrl(testUrl); | 123 | const DolphinQuery query = DolphinQuery::fromBalooSearchUrl(testUrl); | ||
113 | 124 | | |||
114 | QStringList searchTerms = query.searchTerms(); | 125 | QStringList searchTerms = query.searchTerms(); | ||
115 | searchTerms.sort(); | 126 | searchTerms.sort(); | ||
116 | 127 | | |||
117 | // Check for parsed text (would be displayed on the input search bar) | 128 | // Check for parsed text (would be displayed on the input search bar) | ||
118 | QCOMPARE(query.text(), expectedText); | 129 | QCOMPARE(query.text(), expectedText); | ||
119 | 130 | | |||
120 | // Check for parsed search terms (would be displayed by the facetsWidget) | 131 | // Check for parsed search terms (would be displayed by the facetsWidget) | ||
121 | QCOMPARE(searchTerms.count(), expectedTerms.count()); | 132 | QCOMPARE(searchTerms.count(), expectedTerms.count()); | ||
122 | for (int i = 0; i < expectedTerms.count(); i++) { | 133 | for (int i = 0; i < expectedTerms.count(); i++) { | ||
123 | QCOMPARE(searchTerms.at(i), expectedTerms.at(i)); | 134 | QCOMPARE(searchTerms.at(i), expectedTerms.at(i)); | ||
124 | } | 135 | } | ||
136 | | ||||
137 | // Check for filename and content detection | ||||
138 | QCOMPARE(query.hasContentSearch(), hasContent); | ||||
139 | QCOMPARE(query.hasFileName(), hasFileName); | ||||
125 | } | 140 | } | ||
126 | 141 | | |||
127 | QTEST_MAIN(DolphinSearchBoxTest) | 142 | QTEST_MAIN(DolphinSearchBoxTest) | ||
128 | 143 | | |||
129 | #include "dolphinquerytest.moc" | 144 | #include "dolphinquerytest.moc" |