File: halbasictest.cpp

package info (click to toggle)
solid 5.78.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 5,100 kB
  • sloc: cpp: 21,549; xml: 464; lex: 111; yacc: 83; sh: 14; makefile: 5
file content (134 lines) | stat: -rw-r--r-- 4,235 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
    SPDX-FileCopyrightText: 2005, 2006 Kevin Ottens <ervin@kde.org>

    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/

#include "halbasictest.h"

#include <QTest>

#include "solid/devices/backends/hal/halmanager.h"

#include <solid/device.h>
#include <solid/devices/ifaces/device.h>
#include <solid/devices/ifaces/deviceinterface.h>
#include <solid/devices/ifaces/processor.h>
#include "solid/devices/backends/hal/halprocessor.h"

#include <QDBusConnection>

QTEST_MAIN(HalBasicTest)

HalBasicTest::HalBasicTest(QObject *parent)
    : QObject(parent)
{
    qputenv("SOLID_HAL_LEGACY", "1");
}

void HalBasicTest::initTestCase()
{
    if (!QDBusConnection::systemBus().isConnected())
        QSKIP("D-Bus not running");
}

void HalBasicTest::testBasic()
{
    Solid::Backends::Hal::HalManager *manager = new Solid::Backends::Hal::HalManager(nullptr);

    QVERIFY(manager->deviceExists("/org/freedesktop/Hal/devices/computer"));
    QVERIFY(!manager->allDevices().isEmpty());

    QVERIFY(!manager->devicesFromQuery(QString(), Solid::DeviceInterface::Processor).isEmpty());

    QString proc_udi = manager->devicesFromQuery(QString(), Solid::DeviceInterface::Processor).at(0);

    Solid::Backends::Hal::HalDevice *processor = qobject_cast<Solid::Backends::Hal::HalDevice *>(manager->createDevice(proc_udi));

    QCOMPARE(processor->udi(), proc_udi);
    QCOMPARE(processor->parentUdi(), QString("/org/freedesktop/Hal/devices/computer"));
    QVERIFY(!processor->allProperties().isEmpty());
    QVERIFY(processor->propertyExists("info.product"));
    QVERIFY(!processor->propertyExists("the.meaning.of.life"));
    QVERIFY(processor->queryDeviceInterface(Solid::DeviceInterface::Processor));
    QVERIFY(!processor->queryDeviceInterface(Solid::DeviceInterface::OpticalDisc));

    QObject *interface = processor->createDeviceInterface(Solid::DeviceInterface::Processor);
    Solid::Ifaces::Processor *proc_iface = qobject_cast<Solid::Ifaces::Processor *>(interface);

    QVERIFY(proc_iface != nullptr);

#if 0
    // HAL locking support being broken anyway...
    QVERIFY(!processor->isLocked());
    QVERIFY(processor->lock("No reason..."));
    QVERIFY(processor->isLocked());
    QCOMPARE(processor->lockReason(), QString("No reason..."));
    QVERIFY(!processor->lock("Need a reason?"));
    QVERIFY(processor->unlock());
#endif

    QObject *object = processor;
    QCOMPARE(interface->parent(), object);

    delete processor;
    delete manager;
}

void HalBasicTest::testProcessorList()
{
    QList<Solid::Device> list = Solid::Device::listFromType(Solid::DeviceInterface::Processor, QString());
    qDebug() << "Number of processors:" << list.size();
    if (!list.isEmpty()) {
        Solid::Processor *p = list[0].as<Solid::Processor>();
        QVERIFY(p);
        Solid::Processor::InstructionSets features = p->instructionSets();
        qDebug() << "features:" << features;
    }
}

void HalBasicTest::testDeviceCreation()
{
    // Uncomment to check if the "still reachable" number grows in
    // valgrind, which probably indicates a memory leak.
    //for (int i=0; i<1000; i++)
    {
        Solid::Device dev("/org/freedesktop/Hal/devices/computer");
        QVERIFY(dev.isValid());
        dev = Solid::Device("ddd/ff");
        QVERIFY(!dev.isValid());
    }
}

void HalBasicTest::testSignalHandling()
{
    Solid::Backends::Hal::HalManager *manager = new Solid::Backends::Hal::HalManager(nullptr);
    m_device = qobject_cast<Solid::Backends::Hal::HalDevice *>(manager->createDevice("/org/freedesktop/Hal/devices/computer"));

#if 0
    connect(m_device, SIGNAL(propertyChanged(QMap<QString,int>)),
            this, SLOT(slotPropertyChanged(QMap<QString,int>)));

    // HAL locking support being broken anyway...
    QVERIFY(!m_device->isLocked());
    m_signalProcessed = false;
    m_device->lock("Still no reason... really");
    QVERIFY(m_device->isLocked());
    QVERIFY(m_signalProcessed);
#endif

    delete m_device;
    delete manager;
}

void HalBasicTest::slotPropertyChanged(const QMap<QString, int> &changes)
{
    Q_UNUSED(changes)
#if 0
    QVERIFY(m_device->isLocked());
    m_signalProcessed = true;
#endif
}

#include "moc_halbasictest.cpp"