| 211 | } |
| 212 | |
| 213 | void 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 | |
| 264 | void TestProjectModel::testItemSanity() |
| 265 | { |
nothing calls this directly
no test coverage detected