Changeset View
Changeset View
Standalone View
Standalone View
autotests/kurlcompletiontest.cpp
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 40 | #endif | |||
---|---|---|---|---|---|
54 | void testUser(); | 54 | void testUser(); | ||
55 | void testCancel(); | 55 | void testCancel(); | ||
56 | 56 | | |||
57 | // remember to register new test methods in runAllTests | 57 | // remember to register new test methods in runAllTests | ||
58 | 58 | | |||
59 | private: | 59 | private: | ||
60 | void waitForCompletion(KUrlCompletion *completion); | 60 | void waitForCompletion(KUrlCompletion *completion); | ||
61 | KUrlCompletion *m_completion; | 61 | KUrlCompletion *m_completion; | ||
62 | KUrlCompletion *m_completionWithMimeFilter; | ||||
62 | QTemporaryDir *m_tempDir; | 63 | QTemporaryDir *m_tempDir; | ||
63 | QUrl m_dirURL; | 64 | QUrl m_dirURL; | ||
64 | QString m_dir; | 65 | QString m_dir; | ||
65 | KUrlCompletion *m_completionEmptyCwd; | 66 | KUrlCompletion *m_completionEmptyCwd; | ||
66 | }; | 67 | }; | ||
67 | 68 | | |||
68 | void KUrlCompletionTest::setup() | 69 | void KUrlCompletionTest::setup() | ||
69 | { | 70 | { | ||
70 | qDebug(); | 71 | qDebug(); | ||
71 | m_completion = new KUrlCompletion; | 72 | m_completion = new KUrlCompletion; | ||
73 | m_completionWithMimeFilter = new KUrlCompletion; | ||||
74 | m_completionWithMimeFilter->setMimeTypeFilters({QStringLiteral("text/x-c++src")}); | ||||
72 | m_tempDir = new QTemporaryDir; | 75 | m_tempDir = new QTemporaryDir; | ||
73 | m_dir = m_tempDir->path(); | 76 | m_dir = m_tempDir->path(); | ||
74 | m_dir += QLatin1String("/Dir With#Spaces/"); | 77 | m_dir += QLatin1String("/Dir With#Spaces/"); | ||
75 | QDir().mkdir(m_dir); | 78 | QDir().mkdir(m_dir); | ||
76 | qDebug() << "m_dir=" << m_dir; | 79 | qDebug() << "m_dir=" << m_dir; | ||
77 | m_completion->setDir(QUrl::fromLocalFile(m_dir)); | 80 | m_completion->setDir(QUrl::fromLocalFile(m_dir)); | ||
81 | m_completionWithMimeFilter->setDir(m_completion->dir()); | ||||
78 | m_dirURL = QUrl::fromLocalFile(m_dir); | 82 | m_dirURL = QUrl::fromLocalFile(m_dir); | ||
79 | 83 | | |||
80 | QFile f1(m_dir + "/file1"); | 84 | QFile f1(m_dir + "/file1"); | ||
81 | bool ok = f1.open(QIODevice::WriteOnly); | 85 | bool ok = f1.open(QIODevice::WriteOnly); | ||
82 | QVERIFY(ok); | 86 | QVERIFY(ok); | ||
83 | f1.close(); | 87 | f1.close(); | ||
84 | 88 | | |||
85 | QFile f2(m_dir + "/file#a"); | 89 | QFile f2(m_dir + "/file#a"); | ||
86 | ok = f2.open(QIODevice::WriteOnly); | 90 | ok = f2.open(QIODevice::WriteOnly); | ||
87 | QVERIFY(ok); | 91 | QVERIFY(ok); | ||
88 | f2.close(); | 92 | f2.close(); | ||
89 | 93 | | |||
90 | QFile f3(m_dir + "/file."); | 94 | QFile f3(m_dir + "/file."); | ||
91 | ok = f3.open(QIODevice::WriteOnly); | 95 | ok = f3.open(QIODevice::WriteOnly); | ||
92 | QVERIFY(ok); | 96 | QVERIFY(ok); | ||
93 | f3.close(); | 97 | f3.close(); | ||
94 | 98 | | |||
99 | QFile f4(m_dir + "/source.cpp"); | ||||
100 | ok = f4.open(QIODevice::WriteOnly); | ||||
101 | QVERIFY(ok); | ||||
102 | f4.close(); | ||||
103 | | ||||
104 | QFile f5(m_dir + "/source.php"); | ||||
105 | ok = f5.open(QIODevice::WriteOnly); | ||||
106 | QVERIFY(ok); | ||||
107 | f5.close(); | ||||
108 | | ||||
95 | QDir().mkdir(m_dir + "/file_subdir"); | 109 | QDir().mkdir(m_dir + "/file_subdir"); | ||
96 | QDir().mkdir(m_dir + "/.1_hidden_file_subdir"); | 110 | QDir().mkdir(m_dir + "/.1_hidden_file_subdir"); | ||
97 | QDir().mkdir(m_dir + "/.2_hidden_file_subdir"); | 111 | QDir().mkdir(m_dir + "/.2_hidden_file_subdir"); | ||
98 | 112 | | |||
99 | m_completionEmptyCwd = new KUrlCompletion; | 113 | m_completionEmptyCwd = new KUrlCompletion; | ||
100 | m_completionEmptyCwd->setDir(QUrl()); | 114 | m_completionEmptyCwd->setDir(QUrl()); | ||
101 | } | 115 | } | ||
102 | 116 | | |||
103 | void KUrlCompletionTest::teardown() | 117 | void KUrlCompletionTest::teardown() | ||
104 | { | 118 | { | ||
105 | delete m_completion; | 119 | delete m_completion; | ||
106 | m_completion = nullptr; | 120 | m_completion = nullptr; | ||
121 | delete m_completionWithMimeFilter; | ||||
122 | m_completionWithMimeFilter = nullptr; | ||||
107 | delete m_tempDir; | 123 | delete m_tempDir; | ||
108 | m_tempDir = nullptr; | 124 | m_tempDir = nullptr; | ||
109 | delete m_completionEmptyCwd; | 125 | delete m_completionEmptyCwd; | ||
110 | m_completionEmptyCwd = nullptr; | 126 | m_completionEmptyCwd = nullptr; | ||
111 | } | 127 | } | ||
112 | 128 | | |||
113 | void KUrlCompletionTest::waitForCompletion(KUrlCompletion *completion) | 129 | void KUrlCompletionTest::waitForCompletion(KUrlCompletion *completion) | ||
114 | { | 130 | { | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 183 | #endif | |||
174 | QVERIFY(compHiddenStartingWith2.contains(".2_hidden_file_subdir/")); | 190 | QVERIFY(compHiddenStartingWith2.contains(".2_hidden_file_subdir/")); | ||
175 | 191 | | |||
176 | // Completion with 'file.', should only find one file | 192 | // Completion with 'file.', should only find one file | ||
177 | m_completion->makeCompletion("file."); | 193 | m_completion->makeCompletion("file."); | ||
178 | waitForCompletion(m_completion); | 194 | waitForCompletion(m_completion); | ||
179 | const auto compFileEndingWithDot = m_completion->allMatches(); | 195 | const auto compFileEndingWithDot = m_completion->allMatches(); | ||
180 | QCOMPARE(compFileEndingWithDot.count(), 1); | 196 | QCOMPARE(compFileEndingWithDot.count(), 1); | ||
181 | QVERIFY(compFileEndingWithDot.contains("file.")); | 197 | QVERIFY(compFileEndingWithDot.contains("file.")); | ||
198 | | ||||
199 | // Completion with 'source' should only find the C++ file | ||||
200 | m_completionWithMimeFilter->makeCompletion("source"); | ||||
201 | waitForCompletion(m_completionWithMimeFilter); | ||||
202 | const auto compSourceFile = m_completionWithMimeFilter->allMatches(); | ||||
203 | QCOMPARE(compSourceFile.count(), 1); | ||||
204 | QVERIFY(compSourceFile.contains("source.cpp")); | ||||
205 | | ||||
206 | // But it should also be able to find folders | ||||
207 | m_completionWithMimeFilter->makeCompletion("file_subdir"); | ||||
208 | waitForCompletion(m_completionWithMimeFilter); | ||||
209 | const auto compMimeFolder = m_completionWithMimeFilter->allMatches(); | ||||
210 | QCOMPARE(compMimeFolder.count(), 1); | ||||
211 | QVERIFY(compMimeFolder.contains("file_subdir/")); | ||||
182 | } | 212 | } | ||
183 | 213 | | |||
184 | void KUrlCompletionTest::testLocalAbsolutePath() | 214 | void KUrlCompletionTest::testLocalAbsolutePath() | ||
185 | { | 215 | { | ||
186 | // Completion from absolute path | 216 | // Completion from absolute path | ||
187 | qDebug() << m_dir + "file#"; | 217 | qDebug() << m_dir + "file#"; | ||
188 | m_completion->makeCompletion(m_dir + "file#"); | 218 | m_completion->makeCompletion(m_dir + "file#"); | ||
189 | waitForCompletion(m_completion); | 219 | waitForCompletion(m_completion); | ||
Show All 23 Lines | 236 | #endif | |||
213 | QVERIFY(compHiddenStartingWith2.contains(m_dir + ".2_hidden_file_subdir/")); | 243 | QVERIFY(compHiddenStartingWith2.contains(m_dir + ".2_hidden_file_subdir/")); | ||
214 | 244 | | |||
215 | // Completion with 'file.', should only find one file | 245 | // Completion with 'file.', should only find one file | ||
216 | m_completion->makeCompletion(m_dir + "file."); | 246 | m_completion->makeCompletion(m_dir + "file."); | ||
217 | waitForCompletion(m_completion); | 247 | waitForCompletion(m_completion); | ||
218 | const auto compFileEndingWithDot = m_completion->allMatches(); | 248 | const auto compFileEndingWithDot = m_completion->allMatches(); | ||
219 | QCOMPARE(compFileEndingWithDot.count(), 1); | 249 | QCOMPARE(compFileEndingWithDot.count(), 1); | ||
220 | QVERIFY(compFileEndingWithDot.contains(m_dir + "file.")); | 250 | QVERIFY(compFileEndingWithDot.contains(m_dir + "file.")); | ||
251 | | ||||
252 | // Completion with 'source' should only find the C++ file | ||||
253 | m_completionWithMimeFilter->makeCompletion(m_dir + "source"); | ||||
254 | waitForCompletion(m_completionWithMimeFilter); | ||||
255 | const auto compSourceFile = m_completionWithMimeFilter->allMatches(); | ||||
256 | QCOMPARE(compSourceFile.count(), 1); | ||||
257 | QVERIFY(compSourceFile.contains(m_dir + "source.cpp")); | ||||
258 | | ||||
259 | // But it should also be able to find folders | ||||
260 | m_completionWithMimeFilter->makeCompletion(m_dir + "file_subdir"); | ||||
261 | waitForCompletion(m_completionWithMimeFilter); | ||||
262 | const auto compMimeFolder = m_completionWithMimeFilter->allMatches(); | ||||
263 | QCOMPARE(compMimeFolder.count(), 1); | ||||
264 | QVERIFY(compMimeFolder.contains(m_dir + "file_subdir/")); | ||||
221 | } | 265 | } | ||
222 | 266 | | |||
223 | void KUrlCompletionTest::testLocalURL() | 267 | void KUrlCompletionTest::testLocalURL() | ||
224 | { | 268 | { | ||
225 | // Completion from URL | 269 | // Completion from URL | ||
226 | qDebug(); | 270 | qDebug(); | ||
227 | QUrl url = QUrl::fromLocalFile(m_dirURL.toLocalFile() + "file"); | 271 | QUrl url = QUrl::fromLocalFile(m_dirURL.toLocalFile() + "file"); | ||
228 | m_completion->makeCompletion(url.toString()); | 272 | m_completion->makeCompletion(url.toString()); | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 314 | #endif | |||
281 | // Completion with 'file.', should only find one file | 325 | // Completion with 'file.', should only find one file | ||
282 | url = QUrl::fromLocalFile(m_dirURL.toLocalFile() + "file."); | 326 | url = QUrl::fromLocalFile(m_dirURL.toLocalFile() + "file."); | ||
283 | qDebug() << "makeCompletion(" << url << ")"; | 327 | qDebug() << "makeCompletion(" << url << ")"; | ||
284 | m_completion->makeCompletion(url.toString()); | 328 | m_completion->makeCompletion(url.toString()); | ||
285 | waitForCompletion(m_completion); | 329 | waitForCompletion(m_completion); | ||
286 | const auto compFileEndingWithDot = m_completion->allMatches(); | 330 | const auto compFileEndingWithDot = m_completion->allMatches(); | ||
287 | QCOMPARE(compFileEndingWithDot.count(), 1); | 331 | QCOMPARE(compFileEndingWithDot.count(), 1); | ||
288 | QVERIFY(compFileEndingWithDot.contains(m_dirURL.toString() + "file.")); | 332 | QVERIFY(compFileEndingWithDot.contains(m_dirURL.toString() + "file.")); | ||
333 | | ||||
334 | // Completion with 'source' should only find the C++ file | ||||
335 | m_completionWithMimeFilter->makeCompletion(m_dirURL.toString() + "source"); | ||||
336 | waitForCompletion(m_completionWithMimeFilter); | ||||
337 | const auto compSourceFile = m_completionWithMimeFilter->allMatches(); | ||||
338 | QCOMPARE(compSourceFile.count(), 1); | ||||
339 | QVERIFY(compSourceFile.contains(m_dirURL.toString() + "source.cpp")); | ||||
340 | | ||||
341 | // But it should also be able to find folders | ||||
342 | m_completionWithMimeFilter->makeCompletion(m_dirURL.toString() + "file_subdir"); | ||||
343 | waitForCompletion(m_completionWithMimeFilter); | ||||
344 | const auto compMimeFolder = m_completionWithMimeFilter->allMatches(); | ||||
345 | QCOMPARE(compMimeFolder.count(), 1); | ||||
346 | QVERIFY(compMimeFolder.contains(m_dirURL.toString() + "file_subdir/")); | ||||
289 | } | 347 | } | ||
290 | 348 | | |||
291 | void KUrlCompletionTest::testEmptyCwd() | 349 | void KUrlCompletionTest::testEmptyCwd() | ||
292 | { | 350 | { | ||
293 | qDebug(); | 351 | qDebug(); | ||
294 | // Completion with empty string (with a KUrlCompletion whose cwd is "") | 352 | // Completion with empty string (with a KUrlCompletion whose cwd is "") | ||
295 | qDebug() << endl << "now completing on '' with empty cwd"; | 353 | qDebug() << endl << "now completing on '' with empty cwd"; | ||
296 | m_completionEmptyCwd->makeCompletion(QLatin1String("")); | 354 | m_completionEmptyCwd->makeCompletion(QLatin1String("")); | ||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |