Debian Codegraph @

tests/src/test_controlgroup.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include <catch2/catch_all.hpp>
5 #include <catch2/trompeloeil.hpp>
6
7 #include "common/commandqueuestub.h"
8 #include "common/controlmock.h"
9 #include "core/components/controls/controlgroup.h"
10
11 extern template struct trompeloeil::reporter<trompeloeil::specialized>;
12
13 namespace Tests::ControlGroup {
14
15 class ControlGroupTestAdapter : public ::ControlGroup
16 {
17 public:
18 using ControlGroup::ControlGroup;
19
20 using ControlGroup::cleanControl;
21 using ControlGroup::exportControl;
22 using ControlGroup::importControl;
23 using ControlGroup::syncControl;
24 };
25
26 class ControlModeImporterStub : public ::ControlGroup::Importer
27 {
28 public:
29 std::optional<std::reference_wrapper<Importable::Importer>>
30 provideImporter(Item const &) override
31 {
32 return {};
33 }
34
35 bool provideActive() const override
36 {
37 return false;
38 }
39 };
40
41 class ControlModeExporterMock : public ::ControlGroup::Exporter
42 {
43 public:
44 MAKE_MOCK1(takeActive, void(bool), override);
45 MAKE_MOCK1(
46 provideExporter,
47 std::optional<std::reference_wrapper<Exportable::Exporter>>(Item const &),
48 override);
49 };
50
51 TEST_CASE("ControlGroup tests", "[GPU][ControlGroup]")
52 {
53 std::string_view const id{"_id_"};
54 std::vector<std::unique_ptr<IControl>> controlMocks;
55
56 SECTION("ID is assigned")
57 {
58 ControlGroupTestAdapter ts(id, std::move(controlMocks), true);
59 REQUIRE(ts.ID() == id);
60 }
61
62 SECTION("Pre-init its controls")
63 {
64 controlMocks.emplace_back(std::make_unique<ControlMock>());
65 ControlMock *controlMock = static_cast<ControlMock *>(controlMocks[0].get());
66 REQUIRE_CALL(*controlMock, preInit(trompeloeil::_));
67
68 ControlGroupTestAdapter ts(id, std::move(controlMocks), true);
69 CommandQueueStub ctlCmds;
70 ts.preInit(ctlCmds);
71 }
72
73 SECTION("Post-init its controls")
74 {
75 controlMocks.emplace_back(std::make_unique<ControlMock>());
76 ControlMock *controlMock = static_cast<ControlMock *>(controlMocks[0].get());
77 REQUIRE_CALL(*controlMock, postInit(trompeloeil::_));
78
79 ControlGroupTestAdapter ts(id, std::move(controlMocks), true);
80 CommandQueueStub ctlCmds;
81 ts.postInit(ctlCmds);
82 }
83
84 SECTION("On initialization...")
85 {
86 SECTION("Initialize its controls")
87 {
88 controlMocks.emplace_back(std::make_unique<ControlMock>());
89 ControlMock *controlMock =
90 static_cast<ControlMock *>(controlMocks[0].get());
91 std::string const controlMockID("_control_mock_");
92 REQUIRE_CALL(*controlMock, init());
93 ALLOW_CALL(*controlMock, ID()).LR_RETURN(controlMockID);
94 ALLOW_CALL(*controlMock, active()).RETURN(true);
95
96 ControlGroupTestAdapter ts(id, std::move(controlMocks), true);
97 ts.init();
98 }
99
100 SECTION("Activate all inactive controls on initialization")
101 {
102 controlMocks.emplace_back(std::make_unique<ControlMock>());
103 controlMocks.emplace_back(std::make_unique<ControlMock>());
104
105 ControlMock *controlMock =
106 static_cast<ControlMock *>(controlMocks[0].get());
107 std::string const inactiveControlMockID0("_active_control_mock");
108 ALLOW_CALL(*controlMock, init());
109 ALLOW_CALL(*controlMock, ID()).LR_RETURN(inactiveControlMockID0);
110 ALLOW_CALL(*controlMock, active()).RETURN(true);
111 FORBID_CALL(*controlMock, activate(trompeloeil::_));
112
113 controlMock = static_cast<ControlMock *>(controlMocks[1].get());
114 std::string const inactiveControlMockID1("_inactive_control_mock");
115 ALLOW_CALL(*controlMock, init());
116 ALLOW_CALL(*controlMock, ID()).LR_RETURN(inactiveControlMockID1);
117 ALLOW_CALL(*controlMock, active()).RETURN(false);
118 REQUIRE_CALL(*controlMock, activate(true));
119
120 ControlGroupTestAdapter ts(id, std::move(controlMocks), true);
121 ts.init();
122 }
123 }
124
125 SECTION("Imports controls")
126 {
127 controlMocks.emplace_back(std::make_unique<ControlMock>());
128
129 ControlMock *controlMock = static_cast<ControlMock *>(controlMocks[0].get());
130 std::string const controlMockID("_control_mock_");
131 ALLOW_CALL(*controlMock, init());
132 ALLOW_CALL(*controlMock, ID()).LR_RETURN(controlMockID);
133 ALLOW_CALL(*controlMock, active()).RETURN(true);
134 REQUIRE_CALL(*controlMock, importWith(trompeloeil::_));
135 REQUIRE_CALL(*controlMock, activate(true));
136
137 ControlModeImporterStub i;
138 ControlGroupTestAdapter ts(id, std::move(controlMocks), true);
139 ts.init();
140 ts.importControl(i);
141 }
142
143 SECTION("Export controls")
144 {
145 controlMocks.emplace_back(std::make_unique<ControlMock>());
146
147 ControlMock *controlMock = static_cast<ControlMock *>(controlMocks[0].get());
148 std::string const controlMockID("_control_mock_");
149 ALLOW_CALL(*controlMock, init());
150 ALLOW_CALL(*controlMock, ID()).LR_RETURN(controlMockID);
151 ALLOW_CALL(*controlMock, active()).RETURN(true);
152 REQUIRE_CALL(*controlMock, exportWith(trompeloeil::_));
153
154 ControlModeExporterMock e;
155 ControlGroupTestAdapter ts(id, std::move(controlMocks), true);
156 ts.init();
157 ts.exportControl(e);
158 }
159
160 SECTION("Clean controls")
161 {
162 controlMocks.emplace_back(std::make_unique<ControlMock>());
163
164 ControlMock *controlMock = static_cast<ControlMock *>(controlMocks[0].get());
165 std::string const controlMockID("_control_mock_");
166 ALLOW_CALL(*controlMock, init());
167 ALLOW_CALL(*controlMock, ID()).LR_RETURN(controlMockID);
168 ALLOW_CALL(*controlMock, active()).RETURN(true);
169 REQUIRE_CALL(*controlMock, clean(trompeloeil::_));
170
171 ControlGroupTestAdapter ts(id, std::move(controlMocks), true);
172 ts.init();
173 CommandQueueStub ctlCmds;
174 ts.cleanControl(ctlCmds);
175 }
176
177 SECTION("Request clean once on controls when its in dirty state")
178 {
179 controlMocks.emplace_back(std::make_unique<ControlMock>());
180
181 ControlMock *controlMock = static_cast<ControlMock *>(controlMocks[0].get());
182 std::string const controlMockID("_control_mock_");
183 ALLOW_CALL(*controlMock, init());
184 ALLOW_CALL(*controlMock, ID()).LR_RETURN(controlMockID);
185 ALLOW_CALL(*controlMock, active()).RETURN(true);
186 REQUIRE_CALL(*controlMock, cleanOnce());
187
188 ControlGroupTestAdapter ts(id, std::move(controlMocks), true);
189 ts.init();
190 ts.activate(true);
191 ts.activate(false);
192 }
193
194 SECTION("Clean once is propagated to controls")
195 {
196 controlMocks.emplace_back(std::make_unique<ControlMock>());
197
198 ControlMock *controlMock = static_cast<ControlMock *>(controlMocks[0].get());
199 std::string const controlMockID("_control_mock_");
200 ALLOW_CALL(*controlMock, init());
201 ALLOW_CALL(*controlMock, ID()).LR_RETURN(controlMockID);
202 ALLOW_CALL(*controlMock, active()).RETURN(true);
203 REQUIRE_CALL(*controlMock, cleanOnce());
204
205 ControlGroupTestAdapter ts(id, std::move(controlMocks), true);
206 ts.init();
207 ts.cleanOnce();
208 }
209
210 SECTION("Sync controls")
211 {
212 controlMocks.emplace_back(std::make_unique<ControlMock>());
213
214 ControlMock *controlMock = static_cast<ControlMock *>(controlMocks[0].get());
215 std::string const controlMockID("_control_mock_");
216 ALLOW_CALL(*controlMock, init());
217 ALLOW_CALL(*controlMock, ID()).LR_RETURN(controlMockID);
218 ALLOW_CALL(*controlMock, active()).RETURN(true);
219 REQUIRE_CALL(*controlMock, sync(trompeloeil::_));
220
221 ControlGroupTestAdapter ts(id, std::move(controlMocks), true);
222 ts.init();
223 CommandQueueStub ctlCmds;
224 ts.syncControl(ctlCmds);
225 }
226 }
227
228 } // namespace Tests::ControlGroup