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 | const QString tagA = QString("tag:tagA"); | 48 | const QString tagA = QString("tag:tagA"); | ||
49 | const QString tagB = QString("tag:tagB"); | 49 | const QString tagB = QString("tag:tagB"); | ||
50 | 50 | | |||
51 | QTest::addColumn<QString>("searchString"); | 51 | QTest::addColumn<QString>("searchString"); | ||
52 | QTest::addColumn<QString>("expectedText"); | 52 | QTest::addColumn<QString>("expectedText"); | ||
53 | QTest::addColumn<QStringList>("expectedTerms"); | 53 | QTest::addColumn<QStringList>("expectedTerms"); | ||
54 | QTest::addColumn<bool>("hasContent"); | ||||
55 | QTest::addColumn<bool>("hasFileName"); | ||||
54 | 56 | | |||
55 | // Test for "Content" | 57 | // Test for "Content" | ||
56 | QTest::newRow("content") << text << text << QStringList(); | 58 | QTest::newRow("content") << text << text << QStringList() << true << false; | ||
57 | QTest::newRow("content/empty") << "" << "" << QStringList(); | 59 | QTest::newRow("content/empty") << "" << "" << QStringList() << false << false; | ||
58 | QTest::newRow("content/singleQuote") << "\"" << "" << QStringList(); | 60 | QTest::newRow("content/singleQuote") << "\"" << "" << QStringList() << false << false; | ||
59 | QTest::newRow("content/doubleQuote") << "\"\"" << "" << QStringList(); | 61 | QTest::newRow("content/doubleQuote") << "\"\"" << "" << QStringList() << false << false; | ||
60 | 62 | | |||
61 | // Test for "Filename" | 63 | // Test for "FileName" | ||
62 | QTest::newRow("filename") << filename << text << QStringList(); | 64 | QTest::newRow("filename") << filename << text << QStringList() << false << true; | ||
63 | QTest::newRow("filename/empty") << "filename:" << "" << QStringList(); | 65 | QTest::newRow("filename/empty") << "filename:" << "" << QStringList() << false << false; | ||
64 | QTest::newRow("filename/singleQuote") << "filename:\"" << "" << QStringList(); | 66 | QTest::newRow("filename/singleQuote") << "filename:\"" << "" << QStringList() << false << false; | ||
65 | QTest::newRow("filename/doubleQuote") << "filename:\"\"" << "" << QStringList(); | 67 | QTest::newRow("filename/doubleQuote") << "filename:\"\"" << "" << QStringList() << false << false; | ||
68 | | ||||
69 | // Combined content and filename search | ||||
70 | QTest::newRow("content+filename") << text + " " + filename << text + " " + filename << QStringList() << true << true; | ||||
66 | 71 | | |||
67 | // Test for rating | 72 | // Test for rating | ||
68 | QTest::newRow("rating") << rating << "" << QStringList({rating}); | 73 | QTest::newRow("rating") << rating << "" << QStringList({rating}) << false << false; | ||
69 | QTest::newRow("rating+content") << rating + " " + text << text << QStringList({rating}); | 74 | QTest::newRow("rating+content") << rating + " " + text << text << QStringList({rating}) << true << false; | ||
70 | QTest::newRow("rating+filename") << rating + " " + filename << text << QStringList({rating}); | 75 | QTest::newRow("rating+filename") << rating + " " + filename << text << QStringList({rating}) << false << true; | ||
71 | 76 | | |||
72 | // Test for modified date | 77 | // Test for modified date | ||
73 | QTest::newRow("modified") << modified << "" << QStringList({modified}); | 78 | QTest::newRow("modified") << modified << "" << QStringList({modified}) << false << false; | ||
74 | QTest::newRow("modified+content") << modified + " " + text << text << QStringList({modified}); | 79 | QTest::newRow("modified+content") << modified + " " + text << text << QStringList({modified}) << true << false; | ||
75 | QTest::newRow("modified+filename") << modified + " " + filename << text << QStringList({modified}); | 80 | QTest::newRow("modified+filename") << modified + " " + filename << text << QStringList({modified}) << false << true; | ||
76 | 81 | | |||
77 | // Test for tags | 82 | // Test for tags | ||
78 | QTest::newRow("tag") << tagA << "" << QStringList({tagA}); | 83 | QTest::newRow("tag") << tagA << "" << QStringList({tagA}) << false << false; | ||
79 | QTest::newRow("tag/double") << tagA + " " + tagB << "" << QStringList({tagA, tagB}); | 84 | QTest::newRow("tag/double") << tagA + " " + tagB << "" << QStringList({tagA, tagB}) << false << false; | ||
80 | QTest::newRow("tag+content") << tagA + " " + text << text << QStringList({tagA}); | 85 | QTest::newRow("tag+content") << tagA + " " + text << text << QStringList({tagA}) << true << false; | ||
81 | QTest::newRow("tag+filename") << tagA + " " + filename << text << QStringList({tagA}); | 86 | QTest::newRow("tag+filename") << tagA + " " + filename << text << QStringList({tagA}) << false << true; | ||
82 | | ||||
83 | // Combined tests | | |||
84 | QTest::newRow("rating+modified") | | |||
85 | << rating + " AND " + modified | | |||
86 | << "" << QStringList({modified, rating}); | | |||
87 | 87 | | |||
88 | // Combined search terms | ||||
88 | QTest::newRow("allTerms") | 89 | QTest::newRow("allTerms") | ||
89 | << rating + " AND " + modified + " AND " + tagA + " AND " + tagB | 90 | << rating + " AND " + modified + " AND " + tagA + " AND " + tagB | ||
90 | << "" << QStringList({modified, rating, tagA, tagB}); | 91 | << "" << QStringList({modified, rating, tagA, tagB}) << false << false; | ||
91 | 92 | | |||
92 | QTest::newRow("allTerms+content") | 93 | QTest::newRow("allTerms+content") | ||
93 | << rating + " AND " + modified + " " + text + " " + tagA + " AND " + tagB | 94 | << rating + " AND " + modified + " " + text + " " + tagA + " AND " + tagB | ||
94 | << text << QStringList({modified, rating, tagA, tagB}); | 95 | << text << QStringList({modified, rating, tagA, tagB}) << true << false; | ||
95 | 96 | | |||
96 | QTest::newRow("allTerms+filename") | 97 | QTest::newRow("allTerms+filename") | ||
97 | << rating + " AND " + modified + " " + filename + " " + tagA + " AND " + tagB | 98 | << rating + " AND " + modified + " " + filename + " " + tagA + " AND " + tagB | ||
98 | << text << QStringList({modified, rating, tagA, tagB}); | 99 | << text << QStringList({modified, rating, tagA, tagB}) << false << true; | ||
100 | | ||||
101 | QTest::newRow("allTerms+content+filename") | ||||
102 | << text + " " + filename + " " + rating + " AND " + modified + " AND " + tagA + " AND " + tagB | ||||
103 | << text + " " + filename << QStringList({modified, rating, tagA, tagB}) << true << true; | ||||
99 | } | 104 | } | ||
100 | 105 | | |||
101 | /** | 106 | /** | ||
102 | * Helper function to compose the baloo query URL used for searching | 107 | * Helper function to compose the baloo query URL used for searching | ||
103 | */ | 108 | */ | ||
104 | QUrl composeQueryUrl(const QString& searchString) | 109 | QUrl composeQueryUrl(const QString& searchString) | ||
105 | { | 110 | { | ||
106 | const QJsonObject jsonObject { | 111 | const QJsonObject jsonObject { | ||
Show All 18 Lines | |||||
125 | * properly handled by the searchbox, and only "user" or filename terms are added to the | 130 | * properly handled by the searchbox, and only "user" or filename terms are added to the | ||
126 | * text bar of the searchbox. | 131 | * text bar of the searchbox. | ||
127 | */ | 132 | */ | ||
128 | void DolphinSearchBoxTest::testBalooSearchParsing() | 133 | void DolphinSearchBoxTest::testBalooSearchParsing() | ||
129 | { | 134 | { | ||
130 | QFETCH(QString, searchString); | 135 | QFETCH(QString, searchString); | ||
131 | QFETCH(QString, expectedText); | 136 | QFETCH(QString, expectedText); | ||
132 | QFETCH(QStringList, expectedTerms); | 137 | QFETCH(QStringList, expectedTerms); | ||
138 | QFETCH(bool, hasContent); | ||||
139 | QFETCH(bool, hasFileName); | ||||
133 | 140 | | |||
134 | const QUrl testUrl = composeQueryUrl(searchString); | 141 | const QUrl testUrl = composeQueryUrl(searchString); | ||
135 | const DolphinQuery query = DolphinQuery::fromBalooSearchUrl(testUrl); | 142 | const DolphinQuery query = DolphinQuery::fromBalooSearchUrl(testUrl); | ||
136 | 143 | | |||
137 | QStringList searchTerms = query.searchTerms(); | 144 | QStringList searchTerms = query.searchTerms(); | ||
138 | searchTerms.sort(); | 145 | searchTerms.sort(); | ||
139 | 146 | | |||
140 | // Check for parsed text (would be displayed on the input search bar) | 147 | // Check for parsed text (would be displayed on the input search bar) | ||
141 | QCOMPARE(query.text(), expectedText); | 148 | QCOMPARE(query.text(), expectedText); | ||
142 | 149 | | |||
143 | // Check for parsed search terms (would be displayed by the facetsWidget) | 150 | // Check for parsed search terms (would be displayed by the facetsWidget) | ||
144 | QCOMPARE(searchTerms.count(), expectedTerms.count()); | 151 | QCOMPARE(searchTerms.count(), expectedTerms.count()); | ||
145 | for (int i = 0; i < expectedTerms.count(); i++) { | 152 | for (int i = 0; i < expectedTerms.count(); i++) { | ||
146 | QCOMPARE(searchTerms.at(i), expectedTerms.at(i)); | 153 | QCOMPARE(searchTerms.at(i), expectedTerms.at(i)); | ||
147 | } | 154 | } | ||
155 | | ||||
156 | // Check for filename and content detection | ||||
157 | QCOMPARE(query.hasContentSearch(), hasContent); | ||||
158 | QCOMPARE(query.hasFileName(), hasFileName); | ||||
148 | } | 159 | } | ||
149 | 160 | | |||
150 | QTEST_MAIN(DolphinSearchBoxTest) | 161 | QTEST_MAIN(DolphinSearchBoxTest) | ||
151 | 162 | | |||
152 | #include "dolphinquerytest.moc" | 163 | #include "dolphinquerytest.moc" |