Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: media/midi/usb_midi_output_stream_unittest.cc

Issue 107513012: [WebMIDI] Introduce UsbMidi{Input, Output}Stream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usb-midi-parser
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/midi/usb_midi_output_stream.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 <string>
8 #include <vector>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/stringprintf.h"
12 #include "media/midi/usb_midi_device.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace media {
16
17 namespace {
18
19 template<typename T, size_t N>
20 std::vector<T> ToVector(const T((&array)[N])) {
21 return std::vector<T>(array, array + N);
22 }
23
24 class MockUsbMidiDevice : public UsbMidiDevice {
25 public:
26 virtual ~MockUsbMidiDevice() {}
27
28 virtual std::vector<uint8> GetDescriptor() OVERRIDE {
29 return std::vector<uint8>();
30 }
31
32 virtual void Send(int endpoint_number, const std::vector<uint8>& data)
33 OVERRIDE {
34 for (size_t i = 0; i < data.size(); ++i) {
35 log_ += base::StringPrintf("0x%02x ", data[i]);
36 }
37 log_ += base::StringPrintf("(endpoint = %d)\n", endpoint_number);
38 }
39
40 void Checkpoint(int tag) {
41 log_ += base::StringPrintf("checkpoint(%d)\n", tag);
42 }
43
44 const std::string& log() const { return log_; }
45
46 private:
47 std::string log_;
48 };
scherkus (not reviewing) 2014/01/22 06:51:46 nit: these classes can still have DISALLOW_ macros
yhirano 2014/01/22 08:58:23 Done.
49
50 class UsbMidiOutputStreamTest : public ::testing::Test {
51 protected:
52 UsbMidiOutputStreamTest() {
53 UsbMidiJack jack(&device_, 1, 2, 4);
54 stream_.reset(new UsbMidiOutputStream(jack));
55 }
56
57 MockUsbMidiDevice device_;
58 scoped_ptr<UsbMidiOutputStream> stream_;
59 };
60
61 TEST_F(UsbMidiOutputStreamTest, SendEmpty) {
62 stream_->Send(std::vector<uint8>());
63
64 EXPECT_EQ("", device_.log());
65 }
66
67 TEST_F(UsbMidiOutputStreamTest, SendNoteOn) {
68 uint8 data[] = { 0x90, 0x45, 0x7f};
69
70 stream_->Send(ToVector(data));
71
72 EXPECT_EQ("0x29 0x90 0x45 0x7f (endpoint = 4)\n", device_.log());
73 }
74
75 TEST_F(UsbMidiOutputStreamTest, SendNoteOnPending) {
76 device_.Checkpoint(0);
77 stream_->Send(std::vector<uint8>(1, 0x90));
78 device_.Checkpoint(1);
scherkus (not reviewing) 2014/01/22 06:51:46 an alternative to checkpoints is the check device_
yhirano 2014/01/22 08:58:23 That's a nice idea. Done.
79 stream_->Send(std::vector<uint8>(1, 0x45));
80 device_.Checkpoint(2);
81 stream_->Send(std::vector<uint8>(1, 0x7f));
82 device_.Checkpoint(3);
83 stream_->Send(std::vector<uint8>(1, 0x90));
84 device_.Checkpoint(4);
85 stream_->Send(std::vector<uint8>(1, 0x45));
86 device_.Checkpoint(5);
87
88 EXPECT_EQ("checkpoint(0)\n"
89 "checkpoint(1)\n"
90 "checkpoint(2)\n"
91 "0x29 0x90 0x45 0x7f (endpoint = 4)\n"
92 "checkpoint(3)\n"
93 "checkpoint(4)\n"
94 "checkpoint(5)\n", device_.log());
95 }
96
97 TEST_F(UsbMidiOutputStreamTest, SendNoteOnBurst) {
98 uint8 data1[] = { 0x90, };
99 uint8 data2[] = { 0x45, 0x7f, 0x90, 0x45, 0x71, 0x90, 0x45, 0x72, 0x90, };
100
101 stream_->Send(ToVector(data1));
102 stream_->Send(ToVector(data2));
103
104 EXPECT_EQ("0x29 0x90 0x45 0x7f "
105 "0x29 0x90 0x45 0x71 "
106 "0x29 0x90 0x45 0x72 (endpoint = 4)\n", device_.log());
107 }
108
109 TEST_F(UsbMidiOutputStreamTest, SendNoteOff) {
110 uint8 data[] = { 0x80, 0x33, 0x44, };
111
112 stream_->Send(ToVector(data));
113
114 EXPECT_EQ("0x28 0x80 0x33 0x44 (endpoint = 4)\n", device_.log());
115 }
116
117 TEST_F(UsbMidiOutputStreamTest, SendPolyphonicKeyPress) {
118 uint8 data[] = { 0xa0, 0x33, 0x44, };
119
120 stream_->Send(ToVector(data));
121
122 EXPECT_EQ("0x2a 0xa0 0x33 0x44 (endpoint = 4)\n", device_.log());
123 }
124
125 TEST_F(UsbMidiOutputStreamTest, SendControlChange) {
126 uint8 data[] = { 0xb7, 0x33, 0x44, };
127
128 stream_->Send(ToVector(data));
129
130 EXPECT_EQ("0x2b 0xb7 0x33 0x44 (endpoint = 4)\n", device_.log());
131 }
132
133 TEST_F(UsbMidiOutputStreamTest, SendProgramChange) {
134 uint8 data[] = { 0xc2, 0x33, };
135
136 stream_->Send(ToVector(data));
137
138 EXPECT_EQ("0x2c 0xc2 0x33 0x00 (endpoint = 4)\n", device_.log());
139 }
140
141 TEST_F(UsbMidiOutputStreamTest, SendChannelPressure) {
142 uint8 data[] = { 0xd1, 0x33, 0x44, };
143
144 stream_->Send(ToVector(data));
145
146 EXPECT_EQ("0x2d 0xd1 0x33 0x44 (endpoint = 4)\n", device_.log());
147 }
148
149 TEST_F(UsbMidiOutputStreamTest, SendPitchWheelChange) {
150 uint8 data[] = { 0xe4, 0x33, 0x44, };
151
152 stream_->Send(ToVector(data));
153
154 EXPECT_EQ("0x2e 0xe4 0x33 0x44 (endpoint = 4)\n", device_.log());
155 }
156
157 TEST_F(UsbMidiOutputStreamTest, SendTwoByteSysEx) {
158 uint8 data[] = { 0xf0, 0xf7, };
159
160 stream_->Send(ToVector(data));
161
162 EXPECT_EQ("0x26 0xf0 0xf7 0x00 (endpoint = 4)\n", device_.log());
163 }
164
165 TEST_F(UsbMidiOutputStreamTest, SendThreeByteSysEx) {
166 uint8 data[] = { 0xf0, 0x4f, 0xf7, };
167
168 stream_->Send(ToVector(data));
169
170 EXPECT_EQ("0x27 0xf0 0x4f 0xf7 (endpoint = 4)\n", device_.log());
171 }
172
173 TEST_F(UsbMidiOutputStreamTest, SendFourByteSysEx) {
174 uint8 data[] = { 0xf0, 0x00, 0x01, 0xf7, };
175
176 stream_->Send(ToVector(data));
177
178 EXPECT_EQ("0x24 0xf0 0x00 0x01 "
179 "0x25 0xf7 0x00 0x00 (endpoint = 4)\n", device_.log());
180 }
181
182 TEST_F(UsbMidiOutputStreamTest, SendFiveByteSysEx) {
183 uint8 data[] = { 0xf0, 0x00, 0x01, 0x02, 0xf7, };
184
185 stream_->Send(ToVector(data));
186
187 EXPECT_EQ("0x24 0xf0 0x00 0x01 "
188 "0x26 0x02 0xf7 0x00 (endpoint = 4)\n", device_.log());
189 }
190
191 TEST_F(UsbMidiOutputStreamTest, SendSixByteSysEx) {
192 uint8 data[] = { 0xf0, 0x00, 0x01, 0x02, 0x03, 0xf7, };
193
194 stream_->Send(ToVector(data));
195
196 EXPECT_EQ("0x24 0xf0 0x00 0x01 "
197 "0x27 0x02 0x03 0xf7 (endpoint = 4)\n", device_.log());
198 }
199
200 TEST_F(UsbMidiOutputStreamTest, SendPendingSysEx) {
201 uint8 data1[] = { 0xf0, 0x33, };
202 uint8 data2[] = { 0x44, 0x55, 0x66, };
203 uint8 data3[] = { 0x77, 0x88, 0x99, 0xf7, };
204
205 device_.Checkpoint(0);
206 stream_->Send(ToVector(data1));
207 device_.Checkpoint(1);
208 stream_->Send(ToVector(data2));
209 device_.Checkpoint(2);
210 stream_->Send(ToVector(data3));
211 device_.Checkpoint(3);
212
213 EXPECT_EQ("checkpoint(0)\n"
214 "checkpoint(1)\n"
215 "0x24 0xf0 0x33 0x44 (endpoint = 4)\n"
216 "checkpoint(2)\n"
217 "0x24 0x55 0x66 0x77 0x27 0x88 0x99 0xf7 (endpoint = 4)\n"
218 "checkpoint(3)\n", device_.log());
219 }
220
221 TEST_F(UsbMidiOutputStreamTest, SendNoteOnAfterSysEx) {
222 uint8 data[] = { 0xf0, 0x00, 0x01, 0x02, 0x03, 0xf7, 0x90, 0x44, 0x33, };
223
224 stream_->Send(ToVector(data));
225
226 EXPECT_EQ("0x24 0xf0 0x00 0x01 "
227 "0x27 0x02 0x03 0xf7 "
228 "0x29 0x90 0x44 0x33 (endpoint = 4)\n", device_.log());
229 }
230
231 TEST_F(UsbMidiOutputStreamTest, SendTimeCodeQuarterFrame) {
232 uint8 data[] = { 0xf1, 0x22, };
233
234 stream_->Send(ToVector(data));
235
236 EXPECT_EQ("0x22 0xf1 0x22 0x00 (endpoint = 4)\n", device_.log());
237 }
238
239 TEST_F(UsbMidiOutputStreamTest, SendSongPositionPointer) {
240 uint8 data[] = { 0xf2, 0x22, 0x33, };
241
242 stream_->Send(ToVector(data));
243
244 EXPECT_EQ("0x23 0xf2 0x22 0x33 (endpoint = 4)\n", device_.log());
245 }
246
247 TEST_F(UsbMidiOutputStreamTest, SendSongSelect) {
248 uint8 data[] = { 0xf3, 0x22, };
249
250 stream_->Send(ToVector(data));
251
252 EXPECT_EQ("0x22 0xf3 0x22 0x00 (endpoint = 4)\n", device_.log());
253 }
254
255 TEST_F(UsbMidiOutputStreamTest, TuneRequest) {
256 uint8 data[] = { 0xf6, };
257
258 stream_->Send(ToVector(data));
259
260 EXPECT_EQ("0x25 0xf6 0x00 0x00 (endpoint = 4)\n", device_.log());
261 }
262
263 TEST_F(UsbMidiOutputStreamTest, SendSongPositionPointerPending) {
264 uint8 data1[] = { 0xf2, 0x22, };
265 uint8 data2[] = { 0x33, };
266
267 stream_->Send(ToVector(data1));
268 device_.Checkpoint(0);
269 stream_->Send(ToVector(data2));
270
271 EXPECT_EQ("checkpoint(0)\n"
272 "0x23 0xf2 0x22 0x33 (endpoint = 4)\n", device_.log());
273 }
274
275 TEST_F(UsbMidiOutputStreamTest, SendRealTimeMessages) {
276 uint8 data[] = { 0xf8, 0xfa, 0xfb, 0xfc, 0xfe, 0xff, };
277
278 stream_->Send(ToVector(data));
279
280 EXPECT_EQ("0x25 0xf8 0x00 0x00 "
281 "0x25 0xfa 0x00 0x00 "
282 "0x25 0xfb 0x00 0x00 "
283 "0x25 0xfc 0x00 0x00 "
284 "0x25 0xfe 0x00 0x00 "
285 "0x25 0xff 0x00 0x00 (endpoint = 4)\n", device_.log());
286 }
287
288 TEST_F(UsbMidiOutputStreamTest, SendRealTimeInSysExMessage) {
289 uint8 data[] = {
290 0xf0, 0x00, 0x01, 0x02,
291 0xf8, 0xfa,
292 0x03, 0xf7,
293 };
294
295 stream_->Send(ToVector(data));
296
297 EXPECT_EQ("0x24 0xf0 0x00 0x01 "
298 "0x25 0xf8 0x00 0x00 "
299 "0x25 0xfa 0x00 0x00 "
300 "0x27 0x02 0x03 0xf7 (endpoint = 4)\n", device_.log());
301 }
302
303 } // namespace
304
305 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/usb_midi_output_stream.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698