GCC Code Coverage Report


Directory: ./
File: autotests/testbackendloader.cpp
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 40 41 97.6%
Branches: 12 28 42.9%

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 "backendmanager_p.h"
24
25 Q_LOGGING_CATEGORY(DISMAN, "disman")
26
27 using namespace Disman;
28
29 class TestBackendLoader : public QObject
30 {
31 Q_OBJECT
32
33 public:
34 explicit TestBackendLoader(QObject* parent = nullptr);
35
36 private Q_SLOTS:
37 void initTestCase();
38 void cleanupTestCase();
39
40 void testPreferredBackend();
41 void testEnv();
42 void testEnv_data();
43 void testFallback();
44 };
45
46 1 TestBackendLoader::TestBackendLoader(QObject* parent)
47 1 : QObject(parent)
48 {
49 1 qputenv("DISMAN_LOGGING", "false");
50 1 qputenv("DISMAN_IN_PROCESS", QByteArray());
51 1 qputenv("DISMAN_BACKEND", QByteArray());
52 1 }
53
54 1 void TestBackendLoader::initTestCase()
55 {
56 1 }
57
58 1 void TestBackendLoader::cleanupTestCase()
59 {
60 // set to original value
61 1 qputenv("DISMAN_BACKEND", QByteArray());
62 1 }
63
64 1 void TestBackendLoader::testPreferredBackend()
65 {
66 1 auto backends = BackendManager::instance()->list_backends();
67
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(!backends.isEmpty());
68 1 auto preferred = BackendManager::instance()->preferred_backend();
69
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(preferred.exists());
70 1 auto fake = BackendManager::instance()->preferred_backend("fake");
71
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QVERIFY(fake.fileName().startsWith(QLatin1String("fake")));
72
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 }
73
74 1 void TestBackendLoader::testEnv_data()
75 {
76 1 QTest::addColumn<QString>("var");
77 1 QTest::addColumn<QString>("backend");
78
79 QTest::newRow("wayland") << "wayland"
80 1 << "wayland";
81 QTest::newRow("randr") << "randr"
82 1 << "randr";
83 QTest::newRow("qscreen") << "qscreen"
84 1 << "qscreen";
85 QTest::newRow("mixed") << "fake"
86 1 << "fake";
87 1 }
88
89 4 void TestBackendLoader::testEnv()
90 {
91 // We want to be pretty liberal, so this should work
92 4 QFETCH(QString, var);
93 4 QFETCH(QString, backend);
94 4 qputenv("DISMAN_BACKEND", var.toLocal8Bit());
95 4 auto preferred = BackendManager::instance()->preferred_backend();
96
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 QVERIFY(preferred.fileName().startsWith(backend));
97
3/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
4 }
98
99 1 void TestBackendLoader::testFallback()
100 {
101 1 qputenv("DISMAN_BACKEND", "nonsense");
102 1 auto preferred = BackendManager::instance()->preferred_backend();
103
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 QVERIFY(preferred.fileName().startsWith(QLatin1String("qscreen")));
104
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 }
105
106 1 QTEST_GUILESS_MAIN(TestBackendLoader)
107
108 #include "testbackendloader.moc"
109