┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/CMakeLists.txt8
-rw-r--r--src/tests/data/fakecomputer.xml387
-rw-r--r--src/tests/dolphinmainwindowtest.cpp2
-rw-r--r--src/tests/kfileitemlistviewtest.cpp16
-rw-r--r--src/tests/kfileitemmodelbenchmark.cpp4
-rw-r--r--src/tests/kfileitemmodeltest.cpp102
-rw-r--r--src/tests/kitemlistcontrollertest.cpp16
-rw-r--r--src/tests/kitemlistkeyboardsearchmanagertest.cpp8
-rw-r--r--src/tests/kitemlistselectionmanagertest.cpp12
-rw-r--r--src/tests/kstandarditemmodeltest.cpp2
-rw-r--r--src/tests/placesitemmodeltest.cpp850
-rw-r--r--src/tests/viewpropertiestest.cpp2
12 files changed, 1326 insertions, 83 deletions
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 13bd963f9..c656173a8 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -58,4 +58,10 @@ ecm_add_test(dolphinmainwindowtest.cpp
TEST_NAME dolphinmainwindowtest
LINK_LIBRARIES dolphinprivate dolphinstatic Qt5::Test)
-ecm_add_test(draganddrophelpertest.cpp LINK_LIBRARIES dolphinprivate Qt5::Test) \ No newline at end of file
+ecm_add_test(draganddrophelpertest.cpp LINK_LIBRARIES dolphinprivate Qt5::Test)
+
+# PlacesItemModelTest
+ecm_add_test(placesitemmodeltest.cpp
+TEST_NAME placesitemmodeltest
+LINK_LIBRARIES dolphinprivate dolphinstatic Qt5::Test)
+
diff --git a/src/tests/data/fakecomputer.xml b/src/tests/data/fakecomputer.xml
new file mode 100644
index 000000000..48be0461b
--- /dev/null
+++ b/src/tests/data/fakecomputer.xml
@@ -0,0 +1,387 @@
+<!-- Please note that in this file we indent more than necessary so that the
+ device tree is visible -->
+
+<machine>
+ <!-- This is a computer -->
+ <device udi="/org/kde/solid/fakehw/computer">
+ <property key="name">Computer</property>
+ <property key="vendor">Solid</property>
+ </device>
+
+ <!-- Two CPUs -->
+ <device udi="/org/kde/solid/fakehw/acpi_CPU0">
+ <property key="name">Solid Processor #0</property>
+ <property key="interfaces">Processor</property>
+ <property key="vendor">Acme Corporation</property>
+ <property key="parent">/org/kde/solid/fakehw/computer</property>
+ <property key="number">0</property>
+ <property key="maxSpeed">3200</property>
+ <property key="canChangeFrequency">true</property>
+ <property key="instructionSets">mmx,sse</property>
+ </device>
+ <device udi="/org/kde/solid/fakehw/acpi_CPU1">
+ <property key="name">Solid Processor #1</property>
+ <property key="interfaces">Processor</property>
+ <property key="vendor">Acme Corporation</property>
+ <property key="parent">/org/kde/solid/fakehw/computer</property>
+ <property key="number">1</property>
+ <property key="maxSpeed">3200</property>
+ <property key="canChangeFrequency">true</property>
+ </device>
+
+ <!-- Platform Device for a floppy drive -->
+ <device udi="/org/kde/solid/fakehw/platform_floppy_0">
+ <property key="name">Platform Device (floppy)</property>
+ <property key="parent">/org/kde/solid/fakehw/computer</property>
+ </device>
+ <!-- The actual floppy device -->
+ <device udi="/org/kde/solid/fakehw/platform_floppy_0_storage">
+ <property key="name">PC Floppy Drive</property>
+ <property key="interfaces">StorageDrive,Block</property>
+ <property key="parent">/org/kde/solid/fakehw/platform_floppy_0</property>
+
+ <property key="minor">0</property>
+ <property key="major">2</property>
+ <property key="device">/dev/fd0</property>
+
+ <property key="bus">platform</property>
+ <property key="driveType">floppy</property>
+ <property key="isRemovable">true</property>
+ <property key="isEjectRequired">false</property>
+ <property key="isHotpluggable">false</property>
+ <property key="isMediaCheckEnabled">false</property>
+ </device>
+ <!-- A (generally) virtual volume tracking the floppy drive state -->
+ <device udi="/org/kde/solid/fakehw/platform_floppy_0_storage_virt_volume">
+ <property key="name">Floppy Disk</property>
+ <property key="interfaces">Block,StorageVolume,StorageAccess</property>
+ <property key="parent">/org/kde/solid/fakehw/platform_floppy_0_storage</property>
+
+ <property key="minor">0</property>
+ <property key="major">2</property>
+ <property key="device">/dev/fd0</property>
+
+ <property key="isIgnored">false</property>
+ <property key="isMounted">true</property>
+ <property key="mountPoint">/media/floppy0</property>
+ <property key="usage">filesystem</property>
+ </device>
+
+
+
+ <!-- Primary IDE controller -->
+ <device udi="/org/kde/solid/fakehw/pci_001">
+ <property key="name">99021 IDE Controller #1</property>
+ <property key="vendor">Acme Corporation</property>
+ <property key="parent">/org/kde/solid/fakehw/computer</property>
+ </device>
+
+ <!-- Master device... -->
+ <device udi="/org/kde/solid/fakehw/pci_001_ide_0_0">
+ <property key="name">IDE device (master)</property>
+ <property key="parent">/org/kde/solid/fakehw/pci_001</property>
+ </device>
+ <!-- ... is a 250GB disk... -->
+ <device udi="/org/kde/solid/fakehw/storage_serial_HD56890I">
+ <property key="name">HD250GB</property>
+ <property key="vendor">Acme Corporation</property>
+ <property key="interfaces">StorageDrive,Block</property>
+ <property key="parent">/org/kde/solid/fakehw/pci_001_ide_0_0</property>
+
+ <property key="minor">0</property>
+ <property key="major">3</property>
+ <property key="device">/dev/hda</property>
+
+ <property key="bus">scsi</property>
+ <property key="driveType">disk</property>
+ <property key="isRemovable">false</property>
+ <property key="isEjectRequired">false</property>
+ <property key="isHotpluggable">false</property>
+ <property key="isMediaCheckEnabled">false</property>
+ <property key="product">HD250GBSATA</property>
+ </device>
+ <!-- ... with five partitions:
+ - one physical partition (the root /, ext3, 20GB)
+ - one extended containing three logical volumes:
+ - a swap volume (2GB)
+ - /home volume (xfs, 208GB)
+ - /foreign volume (ntfs, 20GB)
+ -->
+ <device udi="/org/kde/solid/fakehw/volume_uuid_feedface">
+ <property key="name">/</property>
+ <property key="interfaces">Block,StorageVolume,StorageAccess</property>
+ <property key="parent">/org/kde/solid/fakehw/storage_serial_HD56890I</property>
+
+ <property key="minor">1</property>
+ <property key="major">3</property>
+ <property key="device">/dev/hda1</property>
+
+ <property key="isIgnored">true</property>
+ <property key="isMounted">true</property>
+ <property key="mountPoint">/</property>
+ <property key="usage">filesystem</property>
+ <property key="fsType">ext3</property>
+ <property key="label">Root</property>
+ <property key="uuid">feedface</property>
+ <property key="size">21474836480</property>
+ </device>
+ <device udi="/org/kde/solid/fakehw/volume_uuid_c0ffee">
+ <property key="name">/home</property>
+ <property key="interfaces">Block,StorageVolume,StorageAccess</property>
+ <property key="parent">/org/kde/solid/fakehw/storage_serial_HD56890I</property>
+
+ <property key="minor">6</property>
+ <property key="major">3</property>
+ <property key="device">/dev/hda6</property>
+
+ <property key="isIgnored">true</property>
+ <property key="isMounted">true</property>
+ <property key="mountPoint">/home</property>
+ <property key="usage">filesystem</property>
+ <property key="fsType">xfs</property>
+ <property key="label">Home</property>
+ <property key="uuid">c0ffee</property>
+ <property key="size">223338299392</property>
+ </device>
+ <device udi="/org/kde/solid/fakehw/volume_uuid_f00ba7">
+ <property key="name">/foreign</property>
+ <property key="interfaces">Block,StorageVolume,StorageAccess</property>
+ <property key="parent">/org/kde/solid/fakehw/storage_serial_HD56890I</property>
+
+ <property key="minor">7</property>
+ <property key="major">3</property>
+ <property key="device">/dev/hda7</property>
+
+ <property key="isIgnored">false</property>
+ <property key="isMounted">true</property>
+ <property key="mountPoint">/foreign</property>
+ <property key="usage">filesystem</property>
+ <property key="fsType">ntfs</property>
+ <property key="label">Foreign</property>
+ <property key="uuid">f00ba7</property>
+ <property key="size">21474836480</property>
+ </device>
+ <device udi="/org/kde/solid/fakehw/volume_part2_size_1024">
+ <property key="name">StorageVolume</property>
+ <property key="interfaces">Block,StorageVolume,StorageAccess</property>
+ <property key="parent">/org/kde/solid/fakehw/storage_serial_HD56890I</property>
+
+ <property key="minor">2</property>
+ <property key="major">3</property>
+ <property key="device">/dev/hda2</property>
+
+ <property key="isIgnored">true</property>
+ <property key="isMounted">false</property>
+ <property key="usage">other</property>
+ <property key="size">1024</property>
+ </device>
+ <device udi="/org/kde/solid/fakehw/volume_part5_size_1048576">
+ <property key="name">StorageVolume (swap)</property>
+ <property key="interfaces">Block,StorageVolume,StorageAccess</property>
+ <property key="parent">/org/kde/solid/fakehw/storage_serial_HD56890I</property>
+
+ <property key="minor">5</property>
+ <property key="major">3</property>
+ <property key="device">/dev/hda5</property>
+
+ <property key="isIgnored">true</property>
+ <property key="isMounted">false</property>
+ <property key="usage">other</property>
+ <property key="fsType">swap</property>
+ <property key="size">2147483648</property>
+ </device>
+
+
+ <!-- Secondary IDE controller -->
+ <device udi="/org/kde/solid/fakehw/pci_002">
+ <property key="name">99021 IDE Controller #2</property>
+ <property key="vendor">Acme Corporation</property>
+ <property key="parent">/org/kde/solid/fakehw/computer</property>
+ </device>
+
+ <!-- Master device... -->
+ <device udi="/org/kde/solid/fakehw/pci_002_ide_1_0">
+ <property key="name">IDE device (master)</property>
+ <property key="parent">/org/kde/solid/fakehw/pci_002</property>
+ </device>
+ <!-- ... is a DVD writer... -->
+ <device udi="/org/kde/solid/fakehw/storage_model_solid_writer">
+ <property key="name">Solid IDE DVD Writer</property>
+ <property key="vendor">Acme Corporation</property>
+ <property key="interfaces">Block,StorageDrive,OpticalDrive</property>
+ <property key="parent">/org/kde/solid/fakehw/pci_002_ide_1_0</property>
+
+ <property key="minor">0</property>
+ <property key="major">22</property>
+ <property key="device">/dev/hdc</property>
+
+ <property key="bus">ide</property>
+ <property key="driveType">cdrom</property>
+ <property key="isRemovable">true</property>
+ <property key="isEjectRequired">true</property>
+ <property key="isHotpluggable">false</property>
+ <property key="isMediaCheckEnabled">true</property>
+ <property key="product">Solid DVD Writer</property>
+
+ <property key="supportedMedia">cdr,cdrw,dvd,dvdr,dvdrw</property>
+ <property key="readSpeed">4234</property>
+ <property key="writeSpeed">4234</property>
+ <property key="writeSpeeds">4234,2822,2117,1411,706</property>
+ </device>
+ <!-- ... with a cd-r in it -->
+ <device udi="/org/kde/solid/fakehw/volume_uuid_5011">
+ <property key="name">FooDistro i386</property>
+ <property key="interfaces">Block,StorageVolume,OpticalDisc,StorageAccess</property>
+ <property key="parent">/org/kde/solid/fakehw/storage_model_solid_writer</property>
+
+ <property key="discType">cd_rw</property>
+ <property key="isAppendable">false</property>
+ <property key="isRewritable">true</property>
+ <property key="isBlank">false</property>
+ <property key="availableContent">data</property>
+ <property key="mountPoint">/media/cdrom</property>
+
+ <property key="uuid">5011</property>
+ <property key="size">731047936</property>
+ <property key="label">FooDistro i386</property>
+ </device>
+
+ <!-- Slave device... -->
+ <device udi="/org/kde/solid/fakehw/pci_002_ide_1_1">
+ <property key="name">IDE device (slave)</property>
+ <property key="parent">/org/kde/solid/fakehw/pci_002</property>
+ </device>
+ <!-- ... is a DVD reader... -->
+ <device udi="/org/kde/solid/fakehw/storage_model_solid_reader">
+ <property key="name">Solid IDE DVD Reader</property>
+ <property key="vendor">Acme Corporation</property>
+ <property key="interfaces">Block,StorageDrive,OpticalDrive</property>
+ <property key="parent">/org/kde/solid/fakehw/pci_002_ide_1_1</property>
+
+ <property key="minor">0</property>
+ <property key="major">22</property>
+ <property key="device">/dev/hdc</property>
+
+ <property key="bus">ide</property>
+ <property key="driveType">cdrom</property>
+ <property key="isRemovable">true</property>
+ <property key="isEjectRequired">true</property>
+ <property key="isHotpluggable">false</property>
+ <property key="isMediaCheckEnabled">true</property>
+ <property key="product">Solid DVD Reader</property>
+
+ <property key="supportedMedia">cdr,cdrw,dvd,dvdr,dvdrw,dvdram,dvdplusr,dvdplusrw</property>
+ <property key="readSpeed">4234</property>
+ </device>
+ <!-- ... with a DVD Video in it -->
+ <device udi="/org/kde/solid/fakehw/volume_label_SOLIDMAN_BEGINS">
+ <property key="name">SolidMan Begins</property>
+ <property key="interfaces">Block,StorageVolume,OpticalDisc</property>
+ <property key="parent">/org/kde/solid/fakehw/storage_model_solid_reader</property>
+
+ <property key="discType">dvd_rom</property>
+ <property key="isAppendable">false</property>
+ <property key="isRewritable">false</property>
+ <property key="isBlank">false</property>
+ <property key="availableContent">dvdvideo</property>
+
+ <property key="uuid">5012</property>
+ <property key="size">8033075200</property>
+ <property key="label">SolidMan Begins</property>
+ </device>
+
+
+
+ <!-- First USB Controller -->
+ <device udi="/org/kde/solid/fakehw/pci_8086_265c">
+ <property key="name">99021 USB2 EHCI Controller #1</property>
+ <property key="vendor">Acme Corporation</property>
+ <property key="parent">/org/kde/solid/fakehw/computer</property>
+ </device>
+ <!-- Host Controller -->
+ <device udi="/org/kde/solid/fakehw/usb_device_0_0_1d_7">
+ <property key="name">EHCI Host Controller</property>
+ <property key="vendor">Kernel ehci_hcd</property>
+ <property key="parent">/org/kde/solid/fakehw/pci_8086_265c</property>
+ </device>
+ <!-- USB Device -->
+ <device udi="/org/kde/solid/fakehw/usb_device_4e8_5041">
+ <property key="name">Acme XO-Y4</property>
+ <property key="parent">/org/kde/solid/fakehw/usb_device_0_0_1d_7</property>
+ </device>
+ <!-- Mass Storage Interface -->
+ <device udi="/org/kde/solid/fakehw/usb_device_4e8_5041_if0">
+ <property key="name">USB Mass Storage Inferface</property>
+ <property key="parent">/org/kde/solid/fakehw/usb_device_4e8_5041</property>
+ </device>
+ <!-- SCSI Adapter -->
+ <device udi="/org/kde/solid/fakehw/usb_device_4e8_5041_if0_scsi_host">
+ <property key="name">SCSI Host Adapter</property>
+ <property key="parent">/org/kde/solid/fakehw/usb_device_4e8_5041_if0</property>
+ </device>
+ <!-- SCSI Device -->
+ <device udi="/org/kde/solid/fakehw/usb_device_4e8_5041_if0_scsi_host_scsi_device_lun0">
+ <property key="name">SCSI Device</property>
+ <property key="parent">/org/kde/solid/fakehw/usb_device_4e8_5041_if0_scsi_host</property>
+ </device>
+ <!-- We finally find the storage device, which is a portable media player... -->
+ <device udi="/org/kde/solid/fakehw/storage_serial_XOY4_5206">
+ <property key="name">XO-Y4</property>
+ <property key="vendor">Acme Electronics</property>
+ <property key="interfaces">StorageDrive,Block,PortableMediaPlayer</property>
+ <property key="parent">/org/kde/solid/fakehw/usb_device_4e8_5041_if0_scsi_host_scsi_device_lun0</property>
+
+ <property key="minor">0</property>
+ <property key="major">8</property>
+ <property key="device">/dev/sda</property>
+
+ <property key="bus">usb</property>
+ <property key="driveType">disk</property>
+ <property key="isRemovable">true</property>
+ <property key="isEjectRequired">true</property>
+ <property key="isHotpluggable">true</property>
+ <property key="isMediaCheckEnabled">true</property>
+ <property key="product">XO-Y4</property>
+
+ <property key="accessMethod">MassStorage</property>
+ <property key="outputFormats">audio/x-mp3</property>
+ <property key="inputFormats">audio/x-wav,audio/x-mp3,audio/vorbis</property>
+ <property key="playlistFormats">audio/x-mpegurl</property>
+ </device>
+ <!-- ... with a partition since it's a USB Mass Storage device -->
+ <device udi="/org/kde/solid/fakehw/volume_part1_size_993284096">
+ <property key="name">StorageVolume (vfat)</property>
+ <property key="interfaces">Block,StorageVolume,StorageAccess</property>
+ <property key="parent">/org/kde/solid/fakehw/storage_serial_XOY4_5206</property>
+
+ <property key="minor">1</property>
+ <property key="major">8</property>
+ <property key="device">/dev/sda1</property>
+
+ <property key="isIgnored">false</property>
+ <property key="isMounted">true</property>
+ <property key="mountPoint">/media/XO-Y4</property>
+ <property key="usage">filesystem</property>
+ <property key="fsType">vfat</property>
+ <property key="size">993284096</property>
+ </device>
+
+ <device udi="/org/kde/solid/fakehw/fstab">
+ <property key="name">Network Shares</property>
+ <property key="product">Network Shares</property>
+ <property key="vendor">KDE</property>
+ <property key="parent">/org/kde/solid/fakehw/computer</property>
+ </device>
+ <device udi="/org/kde/solid/fakehw/fstab/thehost/solidpath">
+ <property key="parent">/org/kde/solid/fstab</property>
+ <property key="interfaces">NetworkShare,StorageAccess</property>
+ <property key="vendor">/solidpath</property>
+ <property key="product">thehost</property>
+ <property key="type">nfs</property>
+ <property key="url">nfs://thehost/solid-path</property>
+ <property key="filePath">/media/nfs</property>
+ <property key="isIgnored">false</property>
+ <property key="isMounted">true</property>
+ <property key="mountPoint">/media/nfs</property>
+ </device>
+</machine>
diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp
index be86c5016..26036c9af 100644
--- a/src/tests/dolphinmainwindowtest.cpp
+++ b/src/tests/dolphinmainwindowtest.cpp
@@ -47,7 +47,7 @@ void DolphinMainWindowTest::testClosingTabsWithSearchBoxVisible()
m_mainWindow->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false);
m_mainWindow->show();
// Without this call the searchbox doesn't get FocusIn events.
- QTest::qWaitForWindowExposed(m_mainWindow.data());
+ QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
QVERIFY(m_mainWindow->isVisible());
auto tabWidget = m_mainWindow->findChild<DolphinTabWidget*>("tabWidget");
diff --git a/src/tests/kfileitemlistviewtest.cpp b/src/tests/kfileitemlistviewtest.cpp
index cac4f7a58..775602f9f 100644
--- a/src/tests/kfileitemlistviewtest.cpp
+++ b/src/tests/kfileitemlistviewtest.cpp
@@ -52,26 +52,26 @@ void KFileItemListViewTest::init()
m_model->m_dirLister->setAutoUpdate(false);
m_listView = new KFileItemListView();
- m_listView->onModelChanged(m_model, 0);
+ m_listView->onModelChanged(m_model, nullptr);
m_graphicsView = new QGraphicsView();
m_graphicsView->show();
- QTest::qWaitForWindowExposed(m_graphicsView);
+ QVERIFY(QTest::qWaitForWindowExposed(m_graphicsView));
}
void KFileItemListViewTest::cleanup()
{
delete m_graphicsView;
- m_graphicsView = 0;
+ m_graphicsView = nullptr;
delete m_listView;
- m_listView = 0;
+ m_listView = nullptr;
delete m_model;
- m_model = 0;
+ m_model = nullptr;
delete m_testDir;
- m_testDir = 0;
+ m_testDir = nullptr;
}
/**
@@ -87,9 +87,9 @@ void KFileItemListViewTest::cleanup()
*/
void KFileItemListViewTest::testGroupedItemChanges()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
QVERIFY(itemsInsertedSpy.isValid());
- QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
+ QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved);
QVERIFY(itemsRemovedSpy.isValid());
m_model->setGroupedSorting(true);
diff --git a/src/tests/kfileitemmodelbenchmark.cpp b/src/tests/kfileitemmodelbenchmark.cpp
index 41dcce019..5e3353396 100644
--- a/src/tests/kfileitemmodelbenchmark.cpp
+++ b/src/tests/kfileitemmodelbenchmark.cpp
@@ -167,8 +167,8 @@ void KFileItemModelBenchmark::insertAndRemoveManyItems()
model.m_naturalSorting = false;
model.setRoles({"text"});
- QSignalSpy spyItemsInserted(&model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy spyItemsRemoved(&model, SIGNAL(itemsRemoved(KItemRangeList)));
+ QSignalSpy spyItemsInserted(&model, &KFileItemModel::itemsInserted);
+ QSignalSpy spyItemsRemoved(&model, &KFileItemModel::itemsRemoved);
QBENCHMARK {
model.slotClear();
diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp
index b8e089530..b455c521d 100644
--- a/src/tests/kfileitemmodeltest.cpp
+++ b/src/tests/kfileitemmodeltest.cpp
@@ -126,10 +126,10 @@ void KFileItemModelTest::init()
void KFileItemModelTest::cleanup()
{
delete m_model;
- m_model = 0;
+ m_model = nullptr;
delete m_testDir;
- m_testDir = 0;
+ m_testDir = nullptr;
}
void KFileItemModelTest::testDefaultRoles()
@@ -144,7 +144,7 @@ void KFileItemModelTest::testDefaultRoles()
void KFileItemModelTest::testDefaultSortRole()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
QVERIFY(itemsInsertedSpy.isValid());
QCOMPARE(m_model->sortRole(), QByteArray("text"));
@@ -167,7 +167,7 @@ void KFileItemModelTest::testDefaultGroupedSorting()
void KFileItemModelTest::testNewItems()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
m_testDir->createFiles({"a.txt", "b.txt", "c.txt"});
@@ -181,8 +181,8 @@ void KFileItemModelTest::testNewItems()
void KFileItemModelTest::testRemoveItems()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
+ QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved);
m_testDir->createFiles({"a.txt", "b.txt"});
m_model->loadDirectory(m_testDir->url());
@@ -199,9 +199,9 @@ void KFileItemModelTest::testRemoveItems()
void KFileItemModelTest::testDirLoadingCompleted()
{
- QSignalSpy loadingCompletedSpy(m_model, SIGNAL(directoryLoadingCompleted()));
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
+ QSignalSpy loadingCompletedSpy(m_model, &KFileItemModel::directoryLoadingCompleted);
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
+ QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved);
m_testDir->createFiles({"a.txt", "b.txt", "c.txt"});
@@ -242,9 +242,9 @@ void KFileItemModelTest::testDirLoadingCompleted()
void KFileItemModelTest::testSetData()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
QVERIFY(itemsInsertedSpy.isValid());
- QSignalSpy itemsChangedSpy(m_model, SIGNAL(itemsChanged(KItemRangeList, QSet<QByteArray>)));
+ QSignalSpy itemsChangedSpy(m_model, &KFileItemModel::itemsChanged);
QVERIFY(itemsChangedSpy.isValid());
m_testDir->createFile("a.txt");
@@ -297,9 +297,9 @@ void KFileItemModelTest::testSetDataWithModifiedSortRole()
QFETCH(int, ratingIndex1);
QFETCH(int, ratingIndex2);
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
QVERIFY(itemsInsertedSpy.isValid());
- QSignalSpy itemsMovedSpy(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)));
+ QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved);
QVERIFY(itemsMovedSpy.isValid());
// Changing the value of a sort-role must result in
@@ -352,8 +352,8 @@ void KFileItemModelTest::testSetDataWithModifiedSortRole()
void KFileItemModelTest::testChangeSortRole()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy itemsMovedSpy(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
+ QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved);
QVERIFY(itemsMovedSpy.isValid());
QCOMPARE(m_model->sortRole(), QByteArray("text"));
@@ -392,8 +392,8 @@ void KFileItemModelTest::testChangeSortRole()
void KFileItemModelTest::testResortAfterChangingName()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy itemsMovedSpy(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
+ QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved);
QVERIFY(itemsMovedSpy.isValid());
// We sort by size in a directory where all files have the same size.
@@ -430,7 +430,7 @@ void KFileItemModelTest::testResortAfterChangingName()
void KFileItemModelTest::testModelConsistencyWhenInsertingItems()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
// KFileItemModel prevents that inserting a punch of items sequentially
// results in an itemsInserted()-signal for each item. Instead internally
@@ -472,7 +472,7 @@ void KFileItemModelTest::testModelConsistencyWhenInsertingItems()
void KFileItemModelTest::testItemRangeConsistencyWhenInsertingItems()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
m_testDir->createFiles({"B", "E", "G"});
@@ -511,11 +511,11 @@ void KFileItemModelTest::testItemRangeConsistencyWhenInsertingItems()
void KFileItemModelTest::testExpandItems()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
QVERIFY(itemsInsertedSpy.isValid());
- QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
+ QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved);
QVERIFY(itemsRemovedSpy.isValid());
- QSignalSpy loadingCompletedSpy(m_model, SIGNAL(directoryLoadingCompleted()));
+ QSignalSpy loadingCompletedSpy(m_model, &KFileItemModel::directoryLoadingCompleted);
QVERIFY(loadingCompletedSpy.isValid());
// Test expanding subfolders in a folder with the items "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1".
@@ -648,8 +648,8 @@ void KFileItemModelTest::testExpandItems()
void KFileItemModelTest::testExpandParentItems()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy loadingCompletedSpy(m_model, SIGNAL(directoryLoadingCompleted()));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
+ QSignalSpy loadingCompletedSpy(m_model, &KFileItemModel::directoryLoadingCompleted);
QVERIFY(loadingCompletedSpy.isValid());
// Create a tree structure of folders:
@@ -729,8 +729,8 @@ void KFileItemModelTest::testExpandParentItems()
*/
void KFileItemModelTest::testMakeExpandedItemHidden()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
+ QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved);
QSet<QByteArray> modelRoles = m_model->roles();
modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
@@ -772,7 +772,7 @@ void KFileItemModelTest::testMakeExpandedItemHidden()
void KFileItemModelTest::testRemoveFilteredExpandedItems()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
QSet<QByteArray> originalModelRoles = m_model->roles();
QSet<QByteArray> modelRoles = originalModelRoles;
@@ -817,8 +817,8 @@ void KFileItemModelTest::testRemoveFilteredExpandedItems()
void KFileItemModelTest::testSorting()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy itemsMovedSpy(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
+ QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved);
QVERIFY(itemsMovedSpy.isValid());
// Create some files with different sizes and modification times to check the different sorting options
@@ -952,7 +952,7 @@ void KFileItemModelTest::testSorting()
void KFileItemModelTest::testIndexForKeyboardSearch()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
m_testDir->createFiles({"a", "aa", "Image.jpg", "Image.png", "Text", "Text1", "Text2", "Text11"});
@@ -1002,7 +1002,7 @@ void KFileItemModelTest::testIndexForKeyboardSearch()
void KFileItemModelTest::testNameFilter()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
m_testDir->createFiles({"A1", "A2", "Abc", "Bcd", "Cde"});
@@ -1059,8 +1059,8 @@ void KFileItemModelTest::testEmptyPath()
*/
void KFileItemModelTest::testRefreshExpandedItem()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy itemsChangedSpy(m_model, SIGNAL(itemsChanged(KItemRangeList, QSet<QByteArray>)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
+ QSignalSpy itemsChangedSpy(m_model, &KFileItemModel::itemsChanged);
QVERIFY(itemsChangedSpy.isValid());
QSet<QByteArray> modelRoles = m_model->roles();
@@ -1098,8 +1098,8 @@ void KFileItemModelTest::testRemoveHiddenItems()
m_testDir->createDir("d");
m_testDir->createFiles({".f", ".g", "h", "i"});
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
+ QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved);
m_model->setShowHiddenFiles(true);
m_model->loadDirectory(m_testDir->url());
@@ -1141,8 +1141,8 @@ void KFileItemModelTest::testRemoveHiddenItems()
*/
void KFileItemModelTest::collapseParentOfHiddenItems()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
+ QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved);
QSet<QByteArray> modelRoles = m_model->roles();
modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
@@ -1191,8 +1191,8 @@ void KFileItemModelTest::collapseParentOfHiddenItems()
*/
void KFileItemModelTest::removeParentOfHiddenItems()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
+ QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved);
QSet<QByteArray> modelRoles = m_model->roles();
modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
@@ -1244,8 +1244,8 @@ void KFileItemModelTest::removeParentOfHiddenItems()
*/
void KFileItemModelTest::testGeneralParentChildRelationships()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
+ QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved);
QSet<QByteArray> modelRoles = m_model->roles();
modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
@@ -1331,10 +1331,10 @@ void KFileItemModelTest::testGeneralParentChildRelationships()
void KFileItemModelTest::testNameRoleGroups()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
- QSignalSpy itemsMovedSpy(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
+ QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved);
QVERIFY(itemsMovedSpy.isValid());
- QSignalSpy groupsChangedSpy(m_model, SIGNAL(groupsChanged()));
+ QSignalSpy groupsChangedSpy(m_model, &KFileItemModel::groupsChanged);
QVERIFY(groupsChangedSpy.isValid());
m_testDir->createFiles({"b.txt", "c.txt", "d.txt", "e.txt"});
@@ -1399,7 +1399,7 @@ void KFileItemModelTest::testNameRoleGroups()
void KFileItemModelTest::testNameRoleGroupsWithExpandedItems()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
QSet<QByteArray> modelRoles = m_model->roles();
modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
@@ -1437,7 +1437,7 @@ void KFileItemModelTest::testNameRoleGroupsWithExpandedItems()
void KFileItemModelTest::testInconsistentModel()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
QSet<QByteArray> modelRoles = m_model->roles();
modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
@@ -1493,7 +1493,7 @@ void KFileItemModelTest::testInconsistentModel()
void KFileItemModelTest::testChangeRolesForFilteredItems()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
QSet<QByteArray> modelRoles = m_model->roles();
modelRoles << "owner";
@@ -1590,7 +1590,7 @@ void KFileItemModelTest::testChangeSortRoleWhileFiltering()
void KFileItemModelTest::testRefreshFilteredItems()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
m_testDir->createFiles({"a.txt", "b.txt", "c.jpg", "d.jpg"});
@@ -1619,7 +1619,7 @@ void KFileItemModelTest::testRefreshFilteredItems()
void KFileItemModelTest::testCreateMimeData()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
QSet<QByteArray> modelRoles = m_model->roles();
modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
@@ -1646,7 +1646,7 @@ void KFileItemModelTest::testCreateMimeData()
void KFileItemModelTest::testCollapseFolderWhileLoading()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
QSet<QByteArray> modelRoles = m_model->roles();
modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
@@ -1724,7 +1724,7 @@ void KFileItemModelTest::testCollapseFolderWhileLoading()
void KFileItemModelTest::testDeleteFileMoreThanOnce()
{
- QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
+ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
m_testDir->createFiles({"a.txt", "b.txt", "c.txt", "d.txt"});
diff --git a/src/tests/kitemlistcontrollertest.cpp b/src/tests/kitemlistcontrollertest.cpp
index 92d05c4d4..a468ca6dc 100644
--- a/src/tests/kitemlistcontrollertest.cpp
+++ b/src/tests/kitemlistcontrollertest.cpp
@@ -58,7 +58,7 @@ public:
int styleHint(StyleHint hint,
const QStyleOption* option = nullptr,
const QWidget* widget = nullptr,
- QStyleHintReturn* returnData = nullptr) const Q_DECL_OVERRIDE
+ QStyleHintReturn* returnData = nullptr) const override
{
switch (hint) {
case QStyle::SH_ItemView_ActivateItemOnSingleClick:
@@ -139,20 +139,20 @@ void KItemListControllerTest::initTestCase()
m_testDir->createFiles(files);
m_model->loadDirectory(m_testDir->url());
- QSignalSpy spyDirectoryLoadingCompleted(m_model, SIGNAL(directoryLoadingCompleted()));
+ QSignalSpy spyDirectoryLoadingCompleted(m_model, &KFileItemModel::directoryLoadingCompleted);
QVERIFY(spyDirectoryLoadingCompleted.wait());
m_container->show();
- QTest::qWaitForWindowExposed(m_container);
+ QVERIFY(QTest::qWaitForWindowExposed(m_container));
}
void KItemListControllerTest::cleanupTestCase()
{
delete m_container;
- m_container = 0;
+ m_container = nullptr;
delete m_testDir;
- m_testDir = 0;
+ m_testDir = nullptr;
}
/** Before each test, the current item, selection, and item size are reset to the defaults. */
@@ -507,8 +507,8 @@ void KItemListControllerTest::testKeyboardNavigation()
adjustGeometryForColumnCount(columnCount);
QCOMPARE(m_view->m_layouter->m_columnCount, columnCount);
- QSignalSpy spySingleItemActivated(m_controller, SIGNAL(itemActivated(int)));
- QSignalSpy spyMultipleItemsActivated(m_controller, SIGNAL(itemsActivated(KItemSet)));
+ QSignalSpy spySingleItemActivated(m_controller, &KItemListController::itemActivated);
+ QSignalSpy spyMultipleItemsActivated(m_controller, &KItemListController::itemsActivated);
while (!testList.isEmpty()) {
const QPair<KeyPress, ViewState> test = testList.takeFirst();
@@ -584,7 +584,7 @@ void KItemListControllerTest::testMouseClickActivation()
mouseReleaseEvent.setButton(Qt::LeftButton);
mouseReleaseEvent.setButtons(Qt::NoButton);
- QSignalSpy spyItemActivated(m_controller, SIGNAL(itemActivated(int)));
+ QSignalSpy spyItemActivated(m_controller, &KItemListController::itemActivated);
// Default setting: single click activation.
m_testStyle->setActivateItemOnSingleClick(true);
diff --git a/src/tests/kitemlistkeyboardsearchmanagertest.cpp b/src/tests/kitemlistkeyboardsearchmanagertest.cpp
index 45fe112ce..c14ce87ac 100644
--- a/src/tests/kitemlistkeyboardsearchmanagertest.cpp
+++ b/src/tests/kitemlistkeyboardsearchmanagertest.cpp
@@ -46,7 +46,7 @@ void KItemListKeyboardSearchManagerTest::init()
void KItemListKeyboardSearchManagerTest::testBasicKeyboardSearch()
{
- QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString, bool)));
+ QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem);
QVERIFY(spy.isValid());
m_keyboardSearchManager.addKeys("f");
@@ -72,7 +72,7 @@ void KItemListKeyboardSearchManagerTest::testAbortedKeyboardSearch()
// to save time when running this test.
m_keyboardSearchManager.setTimeout(100);
- QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString, bool)));
+ QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem);
QVERIFY(spy.isValid());
m_keyboardSearchManager.addKeys("f");
@@ -104,7 +104,7 @@ void KItemListKeyboardSearchManagerTest::testRepeatedKeyPress()
// 1. the string contains the repeated key only once, and
// 2. the bool searchFromNextItem is true.
- QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString, bool)));
+ QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem);
QVERIFY(spy.isValid());
m_keyboardSearchManager.addKeys("p");
@@ -132,7 +132,7 @@ void KItemListKeyboardSearchManagerTest::testPressShift()
// string. Make sure that this does not reset the current search. See
// https://bugs.kde.org/show_bug.cgi?id=321286
- QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString, bool)));
+ QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem);
QVERIFY(spy.isValid());
// Simulate that the user enters "a_b".
diff --git a/src/tests/kitemlistselectionmanagertest.cpp b/src/tests/kitemlistselectionmanagertest.cpp
index 48e8dce04..b65486357 100644
--- a/src/tests/kitemlistselectionmanagertest.cpp
+++ b/src/tests/kitemlistselectionmanagertest.cpp
@@ -30,8 +30,8 @@ class DummyModel : public KItemModelBase
public:
DummyModel();
void setCount(int count);
- int count() const Q_DECL_OVERRIDE;
- QHash<QByteArray, QVariant> data(int index) const Q_DECL_OVERRIDE;
+ int count() const override;
+ QHash<QByteArray, QVariant> data(int index) const override;
private:
int m_count;
@@ -99,10 +99,10 @@ void KItemListSelectionManagerTest::init()
void KItemListSelectionManagerTest::cleanup()
{
delete m_selectionManager;
- m_selectionManager = 0;
+ m_selectionManager = nullptr;
delete m_model;
- m_model = 0;
+ m_model = nullptr;
}
void KItemListSelectionManagerTest::testConstructor()
@@ -115,7 +115,7 @@ void KItemListSelectionManagerTest::testConstructor()
void KItemListSelectionManagerTest::testCurrentItemAnchorItem()
{
- QSignalSpy spyCurrent(m_selectionManager, SIGNAL(currentChanged(int,int)));
+ QSignalSpy spyCurrent(m_selectionManager, &KItemListSelectionManager::currentChanged);
// Set current item and check that the selection manager emits the currentChanged(int,int) signal correctly.
m_selectionManager->setCurrentItem(4);
@@ -445,7 +445,7 @@ void KItemListSelectionManagerTest::testChangeSelection()
QFETCH(QList<QVariant>, data);
QFETCH(KItemSet, finalSelection);
- QSignalSpy spySelectionChanged(m_selectionManager, SIGNAL(selectionChanged(KItemSet,KItemSet)));
+ QSignalSpy spySelectionChanged(m_selectionManager, &KItemListSelectionManager::selectionChanged);
// Initial selection should be empty
QVERIFY(!m_selectionManager->hasSelection());
diff --git a/src/tests/kstandarditemmodeltest.cpp b/src/tests/kstandarditemmodeltest.cpp
index 889748f35..daa8f1e56 100644
--- a/src/tests/kstandarditemmodeltest.cpp
+++ b/src/tests/kstandarditemmodeltest.cpp
@@ -51,7 +51,7 @@ void KStandardItemModelTest::init()
void KStandardItemModelTest::cleanup()
{
delete m_model;
- m_model = 0;
+ m_model = nullptr;
}
void KStandardItemModelTest::testNewItems()
diff --git a/src/tests/placesitemmodeltest.cpp b/src/tests/placesitemmodeltest.cpp
new file mode 100644
index 000000000..a74b3ea6c
--- /dev/null
+++ b/src/tests/placesitemmodeltest.cpp
@@ -0,0 +1,850 @@
+/***************************************************************************
+ * Copyright (C) 2017 by Renato Araujo Oliveira <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#include <QTest>
+#include <QSignalSpy>
+#include <QDebug>
+#include <QList>
+#include <QByteArray>
+#include <QStandardPaths>
+#include <QAction>
+#include <QDBusInterface>
+#include <QUrlQuery>
+
+#include <KBookmarkManager>
+#include <KConfig>
+#include <KConfigGroup>
+#include <KAboutData>
+#include <KFilePlacesModel>
+
+#include "panels/places/placesitemmodel.h"
+#include "panels/places/placesitem.h"
+#include "views/viewproperties.h"
+#include "kitemviews/kitemrange.h"
+
+Q_DECLARE_METATYPE(KItemRangeList)
+Q_DECLARE_METATYPE(KItemRange)
+
+#ifdef Q_OS_WIN
+//c:\ as root for windows
+#define KDE_ROOT_PATH "C:\\"
+#else
+#define KDE_ROOT_PATH "/"
+#endif
+
+static QString bookmarksFile()
+{
+ return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/user-places.xbel";
+}
+
+class PlacesItemModelTest : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void init();
+ void cleanup();
+
+ void initTestCase();
+ void cleanupTestCase();
+
+ void testModelSort();
+ void testGroups();
+ void testDeletePlace();
+ void testPlaceItem_data();
+ void testPlaceItem();
+ void testTearDownDevice();
+ void testDefaultViewProperties_data();
+ void testDefaultViewProperties();
+ void testClear();
+ void testHideItem();
+ void testSystemItems();
+ void testEditBookmark();
+ void testEditAfterCreation();
+ void testEditMetadata();
+ void testRefresh();
+ void testIcons_data();
+ void testIcons();
+ void testDragAndDrop();
+ void testHideDevices();
+ void testDuplicatedEntries();
+ void renameAfterCreation();
+
+private:
+ PlacesItemModel* m_model;
+ QSet<int> m_tobeRemoved;
+ QMap<QString, QDBusInterface *> m_interfacesMap;
+
+ void setBalooEnabled(bool enabled);
+ int indexOf(const QUrl &url);
+ QDBusInterface *fakeManager();
+ QDBusInterface *fakeDevice(const QString &udi);
+ QStringList placesUrls(PlacesItemModel *model = nullptr) const;
+ QStringList initialUrls() const;
+ void createPlaceItem(const QString &text, const QUrl &url, const QString &icon);
+ void removePlaceAfter(int index);
+ void cancelPlaceRemoval(int index);
+ void removeTestUserData();
+ QMimeData *createMimeData(const QList<int> &indexes) const;
+};
+
+#define CHECK_PLACES_URLS(urls) \
+ { \
+ QStringList places = placesUrls(); \
+ if (places != urls) { \
+ qWarning() << "Expected:" << urls; \
+ qWarning() << "Got:" << places; \
+ QCOMPARE(places, urls); \
+ } \
+ }
+
+void PlacesItemModelTest::setBalooEnabled(bool enabled)
+{
+ KConfig config(QStringLiteral("baloofilerc"));
+ KConfigGroup basicSettings = config.group("Basic Settings");
+ basicSettings.writeEntry("Indexing-Enabled", enabled);
+ config.sync();
+}
+
+int PlacesItemModelTest::indexOf(const QUrl &url)
+{
+ for (int r = 0; r < m_model->count(); r++) {
+ if (m_model->placesItem(r)->url() == url) {
+ return r;
+ }
+ }
+ return -1;
+}
+
+QDBusInterface *PlacesItemModelTest::fakeManager()
+{
+ return fakeDevice(QStringLiteral("/org/kde/solid/fakehw"));
+}
+
+QDBusInterface *PlacesItemModelTest::fakeDevice(const QString &udi)
+{
+ if (m_interfacesMap.contains(udi)) {
+ return m_interfacesMap[udi];
+ }
+
+ QDBusInterface *iface = new QDBusInterface(QDBusConnection::sessionBus().baseService(), udi);
+ m_interfacesMap[udi] = iface;
+
+ return iface;
+}
+
+QStringList PlacesItemModelTest::placesUrls(PlacesItemModel *model) const
+{
+ QStringList urls;
+ if (!model) {
+ model = m_model;
+ }
+
+ for (int row = 0; row < model->count(); ++row) {
+ urls << model->placesItem(row)->url().toDisplayString(QUrl::PreferLocalFile);
+ }
+ return urls;
+}
+
+QStringList PlacesItemModelTest::initialUrls() const
+{
+ static QStringList urls;
+ if (urls.isEmpty()) {
+ urls << QDir::homePath() << QStringLiteral(KDE_ROOT_PATH) << QStringLiteral("trash:/")
+ << QStringLiteral("remote:/")
+ << QStringLiteral("timeline:/today") << QStringLiteral("timeline:/yesterday") << QStringLiteral("timeline:/thismonth") << QStringLiteral("timeline:/lastmonth")
+ << QStringLiteral("search:/documents") << QStringLiteral("search:/images") << QStringLiteral("search:/audio") << QStringLiteral("search:/videos")
+ << QStringLiteral("/media/nfs") << QStringLiteral("/foreign")
+ << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom");
+ }
+ return urls;
+}
+
+void PlacesItemModelTest::createPlaceItem(const QString &text, const QUrl &url, const QString &icon)
+{
+ m_model->createPlacesItem(text, url, icon);
+}
+
+void PlacesItemModelTest::removePlaceAfter(int index)
+{
+ m_tobeRemoved.insert(index);
+}
+
+void PlacesItemModelTest::cancelPlaceRemoval(int index)
+{
+ m_tobeRemoved.remove(index);
+}
+
+void PlacesItemModelTest::removeTestUserData()
+{
+ // user hardcoded path to avoid removal of any user personal data
+ QDir dir(QStringLiteral("/home/renato/.qttest/share/placesitemmodeltest"));
+ if (dir.exists()) {
+ QVERIFY(dir.removeRecursively());
+ }
+}
+
+QMimeData *PlacesItemModelTest::createMimeData(const QList<int> &indexes) const
+{
+ QByteArray itemData;
+ QDataStream stream(&itemData, QIODevice::WriteOnly);
+ QList<QUrl> urls;
+
+ for (int index : indexes) {
+ const QUrl itemUrl = m_model->placesItem(index)->url();
+ if (itemUrl.isValid()) {
+ urls << itemUrl;
+ }
+ stream << index;
+ }
+
+ QMimeData* mimeData = new QMimeData();
+ mimeData->setUrls(urls);
+ // copied from PlacesItemModel::internalMimeType()
+ const QString internalMimeType = "application/x-dolphinplacesmodel-" +
+ QString::number((qptrdiff)m_model);
+ mimeData->setData(internalMimeType, itemData);
+ return mimeData;
+}
+
+void PlacesItemModelTest::init()
+{
+ m_model = new PlacesItemModel();
+ // WORKAROUND: need to wait for bookmark to load, check: PlacesItemModel::updateBookmarks
+ QTest::qWait(300);
+ QCOMPARE(m_model->count(), 17);
+}
+
+void PlacesItemModelTest::cleanup()
+{
+ for (int i : m_tobeRemoved) {
+ int before = m_model->count();
+ m_model->deleteItem(i);
+ QTRY_COMPARE(m_model->count(), before - 1);
+ }
+ m_tobeRemoved.clear();
+ delete m_model;
+ m_model = nullptr;
+ removeTestUserData();
+}
+
+void PlacesItemModelTest::initTestCase()
+{
+ QStandardPaths::setTestModeEnabled(true);
+ // remove test user data
+ removeTestUserData();
+
+ const QString fakeHw = QFINDTESTDATA("data/fakecomputer.xml");
+ QVERIFY(!fakeHw.isEmpty());
+ qputenv("SOLID_FAKEHW", QFile::encodeName(fakeHw));
+
+ setBalooEnabled(true);
+ const QString bookmarsFileName = bookmarksFile();
+ if (QFileInfo::exists(bookmarsFileName)) {
+ // Ensure we'll have a clean bookmark file to start
+ QVERIFY(QFile::remove(bookmarsFileName));
+ }
+
+ qRegisterMetaType<KItemRangeList>();
+ qRegisterMetaType<KItemRange>();
+}
+
+void PlacesItemModelTest::cleanupTestCase()
+{
+ qDeleteAll(m_interfacesMap);
+ QFile::remove(bookmarksFile());
+
+ // Remove any previous properties file
+ removeTestUserData();
+}
+
+void PlacesItemModelTest::testModelSort()
+{
+ CHECK_PLACES_URLS(initialUrls());
+}
+
+void PlacesItemModelTest::testGroups()
+{
+ const auto groups = m_model->groups();
+
+ QCOMPARE(groups.size(), 6);
+
+ QCOMPARE(groups.at(0).first, 0);
+ QCOMPARE(groups.at(0).second.toString(), QStringLiteral("Places"));
+
+ QCOMPARE(groups.at(1).first, 3);
+ QCOMPARE(groups.at(1).second.toString(), QStringLiteral("Remote"));
+
+ QCOMPARE(groups.at(2).first, 4);
+ QCOMPARE(groups.at(2).second.toString(), QStringLiteral("Recently Saved"));
+
+ QCOMPARE(groups.at(3).first, 8);
+ QCOMPARE(groups.at(3).second.toString(), QStringLiteral("Search For"));
+
+ QCOMPARE(groups.at(4).first, 12);
+ QCOMPARE(groups.at(4).second.toString(), QStringLiteral("Devices"));
+
+ QCOMPARE(groups.at(5).first, 14);
+ QCOMPARE(groups.at(5).second.toString(), QStringLiteral("Removable Devices"));
+}
+
+void PlacesItemModelTest::testPlaceItem_data()
+{
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<bool>("expectedIsHidden");
+ QTest::addColumn<bool>("expectedIsSystemItem");
+ QTest::addColumn<QString>("expectedGroup");
+ QTest::addColumn<bool>("expectedStorageSetupNeeded");
+
+ // places
+ QTest::newRow("Places - Home") << QUrl::fromLocalFile(QDir::homePath()) << false << true << QStringLiteral("Places") << false;
+
+ // baloo -search
+ QTest::newRow("Baloo - Documents") << QUrl("search:/documents") << false << true << QStringLiteral("Search For") << false;
+
+ // baloo - timeline
+ QTest::newRow("Baloo - Last Month") << QUrl("timeline:/lastmonth") << false << true << QStringLiteral("Recently Saved") << false;
+
+ // devices
+ QTest::newRow("Devices - Floppy") << QUrl("file:///media/floppy0") << false << false << QStringLiteral("Removable Devices") << false;
+}
+
+void PlacesItemModelTest::testPlaceItem()
+{
+ QFETCH(QUrl, url);
+ QFETCH(bool, expectedIsHidden);
+ QFETCH(bool, expectedIsSystemItem);
+ QFETCH(QString, expectedGroup);
+ QFETCH(bool, expectedStorageSetupNeeded);
+
+ const int index = indexOf(url);
+ PlacesItem *item = m_model->placesItem(index);
+ QCOMPARE(item->url(), url);
+ QCOMPARE(item->isHidden(), expectedIsHidden);
+ QCOMPARE(item->isSystemItem(), expectedIsSystemItem);
+ QCOMPARE(item->group(), expectedGroup);
+ QCOMPARE(item->storageSetupNeeded(), expectedStorageSetupNeeded);
+}
+
+void PlacesItemModelTest::testDeletePlace()
+{
+ const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
+ QStringList urls = initialUrls();
+ QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
+ QSignalSpy itemsRemovedSpy(m_model, &PlacesItemModel::itemsRemoved);
+
+ PlacesItemModel *model = new PlacesItemModel();
+
+ // create a new place
+ createPlaceItem(QStringLiteral("Temporary Dir"), tempUrl, QString());
+ urls.insert(3, tempUrl.toLocalFile());
+
+ // check if the new entry was created
+ QTRY_COMPARE(itemsInsertedSpy.count(), 1);
+ CHECK_PLACES_URLS(urls);
+ QTRY_COMPARE(model->count(), m_model->count());
+
+ // delete item
+ m_model->deleteItem(3);
+
+ // make sure that the new item is removed
+ QTRY_COMPARE(itemsRemovedSpy.count(), 1);
+ QTRY_COMPARE(m_model->count(), 17);
+ CHECK_PLACES_URLS(initialUrls());
+ QTRY_COMPARE(model->count(), m_model->count());
+}
+
+void PlacesItemModelTest::testTearDownDevice()
+{
+ const QUrl mediaUrl = QUrl::fromLocalFile(QStringLiteral("/media/XO-Y4"));
+ int index = indexOf(mediaUrl);
+ QVERIFY(index != -1);
+
+ auto ejectAction = m_model->ejectAction(index);
+ QVERIFY(!ejectAction);
+
+ auto teardownAction = m_model->teardownAction(index);
+ QVERIFY(teardownAction);
+
+ QCOMPARE(m_model->count(), 17);
+
+ QSignalSpy spyItemsRemoved(m_model, &PlacesItemModel::itemsRemoved);
+ fakeManager()->call(QStringLiteral("unplug"), "/org/kde/solid/fakehw/volume_part1_size_993284096");
+ QTRY_COMPARE(m_model->count(), 16);
+ QCOMPARE(spyItemsRemoved.count(), 1);
+ const QList<QVariant> spyItemsRemovedArgs = spyItemsRemoved.takeFirst();
+ const KItemRangeList removedRange = spyItemsRemovedArgs.at(0).value<KItemRangeList>();
+ QCOMPARE(removedRange.size(), 1);
+ QCOMPARE(removedRange.first().index, index);
+ QCOMPARE(removedRange.first().count, 1);
+
+ QCOMPARE(indexOf(mediaUrl), -1);
+
+ QSignalSpy spyItemsInserted(m_model, &PlacesItemModel::itemsInserted);
+ fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096");
+ QTRY_COMPARE(m_model->count(), 17);
+ QCOMPARE(spyItemsInserted.count(), 1);
+ index = indexOf(mediaUrl);
+
+ const QList<QVariant> args = spyItemsInserted.takeFirst();
+ const KItemRangeList insertedRange = args.at(0).value<KItemRangeList>();
+ QCOMPARE(insertedRange.size(), 1);
+ QCOMPARE(insertedRange.first().index, index);
+ QCOMPARE(insertedRange.first().count, 1);
+}
+
+void PlacesItemModelTest::testDefaultViewProperties_data()
+{
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<DolphinView::Mode>("expectedViewMode");
+ QTest::addColumn<bool>("expectedPreviewShow");
+ QTest::addColumn<QList<QByteArray> >("expectedVisibleRole");
+
+ // places
+ QTest::newRow("Places - Home") << QUrl::fromLocalFile(QDir::homePath()) << DolphinView::IconsView << true << QList<QByteArray>({"text"});
+
+ // baloo -search
+ QTest::newRow("Baloo - Documents") << QUrl("search:/documents") << DolphinView::DetailsView << false << QList<QByteArray>({"text", "path"});
+
+ // audio files
+ QTest::newRow("Places - Audio") << QUrl("search:/audio") << DolphinView::DetailsView << false << QList<QByteArray>({"text", "artist", "album"});
+
+ // baloo - timeline
+ QTest::newRow("Baloo - Last Month") << QUrl("timeline:/lastmonth") << DolphinView::DetailsView << true << QList<QByteArray>({"text", "modificationtime"});
+
+ // devices
+ QTest::newRow("Devices - Floppy") << QUrl("file:///media/floppy0") << DolphinView::IconsView << true << QList<QByteArray>({"text"});
+
+}
+
+void PlacesItemModelTest::testDefaultViewProperties()
+{
+ QFETCH(QUrl, url);
+ QFETCH(DolphinView::Mode, expectedViewMode);
+ QFETCH(bool, expectedPreviewShow);
+ QFETCH(QList<QByteArray>, expectedVisibleRole);
+
+ ViewProperties properties(KFilePlacesModel::convertedUrl(url));
+ QCOMPARE(properties.viewMode(), expectedViewMode);
+ QCOMPARE(properties.previewsShown(), expectedPreviewShow);
+ QCOMPARE(properties.visibleRoles(), expectedVisibleRole);
+}
+
+void PlacesItemModelTest::testClear()
+{
+ QCOMPARE(m_model->count(), 17);
+ m_model->clear();
+ QCOMPARE(m_model->count(), 0);
+ QCOMPARE(m_model->hiddenCount(), 0);
+ m_model->refresh();
+ QTRY_COMPARE(m_model->count(), 17);
+}
+
+void PlacesItemModelTest::testHideItem()
+{
+ const QUrl mediaUrl = QUrl::fromLocalFile(QStringLiteral("/media/XO-Y4"));
+ const int index = indexOf(mediaUrl);
+
+ PlacesItem *item = m_model->placesItem(index);
+
+ QSignalSpy spyItemsRemoved(m_model, &PlacesItemModel::itemsRemoved);
+ QList<QVariant> spyItemsRemovedArgs;
+ KItemRangeList removedRange;
+
+ QSignalSpy spyItemsInserted(m_model, &PlacesItemModel::itemsInserted);
+ QList<QVariant> spyItemsInsertedArgs;
+ KItemRangeList insertedRange;
+ QVERIFY(item);
+
+ // hide an item
+ item->setHidden(true);
+
+ // check if items removed was fired
+ QTRY_COMPARE(m_model->count(), 16);
+ QCOMPARE(spyItemsRemoved.count(), 1);
+ spyItemsRemovedArgs = spyItemsRemoved.takeFirst();
+ removedRange = spyItemsRemovedArgs.at(0).value<KItemRangeList>();
+ QCOMPARE(removedRange.size(), 1);
+ QCOMPARE(removedRange.first().index, index);
+ QCOMPARE(removedRange.first().count, 1);
+
+ // allow model to show hidden items
+ m_model->setHiddenItemsShown(true);
+
+ // check if the items inserted was fired
+ spyItemsInsertedArgs = spyItemsInserted.takeFirst();
+ insertedRange = spyItemsInsertedArgs.at(0).value<KItemRangeList>();
+ QCOMPARE(insertedRange.size(), 1);
+ QCOMPARE(insertedRange.first().index, index);
+ QCOMPARE(insertedRange.first().count, 1);
+
+ // mark item as visible
+ item = m_model->placesItem(index);
+ item->setHidden(false);
+
+ // mark model to hide invisible items
+ m_model->setHiddenItemsShown(true);
+
+ QTRY_COMPARE(m_model->count(), 17);
+}
+
+void PlacesItemModelTest::testSystemItems()
+{
+ QCOMPARE(m_model->count(), 17);
+ for (int r = 0; r < m_model->count(); r++) {
+ QCOMPARE(m_model->placesItem(r)->isSystemItem(), !m_model->placesItem(r)->device().isValid());
+ }
+
+ QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
+
+ // create a new entry (non system item)
+ createPlaceItem(QStringLiteral("Temporary Dir"), QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation)), QString());
+
+ // check if the new entry was created
+ QTRY_COMPARE(itemsInsertedSpy.count(), 1);
+
+ // make sure the new place get removed
+ removePlaceAfter(3);
+
+ QList<QVariant> args = itemsInsertedSpy.takeFirst();
+ KItemRangeList range = args.at(0).value<KItemRangeList>();
+ QCOMPARE(range.first().index, 3);
+ QCOMPARE(range.first().count, 1);
+ QVERIFY(!m_model->placesItem(3)->isSystemItem());
+ QCOMPARE(m_model->count(), 18);
+
+ QTest::qWait(300);
+ // check if the removal signal is correct
+ QSignalSpy itemsRemovedSpy(m_model, &PlacesItemModel::itemsRemoved);
+ m_model->deleteItem(3);
+ QTRY_COMPARE(itemsRemovedSpy.count(), 1);
+ args = itemsRemovedSpy.takeFirst();
+ range = args.at(0).value<KItemRangeList>();
+ QCOMPARE(range.first().index, 3);
+ QCOMPARE(range.first().count, 1);
+ QTRY_COMPARE(m_model->count(), 17);
+
+ //cancel removal (it was removed above)
+ cancelPlaceRemoval(3);
+}
+
+void PlacesItemModelTest::testEditBookmark()
+{
+ const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
+ QScopedPointer<PlacesItemModel> other(new PlacesItemModel());
+
+ createPlaceItem(QStringLiteral("Temporary Dir"), QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation)), QString());
+
+ // make sure that the new item will be removed later
+ removePlaceAfter(3);
+
+ QSignalSpy itemsChangedSply(m_model, &PlacesItemModel::itemsChanged);
+
+ // modify place text
+ m_model->item(3)->setText(QStringLiteral("Renamed place"));
+ m_model->refresh();
+
+ // check if the correct signal was fired
+ QTRY_COMPARE(itemsChangedSply.count(), 1);
+ QList<QVariant> args = itemsChangedSply.takeFirst();
+ KItemRangeList range = args.at(0).value<KItemRangeList>();
+ QCOMPARE(range.first().index, 3);
+ QCOMPARE(range.first().count, 1);
+ QSet<QByteArray> roles = args.at(1).value<QSet<QByteArray> >();
+ QCOMPARE(roles.size(), 1);
+ QCOMPARE(*roles.begin(), QByteArrayLiteral("text"));
+ QCOMPARE(m_model->item(3)->text(), QStringLiteral("Renamed place"));
+
+ // check if the item was updated in the other model
+ QTRY_COMPARE(other->item(3)->text(), QStringLiteral("Renamed place"));
+}
+
+void PlacesItemModelTest::testEditAfterCreation()
+{
+ const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
+ QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
+
+ // create a new place
+ createPlaceItem(QStringLiteral("Temporary Dir"), tempUrl, QString());
+ QTRY_COMPARE(itemsInsertedSpy.count(), 1);
+
+ PlacesItemModel *model = new PlacesItemModel();
+ QTRY_COMPARE(model->count(), m_model->count());
+
+ // make sure that the new item will be removed later
+ removePlaceAfter(3);
+
+ // modify place text
+ PlacesItem *item = m_model->placesItem(3);
+ item->setText(QStringLiteral("Renamed place"));
+ m_model->refresh();
+
+ // check if the second model got the changes
+ QTRY_COMPARE(model->count(), m_model->count());
+ QTRY_COMPARE(model->placesItem(3)->text(), m_model->placesItem(3)->text());
+ QTRY_COMPARE(model->placesItem(3)->bookmark().metaDataItem(QStringLiteral("OnlyInApp")),
+ m_model->placesItem(3)->bookmark().metaDataItem(QStringLiteral("OnlyInApp")));
+ QTRY_COMPARE(model->placesItem(3)->icon(), m_model->placesItem(3)->icon());
+ QTRY_COMPARE(model->placesItem(3)->url(), m_model->placesItem(3)->url());
+}
+
+void PlacesItemModelTest::testEditMetadata()
+{
+ const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
+ QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
+
+ // create a new place
+ createPlaceItem(QStringLiteral("Temporary Dir"), tempUrl, QString());
+ QTRY_COMPARE(itemsInsertedSpy.count(), 1);
+
+ // check if the new entry was created
+ PlacesItemModel *model = new PlacesItemModel();
+ QTRY_COMPARE(model->count(), m_model->count());
+
+ // make sure that the new item will be removed later
+ removePlaceAfter(3);
+
+ // modify place metadata
+ PlacesItem *item = m_model->placesItem(3);
+ item->bookmark().setMetaDataItem(QStringLiteral("OnlyInApp"), KAboutData::applicationData().componentName());
+ m_model->refresh();
+
+ // check if the place was modified in both models
+ QTRY_COMPARE(model->placesItem(3)->bookmark().metaDataItem(QStringLiteral("OnlyInApp")),
+ KAboutData::applicationData().componentName());
+ QTRY_COMPARE(model->placesItem(3)->text(), m_model->placesItem(3)->text());
+ QTRY_COMPARE(model->placesItem(3)->bookmark().metaDataItem(QStringLiteral("OnlyInApp")),
+ m_model->placesItem(3)->bookmark().metaDataItem(QStringLiteral("OnlyInApp")));
+ QTRY_COMPARE(model->placesItem(3)->icon(), m_model->placesItem(3)->icon());
+ QTRY_COMPARE(model->placesItem(3)->url(), m_model->placesItem(3)->url());
+}
+
+void PlacesItemModelTest::testRefresh()
+{
+ const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
+ QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
+
+ // create a new place
+ createPlaceItem(QStringLiteral("Temporary Dir"), tempUrl, QString());
+ QTRY_COMPARE(itemsInsertedSpy.count(), 1);
+
+ PlacesItemModel *model = new PlacesItemModel();
+ QTRY_COMPARE(model->count(), m_model->count());
+
+ // make sure that the new item will be removed later
+ removePlaceAfter(3);
+
+ PlacesItem *item = m_model->placesItem(3);
+ PlacesItem *sameItem = model->placesItem(3);
+ QCOMPARE(item->text(), sameItem->text());
+
+ // modify place text
+ item->setText(QStringLiteral("Renamed place"));
+
+ // item from another model is not affected at the moment
+ QVERIFY(item->text() != sameItem->text());
+
+ // propagate change
+ m_model->refresh();
+
+ // item must be equal
+ QTRY_COMPARE(item->text(), sameItem->text());
+}
+
+void PlacesItemModelTest::testIcons_data()
+{
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<QString>("expectedIconName");
+
+ // places
+ QTest::newRow("Places - Home") << QUrl::fromLocalFile(QDir::homePath()) << QStringLiteral("user-home");
+
+ // baloo -search
+ QTest::newRow("Baloo - Documents") << QUrl("search:/documents") << QStringLiteral("folder-text");
+
+ // baloo - timeline
+ QTest::newRow("Baloo - Last Month") << QUrl("timeline:/lastmonth") << QStringLiteral("view-calendar-month");
+
+ // devices
+ QTest::newRow("Devices - Floppy") << QUrl("file:///media/floppy0") << QStringLiteral("blockdevice");
+}
+
+void PlacesItemModelTest::testIcons()
+{
+ QFETCH(QUrl, url);
+ QFETCH(QString, expectedIconName);
+
+ PlacesItem *item = m_model->placesItem(indexOf(url));
+ QCOMPARE(item->icon(), expectedIconName);
+
+ for (int r = 0; r < m_model->count(); r++) {
+ QVERIFY(!m_model->placesItem(r)->icon().isEmpty());
+ }
+}
+
+void PlacesItemModelTest::testDragAndDrop()
+{
+ QList<QVariant> args;
+ KItemRangeList range;
+ QStringList urls = initialUrls();
+ QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
+ QSignalSpy itemsRemovedSpy(m_model, &PlacesItemModel::itemsRemoved);
+
+ CHECK_PLACES_URLS(initialUrls());
+ // Move the KDE_ROOT_PATH at the end of the places list will case it to be moved to the end of the places group
+ QMimeData *dropData = createMimeData(QList<int>() << 1);
+ m_model->dropMimeDataBefore(m_model->count() - 1, dropData);
+ urls.move(1, 2);
+ delete dropData;
+
+ QTRY_COMPARE(itemsInsertedSpy.count(), 1);
+ QTRY_COMPARE(itemsRemovedSpy.count(), 1);
+
+ // remove item from actual position
+ args = itemsRemovedSpy.takeFirst();
+ range = args.at(0).value<KItemRangeList>();
+ QCOMPARE(range.size(), 1);
+ QCOMPARE(range.at(0).count, 1);
+ QCOMPARE(range.at(0).index, 1);
+
+ // insert intem in his group
+ args = itemsInsertedSpy.takeFirst();
+ range = args.at(0).value<KItemRangeList>();
+ QCOMPARE(range.size(), 1);
+ QCOMPARE(range.at(0).count, 1);
+ QCOMPARE(range.at(0).index, 2);
+
+ CHECK_PLACES_URLS(urls);
+
+ itemsInsertedSpy.clear();
+ itemsRemovedSpy.clear();
+
+ // Move the KDE_ROOT_PATH to his original position
+ dropData = createMimeData(QList<int>() << 2);
+ m_model->dropMimeDataBefore(1, dropData);
+ urls.move(2, 1);
+ delete dropData;
+
+ QTRY_COMPARE(itemsInsertedSpy.count(), 1);
+ QTRY_COMPARE(itemsRemovedSpy.count(), 1);
+
+ // remove item from actual position
+ args = itemsRemovedSpy.takeFirst();
+ range = args.at(0).value<KItemRangeList>();
+ QCOMPARE(range.size(), 1);
+ QCOMPARE(range.at(0).count, 1);
+ QCOMPARE(range.at(0).index, 2);
+
+ // insert intem in the requested position
+ args = itemsInsertedSpy.takeFirst();
+ range = args.at(0).value<KItemRangeList>();
+ QCOMPARE(range.size(), 1);
+ QCOMPARE(range.at(0).count, 1);
+ QCOMPARE(range.at(0).index, 1);
+
+ CHECK_PLACES_URLS(urls);
+}
+
+void PlacesItemModelTest::testHideDevices()
+{
+ QSignalSpy itemsRemoved(m_model, &PlacesItemModel::itemsRemoved);
+ QStringList urls = initialUrls();
+
+ m_model->setGroupHidden(KFilePlacesModel::RemovableDevicesType, true);
+ QTRY_VERIFY(m_model->isGroupHidden(KFilePlacesModel::RemovableDevicesType));
+ QTRY_COMPARE(itemsRemoved.count(), 3);
+
+ // remove removable-devices
+ urls.removeOne(QStringLiteral("/media/floppy0"));
+ urls.removeOne(QStringLiteral("/media/XO-Y4"));
+ urls.removeOne(QStringLiteral("/media/cdrom"));
+
+ // check if the correct urls was removed
+ CHECK_PLACES_URLS(urls);
+
+ delete m_model;
+ m_model = new PlacesItemModel();
+ QTRY_COMPARE(m_model->count(), urls.count());
+ CHECK_PLACES_URLS(urls);
+
+ // revert changes
+ m_model->setGroupHidden(KFilePlacesModel::RemovableDevicesType, false);
+ urls = initialUrls();
+ QTRY_COMPARE(m_model->count(), urls.count());
+ CHECK_PLACES_URLS(urls);
+}
+
+void PlacesItemModelTest::testDuplicatedEntries()
+{
+ QStringList urls = initialUrls();
+ // create a duplicated entry on bookmark
+ KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces"));
+ KBookmarkGroup root = bookmarkManager->root();
+ KBookmark bookmark = root.addBookmark(QStringLiteral("Duplicated Search Videos"), QUrl("search:/videos"), {});
+
+ const QString id = QUuid::createUuid().toString();
+ bookmark.setMetaDataItem(QStringLiteral("ID"), id);
+ bookmark.setMetaDataItem(QStringLiteral("OnlyInApp"), KAboutData::applicationData().componentName());
+ bookmarkManager->emitChanged(bookmarkManager->root());
+
+ PlacesItemModel *newModel = new PlacesItemModel();
+ QTRY_COMPARE(placesUrls(newModel).count(QStringLiteral("search:/videos")), 1);
+ QTRY_COMPARE(urls, placesUrls(newModel));
+ delete newModel;
+}
+
+void PlacesItemModelTest::renameAfterCreation()
+{
+ const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
+ QStringList urls = initialUrls();
+ PlacesItemModel *model = new PlacesItemModel();
+
+ CHECK_PLACES_URLS(urls);
+ QTRY_COMPARE(model->count(), m_model->count());
+
+ // create a new place
+ createPlaceItem(QStringLiteral("Temporary Dir"), tempUrl, QString());
+ urls.insert(3, tempUrl.toLocalFile());
+
+ // make sure that the new item will be removed later
+ removePlaceAfter(3);
+
+ CHECK_PLACES_URLS(urls);
+ QCOMPARE(model->count(), m_model->count());
+
+
+ // modify place text
+ QSignalSpy changedSpy(m_model, &PlacesItemModel::itemsChanged);
+
+ PlacesItem *item = m_model->placesItem(3);
+ item->setText(QStringLiteral("New Temporary Dir"));
+ item->setUrl(item->url());
+ item->setIcon(item->icon());
+ m_model->refresh();
+
+ QTRY_COMPARE(changedSpy.count(), 1);
+
+ // check if the place was modified in both models
+ QTRY_COMPARE(m_model->placesItem(3)->text(), QStringLiteral("New Temporary Dir"));
+ QTRY_COMPARE(model->placesItem(3)->text(), QStringLiteral("New Temporary Dir"));
+}
+
+QTEST_MAIN(PlacesItemModelTest)
+
+#include "placesitemmodeltest.moc"
diff --git a/src/tests/viewpropertiestest.cpp b/src/tests/viewpropertiestest.cpp
index 114afdc33..5193bb35a 100644
--- a/src/tests/viewpropertiestest.cpp
+++ b/src/tests/viewpropertiestest.cpp
@@ -56,7 +56,7 @@ void ViewPropertiesTest::init()
void ViewPropertiesTest::cleanup()
{
delete m_testDir;
- m_testDir = 0;
+ m_testDir = nullptr;
GeneralSettings::self()->setGlobalViewProps(m_globalViewProps);
GeneralSettings::self()->save();