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

Side by Side Diff: media/midi/usb_midi_input_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_input_stream.cc ('k') | media/midi/usb_midi_output_stream.h » ('j') | 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_input_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 class TestUsbMidiDevice : public UsbMidiDevice {
20 public:
21 TestUsbMidiDevice() {}
22 virtual ~TestUsbMidiDevice() {}
23 virtual std::vector<uint8> GetDescriptor() OVERRIDE {
24 return std::vector<uint8>();
25 }
26 virtual void Send(int endpoint_number,
27 const std::vector<uint8>& data) OVERRIDE {}
28
29 private:
30 DISALLOW_COPY_AND_ASSIGN(TestUsbMidiDevice);
31 };
32
33 class MockDelegate : public UsbMidiInputStream::Delegate {
34 public:
35 MockDelegate() {}
36 virtual ~MockDelegate() {}
37 virtual void OnReceivedData(size_t jack_index,
38 const uint8* data,
39 size_t size,
40 double timestamp) OVERRIDE {
41 for (size_t i = 0; i < size; ++i)
42 received_data_ += base::StringPrintf("0x%02x ", data[i]);
43 received_data_ += "\n";
44 }
45
46 const std::string& received_data() const { return received_data_; }
47
48 private:
49 std::string received_data_;
50 DISALLOW_COPY_AND_ASSIGN(MockDelegate);
51 };
52
53 class UsbMidiInputStreamTest : public ::testing::Test {
54 protected:
55 UsbMidiInputStreamTest() {
56 std::vector<UsbMidiJack> jacks;
57
58 jacks.push_back(UsbMidiJack(&device1_,
59 84, // jack_id
60 4, // cable_number
61 135)); // endpoint_address
62 jacks.push_back(UsbMidiJack(&device2_,
63 85,
64 5,
65 137));
66 jacks.push_back(UsbMidiJack(&device2_,
67 84,
68 4,
69 135));
70 jacks.push_back(UsbMidiJack(&device1_,
71 85,
72 5,
73 135));
74
75 stream_.reset(new UsbMidiInputStream(jacks, &delegate_));
76 }
77
78 TestUsbMidiDevice device1_;
79 TestUsbMidiDevice device2_;
80 MockDelegate delegate_;
81 scoped_ptr<UsbMidiInputStream> stream_;
82
83 private:
84 DISALLOW_COPY_AND_ASSIGN(UsbMidiInputStreamTest);
85 };
86
87 TEST_F(UsbMidiInputStreamTest, UnknownMessage) {
88 uint8 data[] = {
89 0x40, 0xff, 0xff, 0xff,
90 0x41, 0xff, 0xff, 0xff,
91 };
92
93 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), 0);
94 EXPECT_EQ("", delegate_.received_data());
95 }
96
97 TEST_F(UsbMidiInputStreamTest, SystemCommonMessage) {
98 uint8 data[] = {
99 0x45, 0xf8, 0x00, 0x00,
100 0x42, 0xf3, 0x22, 0x00,
101 0x43, 0xf2, 0x33, 0x44,
102 };
103
104 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), 0);
105 EXPECT_EQ("0xf8 \n"
106 "0xf3 0x22 \n"
107 "0xf2 0x33 0x44 \n", delegate_.received_data());
108 }
109
110 TEST_F(UsbMidiInputStreamTest, SystemExclusiveMessage) {
111 uint8 data[] = {
112 0x44, 0xf0, 0x11, 0x22,
113 0x45, 0xf7, 0x00, 0x00,
114 0x46, 0xf0, 0xf7, 0x00,
115 0x47, 0xf0, 0x33, 0xf7,
116 };
117
118 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), 0);
119 EXPECT_EQ("0xf0 0x11 0x22 \n"
120 "0xf7 \n"
121 "0xf0 0xf7 \n"
122 "0xf0 0x33 0xf7 \n", delegate_.received_data());
123 }
124
125 TEST_F(UsbMidiInputStreamTest, ChannelMessage) {
126 uint8 data[] = {
127 0x48, 0x80, 0x11, 0x22,
128 0x49, 0x90, 0x33, 0x44,
129 0x4a, 0xa0, 0x55, 0x66,
130 0x4b, 0xb0, 0x77, 0x88,
131 0x4c, 0xc0, 0x99, 0x00,
132 0x4d, 0xd0, 0xaa, 0x00,
133 0x4e, 0xe0, 0xbb, 0xcc,
134 };
135
136 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), 0);
137 EXPECT_EQ("0x80 0x11 0x22 \n"
138 "0x90 0x33 0x44 \n"
139 "0xa0 0x55 0x66 \n"
140 "0xb0 0x77 0x88 \n"
141 "0xc0 0x99 \n"
142 "0xd0 0xaa \n"
143 "0xe0 0xbb 0xcc \n", delegate_.received_data());
144 }
145
146 TEST_F(UsbMidiInputStreamTest, SingleByteMessage) {
147 uint8 data[] = {
148 0x4f, 0xf8, 0x00, 0x00,
149 };
150
151 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), 0);
152 EXPECT_EQ("0xf8 \n", delegate_.received_data());
153 }
154
155 TEST_F(UsbMidiInputStreamTest, DispatchForMultipleCables) {
156 uint8 data[] = {
157 0x4f, 0xf8, 0x00, 0x00,
158 0x5f, 0xfa, 0x00, 0x00,
159 0x6f, 0xfb, 0x00, 0x00,
160 };
161
162 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), 99);
163 EXPECT_EQ("0xf8 \n0xfa \n", delegate_.received_data());
164 }
165
166 TEST_F(UsbMidiInputStreamTest, DispatchForDevice2) {
167 uint8 data[] = { 0x4f, 0xf8, 0x00, 0x00 };
168
169 stream_->OnReceivedData(&device2_, 7, data, arraysize(data), 99);
170 EXPECT_EQ("0xf8 \n", delegate_.received_data());
171 }
172
173 } // namespace
174
175 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/usb_midi_input_stream.cc ('k') | media/midi/usb_midi_output_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698