diff --git a/autotests/fakeUdisks2.cpp b/autotests/fakeUdisks2.cpp deleted file mode 100644 index b123465..0000000 --- a/autotests/fakeUdisks2.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright 2017 Konstantinos Tsanaktsidis - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library. If not, see . -*/ - -#include "fakeUdisks2.h" - -FakeUdisks2BlockDevice::FakeUdisks2BlockDevice(QObject *parent, const QString &device, quint64 device_number) - : QDBusAbstractAdaptor(parent), m_device(device), m_device_number(device_number) -{ - -} - -const QString &FakeUdisks2BlockDevice::device() -{ - return m_device; -} - -quint64 FakeUdisks2BlockDevice::device_number() -{ - return m_device_number; -} diff --git a/autotests/fakeUdisks2.h b/autotests/fakeUdisks2.h deleted file mode 100644 index 00bec2a..0000000 --- a/autotests/fakeUdisks2.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - Copyright 2017 Konstantinos Tsanaktsidis - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library. If not, see . -*/ - -#ifndef SOLID_FAKE_UDISKS2 -#define SOLID_FAKE_UDISKS2 - -#include -#include -#include - -class FakeUdisks2BlockDevice : public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.freedesktop.UDisks2.Block") - Q_PROPERTY(QString Device READ device) - Q_PROPERTY(quint64 DeviceNumber READ device_number) -public: - FakeUdisks2BlockDevice(QObject *parent, const QString &device, quint64 device_number); - - const QString &device(); - QString m_device; - quint64 device_number(); - quint64 m_device_number; -}; - -#endif // SOLID_FAKE_UDISKS2 diff --git a/autotests/solidudisks2test.cpp b/autotests/solidudisks2test.cpp deleted file mode 100644 index e15b1dc..0000000 --- a/autotests/solidudisks2test.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - Copyright 2017 Konstantinos Tsanaktsidis - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library. If not, see . -*/ - -#include "qtest_dbus.h" -#include "fakeUdisks2.h" - -#include -#include -#include -#include -#include -#include - -#if HAVE_SYSMACROS_MAJOR_MINOR -#include -#elif HAVE_SYSTYPES_MAJOR_MINOR -#include -#elif HAVE_SYSMKDEV_MAJOR_MINOR -#include -#else -#error "Could not find a major/minor/makedev implementation" -#endif - -static Solid::Predicate majorMinorPredicate(quint32 majorNum, quint32 minorNum) -{ - Solid::Predicate hasMajorMinor( - Solid::DeviceInterface::Type::Block, - QStringLiteral("major"), - QVariant(majorNum), - Solid::Predicate::ComparisonOperator::Equals - ); - hasMajorMinor &= Solid::Predicate( - Solid::DeviceInterface::Type::Block, - QStringLiteral("minor"), - QVariant(minorNum), - Solid::Predicate::ComparisonOperator::Equals - ); - return hasMajorMinor; -} - - -class SolidUdisks2Test : public QObject -{ - Q_OBJECT -private Q_SLOTS: - void initTestCase(); - void testDeviceNumbersAreDecomposed(); - void testLargeDeviceNumbersAreDecomposed(); - -private: - FakeUdisks2BlockDevice *m_deviceSda1; - FakeUdisks2BlockDevice *m_deviceNvme0n1p2; - QObject *m_emptyDbus; -}; - -void SolidUdisks2Test::initTestCase() -{ - m_deviceSda1 = new FakeUdisks2BlockDevice(this, "sda1", makedev(8, 1)); - m_deviceNvme0n1p2 = new FakeUdisks2BlockDevice(this, "nvme0n1p2", makedev(259, 2)); - m_emptyDbus = new QObject(this); - QDBusConnection::systemBus().registerService(QStringLiteral("org.freedesktop.UDisks2")); - QDBusConnection::systemBus().registerObject(QStringLiteral("/org/freedesktop/UDisks2/block_devices/sda1"), m_deviceSda1, QDBusConnection::ExportAllContents); - QDBusConnection::systemBus().registerObject(QStringLiteral("/org/freedesktop/UDisks2/block_devices/nvme0n1p2"), m_deviceNvme0n1p2, QDBusConnection::ExportAllContents); - QDBusConnection::systemBus().registerObject(QStringLiteral("/org/freedesktop/UDisks2/drives"), m_emptyDbus, QDBusConnection::ExportAllContents); -} - -void SolidUdisks2Test::testDeviceNumbersAreDecomposed() -{ - auto hasMajorMinor = majorMinorPredicate(8, 1); - QList solidSda1BlockDeviceList = Solid::Device::listFromQuery(hasMajorMinor); - QCOMPARE(solidSda1BlockDeviceList.count(), 1); - - auto solidSda1BlockDevice = dynamic_cast( - solidSda1BlockDeviceList.first().asDeviceInterface(Solid::DeviceInterface::Type::Block) - ); - QVERIFY(solidSda1BlockDevice); - - QCOMPARE(solidSda1BlockDevice->deviceMajor(), 8); - QCOMPARE(solidSda1BlockDevice->deviceMinor(), 1); -} - -void SolidUdisks2Test::testLargeDeviceNumbersAreDecomposed() -{ - // On Linux, nvme devices have a major number > 255, so take up more than 8 bits of dev_t - // This test checks that the correct glibc routines are being used to handle this - auto hasMajorMinor = majorMinorPredicate(259, 2); - QList solidNvme0n1p2BlockDeviceList = Solid::Device::listFromQuery(hasMajorMinor); - QCOMPARE(solidNvme0n1p2BlockDeviceList.count(), 1); - - auto solidNvme0n1p2BlockDevice = dynamic_cast( - solidNvme0n1p2BlockDeviceList.first().asDeviceInterface(Solid::DeviceInterface::Type::Block) - ); - QVERIFY(solidNvme0n1p2BlockDevice); - - QCOMPARE(solidNvme0n1p2BlockDevice->deviceMajor(), 259); - QCOMPARE(solidNvme0n1p2BlockDevice->deviceMinor(), 2); -} - -QTEST_GUILESS_MAIN_SYSTEM_DBUS(SolidUdisks2Test) - -#include "solidudisks2test.moc"