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

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

Issue 1126983007: MidiManagerAlsa: Enable manufacturer again, now with hotplug (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@magical-sound-furnace
Patch Set: Fix midi_device for user clients 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
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace media { 9 namespace media {
10 namespace midi { 10 namespace midi {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 scoped_ptr<MidiManagerAlsa::MidiPort> port_input_0_no_card_alt_client_name_; 113 scoped_ptr<MidiManagerAlsa::MidiPort> port_input_0_no_card_alt_client_name_;
114 scoped_ptr<MidiManagerAlsa::MidiPort> port_input_0_no_card_alt_port_name_; 114 scoped_ptr<MidiManagerAlsa::MidiPort> port_input_0_no_card_alt_port_name_;
115 scoped_ptr<MidiManagerAlsa::MidiPort> port_input_0_no_card_alt_client_id_; 115 scoped_ptr<MidiManagerAlsa::MidiPort> port_input_0_no_card_alt_client_id_;
116 scoped_ptr<MidiManagerAlsa::MidiPort> port_input_0_no_card_alt_port_id_; 116 scoped_ptr<MidiManagerAlsa::MidiPort> port_input_0_no_card_alt_port_id_;
117 117
118 // State fields to avoid declaring in test fixtures below. 118 // State fields to avoid declaring in test fixtures below.
119 MidiManagerAlsa::MidiPortState midi_port_state_0_; 119 MidiManagerAlsa::MidiPortState midi_port_state_0_;
120 MidiManagerAlsa::MidiPortState midi_port_state_1_; 120 MidiManagerAlsa::MidiPortState midi_port_state_1_;
121 MidiManagerAlsa::TemporaryMidiPortState temporary_midi_port_state_0_; 121 MidiManagerAlsa::TemporaryMidiPortState temporary_midi_port_state_0_;
122 MidiManagerAlsa::AlsaSeqState alsa_seq_state_0_; 122 MidiManagerAlsa::AlsaSeqState alsa_seq_state_0_;
123 MidiManagerAlsa::AlsaCardMap alsa_cards_;
123 }; 124 };
124 125
125 // Tests that ExtractManufacturerString works as expected. 126 // Tests that ExtractManufacturerString works as expected.
126 TEST_F(MidiManagerAlsaTest, ExtractManufacturer) { 127 TEST_F(MidiManagerAlsaTest, ExtractManufacturer) {
127 EXPECT_EQ("My\\x20Vendor", MidiManagerAlsa::ExtractManufacturerString( 128 EXPECT_EQ("My\\x20Vendor",
128 "My\\x20Vendor", "1234", "My Vendor, Inc.", 129 MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
129 "Card", "My Vendor Inc Card at bus")); 130 "My\\x20Vendor", "1234", "My Vendor, Inc.", "Card",
130 EXPECT_EQ("My Vendor", MidiManagerAlsa::ExtractManufacturerString( 131 "My Vendor Inc Card at bus"));
132 EXPECT_EQ("My Vendor", MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
131 "My Vendor", "1234", "My Vendor, Inc.", "Card", 133 "My Vendor", "1234", "My Vendor, Inc.", "Card",
132 "My Vendor Inc Card at bus")); 134 "My Vendor Inc Card at bus"));
133 EXPECT_EQ("My Vendor, Inc.", MidiManagerAlsa::ExtractManufacturerString( 135 EXPECT_EQ("My Vendor, Inc.",
134 "1234", "1234", "My Vendor, Inc.", "Card", 136 MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
135 "My Vendor Inc Card at bus")); 137 "1234", "1234", "My Vendor, Inc.", "Card",
138 "My Vendor Inc Card at bus"));
136 EXPECT_EQ("My Vendor Inc", 139 EXPECT_EQ("My Vendor Inc",
137 MidiManagerAlsa::ExtractManufacturerString( 140 MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
138 "1234", "1234", "", "Card", "My Vendor Inc Card at bus")); 141 "1234", "1234", "", "Card", "My Vendor Inc Card at bus"));
139 EXPECT_EQ("My Vendor Inc", 142 EXPECT_EQ("My Vendor Inc",
140 MidiManagerAlsa::ExtractManufacturerString( 143 MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
141 "", "", "", "Card", "My Vendor Inc Card at bus")); 144 "", "", "", "Card", "My Vendor Inc Card at bus"));
142 EXPECT_EQ("", MidiManagerAlsa::ExtractManufacturerString("1234", "1234", "", 145 EXPECT_EQ("", MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
143 "Card", "Longname")); 146 "1234", "1234", "", "Card", "Longname"));
144 EXPECT_EQ("Keystation\\x20Mini\\x2032", 147 EXPECT_EQ("Keystation\\x20Mini\\x2032",
145 MidiManagerAlsa::ExtractManufacturerString( 148 MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
146 "Keystation\\x20Mini\\x2032", "129d", 149 "Keystation\\x20Mini\\x2032", "129d",
147 "Evolution Electronics, Ltd", "Keystation Mini 32", 150 "Evolution Electronics, Ltd", "Keystation Mini 32",
148 "Keystation Mini 32 Keystation Mini 32 at" 151 "Keystation Mini 32 Keystation Mini 32 at"
149 " usb-0000:00:14.0-2.4.4, full speed")); 152 " usb-0000:00:14.0-2.4.4, full speed"));
150 EXPECT_EQ("Keystation Mini 32", 153 EXPECT_EQ("Keystation Mini 32",
151 MidiManagerAlsa::ExtractManufacturerString( 154 MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
152 "Keystation Mini 32", "129d", "Evolution Electronics, Ltd", 155 "Keystation Mini 32", "129d", "Evolution Electronics, Ltd",
153 "Keystation Mini 32", 156 "Keystation Mini 32",
154 "Keystation Mini 32 Keystation Mini 32 at" 157 "Keystation Mini 32 Keystation Mini 32 at"
155 " usb-0000:00:14.0-2.4.4, full speed")); 158 " usb-0000:00:14.0-2.4.4, full speed"));
156 EXPECT_EQ("Keystation Mini 32", MidiManagerAlsa::ExtractManufacturerString( 159 EXPECT_EQ("Keystation Mini 32",
157 "", "", "", "Keystation Mini 32", 160 MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
158 "Keystation Mini 32 Keystation Mini 32 at" 161 "", "", "", "Keystation Mini 32",
159 " usb-0000:00:14.0-2.4.4, full speed")); 162 "Keystation Mini 32 Keystation Mini 32 at"
160 EXPECT_EQ("", MidiManagerAlsa::ExtractManufacturerString( 163 " usb-0000:00:14.0-2.4.4, full speed"));
164 EXPECT_EQ("", MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
161 "", "", "", "Serial MIDI (UART16550A)", 165 "", "", "", "Serial MIDI (UART16550A)",
162 "Serial MIDI (UART16550A) [Soundcanvas] at 0x3f8, irq 4")); 166 "Serial MIDI (UART16550A) [Soundcanvas] at 0x3f8, irq 4"));
163 EXPECT_EQ("", MidiManagerAlsa::ExtractManufacturerString( 167 EXPECT_EQ("", MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
164 "", "", "", "VirMIDI", "Virtual MIDI Card 1")); 168 "", "", "", "VirMIDI", "Virtual MIDI Card 1"));
165 EXPECT_EQ("C-Media Electronics Inc", 169 EXPECT_EQ("C-Media Electronics Inc",
166 MidiManagerAlsa::ExtractManufacturerString( 170 MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
167 "", "0x13f6", "C-Media Electronics Inc", "C-Media CMI8738 MIDI", 171 "", "0x13f6", "C-Media Electronics Inc", "C-Media CMI8738 MIDI",
168 "C-Media CMI8738 (model 55) at 0xd000, irq 19")); 172 "C-Media CMI8738 (model 55) at 0xd000, irq 19"));
169 EXPECT_EQ("C-Media Electronics Inc", 173 EXPECT_EQ("C-Media Electronics Inc",
170 MidiManagerAlsa::ExtractManufacturerString( 174 MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
171 "", "0x13f6", "C-Media Electronics Inc", "C-Media CMI8738 FM", 175 "", "0x13f6", "C-Media Electronics Inc", "C-Media CMI8738 FM",
172 "C-Media CMI8738 (model 55) at 0xd000, irq 19")); 176 "C-Media CMI8738 (model 55) at 0xd000, irq 19"));
173 } 177 }
174 178
175 // Tests that verify proper serialization and generation of opaque key for 179 // Tests that verify proper serialization and generation of opaque key for
176 // MidiPort. 180 // MidiPort.
177 TEST_F(MidiManagerAlsaTest, JSONPortMetadata) { 181 TEST_F(MidiManagerAlsaTest, JSONPortMetadata) {
178 EXPECT_EQ( 182 EXPECT_EQ(
179 "{\"clientId\":1,\"clientName\":\"client_name\",\"id\":\"id\"," 183 "{\"clientId\":1,\"clientName\":\"client_name\",\"id\":\"id\","
180 "\"midiDevice\":5,\"path\":\"path\",\"portId\":2,\"portName\":\"port_" 184 "\"midiDevice\":5,\"path\":\"path\",\"portId\":2,\"portName\":\"port_"
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 *port_input_0_no_card_alt_port_id_.get())); 520 *port_input_0_no_card_alt_port_id_.get()));
517 521
518 // Look for something else that we won't find. 522 // Look for something else that we won't find.
519 EXPECT_EQ(midi_port_state_0_.end(), 523 EXPECT_EQ(midi_port_state_0_.end(),
520 midi_port_state_0_.FindDisconnected(*port_input_minimal_)); 524 midi_port_state_0_.FindDisconnected(*port_input_minimal_));
521 } 525 }
522 526
523 // Tests AlsaSeqState -> MidiPortState. 527 // Tests AlsaSeqState -> MidiPortState.
524 TEST_F(MidiManagerAlsaTest, ToMidiPortState) { 528 TEST_F(MidiManagerAlsaTest, ToMidiPortState) {
525 // Empty state. 529 // Empty state.
526 EXPECT_EQ(0, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 530 EXPECT_EQ(0,
531 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
527 532
528 // Still empty, because there are no ports yet. 533 // Still empty, because there are no ports yet.
529 alsa_seq_state_0_.ClientStart(0, "0", SND_SEQ_KERNEL_CLIENT); 534 alsa_seq_state_0_.ClientStart(0, "0", SND_SEQ_KERNEL_CLIENT);
530 EXPECT_EQ(0, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 535 EXPECT_EQ(0,
536 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
531 537
532 // Add a port, now it has 1 item when converted. 538 // Add a port, now it has 1 item when converted.
533 alsa_seq_state_0_.PortStart( 539 alsa_seq_state_0_.PortStart(
534 0, 0, "0:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kInput, true); 540 0, 0, "0:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kInput, true);
535 EXPECT_EQ(1, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 541 EXPECT_EQ(1,
542 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
536 543
537 // Close client. This closes its ports and returns count to 0. 544 // Close client. This closes its ports and returns count to 0.
538 alsa_seq_state_0_.ClientExit(0); 545 alsa_seq_state_0_.ClientExit(0);
539 EXPECT_EQ(0, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 546 EXPECT_EQ(0,
547 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
540 548
541 // Add another port, without client. This does nothing. 549 // Add another port, without client. This does nothing.
542 alsa_seq_state_0_.PortStart( 550 alsa_seq_state_0_.PortStart(
543 0, 0, "0:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kInput, true); 551 0, 0, "0:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kInput, true);
544 EXPECT_EQ(0, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 552 EXPECT_EQ(0,
553 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
545 554
546 // Close client again. This does nothing. 555 // Close client again. This does nothing.
547 alsa_seq_state_0_.ClientExit(0); 556 alsa_seq_state_0_.ClientExit(0);
548 EXPECT_EQ(0, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 557 EXPECT_EQ(0,
558 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
549 559
550 // Add duplex port. This will add 2 ports when converted. 560 // Add duplex port. This will add 2 ports when converted.
551 alsa_seq_state_0_.ClientStart(0, "0", SND_SEQ_KERNEL_CLIENT); 561 alsa_seq_state_0_.ClientStart(0, "0", SND_SEQ_KERNEL_CLIENT);
552 alsa_seq_state_0_.PortStart( 562 alsa_seq_state_0_.PortStart(
553 0, 0, "0:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kDuplex, true); 563 0, 0, "0:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kDuplex, true);
554 EXPECT_EQ(2, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 564 EXPECT_EQ(2,
565 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
555 566
556 // Add an output port. Now we are at 3. 567 // Add an output port. Now we are at 3.
557 alsa_seq_state_0_.PortStart( 568 alsa_seq_state_0_.PortStart(
558 0, 1, "0:1", MidiManagerAlsa::AlsaSeqState::PortDirection::kOutput, true); 569 0, 1, "0:1", MidiManagerAlsa::AlsaSeqState::PortDirection::kOutput, true);
559 EXPECT_EQ(3, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 570 EXPECT_EQ(3,
571 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
560 572
561 // Add another client. Still at 3. 573 // Add another client. Still at 3.
562 alsa_seq_state_0_.ClientStart(1, "1", SND_SEQ_KERNEL_CLIENT); 574 alsa_seq_state_0_.ClientStart(1, "1", SND_SEQ_KERNEL_CLIENT);
563 EXPECT_EQ(3, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 575 EXPECT_EQ(3,
576 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
564 577
565 // Add a port. Now at 4. 578 // Add a port. Now at 4.
566 alsa_seq_state_0_.PortStart( 579 alsa_seq_state_0_.PortStart(
567 1, 0, "1:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kInput, true); 580 1, 0, "1:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kInput, true);
568 EXPECT_EQ(4, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 581 EXPECT_EQ(4,
582 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
569 583
570 // Add a duplicate port. Still at 4. 584 // Add a duplicate port. Still at 4.
571 alsa_seq_state_0_.PortStart( 585 alsa_seq_state_0_.PortStart(
572 1, 0, "1:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kInput, true); 586 1, 0, "1:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kInput, true);
573 EXPECT_EQ(4, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 587 EXPECT_EQ(4,
588 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
574 589
575 // Add a duplicate client. This will close the ports from the previous client. 590 // Add a duplicate client. This will close the ports from the previous client.
576 alsa_seq_state_0_.ClientStart(1, "1", SND_SEQ_KERNEL_CLIENT); 591 alsa_seq_state_0_.ClientStart(1, "1", SND_SEQ_KERNEL_CLIENT);
577 EXPECT_EQ(3, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 592 EXPECT_EQ(3,
593 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
578 594
579 // Remove a duplex port. This reduces count by 2. 595 // Remove a duplex port. This reduces count by 2.
580 alsa_seq_state_0_.PortExit(0, 0); 596 alsa_seq_state_0_.PortExit(0, 0);
581 EXPECT_EQ(1, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 597 EXPECT_EQ(1,
598 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
582 599
583 // Remove a non-existent port. No change. 600 // Remove a non-existent port. No change.
584 alsa_seq_state_0_.PortExit(0, 0); 601 alsa_seq_state_0_.PortExit(0, 0);
585 EXPECT_EQ(1, CountPorts(*alsa_seq_state_0_.ToMidiPortState().get())); 602 EXPECT_EQ(1,
603 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get()));
586 604
587 // Verify the last entry. 605 // Verify the last entry.
588 EXPECT_TRUE((*alsa_seq_state_0_.ToMidiPortState()->begin()) 606 EXPECT_TRUE((*alsa_seq_state_0_.ToMidiPortState(alsa_cards_)->begin())
589 ->MatchConnected(MidiManagerAlsa::MidiPort( 607 ->MatchConnected(MidiManagerAlsa::MidiPort(
590 "", "", 0, 1, -1, "0", "0:1", "", "", 608 "", "", 0, 1, -1, "0", "0:1", "", "",
591 MidiManagerAlsa::MidiPort::Type::kOutput))); 609 MidiManagerAlsa::MidiPort::Type::kOutput)));
592 } 610 }
593 611
612 // Tests kernel_client_count of AlsaSeqState.
613 TEST_F(MidiManagerAlsaTest, KernelClientCount) {
614 EXPECT_EQ(0, alsa_seq_state_0_.kernel_client_count());
615
616 // Add a kernel client.
617 alsa_seq_state_0_.ClientStart(16, "16", SND_SEQ_KERNEL_CLIENT);
618 EXPECT_EQ(1, alsa_seq_state_0_.kernel_client_count());
619
620 // Add a duplicate kernel client.
621 alsa_seq_state_0_.ClientStart(16, "16", SND_SEQ_KERNEL_CLIENT);
622 EXPECT_EQ(1, alsa_seq_state_0_.kernel_client_count());
623
624 // Add a duplicate user client.
625 alsa_seq_state_0_.ClientStart(16, "16", SND_SEQ_USER_CLIENT);
626 EXPECT_EQ(0, alsa_seq_state_0_.kernel_client_count());
627
628 // Add 2 more kernel clients.
629 alsa_seq_state_0_.ClientStart(17, "17", SND_SEQ_KERNEL_CLIENT);
630 alsa_seq_state_0_.ClientStart(18, "18", SND_SEQ_KERNEL_CLIENT);
631 EXPECT_EQ(2, alsa_seq_state_0_.kernel_client_count());
632
633 // Add another user client.
634 alsa_seq_state_0_.ClientStart(101, "101", SND_SEQ_USER_CLIENT);
635 EXPECT_EQ(2, alsa_seq_state_0_.kernel_client_count());
636
637 // Remove kernel client.
638 alsa_seq_state_0_.ClientExit(17);
639 EXPECT_EQ(1, alsa_seq_state_0_.kernel_client_count());
640
641 // Remove user client.
642 alsa_seq_state_0_.ClientExit(16);
643 EXPECT_EQ(1, alsa_seq_state_0_.kernel_client_count());
644
645 // Remove kernel client.
646 alsa_seq_state_0_.ClientExit(18);
647 EXPECT_EQ(0, alsa_seq_state_0_.kernel_client_count());
648
649 // Add a duplicate kernel client.
650 alsa_seq_state_0_.ClientStart(101, "101", SND_SEQ_KERNEL_CLIENT);
651 EXPECT_EQ(1, alsa_seq_state_0_.kernel_client_count());
652
653 // Add a low kernel client.
654 alsa_seq_state_0_.ClientStart(1, "1", SND_SEQ_KERNEL_CLIENT);
655 EXPECT_EQ(1, alsa_seq_state_0_.kernel_client_count());
656
657 // Remove low kernel client.
658 alsa_seq_state_0_.ClientExit(1);
659 EXPECT_EQ(1, alsa_seq_state_0_.kernel_client_count());
660 }
661
662 TEST_F(MidiManagerAlsaTest, AlsaCards) {
663 // TODO(agoode): test add/remove of alsa cards.
664 }
665
594 // TODO(agoode): Test old -> new state event generation, using mocks. 666 // TODO(agoode): Test old -> new state event generation, using mocks.
595 667
596 } // namespace midi 668 } // namespace midi
597 } // namespace media 669 } // namespace media
OLDNEW
« media/midi/midi_manager_alsa.cc ('K') | « media/midi/midi_manager_alsa.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698