File indexing completed on 2024-04-14 03:58:06

0001 /*
0002     SPDX-FileCopyrightText: 2005 Kevin Ottens <ervin@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "solidhwtest.h"
0008 
0009 #include <QSignalSpy>
0010 #include <QTest>
0011 
0012 #include "solid/devices/managerbase_p.h"
0013 #include <solid/device.h>
0014 #include <solid/devicenotifier.h>
0015 #include <solid/genericinterface.h>
0016 #include <solid/predicate.h>
0017 #include <solid/processor.h>
0018 #include <solid/storageaccess.h>
0019 #include <solid/storagevolume.h>
0020 
0021 #include <fakedevice.h>
0022 #include <fakemanager.h>
0023 
0024 #include <stdlib.h>
0025 
0026 #ifndef FAKE_COMPUTER_XML
0027 #error "FAKE_COMPUTER_XML not set. An XML file describing a computer is required for this test"
0028 #endif
0029 
0030 QTEST_MAIN(SolidHwTest)
0031 
0032 #if defined(Q_OS_WIN)
0033 #include <qt_windows.h>
0034 #define setenv(x, y, z) SetEnvironmentVariableA(x, y)
0035 #endif
0036 
0037 void SolidHwTest::initTestCase()
0038 {
0039     qputenv("SOLID_FAKEHW", FAKE_COMPUTER_XML);
0040     Solid::ManagerBasePrivate *manager = dynamic_cast<Solid::ManagerBasePrivate *>(Solid::DeviceNotifier::instance());
0041     fakeManager = qobject_cast<Solid::Backends::Fake::FakeManager *>(manager->managerBackends().first());
0042 }
0043 
0044 void SolidHwTest::testAllDevices()
0045 {
0046     const QList<Solid::Device> devices = Solid::Device::allDevices();
0047 
0048     // Verify that the framework reported correctly the devices available
0049     // in the backend.
0050     QStringList expected_udis;
0051     QStringList received_udis;
0052 
0053     expected_udis = fakeManager->allDevices();
0054     std::sort(expected_udis.begin(), expected_udis.end());
0055 
0056     for (const Solid::Device &dev : devices) {
0057         received_udis << dev.udi();
0058     }
0059 
0060     std::sort(received_udis.begin(), received_udis.end());
0061 
0062     QCOMPARE(expected_udis, received_udis);
0063 }
0064 
0065 void SolidHwTest::testDeviceBasicFeatures()
0066 {
0067     // Retrieve a valid Device object
0068     Solid::Device valid_dev("/org/kde/solid/fakehw/storage_model_solid_writer");
0069 
0070     QCOMPARE(valid_dev.isValid(), true);
0071 
0072     // A few attempts at creating invalid Device objects
0073     Solid::Device invalid_dev("uhoh? doesn't exist, I guess");
0074     QCOMPARE(invalid_dev.isValid(), false);
0075     invalid_dev = Solid::Device(QString());
0076     QCOMPARE(invalid_dev.isValid(), false);
0077     invalid_dev = Solid::Device();
0078     QCOMPARE(invalid_dev.isValid(), false);
0079 
0080     QCOMPARE(valid_dev.udi(), QString("/org/kde/solid/fakehw/storage_model_solid_writer"));
0081     QCOMPARE(invalid_dev.udi(), QString());
0082 
0083     // Query properties
0084     QCOMPARE(valid_dev.as<Solid::GenericInterface>()->propertyExists("name"), true);
0085     QCOMPARE(valid_dev.as<Solid::GenericInterface>()->propertyExists("foo.bar"), false);
0086     QCOMPARE((QObject *)invalid_dev.as<Solid::GenericInterface>(), (QObject *)nullptr);
0087 
0088     QCOMPARE(valid_dev.as<Solid::GenericInterface>()->property("name"), QVariant("Solid IDE DVD Writer"));
0089     QVERIFY(!valid_dev.as<Solid::GenericInterface>()->property("foo.bar").isValid());
0090 
0091     Solid::Backends::Fake::FakeDevice *fake_device = fakeManager->findDevice("/org/kde/solid/fakehw/storage_model_solid_writer");
0092     QMap<QString, QVariant> expected_properties = fake_device->allProperties();
0093 
0094     QCOMPARE(valid_dev.as<Solid::GenericInterface>()->allProperties(), expected_properties);
0095 
0096     // Query device interfaces
0097     QCOMPARE(valid_dev.isDeviceInterface(Solid::DeviceInterface::StorageDrive), true);
0098     QCOMPARE(valid_dev.isDeviceInterface(Solid::DeviceInterface::OpticalDrive), true);
0099     QCOMPARE(valid_dev.isDeviceInterface(Solid::DeviceInterface::StorageVolume), false);
0100 
0101     QCOMPARE(invalid_dev.isDeviceInterface(Solid::DeviceInterface::Unknown), false);
0102     QCOMPARE(invalid_dev.isDeviceInterface(Solid::DeviceInterface::StorageDrive), false);
0103 
0104     // Query parent
0105     QCOMPARE(valid_dev.parentUdi(), QString("/org/kde/solid/fakehw/pci_002_ide_1_0"));
0106     QCOMPARE(valid_dev.parent().udi(), Solid::Device("/org/kde/solid/fakehw/pci_002_ide_1_0").udi());
0107 
0108     QVERIFY(!invalid_dev.parent().isValid());
0109     QVERIFY(invalid_dev.parentUdi().isEmpty());
0110 
0111     // Query vendor/product
0112     QCOMPARE(valid_dev.vendor(), QString("Acme Corporation"));
0113     QCOMPARE(valid_dev.product(), QString("Solid IDE DVD Writer"));
0114 
0115     QCOMPARE(invalid_dev.vendor(), QString());
0116     QCOMPARE(invalid_dev.product(), QString());
0117 }
0118 
0119 void SolidHwTest::testManagerSignals()
0120 {
0121     fakeManager->unplug("/org/kde/solid/fakehw/acpi_CPU0");
0122 
0123     // Heh, we missed a processor in this system ;-)
0124     // We're going to add this device, and check that the signal has been
0125     // properly emitted by the manager
0126     QSignalSpy added(Solid::DeviceNotifier::instance(), SIGNAL(deviceAdded(QString)));
0127     fakeManager->plug("/org/kde/solid/fakehw/acpi_CPU0");
0128     QCOMPARE(added.count(), 1);
0129     QCOMPARE(added.at(0).at(0).toString(), QString("/org/kde/solid/fakehw/acpi_CPU0"));
0130 
0131     // Moreover we check that the device is really available
0132     Solid::Device cpu("/org/kde/solid/fakehw/acpi_CPU0");
0133     QVERIFY(cpu.isValid());
0134 
0135     // Finally we remove the device and spy the corresponding signal again
0136     QSignalSpy removed(Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(QString)));
0137     fakeManager->unplug("/org/kde/solid/fakehw/acpi_CPU0");
0138     QCOMPARE(added.count(), 1);
0139     QCOMPARE(added.at(0).at(0).toString(), QString("/org/kde/solid/fakehw/acpi_CPU0"));
0140 
0141     // The Device object should become automatically invalid
0142     QVERIFY(!cpu.isValid());
0143 
0144     // Restore original state
0145     fakeManager->plug("/org/kde/solid/fakehw/acpi_CPU0");
0146 }
0147 
0148 void SolidHwTest::testDeviceSignals()
0149 {
0150     // A button is a nice device for testing state changes, isn't it?
0151     Solid::Backends::Fake::FakeDevice *fake = fakeManager->findDevice("/org/kde/solid/fakehw/platform_floppy_0_storage_virt_volume");
0152     Solid::Device device("/org/kde/solid/fakehw/platform_floppy_0_storage_virt_volume");
0153 
0154     // We'll spy our floppy
0155     connect(device.as<Solid::GenericInterface>(), SIGNAL(propertyChanged(QMap<QString, int>)), this, SLOT(slotPropertyChanged(QMap<QString, int>)));
0156     QSignalSpy condition_raised(device.as<Solid::GenericInterface>(), SIGNAL(conditionRaised(QString, QString)));
0157 
0158     fake->setProperty("mountPoint", "/tmp.foo"); // The button is now pressed (modified property)
0159     fake->raiseCondition("Floppy Closed", "Why not?"); // Since it's a LID we notify this change
0160     fake->setProperty("hactar", 42); // We add a property
0161     fake->removeProperty("hactar"); // We remove a property
0162 
0163     // 3 property changes occurred in the device
0164     QCOMPARE(m_changesList.count(), 3);
0165 
0166     QMap<QString, int> changes;
0167 
0168     // First one is a "PropertyModified" for "button.state"
0169     changes = m_changesList.at(0);
0170     QCOMPARE(changes.count(), 1);
0171     QVERIFY(changes.contains("mountPoint"));
0172     QCOMPARE(changes["stateValue"], (int)Solid::GenericInterface::PropertyModified);
0173 
0174     // Second one is a "PropertyAdded" for "hactar"
0175     changes = m_changesList.at(1);
0176     QCOMPARE(changes.count(), 1);
0177     QVERIFY(changes.contains("hactar"));
0178     QCOMPARE(changes["hactar"], (int)Solid::GenericInterface::PropertyAdded);
0179 
0180     // Third one is a "PropertyRemoved" for "hactar"
0181     changes = m_changesList.at(2);
0182     QCOMPARE(changes.count(), 1);
0183     QVERIFY(changes.contains("hactar"));
0184     QCOMPARE(changes["hactar"], (int)Solid::GenericInterface::PropertyRemoved);
0185 
0186     // Only one condition has been raised in the device
0187     QCOMPARE(condition_raised.count(), 1);
0188 
0189     // It must be identical to the condition we raised by hand
0190     QCOMPARE(condition_raised.at(0).at(0).toString(), QString("Floppy Closed"));
0191     QCOMPARE(condition_raised.at(0).at(1).toString(), QString("Why not?"));
0192 }
0193 
0194 void SolidHwTest::testDeviceExistence()
0195 {
0196     QCOMPARE(Solid::Device("/org/kde/solid/fakehw/platform_floppy_0_storage_virt_volume").isValid(), true);
0197     QCOMPARE(Solid::Device("/org/kde/solid/fakehw/volume_label_SOLIDMAN_BEGINS").isValid(), true);
0198 
0199     // Note the extra space
0200     QCOMPARE(Solid::Device("/org/kde/solid/fakehw/computer ").isValid(), false);
0201     QCOMPARE(Solid::Device("#'({(]").isValid(), false);
0202     QCOMPARE(Solid::Device(QString()).isValid(), false);
0203 
0204     // Now try to see if isValid() changes on plug/unplug events
0205     Solid::Device cpu("/org/kde/solid/fakehw/acpi_CPU0");
0206     QVERIFY(cpu.isValid());
0207     fakeManager->unplug("/org/kde/solid/fakehw/acpi_CPU0");
0208     QVERIFY(!cpu.isValid());
0209     fakeManager->plug("/org/kde/solid/fakehw/acpi_CPU0");
0210     QVERIFY(cpu.isValid());
0211 }
0212 
0213 void SolidHwTest::testDeviceInterfaces()
0214 {
0215     Solid::Device cpu("/org/kde/solid/fakehw/acpi_CPU0");
0216 
0217     Solid::DeviceInterface *iface = cpu.asDeviceInterface(Solid::DeviceInterface::Processor);
0218     Solid::DeviceInterface *processor = cpu.as<Solid::Processor>();
0219 
0220     QVERIFY(cpu.isDeviceInterface(Solid::DeviceInterface::Processor));
0221     QVERIFY(iface != nullptr);
0222     QCOMPARE(iface, processor);
0223 
0224     Solid::Device cpu2("/org/kde/solid/fakehw/acpi_CPU0");
0225     QCOMPARE(cpu.as<Solid::Processor>(), cpu2.as<Solid::Processor>());
0226     QCOMPARE(cpu.as<Solid::GenericInterface>(), cpu2.as<Solid::GenericInterface>());
0227 
0228     QPointer<Solid::Processor> p = cpu.as<Solid::Processor>();
0229     QVERIFY(p != nullptr);
0230     fakeManager->unplug("/org/kde/solid/fakehw/acpi_CPU0");
0231     QVERIFY(p == nullptr);
0232     fakeManager->plug("/org/kde/solid/fakehw/acpi_CPU0");
0233 
0234     QPointer<Solid::StorageVolume> v;
0235     QPointer<Solid::StorageVolume> v2;
0236     {
0237         Solid::Device partition("/org/kde/solid/fakehw/volume_uuid_f00ba7");
0238         v = partition.as<Solid::StorageVolume>();
0239         QVERIFY(v != nullptr);
0240         {
0241             Solid::Device partition2("/org/kde/solid/fakehw/volume_uuid_f00ba7");
0242             v2 = partition2.as<Solid::StorageVolume>();
0243             QVERIFY(v2 != nullptr);
0244             QVERIFY(v == v2);
0245         }
0246         QVERIFY(v != nullptr);
0247         QVERIFY(v2 != nullptr);
0248     }
0249     QVERIFY(v != nullptr);
0250     QVERIFY(v2 != nullptr);
0251     fakeManager->unplug("/org/kde/solid/fakehw/volume_uuid_f00ba7");
0252     QVERIFY(v == nullptr);
0253     QVERIFY(v2 == nullptr);
0254     fakeManager->plug("/org/kde/solid/fakehw/volume_uuid_f00ba7");
0255 }
0256 
0257 void SolidHwTest::testDeviceInterfaceIntrospection_data()
0258 {
0259     QTest::addColumn<QString>("name");
0260     QTest::addColumn<int>("value");
0261 
0262     QTest::newRow("DeviceInterface: Unknown") << "Unknown" << (int)Solid::DeviceInterface::Unknown;
0263     QTest::newRow("DeviceInterface: Processor") << "Processor" << (int)Solid::DeviceInterface::Processor;
0264     QTest::newRow("DeviceInterface: Block") << "Block" << (int)Solid::DeviceInterface::Block;
0265     QTest::newRow("DeviceInterface: StorageDrive") << "StorageDrive" << (int)Solid::DeviceInterface::StorageDrive;
0266     QTest::newRow("DeviceInterface: OpticalDrive") << "OpticalDrive" << (int)Solid::DeviceInterface::OpticalDrive;
0267     QTest::newRow("DeviceInterface: StorageVolume") << "StorageVolume" << (int)Solid::DeviceInterface::StorageVolume;
0268     QTest::newRow("DeviceInterface: OpticalDisc") << "OpticalDisc" << (int)Solid::DeviceInterface::OpticalDisc;
0269     QTest::newRow("DeviceInterface: Camera") << "Camera" << (int)Solid::DeviceInterface::Camera;
0270     QTest::newRow("DeviceInterface: PortableMediaPlayer") << "PortableMediaPlayer" << (int)Solid::DeviceInterface::PortableMediaPlayer;
0271     QTest::newRow("DeviceInterface: Battery") << "Battery" << (int)Solid::DeviceInterface::Battery;
0272 }
0273 
0274 void SolidHwTest::testDeviceInterfaceIntrospection()
0275 {
0276     QFETCH(QString, name);
0277     QFETCH(int, value);
0278 
0279     QCOMPARE(Solid::DeviceInterface::typeToString((Solid::DeviceInterface::Type)value), name);
0280     QCOMPARE((int)Solid::DeviceInterface::stringToType(name), value);
0281 }
0282 
0283 void SolidHwTest::testDeviceInterfaceIntrospectionCornerCases()
0284 {
0285     QCOMPARE(Solid::DeviceInterface::typeToString((Solid::DeviceInterface::Type)-1), QString());
0286     QCOMPARE((int)Solid::DeviceInterface::stringToType("blup"), -1);
0287 }
0288 
0289 static QStringList to_string_list(const QList<Solid::Device> &list)
0290 {
0291     QStringList res;
0292     res.reserve(list.size());
0293     for (const Solid::Device &device : list) {
0294         res << device.udi();
0295     }
0296     return res;
0297 }
0298 
0299 void SolidHwTest::testInvalidPredicate()
0300 {
0301     QString str_pred = "[[Processor.maxSpeed == 3201 AND Processor.canChangeFrequency == false] OR StorageVolume.mountPoint == '/media/blup']";
0302     // Since str_pred is canonicalized, fromString().toString() should be invariant
0303     QCOMPARE(Solid::Predicate::fromString(str_pred).toString(), str_pred);
0304 
0305     // Invalid predicate
0306     str_pred = "[StorageVolume.ignored == false AND OpticalDisc.isBlank == true AND OpticalDisc.discType & 'CdRecordable|CdRewritable']";
0307     QVERIFY(!Solid::Predicate::fromString(str_pred).isValid());
0308 }
0309 
0310 void SolidHwTest::testPredicate()
0311 {
0312     Solid::Device dev("/org/kde/solid/fakehw/acpi_CPU0");
0313     /* clang-format off */
0314     Solid::Predicate p1 = (Solid::Predicate(Solid::DeviceInterface::Processor, "maxSpeed", 3200)
0315                            & Solid::Predicate(Solid::DeviceInterface::Processor, "canChangeFrequency", true));
0316     Solid::Predicate p2 = Solid::Predicate(Solid::DeviceInterface::Processor, "maxSpeed", 3200)
0317                           & Solid::Predicate(Solid::DeviceInterface::Processor, "canChangeFrequency", false);
0318     Solid::Predicate p3 = Solid::Predicate(Solid::DeviceInterface::Processor, "maxSpeed", 3201)
0319                           | Solid::Predicate(Solid::DeviceInterface::Processor, "canChangeFrequency", true);
0320     Solid::Predicate p4 = Solid::Predicate(Solid::DeviceInterface::Processor, "maxSpeed", 3201)
0321                           | Solid::Predicate(Solid::DeviceInterface::Processor, "canChangeFrequency", false);
0322     Solid::Predicate p5 =
0323         Solid::Predicate::fromString("[[Processor.maxSpeed == 3201 AND Processor.canChangeFrequency == false] OR StorageVolume.mountPoint == '/media/blup']");
0324     /* clang-format on */
0325 
0326     QVERIFY(p1.matches(dev));
0327     QVERIFY(!p2.matches(dev));
0328     QVERIFY(p3.matches(dev));
0329     QVERIFY(!p4.matches(dev));
0330 
0331     Solid::Predicate p6 = Solid::Predicate::fromString("StorageVolume.usage == 'Other'");
0332     Solid::Predicate p7 = Solid::Predicate::fromString(QString("StorageVolume.usage == %1").arg((int)Solid::StorageVolume::Other));
0333     QVERIFY(!p6.matches(dev));
0334     QVERIFY(!p7.matches(dev));
0335     dev = Solid::Device("/org/kde/solid/fakehw/volume_part2_size_1024");
0336     QVERIFY(p6.matches(dev));
0337     QVERIFY(p7.matches(dev));
0338 
0339     QList<Solid::Device> list;
0340 
0341     QStringList cpuSet;
0342     cpuSet << QString("/org/kde/solid/fakehw/acpi_CPU0") << QString("/org/kde/solid/fakehw/acpi_CPU1");
0343 
0344     list = Solid::Device::listFromQuery(p1);
0345     QCOMPARE(list.size(), 2);
0346     QCOMPARE(to_string_list(list), cpuSet);
0347 
0348     list = Solid::Device::listFromQuery(p2);
0349     QCOMPARE(list.size(), 0);
0350 
0351     list = Solid::Device::listFromQuery(p3);
0352     QCOMPARE(list.size(), 2);
0353     QCOMPARE(to_string_list(list), cpuSet);
0354 
0355     list = Solid::Device::listFromQuery(p4);
0356     QCOMPARE(list.size(), 0);
0357 
0358     list = Solid::Device::listFromQuery("[Processor.canChangeFrequency==true AND Processor.number==1]");
0359     QCOMPARE(list.size(), 1);
0360     QCOMPARE(list.at(0).udi(), QString("/org/kde/solid/fakehw/acpi_CPU1"));
0361 
0362     // writeSpeeds is a QList, make sure we can match a single element.
0363     list = Solid::Device::listFromQuery("[OpticalDrive.writeSpeeds==2117 AND OpticalDrive.removable==true]");
0364     QCOMPARE(list.size(), 1);
0365     QCOMPARE(list.at(0).udi(), QString("/org/kde/solid/fakehw/storage_model_solid_writer"));
0366 }
0367 
0368 void SolidHwTest::testQueryStorageVolumeOrProcessor()
0369 {
0370     auto list = Solid::Device::listFromQuery("[Processor.number==1 OR IS StorageVolume]");
0371     QCOMPARE(list.size(), 10);
0372 
0373     // make sure predicate case-insensitiveness is sane
0374     list = Solid::Device::listFromQuery("[Processor.number==1 or is StorageVolume]");
0375     QCOMPARE(list.size(), 10);
0376     list = Solid::Device::listFromQuery("[Processor.number==1 oR Is StorageVolume]");
0377     QCOMPARE(list.size(), 10);
0378     QStringList expected{"/org/kde/solid/fakehw/acpi_CPU1",
0379                          "/org/kde/solid/fakehw/platform_floppy_0_storage_virt_volume",
0380                          "/org/kde/solid/fakehw/volume_label_SOLIDMAN_BEGINS",
0381                          "/org/kde/solid/fakehw/volume_part1_size_993284096",
0382                          "/org/kde/solid/fakehw/volume_part2_size_1024",
0383                          "/org/kde/solid/fakehw/volume_part5_size_1048576",
0384                          "/org/kde/solid/fakehw/volume_uuid_5011",
0385                          "/org/kde/solid/fakehw/volume_uuid_c0ffee",
0386                          "/org/kde/solid/fakehw/volume_uuid_f00ba7",
0387                          "/org/kde/solid/fakehw/volume_uuid_feedface"};
0388     QCOMPARE(to_string_list(list), expected);
0389 
0390     list = Solid::Device::listFromQuery("[IS Processor OR IS StorageVolume]");
0391     QCOMPARE(list.size(), 11);
0392     expected.prepend("/org/kde/solid/fakehw/acpi_CPU0");
0393     QCOMPARE(to_string_list(list), expected);
0394 }
0395 
0396 void SolidHwTest::testQueryStorageVolumeOrStorageAccess()
0397 {
0398     // the query from KFilePlacesModel
0399     const auto list = Solid::Device::listFromQuery(
0400         "[[[[ StorageVolume.ignored == false AND [ StorageVolume.usage == 'FileSystem' OR StorageVolume.usage == 'Encrypted' ]]"
0401         " OR "
0402         "[ IS StorageAccess AND StorageDrive.driveType == 'Floppy' ]]"
0403         " OR "
0404         "OpticalDisc.availableContent & 'Audio' ]"
0405         " OR "
0406         "StorageAccess.ignored == false ]");
0407     const QStringList expected{"/org/kde/solid/fakehw/fstab/thehost/solidpath",
0408                                "/org/kde/solid/fakehw/platform_floppy_0_storage_virt_volume",
0409                                "/org/kde/solid/fakehw/volume_part1_size_993284096",
0410                                "/org/kde/solid/fakehw/volume_uuid_5011",
0411                                "/org/kde/solid/fakehw/volume_uuid_f00ba7"};
0412     QCOMPARE(to_string_list(list), expected);
0413 }
0414 
0415 void SolidHwTest::testQueryWithParentUdi()
0416 {
0417     QString parentUdi = "/org/kde/solid/fakehw/storage_model_solid_reader";
0418     Solid::DeviceInterface::Type ifaceType = Solid::DeviceInterface::Unknown;
0419     QCOMPARE(fakeManager->devicesFromQuery(parentUdi, ifaceType).size(), 1);
0420     QCOMPARE(fakeManager->devicesFromQuery(parentUdi, ifaceType).at(0), QString("/org/kde/solid/fakehw/volume_label_SOLIDMAN_BEGINS"));
0421 
0422     ifaceType = Solid::DeviceInterface::Processor;
0423     QCOMPARE(fakeManager->devicesFromQuery(parentUdi, ifaceType).size(), 0);
0424 
0425     parentUdi = "/org/kde/solid/fakehw/computer";
0426     QCOMPARE(fakeManager->devicesFromQuery(parentUdi, ifaceType).size(), 2);
0427     QCOMPARE(fakeManager->devicesFromQuery(parentUdi, ifaceType).at(0), QString("/org/kde/solid/fakehw/acpi_CPU0"));
0428     QCOMPARE(fakeManager->devicesFromQuery(parentUdi, ifaceType).at(1), QString("/org/kde/solid/fakehw/acpi_CPU1"));
0429 }
0430 
0431 void SolidHwTest::testListFromTypeProcessor()
0432 {
0433     const auto ifaceType = Solid::DeviceInterface::Processor;
0434     const auto list = Solid::Device::listFromType(ifaceType, QString());
0435     QCOMPARE(list.size(), 2);
0436     QCOMPARE(list.at(0).udi(), QString("/org/kde/solid/fakehw/acpi_CPU0"));
0437     QCOMPARE(list.at(1).udi(), QString("/org/kde/solid/fakehw/acpi_CPU1"));
0438 }
0439 
0440 void SolidHwTest::testListFromTypeInvalid()
0441 {
0442     const auto list = Solid::Device::listFromQuery("blup", QString());
0443     QCOMPARE(list.size(), 0);
0444 }
0445 
0446 void SolidHwTest::testSetupTeardown()
0447 {
0448     Solid::StorageAccess *access;
0449     {
0450         Solid::Device device("/org/kde/solid/fakehw/volume_part1_size_993284096");
0451         access = device.as<Solid::StorageAccess>();
0452     }
0453 
0454     QList<QVariant> args;
0455     QSignalSpy spy(access, SIGNAL(accessibilityChanged(bool, QString)));
0456 
0457     access->teardown();
0458 
0459     QCOMPARE(spy.count(), 1);
0460     args = spy.takeFirst();
0461     QCOMPARE(args.at(0).toBool(), false);
0462 
0463     access->setup();
0464 
0465     QCOMPARE(spy.count(), 1);
0466     args = spy.takeFirst();
0467     QCOMPARE(args.at(0).toBool(), true);
0468 }
0469 
0470 void SolidHwTest::slotPropertyChanged(const QMap<QString, int> &changes)
0471 {
0472     m_changesList << changes;
0473 }
0474 
0475 #include "moc_solidhwtest.cpp"