File: solidpowertest.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 (110 lines) | stat: -rw-r--r-- 2,768 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
/*
    SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares <afiestas@kde.org>

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

#include <QTest>
#include <QSignalSpy>
#include <Solid/Power>
#include <Solid/AcPluggedJob>
#include <Solid/Inhibition>
#include <Solid/InhibitionJob>
#include <Solid/StatesJob>
#include <Solid/RequestStateJob>

using namespace Solid;
class solidPowerTest : public QObject
{
    Q_OBJECT
private Q_SLOTS:
    void initTestCase();
    void testAcPluggedJob();
    void testAcPluggedChanged();
    void testAddInhibition();
    void testSupportedStates();
    void testRequestState();
};

void solidPowerTest::initTestCase()
{
    qputenv("SOLID_POWER_BACKEND", "DUMMY");
}

void solidPowerTest::testAcPluggedJob()
{
    AcPluggedJob *job = new AcPluggedJob();
    QVERIFY(job->exec());
    QVERIFY(job->isPlugged());

    job = Power::isAcPlugged();
    QVERIFY(job->exec());
    QVERIFY(job->isPlugged());
}

void solidPowerTest::testAcPluggedChanged()
{
    Power *power = Power::self();
    QSignalSpy spy(power, SIGNAL(acPluggedChanged(bool)));

    QVERIFY(spy.wait());
    QVERIFY(spy.takeFirst().first().toBool());
}

void solidPowerTest::testAddInhibition()
{
    InhibitionJob *job = new InhibitionJob();
    QVERIFY(!job->exec());

    QCOMPARE(job->error(), (int) InhibitionJob::InvalidInhibitions);
    delete job;

    job = new InhibitionJob();
    job->setInhibitions(Power::Sleep);
    QVERIFY(!job->exec());
    QCOMPARE(job->error(), (int) InhibitionJob::EmptyDescription);
    delete job;

    job = Power::inhibit(Power::Sleep, QLatin1String("Running a test, we don't want to suspend now"));
    QVERIFY(job->exec());

    auto inhibition = job->inhibition();
    QSignalSpy spy(inhibition, SIGNAL(stateChanged(Inhibition::State)));
    inhibition->deleteLater();

    QVERIFY(spy.wait());
    QCOMPARE(spy.takeFirst().first().toInt(), (int) Inhibition::Stopped);
}

void solidPowerTest::testSupportedStates()
{
    auto job = new StatesJob();
    QVERIFY(job->exec());

    QCOMPARE(job->states(), Power::Shutdown | Power::Sleep);

    job = Power::supportedStates();
    QVERIFY(job->exec());

    QCOMPARE(job->states(), Power::Shutdown | Power::Sleep);
}

void solidPowerTest::testRequestState()
{
    auto job = new RequestStateJob();
    job->setState(Power::Sleep);
    QVERIFY(job->exec());

    job = Power::requestState(Power::Sleep);
    QVERIFY(job->exec());

    job = Power::requestState(Power::Shutdown);
    QVERIFY(!job->exec());

    QCOMPARE(job->error(), (int) RequestStateJob::Unsupported);
    QCOMPARE(job->errorText(), QLatin1String(QLatin1String("State Brightness is unsupported")));
}

QTEST_MAIN(solidPowerTest)

#include "solidpowertest.moc"