File indexing completed on 2024-05-12 04:38:11

0001 /*
0002     SPDX-FileCopyrightText: 2010 Andreas Pakulat <apaku@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "test_projectmodel.h"
0008 
0009 #include <QTest>
0010 #include <QSortFilterProxyModel>
0011 #include <QDir>
0012 #include <QMimeType>
0013 #include <QMimeDatabase>
0014 #include <QSignalSpy>
0015 #include <QAbstractItemModelTester>
0016 
0017 #include <projectmodel.h>
0018 #include <projectproxymodel.h>
0019 #include <tests/testproject.h>
0020 #include <tests/kdevsignalspy.h>
0021 #include <tests/autotestshell.h>
0022 #include <tests/testcore.h>
0023 #include <util/path.h>
0024 
0025 using namespace KDevelop;
0026 
0027 void debugItemModel(QAbstractItemModel* m, const QModelIndex& parent=QModelIndex(), int depth=0)
0028 {
0029     Q_ASSERT(m);
0030     qDebug() << QByteArray(depth*2, '-') << m->data(parent).toString();
0031     for(int i=0; i<m->rowCount(parent); i++) {
0032         debugItemModel(m, m->index(i, 0, parent), depth+1);
0033     }
0034 }
0035 
0036 void TestProjectModel::initTestCase()
0037 {
0038     AutoTestShell::init();
0039     TestCore::initialize(Core::NoUi);
0040 
0041     qRegisterMetaType<QModelIndex>("QModelIndex");
0042     model = ICore::self()->projectController()->projectModel();
0043     new QAbstractItemModelTester( model, this );
0044     proxy = new ProjectProxyModel( model );
0045     new QAbstractItemModelTester(proxy, proxy);
0046     proxy->setSourceModel(model);
0047 }
0048 
0049 void TestProjectModel::init()
0050 {
0051     model->clear();
0052 }
0053 
0054 void TestProjectModel::cleanupTestCase()
0055 {
0056     TestCore::shutdown();
0057 }
0058 
0059 void TestProjectModel::testCreateFileSystemItems()
0060 {
0061     QFETCH( int, itemType );
0062     QFETCH( Path, itemPath );
0063     QFETCH( Path, expectedItemPath );
0064     QFETCH( QString, expectedItemText );
0065     QFETCH( QStringList, expectedRelativeItemPath );
0066     QFETCH( int, expectedItemRow );
0067 
0068     ProjectBaseItem* newitem = nullptr;
0069     switch( itemType ) {
0070         case ProjectBaseItem::Folder:
0071             newitem = new ProjectFolderItem( nullptr, itemPath );
0072             break;
0073         case ProjectBaseItem::BuildFolder:
0074             newitem = new ProjectBuildFolderItem( nullptr, itemPath );
0075             break;
0076         case ProjectBaseItem::File:
0077             newitem = new ProjectFileItem( nullptr, itemPath );
0078             break;
0079     }
0080     int origRowCount = model->rowCount();
0081     model->appendRow( newitem );
0082     QCOMPARE( model->rowCount(), origRowCount+1 );
0083     QCOMPARE( newitem->row(), expectedItemRow );
0084     QModelIndex idx = model->index( expectedItemRow, 0, QModelIndex() );
0085     QVERIFY( model->itemFromIndex( idx ) );
0086     QCOMPARE( model->itemFromIndex( idx ), newitem );
0087     QCOMPARE( newitem->text(), expectedItemText );
0088     QCOMPARE( newitem->path(), expectedItemPath );
0089     if( itemType == ProjectBaseItem::File ) {
0090         QCOMPARE( dynamic_cast<ProjectFileItem*>( newitem )->fileName(), expectedItemText );
0091     }
0092     if( itemType == ProjectBaseItem::Folder || itemType == ProjectBaseItem::BuildFolder ) {
0093         QCOMPARE( dynamic_cast<ProjectFolderItem*>( newitem )->folderName(), expectedItemText );
0094     }
0095     QCOMPARE( newitem->type(), itemType );
0096     QCOMPARE( model->data( idx ).toString(), expectedItemText );
0097     QCOMPARE( model->indexFromItem( newitem ), idx );
0098     QCOMPARE( model->pathFromIndex( idx ), expectedRelativeItemPath );
0099     QCOMPARE( model->pathToIndex( expectedRelativeItemPath ), idx );
0100 }
0101 
0102 void TestProjectModel::testCreateFileSystemItems_data()
0103 {
0104     QString testRootDir = QDir::rootPath() + QStringLiteral("rootdir");
0105     QString testRootFile = QDir::rootPath() + QStringLiteral("rootfile");
0106     QTest::addColumn<int>( "itemType" );
0107     QTest::addColumn<Path>( "itemPath" );
0108     QTest::addColumn<Path>( "expectedItemPath" );
0109     QTest::addColumn<QString>( "expectedItemText" );
0110     QTest::addColumn<QStringList>( "expectedRelativeItemPath" );
0111     QTest::addColumn<int>( "expectedItemRow" );
0112 
0113     QTest::newRow("RootFolder")
0114         << (int)ProjectBaseItem::Folder
0115         << Path(QUrl::fromLocalFile(testRootDir))
0116         << Path(QUrl::fromLocalFile(testRootDir))
0117         << QStringLiteral("rootdir")
0118         << ( QStringList() << QStringLiteral("rootdir") )
0119         << 0;
0120 
0121     QTest::newRow("RootBuildFolder")
0122         << (int)ProjectBaseItem::BuildFolder
0123         << Path(QUrl::fromLocalFile(testRootDir))
0124         << Path(QUrl::fromLocalFile(testRootDir))
0125         << QStringLiteral("rootdir")
0126         << ( QStringList() << QStringLiteral("rootdir") )
0127         << 0;
0128 
0129     QTest::newRow("RootFile")
0130         << (int)ProjectBaseItem::File
0131         << Path(QUrl::fromLocalFile(testRootFile))
0132         << Path(QUrl::fromLocalFile(testRootFile))
0133         << QStringLiteral("rootfile")
0134         << ( QStringList() << QStringLiteral("rootfile") )
0135         << 0;
0136 
0137 }
0138 
0139 void TestProjectModel::testCreateTargetItems()
0140 {
0141     QFETCH( int, itemType );
0142     QFETCH( QString, itemText );
0143     QFETCH( QString, expectedItemText );
0144     QFETCH( QStringList, expectedItemPath );
0145     QFETCH( int, expectedItemRow );
0146 
0147     ProjectBaseItem* newitem = nullptr;
0148     switch( itemType ) {
0149         case ProjectBaseItem::Target:
0150             newitem = new ProjectTargetItem( nullptr, itemText );
0151             break;
0152         case ProjectBaseItem::LibraryTarget:
0153             newitem = new ProjectLibraryTargetItem( nullptr, itemText );
0154             break;
0155     }
0156     int origRowCount = model->rowCount();
0157     model->appendRow( newitem );
0158     QCOMPARE( model->rowCount(), origRowCount+1 );
0159     QCOMPARE( newitem->row(), expectedItemRow );
0160     QModelIndex idx = model->index( expectedItemRow, 0, QModelIndex() );
0161     QVERIFY( model->itemFromIndex( idx ) );
0162     QCOMPARE( model->itemFromIndex( idx ), newitem );
0163     QCOMPARE( newitem->text(), expectedItemText );
0164     QCOMPARE( newitem->type(), itemType );
0165     QCOMPARE( model->data( idx ).toString(), expectedItemText );
0166     QCOMPARE( model->indexFromItem( newitem ), idx );
0167     QCOMPARE( model->pathFromIndex( idx ), expectedItemPath );
0168     QCOMPARE( model->pathToIndex( expectedItemPath ), idx );
0169 }
0170 
0171 void TestProjectModel::testCreateTargetItems_data()
0172 {
0173     QTest::addColumn<int>( "itemType" );
0174     QTest::addColumn<QString>( "itemText" );
0175     QTest::addColumn<QString>( "expectedItemText" );
0176     QTest::addColumn<QStringList>( "expectedItemPath" );
0177     QTest::addColumn<int>( "expectedItemRow" );
0178 
0179     QTest::newRow("RootTarget")
0180         << (int)ProjectBaseItem::Target
0181         << "target"
0182         << QStringLiteral("target")
0183         << ( QStringList() << QStringLiteral("target") )
0184         << 0;
0185 
0186     QTest::newRow("RootLibraryTarget")
0187         << (int)ProjectBaseItem::LibraryTarget
0188         << "libtarget"
0189         << QStringLiteral("libtarget")
0190         << ( QStringList() << QStringLiteral("libtarget") )
0191         << 0;
0192 }
0193 
0194 void TestProjectModel::testChangeWithProxyModel()
0195 {
0196     QString projectFolderPath = QDir::rootPath() + QStringLiteral("folder1");
0197     QString projectFilePath = QDir::rootPath() + QStringLiteral("folder1/file1");
0198     auto* proxy = new QSortFilterProxyModel( this );
0199     proxy->setSourceModel( model );
0200     auto* root = new ProjectFolderItem( nullptr, Path(QUrl::fromLocalFile(projectFolderPath)) );
0201     root->appendRow( new ProjectFileItem( nullptr, Path(QUrl::fromLocalFile(projectFilePath)) ) );
0202     model->appendRow( root );
0203 
0204     QCOMPARE( model->rowCount(), 1 );
0205     QCOMPARE( proxy->rowCount(), 1 );
0206 
0207     model->removeRow( 0 );
0208 
0209     QCOMPARE( model->rowCount(), 0 );
0210     QCOMPARE( proxy->rowCount(), 0 );
0211 }
0212 
0213 void TestProjectModel::testCreateSimpleHierarchy()
0214 {
0215     QString folderName = QStringLiteral("rootfolder");
0216     QString fileName = QStringLiteral("file");
0217     QString targetName = QStringLiteral("testtarged");
0218     QString cppFileName = QStringLiteral("file.cpp");
0219     auto* rootFolder = new ProjectFolderItem( nullptr, Path(QUrl::fromLocalFile( QDir::rootPath() + folderName )) );
0220     QCOMPARE(rootFolder->baseName(), folderName);
0221     auto* file = new ProjectFileItem( fileName, rootFolder );
0222     QCOMPARE(file->baseName(), fileName);
0223     auto* target = new ProjectTargetItem( nullptr, targetName );
0224     rootFolder->appendRow( target );
0225     auto* targetfile = new ProjectFileItem( nullptr, Path(rootFolder->path(), cppFileName), target );
0226 
0227     model->appendRow( rootFolder );
0228 
0229     QCOMPARE( model->rowCount(), 1 );
0230     QModelIndex folderIdx = model->index( 0, 0, QModelIndex() );
0231     QCOMPARE( model->data( folderIdx ).toString(), folderName );
0232     QCOMPARE( model->rowCount( folderIdx ), 2 );
0233     QCOMPARE( model->itemFromIndex( folderIdx ), rootFolder );
0234     QVERIFY( rootFolder->hasFileOrFolder( fileName ) );
0235 
0236     QModelIndex fileIdx = model->index( 0, 0, folderIdx );
0237     QCOMPARE( model->data( fileIdx ).toString(), fileName );
0238     QCOMPARE( model->rowCount( fileIdx ), 0 );
0239     QCOMPARE( model->itemFromIndex( fileIdx ), file );
0240 
0241     QModelIndex targetIdx = model->index( 1, 0, folderIdx );
0242     QCOMPARE( model->data( targetIdx ).toString(), targetName );
0243     QCOMPARE( model->rowCount( targetIdx ), 1 );
0244     QCOMPARE( model->itemFromIndex( targetIdx ), target );
0245 
0246     QModelIndex targetFileIdx = model->index( 0, 0, targetIdx );
0247     QCOMPARE( model->data( targetFileIdx ).toString(), cppFileName );
0248     QCOMPARE( model->rowCount( targetFileIdx ), 0 );
0249     QCOMPARE( model->itemFromIndex( targetFileIdx ), targetfile );
0250 
0251     rootFolder->removeRow( 1 );
0252     QCOMPARE( model->rowCount( folderIdx ), 1 );
0253     delete file;
0254     file = nullptr;
0255 
0256     // Check that we also find a folder with the fileName
0257     new ProjectFolderItem( fileName, rootFolder );
0258     QVERIFY( rootFolder->hasFileOrFolder( fileName ) );
0259 
0260     delete rootFolder;
0261     QCOMPARE( model->rowCount(), 0 );
0262 }
0263 
0264 void TestProjectModel::testItemSanity()
0265 {
0266 #ifdef Q_OS_WIN
0267     QString child3Path = QStringLiteral("file:///c:/bcd");
0268     QString child4Path = QStringLiteral("file:///c:/abcd");
0269 #else
0270     QString child3Path = QStringLiteral("file:///bcd");
0271     QString child4Path = QStringLiteral("file:///abcd");
0272 #endif
0273     QString newtestPath = QDir::rootPath() + QStringLiteral("newtest");
0274     auto* parent = new ProjectBaseItem(nullptr, QStringLiteral("test"));
0275     auto* child = new ProjectBaseItem( nullptr, QStringLiteral("test"), parent );
0276     auto* child2 = new ProjectBaseItem(nullptr, QStringLiteral("ztest"), parent);
0277     auto* child3 = new ProjectFileItem(nullptr, Path(QUrl(child3Path)), parent);
0278     auto* child4 = new ProjectFileItem(nullptr, Path(QUrl(child4Path)), parent);
0279 
0280     // Just some basic santiy checks on the API
0281     QCOMPARE( parent->child( 0 ), child );
0282     QCOMPARE( parent->row(), -1 );
0283     QVERIFY( !parent->child( -1 ) );
0284     QVERIFY( !parent->file() );
0285     QVERIFY( !parent->folder() );
0286     QVERIFY( !parent->project() );
0287     QVERIFY( !parent->child( parent->rowCount() ) );
0288     QCOMPARE( parent->iconName(), QString() );
0289     QCOMPARE( parent->index(), QModelIndex() );
0290 
0291     QCOMPARE( child->type(), (int)ProjectBaseItem::BaseItem );
0292 
0293     QCOMPARE( child->lessThan( child2 ), true );
0294     QCOMPARE( child3->lessThan( child4 ), false );
0295 
0296     // Check that model is properly emitting data-changes
0297     model->appendRow( parent );
0298     QCOMPARE( parent->index(), model->index(0, 0, QModelIndex()) );
0299     QSignalSpy s( model, SIGNAL(dataChanged(QModelIndex,QModelIndex)) );
0300     parent->setPath( Path(newtestPath) );
0301     QCOMPARE( s.count(), 1 );
0302     QCOMPARE( model->data( parent->index() ).toString(), QStringLiteral("newtest") );
0303 
0304     parent->removeRow( child->row() );
0305 }
0306 
0307 void TestProjectModel::testTakeRow()
0308 {
0309     QScopedPointer<ProjectBaseItem> parent(new ProjectBaseItem( nullptr, QStringLiteral("test") ));
0310     QScopedPointer<ProjectBaseItem> child(new ProjectBaseItem( nullptr, QStringLiteral("test"), parent.data() ));
0311     QScopedPointer<ProjectBaseItem> subchild(new ProjectBaseItem( nullptr, QStringLiteral("subtest"), child.data() ));
0312 
0313     model->appendRow( parent.data() );
0314 
0315     QCOMPARE( parent->model(), model );
0316     QCOMPARE( child->model(), model );
0317     QCOMPARE( subchild->model(), model );
0318 
0319     parent->takeRow( child->row() );
0320 
0321     QCOMPARE( child->model(), static_cast<ProjectModel*>(nullptr) );
0322     QCOMPARE( subchild->model(), static_cast<ProjectModel*>(nullptr) );
0323 }
0324 
0325 void TestProjectModel::testRename()
0326 {
0327     QString projectFolderPath = QDir::rootPath() + QStringLiteral("dummyprojectfolder");
0328     QFETCH( int, itemType );
0329     QFETCH( QString, itemText );
0330     QFETCH( QString, newName );
0331     QFETCH( bool, datachangesignal );
0332     QFETCH( QString, expectedItemText );
0333     QFETCH( int, expectedRenameCode );
0334 
0335     const Path projectFolder = Path(QUrl::fromLocalFile(projectFolderPath));
0336     QScopedPointer<TestProject> proj(new TestProject());
0337     auto* rootItem = new ProjectFolderItem( proj.data(), projectFolder, nullptr);
0338     proj->setProjectItem( rootItem );
0339 
0340     new ProjectFileItem(QStringLiteral("existing"), rootItem);
0341 
0342     ProjectBaseItem* item = nullptr;
0343     if( itemType == ProjectBaseItem::Target ) {
0344         item = new ProjectTargetItem( proj.data(), itemText, rootItem );
0345     } else if( itemType == ProjectBaseItem::File ) {
0346         item = new ProjectFileItem( itemText, rootItem );
0347     } else if( itemType == ProjectBaseItem::Folder ) {
0348         item = new ProjectFolderItem( itemText, rootItem );
0349     } else if( itemType == ProjectBaseItem::BuildFolder ) {
0350         item = new ProjectBuildFolderItem( itemText, rootItem );
0351     }
0352     Q_ASSERT( item );
0353 
0354     QCOMPARE(item->model(), model);
0355     QSignalSpy s( model, SIGNAL(dataChanged(QModelIndex,QModelIndex)) );
0356     ProjectBaseItem::RenameStatus stat = item->rename( newName );
0357     QCOMPARE( (int)stat, expectedRenameCode );
0358     if( datachangesignal ) {
0359         QCOMPARE( s.count(), 1 );
0360         QCOMPARE( qvariant_cast<QModelIndex>( s.takeFirst().at(0) ), item->index() );
0361     } else {
0362         QCOMPARE( s.count(), 0 );
0363     }
0364     QCOMPARE( item->text(), expectedItemText );
0365 }
0366 
0367 void TestProjectModel::testRename_data()
0368 {
0369     QTest::addColumn<int>( "itemType" );
0370     QTest::addColumn<QString>( "itemText" );
0371     QTest::addColumn<QString>( "newName" );
0372     QTest::addColumn<bool>( "datachangesignal" );
0373     QTest::addColumn<QString>( "expectedItemText" );
0374     QTest::addColumn<int>( "expectedRenameCode" );
0375 
0376     QTest::newRow("RenameableTarget")
0377     << (int)ProjectBaseItem::Target
0378     << QStringLiteral("target")
0379     << QStringLiteral("othertarget")
0380     << true
0381     << QStringLiteral("othertarget")
0382     << (int)ProjectBaseItem::RenameOk;
0383 
0384     QTest::newRow("RenameableFile")
0385     << (int)ProjectBaseItem::File
0386     << QStringLiteral("newfile.cpp")
0387     << QStringLiteral("otherfile.cpp")
0388     << true
0389     << QStringLiteral("otherfile.cpp")
0390     << (int)ProjectBaseItem::RenameOk;
0391 
0392     QTest::newRow("SourceAndDestinationFileEqual")
0393     << (int)ProjectBaseItem::File
0394     << QStringLiteral("newfile.cpp")
0395     << QStringLiteral("newfile.cpp")
0396     << false
0397     << QStringLiteral("newfile.cpp")
0398     << (int)ProjectBaseItem::RenameOk;
0399 
0400     QTest::newRow("RenameableFolder")
0401     << (int)ProjectBaseItem::Folder
0402     << QStringLiteral("newfolder")
0403     << QStringLiteral("otherfolder")
0404     << true
0405     << QStringLiteral("otherfolder")
0406     << (int)ProjectBaseItem::RenameOk;
0407 
0408     QTest::newRow("SourceAndDestinationFolderEqual")
0409     << (int)ProjectBaseItem::Folder
0410     << QStringLiteral("newfolder")
0411     << QStringLiteral("newfolder")
0412     << false
0413     << QStringLiteral("newfolder")
0414     << (int)ProjectBaseItem::RenameOk;
0415 
0416     QTest::newRow("RenameableBuildFolder")
0417     << (int)ProjectBaseItem::BuildFolder
0418     << QStringLiteral("newbfolder")
0419     << QStringLiteral("otherbfolder")
0420     << true
0421     << QStringLiteral("otherbfolder")
0422     << (int)ProjectBaseItem::RenameOk;
0423 
0424     QTest::newRow("SourceAndDestinationBuildFolderEqual")
0425     << (int)ProjectBaseItem::BuildFolder
0426     << QStringLiteral("newbfolder")
0427     << QStringLiteral("newbfolder")
0428     << false
0429     << QStringLiteral("newbfolder")
0430     << (int)ProjectBaseItem::RenameOk;
0431 
0432     QTest::newRow("ExistingFileError")
0433     << (int)ProjectBaseItem::Folder
0434     << QStringLiteral("mynew")
0435     << QStringLiteral("existing")
0436     << false
0437     << QStringLiteral("mynew")
0438     << (int)ProjectBaseItem::ExistingItemSameName;
0439 
0440     QTest::newRow("InvalidNameError")
0441     << (int)ProjectBaseItem::File
0442     << QStringLiteral("mynew")
0443     << QStringLiteral("other/bash")
0444     << false
0445     << QStringLiteral("mynew")
0446     << (int)ProjectBaseItem::InvalidNewName;
0447 }
0448 
0449 void TestProjectModel::testWithProject()
0450 {
0451     QString projectFolderPath = QDir::rootPath() + QStringLiteral("dummyprojectfolder");
0452     QScopedPointer<TestProject> proj(new TestProject());
0453     auto* rootItem = new ProjectFolderItem( proj.data(), Path(QUrl::fromLocalFile(projectFolderPath)), nullptr);
0454     proj->setProjectItem( rootItem );
0455     ProjectBaseItem* item = model->itemFromIndex( model->index( 0, 0 ) );
0456     QCOMPARE( item, rootItem );
0457     QCOMPARE( item->text(), proj->name() );
0458     QCOMPARE( item->path(), proj->path() );
0459 }
0460 
0461 void TestProjectModel::testItemsForPath()
0462 {
0463     QFETCH(Path, path);
0464     QFETCH(ProjectBaseItem*, root);
0465     QFETCH(int, matches);
0466 
0467     model->appendRow(root);
0468 
0469     const auto items = model->itemsForPath(IndexedString(path.pathOrUrl()));
0470     QCOMPARE(items.size(), matches);
0471     for (ProjectBaseItem* item : items) {
0472         QVERIFY(item->path() == path);
0473     }
0474 
0475     model->clear();
0476 }
0477 
0478 void TestProjectModel::testItemsForPath_data()
0479 {
0480     QTest::addColumn<Path>("path");
0481     QTest::addColumn<ProjectBaseItem*>("root");
0482     QTest::addColumn<int>("matches");
0483 
0484     {
0485         auto* root = new ProjectFolderItem(nullptr, Path(QUrl::fromLocalFile(QDir::tempPath())));
0486         auto* file = new ProjectFileItem(QStringLiteral("a"), root);
0487         QTest::newRow("find one") << file->path() << static_cast<ProjectBaseItem*>(root) << 1;
0488     }
0489 
0490     {
0491         auto* root = new ProjectFolderItem(nullptr, Path(QUrl::fromLocalFile(QDir::tempPath())));
0492         auto* folder = new ProjectFolderItem(QStringLiteral("a"), root);
0493         auto* file = new ProjectFileItem(QStringLiteral("foo"), folder);
0494         auto* target = new ProjectTargetItem(nullptr, QStringLiteral("b"), root);
0495         auto* file2 = new ProjectFileItem(nullptr, file->path(), target);
0496         Q_UNUSED(file2);
0497         QTest::newRow("find two") << file->path() << static_cast<ProjectBaseItem*>(root) << 2;
0498     }
0499 }
0500 
0501 void TestProjectModel::testProjectProxyModel()
0502 {
0503     auto* root = new ProjectFolderItem(nullptr, Path(QUrl::fromLocalFile(QDir::tempPath())));
0504     new ProjectFileItem(QStringLiteral("b1"), root);
0505     new ProjectFileItem(QStringLiteral("a1"), root);
0506     new ProjectFileItem(QStringLiteral("d1"), root);
0507     new ProjectFileItem(QStringLiteral("c1"), root);
0508     model->appendRow(root);
0509 
0510     QModelIndex proxyRoot = proxy->mapFromSource(root->index());
0511     QCOMPARE(model->rowCount(root->index()), 4);
0512     QCOMPARE(proxy->rowCount(proxyRoot), 4);
0513     QCOMPARE(proxy->index(0, 0, proxy->index(0, 0)).data().toString(), QStringLiteral("a1"));
0514     QCOMPARE(proxy->index(1, 0, proxy->index(0, 0)).data().toString(), QStringLiteral("b1"));
0515     QCOMPARE(proxy->index(2, 0, proxy->index(0, 0)).data().toString(), QStringLiteral("c1"));
0516     QCOMPARE(proxy->index(3, 0, proxy->index(0, 0)).data().toString(), QStringLiteral("d1"));
0517 
0518     model->clear();
0519 }
0520 
0521 void TestProjectModel::testProjectFileSet()
0522 {
0523     QScopedPointer<TestProject> project(new TestProject());
0524 
0525     QVERIFY(project->fileSet().isEmpty());
0526     Path path(QUrl::fromLocalFile(QDir::tempPath() + "/a"));
0527     auto* item = new ProjectFileItem(project.data(), path, project->projectItem());
0528     QCOMPARE(project->fileSet().size(), 1);
0529     qDebug() << path << project->fileSet().values().at(0).toUrl();
0530     QCOMPARE(Path(project->fileSet().values().at(0).toUrl()), path);
0531     delete item;
0532     QVERIFY(project->fileSet().isEmpty());
0533 }
0534 
0535 void TestProjectModel::testProjectFileIcon()
0536 {
0537     QMimeDatabase db;
0538 
0539     QScopedPointer<ProjectFileItem> item(new ProjectFileItem(nullptr, Path(QDir::tempPath() + "/foo.txt")));
0540     const QString txtIcon = db.mimeTypeForUrl(item->path().toUrl()).iconName();
0541     QCOMPARE(item->iconName(), txtIcon);
0542     item->setPath(Path(QDir::tempPath() + "/bar.cpp"));
0543     QCOMPARE(item->iconName(), db.mimeTypeForUrl(item->path().toUrl()).iconName());
0544     QVERIFY(item->iconName() != txtIcon);
0545 }
0546 
0547 QTEST_MAIN(TestProjectModel)
0548 
0549 #include "moc_test_projectmodel.cpp"