Debian Codegraph @

tests/src/test_control.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 "core/components/controls/control.h"
9
10 extern template struct trompeloeil::reporter<trompeloeil::specialized>;
11
12 namespace Tests::Control {
13
14 class ControlMock : public ::Control
15 {
16 public:
17 ControlMock(bool active = true, bool forceClean = false)
18 : ::Control(active, forceClean)
19 {
20 }
21
22 MAKE_MOCK1(preInit, void(ICommandQueue &), override);
23 MAKE_MOCK1(postInit, void(ICommandQueue &), override);
24 MAKE_MOCK0(init, void(), override);
25 MAKE_MOCK1(importControl, void(IControl::Importer &), override);
26 MAKE_CONST_MOCK1(exportControl, void(IControl::Exporter &), override);
27 MAKE_MOCK1(cleanControl, void(ICommandQueue &), override);
28 MAKE_MOCK1(syncControl, void(ICommandQueue &), override);
29 MAKE_CONST_MOCK0(ID, std::string const &(), override);
30 };
31
32 class ControlImporterStub : public IControl::Importer
33 {
34 public:
35 std::optional<std::reference_wrapper<Importable::Importer>>
36 provideImporter(Item const &) override
37 {
38 return *this;
39 }
40
41 bool provideActive() const override
42 {
43 return false;
44 }
45 };
46
47 class ControlExporterMock : public IControl::Exporter
48 {
49 public:
50 MAKE_MOCK1(takeActive, void(bool), override);
51 MAKE_MOCK1(
52 provideExporter,
53 std::optional<std::reference_wrapper<Exportable::Exporter>>(Item const &),
54 override);
55 };
56
57 TEST_CASE("Control tests", "[GPU][Control]")
58 {
59 ControlMock ts;
60 std::string const tsID("_id_");
61 ALLOW_CALL(ts, ID()).LR_RETURN(tsID);
62
63 SECTION("Is active by default")
64 {
65 REQUIRE(ts.active());
66
67 SECTION("Can be deactivated")
68 {
69 ts.activate(false);
70
71 REQUIRE_FALSE(ts.active());
72
73 SECTION("Can be activated")
74 {
75 ts.activate(true);
76
77 REQUIRE(ts.active());
78 }
79 }
80 }
81
82 SECTION("Imports active state and control")
83 {
84 REQUIRE_CALL(ts, importControl(trompeloeil::_));
85
86 ControlImporterStub i;
87 ts.importWith(i);
88
89 REQUIRE_FALSE(ts.active());
90 }
91
92 SECTION("Exports active state and control")
93 {
94 REQUIRE_CALL(ts, exportControl(trompeloeil::_));
95
96 ControlExporterMock e;
97 ALLOW_CALL(e, provideExporter(trompeloeil::_)).LR_RETURN(e);
98 REQUIRE_CALL(e, takeActive(ts.active()));
99
100 ts.exportWith(e);
101 }
102
103 SECTION("Cleans control when gone from active to inactive")
104 {
105 CommandQueueStub ctlCmds;
106
107 REQUIRE_CALL(ts, cleanControl(trompeloeil::_));
108 ts.activate(true);
109 ts.activate(false);
110 ts.clean(ctlCmds);
111
112 FORBID_CALL(ts, cleanControl(trompeloeil::_));
113 ts.activate(true);
114 ts.clean(ctlCmds);
115 }
116
117 SECTION("Cleans control when force clean is true")
118 {
119 ControlMock tsForceClean(false, true);
120 CommandQueueStub ctlCmds;
121
122 REQUIRE_CALL(tsForceClean, cleanControl(trompeloeil::_));
123 tsForceClean.clean(ctlCmds);
124 }
125
126 SECTION("Cleans control when clean once is requested")
127 {
128 CommandQueueStub ctlCmds;
129
130 REQUIRE_CALL(ts, cleanControl(trompeloeil::_));
131 ts.cleanOnce();
132 ts.clean(ctlCmds);
133 }
134
135 SECTION("Sync control when is active")
136 {
137 CommandQueueStub ctlCmds;
138
139 REQUIRE_CALL(ts, syncControl(trompeloeil::_));
140 ts.activate(true);
141 ts.sync(ctlCmds);
142
143 FORBID_CALL(ts, syncControl(trompeloeil::_));
144 ts.activate(false);
145 ts.sync(ctlCmds);
146 }
147 }
148
149 } // namespace Tests::Control