GCC Code Coverage Report


Directory: ./
File: autotests/testconfigmonitor.cpp
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 41 43 95.3%
Branches: 31 90 34.4%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2014 Daniel Vratil <dvratil@redhat.com>
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 Street, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 */
19 #include <QObject>
20 #include <QSignalSpy>
21 #include <QtTest>
22
23 #include "backendmanager_p.h"
24 #include "config.h"
25 #include "configmonitor.h"
26 #include "configoperation.h"
27 #include "getconfigoperation.h"
28 #include "output.h"
29 #include "setconfigoperation.h"
30 #include <QSignalSpy>
31
32 #include "fakebackendinterface.h"
33
34 class TestConfigMonitor : public QObject
35 {
36 Q_OBJECT
37 public:
38 1 TestConfigMonitor()
39 1 {
40 1 }
41
42 1 Disman::ConfigPtr getConfig()
43 {
44 1 auto op = new Disman::GetConfigOperation();
45
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!op->exec()) {
46 qWarning("Failed to retrieve backend: %s", qPrintable(op->error_string()));
47 return Disman::ConfigPtr();
48 }
49
50 1 return op->config();
51 }
52
53 private Q_SLOTS:
54 1 void initTestCase()
55 {
56 1 qputenv("DISMAN_LOGGING", "false");
57 1 qputenv("DISMAN_BACKEND", "fake");
58 // This particular test is only useful for out of process operation, so enforce that
59 1 qputenv("DISMAN_IN_PROCESS", "0");
60 1 Disman::BackendManager::instance()->shutdown_backend();
61 1 }
62
63 1 void cleanupTestCase()
64 {
65 1 Disman::BackendManager::instance()->shutdown_backend();
66 1 }
67
68 1 void testChangeNotifyInProcess()
69 {
70 1 qputenv("DISMAN_IN_PROCESS", "1");
71 1 Disman::BackendManager::instance()->shutdown_backend();
72 1 Disman::BackendManager::instance()->set_method(Disman::BackendManager::InProcess);
73 // json file for the fake backend
74 1 qputenv("DISMAN_BACKEND_ARGS", "TEST_DATA=" TEST_DATA "singleoutput.json");
75
76 // Prepare monitor
77 1 Disman::ConfigMonitor* monitor = Disman::ConfigMonitor::instance();
78 1 QSignalSpy spy(monitor, SIGNAL(configuration_changed()));
79
80 // Get config and monitor it for changes
81 1 Disman::ConfigPtr config = getConfig();
82 1 monitor->add_config(config);
83
84 1 auto output = config->outputs().begin()->second;
85
86 1 output->set_enabled(false);
87 1 auto setop = new Disman::SetConfigOperation(config);
88
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(!setop->has_error());
89 1 setop->exec();
90
11/36
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ 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 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 1 times.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✓ Branch 26 taken 1 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 60 not taken.
✓ Branch 61 taken 1 times.
1 QTRY_VERIFY(!spy.isEmpty());
91
92
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QCOMPARE(spy.size(), 1);
93
1/2
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
1 QCOMPARE(config->output(1)->enabled(), false);
94
95 1 output->set_enabled(false);
96 1 auto setop2 = new Disman::SetConfigOperation(config);
97
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QVERIFY(!setop2->has_error());
98 1 setop2->exec();
99
11/36
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ 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 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 1 times.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✓ Branch 26 taken 1 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 60 not taken.
✓ Branch 61 taken 1 times.
1 QTRY_VERIFY(!spy.isEmpty());
100
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 QCOMPARE(spy.size(), 2);
101
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 }
102 };
103
104 1 QTEST_MAIN(TestConfigMonitor)
105
106 #include "testconfigmonitor.moc"
107