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/midi_manager_usb.h" | 5 #include "media/midi/midi_manager_usb.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 }; | 71 }; |
72 | 72 |
73 class FakeMidiManagerClient : public MidiManagerClient { | 73 class FakeMidiManagerClient : public MidiManagerClient { |
74 public: | 74 public: |
75 explicit FakeMidiManagerClient(Logger* logger) | 75 explicit FakeMidiManagerClient(Logger* logger) |
76 : complete_start_session_(false), | 76 : complete_start_session_(false), |
77 result_(MIDI_NOT_SUPPORTED), | 77 result_(MIDI_NOT_SUPPORTED), |
78 logger_(logger) {} | 78 logger_(logger) {} |
79 ~FakeMidiManagerClient() override {} | 79 ~FakeMidiManagerClient() override {} |
80 | 80 |
| 81 void AddInputPort(const MidiPortInfo& info) override { |
| 82 input_ports_.push_back(info); |
| 83 } |
| 84 |
| 85 void AddOutputPort(const MidiPortInfo& info) override { |
| 86 output_ports_.push_back(info); |
| 87 } |
| 88 |
81 void CompleteStartSession(MidiResult result) override { | 89 void CompleteStartSession(MidiResult result) override { |
82 complete_start_session_ = true; | 90 complete_start_session_ = true; |
83 result_ = result; | 91 result_ = result; |
84 } | 92 } |
85 | 93 |
86 void ReceiveMidiData(uint32 port_index, | 94 void ReceiveMidiData(uint32 port_index, |
87 const uint8* data, | 95 const uint8* data, |
88 size_t size, | 96 size_t size, |
89 double timestamp) override { | 97 double timestamp) override { |
90 logger_->AddLog("MidiManagerClient::ReceiveMidiData "); | 98 logger_->AddLog("MidiManagerClient::ReceiveMidiData "); |
91 logger_->AddLog(base::StringPrintf("port_index = %d data =", port_index)); | 99 logger_->AddLog(base::StringPrintf("port_index = %d data =", port_index)); |
92 for (size_t i = 0; i < size; ++i) | 100 for (size_t i = 0; i < size; ++i) |
93 logger_->AddLog(base::StringPrintf(" 0x%02x", data[i])); | 101 logger_->AddLog(base::StringPrintf(" 0x%02x", data[i])); |
94 logger_->AddLog("\n"); | 102 logger_->AddLog("\n"); |
95 } | 103 } |
96 | 104 |
97 void AccumulateMidiBytesSent(size_t size) override { | 105 void AccumulateMidiBytesSent(size_t size) override { |
98 logger_->AddLog("MidiManagerClient::AccumulateMidiBytesSent "); | 106 logger_->AddLog("MidiManagerClient::AccumulateMidiBytesSent "); |
99 // Windows has no "%zu". | 107 // Windows has no "%zu". |
100 logger_->AddLog(base::StringPrintf("size = %u\n", | 108 logger_->AddLog(base::StringPrintf("size = %u\n", |
101 static_cast<unsigned>(size))); | 109 static_cast<unsigned>(size))); |
102 } | 110 } |
103 | 111 |
104 bool complete_start_session_; | 112 bool complete_start_session_; |
105 MidiResult result_; | 113 MidiResult result_; |
| 114 MidiPortInfoList input_ports_; |
| 115 MidiPortInfoList output_ports_; |
106 | 116 |
107 private: | 117 private: |
108 Logger* logger_; | 118 Logger* logger_; |
109 | 119 |
110 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient); | 120 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient); |
111 }; | 121 }; |
112 | 122 |
113 class TestUsbMidiDeviceFactory : public UsbMidiDevice::Factory { | 123 class TestUsbMidiDeviceFactory : public UsbMidiDevice::Factory { |
114 public: | 124 public: |
115 TestUsbMidiDeviceFactory() {} | 125 TestUsbMidiDeviceFactory() {} |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 186 |
177 void RunCallbackUntilCallbackInvoked( | 187 void RunCallbackUntilCallbackInvoked( |
178 bool result, UsbMidiDevice::Devices* devices) { | 188 bool result, UsbMidiDevice::Devices* devices) { |
179 factory_->callback_.Run(result, devices); | 189 factory_->callback_.Run(result, devices); |
180 while (!client_->complete_start_session_) { | 190 while (!client_->complete_start_session_) { |
181 base::RunLoop run_loop; | 191 base::RunLoop run_loop; |
182 run_loop.RunUntilIdle(); | 192 run_loop.RunUntilIdle(); |
183 } | 193 } |
184 } | 194 } |
185 | 195 |
| 196 const MidiPortInfoList& input_ports() { return client_->input_ports_; } |
| 197 const MidiPortInfoList& output_ports() { return client_->output_ports_; } |
| 198 |
186 scoped_ptr<MidiManagerUsbForTesting> manager_; | 199 scoped_ptr<MidiManagerUsbForTesting> manager_; |
187 scoped_ptr<FakeMidiManagerClient> client_; | 200 scoped_ptr<FakeMidiManagerClient> client_; |
188 // Owned by manager_. | 201 // Owned by manager_. |
189 TestUsbMidiDeviceFactory* factory_; | 202 TestUsbMidiDeviceFactory* factory_; |
190 Logger logger_; | 203 Logger logger_; |
191 | 204 |
192 private: | 205 private: |
193 scoped_ptr<base::MessageLoop> message_loop_; | 206 scoped_ptr<base::MessageLoop> message_loop_; |
194 | 207 |
195 DISALLOW_COPY_AND_ASSIGN(MidiManagerUsbTest); | 208 DISALLOW_COPY_AND_ASSIGN(MidiManagerUsbTest); |
(...skipping 20 matching lines...) Expand all Loading... |
216 }; | 229 }; |
217 device->SetDescriptor(ToVector(descriptor)); | 230 device->SetDescriptor(ToVector(descriptor)); |
218 | 231 |
219 Initialize(); | 232 Initialize(); |
220 ScopedVector<UsbMidiDevice> devices; | 233 ScopedVector<UsbMidiDevice> devices; |
221 devices.push_back(device.release()); | 234 devices.push_back(device.release()); |
222 EXPECT_FALSE(IsInitializationCallbackInvoked()); | 235 EXPECT_FALSE(IsInitializationCallbackInvoked()); |
223 RunCallbackUntilCallbackInvoked(true, &devices); | 236 RunCallbackUntilCallbackInvoked(true, &devices); |
224 EXPECT_EQ(MIDI_OK, GetInitializationResult()); | 237 EXPECT_EQ(MIDI_OK, GetInitializationResult()); |
225 | 238 |
226 ASSERT_EQ(1u, manager_->input_ports().size()); | 239 ASSERT_EQ(1u, input_ports().size()); |
227 ASSERT_EQ(2u, manager_->output_ports().size()); | 240 ASSERT_EQ(2u, output_ports().size()); |
228 ASSERT_TRUE(manager_->input_stream()); | 241 ASSERT_TRUE(manager_->input_stream()); |
229 std::vector<UsbMidiInputStream::JackUniqueKey> keys = | 242 std::vector<UsbMidiInputStream::JackUniqueKey> keys = |
230 manager_->input_stream()->RegisteredJackKeysForTesting(); | 243 manager_->input_stream()->RegisteredJackKeysForTesting(); |
231 ASSERT_EQ(2u, manager_->output_streams().size()); | 244 ASSERT_EQ(2u, manager_->output_streams().size()); |
232 EXPECT_EQ(2u, manager_->output_streams()[0]->jack().jack_id); | 245 EXPECT_EQ(2u, manager_->output_streams()[0]->jack().jack_id); |
233 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id); | 246 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id); |
234 ASSERT_EQ(1u, keys.size()); | 247 ASSERT_EQ(1u, keys.size()); |
235 EXPECT_EQ(2, keys[0].endpoint_number); | 248 EXPECT_EQ(2, keys[0].endpoint_number); |
236 | 249 |
237 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog()); | 250 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n", logger_.TakeLog()); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 "data = 0x90 0x45 0x7f\n" | 360 "data = 0x90 0x45 0x7f\n" |
348 "MidiManagerClient::ReceiveMidiData port_index = 0 " | 361 "MidiManagerClient::ReceiveMidiData port_index = 0 " |
349 "data = 0xf0 0x00 0x01\n" | 362 "data = 0xf0 0x00 0x01\n" |
350 "MidiManagerClient::ReceiveMidiData port_index = 0 data = 0xf7\n", | 363 "MidiManagerClient::ReceiveMidiData port_index = 0 data = 0xf7\n", |
351 logger_.TakeLog()); | 364 logger_.TakeLog()); |
352 } | 365 } |
353 | 366 |
354 } // namespace | 367 } // namespace |
355 | 368 |
356 } // namespace media | 369 } // namespace media |
OLD | NEW |