| 344 | } |
| 345 | |
| 346 | void 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(); |
nothing calls this directly
no test coverage detected