Debian Codegraph @

olad/plugin_api/PortManagerTest.cpp

raw
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 * PortManagerTest.cpp
17 * Test fixture for the PortManager classes
18 * Copyright (C) 2005 Simon Newton
19 */
20
21 #include <cppunit/extensions/HelperMacros.h>
22 #include <string>
23
24 #include "olad/DmxSource.h"
25 #include "olad/PortBroker.h"
26 #include "olad/plugin_api/PortManager.h"
27 #include "olad/plugin_api/TestCommon.h"
28 #include "olad/plugin_api/UniverseStore.h"
29 #include "ola/testing/TestUtils.h"
30
31
32 using ola::DmxSource;
33 using ola::PortManager;
34 using ola::Port;
35 using ola::Universe;
36 using std::string;
37
38
39 class PortManagerTest: public CppUnit::TestFixture {
40 CPPUNIT_TEST_SUITE(PortManagerTest);
41 CPPUNIT_TEST(testPortPatching);
42 CPPUNIT_TEST(testPortPatchingLoopMulti);
43 CPPUNIT_TEST(testInputPortSetPriority);
44 CPPUNIT_TEST(testOutputPortSetPriority);
45 CPPUNIT_TEST_SUITE_END();
46
47 public:
48 void testPortPatching();
49 void testPortPatchingLoopMulti();
50 void testInputPortSetPriority();
51 void testOutputPortSetPriority();
52 };
53
54
55 CPPUNIT_TEST_SUITE_REGISTRATION(PortManagerTest);
56
57
58
59 /*
60 * Check that we can patch ports correctly.
61 */
62 void PortManagerTest::testPortPatching() {
63 ola::UniverseStore uni_store(NULL, NULL);
64 ola::PortBroker broker;
65 ola::PortManager port_manager(&uni_store, &broker);
66
67 // mock device, this doesn't allow looping or multiport patching
68 MockDevice device1(NULL, "test_device_1");
69 TestMockInputPort input_port(&device1, 1, NULL);
70 TestMockInputPort input_port2(&device1, 2, NULL);
71 TestMockOutputPort output_port(&device1, 1);
72 TestMockOutputPort output_port2(&device1, 2);
73 device1.AddPort(&input_port);
74 device1.AddPort(&input_port2);
75 device1.AddPort(&output_port);
76 device1.AddPort(&output_port2);
77
78 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), input_port.GetUniverse());
79 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), input_port2.GetUniverse());
80 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), output_port.GetUniverse());
81 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), output_port2.GetUniverse());
82
83 // simple patching
84 OLA_ASSERT(port_manager.PatchPort(&input_port, 1));
85 OLA_ASSERT(port_manager.PatchPort(&output_port, 2));
86 OLA_ASSERT(input_port.GetUniverse());
87 OLA_ASSERT_EQ((unsigned int) 1, input_port.GetUniverse()->UniverseId());
88 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), input_port2.GetUniverse());
89 OLA_ASSERT(output_port.GetUniverse());
90 OLA_ASSERT_EQ((unsigned int) 2, output_port.GetUniverse()->UniverseId());
91 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), output_port2.GetUniverse());
92
93 // test looping
94 OLA_ASSERT_FALSE(port_manager.PatchPort(&input_port2, 2));
95 OLA_ASSERT_FALSE(port_manager.PatchPort(&output_port2, 1));
96 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), input_port2.GetUniverse());
97 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), output_port2.GetUniverse());
98
99 // test multiport
100 OLA_ASSERT_FALSE(port_manager.PatchPort(&input_port2, 1));
101 OLA_ASSERT_FALSE(port_manager.PatchPort(&output_port2, 2));
102 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), input_port2.GetUniverse());
103 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), output_port2.GetUniverse());
104
105 // test repatching
106 OLA_ASSERT(port_manager.PatchPort(&input_port, 3));
107 OLA_ASSERT(port_manager.PatchPort(&output_port, 4));
108 OLA_ASSERT(input_port.GetUniverse());
109 OLA_ASSERT_EQ((unsigned int) 3, input_port.GetUniverse()->UniverseId());
110 OLA_ASSERT(output_port.GetUniverse());
111 OLA_ASSERT_EQ((unsigned int) 4, output_port.GetUniverse()->UniverseId());
112
113 // test unpatching
114 OLA_ASSERT(port_manager.UnPatchPort(&input_port));
115 OLA_ASSERT(port_manager.UnPatchPort(&input_port2));
116 OLA_ASSERT(port_manager.UnPatchPort(&output_port));
117 OLA_ASSERT(port_manager.UnPatchPort(&output_port2));
118 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), input_port.GetUniverse());
119 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), input_port2.GetUniverse());
120 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), output_port.GetUniverse());
121 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), output_port2.GetUniverse());
122 }
123
124
125 /*
126 * test that patching works correctly for devices with looping and multiport
127 * patching enabled.
128 */
129 void PortManagerTest::testPortPatchingLoopMulti() {
130 ola::UniverseStore uni_store(NULL, NULL);
131 ola::PortBroker broker;
132 ola::PortManager port_manager(&uni_store, &broker);
133
134 // mock device that allows looping and multi port patching
135 MockDeviceLoopAndMulti device1(NULL, "test_device_1");
136 TestMockInputPort input_port(&device1, 1, NULL);
137 TestMockInputPort input_port2(&device1, 2, NULL);
138 TestMockOutputPort output_port(&device1, 1);
139 TestMockOutputPort output_port2(&device1, 2);
140 device1.AddPort(&input_port);
141 device1.AddPort(&input_port2);
142 device1.AddPort(&output_port);
143 device1.AddPort(&output_port2);
144
145 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), input_port.GetUniverse());
146 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), input_port2.GetUniverse());
147 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), output_port.GetUniverse());
148 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), output_port2.GetUniverse());
149
150 // simple patching
151 OLA_ASSERT(port_manager.PatchPort(&input_port, 1));
152 OLA_ASSERT(port_manager.PatchPort(&output_port, 2));
153 OLA_ASSERT(input_port.GetUniverse());
154 OLA_ASSERT_EQ((unsigned int) 1, input_port.GetUniverse()->UniverseId());
155 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), input_port2.GetUniverse());
156 OLA_ASSERT(output_port.GetUniverse());
157 OLA_ASSERT_EQ((unsigned int) 2, output_port.GetUniverse()->UniverseId());
158 OLA_ASSERT_EQ(static_cast<Universe*>(NULL), output_port2.GetUniverse());
159
160 // test looping
161 OLA_ASSERT(port_manager.PatchPort(&input_port2, 2));
162 OLA_ASSERT(port_manager.PatchPort(&output_port2, 1));
163 OLA_ASSERT(input_port2.GetUniverse());
164 OLA_ASSERT_EQ((unsigned int) 2, input_port2.GetUniverse()->UniverseId());
165 OLA_ASSERT(output_port2.GetUniverse());
166 OLA_ASSERT_EQ((unsigned int) 1, output_port2.GetUniverse()->UniverseId());
167
168 // test multiport
169 OLA_ASSERT(port_manager.PatchPort(&input_port2, 1));
170 OLA_ASSERT(port_manager.PatchPort(&output_port2, 2));
171 OLA_ASSERT(input_port2.GetUniverse());
172 OLA_ASSERT_EQ((unsigned int) 1, input_port2.GetUniverse()->UniverseId());
173 OLA_ASSERT(output_port2.GetUniverse());
174 OLA_ASSERT_EQ((unsigned int) 2, output_port2.GetUniverse()->UniverseId());
175 }
176
177
178 /*
179 * Check that we can set priorities on an input port
180 */
181 void PortManagerTest::testInputPortSetPriority() {
182 // we're not testing patching so pass NULL here
183 PortManager patcher(NULL, NULL);
184
185 // Input port that doesn't support priorities
186 TestMockInputPort input_port(NULL, 0, NULL);
187
188 OLA_ASSERT_EQ(input_port.PriorityCapability(), ola::CAPABILITY_STATIC);
189 OLA_ASSERT_EQ(input_port.GetPriorityMode(), ola::PRIORITY_MODE_STATIC);
190 OLA_ASSERT_EQ(input_port.GetPriority(), ola::dmx::SOURCE_PRIORITY_DEFAULT);
191
192 // this port doesn't support priorities so this is a noop
193 OLA_ASSERT(patcher.SetPriorityInherit(&input_port));
194 OLA_ASSERT_EQ(input_port.GetPriorityMode(), ola::PRIORITY_MODE_STATIC);
195 OLA_ASSERT_EQ(input_port.GetPriority(), ola::dmx::SOURCE_PRIORITY_DEFAULT);
196
197 // set the static priority to 20
198 OLA_ASSERT(patcher.SetPriorityStatic(&input_port, 20));
199 OLA_ASSERT_EQ(input_port.GetPriorityMode(), ola::PRIORITY_MODE_STATIC);
200 OLA_ASSERT_EQ(input_port.GetPriority(), (uint8_t) 20);
201
202 // Now test an input port that does support priorities
203 TestMockPriorityInputPort input_port2(NULL, 1, NULL);
204
205 OLA_ASSERT_EQ(input_port2.PriorityCapability(), ola::CAPABILITY_FULL);
206 OLA_ASSERT_EQ(input_port2.GetPriorityMode(), ola::PRIORITY_MODE_STATIC);
207 OLA_ASSERT_EQ(input_port2.GetPriority(), ola::dmx::SOURCE_PRIORITY_DEFAULT);
208
209 // try changing to static mode
210 OLA_ASSERT(patcher.SetPriorityStatic(&input_port2, 20));
211 OLA_ASSERT_EQ(input_port2.GetPriorityMode(), ola::PRIORITY_MODE_STATIC);
212 OLA_ASSERT_EQ(input_port2.GetPriority(), (uint8_t) 20);
213
214 // bump priority
215 OLA_ASSERT(patcher.SetPriorityStatic(&input_port2, 180));
216 OLA_ASSERT_EQ(input_port2.GetPriorityMode(), ola::PRIORITY_MODE_STATIC);
217 OLA_ASSERT_EQ(input_port2.GetPriority(), (uint8_t) 180);
218
219 // change to inherit mode
220 OLA_ASSERT(patcher.SetPriorityInherit(&input_port2));
221 OLA_ASSERT_EQ(input_port2.GetPriorityMode(), ola::PRIORITY_MODE_INHERIT);
222 OLA_ASSERT_EQ(input_port2.GetPriority(), (uint8_t) 180);
223 }
224
225
226 /*
227 * Check that we can set priorities on an Output port
228 */
229 void PortManagerTest::testOutputPortSetPriority() {
230 // we're not testing patching so pass NULL here
231 PortManager patcher(NULL, NULL);
232
233 // Input port that doesn't support priorities
234 TestMockOutputPort output_port(NULL, 0);
235
236 OLA_ASSERT_EQ(output_port.PriorityCapability(), ola::CAPABILITY_NONE);
237 OLA_ASSERT_EQ(output_port.GetPriorityMode(), ola::PRIORITY_MODE_INHERIT);
238 OLA_ASSERT_EQ(output_port.GetPriority(), ola::dmx::SOURCE_PRIORITY_DEFAULT);
239
240 // this port doesn't support priorities so these are all noops
241 OLA_ASSERT(patcher.SetPriorityInherit(&output_port));
242 OLA_ASSERT(patcher.SetPriorityStatic(&output_port, 20));
243 OLA_ASSERT_EQ(output_port.GetPriorityMode(), ola::PRIORITY_MODE_INHERIT);
244 OLA_ASSERT_EQ(output_port.GetPriority(), ola::dmx::SOURCE_PRIORITY_DEFAULT);
245
246 // now test an output port that supports priorities
247 TestMockPriorityOutputPort output_port2(NULL, 1);
248
249 OLA_ASSERT_EQ(output_port2.PriorityCapability(), ola::CAPABILITY_FULL);
250 OLA_ASSERT_EQ(output_port2.GetPriorityMode(), ola::PRIORITY_MODE_INHERIT);
251 OLA_ASSERT_EQ(output_port2.GetPriority(), ola::dmx::SOURCE_PRIORITY_DEFAULT);
252
253 // try changing to static mode
254 OLA_ASSERT(patcher.SetPriorityStatic(&output_port2, 20));
255 OLA_ASSERT_EQ(output_port2.GetPriorityMode(), ola::PRIORITY_MODE_STATIC);
256 OLA_ASSERT_EQ(output_port2.GetPriority(), (uint8_t) 20);
257
258 // bump priority
259 OLA_ASSERT(patcher.SetPriorityStatic(&output_port2, 180));
260 OLA_ASSERT_EQ(output_port2.GetPriorityMode(), ola::PRIORITY_MODE_STATIC);
261 OLA_ASSERT_EQ(output_port2.GetPriority(), (uint8_t) 180);
262
263 // change back to inherit mode
264 OLA_ASSERT(patcher.SetPriorityInherit(&output_port2));
265 OLA_ASSERT_EQ(output_port2.GetPriorityMode(), ola::PRIORITY_MODE_INHERIT);
266 OLA_ASSERT_EQ(output_port2.GetPriority(), (uint8_t) 180);
267 }