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

Method testCreateSimpleHierarchy

kdevplatform/project/tests/test_projectmodel.cpp:213–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211}
212
213void TestProjectModel::testCreateSimpleHierarchy()
214{
215 QString folderName = QStringLiteral("rootfolder");
216 QString fileName = QStringLiteral("file");
217 QString targetName = QStringLiteral("testtarged");
218 QString cppFileName = QStringLiteral("file.cpp");
219 auto* rootFolder = new ProjectFolderItem( nullptr, Path(QUrl::fromLocalFile( QDir::rootPath() + folderName )) );
220 QCOMPARE(rootFolder->baseName(), folderName);
221 auto* file = new ProjectFileItem( fileName, rootFolder );
222 QCOMPARE(file->baseName(), fileName);
223 auto* target = new ProjectTargetItem( nullptr, targetName );
224 rootFolder->appendRow( target );
225 auto* targetfile = new ProjectFileItem( nullptr, Path(rootFolder->path(), cppFileName), target );
226
227 model->appendRow( rootFolder );
228
229 QCOMPARE( model->rowCount(), 1 );
230 QModelIndex folderIdx = model->index( 0, 0, QModelIndex() );
231 QCOMPARE( model->data( folderIdx ).toString(), folderName );
232 QCOMPARE( model->rowCount( folderIdx ), 2 );
233 QCOMPARE( model->itemFromIndex( folderIdx ), rootFolder );
234 QVERIFY( rootFolder->hasFileOrFolder( fileName ) );
235
236 QModelIndex fileIdx = model->index( 0, 0, folderIdx );
237 QCOMPARE( model->data( fileIdx ).toString(), fileName );
238 QCOMPARE( model->rowCount( fileIdx ), 0 );
239 QCOMPARE( model->itemFromIndex( fileIdx ), file );
240
241 QModelIndex targetIdx = model->index( 1, 0, folderIdx );
242 QCOMPARE( model->data( targetIdx ).toString(), targetName );
243 QCOMPARE( model->rowCount( targetIdx ), 1 );
244 QCOMPARE( model->itemFromIndex( targetIdx ), target );
245
246 QModelIndex targetFileIdx = model->index( 0, 0, targetIdx );
247 QCOMPARE( model->data( targetFileIdx ).toString(), cppFileName );
248 QCOMPARE( model->rowCount( targetFileIdx ), 0 );
249 QCOMPARE( model->itemFromIndex( targetFileIdx ), targetfile );
250
251 rootFolder->removeRow( 1 );
252 QCOMPARE( model->rowCount( folderIdx ), 1 );
253 delete file;
254 file = nullptr;
255
256 // Check that we also find a folder with the fileName
257 new ProjectFolderItem( fileName, rootFolder );
258 QVERIFY( rootFolder->hasFileOrFolder( fileName ) );
259
260 delete rootFolder;
261 QCOMPARE( model->rowCount(), 0 );
262}
263
264void TestProjectModel::testItemSanity()
265{

Callers

nothing calls this directly

Calls 12

baseNameMethod · 0.80
appendRowMethod · 0.80
hasFileOrFolderMethod · 0.80
removeRowMethod · 0.80
PathClass · 0.50
QModelIndexClass · 0.50
pathMethod · 0.45
rowCountMethod · 0.45
indexMethod · 0.45
toStringMethod · 0.45
dataMethod · 0.45
itemFromIndexMethod · 0.45

Tested by

no test coverage detected