OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "media/midi/usb_midi_output_stream.h" | |
6 | |
7 #include "base/memory/scoped_ptr.h" | |
8 #include "media/midi/usb_midi_device.h" | |
9 #include "testing/gmock/include/gmock/gmock.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 namespace media { | |
13 | |
14 namespace { | |
15 | |
16 using ::testing::InSequence; | |
17 using ::testing::StrictMock; | |
18 | |
19 typedef ::testing::MockFunction<void(int)> Checkpoint; // NOLINT | |
20 | |
21 template<typename T, size_t N> | |
22 std::vector<T> ToVector(const T((&array)[N])) { | |
23 return std::vector<T>(array, array + N); | |
24 } | |
25 | |
26 class MockUsbMidiDevice : public UsbMidiDevice { | |
27 public: | |
28 virtual ~MockUsbMidiDevice() {} | |
29 MOCK_METHOD0(GetDescriptor, std::vector<uint8>()); | |
30 MOCK_METHOD2(Send, void(int, const std::vector<uint8>&)); | |
31 }; | |
32 | |
33 class UsbMidiOutputStreamTest : public ::testing::Test { | |
34 protected: | |
35 UsbMidiOutputStreamTest() { | |
36 UsbMidiJack jack(&device_, 1, 2, 4); | |
37 stream_.reset(new UsbMidiOutputStream(jack)); | |
38 } | |
39 | |
40 StrictMock<MockUsbMidiDevice> device_; | |
scherkus (not reviewing)
2014/01/21 21:25:25
think you can update this test to use string-based
yhirano
2014/01/22 02:33:31
Done.
| |
41 scoped_ptr<UsbMidiOutputStream> stream_; | |
42 }; | |
43 | |
44 TEST_F(UsbMidiOutputStreamTest, SendEmpty) { | |
45 stream_->Send(std::vector<uint8>()); | |
46 } | |
47 | |
48 TEST_F(UsbMidiOutputStreamTest, SendNoteOn) { | |
49 uint8 data[] = { 0x90, 0x45, 0x7f}; | |
50 uint8 expected[] = { 0x29, 0x90, 0x45, 0x7f }; | |
51 | |
52 { | |
53 InSequence s; | |
54 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
55 } | |
56 | |
57 stream_->Send(ToVector(data)); | |
58 } | |
59 | |
60 TEST_F(UsbMidiOutputStreamTest, SendNoteOnPending) { | |
61 uint8 expected[] = { 0x29, 0x90, 0x45, 0x7f, }; | |
62 Checkpoint checkpoint; | |
63 | |
64 { | |
65 InSequence s; | |
66 EXPECT_CALL(checkpoint, Call(0)); | |
67 EXPECT_CALL(checkpoint, Call(1)); | |
68 EXPECT_CALL(checkpoint, Call(2)); | |
69 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
70 EXPECT_CALL(checkpoint, Call(3)); | |
71 EXPECT_CALL(checkpoint, Call(4)); | |
72 EXPECT_CALL(checkpoint, Call(5)); | |
73 } | |
74 | |
75 checkpoint.Call(0); | |
76 stream_->Send(std::vector<uint8>(1, 0x90)); | |
77 checkpoint.Call(1); | |
78 stream_->Send(std::vector<uint8>(1, 0x45)); | |
79 checkpoint.Call(2); | |
80 stream_->Send(std::vector<uint8>(1, 0x7f)); | |
81 checkpoint.Call(3); | |
82 stream_->Send(std::vector<uint8>(1, 0x90)); | |
83 checkpoint.Call(4); | |
84 stream_->Send(std::vector<uint8>(1, 0x45)); | |
85 checkpoint.Call(5); | |
86 } | |
87 | |
88 TEST_F(UsbMidiOutputStreamTest, SendNoteOnBurst) { | |
89 uint8 data1[] = { 0x90, }; | |
90 uint8 data2[] = { 0x45, 0x7f, 0x90, 0x45, 0x71, 0x90, 0x45, 0x72, 0x90, }; | |
91 uint8 expected[] = { | |
92 0x29, 0x90, 0x45, 0x7f, | |
93 0x29, 0x90, 0x45, 0x71, | |
94 0x29, 0x90, 0x45, 0x72, | |
95 }; | |
96 | |
97 { | |
98 InSequence s; | |
99 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
100 } | |
101 | |
102 stream_->Send(ToVector(data1)); | |
103 stream_->Send(ToVector(data2)); | |
104 } | |
105 | |
106 TEST_F(UsbMidiOutputStreamTest, SendNoteOff) { | |
107 uint8 data[] = { 0x80, 0x33, 0x44, }; | |
108 uint8 expected[] = { | |
109 0x28, 0x80, 0x33, 0x44, | |
110 }; | |
111 | |
112 { | |
113 InSequence s; | |
114 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
115 } | |
116 | |
117 stream_->Send(ToVector(data)); | |
118 } | |
119 | |
120 TEST_F(UsbMidiOutputStreamTest, SendPolyphonicKeyPress) { | |
121 uint8 data[] = { 0xa0, 0x33, 0x44, }; | |
122 uint8 expected[] = { | |
123 0x2a, 0xa0, 0x33, 0x44, | |
124 }; | |
125 | |
126 { | |
127 InSequence s; | |
128 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
129 } | |
130 | |
131 stream_->Send(ToVector(data)); | |
132 } | |
133 | |
134 TEST_F(UsbMidiOutputStreamTest, SendControlChange) { | |
135 uint8 data[] = { 0xb7, 0x33, 0x44, }; | |
136 uint8 expected[] = { | |
137 0x2b, 0xb7, 0x33, 0x44, | |
138 }; | |
139 | |
140 { | |
141 InSequence s; | |
142 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
143 } | |
144 | |
145 stream_->Send(ToVector(data)); | |
146 } | |
147 | |
148 TEST_F(UsbMidiOutputStreamTest, SendProgramChange) { | |
149 uint8 data[] = { 0xc2, 0x33, }; | |
150 uint8 expected[] = { | |
151 0x2c, 0xc2, 0x33, 0x00, | |
152 }; | |
153 | |
154 { | |
155 InSequence s; | |
156 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
157 } | |
158 | |
159 stream_->Send(ToVector(data)); | |
160 } | |
161 | |
162 TEST_F(UsbMidiOutputStreamTest, SendChannelPressure) { | |
163 uint8 data[] = { 0xd1, 0x33, 0x44, }; | |
164 uint8 expected[] = { | |
165 0x2d, 0xd1, 0x33, 0x44, | |
166 }; | |
167 | |
168 { | |
169 InSequence s; | |
170 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
171 } | |
172 | |
173 stream_->Send(ToVector(data)); | |
174 } | |
175 | |
176 TEST_F(UsbMidiOutputStreamTest, SendPitchWheelChange) { | |
177 uint8 data[] = { 0xe4, 0x33, 0x44, }; | |
178 uint8 expected[] = { | |
179 0x2e, 0xe4, 0x33, 0x44, | |
180 }; | |
181 | |
182 { | |
183 InSequence s; | |
184 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
185 } | |
186 | |
187 stream_->Send(ToVector(data)); | |
188 } | |
189 | |
190 TEST_F(UsbMidiOutputStreamTest, SendTwoByteSysEx) { | |
191 uint8 data[] = { 0xf0, 0xf7, }; | |
192 uint8 expected[] = { | |
193 0x26, 0xf0, 0xf7, 0x00, | |
194 }; | |
195 | |
196 { | |
197 InSequence s; | |
198 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
199 } | |
200 | |
201 stream_->Send(ToVector(data)); | |
202 } | |
203 | |
204 TEST_F(UsbMidiOutputStreamTest, SendThreeByteSysEx) { | |
205 uint8 data[] = { 0xf0, 0x4f, 0xf7, }; | |
206 uint8 expected[] = { | |
207 0x27, 0xf0, 0x4f, 0xf7, | |
208 }; | |
209 | |
210 { | |
211 InSequence s; | |
212 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
213 } | |
214 | |
215 stream_->Send(ToVector(data)); | |
216 } | |
217 | |
218 TEST_F(UsbMidiOutputStreamTest, SendFourByteSysEx) { | |
219 uint8 data[] = { 0xf0, 0x00, 0x01, 0xf7, }; | |
220 uint8 expected[] = { | |
221 0x24, 0xf0, 0x00, 0x01, | |
222 0x25, 0xf7, 0x00, 0x00, | |
223 }; | |
224 | |
225 { | |
226 InSequence s; | |
227 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
228 } | |
229 | |
230 stream_->Send(ToVector(data)); | |
231 } | |
232 | |
233 TEST_F(UsbMidiOutputStreamTest, SendFiveByteSysEx) { | |
234 uint8 data[] = { 0xf0, 0x00, 0x01, 0x02, 0xf7, }; | |
235 uint8 expected[] = { | |
236 0x24, 0xf0, 0x00, 0x01, | |
237 0x26, 0x02, 0xf7, 0x00, | |
238 }; | |
239 | |
240 { | |
241 InSequence s; | |
242 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
243 } | |
244 | |
245 stream_->Send(ToVector(data)); | |
246 } | |
247 | |
248 TEST_F(UsbMidiOutputStreamTest, SendSixByteSysEx) { | |
249 uint8 data[] = { 0xf0, 0x00, 0x01, 0x02, 0x03, 0xf7, }; | |
250 uint8 expected[] = { | |
251 0x24, 0xf0, 0x00, 0x01, | |
252 0x27, 0x02, 0x03, 0xf7, | |
253 }; | |
254 | |
255 { | |
256 InSequence s; | |
257 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
258 } | |
259 | |
260 stream_->Send(ToVector(data)); | |
261 } | |
262 | |
263 TEST_F(UsbMidiOutputStreamTest, SendPendingSysEx) { | |
264 uint8 data1[] = { 0xf0, 0x33, }; | |
265 uint8 data2[] = { 0x44, 0x55, 0x66, }; | |
266 uint8 data3[] = { 0x77, 0x88, 0x99, 0xf7, }; | |
267 | |
268 uint8 expected1[] = { 0x24, 0xf0, 0x33, 0x44, }; | |
269 uint8 expected2[] = { | |
270 0x24, 0x55, 0x66, 0x77, | |
271 0x27, 0x88, 0x99, 0xf7, | |
272 }; | |
273 | |
274 Checkpoint checkpoint; | |
275 | |
276 { | |
277 InSequence s; | |
278 EXPECT_CALL(checkpoint, Call(0)); | |
279 EXPECT_CALL(checkpoint, Call(1)); | |
280 EXPECT_CALL(device_, Send(4, ToVector(expected1))); | |
281 EXPECT_CALL(checkpoint, Call(2)); | |
282 EXPECT_CALL(device_, Send(4, ToVector(expected2))); | |
283 EXPECT_CALL(checkpoint, Call(3)); | |
284 } | |
285 | |
286 checkpoint.Call(0); | |
287 stream_->Send(ToVector(data1)); | |
288 checkpoint.Call(1); | |
289 stream_->Send(ToVector(data2)); | |
290 checkpoint.Call(2); | |
291 stream_->Send(ToVector(data3)); | |
292 checkpoint.Call(3); | |
293 } | |
294 | |
295 TEST_F(UsbMidiOutputStreamTest, SendNoteOnAfterSysEx) { | |
296 uint8 data[] = { 0xf0, 0x00, 0x01, 0x02, 0x03, 0xf7, 0x90, 0x44, 0x33, }; | |
297 uint8 expected[] = { | |
298 0x24, 0xf0, 0x00, 0x01, | |
299 0x27, 0x02, 0x03, 0xf7, | |
300 0x29, 0x90, 0x44, 0x33, | |
301 }; | |
302 | |
303 { | |
304 InSequence s; | |
305 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
306 } | |
307 | |
308 stream_->Send(ToVector(data)); | |
309 } | |
310 | |
311 TEST_F(UsbMidiOutputStreamTest, SendTimeCodeQuarterFrame) { | |
312 uint8 data[] = { 0xf1, 0x22, }; | |
313 uint8 expected[] = { 0x22, 0xf1, 0x22, 0x00, }; | |
314 | |
315 { | |
316 InSequence s; | |
317 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
318 } | |
319 | |
320 stream_->Send(ToVector(data)); | |
321 } | |
322 | |
323 TEST_F(UsbMidiOutputStreamTest, SendSongPositionPointer) { | |
324 uint8 data[] = { 0xf2, 0x22, 0x33, }; | |
325 uint8 expected[] = { 0x23, 0xf2, 0x22, 0x33, }; | |
326 | |
327 { | |
328 InSequence s; | |
329 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
330 } | |
331 | |
332 stream_->Send(ToVector(data)); | |
333 } | |
334 | |
335 TEST_F(UsbMidiOutputStreamTest, SendSongSelect) { | |
336 uint8 data[] = { 0xf3, 0x22, }; | |
337 uint8 expected[] = { 0x22, 0xf3, 0x22, 0x00, }; | |
338 | |
339 { | |
340 InSequence s; | |
341 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
342 } | |
343 | |
344 stream_->Send(ToVector(data)); | |
345 } | |
346 | |
347 TEST_F(UsbMidiOutputStreamTest, TuneRequest) { | |
348 uint8 data[] = { 0xf6, }; | |
349 uint8 expected[] = { 0x25, 0xf6, 0x00, 0x00, }; | |
350 | |
351 { | |
352 InSequence s; | |
353 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
354 } | |
355 | |
356 stream_->Send(ToVector(data)); | |
357 } | |
358 | |
359 TEST_F(UsbMidiOutputStreamTest, SendSongPositionPointerPending) { | |
360 uint8 data1[] = { 0xf2, 0x22, }; | |
361 uint8 data2[] = { 0x33, }; | |
362 uint8 expected[] = { 0x23, 0xf2, 0x22, 0x33, }; | |
363 | |
364 Checkpoint checkpoint; | |
365 { | |
366 InSequence s; | |
367 EXPECT_CALL(checkpoint, Call(0)); | |
368 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
369 } | |
370 | |
371 stream_->Send(ToVector(data1)); | |
372 checkpoint.Call(0); | |
373 stream_->Send(ToVector(data2)); | |
374 } | |
375 | |
376 TEST_F(UsbMidiOutputStreamTest, SendRealTimeMessages) { | |
377 uint8 data[] = { 0xf8, 0xfa, 0xfb, 0xfc, 0xfe, 0xff, }; | |
378 uint8 expected[] = { | |
379 0x25, 0xf8, 0x00, 0x00, | |
380 0x25, 0xfa, 0x00, 0x00, | |
381 0x25, 0xfb, 0x00, 0x00, | |
382 0x25, 0xfc, 0x00, 0x00, | |
383 0x25, 0xfe, 0x00, 0x00, | |
384 0x25, 0xff, 0x00, 0x00, | |
385 }; | |
386 | |
387 { | |
388 InSequence s; | |
389 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
390 } | |
391 | |
392 stream_->Send(ToVector(data)); | |
393 } | |
394 | |
395 TEST_F(UsbMidiOutputStreamTest, SendRealTimeInSysExMessage) { | |
396 uint8 data[] = { | |
397 0xf0, 0x00, 0x01, 0x02, | |
398 0xf8, 0xfa, | |
399 0x03, 0xf7, | |
400 }; | |
401 uint8 expected[] = { | |
402 0x24, 0xf0, 0x00, 0x01, | |
403 0x25, 0xf8, 0x00, 0x00, | |
404 0x25, 0xfa, 0x00, 0x00, | |
405 0x27, 0x02, 0x03, 0xf7, | |
406 }; | |
407 | |
408 { | |
409 InSequence s; | |
410 EXPECT_CALL(device_, Send(4, ToVector(expected))); | |
411 } | |
412 | |
413 stream_->Send(ToVector(data)); | |
414 } | |
415 | |
416 } // namespace | |
417 | |
418 } // namespace media | |
OLD | NEW |