MCPcopy Create free account
hub / github.com/KDE/kdevelop / testProjectFileFilter

Method testProjectFileFilter

plugins/quickopen/tests/test_quickopen.cpp:346–436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344}
345
346void TestQuickOpen::testProjectFileFilter()
347{
348 QTemporaryDir dir;
349 auto* project = new TestProject(Path(dir.path()));
350 auto* foo = createChild<ProjectFolderItem>(project->projectItem(), QStringLiteral("foo"));
351 createChild<ProjectFileItem>(foo, QStringLiteral("bar"));
352 createChild<ProjectFileItem>(foo, QStringLiteral("asdf"));
353 createChild<ProjectFileItem>(foo, QStringLiteral("space bar"));
354 auto* asdf = createChild<ProjectFolderItem>(project->projectItem(), QStringLiteral("asdf"));
355 createChild<ProjectFileItem>(asdf, QStringLiteral("bar"));
356
357 QTemporaryFile tmpFile;
358 tmpFile.setFileName(dir.path() + "/aaaa");
359 QVERIFY(tmpFile.open());
360 auto* aaaa = new ProjectFileItem(QStringLiteral("aaaa"), project->projectItem());
361 QCOMPARE(project->fileSet().size(), 5);
362
363 ProjectFileDataProvider provider;
364 QCOMPARE(provider.itemCount(), 0u);
365 projectController->addProject(project);
366
367 const QStringList original = QStringList()
368 << QStringLiteral("aaaa") << QStringLiteral("asdf/bar") << QStringLiteral("foo/asdf") << QStringLiteral("foo/bar") << QStringLiteral("foo/space bar");
369
370 // lazy load
371 QCOMPARE(provider.itemCount(), 0u);
372 provider.reset();
373 QCOMPARE(items(provider), original);
374
375 QCOMPARE(provider.itemPath(provider.items().first()), aaaa->path());
376 QCOMPARE(provider.data(0)->text(), QStringLiteral("aaaa"));
377
378 // don't show opened file
379 QVERIFY(core->documentController()->openDocument(QUrl::fromLocalFile(tmpFile.fileName())));
380 // lazy load again
381 QCOMPARE(items(provider), original);
382 provider.reset();
383 QCOMPARE(items(provider), QStringList() << QStringLiteral("asdf/bar") << QStringLiteral("foo/asdf") << QStringLiteral("foo/bar") << QStringLiteral("foo/space bar"));
384
385 // prefer files starting with filter
386 provider.setFilterText(QStringLiteral("as"));
387 qDebug() << items(provider);
388 QCOMPARE(items(provider), QStringList() << QStringLiteral("foo/asdf") << QStringLiteral("asdf/bar"));
389
390 // clear filter
391 provider.reset();
392 QCOMPARE(items(provider), QStringList() << QStringLiteral("asdf/bar") << QStringLiteral("foo/asdf") << QStringLiteral("foo/bar") << QStringLiteral("foo/space bar"));
393
394 // update on document close, lazy load again
395 core->documentController()->closeAllDocuments();
396 QCOMPARE(items(provider), QStringList() << QStringLiteral("asdf/bar") << QStringLiteral("foo/asdf") << QStringLiteral("foo/bar") << QStringLiteral("foo/space bar"));
397 provider.reset();
398 QCOMPARE(items(provider), original);
399
400 auto* blub = createChild<ProjectFileItem>(project->projectItem(), QStringLiteral("blub"));
401 // lazy load
402 QCOMPARE(provider.itemCount(), 5u);
403 provider.reset();

Callers

nothing calls this directly

Calls 15

QStringListClass · 0.85
itemsFunction · 0.85
documentControllerMethod · 0.80
closeAllDocumentsMethod · 0.80
PathClass · 0.50
pathMethod · 0.45
projectItemMethod · 0.45
openMethod · 0.45
sizeMethod · 0.45
fileSetMethod · 0.45
itemCountMethod · 0.45
addProjectMethod · 0.45

Tested by

no test coverage detected