OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/midi/usb_midi_input_stream.h" | 5 #include "media/midi/usb_midi_input_stream.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "media/midi/usb_midi_device.h" | 13 #include "media/midi/usb_midi_device.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using base::TimeTicks; | 16 using base::TimeTicks; |
17 | 17 |
18 namespace media { | 18 namespace media { |
19 namespace midi { | 19 namespace midi { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 class TestUsbMidiDevice : public UsbMidiDevice { | 23 class TestUsbMidiDevice : public UsbMidiDevice { |
24 public: | 24 public: |
25 TestUsbMidiDevice() {} | 25 TestUsbMidiDevice() {} |
26 ~TestUsbMidiDevice() override {} | 26 ~TestUsbMidiDevice() override {} |
27 std::vector<uint8> GetDescriptors() override { return std::vector<uint8>(); } | 27 std::vector<uint8_t> GetDescriptors() override { |
| 28 return std::vector<uint8_t>(); |
| 29 } |
28 std::string GetManufacturer() override { return std::string(); } | 30 std::string GetManufacturer() override { return std::string(); } |
29 std::string GetProductName() override { return std::string(); } | 31 std::string GetProductName() override { return std::string(); } |
30 std::string GetDeviceVersion() override { return std::string(); } | 32 std::string GetDeviceVersion() override { return std::string(); } |
31 void Send(int endpoint_number, const std::vector<uint8>& data) override {} | 33 void Send(int endpoint_number, const std::vector<uint8_t>& data) override {} |
32 | 34 |
33 private: | 35 private: |
34 DISALLOW_COPY_AND_ASSIGN(TestUsbMidiDevice); | 36 DISALLOW_COPY_AND_ASSIGN(TestUsbMidiDevice); |
35 }; | 37 }; |
36 | 38 |
37 class MockDelegate : public UsbMidiInputStream::Delegate { | 39 class MockDelegate : public UsbMidiInputStream::Delegate { |
38 public: | 40 public: |
39 MockDelegate() {} | 41 MockDelegate() {} |
40 ~MockDelegate() override {} | 42 ~MockDelegate() override {} |
41 void OnReceivedData(size_t jack_index, | 43 void OnReceivedData(size_t jack_index, |
42 const uint8* data, | 44 const uint8_t* data, |
43 size_t size, | 45 size_t size, |
44 base::TimeTicks time) override { | 46 base::TimeTicks time) override { |
45 for (size_t i = 0; i < size; ++i) | 47 for (size_t i = 0; i < size; ++i) |
46 received_data_ += base::StringPrintf("0x%02x ", data[i]); | 48 received_data_ += base::StringPrintf("0x%02x ", data[i]); |
47 received_data_ += "\n"; | 49 received_data_ += "\n"; |
48 } | 50 } |
49 | 51 |
50 const std::string& received_data() const { return received_data_; } | 52 const std::string& received_data() const { return received_data_; } |
51 | 53 |
52 private: | 54 private: |
(...skipping 27 matching lines...) Expand all Loading... |
80 TestUsbMidiDevice device1_; | 82 TestUsbMidiDevice device1_; |
81 TestUsbMidiDevice device2_; | 83 TestUsbMidiDevice device2_; |
82 MockDelegate delegate_; | 84 MockDelegate delegate_; |
83 scoped_ptr<UsbMidiInputStream> stream_; | 85 scoped_ptr<UsbMidiInputStream> stream_; |
84 | 86 |
85 private: | 87 private: |
86 DISALLOW_COPY_AND_ASSIGN(UsbMidiInputStreamTest); | 88 DISALLOW_COPY_AND_ASSIGN(UsbMidiInputStreamTest); |
87 }; | 89 }; |
88 | 90 |
89 TEST_F(UsbMidiInputStreamTest, UnknownMessage) { | 91 TEST_F(UsbMidiInputStreamTest, UnknownMessage) { |
90 uint8 data[] = { | 92 uint8_t data[] = { |
91 0x40, 0xff, 0xff, 0xff, | 93 0x40, 0xff, 0xff, 0xff, 0x41, 0xff, 0xff, 0xff, |
92 0x41, 0xff, 0xff, 0xff, | |
93 }; | 94 }; |
94 | 95 |
95 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), TimeTicks()); | 96 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), TimeTicks()); |
96 EXPECT_EQ("", delegate_.received_data()); | 97 EXPECT_EQ("", delegate_.received_data()); |
97 } | 98 } |
98 | 99 |
99 TEST_F(UsbMidiInputStreamTest, SystemCommonMessage) { | 100 TEST_F(UsbMidiInputStreamTest, SystemCommonMessage) { |
100 uint8 data[] = { | 101 uint8_t data[] = { |
101 0x45, 0xf8, 0x00, 0x00, | 102 0x45, 0xf8, 0x00, 0x00, 0x42, 0xf3, 0x22, 0x00, 0x43, 0xf2, 0x33, 0x44, |
102 0x42, 0xf3, 0x22, 0x00, | |
103 0x43, 0xf2, 0x33, 0x44, | |
104 }; | 103 }; |
105 | 104 |
106 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), TimeTicks()); | 105 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), TimeTicks()); |
107 EXPECT_EQ("0xf8 \n" | 106 EXPECT_EQ("0xf8 \n" |
108 "0xf3 0x22 \n" | 107 "0xf3 0x22 \n" |
109 "0xf2 0x33 0x44 \n", delegate_.received_data()); | 108 "0xf2 0x33 0x44 \n", delegate_.received_data()); |
110 } | 109 } |
111 | 110 |
112 TEST_F(UsbMidiInputStreamTest, SystemExclusiveMessage) { | 111 TEST_F(UsbMidiInputStreamTest, SystemExclusiveMessage) { |
113 uint8 data[] = { | 112 uint8_t data[] = { |
114 0x44, 0xf0, 0x11, 0x22, | 113 0x44, 0xf0, 0x11, 0x22, 0x45, 0xf7, 0x00, 0x00, |
115 0x45, 0xf7, 0x00, 0x00, | 114 0x46, 0xf0, 0xf7, 0x00, 0x47, 0xf0, 0x33, 0xf7, |
116 0x46, 0xf0, 0xf7, 0x00, | |
117 0x47, 0xf0, 0x33, 0xf7, | |
118 }; | 115 }; |
119 | 116 |
120 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), TimeTicks()); | 117 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), TimeTicks()); |
121 EXPECT_EQ("0xf0 0x11 0x22 \n" | 118 EXPECT_EQ("0xf0 0x11 0x22 \n" |
122 "0xf7 \n" | 119 "0xf7 \n" |
123 "0xf0 0xf7 \n" | 120 "0xf0 0xf7 \n" |
124 "0xf0 0x33 0xf7 \n", delegate_.received_data()); | 121 "0xf0 0x33 0xf7 \n", delegate_.received_data()); |
125 } | 122 } |
126 | 123 |
127 TEST_F(UsbMidiInputStreamTest, ChannelMessage) { | 124 TEST_F(UsbMidiInputStreamTest, ChannelMessage) { |
128 uint8 data[] = { | 125 uint8_t data[] = { |
129 0x48, 0x80, 0x11, 0x22, | 126 0x48, 0x80, 0x11, 0x22, 0x49, 0x90, 0x33, 0x44, 0x4a, 0xa0, |
130 0x49, 0x90, 0x33, 0x44, | 127 0x55, 0x66, 0x4b, 0xb0, 0x77, 0x88, 0x4c, 0xc0, 0x99, 0x00, |
131 0x4a, 0xa0, 0x55, 0x66, | 128 0x4d, 0xd0, 0xaa, 0x00, 0x4e, 0xe0, 0xbb, 0xcc, |
132 0x4b, 0xb0, 0x77, 0x88, | |
133 0x4c, 0xc0, 0x99, 0x00, | |
134 0x4d, 0xd0, 0xaa, 0x00, | |
135 0x4e, 0xe0, 0xbb, 0xcc, | |
136 }; | 129 }; |
137 | 130 |
138 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), TimeTicks()); | 131 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), TimeTicks()); |
139 EXPECT_EQ("0x80 0x11 0x22 \n" | 132 EXPECT_EQ("0x80 0x11 0x22 \n" |
140 "0x90 0x33 0x44 \n" | 133 "0x90 0x33 0x44 \n" |
141 "0xa0 0x55 0x66 \n" | 134 "0xa0 0x55 0x66 \n" |
142 "0xb0 0x77 0x88 \n" | 135 "0xb0 0x77 0x88 \n" |
143 "0xc0 0x99 \n" | 136 "0xc0 0x99 \n" |
144 "0xd0 0xaa \n" | 137 "0xd0 0xaa \n" |
145 "0xe0 0xbb 0xcc \n", delegate_.received_data()); | 138 "0xe0 0xbb 0xcc \n", delegate_.received_data()); |
146 } | 139 } |
147 | 140 |
148 TEST_F(UsbMidiInputStreamTest, SingleByteMessage) { | 141 TEST_F(UsbMidiInputStreamTest, SingleByteMessage) { |
149 uint8 data[] = { | 142 uint8_t data[] = { |
150 0x4f, 0xf8, 0x00, 0x00, | 143 0x4f, 0xf8, 0x00, 0x00, |
151 }; | 144 }; |
152 | 145 |
153 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), TimeTicks()); | 146 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), TimeTicks()); |
154 EXPECT_EQ("0xf8 \n", delegate_.received_data()); | 147 EXPECT_EQ("0xf8 \n", delegate_.received_data()); |
155 } | 148 } |
156 | 149 |
157 TEST_F(UsbMidiInputStreamTest, DispatchForMultipleCables) { | 150 TEST_F(UsbMidiInputStreamTest, DispatchForMultipleCables) { |
158 uint8 data[] = { | 151 uint8_t data[] = { |
159 0x4f, 0xf8, 0x00, 0x00, | 152 0x4f, 0xf8, 0x00, 0x00, 0x5f, 0xfa, 0x00, 0x00, 0x6f, 0xfb, 0x00, 0x00, |
160 0x5f, 0xfa, 0x00, 0x00, | |
161 0x6f, 0xfb, 0x00, 0x00, | |
162 }; | 153 }; |
163 | 154 |
164 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), TimeTicks()); | 155 stream_->OnReceivedData(&device1_, 7, data, arraysize(data), TimeTicks()); |
165 EXPECT_EQ("0xf8 \n0xfa \n", delegate_.received_data()); | 156 EXPECT_EQ("0xf8 \n0xfa \n", delegate_.received_data()); |
166 } | 157 } |
167 | 158 |
168 TEST_F(UsbMidiInputStreamTest, DispatchForDevice2) { | 159 TEST_F(UsbMidiInputStreamTest, DispatchForDevice2) { |
169 uint8 data[] = { 0x4f, 0xf8, 0x00, 0x00 }; | 160 uint8_t data[] = {0x4f, 0xf8, 0x00, 0x00}; |
170 | 161 |
171 stream_->OnReceivedData(&device2_, 7, data, arraysize(data), TimeTicks()); | 162 stream_->OnReceivedData(&device2_, 7, data, arraysize(data), TimeTicks()); |
172 EXPECT_EQ("0xf8 \n", delegate_.received_data()); | 163 EXPECT_EQ("0xf8 \n", delegate_.received_data()); |
173 } | 164 } |
174 | 165 |
175 } // namespace | 166 } // namespace |
176 | 167 |
177 } // namespace midi | 168 } // namespace midi |
178 } // namespace media | 169 } // namespace media |
OLD | NEW |