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

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

Issue 1138163002: Passing scoped_ptr into ScopedVector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed file as suggested Created 5 years, 7 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/midi_manager_usb.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
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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 248 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
249 0x05, 0x25, 0x01, 0x01, 0x07, 249 0x05, 0x25, 0x01, 0x01, 0x07,
250 }; 250 };
251 device->SetDescriptors(ToVector(descriptors)); 251 device->SetDescriptors(ToVector(descriptors));
252 device->SetManufacturer("vendor1"); 252 device->SetManufacturer("vendor1");
253 device->SetProductName("device1"); 253 device->SetProductName("device1");
254 device->SetDeviceVersion("1.02"); 254 device->SetDeviceVersion("1.02");
255 255
256 Initialize(); 256 Initialize();
257 ScopedVector<UsbMidiDevice> devices; 257 ScopedVector<UsbMidiDevice> devices;
258 devices.push_back(device.release()); 258 devices.push_back(device.Pass());
259 EXPECT_FALSE(IsInitializationCallbackInvoked()); 259 EXPECT_FALSE(IsInitializationCallbackInvoked());
260 RunCallbackUntilCallbackInvoked(true, &devices); 260 RunCallbackUntilCallbackInvoked(true, &devices);
261 EXPECT_EQ(MIDI_OK, GetInitializationResult()); 261 EXPECT_EQ(MIDI_OK, GetInitializationResult());
262 262
263 ASSERT_EQ(1u, input_ports().size()); 263 ASSERT_EQ(1u, input_ports().size());
264 EXPECT_EQ("port-0-2", input_ports()[0].id); 264 EXPECT_EQ("port-0-2", input_ports()[0].id);
265 EXPECT_EQ("vendor1", input_ports()[0].manufacturer); 265 EXPECT_EQ("vendor1", input_ports()[0].manufacturer);
266 EXPECT_EQ("device1", input_ports()[0].name); 266 EXPECT_EQ("device1", input_ports()[0].name);
267 EXPECT_EQ("1.02", input_ports()[0].version); 267 EXPECT_EQ("1.02", input_ports()[0].version);
268 268
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 device1->SetManufacturer("vendor1"); 308 device1->SetManufacturer("vendor1");
309 device1->SetProductName("device1"); 309 device1->SetProductName("device1");
310 device1->SetDeviceVersion("1.02"); 310 device1->SetDeviceVersion("1.02");
311 device2->SetDescriptors(ToVector(descriptors)); 311 device2->SetDescriptors(ToVector(descriptors));
312 device2->SetManufacturer("vendor2"); 312 device2->SetManufacturer("vendor2");
313 device2->SetProductName("device2"); 313 device2->SetProductName("device2");
314 device2->SetDeviceVersion("98.76"); 314 device2->SetDeviceVersion("98.76");
315 315
316 Initialize(); 316 Initialize();
317 ScopedVector<UsbMidiDevice> devices; 317 ScopedVector<UsbMidiDevice> devices;
318 devices.push_back(device1.release()); 318 devices.push_back(device1.Pass());
319 devices.push_back(device2.release()); 319 devices.push_back(device2.Pass());
320 EXPECT_FALSE(IsInitializationCallbackInvoked()); 320 EXPECT_FALSE(IsInitializationCallbackInvoked());
321 RunCallbackUntilCallbackInvoked(true, &devices); 321 RunCallbackUntilCallbackInvoked(true, &devices);
322 EXPECT_EQ(MIDI_OK, GetInitializationResult()); 322 EXPECT_EQ(MIDI_OK, GetInitializationResult());
323 323
324 ASSERT_EQ(2u, input_ports().size()); 324 ASSERT_EQ(2u, input_ports().size());
325 EXPECT_EQ("port-0-2", input_ports()[0].id); 325 EXPECT_EQ("port-0-2", input_ports()[0].id);
326 EXPECT_EQ("vendor1", input_ports()[0].manufacturer); 326 EXPECT_EQ("vendor1", input_ports()[0].manufacturer);
327 EXPECT_EQ("device1", input_ports()[0].name); 327 EXPECT_EQ("device1", input_ports()[0].name);
328 EXPECT_EQ("1.02", input_ports()[0].version); 328 EXPECT_EQ("1.02", input_ports()[0].version);
329 EXPECT_EQ("port-1-2", input_ports()[1].id); 329 EXPECT_EQ("port-1-2", input_ports()[1].id);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult()); 371 EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult());
372 } 372 }
373 373
374 TEST_F(MidiManagerUsbTest, InitializeFailBecauseOfInvalidDescriptors) { 374 TEST_F(MidiManagerUsbTest, InitializeFailBecauseOfInvalidDescriptors) {
375 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); 375 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
376 uint8 descriptors[] = {0x04}; 376 uint8 descriptors[] = {0x04};
377 device->SetDescriptors(ToVector(descriptors)); 377 device->SetDescriptors(ToVector(descriptors));
378 378
379 Initialize(); 379 Initialize();
380 ScopedVector<UsbMidiDevice> devices; 380 ScopedVector<UsbMidiDevice> devices;
381 devices.push_back(device.release()); 381 devices.push_back(device.Pass());
382 EXPECT_FALSE(IsInitializationCallbackInvoked()); 382 EXPECT_FALSE(IsInitializationCallbackInvoked());
383 RunCallbackUntilCallbackInvoked(true, &devices); 383 RunCallbackUntilCallbackInvoked(true, &devices);
384 EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult()); 384 EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult());
385 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); 385 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog());
386 } 386 }
387 387
388 TEST_F(MidiManagerUsbTest, Send) { 388 TEST_F(MidiManagerUsbTest, Send) {
389 Initialize(); 389 Initialize();
390 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_)); 390 scoped_ptr<FakeUsbMidiDevice> device(new FakeUsbMidiDevice(&logger_));
391 uint8 descriptors[] = { 391 uint8 descriptors[] = {
(...skipping 13 matching lines...) Expand all
405 0x05, 0x25, 0x01, 0x01, 0x07, 405 0x05, 0x25, 0x01, 0x01, 0x07,
406 }; 406 };
407 407
408 device->SetDescriptors(ToVector(descriptors)); 408 device->SetDescriptors(ToVector(descriptors));
409 uint8 data[] = { 409 uint8 data[] = {
410 0x90, 0x45, 0x7f, 410 0x90, 0x45, 0x7f,
411 0xf0, 0x00, 0x01, 0xf7, 411 0xf0, 0x00, 0x01, 0xf7,
412 }; 412 };
413 413
414 ScopedVector<UsbMidiDevice> devices; 414 ScopedVector<UsbMidiDevice> devices;
415 devices.push_back(device.release()); 415 devices.push_back(device.Pass());
416 EXPECT_FALSE(IsInitializationCallbackInvoked()); 416 EXPECT_FALSE(IsInitializationCallbackInvoked());
417 RunCallbackUntilCallbackInvoked(true, &devices); 417 RunCallbackUntilCallbackInvoked(true, &devices);
418 EXPECT_EQ(MIDI_OK, GetInitializationResult()); 418 EXPECT_EQ(MIDI_OK, GetInitializationResult());
419 ASSERT_EQ(2u, manager_->output_streams().size()); 419 ASSERT_EQ(2u, manager_->output_streams().size());
420 420
421 manager_->DispatchSendMidiData(client_.get(), 1, ToVector(data), 0); 421 manager_->DispatchSendMidiData(client_.get(), 1, ToVector(data), 0);
422 // Since UsbMidiDevice::Send is posted as a task, RunLoop should run to 422 // Since UsbMidiDevice::Send is posted as a task, RunLoop should run to
423 // invoke the task. 423 // invoke the task.
424 base::RunLoop run_loop; 424 base::RunLoop run_loop;
425 run_loop.RunUntilIdle(); 425 run_loop.RunUntilIdle();
(...skipping 26 matching lines...) Expand all
452 }; 452 };
453 453
454 device->SetDescriptors(ToVector(descriptors)); 454 device->SetDescriptors(ToVector(descriptors));
455 uint8 data[] = { 455 uint8 data[] = {
456 0x90, 0x45, 0x7f, 456 0x90, 0x45, 0x7f,
457 0xf0, 0x00, 0x01, 0xf7, 457 0xf0, 0x00, 0x01, 0xf7,
458 }; 458 };
459 459
460 Initialize(); 460 Initialize();
461 ScopedVector<UsbMidiDevice> devices; 461 ScopedVector<UsbMidiDevice> devices;
462 devices.push_back(device.release()); 462 devices.push_back(device.Pass());
463 EXPECT_FALSE(IsInitializationCallbackInvoked()); 463 EXPECT_FALSE(IsInitializationCallbackInvoked());
464 RunCallbackUntilCallbackInvoked(true, &devices); 464 RunCallbackUntilCallbackInvoked(true, &devices);
465 EXPECT_EQ(MIDI_OK, GetInitializationResult()); 465 EXPECT_EQ(MIDI_OK, GetInitializationResult());
466 ASSERT_EQ(2u, manager_->output_streams().size()); 466 ASSERT_EQ(2u, manager_->output_streams().size());
467 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); 467 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog());
468 468
469 // The specified port index is invalid. The manager must ignore the request. 469 // The specified port index is invalid. The manager must ignore the request.
470 manager_->DispatchSendMidiData(client_.get(), 99, ToVector(data), 0); 470 manager_->DispatchSendMidiData(client_.get(), 99, ToVector(data), 0);
471 EXPECT_EQ("", logger_.TakeLog()); 471 EXPECT_EQ("", logger_.TakeLog());
472 472
(...skipping 25 matching lines...) Expand all
498 uint8 data[] = { 498 uint8 data[] = {
499 0x09, 0x90, 0x45, 0x7f, 499 0x09, 0x90, 0x45, 0x7f,
500 0x04, 0xf0, 0x00, 0x01, 500 0x04, 0xf0, 0x00, 0x01,
501 0x49, 0x90, 0x88, 0x99, // This data should be ignored (CN = 4). 501 0x49, 0x90, 0x88, 0x99, // This data should be ignored (CN = 4).
502 0x05, 0xf7, 0x00, 0x00, 502 0x05, 0xf7, 0x00, 0x00,
503 }; 503 };
504 504
505 Initialize(); 505 Initialize();
506 ScopedVector<UsbMidiDevice> devices; 506 ScopedVector<UsbMidiDevice> devices;
507 UsbMidiDevice* device_raw = device.get(); 507 UsbMidiDevice* device_raw = device.get();
508 devices.push_back(device.release()); 508 devices.push_back(device.Pass());
509 EXPECT_FALSE(IsInitializationCallbackInvoked()); 509 EXPECT_FALSE(IsInitializationCallbackInvoked());
510 RunCallbackUntilCallbackInvoked(true, &devices); 510 RunCallbackUntilCallbackInvoked(true, &devices);
511 EXPECT_EQ(MIDI_OK, GetInitializationResult()); 511 EXPECT_EQ(MIDI_OK, GetInitializationResult());
512 512
513 manager_->ReceiveUsbMidiData(device_raw, 2, data, arraysize(data), 513 manager_->ReceiveUsbMidiData(device_raw, 2, data, arraysize(data),
514 base::TimeTicks()); 514 base::TimeTicks());
515 Finalize(); 515 Finalize();
516 516
517 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n" 517 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n"
518 "MidiManagerClient::ReceiveMidiData port_index = 0 " 518 "MidiManagerClient::ReceiveMidiData port_index = 0 "
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id); 568 EXPECT_EQ(3u, manager_->output_streams()[1]->jack().jack_id);
569 ASSERT_EQ(1u, jacks.size()); 569 ASSERT_EQ(1u, jacks.size());
570 EXPECT_EQ(2, jacks[0].endpoint_number()); 570 EXPECT_EQ(2, jacks[0].endpoint_number());
571 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); 571 EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog());
572 } 572 }
573 573
574 } // namespace 574 } // namespace
575 575
576 } // namespace midi 576 } // namespace midi
577 } // namespace media 577 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/midi_manager_usb.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698