Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/project/tests/test_projectmodel.cpp
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | 73 | { | |||
---|---|---|---|---|---|
109 | QCOMPARE( model->data( idx ).toString(), expectedItemText ); | 109 | QCOMPARE( model->data( idx ).toString(), expectedItemText ); | ||
110 | QCOMPARE( model->indexFromItem( newitem ), idx ); | 110 | QCOMPARE( model->indexFromItem( newitem ), idx ); | ||
111 | QCOMPARE( model->pathFromIndex( idx ), expectedRelativeItemPath ); | 111 | QCOMPARE( model->pathFromIndex( idx ), expectedRelativeItemPath ); | ||
112 | QCOMPARE( model->pathToIndex( expectedRelativeItemPath ), idx ); | 112 | QCOMPARE( model->pathToIndex( expectedRelativeItemPath ), idx ); | ||
113 | } | 113 | } | ||
114 | 114 | | |||
115 | void TestProjectModel::testCreateFileSystemItems_data() | 115 | void TestProjectModel::testCreateFileSystemItems_data() | ||
116 | { | 116 | { | ||
117 | QString testRootDir = QDir::rootPath() + QStringLiteral("rootdir"); | ||||
118 | QString testRootFile = QDir::rootPath() + QStringLiteral("rootfile"); | ||||
117 | QTest::addColumn<int>( "itemType" ); | 119 | QTest::addColumn<int>( "itemType" ); | ||
118 | QTest::addColumn<Path>( "itemPath" ); | 120 | QTest::addColumn<Path>( "itemPath" ); | ||
119 | QTest::addColumn<Path>( "expectedItemPath" ); | 121 | QTest::addColumn<Path>( "expectedItemPath" ); | ||
120 | QTest::addColumn<QString>( "expectedItemText" ); | 122 | QTest::addColumn<QString>( "expectedItemText" ); | ||
121 | QTest::addColumn<QStringList>( "expectedRelativeItemPath" ); | 123 | QTest::addColumn<QStringList>( "expectedRelativeItemPath" ); | ||
122 | QTest::addColumn<int>( "expectedItemRow" ); | 124 | QTest::addColumn<int>( "expectedItemRow" ); | ||
123 | 125 | | |||
124 | QTest::newRow("RootFolder") | 126 | QTest::newRow("RootFolder") | ||
125 | << (int)ProjectBaseItem::Folder | 127 | << (int)ProjectBaseItem::Folder | ||
126 | << Path(QUrl::fromLocalFile(QStringLiteral("/rootdir"))) | 128 | << Path(QUrl::fromLocalFile(testRootDir)) | ||
127 | << Path(QUrl::fromLocalFile(QStringLiteral("/rootdir/"))) | 129 | << Path(QUrl::fromLocalFile(testRootDir)) | ||
128 | << QStringLiteral("rootdir") | 130 | << QStringLiteral("rootdir") | ||
129 | << ( QStringList() << QStringLiteral("rootdir") ) | 131 | << ( QStringList() << QStringLiteral("rootdir") ) | ||
130 | << 0; | 132 | << 0; | ||
131 | 133 | | |||
132 | QTest::newRow("RootBuildFolder") | 134 | QTest::newRow("RootBuildFolder") | ||
133 | << (int)ProjectBaseItem::BuildFolder | 135 | << (int)ProjectBaseItem::BuildFolder | ||
134 | << Path(QUrl::fromLocalFile(QStringLiteral("/rootdir"))) | 136 | << Path(QUrl::fromLocalFile(testRootDir)) | ||
135 | << Path(QUrl::fromLocalFile(QStringLiteral("/rootdir/"))) | 137 | << Path(QUrl::fromLocalFile(testRootDir)) | ||
136 | << QStringLiteral("rootdir") | 138 | << QStringLiteral("rootdir") | ||
137 | << ( QStringList() << QStringLiteral("rootdir") ) | 139 | << ( QStringList() << QStringLiteral("rootdir") ) | ||
138 | << 0; | 140 | << 0; | ||
139 | 141 | | |||
140 | QTest::newRow("RootFile") | 142 | QTest::newRow("RootFile") | ||
141 | << (int)ProjectBaseItem::File | 143 | << (int)ProjectBaseItem::File | ||
142 | << Path(QUrl::fromLocalFile(QStringLiteral("/rootfile"))) | 144 | << Path(QUrl::fromLocalFile(testRootFile)) | ||
143 | << Path(QUrl::fromLocalFile(QStringLiteral("/rootfile"))) | 145 | << Path(QUrl::fromLocalFile(testRootFile)) | ||
144 | << QStringLiteral("rootfile") | 146 | << QStringLiteral("rootfile") | ||
145 | << ( QStringList() << QStringLiteral("rootfile") ) | 147 | << ( QStringList() << QStringLiteral("rootfile") ) | ||
146 | << 0; | 148 | << 0; | ||
147 | 149 | | |||
148 | } | 150 | } | ||
149 | 151 | | |||
150 | void TestProjectModel::testCreateTargetItems() | 152 | void TestProjectModel::testCreateTargetItems() | ||
151 | { | 153 | { | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 199 | QTest::newRow("RootLibraryTarget") | |||
199 | << "libtarget" | 201 | << "libtarget" | ||
200 | << QStringLiteral("libtarget") | 202 | << QStringLiteral("libtarget") | ||
201 | << ( QStringList() << QStringLiteral("libtarget") ) | 203 | << ( QStringList() << QStringLiteral("libtarget") ) | ||
202 | << 0; | 204 | << 0; | ||
203 | } | 205 | } | ||
204 | 206 | | |||
205 | void TestProjectModel::testChangeWithProxyModel() | 207 | void TestProjectModel::testChangeWithProxyModel() | ||
206 | { | 208 | { | ||
209 | QString projectFolderPath = QDir::rootPath() + QStringLiteral("folder1"); | ||||
210 | QString projectFilePath = QDir::rootPath() + QStringLiteral("folder1/file1"); | ||||
207 | QSortFilterProxyModel* proxy = new QSortFilterProxyModel( this ); | 211 | QSortFilterProxyModel* proxy = new QSortFilterProxyModel( this ); | ||
208 | proxy->setSourceModel( model ); | 212 | proxy->setSourceModel( model ); | ||
209 | ProjectFolderItem* root = new ProjectFolderItem( nullptr, Path(QUrl::fromLocalFile(QStringLiteral("/folder1"))) ); | 213 | ProjectFolderItem* root = new ProjectFolderItem( nullptr, Path(QUrl::fromLocalFile(projectFolderPath)) ); | ||
210 | root->appendRow( new ProjectFileItem( nullptr, Path(QUrl::fromLocalFile(QStringLiteral("/folder1/file1"))) ) ); | 214 | root->appendRow( new ProjectFileItem( nullptr, Path(QUrl::fromLocalFile(projectFilePath)) ) ); | ||
211 | model->appendRow( root ); | 215 | model->appendRow( root ); | ||
212 | 216 | | |||
213 | QCOMPARE( model->rowCount(), 1 ); | 217 | QCOMPARE( model->rowCount(), 1 ); | ||
214 | QCOMPARE( proxy->rowCount(), 1 ); | 218 | QCOMPARE( proxy->rowCount(), 1 ); | ||
215 | 219 | | |||
216 | model->removeRow( 0 ); | 220 | model->removeRow( 0 ); | ||
217 | 221 | | |||
218 | QCOMPARE( model->rowCount(), 0 ); | 222 | QCOMPARE( model->rowCount(), 0 ); | ||
219 | QCOMPARE( proxy->rowCount(), 0 ); | 223 | QCOMPARE( proxy->rowCount(), 0 ); | ||
220 | } | 224 | } | ||
221 | 225 | | |||
222 | void TestProjectModel::testCreateSimpleHierarchy() | 226 | void TestProjectModel::testCreateSimpleHierarchy() | ||
223 | { | 227 | { | ||
224 | QString folderName = QStringLiteral("rootfolder"); | 228 | QString folderName = QStringLiteral("rootfolder"); | ||
225 | QString fileName = QStringLiteral("file"); | 229 | QString fileName = QStringLiteral("file"); | ||
226 | QString targetName = QStringLiteral("testtarged"); | 230 | QString targetName = QStringLiteral("testtarged"); | ||
227 | QString cppFileName = QStringLiteral("file.cpp"); | 231 | QString cppFileName = QStringLiteral("file.cpp"); | ||
228 | ProjectFolderItem* rootFolder = new ProjectFolderItem( nullptr, Path(QUrl::fromLocalFile("/"+folderName)) ); | 232 | ProjectFolderItem* rootFolder = new ProjectFolderItem( nullptr, Path(QUrl::fromLocalFile( QDir::rootPath() + folderName )) ); | ||
229 | QCOMPARE(rootFolder->baseName(), folderName); | 233 | QCOMPARE(rootFolder->baseName(), folderName); | ||
230 | ProjectFileItem* file = new ProjectFileItem( fileName, rootFolder ); | 234 | ProjectFileItem* file = new ProjectFileItem( fileName, rootFolder ); | ||
231 | QCOMPARE(file->baseName(), fileName); | 235 | QCOMPARE(file->baseName(), fileName); | ||
232 | ProjectTargetItem* target = new ProjectTargetItem( nullptr, targetName ); | 236 | ProjectTargetItem* target = new ProjectTargetItem( nullptr, targetName ); | ||
233 | rootFolder->appendRow( target ); | 237 | rootFolder->appendRow( target ); | ||
234 | ProjectFileItem* targetfile = new ProjectFileItem( nullptr, Path(rootFolder->path(), cppFileName), target ); | 238 | ProjectFileItem* targetfile = new ProjectFileItem( nullptr, Path(rootFolder->path(), cppFileName), target ); | ||
235 | 239 | | |||
236 | model->appendRow( rootFolder ); | 240 | model->appendRow( rootFolder ); | ||
Show All 30 Lines | |||||
267 | QVERIFY( rootFolder->hasFileOrFolder( fileName ) ); | 271 | QVERIFY( rootFolder->hasFileOrFolder( fileName ) ); | ||
268 | 272 | | |||
269 | delete rootFolder; | 273 | delete rootFolder; | ||
270 | QCOMPARE( model->rowCount(), 0 ); | 274 | QCOMPARE( model->rowCount(), 0 ); | ||
271 | } | 275 | } | ||
272 | 276 | | |||
273 | void TestProjectModel::testItemSanity() | 277 | void TestProjectModel::testItemSanity() | ||
274 | { | 278 | { | ||
279 | #ifdef Q_OS_WIN | ||||
280 | QString child3Path = QStringLiteral("file:///c:/bcd"); | ||||
281 | QString child4Path = QStringLiteral("file:///c:/abcd"); | ||||
282 | #else | ||||
283 | QString child3Path = QStringLiteral("file:///bcd"); | ||||
284 | QString child4Path = QStringLiteral("file:///abcd"); | ||||
285 | #endif | ||||
286 | QString newtestPath = QDir::rootPath() + QStringLiteral("newtest"); | ||||
275 | ProjectBaseItem* parent = new ProjectBaseItem( nullptr, QStringLiteral("test") ); | 287 | ProjectBaseItem* parent = new ProjectBaseItem( nullptr, QStringLiteral("test") ); | ||
276 | ProjectBaseItem* child = new ProjectBaseItem( nullptr, QStringLiteral("test"), parent ); | 288 | ProjectBaseItem* child = new ProjectBaseItem( nullptr, QStringLiteral("test"), parent ); | ||
277 | ProjectBaseItem* child2 = new ProjectBaseItem( nullptr, QStringLiteral("ztest"), parent ); | 289 | ProjectBaseItem* child2 = new ProjectBaseItem( nullptr, QStringLiteral("ztest"), parent ); | ||
278 | ProjectFileItem* child3 = new ProjectFileItem( nullptr, Path(QUrl(QStringLiteral("file:///bcd"))), parent ); | 290 | ProjectFileItem* child3 = new ProjectFileItem( nullptr, Path(QUrl(child3Path)), parent ); | ||
279 | ProjectFileItem* child4 = new ProjectFileItem( nullptr, Path(QUrl(QStringLiteral("file:///abcd"))), parent ); | 291 | ProjectFileItem* child4 = new ProjectFileItem( nullptr, Path(QUrl(child4Path)), parent ); | ||
280 | 292 | | |||
281 | // Just some basic santiy checks on the API | 293 | // Just some basic santiy checks on the API | ||
282 | QCOMPARE( parent->child( 0 ), child ); | 294 | QCOMPARE( parent->child( 0 ), child ); | ||
283 | QCOMPARE( parent->row(), -1 ); | 295 | QCOMPARE( parent->row(), -1 ); | ||
284 | QVERIFY( !parent->child( -1 ) ); | 296 | QVERIFY( !parent->child( -1 ) ); | ||
285 | QVERIFY( !parent->file() ); | 297 | QVERIFY( !parent->file() ); | ||
286 | QVERIFY( !parent->folder() ); | 298 | QVERIFY( !parent->folder() ); | ||
287 | QVERIFY( !parent->project() ); | 299 | QVERIFY( !parent->project() ); | ||
288 | QVERIFY( !parent->child( parent->rowCount() ) ); | 300 | QVERIFY( !parent->child( parent->rowCount() ) ); | ||
289 | QCOMPARE( parent->iconName(), QString() ); | 301 | QCOMPARE( parent->iconName(), QString() ); | ||
290 | QCOMPARE( parent->index(), QModelIndex() ); | 302 | QCOMPARE( parent->index(), QModelIndex() ); | ||
291 | 303 | | |||
292 | QCOMPARE( child->type(), (int)ProjectBaseItem::BaseItem ); | 304 | QCOMPARE( child->type(), (int)ProjectBaseItem::BaseItem ); | ||
293 | 305 | | |||
294 | QCOMPARE( child->lessThan( child2 ), true ); | 306 | QCOMPARE( child->lessThan( child2 ), true ); | ||
295 | QCOMPARE( child3->lessThan( child4 ), false ); | 307 | QCOMPARE( child3->lessThan( child4 ), false ); | ||
296 | 308 | | |||
297 | // Check that model is properly emitting data-changes | 309 | // Check that model is properly emitting data-changes | ||
298 | model->appendRow( parent ); | 310 | model->appendRow( parent ); | ||
299 | QCOMPARE( parent->index(), model->index(0, 0, QModelIndex()) ); | 311 | QCOMPARE( parent->index(), model->index(0, 0, QModelIndex()) ); | ||
300 | QSignalSpy s( model, SIGNAL(dataChanged(QModelIndex,QModelIndex)) ); | 312 | QSignalSpy s( model, SIGNAL(dataChanged(QModelIndex,QModelIndex)) ); | ||
301 | parent->setPath( Path(QStringLiteral("/newtest")) ); | 313 | parent->setPath( Path(newtestPath) ); | ||
302 | QCOMPARE( s.count(), 1 ); | 314 | QCOMPARE( s.count(), 1 ); | ||
303 | QCOMPARE( model->data( parent->index() ).toString(), QStringLiteral("newtest") ); | 315 | QCOMPARE( model->data( parent->index() ).toString(), QStringLiteral("newtest") ); | ||
304 | 316 | | |||
305 | parent->removeRow( child->row() ); | 317 | parent->removeRow( child->row() ); | ||
306 | } | 318 | } | ||
307 | 319 | | |||
308 | void TestProjectModel::testTakeRow() | 320 | void TestProjectModel::testTakeRow() | ||
309 | { | 321 | { | ||
Show All 10 Lines | |||||
320 | parent->takeRow( child->row() ); | 332 | parent->takeRow( child->row() ); | ||
321 | 333 | | |||
322 | QCOMPARE( child->model(), static_cast<ProjectModel*>(nullptr) ); | 334 | QCOMPARE( child->model(), static_cast<ProjectModel*>(nullptr) ); | ||
323 | QCOMPARE( subchild->model(), static_cast<ProjectModel*>(nullptr) ); | 335 | QCOMPARE( subchild->model(), static_cast<ProjectModel*>(nullptr) ); | ||
324 | } | 336 | } | ||
325 | 337 | | |||
326 | void TestProjectModel::testRename() | 338 | void TestProjectModel::testRename() | ||
327 | { | 339 | { | ||
340 | QString projectFolderPath = QDir::rootPath() + QStringLiteral("dummyprojectfolder"); | ||||
328 | QFETCH( int, itemType ); | 341 | QFETCH( int, itemType ); | ||
329 | QFETCH( QString, itemText ); | 342 | QFETCH( QString, itemText ); | ||
330 | QFETCH( QString, newName ); | 343 | QFETCH( QString, newName ); | ||
331 | QFETCH( bool, datachangesignal ); | 344 | QFETCH( bool, datachangesignal ); | ||
332 | QFETCH( QString, expectedItemText ); | 345 | QFETCH( QString, expectedItemText ); | ||
333 | QFETCH( int, expectedRenameCode ); | 346 | QFETCH( int, expectedRenameCode ); | ||
334 | 347 | | |||
335 | const Path projectFolder = Path(QUrl::fromLocalFile(QStringLiteral("/dummyprojectfolder"))); | 348 | const Path projectFolder = Path(QUrl::fromLocalFile(projectFolderPath)); | ||
336 | QScopedPointer<TestProject> proj(new TestProject()); | 349 | QScopedPointer<TestProject> proj(new TestProject()); | ||
337 | ProjectFolderItem* rootItem = new ProjectFolderItem( proj.data(), projectFolder, nullptr); | 350 | ProjectFolderItem* rootItem = new ProjectFolderItem( proj.data(), projectFolder, nullptr); | ||
338 | proj->setProjectItem( rootItem ); | 351 | proj->setProjectItem( rootItem ); | ||
339 | 352 | | |||
340 | new ProjectFileItem(QStringLiteral("existing"), rootItem); | 353 | new ProjectFileItem(QStringLiteral("existing"), rootItem); | ||
341 | 354 | | |||
342 | ProjectBaseItem* item = nullptr; | 355 | ProjectBaseItem* item = nullptr; | ||
343 | if( itemType == ProjectBaseItem::Target ) { | 356 | if( itemType == ProjectBaseItem::Target ) { | ||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 381 | { | |||
443 | << QStringLiteral("other/bash") | 456 | << QStringLiteral("other/bash") | ||
444 | << false | 457 | << false | ||
445 | << QStringLiteral("mynew") | 458 | << QStringLiteral("mynew") | ||
446 | << (int)ProjectBaseItem::InvalidNewName; | 459 | << (int)ProjectBaseItem::InvalidNewName; | ||
447 | } | 460 | } | ||
448 | 461 | | |||
449 | void TestProjectModel::testWithProject() | 462 | void TestProjectModel::testWithProject() | ||
450 | { | 463 | { | ||
464 | QString projectFolderPath = QDir::rootPath() + QStringLiteral("dummyprojectfolder"); | ||||
451 | QScopedPointer<TestProject> proj(new TestProject()); | 465 | QScopedPointer<TestProject> proj(new TestProject()); | ||
452 | ProjectFolderItem* rootItem = new ProjectFolderItem( proj.data(), Path(QUrl::fromLocalFile(QStringLiteral("/dummyprojectfolder"))), nullptr); | 466 | ProjectFolderItem* rootItem = new ProjectFolderItem( proj.data(), Path(QUrl::fromLocalFile(projectFolderPath)), nullptr); | ||
453 | proj->setProjectItem( rootItem ); | 467 | proj->setProjectItem( rootItem ); | ||
454 | ProjectBaseItem* item = model->itemFromIndex( model->index( 0, 0 ) ); | 468 | ProjectBaseItem* item = model->itemFromIndex( model->index( 0, 0 ) ); | ||
455 | QCOMPARE( item, rootItem ); | 469 | QCOMPARE( item, rootItem ); | ||
456 | QCOMPARE( item->text(), proj->name() ); | 470 | QCOMPARE( item->text(), proj->name() ); | ||
457 | QCOMPARE( item->path(), proj->path() ); | 471 | QCOMPARE( item->path(), proj->path() ); | ||
458 | } | 472 | } | ||
459 | 473 | | |||
460 | void TestProjectModel::testItemsForPath() | 474 | void TestProjectModel::testItemsForPath() | ||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |