Changeset View
Changeset View
Standalone View
Standalone View
autotests/kfileplacesmodeltest.cpp
Show All 30 Lines | |||||
31 | 31 | | |||
32 | #include <QtTest> | 32 | #include <QtTest> | ||
33 | 33 | | |||
34 | #include <stdlib.h> | 34 | #include <stdlib.h> | ||
35 | #include <qstandardpaths.h> | 35 | #include <qstandardpaths.h> | ||
36 | 36 | | |||
37 | Q_DECLARE_METATYPE(KFilePlacesModel::GroupType) | 37 | Q_DECLARE_METATYPE(KFilePlacesModel::GroupType) | ||
38 | 38 | | |||
39 | #ifdef Q_OS_WIN | | |||
40 | //c:\ as root for windows | | |||
41 | #define KDE_ROOT_PATH "C:\\" | | |||
42 | #else | | |||
43 | #define KDE_ROOT_PATH "/" | | |||
44 | #endif | | |||
45 | | ||||
46 | // Avoid QHash randomization so that the order of the devices is stable | 39 | // Avoid QHash randomization so that the order of the devices is stable | ||
47 | static void seedInit() | 40 | static void seedInit() | ||
48 | { | 41 | { | ||
49 | qputenv("QT_HASH_SEED", "0"); | 42 | qputenv("QT_HASH_SEED", "0"); | ||
50 | // This env var has no effect because this comes too late. qCpuFeatures() was already called by | 43 | // This env var has no effect because this comes too late. qCpuFeatures() was already called by | ||
51 | // a Q_CONSTRUCTOR_FUNCTION inside QtGui (see image/qimage_conversions.cpp). Argh. QTBUG-47566. | 44 | // a Q_CONSTRUCTOR_FUNCTION inside QtGui (see image/qimage_conversions.cpp). Argh. QTBUG-47566. | ||
52 | qputenv("QT_NO_CPU_FEATURE", "sse4.2"); | 45 | qputenv("QT_NO_CPU_FEATURE", "sse4.2"); | ||
53 | } | 46 | } | ||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Line(s) | 184 | { | |||
197 | QDBusInterface *iface = new QDBusInterface(QDBusConnection::sessionBus().baseService(), udi); | 190 | QDBusInterface *iface = new QDBusInterface(QDBusConnection::sessionBus().baseService(), udi); | ||
198 | m_interfacesMap[udi] = iface; | 191 | m_interfacesMap[udi] = iface; | ||
199 | 192 | | |||
200 | return iface; | 193 | return iface; | ||
201 | } | 194 | } | ||
202 | 195 | | |||
203 | void KFilePlacesModelTest::testInitialState() | 196 | void KFilePlacesModelTest::testInitialState() | ||
204 | { | 197 | { | ||
205 | QCOMPARE(m_places->rowCount(), 4); // when the xbel file is empty, KFilePlacesModel fills it with 4 default items | 198 | QCOMPARE(m_places->rowCount(), 3); // when the xbel file is empty, KFilePlacesModel fills it with 3 default items | ||
206 | QCoreApplication::processEvents(); // Devices have a delayed loading | 199 | QCoreApplication::processEvents(); // Devices have a delayed loading | ||
207 | QCOMPARE(m_places->rowCount(), 9); | 200 | QCOMPARE(m_places->rowCount(), 8); | ||
208 | } | 201 | } | ||
209 | 202 | | |||
210 | static const QStringList initialListOfPlaces() | 203 | static const QStringList initialListOfPlaces() | ||
211 | { | 204 | { | ||
212 | return QStringList() << QDir::homePath() << QStringLiteral(KDE_ROOT_PATH) << QStringLiteral("trash:/"); | 205 | return QStringList() << QDir::homePath() << QStringLiteral("trash:/"); | ||
213 | } | 206 | } | ||
214 | 207 | | |||
215 | static const QStringList initialListOfShared() | 208 | static const QStringList initialListOfShared() | ||
216 | { | 209 | { | ||
217 | return QStringList() << QStringLiteral("remote:/") << QStringLiteral("/media/nfs"); | 210 | return QStringList() << QStringLiteral("remote:/") << QStringLiteral("/media/nfs"); | ||
218 | } | 211 | } | ||
219 | 212 | | |||
220 | static const QStringList initialListOfDevices() | 213 | static const QStringList initialListOfDevices() | ||
Show All 27 Lines | 238 | { | |||
248 | // add item | 241 | // add item | ||
249 | 242 | | |||
250 | m_places->addPlace(QStringLiteral("foo"), QUrl::fromLocalFile(QStringLiteral("/foo")), | 243 | m_places->addPlace(QStringLiteral("foo"), QUrl::fromLocalFile(QStringLiteral("/foo")), | ||
251 | QString(), QString()); | 244 | QString(), QString()); | ||
252 | 245 | | |||
253 | urls = initialListOfUrls(); | 246 | urls = initialListOfUrls(); | ||
254 | 247 | | |||
255 | // it will be added at the end of places section | 248 | // it will be added at the end of places section | ||
256 | urls.insert(3, QStringLiteral("/foo")); | 249 | urls.insert(2, QStringLiteral("/foo")); | ||
257 | CHECK_PLACES_URLS(urls); | 250 | CHECK_PLACES_URLS(urls); | ||
258 | 251 | | |||
259 | // reparse the bookmark file | 252 | // reparse the bookmark file | ||
260 | 253 | | |||
261 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | 254 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | ||
262 | 255 | | |||
263 | bookmarkManager->notifyCompleteChange(QString()); | 256 | bookmarkManager->notifyCompleteChange(QString()); | ||
264 | 257 | | |||
265 | // check if they are the same | 258 | // check if they are the same | ||
266 | 259 | | |||
267 | CHECK_PLACES_URLS(urls); | 260 | CHECK_PLACES_URLS(urls); | ||
268 | 261 | | |||
269 | // try to remove item | 262 | // try to remove item | ||
270 | m_places->removePlace(m_places->index(3, 0)); | 263 | m_places->removePlace(m_places->index(2, 0)); | ||
271 | 264 | | |||
272 | urls = initialListOfUrls(); | 265 | urls = initialListOfUrls(); | ||
273 | CHECK_PLACES_URLS(urls); | 266 | CHECK_PLACES_URLS(urls); | ||
274 | } | 267 | } | ||
275 | 268 | | |||
276 | void KFilePlacesModelTest::testInternalBookmarksHaveIds() | 269 | void KFilePlacesModelTest::testInternalBookmarksHaveIds() | ||
277 | { | 270 | { | ||
278 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | 271 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | ||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | |||||
382 | void KFilePlacesModelTest::testMove() | 375 | void KFilePlacesModelTest::testMove() | ||
383 | { | 376 | { | ||
384 | QList<QVariant> args; | 377 | QList<QVariant> args; | ||
385 | QSignalSpy spy_inserted(m_places, SIGNAL(rowsInserted(QModelIndex,int,int))); | 378 | QSignalSpy spy_inserted(m_places, SIGNAL(rowsInserted(QModelIndex,int,int))); | ||
386 | QSignalSpy spy_removed(m_places, SIGNAL(rowsRemoved(QModelIndex,int,int))); | 379 | QSignalSpy spy_removed(m_places, SIGNAL(rowsRemoved(QModelIndex,int,int))); | ||
387 | 380 | | |||
388 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | 381 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | ||
389 | KBookmarkGroup root = bookmarkManager->root(); | 382 | KBookmarkGroup root = bookmarkManager->root(); | ||
390 | KBookmark system_root = m_places->bookmarkForIndex(m_places->index(1, 0)); | 383 | | ||
391 | KBookmark before_system_root = m_places->bookmarkForIndex(m_places->index(0, 0)); | 384 | KBookmark system_home = m_places->bookmarkForIndex(m_places->index(0, 0)); | ||
392 | 385 | | |||
393 | // Trying move the root at the end of the list, should move it to the end of places section instead | 386 | // Trying move the root at the end of the list, should move it to the end of places section instead | ||
394 | // to keep it grouped | 387 | // to keep it grouped | ||
395 | KBookmark last = root.first(); | 388 | KBookmark last = root.first(); | ||
396 | while (!root.next(last).isNull()) { | 389 | while (!root.next(last).isNull()) { | ||
397 | last = root.next(last); | 390 | last = root.next(last); | ||
398 | } | 391 | } | ||
399 | root.moveBookmark(system_root, last); | 392 | root.moveBookmark(system_home, last); | ||
400 | bookmarkManager->emitChanged(root); | 393 | bookmarkManager->emitChanged(root); | ||
401 | 394 | | |||
402 | QStringList urls; | 395 | QStringList urls; | ||
403 | urls << QDir::homePath() << QStringLiteral("trash:/") << QStringLiteral(KDE_ROOT_PATH) | 396 | urls << QStringLiteral("trash:/") << QDir::homePath() | ||
404 | << initialListOfShared() | 397 | << initialListOfShared() | ||
405 | << initialListOfDevices() | 398 | << initialListOfDevices() | ||
406 | << initialListOfRemovableDevices(); | 399 | << initialListOfRemovableDevices(); | ||
407 | 400 | | |||
408 | CHECK_PLACES_URLS(urls); | 401 | CHECK_PLACES_URLS(urls); | ||
409 | QCOMPARE(spy_inserted.count(), 1); | 402 | QCOMPARE(spy_inserted.count(), 1); | ||
410 | args = spy_inserted.takeFirst(); | 403 | args = spy_inserted.takeFirst(); | ||
411 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 404 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
412 | QCOMPARE(args.at(1).toInt(), 2); | | |||
413 | QCOMPARE(args.at(2).toInt(), 2); | | |||
414 | QCOMPARE(spy_removed.count(), 1); | | |||
415 | args = spy_removed.takeFirst(); | | |||
416 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | | |||
417 | QCOMPARE(args.at(1).toInt(), 1); | 405 | QCOMPARE(args.at(1).toInt(), 1); | ||
418 | QCOMPARE(args.at(2).toInt(), 1); | 406 | QCOMPARE(args.at(2).toInt(), 1); | ||
419 | | ||||
420 | // Move the root at the beginning of the list | | |||
421 | root.moveBookmark(system_root, KBookmark()); | | |||
422 | bookmarkManager->emitChanged(root); | | |||
423 | | ||||
424 | urls.clear(); | | |||
425 | urls << QStringLiteral(KDE_ROOT_PATH) << QDir::homePath() << QStringLiteral("trash:/") | | |||
426 | << initialListOfShared() | | |||
427 | << initialListOfDevices() | | |||
428 | << initialListOfRemovableDevices(); | | |||
429 | | ||||
430 | CHECK_PLACES_URLS(urls); | | |||
431 | QCOMPARE(spy_inserted.count(), 1); | | |||
432 | args = spy_inserted.takeFirst(); | | |||
433 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | | |||
434 | QCOMPARE(args.at(1).toInt(), 0); | | |||
435 | QCOMPARE(args.at(2).toInt(), 0); | | |||
436 | QCOMPARE(spy_removed.count(), 1); | 407 | QCOMPARE(spy_removed.count(), 1); | ||
437 | args = spy_removed.takeFirst(); | 408 | args = spy_removed.takeFirst(); | ||
438 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 409 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
439 | QCOMPARE(args.at(1).toInt(), 3); | 410 | QCOMPARE(args.at(1).toInt(), 0); | ||
440 | QCOMPARE(args.at(2).toInt(), 3); | 411 | QCOMPARE(args.at(2).toInt(), 0); | ||
441 | 412 | | |||
442 | // Move the root in the list (at its original place) | 413 | // Move home at the beginning of the list (at its original place) | ||
443 | root.moveBookmark(system_root, before_system_root); | 414 | root.moveBookmark(system_home, KBookmark()); | ||
444 | bookmarkManager->emitChanged(root); | 415 | bookmarkManager->emitChanged(root); | ||
445 | urls.clear(); | 416 | urls.clear(); | ||
446 | urls << initialListOfPlaces() | 417 | urls << initialListOfPlaces() | ||
447 | << initialListOfShared() | 418 | << initialListOfShared() | ||
448 | << initialListOfDevices() | 419 | << initialListOfDevices() | ||
449 | << initialListOfRemovableDevices(); | 420 | << initialListOfRemovableDevices(); | ||
450 | CHECK_PLACES_URLS(urls); | 421 | CHECK_PLACES_URLS(urls); | ||
451 | QCOMPARE(spy_inserted.count(), 1); | 422 | QCOMPARE(spy_inserted.count(), 1); | ||
452 | args = spy_inserted.takeFirst(); | 423 | args = spy_inserted.takeFirst(); | ||
453 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 424 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
454 | QCOMPARE(args.at(1).toInt(), 1); | 425 | QCOMPARE(args.at(1).toInt(), 1); | ||
455 | QCOMPARE(args.at(2).toInt(), 1); | 426 | QCOMPARE(args.at(2).toInt(), 1); | ||
456 | QCOMPARE(spy_removed.count(), 1); | 427 | QCOMPARE(spy_removed.count(), 1); | ||
457 | args = spy_removed.takeFirst(); | 428 | args = spy_removed.takeFirst(); | ||
458 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 429 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
459 | QCOMPARE(args.at(1).toInt(), 0); | 430 | QCOMPARE(args.at(1).toInt(), 0); | ||
460 | QCOMPARE(args.at(2).toInt(), 0); | 431 | QCOMPARE(args.at(2).toInt(), 0); | ||
461 | } | 432 | } | ||
462 | 433 | | |||
434 | | ||||
463 | void KFilePlacesModelTest::testDragAndDrop() | 435 | void KFilePlacesModelTest::testDragAndDrop() | ||
464 | { | 436 | { | ||
465 | QList<QVariant> args; | 437 | QList<QVariant> args; | ||
466 | QSignalSpy spy_moved(m_places, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int))); | 438 | QSignalSpy spy_moved(m_places, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int))); | ||
467 | 439 | | |||
468 | // Monitor rowsInserted() and rowsRemoved() to ensure they are never emitted: | 440 | // Monitor rowsInserted() and rowsRemoved() to ensure they are never emitted: | ||
469 | // Moving with drag and drop is expected to emit rowsMoved() | 441 | // Moving with drag and drop is expected to emit rowsMoved() | ||
470 | QSignalSpy spy_inserted(m_places, SIGNAL(rowsInserted(QModelIndex,int,int))); | 442 | QSignalSpy spy_inserted(m_places, SIGNAL(rowsInserted(QModelIndex,int,int))); | ||
471 | QSignalSpy spy_removed(m_places, SIGNAL(rowsRemoved(QModelIndex,int,int))); | 443 | QSignalSpy spy_removed(m_places, SIGNAL(rowsRemoved(QModelIndex,int,int))); | ||
472 | 444 | | |||
473 | // Move the KDE_ROOT_PATH at the end of the places list | 445 | | ||
446 | // Move /home at the end of the places list | ||||
474 | QModelIndexList indexes; | 447 | QModelIndexList indexes; | ||
475 | indexes << m_places->index(1, 0); | 448 | indexes << m_places->index(0, 0); | ||
476 | QMimeData *mimeData = m_places->mimeData(indexes); | 449 | QMimeData *mimeData = m_places->mimeData(indexes); | ||
477 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 3, 0, QModelIndex())); | 450 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 2, 0, QModelIndex())); | ||
478 | 451 | | |||
479 | QStringList urls; | 452 | QStringList urls; | ||
480 | urls << QDir::homePath() << QStringLiteral("trash:/") << QStringLiteral(KDE_ROOT_PATH) | 453 | urls << QStringLiteral("trash:/") << QDir::homePath() | ||
481 | << initialListOfShared() | 454 | << initialListOfShared() | ||
482 | << initialListOfDevices() | 455 | << initialListOfDevices() | ||
483 | << initialListOfRemovableDevices(); | 456 | << initialListOfRemovableDevices(); | ||
484 | CHECK_PLACES_URLS(urls); | 457 | CHECK_PLACES_URLS(urls); | ||
485 | QCOMPARE(spy_inserted.count(), 0); | 458 | QCOMPARE(spy_inserted.count(), 0); | ||
486 | QCOMPARE(spy_removed.count(), 0); | 459 | QCOMPARE(spy_removed.count(), 0); | ||
487 | QCOMPARE(spy_moved.count(), 1); | 460 | QCOMPARE(spy_moved.count(), 1); | ||
488 | args = spy_moved.takeFirst(); | 461 | args = spy_moved.takeFirst(); | ||
489 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 462 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
490 | QCOMPARE(args.at(1).toInt(), 1); | 463 | QCOMPARE(args.at(1).toInt(), 0); | ||
491 | QCOMPARE(args.at(2).toInt(), 1); | 464 | QCOMPARE(args.at(2).toInt(), 0); | ||
492 | QCOMPARE(args.at(3).toModelIndex(), QModelIndex()); | 465 | QCOMPARE(args.at(3).toModelIndex(), QModelIndex()); | ||
493 | QCOMPARE(args.at(4).toInt(), 3); | 466 | QCOMPARE(args.at(4).toInt(), 2); | ||
494 | 467 | | |||
495 | // Move the KDE_ROOT_PATH at the beginning of the list | 468 | // Move home back at the beginning of the list | ||
496 | indexes.clear(); | 469 | indexes.clear(); | ||
497 | indexes << m_places->index(2, 0); | 470 | indexes << m_places->index(1, 0); | ||
498 | mimeData = m_places->mimeData(indexes); | 471 | mimeData = m_places->mimeData(indexes); | ||
499 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 0, 0, QModelIndex())); | 472 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 0, 0, QModelIndex())); | ||
500 | 473 | | |||
501 | urls.clear(); | 474 | urls.clear(); | ||
502 | urls << QStringLiteral(KDE_ROOT_PATH) << QDir::homePath() << QStringLiteral("trash:/") | 475 | urls << QDir::homePath() << QStringLiteral("trash:/") | ||
503 | << initialListOfShared() | 476 | << initialListOfShared() | ||
504 | << initialListOfDevices() | 477 | << initialListOfDevices() | ||
505 | << initialListOfRemovableDevices(); | 478 | << initialListOfRemovableDevices(); | ||
506 | CHECK_PLACES_URLS(urls); | 479 | CHECK_PLACES_URLS(urls); | ||
507 | QCOMPARE(spy_inserted.count(), 0); | 480 | QCOMPARE(spy_inserted.count(), 0); | ||
508 | QCOMPARE(spy_removed.count(), 0); | 481 | QCOMPARE(spy_removed.count(), 0); | ||
509 | QCOMPARE(spy_moved.count(), 1); | 482 | QCOMPARE(spy_moved.count(), 1); | ||
510 | args = spy_moved.takeFirst(); | 483 | args = spy_moved.takeFirst(); | ||
511 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 484 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
512 | QCOMPARE(args.at(1).toInt(), 2); | 485 | QCOMPARE(args.at(1).toInt(), 1); | ||
513 | QCOMPARE(args.at(2).toInt(), 2); | 486 | QCOMPARE(args.at(2).toInt(), 1); | ||
514 | QCOMPARE(args.at(3).toModelIndex(), QModelIndex()); | 487 | QCOMPARE(args.at(3).toModelIndex(), QModelIndex()); | ||
515 | QCOMPARE(args.at(4).toInt(), 0); | 488 | QCOMPARE(args.at(4).toInt(), 0); | ||
516 | 489 | | |||
517 | // Move the KDE_ROOT_PATH in the list (at its original place) | | |||
518 | indexes.clear(); | | |||
519 | indexes << m_places->index(0, 0); | | |||
520 | mimeData = m_places->mimeData(indexes); | | |||
521 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 2, 0, QModelIndex())); | | |||
522 | | ||||
523 | urls.clear(); | | |||
524 | urls << initialListOfPlaces() | | |||
525 | << initialListOfShared() | | |||
526 | << initialListOfDevices() | | |||
527 | << initialListOfRemovableDevices(); | | |||
528 | CHECK_PLACES_URLS(urls); | | |||
529 | QCOMPARE(spy_inserted.count(), 0); | | |||
530 | QCOMPARE(spy_removed.count(), 0); | | |||
531 | QCOMPARE(spy_moved.count(), 1); | | |||
532 | args = spy_moved.takeFirst(); | | |||
533 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | | |||
534 | QCOMPARE(args.at(1).toInt(), 0); | | |||
535 | QCOMPARE(args.at(2).toInt(), 0); | | |||
536 | QCOMPARE(args.at(3).toModelIndex(), QModelIndex()); | | |||
537 | QCOMPARE(args.at(4).toInt(), 2); | | |||
538 | | ||||
539 | // Dropping on an item is not allowed | 490 | // Dropping on an item is not allowed | ||
540 | indexes.clear(); | 491 | indexes.clear(); | ||
541 | indexes << m_places->index(4, 0); | 492 | indexes << m_places->index(4, 0); | ||
542 | mimeData = m_places->mimeData(indexes); | 493 | mimeData = m_places->mimeData(indexes); | ||
543 | QVERIFY(!m_places->dropMimeData(mimeData, Qt::MoveAction, -1, 0, m_places->index(2, 0))); | 494 | QVERIFY(!m_places->dropMimeData(mimeData, Qt::MoveAction, -1, 0, m_places->index(2, 0))); | ||
544 | CHECK_PLACES_URLS(urls); | 495 | CHECK_PLACES_URLS(urls); | ||
545 | QCOMPARE(spy_inserted.count(), 0); | 496 | QCOMPARE(spy_inserted.count(), 0); | ||
546 | QCOMPARE(spy_removed.count(), 0); | 497 | QCOMPARE(spy_removed.count(), 0); | ||
Show All 13 Lines | 502 | { | |||
560 | urls << initialListOfPlaces() << QStringLiteral("/home/foo") | 511 | urls << initialListOfPlaces() << QStringLiteral("/home/foo") | ||
561 | << initialListOfShared() | 512 | << initialListOfShared() | ||
562 | << initialListOfDevices() | 513 | << initialListOfDevices() | ||
563 | << initialListOfRemovableDevices(); | 514 | << initialListOfRemovableDevices(); | ||
564 | CHECK_PLACES_URLS(urls); | 515 | CHECK_PLACES_URLS(urls); | ||
565 | QCOMPARE(spy_inserted.count(), 1); | 516 | QCOMPARE(spy_inserted.count(), 1); | ||
566 | args = spy_inserted.takeFirst(); | 517 | args = spy_inserted.takeFirst(); | ||
567 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 518 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
568 | QCOMPARE(args.at(1).toInt(), 3); | 519 | QCOMPARE(args.at(1).toInt(), 2); | ||
569 | QCOMPARE(args.at(2).toInt(), 3); | 520 | QCOMPARE(args.at(2).toInt(), 2); | ||
570 | QCOMPARE(spy_removed.count(), 0); | 521 | QCOMPARE(spy_removed.count(), 0); | ||
571 | 522 | | |||
572 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | 523 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | ||
573 | KBookmarkGroup root = bookmarkManager->root(); | 524 | KBookmarkGroup root = bookmarkManager->root(); | ||
574 | KBookmark before_trash = m_places->bookmarkForIndex(m_places->index(1, 0)); | 525 | KBookmark before_trash = m_places->bookmarkForIndex(m_places->index(0, 0)); | ||
575 | KBookmark foo = m_places->bookmarkForIndex(m_places->index(3, 0)); | 526 | KBookmark foo = m_places->bookmarkForIndex(m_places->index(2, 0)); | ||
576 | 527 | | |||
577 | root.moveBookmark(foo, before_trash); | 528 | root.moveBookmark(foo, before_trash); | ||
578 | bookmarkManager->emitChanged(root); | 529 | bookmarkManager->emitChanged(root); | ||
579 | 530 | | |||
580 | urls.clear(); | 531 | urls.clear(); | ||
581 | urls << QDir::homePath() << QStringLiteral(KDE_ROOT_PATH) << QStringLiteral("/home/foo") << QStringLiteral("trash:/") | 532 | urls << QDir::homePath() << QStringLiteral("/home/foo") << QStringLiteral("trash:/") | ||
582 | << initialListOfShared() | 533 | << initialListOfShared() | ||
583 | << initialListOfDevices() | 534 | << initialListOfDevices() | ||
584 | << initialListOfRemovableDevices(); | 535 | << initialListOfRemovableDevices(); | ||
585 | CHECK_PLACES_URLS(urls); | 536 | CHECK_PLACES_URLS(urls); | ||
586 | QCOMPARE(spy_inserted.count(), 1); | 537 | QCOMPARE(spy_inserted.count(), 1); | ||
587 | args = spy_inserted.takeFirst(); | 538 | args = spy_inserted.takeFirst(); | ||
588 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 539 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
589 | QCOMPARE(args.at(1).toInt(), 3); | 540 | QCOMPARE(args.at(1).toInt(), 2); | ||
590 | QCOMPARE(args.at(2).toInt(), 3); | 541 | QCOMPARE(args.at(2).toInt(), 2); | ||
591 | QCOMPARE(spy_removed.count(), 1); | 542 | QCOMPARE(spy_removed.count(), 1); | ||
592 | args = spy_removed.takeFirst(); | 543 | args = spy_removed.takeFirst(); | ||
593 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 544 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
594 | QCOMPARE(args.at(1).toInt(), 2); | 545 | QCOMPARE(args.at(1).toInt(), 1); | ||
595 | QCOMPARE(args.at(2).toInt(), 2); | 546 | QCOMPARE(args.at(2).toInt(), 1); | ||
596 | 547 | | |||
597 | m_places->editPlace(m_places->index(2, 0), QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/mnt/foo"))); | 548 | m_places->editPlace(m_places->index(1, 0), QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/mnt/foo"))); | ||
598 | 549 | | |||
599 | urls.clear(); | 550 | urls.clear(); | ||
600 | urls << QDir::homePath() << QStringLiteral(KDE_ROOT_PATH) << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") | 551 | urls << QDir::homePath() << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") | ||
601 | << initialListOfShared() | 552 | << initialListOfShared() | ||
602 | << initialListOfDevices() | 553 | << initialListOfDevices() | ||
603 | << initialListOfRemovableDevices(); | 554 | << initialListOfRemovableDevices(); | ||
604 | CHECK_PLACES_URLS(urls); | 555 | CHECK_PLACES_URLS(urls); | ||
605 | QCOMPARE(spy_inserted.count(), 0); | 556 | QCOMPARE(spy_inserted.count(), 0); | ||
606 | QCOMPARE(spy_removed.count(), 0); | 557 | QCOMPARE(spy_removed.count(), 0); | ||
607 | QCOMPARE(spy_changed.count(), 1); | 558 | QCOMPARE(spy_changed.count(), 1); | ||
608 | args = spy_changed.takeFirst(); | 559 | args = spy_changed.takeFirst(); | ||
609 | QCOMPARE(args.at(0).toModelIndex(), m_places->index(2, 0)); | 560 | QCOMPARE(args.at(0).toModelIndex(), m_places->index(1, 0)); | ||
610 | QCOMPARE(args.at(1).toModelIndex(), m_places->index(2, 0)); | 561 | QCOMPARE(args.at(1).toModelIndex(), m_places->index(1, 0)); | ||
611 | 562 | | |||
612 | foo = m_places->bookmarkForIndex(m_places->index(2, 0)); | 563 | foo = m_places->bookmarkForIndex(m_places->index(1, 0)); | ||
613 | foo.setFullText(QStringLiteral("Bar")); | 564 | foo.setFullText(QStringLiteral("Bar")); | ||
614 | bookmarkManager->notifyCompleteChange(QString()); | 565 | bookmarkManager->notifyCompleteChange(QString()); | ||
615 | 566 | | |||
616 | urls.clear(); | 567 | urls.clear(); | ||
617 | urls << QDir::homePath() << QStringLiteral(KDE_ROOT_PATH) << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") | 568 | urls << QDir::homePath() << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") | ||
618 | << initialListOfShared() | 569 | << initialListOfShared() | ||
619 | << initialListOfDevices() | 570 | << initialListOfDevices() | ||
620 | << initialListOfRemovableDevices(); | 571 | << initialListOfRemovableDevices(); | ||
621 | 572 | | |||
622 | CHECK_PLACES_URLS(urls); | 573 | CHECK_PLACES_URLS(urls); | ||
623 | QCOMPARE(spy_inserted.count(), 0); | 574 | QCOMPARE(spy_inserted.count(), 0); | ||
624 | QCOMPARE(spy_removed.count(), 0); | 575 | QCOMPARE(spy_removed.count(), 0); | ||
625 | QCOMPARE(spy_changed.count(), 10); | 576 | QCOMPARE(spy_changed.count(), 9); | ||
626 | args = spy_changed[2]; | 577 | args = spy_changed[2]; | ||
627 | QCOMPARE(args.at(0).toModelIndex(), m_places->index(2, 0)); | 578 | QCOMPARE(args.at(0).toModelIndex(), m_places->index(2, 0)); | ||
628 | QCOMPARE(args.at(1).toModelIndex(), m_places->index(2, 0)); | 579 | QCOMPARE(args.at(1).toModelIndex(), m_places->index(2, 0)); | ||
629 | spy_changed.clear(); | 580 | spy_changed.clear(); | ||
630 | 581 | | |||
631 | m_places->removePlace(m_places->index(2, 0)); | 582 | m_places->removePlace(m_places->index(1, 0)); | ||
632 | 583 | | |||
633 | urls.clear(); | 584 | urls.clear(); | ||
634 | urls << initialListOfPlaces() | 585 | urls << initialListOfPlaces() | ||
635 | << initialListOfShared() | 586 | << initialListOfShared() | ||
636 | << initialListOfDevices() | 587 | << initialListOfDevices() | ||
637 | << initialListOfRemovableDevices(); | 588 | << initialListOfRemovableDevices(); | ||
638 | CHECK_PLACES_URLS(urls); | 589 | CHECK_PLACES_URLS(urls); | ||
639 | QCOMPARE(spy_inserted.count(), 0); | 590 | QCOMPARE(spy_inserted.count(), 0); | ||
640 | QCOMPARE(spy_removed.count(), 1); | 591 | QCOMPARE(spy_removed.count(), 1); | ||
641 | args = spy_removed.takeFirst(); | 592 | args = spy_removed.takeFirst(); | ||
642 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 593 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
643 | QCOMPARE(args.at(1).toInt(), 2); | 594 | QCOMPARE(args.at(1).toInt(), 1); | ||
644 | QCOMPARE(args.at(2).toInt(), 2); | 595 | QCOMPARE(args.at(2).toInt(), 1); | ||
645 | 596 | | |||
646 | m_places->addPlace(QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/home/foo")), QString(), QString(), m_places->index(0, 0)); | 597 | m_places->addPlace(QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/home/foo")), QString(), QString(), m_places->index(0, 0)); | ||
647 | 598 | | |||
648 | urls.clear(); | 599 | urls.clear(); | ||
649 | urls << QDir::homePath() << QStringLiteral("/home/foo") << QStringLiteral(KDE_ROOT_PATH) << QStringLiteral("trash:/") | 600 | urls << QDir::homePath() << QStringLiteral("/home/foo") << QStringLiteral("trash:/") | ||
650 | << initialListOfShared() | 601 | << initialListOfShared() | ||
651 | << initialListOfDevices() | 602 | << initialListOfDevices() | ||
652 | << initialListOfRemovableDevices(); | 603 | << initialListOfRemovableDevices(); | ||
653 | CHECK_PLACES_URLS(urls); | 604 | CHECK_PLACES_URLS(urls); | ||
654 | QCOMPARE(spy_inserted.count(), 1); | 605 | QCOMPARE(spy_inserted.count(), 1); | ||
655 | args = spy_inserted.takeFirst(); | 606 | args = spy_inserted.takeFirst(); | ||
656 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 607 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
657 | QCOMPARE(args.at(1).toInt(), 1); | 608 | QCOMPARE(args.at(1).toInt(), 1); | ||
Show All 16 Lines | 624 | urls << initialListOfPlaces() | |||
674 | << initialListOfShared() | 625 | << initialListOfShared() | ||
675 | << initialListOfDevices() | 626 | << initialListOfDevices() | ||
676 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | 627 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | ||
677 | CHECK_PLACES_URLS(urls); | 628 | CHECK_PLACES_URLS(urls); | ||
678 | QCOMPARE(spy_inserted.count(), 0); | 629 | QCOMPARE(spy_inserted.count(), 0); | ||
679 | QCOMPARE(spy_removed.count(), 1); | 630 | QCOMPARE(spy_removed.count(), 1); | ||
680 | args = spy_removed.takeFirst(); | 631 | args = spy_removed.takeFirst(); | ||
681 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 632 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
682 | QCOMPARE(args.at(1).toInt(), 7); | 633 | QCOMPARE(args.at(1).toInt(), 6); | ||
683 | QCOMPARE(args.at(2).toInt(), 7); | 634 | QCOMPARE(args.at(2).toInt(), 6); | ||
684 | 635 | | |||
685 | fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | 636 | fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | ||
686 | 637 | | |||
687 | urls.clear(); | 638 | urls.clear(); | ||
688 | urls << initialListOfPlaces() | 639 | urls << initialListOfPlaces() | ||
689 | << initialListOfShared() | 640 | << initialListOfShared() | ||
690 | << initialListOfDevices() | 641 | << initialListOfDevices() | ||
691 | << initialListOfRemovableDevices(); | 642 | << initialListOfRemovableDevices(); | ||
692 | CHECK_PLACES_URLS(urls); | 643 | CHECK_PLACES_URLS(urls); | ||
693 | QCOMPARE(spy_inserted.count(), 1); | 644 | QCOMPARE(spy_inserted.count(), 1); | ||
694 | args = spy_inserted.takeFirst(); | 645 | args = spy_inserted.takeFirst(); | ||
695 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 646 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
696 | QCOMPARE(args.at(1).toInt(), 7); | 647 | QCOMPARE(args.at(1).toInt(), 6); | ||
697 | QCOMPARE(args.at(2).toInt(), 7); | 648 | QCOMPARE(args.at(2).toInt(), 6); | ||
698 | QCOMPARE(spy_removed.count(), 0); | 649 | QCOMPARE(spy_removed.count(), 0); | ||
699 | 650 | | |||
700 | // Move the device in the list, and check that it memorizes the position across plug/unplug | 651 | // Move the device in the list, and check that it memorizes the position across plug/unplug | ||
701 | 652 | | |||
702 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | 653 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | ||
703 | KBookmarkGroup root = bookmarkManager->root(); | 654 | KBookmarkGroup root = bookmarkManager->root(); | ||
704 | KBookmark before_floppy; | 655 | KBookmark before_floppy; | ||
705 | 656 | | |||
706 | KBookmark device = root.first(); // The device we'll move is the 7th bookmark | 657 | KBookmark device = root.first(); // The device we'll move is the 6th bookmark | ||
707 | for (int i = 0; i < 6; i++) { | 658 | for (int i = 0; i < 5; i++) { | ||
708 | if (i == 3) { | 659 | if (i == 2) { | ||
709 | // store item before to be able to move it back to original position | 660 | // store item before to be able to move it back to original position | ||
710 | device = before_floppy = root.next(device); | 661 | device = before_floppy = root.next(device); | ||
711 | } else { | 662 | } else { | ||
712 | device = root.next(device); | 663 | device = root.next(device); | ||
713 | } | 664 | } | ||
714 | } | 665 | } | ||
715 | 666 | | |||
716 | root.moveBookmark(device, before_floppy); | 667 | root.moveBookmark(device, before_floppy); | ||
717 | bookmarkManager->emitChanged(root); | 668 | bookmarkManager->emitChanged(root); | ||
718 | 669 | | |||
719 | urls.clear(); | 670 | urls.clear(); | ||
720 | urls << initialListOfPlaces() | 671 | urls << initialListOfPlaces() | ||
721 | << initialListOfShared() | 672 | << initialListOfShared() | ||
722 | << initialListOfDevices() | 673 | << initialListOfDevices() | ||
723 | << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | 674 | << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | ||
724 | CHECK_PLACES_URLS(urls); | 675 | CHECK_PLACES_URLS(urls); | ||
725 | QCOMPARE(spy_inserted.count(), 1); | 676 | QCOMPARE(spy_inserted.count(), 1); | ||
726 | args = spy_inserted.takeFirst(); | 677 | args = spy_inserted.takeFirst(); | ||
727 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 678 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
728 | QCOMPARE(args.at(1).toInt(), 7); | 679 | QCOMPARE(args.at(1).toInt(), 6); | ||
729 | QCOMPARE(args.at(2).toInt(), 7); | 680 | QCOMPARE(args.at(2).toInt(), 6); | ||
730 | QCOMPARE(spy_removed.count(), 1); | 681 | QCOMPARE(spy_removed.count(), 1); | ||
731 | args = spy_removed.takeFirst(); | 682 | args = spy_removed.takeFirst(); | ||
732 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 683 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
733 | QCOMPARE(args.at(1).toInt(), 6); | 684 | QCOMPARE(args.at(1).toInt(), 5); | ||
734 | QCOMPARE(args.at(2).toInt(), 6); | 685 | QCOMPARE(args.at(2).toInt(), 5); | ||
735 | 686 | | |||
736 | fakeManager()->call(QStringLiteral("unplug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | 687 | fakeManager()->call(QStringLiteral("unplug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | ||
737 | 688 | | |||
738 | urls.clear(); | 689 | urls.clear(); | ||
739 | urls << initialListOfPlaces() | 690 | urls << initialListOfPlaces() | ||
740 | << initialListOfShared() | 691 | << initialListOfShared() | ||
741 | << initialListOfDevices() | 692 | << initialListOfDevices() | ||
742 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | 693 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | ||
743 | CHECK_PLACES_URLS(urls); | 694 | CHECK_PLACES_URLS(urls); | ||
744 | QCOMPARE(spy_inserted.count(), 0); | 695 | QCOMPARE(spy_inserted.count(), 0); | ||
745 | QCOMPARE(spy_removed.count(), 1); | 696 | QCOMPARE(spy_removed.count(), 1); | ||
746 | args = spy_removed.takeFirst(); | 697 | args = spy_removed.takeFirst(); | ||
747 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 698 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
748 | QCOMPARE(args.at(1).toInt(), 6); | 699 | QCOMPARE(args.at(1).toInt(), 5); | ||
749 | QCOMPARE(args.at(2).toInt(), 6); | 700 | QCOMPARE(args.at(2).toInt(), 5); | ||
750 | 701 | | |||
751 | fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | 702 | fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | ||
752 | 703 | | |||
753 | urls.clear(); | 704 | urls.clear(); | ||
754 | urls << initialListOfPlaces() | 705 | urls << initialListOfPlaces() | ||
755 | << initialListOfShared() | 706 | << initialListOfShared() | ||
756 | << initialListOfDevices() << QStringLiteral("/media/XO-Y4") | 707 | << initialListOfDevices() << QStringLiteral("/media/XO-Y4") | ||
757 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | 708 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | ||
758 | CHECK_PLACES_URLS(urls); | 709 | CHECK_PLACES_URLS(urls); | ||
759 | QCOMPARE(spy_inserted.count(), 1); | 710 | QCOMPARE(spy_inserted.count(), 1); | ||
760 | args = spy_inserted.takeFirst(); | 711 | args = spy_inserted.takeFirst(); | ||
761 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 712 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
762 | QCOMPARE(args.at(1).toInt(), 6); | 713 | QCOMPARE(args.at(1).toInt(), 5); | ||
763 | QCOMPARE(args.at(2).toInt(), 6); | 714 | QCOMPARE(args.at(2).toInt(), 5); | ||
764 | QCOMPARE(spy_removed.count(), 0); | 715 | QCOMPARE(spy_removed.count(), 0); | ||
765 | 716 | | |||
766 | KBookmark seventh = root.first(); | 717 | KBookmark sixth = root.first(); | ||
767 | for (int i = 0; i < 6; i++) { | 718 | for (int i = 0; i < 5; i++) { | ||
768 | seventh = root.next(seventh); | 719 | sixth = root.next(sixth); | ||
769 | } | 720 | } | ||
770 | root.moveBookmark(device, seventh); | 721 | root.moveBookmark(device, sixth); | ||
771 | bookmarkManager->emitChanged(root); | 722 | bookmarkManager->emitChanged(root); | ||
772 | 723 | | |||
773 | urls.clear(); | 724 | urls.clear(); | ||
774 | urls << initialListOfPlaces() | 725 | urls << initialListOfPlaces() | ||
775 | << initialListOfShared() | 726 | << initialListOfShared() | ||
776 | << initialListOfDevices() | 727 | << initialListOfDevices() | ||
777 | << initialListOfRemovableDevices(); | 728 | << initialListOfRemovableDevices(); | ||
778 | CHECK_PLACES_URLS(urls); | 729 | CHECK_PLACES_URLS(urls); | ||
779 | QCOMPARE(spy_inserted.count(), 1); | 730 | QCOMPARE(spy_inserted.count(), 1); | ||
780 | args = spy_inserted.takeFirst(); | 731 | args = spy_inserted.takeFirst(); | ||
781 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 732 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
782 | QCOMPARE(args.at(1).toInt(), 7); | 733 | QCOMPARE(args.at(1).toInt(), 6); | ||
783 | QCOMPARE(args.at(2).toInt(), 7); | 734 | QCOMPARE(args.at(2).toInt(), 6); | ||
784 | QCOMPARE(spy_removed.count(), 1); | 735 | QCOMPARE(spy_removed.count(), 1); | ||
785 | args = spy_removed.takeFirst(); | 736 | args = spy_removed.takeFirst(); | ||
786 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 737 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
787 | QCOMPARE(args.at(1).toInt(), 6); | 738 | QCOMPARE(args.at(1).toInt(), 5); | ||
788 | QCOMPARE(args.at(2).toInt(), 6); | 739 | QCOMPARE(args.at(2).toInt(), 5); | ||
789 | } | 740 | } | ||
790 | 741 | | |||
791 | void KFilePlacesModelTest::testDeviceSetupTeardown() | 742 | void KFilePlacesModelTest::testDeviceSetupTeardown() | ||
792 | { | 743 | { | ||
793 | QList<QVariant> args; | 744 | QList<QVariant> args; | ||
794 | QSignalSpy spy_changed(m_places, SIGNAL(dataChanged(QModelIndex,QModelIndex))); | 745 | QSignalSpy spy_changed(m_places, SIGNAL(dataChanged(QModelIndex,QModelIndex))); | ||
795 | 746 | | |||
796 | fakeDevice(QStringLiteral("/org/kde/solid/fakehw/volume_part1_size_993284096/StorageAccess"))->call(QStringLiteral("teardown")); | 747 | fakeDevice(QStringLiteral("/org/kde/solid/fakehw/volume_part1_size_993284096/StorageAccess"))->call(QStringLiteral("teardown")); | ||
797 | 748 | | |||
798 | QCOMPARE(spy_changed.count(), 1); | 749 | QCOMPARE(spy_changed.count(), 1); | ||
799 | args = spy_changed.takeFirst(); | 750 | args = spy_changed.takeFirst(); | ||
800 | QCOMPARE(args.at(0).toModelIndex().row(), 7); | 751 | QCOMPARE(args.at(0).toModelIndex().row(), 6); | ||
801 | QCOMPARE(args.at(1).toModelIndex().row(), 7); | 752 | QCOMPARE(args.at(1).toModelIndex().row(), 6); | ||
802 | 753 | | |||
803 | fakeDevice(QStringLiteral("/org/kde/solid/fakehw/volume_part1_size_993284096/StorageAccess"))->call(QStringLiteral("setup")); | 754 | fakeDevice(QStringLiteral("/org/kde/solid/fakehw/volume_part1_size_993284096/StorageAccess"))->call(QStringLiteral("setup")); | ||
804 | 755 | | |||
805 | QCOMPARE(spy_changed.count(), 1); | 756 | QCOMPARE(spy_changed.count(), 1); | ||
806 | args = spy_changed.takeFirst(); | 757 | args = spy_changed.takeFirst(); | ||
807 | QCOMPARE(args.at(0).toModelIndex().row(), 7); | 758 | QCOMPARE(args.at(0).toModelIndex().row(), 6); | ||
808 | QCOMPARE(args.at(1).toModelIndex().row(), 7); | 759 | QCOMPARE(args.at(1).toModelIndex().row(), 6); | ||
809 | } | 760 | } | ||
810 | 761 | | |||
811 | void KFilePlacesModelTest::testEnableBaloo() | 762 | void KFilePlacesModelTest::testEnableBaloo() | ||
812 | { | 763 | { | ||
813 | KConfig config(QStringLiteral("baloofilerc")); | 764 | KConfig config(QStringLiteral("baloofilerc")); | ||
814 | KConfigGroup basicSettings = config.group("Basic Settings"); | 765 | KConfigGroup basicSettings = config.group("Basic Settings"); | ||
815 | basicSettings.writeEntry("Indexing-Enabled", true); | 766 | basicSettings.writeEntry("Indexing-Enabled", true); | ||
816 | config.sync(); | 767 | config.sync(); | ||
Show All 15 Lines | |||||
832 | } | 783 | } | ||
833 | 784 | | |||
834 | void KFilePlacesModelTest::testRemoteUrls_data() | 785 | void KFilePlacesModelTest::testRemoteUrls_data() | ||
835 | { | 786 | { | ||
836 | QTest::addColumn<QUrl>("url"); | 787 | QTest::addColumn<QUrl>("url"); | ||
837 | QTest::addColumn<int>("expectedRow"); | 788 | QTest::addColumn<int>("expectedRow"); | ||
838 | QTest::addColumn<QString>("expectedGroup"); | 789 | QTest::addColumn<QString>("expectedGroup"); | ||
839 | 790 | | |||
840 | QTest::newRow("Ftp") << QUrl(QStringLiteral("ftp://192.168.1.1/ftp")) << 5 << QStringLiteral("Remote"); | 791 | QTest::newRow("Ftp") << QUrl(QStringLiteral("ftp://192.168.1.1/ftp")) << 4 << QStringLiteral("Remote"); | ||
841 | QTest::newRow("Samba") << QUrl(QStringLiteral("smb://192.168.1.1/share")) << 5 << QStringLiteral("Remote"); | 792 | QTest::newRow("Samba") << QUrl(QStringLiteral("smb://192.168.1.1/share")) << 4 << QStringLiteral("Remote"); | ||
842 | QTest::newRow("Sftp") << QUrl(QStringLiteral("sftp://192.168.1.1/share")) << 5 << QStringLiteral("Remote"); | 793 | QTest::newRow("Sftp") << QUrl(QStringLiteral("sftp://192.168.1.1/share")) << 4 << QStringLiteral("Remote"); | ||
843 | QTest::newRow("Fish") << QUrl(QStringLiteral("fish://192.168.1.1/share")) << 5 << QStringLiteral("Remote"); | 794 | QTest::newRow("Fish") << QUrl(QStringLiteral("fish://192.168.1.1/share")) << 4 << QStringLiteral("Remote"); | ||
844 | QTest::newRow("Webdav") << QUrl(QStringLiteral("webdav://192.168.1.1/share")) << 5 << QStringLiteral("Remote"); | 795 | QTest::newRow("Webdav") << QUrl(QStringLiteral("webdav://192.168.1.1/share")) << 4 << QStringLiteral("Remote"); | ||
845 | } | 796 | } | ||
846 | 797 | | |||
847 | void KFilePlacesModelTest::testRemoteUrls() | 798 | void KFilePlacesModelTest::testRemoteUrls() | ||
848 | { | 799 | { | ||
849 | QFETCH(QUrl, url); | 800 | QFETCH(QUrl, url); | ||
850 | QFETCH(int, expectedRow); | 801 | QFETCH(int, expectedRow); | ||
851 | QFETCH(QString, expectedGroup); | 802 | QFETCH(QString, expectedGroup); | ||
852 | 803 | | |||
853 | QList<QVariant> args; | 804 | QList<QVariant> args; | ||
854 | QSignalSpy spy_inserted(m_places, SIGNAL(rowsInserted(QModelIndex,int,int))); | 805 | QSignalSpy spy_inserted(m_places, SIGNAL(rowsInserted(QModelIndex,int,int))); | ||
855 | 806 | | |||
856 | // insert a new network url | 807 | // insert a new network url | ||
857 | m_places->addPlace(QStringLiteral("My Shared"), url, QString(), QString(), QModelIndex()); | 808 | m_places->addPlace(QStringLiteral("My Shared"), url, QString(), QString(), QModelIndex()); | ||
858 | 809 | | |||
859 | // check if url list is correct after insertion | 810 | // check if url list is correct after insertion | ||
860 | QStringList urls; | 811 | QStringList urls; | ||
861 | urls << QDir::homePath() << QStringLiteral(KDE_ROOT_PATH) << QStringLiteral("trash:/") // places | 812 | urls << QDir::homePath() << QStringLiteral("trash:/") // places | ||
862 | << QStringLiteral("remote:/") << QStringLiteral("/media/nfs") | 813 | << QStringLiteral("remote:/") << QStringLiteral("/media/nfs") | ||
863 | << url.toString() << QStringLiteral("/foreign") | 814 | << url.toString() << QStringLiteral("/foreign") | ||
864 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | 815 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | ||
865 | CHECK_PLACES_URLS(urls); | 816 | CHECK_PLACES_URLS(urls); | ||
866 | 817 | | |||
867 | // check if the new url was inserted in the right position (end of "Remote" section) | 818 | // check if the new url was inserted in the right position (end of "Remote" section) | ||
868 | QTRY_COMPARE(spy_inserted.count(), 1); | 819 | QTRY_COMPARE(spy_inserted.count(), 1); | ||
869 | args = spy_inserted.takeFirst(); | 820 | args = spy_inserted.takeFirst(); | ||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Line(s) | |||||
975 | void KFilePlacesModelTest::testIconRole_data() | 926 | void KFilePlacesModelTest::testIconRole_data() | ||
976 | { | 927 | { | ||
977 | QTest::addColumn<QModelIndex>("index"); | 928 | QTest::addColumn<QModelIndex>("index"); | ||
978 | QTest::addColumn<QString>("expectedIconName"); | 929 | QTest::addColumn<QString>("expectedIconName"); | ||
979 | 930 | | |||
980 | // places | 931 | // places | ||
981 | QTest::newRow("Places - Home") << m_places->index(0, 0) | 932 | QTest::newRow("Places - Home") << m_places->index(0, 0) | ||
982 | << QStringLiteral("user-home"); | 933 | << QStringLiteral("user-home"); | ||
983 | QTest::newRow("Places - Root") << m_places->index(1, 0) | 934 | QTest::newRow("Places - Trash") << m_places->index(1, 0) | ||
984 | << QStringLiteral("folder-root"); | | |||
985 | QTest::newRow("Places - Trash") << m_places->index(2, 0) | | |||
986 | << QStringLiteral("user-trash"); | 935 | << QStringLiteral("user-trash"); | ||
987 | QTest::newRow("Remote - Network") << m_places->index(3, 0) | 936 | QTest::newRow("Remote - Network") << m_places->index(2, 0) | ||
988 | << QStringLiteral("folder-network"); | 937 | << QStringLiteral("folder-network"); | ||
989 | QTest::newRow("Devices - Nfs") << m_places->index(4, 0) | 938 | QTest::newRow("Devices - Nfs") << m_places->index(3, 0) | ||
990 | << QStringLiteral("hwinfo"); | 939 | << QStringLiteral("hwinfo"); | ||
991 | QTest::newRow("Devices - foreign") << m_places->index(5, 0) | 940 | QTest::newRow("Devices - foreign") << m_places->index(4, 0) | ||
992 | << QStringLiteral("blockdevice"); | 941 | << QStringLiteral("blockdevice"); | ||
993 | QTest::newRow("Devices - Floppy") << m_places->index(6, 0) | 942 | QTest::newRow("Devices - Floppy") << m_places->index(5, 0) | ||
994 | << QStringLiteral("blockdevice"); | 943 | << QStringLiteral("blockdevice"); | ||
995 | QTest::newRow("Devices - cdrom") << m_places->index(7, 0) | 944 | QTest::newRow("Devices - cdrom") << m_places->index(6, 0) | ||
996 | << QStringLiteral("blockdevice"); | 945 | << QStringLiteral("blockdevice"); | ||
997 | } | 946 | } | ||
998 | 947 | | |||
999 | void KFilePlacesModelTest::testIconRole() | 948 | void KFilePlacesModelTest::testIconRole() | ||
1000 | { | 949 | { | ||
1001 | QFETCH(QModelIndex, index); | 950 | QFETCH(QModelIndex, index); | ||
1002 | QFETCH(QString, expectedIconName); | 951 | QFETCH(QString, expectedIconName); | ||
1003 | 952 | | |||
1004 | QVERIFY(index.data(KFilePlacesModel::IconNameRole).toString().startsWith(expectedIconName)); | 953 | QVERIFY(index.data(KFilePlacesModel::IconNameRole).toString().startsWith(expectedIconName)); | ||
1005 | } | 954 | } | ||
1006 | 955 | | |||
1007 | void KFilePlacesModelTest::testMoveFunction() | 956 | void KFilePlacesModelTest::testMoveFunction() | ||
1008 | { | 957 | { | ||
1009 | QList<QVariant> args; | 958 | QList<QVariant> args; | ||
1010 | QStringList urls = initialListOfUrls(); | 959 | QStringList urls = initialListOfUrls(); | ||
1011 | QSignalSpy rowsMoved(m_places, &KFilePlacesModel::rowsMoved); | 960 | QSignalSpy rowsMoved(m_places, &KFilePlacesModel::rowsMoved); | ||
1012 | 961 | | |||
1013 | // move item 0 to pos 2 | 962 | // move item 0 to pos 1 | ||
1014 | QVERIFY(m_places->movePlace(0, 3)); | 963 | QVERIFY(m_places->movePlace(0, 2)); | ||
1015 | urls.move(0, 2); | 964 | urls.move(0, 1); | ||
1016 | QTRY_COMPARE(rowsMoved.count(), 1); | 965 | QTRY_COMPARE(rowsMoved.count(), 1); | ||
1017 | args = rowsMoved.takeFirst(); | 966 | args = rowsMoved.takeFirst(); | ||
1018 | QCOMPARE(args.at(1).toInt(), 0); // start | 967 | QCOMPARE(args.at(1).toInt(), 0); // start | ||
1019 | QCOMPARE(args.at(2).toInt(), 0); // end | 968 | QCOMPARE(args.at(2).toInt(), 0); // end | ||
1020 | QCOMPARE(args.at(4).toInt(), 3); // row (destination) | 969 | QCOMPARE(args.at(4).toInt(), 2); // row (destination) | ||
1021 | QCOMPARE(placesUrls(), urls); | 970 | QCOMPARE(placesUrls(), urls); | ||
1022 | rowsMoved.clear(); | 971 | rowsMoved.clear(); | ||
1023 | 972 | | |||
1024 | // move it back | 973 | // move it back | ||
1025 | QVERIFY(m_places->movePlace(2, 0)); | 974 | QVERIFY(m_places->movePlace(1, 0)); | ||
1026 | urls.move(2, 0); | 975 | urls.move(1, 0); | ||
1027 | QTRY_COMPARE(rowsMoved.count(), 1); | 976 | QTRY_COMPARE(rowsMoved.count(), 1); | ||
1028 | args = rowsMoved.takeFirst(); | 977 | args = rowsMoved.takeFirst(); | ||
1029 | QCOMPARE(args.at(1).toInt(), 2); // start | 978 | QCOMPARE(args.at(1).toInt(), 1); // start | ||
1030 | QCOMPARE(args.at(2).toInt(), 2); // end | 979 | QCOMPARE(args.at(2).toInt(), 1); // end | ||
1031 | QCOMPARE(args.at(4).toInt(), 0); // row (destination) | 980 | QCOMPARE(args.at(4).toInt(), 0); // row (destination) | ||
1032 | QCOMPARE(placesUrls(), urls); | 981 | QCOMPARE(placesUrls(), urls); | ||
1033 | rowsMoved.clear(); | 982 | rowsMoved.clear(); | ||
1034 | 983 | | |||
1035 | // target position is greater than model rows | 984 | // target position is greater than model rows | ||
1036 | // will move to the end of the first group | 985 | // will move to the end of the first group | ||
1037 | QVERIFY(m_places->movePlace(0, 20)); | 986 | QVERIFY(m_places->movePlace(0, 20)); | ||
1038 | urls.move(0, 2); | 987 | urls.move(0, 1); | ||
1039 | QTRY_COMPARE(rowsMoved.count(), 1); | 988 | QTRY_COMPARE(rowsMoved.count(), 1); | ||
1040 | args = rowsMoved.takeFirst(); | 989 | args = rowsMoved.takeFirst(); | ||
1041 | QCOMPARE(args.at(1).toInt(), 0); // start | 990 | QCOMPARE(args.at(1).toInt(), 0); // start | ||
1042 | QCOMPARE(args.at(2).toInt(), 0); // end | 991 | QCOMPARE(args.at(2).toInt(), 0); // end | ||
1043 | QCOMPARE(args.at(4).toInt(), 3); // row (destination) | 992 | QCOMPARE(args.at(4).toInt(), 2); // row (destination) | ||
1044 | QCOMPARE(placesUrls(), urls); | 993 | QCOMPARE(placesUrls(), urls); | ||
1045 | rowsMoved.clear(); | 994 | rowsMoved.clear(); | ||
1046 | 995 | | |||
1047 | // move it back | 996 | // move it back | ||
1048 | QVERIFY(m_places->movePlace(2, 0)); | 997 | QVERIFY(m_places->movePlace(1, 0)); | ||
1049 | urls.move(2, 0); | 998 | urls.move(1, 0); | ||
1050 | QTRY_COMPARE(rowsMoved.count(), 1); | 999 | QTRY_COMPARE(rowsMoved.count(), 1); | ||
1051 | args = rowsMoved.takeFirst(); | 1000 | args = rowsMoved.takeFirst(); | ||
1052 | QCOMPARE(args.at(1).toInt(), 2); // start | 1001 | QCOMPARE(args.at(1).toInt(), 1); // start | ||
1053 | QCOMPARE(args.at(2).toInt(), 2); // end | 1002 | QCOMPARE(args.at(2).toInt(), 1); // end | ||
1054 | QCOMPARE(args.at(4).toInt(), 0); // row (destination) | 1003 | QCOMPARE(args.at(4).toInt(), 0); // row (destination) | ||
1055 | QCOMPARE(placesUrls(), urls); | 1004 | QCOMPARE(placesUrls(), urls); | ||
1056 | rowsMoved.clear(); | 1005 | rowsMoved.clear(); | ||
1057 | 1006 | | |||
1058 | QVERIFY(m_places->movePlace(8, 6)); | 1007 | QVERIFY(m_places->movePlace(7, 5)); | ||
1059 | urls.move(8, 6); | 1008 | urls.move(7, 5); | ||
1060 | QTRY_COMPARE(rowsMoved.count(), 1); | 1009 | QTRY_COMPARE(rowsMoved.count(), 1); | ||
1061 | args = rowsMoved.takeFirst(); | 1010 | args = rowsMoved.takeFirst(); | ||
1062 | QCOMPARE(args.at(1).toInt(), 8); // start | 1011 | QCOMPARE(args.at(1).toInt(), 7); // start | ||
1063 | QCOMPARE(args.at(2).toInt(), 8); // end | 1012 | QCOMPARE(args.at(2).toInt(), 7); // end | ||
1064 | QCOMPARE(args.at(4).toInt(), 6); // row (destination) | 1013 | QCOMPARE(args.at(4).toInt(), 5); // row (destination) | ||
1065 | QCOMPARE(placesUrls(), urls); | 1014 | QCOMPARE(placesUrls(), urls); | ||
1066 | rowsMoved.clear(); | 1015 | rowsMoved.clear(); | ||
1067 | 1016 | | |||
1068 | // move it back | 1017 | // move it back | ||
1069 | QVERIFY(m_places->movePlace(6, 9)); | 1018 | QVERIFY(m_places->movePlace(5, 8)); | ||
1070 | urls.move(6, 8); | 1019 | urls.move(5, 7); | ||
1071 | QTRY_COMPARE(rowsMoved.count(), 1); | 1020 | QTRY_COMPARE(rowsMoved.count(), 1); | ||
1072 | args = rowsMoved.takeFirst(); | 1021 | args = rowsMoved.takeFirst(); | ||
1073 | QCOMPARE(args.at(1).toInt(), 6); // start | 1022 | QCOMPARE(args.at(1).toInt(), 5); // start | ||
1074 | QCOMPARE(args.at(2).toInt(), 6); // end | 1023 | QCOMPARE(args.at(2).toInt(), 5); // end | ||
1075 | QCOMPARE(args.at(4).toInt(), 9); // row (destination) | 1024 | QCOMPARE(args.at(4).toInt(), 8); // row (destination) | ||
1076 | QCOMPARE(placesUrls(), urls); | 1025 | QCOMPARE(placesUrls(), urls); | ||
1077 | rowsMoved.clear(); | 1026 | rowsMoved.clear(); | ||
1078 | 1027 | | |||
1079 | //use a invalid start position | 1028 | //use a invalid start position | ||
1080 | QVERIFY(!m_places->movePlace(100, 20)); | 1029 | QVERIFY(!m_places->movePlace(100, 20)); | ||
1081 | QCOMPARE(rowsMoved.count(), 0); | 1030 | QCOMPARE(rowsMoved.count(), 0); | ||
1082 | 1031 | | |||
1083 | //use same start and target position | 1032 | //use same start and target position | ||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |