File: solidmttest.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 (87 lines) | stat: -rw-r--r-- 2,798 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
/*
    SPDX-FileCopyrightText: 2008 Kevin Ottens <ervin@kde.org>

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

#include <QObject>
#include <QThread>
#include <QThreadPool>
#include <qtconcurrentrun.h>

#include <QTest>

#include <solid/device.h>
#include <solid/predicate.h>
#include <solid/storagevolume.h>
#include <solid/storagedrive.h>
#include <solid/genericinterface.h>

class SolidMtTest : public QObject
{
    Q_OBJECT
private Q_SLOTS:
    void testWorkerThread();
    void testThreadedPredicate();
};

class WorkerThread : public QThread
{
    Q_OBJECT
protected:
    void run() override
    {
        Solid::Device dev("/org/freedesktop/Hal/devices/computer");

        const QList<Solid::Device> driveList = Solid::Device::listFromType(Solid::DeviceInterface::StorageDrive);
        for (const Solid::Device &solidDevice : driveList) {
            const Solid::StorageDrive *solidDrive = solidDevice.as<Solid::StorageDrive>();
            Q_ASSERT(solidDrive);
            Q_UNUSED(solidDrive);
        }
    }
};

static void doPredicates()
{
    Solid::Predicate p5 = Solid::Predicate::fromString("[[Processor.maxSpeed == 3201 AND Processor.canChangeFrequency == false] OR StorageVolume.mountPoint == '/media/blup']");

    Solid::Predicate p6 = Solid::Predicate::fromString("StorageVolume.usage == 'Other'");
    Solid::Predicate p7 = Solid::Predicate::fromString(QString("StorageVolume.usage == %1").arg((int)Solid::StorageVolume::Other));
}

QTEST_MAIN(SolidMtTest)

void SolidMtTest::testWorkerThread()
{
    Solid::Device dev("/org/freedesktop/Hal/devices/acpi_ADP1");

    WorkerThread *wt = new WorkerThread;
    wt->start();
    wt->wait();

    const QList<Solid::Device> driveList = Solid::Device::listFromType(Solid::DeviceInterface::StorageDrive);
    for (const Solid::Device &solidDevice : driveList) {
        const Solid::GenericInterface *solidDrive = solidDevice.as<Solid::GenericInterface>();
        Q_ASSERT(solidDrive);
        Q_UNUSED(solidDrive);
    }

    delete wt;
}

void SolidMtTest::testThreadedPredicate()
{
    QThreadPool::globalInstance()->setMaxThreadCount(10);
    const QList<QFuture<void> > futures = { QtConcurrent::run(&doPredicates), QtConcurrent::run(&doPredicates),
                                            QtConcurrent::run(&doPredicates), QtConcurrent::run(&doPredicates),
                                            QtConcurrent::run(&doPredicates), QtConcurrent::run(&doPredicates),
                                            QtConcurrent::run(&doPredicates), QtConcurrent::run(&doPredicates) };
    for (QFuture<void> f : futures) {
        f.waitForFinished();
    }
    QThreadPool::globalInstance()->setMaxThreadCount(1); // delete those threads
}

#include "solidmttest.moc"