GCC Code Coverage Report


Directory: ./
File: autotests/wayland_dpms.cpp
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 41 43 95.3%
Branches: 47 114 41.2%

Line Branch Exec Source
1 /*************************************************************************************
2 * Copyright 2016 by Sebastian K├╝gler <sebas@kde.org> *
3 * *
4 * This library is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with this library; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
17 *************************************************************************************/
18 #include <QCoreApplication>
19 #include <QObject>
20 #include <QSignalSpy>
21 #include <QtTest>
22
23 #include <Wrapland/Client/connection_thread.h>
24 #include <Wrapland/Client/dpms.h>
25 #include <Wrapland/Client/registry.h>
26
27 #include "server.h"
28
29 static const QString s_socketName = QStringLiteral("disman-test-wayland-backend-0");
30
31 Q_LOGGING_CATEGORY(DISMAN, "disman")
32
33 using namespace Wrapland::Client;
34
35 class wayland_dpms : public QObject
36 {
37 Q_OBJECT
38
39 public:
40 explicit wayland_dpms(QObject* parent = nullptr);
41
42 Q_SIGNALS:
43 void dpmsAnnounced();
44
45 private Q_SLOTS:
46
47 void initTestCase();
48 void cleanupTestCase();
49 void testDpmsConnect();
50
51 private:
52 ConnectionThread* m_connection;
53 QThread* m_thread;
54 Registry* m_registry;
55
56 Disman::server* m_server;
57 };
58
59 1 wayland_dpms::wayland_dpms(QObject* parent)
60 : QObject(parent)
61 1 , m_server(nullptr)
62 {
63
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 setenv("WAYLAND_DISPLAY", s_socketName.toLocal8Bit().constData(), true);
64
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 m_server = new Disman::server(this);
65
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 m_server->start();
66 1 }
67
68 1 void wayland_dpms::initTestCase()
69 {
70 // setup connection
71
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 m_connection = new Wrapland::Client::ConnectionThread;
72
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 m_connection->setSocketName(s_socketName);
73
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 QSignalSpy connectedSpy(m_connection, &Wrapland::Client::ConnectionThread::establishedChanged);
74
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 QVERIFY(connectedSpy.isValid());
75
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 m_connection->setSocketName(s_socketName);
76
77
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 m_thread = new QThread(this);
78
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 m_connection->moveToThread(m_thread);
79
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 m_thread->start();
80
81
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 m_connection->establishConnection();
82
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
1 QVERIFY(connectedSpy.wait());
83
84
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 QSignalSpy dpmsSpy(this, &wayland_dpms::dpmsAnnounced);
85
86
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 m_connection->establishConnection();
87
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
1 QVERIFY(connectedSpy.wait(100));
88
89
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 m_registry = new Wrapland::Client::Registry;
90
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 m_registry->create(m_connection);
91
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 QObject::connect(m_registry, &Registry::interfacesAnnounced, this, [this] {
92 1 const bool hasDpms = m_registry->hasInterface(Registry::Interface::Dpms);
93
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (hasDpms) {
94
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
2 qDebug() << QStringLiteral("Compositor provides a DpmsManager");
95 } else {
96 qDebug() << QStringLiteral("Compositor does not provid a DpmsManager");
97 }
98 1 emit this->dpmsAnnounced();
99 1 });
100
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 m_registry->setup();
101
102
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
1 QVERIFY(dpmsSpy.wait(100));
103
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 }
104
105 1 void wayland_dpms::cleanupTestCase()
106 {
107 1 m_thread->exit();
108
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 m_thread->wait();
109
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 delete m_registry;
110
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 delete m_thread;
111
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 delete m_connection;
112 1 }
113
114 1 void wayland_dpms::testDpmsConnect()
115 {
116
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(m_registry->isValid());
117 }
118
119
5/10
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 QTEST_GUILESS_MAIN(wayland_dpms)
120
121 #include "wayland_dpms.moc"
122