| 317 | } |
| 318 | |
| 319 | void TestProjectLoad::addDuringImport() |
| 320 | { |
| 321 | // our goal here is to try to reproduce an issue in the optimized filesForPath implementation |
| 322 | // which requires the project to be associated to the model to function properly |
| 323 | // to trigger this we create a big project, import it and then call filesForPath during |
| 324 | // the import action |
| 325 | TestProject p = makeProject(); |
| 326 | QDir dir(p.dir->path()); |
| 327 | QVERIFY(dir.mkpath(QStringLiteral("test/zzzzz"))); |
| 328 | for(int i = 0; i < 1000; ++i) { |
| 329 | createFile(QString(p.dir->path() + "/test/zzzzz/%1").arg(i)); |
| 330 | createFile(QString(p.dir->path() + "/test/%1").arg(i)); |
| 331 | } |
| 332 | |
| 333 | QSignalSpy spy(ICore::self()->projectController(), |
| 334 | SIGNAL(projectAboutToBeOpened(KDevelop::IProject*))); |
| 335 | ICore::self()->projectController()->openProject(p.file); |
| 336 | // not yet ready |
| 337 | QCOMPARE(ICore::self()->projectController()->projectCount(), 0); |
| 338 | // but about to be opened |
| 339 | QCOMPARE(spy.count(), 1); |
| 340 | auto* project = spy.value(0).at(0).value<IProject*>(); |
| 341 | QVERIFY(project); |
| 342 | QCOMPARE(project->path(), Path(KIO::upUrl(p.file))); |
| 343 | QUrl file = p.file.resolved(QUrl(QStringLiteral("test/zzzzz/999"))); |
| 344 | QVERIFY(QFile::exists(file.toLocalFile())); |
| 345 | // this most probably is not yet loaded |
| 346 | // and this should not crash |
| 347 | QCOMPARE(project->itemsForPath(IndexedString(file)).size(), 0); |
| 348 | // now delete that file and don't crash |
| 349 | QFile::remove(file.toLocalFile()); |
| 350 | // now create another file |
| 351 | QUrl file2 = file.adjusted(QUrl::RemoveFilename); |
| 352 | file2.setPath(file2.path() + "999v2"); |
| 353 | createFile(file2.toLocalFile()); |
| 354 | QVERIFY(!project->isReady()); |
| 355 | // now wait for finish |
| 356 | QTRY_VERIFY(project->isReady()); |
| 357 | // make sure our file removal + addition was properly tracked |
| 358 | QCOMPARE(project->filesForPath(IndexedString(file)).size(), 0); |
| 359 | QCOMPARE(project->filesForPath(IndexedString(file2)).size(), 1); |
| 360 | |
| 361 | //NOTE: this test is probably incomplete, I bet there are some race conditions left, |
| 362 | // esp. when adding a file at a point where the parent folder was already imported |
| 363 | // or removing a file that was already imported |
| 364 | } |
| 365 | |
| 366 | #include "moc_test_projectload.cpp" |
nothing calls this directly
no test coverage detected