| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_alsa.h" | 5 #include "media/midi/midi_manager_alsa.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 10 |
| 9 namespace media { | 11 namespace media { |
| 10 namespace midi { | 12 namespace midi { |
| 11 | 13 |
| 12 class MidiManagerAlsaTest : public ::testing::Test { | 14 class MidiManagerAlsaTest : public ::testing::Test { |
| 13 protected: | 15 protected: |
| 14 void SetUp() override { | 16 void SetUp() override { |
| 15 // Pre-instantiate typical MidiPort instances that are often used in | 17 // Pre-instantiate typical MidiPort instances that are often used in |
| 16 // following tests. | 18 // following tests. |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 TEST_F(MidiManagerAlsaTest, PortIndexSet) { | 371 TEST_F(MidiManagerAlsaTest, PortIndexSet) { |
| 370 auto* port_input_0_tracking_pointer = port_input_0_.get(); | 372 auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 371 auto* port_output_0_tracking_pointer = port_output_0_.get(); | 373 auto* port_output_0_tracking_pointer = port_output_0_.get(); |
| 372 auto* port_input_1_tracking_pointer = port_input_1_.get(); | 374 auto* port_input_1_tracking_pointer = port_input_1_.get(); |
| 373 auto* port_output_1_tracking_pointer = port_input_1_.get(); | 375 auto* port_output_1_tracking_pointer = port_input_1_.get(); |
| 374 | 376 |
| 375 // Explicitly initialize web_port_index. | 377 // Explicitly initialize web_port_index. |
| 376 port_input_1_->set_web_port_index(5000); | 378 port_input_1_->set_web_port_index(5000); |
| 377 port_output_1_->set_web_port_index(5000); | 379 port_output_1_->set_web_port_index(5000); |
| 378 | 380 |
| 379 midi_port_state_0_.push_back(port_input_0_.Pass()); | 381 midi_port_state_0_.push_back(std::move(port_input_0_)); |
| 380 midi_port_state_0_.push_back(port_output_0_.Pass()); | 382 midi_port_state_0_.push_back(std::move(port_output_0_)); |
| 381 midi_port_state_0_.push_back(port_input_1_.Pass()); | 383 midi_port_state_0_.push_back(std::move(port_input_1_)); |
| 382 midi_port_state_0_.push_back(port_output_1_.Pass()); | 384 midi_port_state_0_.push_back(std::move(port_output_1_)); |
| 383 | 385 |
| 384 // First port of each type has index of 0. | 386 // First port of each type has index of 0. |
| 385 EXPECT_EQ(0U, port_input_0_tracking_pointer->web_port_index()); | 387 EXPECT_EQ(0U, port_input_0_tracking_pointer->web_port_index()); |
| 386 EXPECT_EQ(0U, port_output_0_tracking_pointer->web_port_index()); | 388 EXPECT_EQ(0U, port_output_0_tracking_pointer->web_port_index()); |
| 387 // Second port of each type has index of 1. | 389 // Second port of each type has index of 1. |
| 388 EXPECT_EQ(1U, port_input_1_tracking_pointer->web_port_index()); | 390 EXPECT_EQ(1U, port_input_1_tracking_pointer->web_port_index()); |
| 389 EXPECT_EQ(1U, port_output_1_tracking_pointer->web_port_index()); | 391 EXPECT_EQ(1U, port_output_1_tracking_pointer->web_port_index()); |
| 390 } | 392 } |
| 391 | 393 |
| 392 // Tests that the web_port_index is not updated by TemporaryMidiPortState. | 394 // Tests that the web_port_index is not updated by TemporaryMidiPortState. |
| 393 TEST_F(MidiManagerAlsaTest, PortIndexNotSet) { | 395 TEST_F(MidiManagerAlsaTest, PortIndexNotSet) { |
| 394 auto* port_input_0_tracking_pointer = port_input_0_.get(); | 396 auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 395 auto* port_output_0_tracking_pointer = port_output_0_.get(); | 397 auto* port_output_0_tracking_pointer = port_output_0_.get(); |
| 396 auto* port_input_1_tracking_pointer = port_input_1_.get(); | 398 auto* port_input_1_tracking_pointer = port_input_1_.get(); |
| 397 auto* port_output_1_tracking_pointer = port_input_1_.get(); | 399 auto* port_output_1_tracking_pointer = port_input_1_.get(); |
| 398 | 400 |
| 399 // Explicitly initialize web_port_index. | 401 // Explicitly initialize web_port_index. |
| 400 port_input_1_->set_web_port_index(5000); | 402 port_input_1_->set_web_port_index(5000); |
| 401 port_output_1_->set_web_port_index(5000); | 403 port_output_1_->set_web_port_index(5000); |
| 402 | 404 |
| 403 temporary_midi_port_state_0_.push_back(port_input_0_.Pass()); | 405 temporary_midi_port_state_0_.push_back(std::move(port_input_0_)); |
| 404 temporary_midi_port_state_0_.push_back(port_output_0_.Pass()); | 406 temporary_midi_port_state_0_.push_back(std::move(port_output_0_)); |
| 405 temporary_midi_port_state_0_.push_back(port_input_1_.Pass()); | 407 temporary_midi_port_state_0_.push_back(std::move(port_input_1_)); |
| 406 temporary_midi_port_state_0_.push_back(port_output_1_.Pass()); | 408 temporary_midi_port_state_0_.push_back(std::move(port_output_1_)); |
| 407 | 409 |
| 408 // web_port_index is untouched. | 410 // web_port_index is untouched. |
| 409 EXPECT_EQ(0U, port_input_0_tracking_pointer->web_port_index()); | 411 EXPECT_EQ(0U, port_input_0_tracking_pointer->web_port_index()); |
| 410 EXPECT_EQ(0U, port_output_0_tracking_pointer->web_port_index()); | 412 EXPECT_EQ(0U, port_output_0_tracking_pointer->web_port_index()); |
| 411 EXPECT_EQ(5000U, port_input_1_tracking_pointer->web_port_index()); | 413 EXPECT_EQ(5000U, port_input_1_tracking_pointer->web_port_index()); |
| 412 EXPECT_EQ(5000U, port_output_1_tracking_pointer->web_port_index()); | 414 EXPECT_EQ(5000U, port_output_1_tracking_pointer->web_port_index()); |
| 413 } | 415 } |
| 414 | 416 |
| 415 // Tests that inputs and outputs stay separate in MidiPortState. | 417 // Tests that inputs and outputs stay separate in MidiPortState. |
| 416 TEST_F(MidiManagerAlsaTest, SeparateInputOutput) { | 418 TEST_F(MidiManagerAlsaTest, SeparateInputOutput) { |
| 417 auto* port_input_0_tracking_pointer = port_input_0_.get(); | 419 auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 418 auto* port_output_0_tracking_pointer = port_output_0_.get(); | 420 auto* port_output_0_tracking_pointer = port_output_0_.get(); |
| 419 auto* port_input_1_tracking_pointer = port_input_1_.get(); | 421 auto* port_input_1_tracking_pointer = port_input_1_.get(); |
| 420 auto* port_output_1_tracking_pointer = port_input_1_.get(); | 422 auto* port_output_1_tracking_pointer = port_input_1_.get(); |
| 421 | 423 |
| 422 // First port of each type has index of 0. | 424 // First port of each type has index of 0. |
| 423 EXPECT_EQ(0U, midi_port_state_0_.push_back(port_input_0_.Pass())); | 425 EXPECT_EQ(0U, midi_port_state_0_.push_back(std::move(port_input_0_))); |
| 424 EXPECT_EQ(0U, midi_port_state_0_.push_back(port_output_0_.Pass())); | 426 EXPECT_EQ(0U, midi_port_state_0_.push_back(std::move(port_output_0_))); |
| 425 | 427 |
| 426 // Second port of each type has index of 1. | 428 // Second port of each type has index of 1. |
| 427 EXPECT_EQ(1U, midi_port_state_0_.push_back(port_input_1_.Pass())); | 429 EXPECT_EQ(1U, midi_port_state_0_.push_back(std::move(port_input_1_))); |
| 428 EXPECT_EQ(1U, midi_port_state_0_.push_back(port_output_1_.Pass())); | 430 EXPECT_EQ(1U, midi_port_state_0_.push_back(std::move(port_output_1_))); |
| 429 | 431 |
| 430 // Check again that the field matches what was returned. | 432 // Check again that the field matches what was returned. |
| 431 EXPECT_EQ(0U, port_input_0_tracking_pointer->web_port_index()); | 433 EXPECT_EQ(0U, port_input_0_tracking_pointer->web_port_index()); |
| 432 EXPECT_EQ(0U, port_output_0_tracking_pointer->web_port_index()); | 434 EXPECT_EQ(0U, port_output_0_tracking_pointer->web_port_index()); |
| 433 EXPECT_EQ(1U, port_input_1_tracking_pointer->web_port_index()); | 435 EXPECT_EQ(1U, port_input_1_tracking_pointer->web_port_index()); |
| 434 EXPECT_EQ(1U, port_output_1_tracking_pointer->web_port_index()); | 436 EXPECT_EQ(1U, port_output_1_tracking_pointer->web_port_index()); |
| 435 } | 437 } |
| 436 | 438 |
| 437 // Tests FindConnected. | 439 // Tests FindConnected. |
| 438 TEST_F(MidiManagerAlsaTest, FindConnected) { | 440 TEST_F(MidiManagerAlsaTest, FindConnected) { |
| 439 auto* port_input_0_tracking_pointer = port_input_0_.get(); | 441 auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 440 auto* port_input_1_tracking_pointer = port_input_1_.get(); | 442 auto* port_input_1_tracking_pointer = port_input_1_.get(); |
| 441 | 443 |
| 442 // Insert port_input_0. | 444 // Insert port_input_0. |
| 443 midi_port_state_0_.push_back(port_input_0_.Pass()); | 445 midi_port_state_0_.push_back(std::move(port_input_0_)); |
| 444 // Look for port_input_1 (every field matches port_input_0). | 446 // Look for port_input_1 (every field matches port_input_0). |
| 445 auto it = midi_port_state_0_.FindConnected(*port_input_1_tracking_pointer); | 447 auto it = midi_port_state_0_.FindConnected(*port_input_1_tracking_pointer); |
| 446 EXPECT_EQ(port_input_0_tracking_pointer, it->get()); | 448 EXPECT_EQ(port_input_0_tracking_pointer, it->get()); |
| 447 // Look for something else that we won't find. | 449 // Look for something else that we won't find. |
| 448 EXPECT_EQ(midi_port_state_0_.end(), | 450 EXPECT_EQ(midi_port_state_0_.end(), |
| 449 midi_port_state_0_.FindConnected(*port_input_0_alt_path_)); | 451 midi_port_state_0_.FindConnected(*port_input_0_alt_path_)); |
| 450 } | 452 } |
| 451 | 453 |
| 452 TEST_F(MidiManagerAlsaTest, FindConnected2) { | 454 TEST_F(MidiManagerAlsaTest, FindConnected2) { |
| 453 auto* port_input_0_tracking_pointer = port_input_0_.get(); | 455 auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 454 auto* port_input_1_tracking_pointer = port_input_1_.get(); | 456 auto* port_input_1_tracking_pointer = port_input_1_.get(); |
| 455 | 457 |
| 456 // Insert some stuff. | 458 // Insert some stuff. |
| 457 midi_port_state_0_.push_back(port_input_0_alt_path_.Pass()); | 459 midi_port_state_0_.push_back(std::move(port_input_0_alt_path_)); |
| 458 midi_port_state_0_.push_back(port_input_0_alt_id_.Pass()); | 460 midi_port_state_0_.push_back(std::move(port_input_0_alt_id_)); |
| 459 midi_port_state_0_.push_back(port_input_0_alt_client_name_.Pass()); | 461 midi_port_state_0_.push_back(std::move(port_input_0_alt_client_name_)); |
| 460 // Insert port_input_0. | 462 // Insert port_input_0. |
| 461 midi_port_state_0_.push_back(port_input_0_.Pass()); | 463 midi_port_state_0_.push_back(std::move(port_input_0_)); |
| 462 // Insert some more stuff. | 464 // Insert some more stuff. |
| 463 midi_port_state_0_.push_back(port_input_0_alt_port_id_.Pass()); | 465 midi_port_state_0_.push_back(std::move(port_input_0_alt_port_id_)); |
| 464 // Look for port_input_1 (matches to port_input_0). | 466 // Look for port_input_1 (matches to port_input_0). |
| 465 auto it = midi_port_state_0_.FindConnected(*port_input_1_tracking_pointer); | 467 auto it = midi_port_state_0_.FindConnected(*port_input_1_tracking_pointer); |
| 466 EXPECT_EQ(port_input_0_tracking_pointer, it->get()); | 468 EXPECT_EQ(port_input_0_tracking_pointer, it->get()); |
| 467 // Look for something else that we won't find. | 469 // Look for something else that we won't find. |
| 468 EXPECT_EQ(midi_port_state_0_.end(), | 470 EXPECT_EQ(midi_port_state_0_.end(), |
| 469 midi_port_state_0_.FindConnected(*port_input_minimal_)); | 471 midi_port_state_0_.FindConnected(*port_input_minimal_)); |
| 470 } | 472 } |
| 471 | 473 |
| 472 TEST_F(MidiManagerAlsaTest, FindConnected3) { | 474 TEST_F(MidiManagerAlsaTest, FindConnected3) { |
| 473 // midi_port_state_0_ is empty to start. | 475 // midi_port_state_0_ is empty to start. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 486 auto* port_input_0_tracking_pointer = port_input_0_.get(); | 488 auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 487 auto* port_input_1_tracking_pointer = port_input_1_.get(); | 489 auto* port_input_1_tracking_pointer = port_input_1_.get(); |
| 488 auto* port_input_1_no_card_tracking_pointer = port_input_1_no_card_.get(); | 490 auto* port_input_1_no_card_tracking_pointer = port_input_1_no_card_.get(); |
| 489 | 491 |
| 490 // Ports need to be disconnected to find them. | 492 // Ports need to be disconnected to find them. |
| 491 port_input_0_alt_id_->set_connected(false); | 493 port_input_0_alt_id_->set_connected(false); |
| 492 port_input_0_alt_path_->set_connected(false); | 494 port_input_0_alt_path_->set_connected(false); |
| 493 port_input_0_->set_connected(false); | 495 port_input_0_->set_connected(false); |
| 494 | 496 |
| 495 // Insert some stuff. | 497 // Insert some stuff. |
| 496 midi_port_state_0_.push_back(port_input_0_alt_id_.Pass()); | 498 midi_port_state_0_.push_back(std::move(port_input_0_alt_id_)); |
| 497 midi_port_state_0_.push_back(port_input_0_alt_path_.Pass()); | 499 midi_port_state_0_.push_back(std::move(port_input_0_alt_path_)); |
| 498 // Insert port_input_0. | 500 // Insert port_input_0. |
| 499 midi_port_state_0_.push_back(port_input_0_.Pass()); | 501 midi_port_state_0_.push_back(std::move(port_input_0_)); |
| 500 | 502 |
| 501 // Add "no card" stuff. | 503 // Add "no card" stuff. |
| 502 port_input_1_no_card_->set_connected(false); | 504 port_input_1_no_card_->set_connected(false); |
| 503 midi_port_state_0_.push_back(port_input_1_no_card_.Pass()); | 505 midi_port_state_0_.push_back(std::move(port_input_1_no_card_)); |
| 504 | 506 |
| 505 // Insert some more stuff. | 507 // Insert some more stuff. |
| 506 midi_port_state_0_.push_back(port_input_0_alt_port_id_.Pass()); | 508 midi_port_state_0_.push_back(std::move(port_input_0_alt_port_id_)); |
| 507 | 509 |
| 508 // Look for port_input_1, should trigger exact match. | 510 // Look for port_input_1, should trigger exact match. |
| 509 EXPECT_EQ(port_input_0_tracking_pointer, | 511 EXPECT_EQ(port_input_0_tracking_pointer, |
| 510 midi_port_state_0_.FindDisconnected(*port_input_1_tracking_pointer) | 512 midi_port_state_0_.FindDisconnected(*port_input_1_tracking_pointer) |
| 511 ->get()); | 513 ->get()); |
| 512 | 514 |
| 513 // Look for no card exact match. | 515 // Look for no card exact match. |
| 514 EXPECT_EQ( | 516 EXPECT_EQ( |
| 515 port_input_1_no_card_tracking_pointer, | 517 port_input_1_no_card_tracking_pointer, |
| 516 midi_port_state_0_.FindDisconnected(*port_input_0_no_card_.get())->get()); | 518 midi_port_state_0_.FindDisconnected(*port_input_0_no_card_.get())->get()); |
| 517 | 519 |
| 518 // Look for something else that we won't find. | 520 // Look for something else that we won't find. |
| 519 EXPECT_EQ(midi_port_state_0_.end(), | 521 EXPECT_EQ(midi_port_state_0_.end(), |
| 520 midi_port_state_0_.FindDisconnected(*port_input_minimal_)); | 522 midi_port_state_0_.FindDisconnected(*port_input_minimal_)); |
| 521 } | 523 } |
| 522 | 524 |
| 523 TEST_F(MidiManagerAlsaTest, FindDisconnected3) { | 525 TEST_F(MidiManagerAlsaTest, FindDisconnected3) { |
| 524 auto* port_input_0_tracking_pointer = port_input_0_.get(); | 526 auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 525 auto* port_input_0_alt_path_tracking_pointer = port_input_0_alt_path_.get(); | 527 auto* port_input_0_alt_path_tracking_pointer = port_input_0_alt_path_.get(); |
| 526 auto* port_input_1_no_card_tracking_pointer = port_input_1_no_card_.get(); | 528 auto* port_input_1_no_card_tracking_pointer = port_input_1_no_card_.get(); |
| 527 | 529 |
| 528 // Ports need to be disconnected to find them. | 530 // Ports need to be disconnected to find them. |
| 529 port_input_0_alt_path_->set_connected(false); | 531 port_input_0_alt_path_->set_connected(false); |
| 530 port_input_0_->set_connected(false); | 532 port_input_0_->set_connected(false); |
| 531 | 533 |
| 532 // Insert some stuff. | 534 // Insert some stuff. |
| 533 midi_port_state_0_.push_back(port_input_0_alt_path_.Pass()); | 535 midi_port_state_0_.push_back(std::move(port_input_0_alt_path_)); |
| 534 midi_port_state_0_.push_back(port_input_0_alt_id_.Pass()); | 536 midi_port_state_0_.push_back(std::move(port_input_0_alt_id_)); |
| 535 | 537 |
| 536 // Add no card stuff. | 538 // Add no card stuff. |
| 537 port_input_1_no_card_->set_connected(false); | 539 port_input_1_no_card_->set_connected(false); |
| 538 midi_port_state_0_.push_back(port_input_1_no_card_.Pass()); | 540 midi_port_state_0_.push_back(std::move(port_input_1_no_card_)); |
| 539 | 541 |
| 540 // Look for port_input_0, should find port_input_0_alt_path. | 542 // Look for port_input_0, should find port_input_0_alt_path. |
| 541 EXPECT_EQ(port_input_0_alt_path_tracking_pointer, | 543 EXPECT_EQ(port_input_0_alt_path_tracking_pointer, |
| 542 midi_port_state_0_.FindDisconnected(*port_input_0_tracking_pointer) | 544 midi_port_state_0_.FindDisconnected(*port_input_0_tracking_pointer) |
| 543 ->get()); | 545 ->get()); |
| 544 | 546 |
| 545 // Look for no card partial match. | 547 // Look for no card partial match. |
| 546 EXPECT_EQ(port_input_1_no_card_tracking_pointer, | 548 EXPECT_EQ(port_input_1_no_card_tracking_pointer, |
| 547 midi_port_state_0_.FindDisconnected( | 549 midi_port_state_0_.FindDisconnected( |
| 548 *port_input_0_no_card_alt_client_id_.get()) | 550 *port_input_0_no_card_alt_client_id_.get()) |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 } | 696 } |
| 695 | 697 |
| 696 TEST_F(MidiManagerAlsaTest, AlsaCards) { | 698 TEST_F(MidiManagerAlsaTest, AlsaCards) { |
| 697 // TODO(agoode): test add/remove of alsa cards. | 699 // TODO(agoode): test add/remove of alsa cards. |
| 698 } | 700 } |
| 699 | 701 |
| 700 // TODO(agoode): Test old -> new state event generation, using mocks. | 702 // TODO(agoode): Test old -> new state event generation, using mocks. |
| 701 | 703 |
| 702 } // namespace midi | 704 } // namespace midi |
| 703 } // namespace media | 705 } // namespace media |
| OLD | NEW |