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 "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 { |
11 | 11 |
12 class MidiManagerAlsaTest : public ::testing::Test { | 12 class MidiManagerAlsaTest : public ::testing::Test { |
13 protected: | 13 protected: |
14 void SetUp() override { | 14 void SetUp() override { |
15 // Pre-instantiate typical MidiPort instances that are often used in | 15 // Pre-instantiate typical MidiPort instances that are often used in |
16 // following tests. | 16 // following tests. |
17 | 17 |
18 // Inputs. port_input_0_ == port_input_1_. | 18 // Inputs. port_input_0_ == port_input_1_. |
19 port_input_0_.reset(new MidiManagerAlsa::MidiPort( | 19 port_input_0_.reset(new MidiManagerAlsa::MidiPort( |
20 "path", "id", 1, 2, 5, "client_name", "port_name", "manufacturer", | 20 "path", MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", |
21 "version", MidiManagerAlsa::MidiPort::Type::kInput)); | 21 "interface", "serial"), |
| 22 1, 2, 5, "client_name", "port_name", "manufacturer", "version", |
| 23 MidiManagerAlsa::MidiPort::Type::kInput)); |
22 port_input_1_.reset(new MidiManagerAlsa::MidiPort( | 24 port_input_1_.reset(new MidiManagerAlsa::MidiPort( |
23 "path", "id", 1, 2, 5, "client_name", "port_name", "manufacturer", | 25 "path", MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", |
24 "version", MidiManagerAlsa::MidiPort::Type::kInput)); | 26 "interface", "serial"), |
25 port_input_minimal_.reset( | 27 1, 2, 5, "client_name", "port_name", "manufacturer", "version", |
26 new MidiManagerAlsa::MidiPort("", "", 0, 0, 0, "", "", "", "", | 28 MidiManagerAlsa::MidiPort::Type::kInput)); |
27 MidiManagerAlsa::MidiPort::Type::kInput)); | 29 port_input_minimal_.reset(new MidiManagerAlsa::MidiPort( |
| 30 "", MidiManagerAlsa::MidiPort::Id(), 0, 0, 0, "", "", "", "", |
| 31 MidiManagerAlsa::MidiPort::Type::kInput)); |
28 // Outputs. port_output_0_ == port_output_1_. | 32 // Outputs. port_output_0_ == port_output_1_. |
29 port_output_0_.reset(new MidiManagerAlsa::MidiPort( | 33 port_output_0_.reset(new MidiManagerAlsa::MidiPort( |
30 "path", "id", 1, 2, 5, "client_name", "port_name", "manufacturer", | 34 "path", MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", |
31 "version", MidiManagerAlsa::MidiPort::Type::kOutput)); | 35 "interface", "serial"), |
| 36 1, 2, 5, "client_name", "port_name", "manufacturer", "version", |
| 37 MidiManagerAlsa::MidiPort::Type::kOutput)); |
32 port_output_1_.reset(new MidiManagerAlsa::MidiPort( | 38 port_output_1_.reset(new MidiManagerAlsa::MidiPort( |
33 "path", "id", 1, 2, 5, "client_name", "port_name", "manufacturer", | 39 "path", MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", |
34 "version", MidiManagerAlsa::MidiPort::Type::kOutput)); | 40 "interface", "serial"), |
| 41 1, 2, 5, "client_name", "port_name", "manufacturer", "version", |
| 42 MidiManagerAlsa::MidiPort::Type::kOutput)); |
35 | 43 |
36 // MidiPort fields that differ from port_input_0_ in a single way each time. | 44 // MidiPort fields that differ from port_input_0_ in a single way each time. |
37 // Used for testing the Match* and Find* methods. | 45 // Used for testing the Match* and Find* methods. |
38 port_input_0_alt_path_.reset(new MidiManagerAlsa::MidiPort( | 46 port_input_0_alt_path_.reset(new MidiManagerAlsa::MidiPort( |
39 "path2", "id", 1, 2, 5, "client_name", "port_name", "manufacturer", | 47 "path2", MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", |
40 "version", MidiManagerAlsa::MidiPort::Type::kInput)); | 48 "interface", "serial"), |
| 49 1, 2, 5, "client_name", "port_name", "manufacturer", "version", |
| 50 MidiManagerAlsa::MidiPort::Type::kInput)); |
41 port_input_0_alt_id_.reset(new MidiManagerAlsa::MidiPort( | 51 port_input_0_alt_id_.reset(new MidiManagerAlsa::MidiPort( |
42 "path", "id2", 1, 2, 5, "client_name", "port_name", "manufacturer", | 52 "path", MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", |
43 "version", MidiManagerAlsa::MidiPort::Type::kInput)); | 53 "interface", "serial2"), |
| 54 1, 2, 5, "client_name", "port_name", "manufacturer", "version", |
| 55 MidiManagerAlsa::MidiPort::Type::kInput)); |
44 port_input_0_alt_client_name_.reset(new MidiManagerAlsa::MidiPort( | 56 port_input_0_alt_client_name_.reset(new MidiManagerAlsa::MidiPort( |
45 "path", "id", 1, 2, 5, "client_name2", "port_name", "manufacturer", | 57 "path", MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", |
46 "version", MidiManagerAlsa::MidiPort::Type::kInput)); | 58 "interface", "serial"), |
| 59 1, 2, 5, "client_name2", "port_name", "manufacturer", "version", |
| 60 MidiManagerAlsa::MidiPort::Type::kInput)); |
47 port_input_0_alt_port_name_.reset(new MidiManagerAlsa::MidiPort( | 61 port_input_0_alt_port_name_.reset(new MidiManagerAlsa::MidiPort( |
48 "path", "id", 1, 2, 5, "client_name", "port_name2", "manufacturer", | 62 "path", MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", |
49 "version", MidiManagerAlsa::MidiPort::Type::kInput)); | 63 "interface", "serial"), |
| 64 1, 2, 5, "client_name", "port_name2", "manufacturer", "version", |
| 65 MidiManagerAlsa::MidiPort::Type::kInput)); |
50 port_input_0_alt_client_id_.reset(new MidiManagerAlsa::MidiPort( | 66 port_input_0_alt_client_id_.reset(new MidiManagerAlsa::MidiPort( |
51 "path", "id", 2, 2, 5, "client_name", "port_name", "manufacturer", | 67 "path", MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", |
52 "version", MidiManagerAlsa::MidiPort::Type::kInput)); | 68 "interface", "serial"), |
| 69 2, 2, 5, "client_name", "port_name", "manufacturer", "version", |
| 70 MidiManagerAlsa::MidiPort::Type::kInput)); |
53 port_input_0_alt_port_id_.reset(new MidiManagerAlsa::MidiPort( | 71 port_input_0_alt_port_id_.reset(new MidiManagerAlsa::MidiPort( |
54 "path", "id", 1, 3, 5, "client_name", "port_name", "manufacturer", | 72 "path", MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", |
55 "version", MidiManagerAlsa::MidiPort::Type::kInput)); | 73 "interface", "serial"), |
| 74 1, 3, 5, "client_name", "port_name", "manufacturer", "version", |
| 75 MidiManagerAlsa::MidiPort::Type::kInput)); |
56 port_input_0_alt_midi_device_.reset(new MidiManagerAlsa::MidiPort( | 76 port_input_0_alt_midi_device_.reset(new MidiManagerAlsa::MidiPort( |
57 "path", "id", 1, 2, 6, "client_name", "port_name", "manufacturer", | 77 "path", MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", |
58 "version", MidiManagerAlsa::MidiPort::Type::kInput)); | 78 "interface", "serial"), |
| 79 1, 2, 6, "client_name", "port_name", "manufacturer", "version", |
| 80 MidiManagerAlsa::MidiPort::Type::kInput)); |
59 | 81 |
60 // "No card" variants of above. For testing FindDisconnected. | 82 // "No card" variants of above. For testing FindDisconnected. |
61 port_input_0_no_card_.reset(new MidiManagerAlsa::MidiPort( | 83 port_input_0_no_card_.reset(new MidiManagerAlsa::MidiPort( |
62 "", "", 1, 2, -1, "client_name", "port_name", "manufacturer", "version", | 84 "", MidiManagerAlsa::MidiPort::Id(), 1, 2, -1, "client_name", |
| 85 "port_name", "manufacturer", "version", |
63 MidiManagerAlsa::MidiPort::Type::kInput)); | 86 MidiManagerAlsa::MidiPort::Type::kInput)); |
64 port_input_1_no_card_.reset(new MidiManagerAlsa::MidiPort( | 87 port_input_1_no_card_.reset(new MidiManagerAlsa::MidiPort( |
65 "", "", 1, 2, -1, "client_name", "port_name", "manufacturer", "version", | 88 "", MidiManagerAlsa::MidiPort::Id(), 1, 2, -1, "client_name", |
| 89 "port_name", "manufacturer", "version", |
66 MidiManagerAlsa::MidiPort::Type::kInput)); | 90 MidiManagerAlsa::MidiPort::Type::kInput)); |
67 port_output_0_no_card_.reset(new MidiManagerAlsa::MidiPort( | 91 port_output_0_no_card_.reset(new MidiManagerAlsa::MidiPort( |
68 "", "", 1, 2, -1, "client_name", "port_name", "manufacturer", "version", | 92 "", MidiManagerAlsa::MidiPort::Id(), 1, 2, -1, "client_name", |
| 93 "port_name", "manufacturer", "version", |
69 MidiManagerAlsa::MidiPort::Type::kOutput)); | 94 MidiManagerAlsa::MidiPort::Type::kOutput)); |
70 | 95 |
71 // No card variants of the alt variants from above. For more testing | 96 // No card variants of the alt variants from above. For more testing |
72 // of Match* and Find*. | 97 // of Match* and Find*. |
73 port_input_0_no_card_alt_client_name_.reset(new MidiManagerAlsa::MidiPort( | 98 port_input_0_no_card_alt_client_name_.reset(new MidiManagerAlsa::MidiPort( |
74 "", "", 1, 2, -1, "client_name2", "port_name", "manufacturer", | 99 "", MidiManagerAlsa::MidiPort::Id(), 1, 2, -1, "client_name2", |
75 "version", MidiManagerAlsa::MidiPort::Type::kInput)); | 100 "port_name", "manufacturer", "version", |
| 101 MidiManagerAlsa::MidiPort::Type::kInput)); |
76 port_input_0_no_card_alt_port_name_.reset(new MidiManagerAlsa::MidiPort( | 102 port_input_0_no_card_alt_port_name_.reset(new MidiManagerAlsa::MidiPort( |
77 "", "", 1, 2, -1, "client_name", "port_name2", "manufacturer", | 103 "", MidiManagerAlsa::MidiPort::Id(), 1, 2, -1, "client_name", |
78 "version", MidiManagerAlsa::MidiPort::Type::kInput)); | 104 "port_name2", "manufacturer", "version", |
| 105 MidiManagerAlsa::MidiPort::Type::kInput)); |
79 port_input_0_no_card_alt_client_id_.reset(new MidiManagerAlsa::MidiPort( | 106 port_input_0_no_card_alt_client_id_.reset(new MidiManagerAlsa::MidiPort( |
80 "", "", 2, 2, -1, "client_name", "port_name", "manufacturer", "version", | 107 "", MidiManagerAlsa::MidiPort::Id(), 2, 2, -1, "client_name", |
| 108 "port_name", "manufacturer", "version", |
81 MidiManagerAlsa::MidiPort::Type::kInput)); | 109 MidiManagerAlsa::MidiPort::Type::kInput)); |
82 port_input_0_no_card_alt_port_id_.reset(new MidiManagerAlsa::MidiPort( | 110 port_input_0_no_card_alt_port_id_.reset(new MidiManagerAlsa::MidiPort( |
83 "", "", 1, 3, -1, "client_name", "port_name", "manufacturer", "version", | 111 "", MidiManagerAlsa::MidiPort::Id(), 1, 3, -1, "client_name", |
| 112 "port_name", "manufacturer", "version", |
84 MidiManagerAlsa::MidiPort::Type::kInput)); | 113 MidiManagerAlsa::MidiPort::Type::kInput)); |
85 } | 114 } |
86 | 115 |
87 // Counts ports for help with testing ToMidiPortState(). | 116 // Counts ports for help with testing ToMidiPortState(). |
88 int CountPorts(MidiManagerAlsa::TemporaryMidiPortState& state) { | 117 int CountPorts(MidiManagerAlsa::TemporaryMidiPortState& state) { |
89 int count = 0; | 118 int count = 0; |
90 for (auto it = state.begin(); it != state.end(); ++it) | 119 for (auto it = state.begin(); it != state.end(); ++it) |
91 ++count; | 120 ++count; |
92 return count; | 121 return count; |
93 } | 122 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 EXPECT_EQ("C-Media Electronics Inc", | 202 EXPECT_EQ("C-Media Electronics Inc", |
174 MidiManagerAlsa::AlsaCard::ExtractManufacturerString( | 203 MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
175 "", "0x13f6", "C-Media Electronics Inc", "C-Media CMI8738 FM", | 204 "", "0x13f6", "C-Media Electronics Inc", "C-Media CMI8738 FM", |
176 "C-Media CMI8738 (model 55) at 0xd000, irq 19")); | 205 "C-Media CMI8738 (model 55) at 0xd000, irq 19")); |
177 } | 206 } |
178 | 207 |
179 // Tests that verify proper serialization and generation of opaque key for | 208 // Tests that verify proper serialization and generation of opaque key for |
180 // MidiPort. | 209 // MidiPort. |
181 TEST_F(MidiManagerAlsaTest, JSONPortMetadata) { | 210 TEST_F(MidiManagerAlsaTest, JSONPortMetadata) { |
182 EXPECT_EQ( | 211 EXPECT_EQ( |
183 "{\"clientId\":1,\"clientName\":\"client_name\",\"id\":\"id\"," | 212 "{\"bus\":\"bus\",\"clientId\":1,\"clientName\":\"client_name\"," |
184 "\"midiDevice\":5,\"path\":\"path\",\"portId\":2,\"portName\":\"port_" | 213 "\"midiDevice\":5,\"modelId\":\"model\",\"path\":\"path\",\"portId\":2," |
185 "name\",\"type\":\"input\"}", | 214 "\"portName\":\"port_name\",\"serial\":\"serial\",\"type\":\"input\"," |
| 215 "\"usbInterfaceNum\":\"interface\",\"vendorId\":\"vendor\"}", |
186 port_input_0_->JSONValue()); | 216 port_input_0_->JSONValue()); |
187 | 217 |
188 EXPECT_EQ("03F255B7EE4D9D061597289CB16B45F997DBDB20D8E44429B052019C84E20A4A", | 218 EXPECT_EQ("810194DAF713B32FC9BE40EC822E21682635B48C242D09EA95DBA4A184A95877", |
189 port_input_0_->OpaqueKey()); | 219 port_input_0_->OpaqueKey()); |
190 | 220 |
191 EXPECT_EQ( | 221 EXPECT_EQ( |
192 "{\"clientId\":1,\"clientName\":\"client_name\",\"id\":\"id\"," | 222 "{\"bus\":\"bus\",\"clientId\":1,\"clientName\":\"client_name\"," |
193 "\"midiDevice\":5,\"path\":\"path\",\"portId\":2,\"portName\":\"port_" | 223 "\"midiDevice\":5,\"modelId\":\"model\",\"path\":\"path\",\"portId\":2," |
194 "name\",\"type\":\"output\"}", | 224 "\"portName\":\"port_name\",\"serial\":\"serial\",\"type\":\"output\"," |
| 225 "\"usbInterfaceNum\":\"interface\",\"vendorId\":\"vendor\"}", |
195 port_output_0_->JSONValue()); | 226 port_output_0_->JSONValue()); |
196 EXPECT_EQ("3A3380FD64B8C79900C052D64C3F52E9ECD6537D00ECB02B8FA30032C0C03924", | 227 EXPECT_EQ("C32552FC772A0CA453A675CED05EFB3BDEF749EB58ED9522475206F111BC01E2", |
197 port_output_0_->OpaqueKey()); | 228 port_output_0_->OpaqueKey()); |
198 | 229 |
199 EXPECT_EQ("{\"clientId\":0,\"midiDevice\":0,\"portId\":0,\"type\":\"input\"}", | 230 EXPECT_EQ("{\"clientId\":0,\"midiDevice\":0,\"portId\":0,\"type\":\"input\"}", |
200 port_input_minimal_->JSONValue()); | 231 port_input_minimal_->JSONValue()); |
201 EXPECT_EQ("3BC2A85598E5026D01DBCB022016C8A3362A9C7F912B88E303BF619C56D0C111", | 232 EXPECT_EQ("3BC2A85598E5026D01DBCB022016C8A3362A9C7F912B88E303BF619C56D0C111", |
202 port_input_minimal_->OpaqueKey()); | 233 port_input_minimal_->OpaqueKey()); |
203 } | 234 } |
204 | 235 |
205 // Tests Match* methods. | 236 // Tests Match* methods. |
206 TEST_F(MidiManagerAlsaTest, MatchConnected) { | 237 TEST_F(MidiManagerAlsaTest, MatchConnected) { |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); | 629 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
599 | 630 |
600 // Remove a non-existent port. No change. | 631 // Remove a non-existent port. No change. |
601 alsa_seq_state_0_.PortExit(0, 0); | 632 alsa_seq_state_0_.PortExit(0, 0); |
602 EXPECT_EQ(1, | 633 EXPECT_EQ(1, |
603 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); | 634 CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
604 | 635 |
605 // Verify the last entry. | 636 // Verify the last entry. |
606 EXPECT_TRUE((*alsa_seq_state_0_.ToMidiPortState(alsa_cards_)->begin()) | 637 EXPECT_TRUE((*alsa_seq_state_0_.ToMidiPortState(alsa_cards_)->begin()) |
607 ->MatchConnected(MidiManagerAlsa::MidiPort( | 638 ->MatchConnected(MidiManagerAlsa::MidiPort( |
608 "", "", 0, 1, -1, "0", "0:1", "", "", | 639 "", MidiManagerAlsa::MidiPort::Id(), 0, 1, -1, "0", "0:1", |
609 MidiManagerAlsa::MidiPort::Type::kOutput))); | 640 "", "", MidiManagerAlsa::MidiPort::Type::kOutput))); |
610 } | 641 } |
611 | 642 |
612 // Tests card_client_count of AlsaSeqState. | 643 // Tests card_client_count of AlsaSeqState. |
613 TEST_F(MidiManagerAlsaTest, CardClientCount) { | 644 TEST_F(MidiManagerAlsaTest, CardClientCount) { |
614 EXPECT_EQ(0, alsa_seq_state_0_.card_client_count()); | 645 EXPECT_EQ(0, alsa_seq_state_0_.card_client_count()); |
615 | 646 |
616 // Add a kernel client. | 647 // Add a kernel client. |
617 alsa_seq_state_0_.ClientStart(16, "16", SND_SEQ_KERNEL_CLIENT); | 648 alsa_seq_state_0_.ClientStart(16, "16", SND_SEQ_KERNEL_CLIENT); |
618 EXPECT_EQ(1, alsa_seq_state_0_.card_client_count()); | 649 EXPECT_EQ(1, alsa_seq_state_0_.card_client_count()); |
619 | 650 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 } | 691 } |
661 | 692 |
662 TEST_F(MidiManagerAlsaTest, AlsaCards) { | 693 TEST_F(MidiManagerAlsaTest, AlsaCards) { |
663 // TODO(agoode): test add/remove of alsa cards. | 694 // TODO(agoode): test add/remove of alsa cards. |
664 } | 695 } |
665 | 696 |
666 // TODO(agoode): Test old -> new state event generation, using mocks. | 697 // TODO(agoode): Test old -> new state event generation, using mocks. |
667 | 698 |
668 } // namespace midi | 699 } // namespace midi |
669 } // namespace media | 700 } // namespace media |
OLD | NEW |