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

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

Issue 151343002: Web MIDI: make naming convention be consistent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review boliu #2 Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « media/midi/midi_manager_usb.cc ('k') | media/midi/midi_manager_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "media/midi/usb_midi_device.h" 10 #include "media/midi/usb_midi_device.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 descriptor_ = descriptor; 61 descriptor_ = descriptor;
62 } 62 }
63 63
64 private: 64 private:
65 std::vector<uint8> descriptor_; 65 std::vector<uint8> descriptor_;
66 Logger* logger_; 66 Logger* logger_;
67 67
68 DISALLOW_COPY_AND_ASSIGN(FakeUsbMidiDevice); 68 DISALLOW_COPY_AND_ASSIGN(FakeUsbMidiDevice);
69 }; 69 };
70 70
71 class FakeMidiManagerClient : public MIDIManagerClient { 71 class FakeMidiManagerClient : public MidiManagerClient {
72 public: 72 public:
73 explicit FakeMidiManagerClient(Logger* logger) : logger_(logger) {} 73 explicit FakeMidiManagerClient(Logger* logger) : logger_(logger) {}
74 virtual ~FakeMidiManagerClient() {} 74 virtual ~FakeMidiManagerClient() {}
75 75
76 virtual void ReceiveMIDIData(uint32 port_index, 76 virtual void ReceiveMidiData(uint32 port_index,
77 const uint8* data, 77 const uint8* data,
78 size_t size, 78 size_t size,
79 double timestamp) OVERRIDE { 79 double timestamp) OVERRIDE {
80 logger_->AddLog("MIDIManagerClient::ReceiveMIDIData "); 80 logger_->AddLog("MidiManagerClient::ReceiveMidiData ");
81 logger_->AddLog(base::StringPrintf("port_index = %d data =", port_index)); 81 logger_->AddLog(base::StringPrintf("port_index = %d data =", port_index));
82 for (size_t i = 0; i < size; ++i) 82 for (size_t i = 0; i < size; ++i)
83 logger_->AddLog(base::StringPrintf(" 0x%02x", data[i])); 83 logger_->AddLog(base::StringPrintf(" 0x%02x", data[i]));
84 logger_->AddLog("\n"); 84 logger_->AddLog("\n");
85 } 85 }
86 86
87 virtual void AccumulateMIDIBytesSent(size_t size) OVERRIDE { 87 virtual void AccumulateMidiBytesSent(size_t size) OVERRIDE {
88 logger_->AddLog("MIDIManagerClient::AccumulateMIDIBytesSent "); 88 logger_->AddLog("MidiManagerClient::AccumulateMidiBytesSent ");
89 // Windows has no "%zu". 89 // Windows has no "%zu".
90 logger_->AddLog(base::StringPrintf("size = %u\n", 90 logger_->AddLog(base::StringPrintf("size = %u\n",
91 static_cast<unsigned>(size))); 91 static_cast<unsigned>(size)));
92 } 92 }
93 93
94 private: 94 private:
95 Logger* logger_; 95 Logger* logger_;
96 96
97 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient); 97 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient);
98 }; 98 };
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 246
247 Initialize(); 247 Initialize();
248 ScopedVector<UsbMidiDevice> devices; 248 ScopedVector<UsbMidiDevice> devices;
249 devices.push_back(device.release()); 249 devices.push_back(device.release());
250 EXPECT_FALSE(initialize_callback_run_); 250 EXPECT_FALSE(initialize_callback_run_);
251 factory_->callback_.Run(true, &devices); 251 factory_->callback_.Run(true, &devices);
252 ASSERT_TRUE(initialize_callback_run_); 252 ASSERT_TRUE(initialize_callback_run_);
253 ASSERT_TRUE(initialize_result_); 253 ASSERT_TRUE(initialize_result_);
254 ASSERT_EQ(2u, manager_->output_streams().size()); 254 ASSERT_EQ(2u, manager_->output_streams().size());
255 255
256 manager_->DispatchSendMIDIData(&client, 1, ToVector(data), 0); 256 manager_->DispatchSendMidiData(&client, 1, ToVector(data), 0);
257 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n" 257 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n"
258 "UsbMidiDevice::Send endpoint = 2 data = " 258 "UsbMidiDevice::Send endpoint = 2 data = "
259 "0x19 0x90 0x45 0x7f " 259 "0x19 0x90 0x45 0x7f "
260 "0x14 0xf0 0x00 0x01 " 260 "0x14 0xf0 0x00 0x01 "
261 "0x15 0xf7 0x00 0x00\n" 261 "0x15 0xf7 0x00 0x00\n"
262 "MIDIManagerClient::AccumulateMIDIBytesSent size = 7\n", 262 "MidiManagerClient::AccumulateMidiBytesSent size = 7\n",
263 logger_.TakeLog()); 263 logger_.TakeLog());
264 } 264 }
265 265
266 TEST_F(MidiManagerUsbTest, Receive) { 266 TEST_F(MidiManagerUsbTest, Receive) {
267 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); 267 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
268 FakeMidiManagerClient client(&logger_); 268 FakeMidiManagerClient client(&logger_);
269 uint8 descriptor[] = { 269 uint8 descriptor[] = {
270 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 270 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
271 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 271 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
272 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 272 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
(...skipping 25 matching lines...) Expand all
298 EXPECT_FALSE(initialize_callback_run_); 298 EXPECT_FALSE(initialize_callback_run_);
299 factory_->callback_.Run(true, &devices); 299 factory_->callback_.Run(true, &devices);
300 ASSERT_TRUE(initialize_callback_run_); 300 ASSERT_TRUE(initialize_callback_run_);
301 ASSERT_TRUE(initialize_result_); 301 ASSERT_TRUE(initialize_result_);
302 302
303 manager_->StartSession(&client); 303 manager_->StartSession(&client);
304 manager_->ReceiveUsbMidiData(device_raw, 2, data, arraysize(data), 0); 304 manager_->ReceiveUsbMidiData(device_raw, 2, data, arraysize(data), 0);
305 manager_->EndSession(&client); 305 manager_->EndSession(&client);
306 306
307 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n" 307 EXPECT_EQ("UsbMidiDevice::GetDescriptor\n"
308 "MIDIManagerClient::ReceiveMIDIData port_index = 0 " 308 "MidiManagerClient::ReceiveMidiData port_index = 0 "
309 "data = 0x90 0x45 0x7f\n" 309 "data = 0x90 0x45 0x7f\n"
310 "MIDIManagerClient::ReceiveMIDIData port_index = 0 " 310 "MidiManagerClient::ReceiveMidiData port_index = 0 "
311 "data = 0xf0 0x00 0x01\n" 311 "data = 0xf0 0x00 0x01\n"
312 "MIDIManagerClient::ReceiveMIDIData port_index = 0 data = 0xf7\n", 312 "MidiManagerClient::ReceiveMidiData port_index = 0 data = 0xf7\n",
313 logger_.TakeLog()); 313 logger_.TakeLog());
314 } 314 }
315 315
316 } // namespace 316 } // namespace
317 317
318 } // namespace media 318 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/midi_manager_usb.cc ('k') | media/midi/midi_manager_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698