agoode | 55a8b52 | 2015-03-08 12:40:17 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "media/midi/midi_manager_alsa.h" |
| 6 | |
danakj | 75afea0 | 2016-04-25 20:36:04 -0700 | [diff] [blame] | 7 | #include <memory> |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 8 | #include <utility> |
| 9 | |
agoode | 55a8b52 | 2015-03-08 12:40:17 -0700 | [diff] [blame] | 10 | #include "testing/gtest/include/gtest/gtest.h" |
| 11 | |
toyoshim | e147c5e | 2015-05-07 21:58:31 -0700 | [diff] [blame] | 12 | namespace midi { |
agoode | 55a8b52 | 2015-03-08 12:40:17 -0700 | [diff] [blame] | 13 | |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 14 | class MidiManagerAlsaTest : public ::testing::Test { |
| 15 | protected: |
| 16 | void SetUp() override { |
| 17 | // Pre-instantiate typical MidiPort instances that are often used in |
| 18 | // following tests. |
| 19 | |
| 20 | // Inputs. port_input_0_ == port_input_1_. |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 21 | port_input_0_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
| 22 | "path", |
| 23 | MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", "interface", |
| 24 | "serial"), |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 25 | 1, 2, 5, "client_name", "port_name", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 26 | MidiManagerAlsa::MidiPort::Type::kInput); |
| 27 | port_input_1_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
| 28 | "path", |
| 29 | MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", "interface", |
| 30 | "serial"), |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 31 | 1, 2, 5, "client_name", "port_name", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 32 | MidiManagerAlsa::MidiPort::Type::kInput); |
| 33 | port_input_minimal_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 34 | "", MidiManagerAlsa::MidiPort::Id(), 0, 0, 0, "", "", "", "", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 35 | MidiManagerAlsa::MidiPort::Type::kInput); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 36 | // Outputs. port_output_0_ == port_output_1_. |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 37 | port_output_0_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
| 38 | "path", |
| 39 | MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", "interface", |
| 40 | "serial"), |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 41 | 1, 2, 5, "client_name", "port_name", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 42 | MidiManagerAlsa::MidiPort::Type::kOutput); |
| 43 | port_output_1_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
| 44 | "path", |
| 45 | MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", "interface", |
| 46 | "serial"), |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 47 | 1, 2, 5, "client_name", "port_name", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 48 | MidiManagerAlsa::MidiPort::Type::kOutput); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 49 | |
| 50 | // MidiPort fields that differ from port_input_0_ in a single way each time. |
| 51 | // Used for testing the Match* and Find* methods. |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 52 | port_input_0_alt_path_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
| 53 | "path2", |
| 54 | MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", "interface", |
| 55 | "serial"), |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 56 | 1, 2, 5, "client_name", "port_name", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 57 | MidiManagerAlsa::MidiPort::Type::kInput); |
| 58 | port_input_0_alt_id_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
| 59 | "path", |
| 60 | MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", "interface", |
| 61 | "serial2"), |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 62 | 1, 2, 5, "client_name", "port_name", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 63 | MidiManagerAlsa::MidiPort::Type::kInput); |
| 64 | port_input_0_alt_client_name_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
| 65 | "path", |
| 66 | MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", "interface", |
| 67 | "serial"), |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 68 | 1, 2, 5, "client_name2", "port_name", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 69 | MidiManagerAlsa::MidiPort::Type::kInput); |
| 70 | port_input_0_alt_port_name_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
| 71 | "path", |
| 72 | MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", "interface", |
| 73 | "serial"), |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 74 | 1, 2, 5, "client_name", "port_name2", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 75 | MidiManagerAlsa::MidiPort::Type::kInput); |
| 76 | port_input_0_alt_client_id_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
| 77 | "path", |
| 78 | MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", "interface", |
| 79 | "serial"), |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 80 | 2, 2, 5, "client_name", "port_name", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 81 | MidiManagerAlsa::MidiPort::Type::kInput); |
| 82 | port_input_0_alt_port_id_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
| 83 | "path", |
| 84 | MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", "interface", |
| 85 | "serial"), |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 86 | 1, 3, 5, "client_name", "port_name", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 87 | MidiManagerAlsa::MidiPort::Type::kInput); |
| 88 | port_input_0_alt_midi_device_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
| 89 | "path", |
| 90 | MidiManagerAlsa::MidiPort::Id("bus", "vendor", "model", "interface", |
| 91 | "serial"), |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 92 | 1, 2, 6, "client_name", "port_name", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 93 | MidiManagerAlsa::MidiPort::Type::kInput); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 94 | |
| 95 | // "No card" variants of above. For testing FindDisconnected. |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 96 | port_input_0_no_card_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 97 | "", MidiManagerAlsa::MidiPort::Id(), 1, 2, -1, "client_name", |
| 98 | "port_name", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 99 | MidiManagerAlsa::MidiPort::Type::kInput); |
| 100 | port_input_1_no_card_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 101 | "", MidiManagerAlsa::MidiPort::Id(), 1, 2, -1, "client_name", |
| 102 | "port_name", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 103 | MidiManagerAlsa::MidiPort::Type::kInput); |
| 104 | port_output_0_no_card_ = std::make_unique<MidiManagerAlsa::MidiPort>( |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 105 | "", MidiManagerAlsa::MidiPort::Id(), 1, 2, -1, "client_name", |
| 106 | "port_name", "manufacturer", "version", |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 107 | MidiManagerAlsa::MidiPort::Type::kOutput); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 108 | |
| 109 | // No card variants of the alt variants from above. For more testing |
| 110 | // of Match* and Find*. |
Peter Boström | 6cdc752 | 2021-04-15 03:53:08 +0000 | [diff] [blame] | 111 | port_input_0_no_card_alt_client_name_ = |
| 112 | std::make_unique<MidiManagerAlsa::MidiPort>( |
| 113 | "", MidiManagerAlsa::MidiPort::Id(), 1, 2, -1, "client_name2", |
| 114 | "port_name", "manufacturer", "version", |
| 115 | MidiManagerAlsa::MidiPort::Type::kInput); |
| 116 | port_input_0_no_card_alt_port_name_ = |
| 117 | std::make_unique<MidiManagerAlsa::MidiPort>( |
| 118 | "", MidiManagerAlsa::MidiPort::Id(), 1, 2, -1, "client_name", |
| 119 | "port_name2", "manufacturer", "version", |
| 120 | MidiManagerAlsa::MidiPort::Type::kInput); |
| 121 | port_input_0_no_card_alt_client_id_ = |
| 122 | std::make_unique<MidiManagerAlsa::MidiPort>( |
| 123 | "", MidiManagerAlsa::MidiPort::Id(), 2, 2, -1, "client_name", |
| 124 | "port_name", "manufacturer", "version", |
| 125 | MidiManagerAlsa::MidiPort::Type::kInput); |
| 126 | port_input_0_no_card_alt_port_id_ = |
| 127 | std::make_unique<MidiManagerAlsa::MidiPort>( |
| 128 | "", MidiManagerAlsa::MidiPort::Id(), 1, 3, -1, "client_name", |
| 129 | "port_name", "manufacturer", "version", |
| 130 | MidiManagerAlsa::MidiPort::Type::kInput); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | // Counts ports for help with testing ToMidiPortState(). |
| 134 | int CountPorts(MidiManagerAlsa::TemporaryMidiPortState& state) { |
| 135 | int count = 0; |
| 136 | for (auto it = state.begin(); it != state.end(); ++it) |
| 137 | ++count; |
| 138 | return count; |
| 139 | } |
| 140 | |
danakj | 75afea0 | 2016-04-25 20:36:04 -0700 | [diff] [blame] | 141 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_input_0_; |
| 142 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_input_1_; |
| 143 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_input_minimal_; |
| 144 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_output_0_; |
| 145 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_output_1_; |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 146 | |
danakj | 75afea0 | 2016-04-25 20:36:04 -0700 | [diff] [blame] | 147 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_input_0_alt_path_; |
| 148 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_input_0_alt_id_; |
| 149 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_input_0_alt_client_name_; |
| 150 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_input_0_alt_port_name_; |
| 151 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_input_0_alt_client_id_; |
| 152 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_input_0_alt_port_id_; |
| 153 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_input_0_alt_midi_device_; |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 154 | |
danakj | 75afea0 | 2016-04-25 20:36:04 -0700 | [diff] [blame] | 155 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_input_0_no_card_; |
| 156 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_input_1_no_card_; |
| 157 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_output_0_no_card_; |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 158 | |
danakj | 75afea0 | 2016-04-25 20:36:04 -0700 | [diff] [blame] | 159 | std::unique_ptr<MidiManagerAlsa::MidiPort> |
| 160 | port_input_0_no_card_alt_client_name_; |
| 161 | std::unique_ptr<MidiManagerAlsa::MidiPort> |
| 162 | port_input_0_no_card_alt_port_name_; |
| 163 | std::unique_ptr<MidiManagerAlsa::MidiPort> |
| 164 | port_input_0_no_card_alt_client_id_; |
| 165 | std::unique_ptr<MidiManagerAlsa::MidiPort> port_input_0_no_card_alt_port_id_; |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 166 | |
| 167 | // State fields to avoid declaring in test fixtures below. |
| 168 | MidiManagerAlsa::MidiPortState midi_port_state_0_; |
| 169 | MidiManagerAlsa::MidiPortState midi_port_state_1_; |
| 170 | MidiManagerAlsa::TemporaryMidiPortState temporary_midi_port_state_0_; |
| 171 | MidiManagerAlsa::AlsaSeqState alsa_seq_state_0_; |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 172 | MidiManagerAlsa::AlsaCardMap alsa_cards_; |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | // Tests that ExtractManufacturerString works as expected. |
| 176 | TEST_F(MidiManagerAlsaTest, ExtractManufacturer) { |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 177 | EXPECT_EQ("My\\x20Vendor", |
| 178 | MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
| 179 | "My\\x20Vendor", "1234", "My Vendor, Inc.", "Card", |
| 180 | "My Vendor Inc Card at bus")); |
| 181 | EXPECT_EQ("My Vendor", MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
agoode | af6e9f5 | 2015-03-24 10:23:49 -0700 | [diff] [blame] | 182 | "My Vendor", "1234", "My Vendor, Inc.", "Card", |
| 183 | "My Vendor Inc Card at bus")); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 184 | EXPECT_EQ("My Vendor, Inc.", |
| 185 | MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
| 186 | "1234", "1234", "My Vendor, Inc.", "Card", |
| 187 | "My Vendor Inc Card at bus")); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 188 | EXPECT_EQ("My Vendor Inc", |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 189 | MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
agoode | bd4be9b | 2015-03-16 19:17:25 -0700 | [diff] [blame] | 190 | "1234", "1234", "", "Card", "My Vendor Inc Card at bus")); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 191 | EXPECT_EQ("My Vendor Inc", |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 192 | MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
agoode | bd4be9b | 2015-03-16 19:17:25 -0700 | [diff] [blame] | 193 | "", "", "", "Card", "My Vendor Inc Card at bus")); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 194 | EXPECT_EQ("", MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
| 195 | "1234", "1234", "", "Card", "Longname")); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 196 | EXPECT_EQ("Keystation\\x20Mini\\x2032", |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 197 | MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
agoode | bd4be9b | 2015-03-16 19:17:25 -0700 | [diff] [blame] | 198 | "Keystation\\x20Mini\\x2032", "129d", |
| 199 | "Evolution Electronics, Ltd", "Keystation Mini 32", |
| 200 | "Keystation Mini 32 Keystation Mini 32 at" |
| 201 | " usb-0000:00:14.0-2.4.4, full speed")); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 202 | EXPECT_EQ("Keystation Mini 32", |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 203 | MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
agoode | bd4be9b | 2015-03-16 19:17:25 -0700 | [diff] [blame] | 204 | "Keystation Mini 32", "129d", "Evolution Electronics, Ltd", |
agoode | 55a8b52 | 2015-03-08 12:40:17 -0700 | [diff] [blame] | 205 | "Keystation Mini 32", |
| 206 | "Keystation Mini 32 Keystation Mini 32 at" |
| 207 | " usb-0000:00:14.0-2.4.4, full speed")); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 208 | EXPECT_EQ("Keystation Mini 32", |
| 209 | MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
| 210 | "", "", "", "Keystation Mini 32", |
| 211 | "Keystation Mini 32 Keystation Mini 32 at" |
| 212 | " usb-0000:00:14.0-2.4.4, full speed")); |
| 213 | EXPECT_EQ("", MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
agoode | f212b2a | 2015-03-19 12:53:23 -0700 | [diff] [blame] | 214 | "", "", "", "Serial MIDI (UART16550A)", |
| 215 | "Serial MIDI (UART16550A) [Soundcanvas] at 0x3f8, irq 4")); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 216 | EXPECT_EQ("", MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
agoode | f212b2a | 2015-03-19 12:53:23 -0700 | [diff] [blame] | 217 | "", "", "", "VirMIDI", "Virtual MIDI Card 1")); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 218 | EXPECT_EQ("C-Media Electronics Inc", |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 219 | MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
agoode | e83758c | 2015-03-23 22:07:54 -0700 | [diff] [blame] | 220 | "", "0x13f6", "C-Media Electronics Inc", "C-Media CMI8738 MIDI", |
| 221 | "C-Media CMI8738 (model 55) at 0xd000, irq 19")); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 222 | EXPECT_EQ("C-Media Electronics Inc", |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 223 | MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
agoode | e83758c | 2015-03-23 22:07:54 -0700 | [diff] [blame] | 224 | "", "0x13f6", "C-Media Electronics Inc", "C-Media CMI8738 FM", |
| 225 | "C-Media CMI8738 (model 55) at 0xd000, irq 19")); |
agoode | f212b2a | 2015-03-19 12:53:23 -0700 | [diff] [blame] | 226 | } |
| 227 | |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 228 | // Tests that verify proper serialization and generation of opaque key for |
| 229 | // MidiPort. |
| 230 | TEST_F(MidiManagerAlsaTest, JSONPortMetadata) { |
| 231 | EXPECT_EQ( |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 232 | "{\"bus\":\"bus\",\"clientId\":1,\"clientName\":\"client_name\"," |
| 233 | "\"midiDevice\":5,\"modelId\":\"model\",\"path\":\"path\",\"portId\":2," |
| 234 | "\"portName\":\"port_name\",\"serial\":\"serial\",\"type\":\"input\"," |
| 235 | "\"usbInterfaceNum\":\"interface\",\"vendorId\":\"vendor\"}", |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 236 | port_input_0_->JSONValue()); |
agoode | f212b2a | 2015-03-19 12:53:23 -0700 | [diff] [blame] | 237 | |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 238 | EXPECT_EQ("810194DAF713B32FC9BE40EC822E21682635B48C242D09EA95DBA4A184A95877", |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 239 | port_input_0_->OpaqueKey()); |
agoode | f212b2a | 2015-03-19 12:53:23 -0700 | [diff] [blame] | 240 | |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 241 | EXPECT_EQ( |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 242 | "{\"bus\":\"bus\",\"clientId\":1,\"clientName\":\"client_name\"," |
| 243 | "\"midiDevice\":5,\"modelId\":\"model\",\"path\":\"path\",\"portId\":2," |
| 244 | "\"portName\":\"port_name\",\"serial\":\"serial\",\"type\":\"output\"," |
| 245 | "\"usbInterfaceNum\":\"interface\",\"vendorId\":\"vendor\"}", |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 246 | port_output_0_->JSONValue()); |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 247 | EXPECT_EQ("C32552FC772A0CA453A675CED05EFB3BDEF749EB58ED9522475206F111BC01E2", |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 248 | port_output_0_->OpaqueKey()); |
agoode | f212b2a | 2015-03-19 12:53:23 -0700 | [diff] [blame] | 249 | |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 250 | EXPECT_EQ("{\"clientId\":0,\"midiDevice\":0,\"portId\":0,\"type\":\"input\"}", |
| 251 | port_input_minimal_->JSONValue()); |
| 252 | EXPECT_EQ("3BC2A85598E5026D01DBCB022016C8A3362A9C7F912B88E303BF619C56D0C111", |
| 253 | port_input_minimal_->OpaqueKey()); |
agoode | 55a8b52 | 2015-03-08 12:40:17 -0700 | [diff] [blame] | 254 | } |
| 255 | |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 256 | // Tests Match* methods. |
| 257 | TEST_F(MidiManagerAlsaTest, MatchConnected) { |
| 258 | // The query can be disconnected or connected, but the target |
| 259 | // must be connected. |
| 260 | port_input_1_->set_connected(false); |
| 261 | EXPECT_TRUE(port_input_0_->MatchConnected(*port_input_1_.get())); |
| 262 | EXPECT_FALSE(port_input_1_->MatchConnected(*port_input_0_.get())); |
| 263 | |
| 264 | // Differing types. |
| 265 | EXPECT_FALSE(port_input_0_->MatchConnected(*port_output_0_.get())); |
| 266 | |
| 267 | // Differing in 1 field. None should succeed. |
| 268 | EXPECT_FALSE(port_input_0_->MatchConnected(*port_input_0_alt_path_.get())); |
| 269 | EXPECT_FALSE(port_input_0_->MatchConnected(*port_input_0_alt_id_.get())); |
| 270 | EXPECT_FALSE( |
| 271 | port_input_0_->MatchConnected(*port_input_0_alt_client_name_.get())); |
| 272 | EXPECT_FALSE( |
| 273 | port_input_0_->MatchConnected(*port_input_0_alt_port_name_.get())); |
| 274 | EXPECT_FALSE( |
| 275 | port_input_0_->MatchConnected(*port_input_0_alt_client_id_.get())); |
| 276 | EXPECT_FALSE(port_input_0_->MatchConnected(*port_input_0_alt_port_id_.get())); |
| 277 | EXPECT_FALSE( |
| 278 | port_input_0_->MatchConnected(*port_input_0_alt_midi_device_.get())); |
| 279 | } |
| 280 | |
| 281 | TEST_F(MidiManagerAlsaTest, MatchCard1) { |
| 282 | // The query can be disconnected or connected, but the target |
| 283 | // must be disonnected. |
| 284 | EXPECT_FALSE(port_input_0_->MatchCardPass1(*port_input_1_.get())); |
| 285 | port_input_0_->set_connected(false); |
| 286 | EXPECT_TRUE(port_input_0_->MatchCardPass1(*port_input_1_.get())); |
| 287 | |
| 288 | // Differing types. |
| 289 | EXPECT_FALSE(port_input_0_->MatchCardPass1(*port_output_0_.get())); |
| 290 | |
| 291 | // Tests matches differing in 1 field. |
| 292 | // client_name, port_name, client_id are ok to differ. |
| 293 | EXPECT_FALSE(port_input_0_->MatchCardPass1(*port_input_0_alt_path_.get())); |
| 294 | EXPECT_FALSE(port_input_0_->MatchCardPass1(*port_input_0_alt_id_.get())); |
| 295 | EXPECT_TRUE( |
| 296 | port_input_0_->MatchCardPass1(*port_input_0_alt_client_name_.get())); |
| 297 | EXPECT_TRUE( |
| 298 | port_input_0_->MatchCardPass1(*port_input_0_alt_port_name_.get())); |
| 299 | EXPECT_TRUE( |
| 300 | port_input_0_->MatchCardPass1(*port_input_0_alt_client_id_.get())); |
| 301 | EXPECT_FALSE(port_input_0_->MatchCardPass1(*port_input_0_alt_port_id_.get())); |
| 302 | EXPECT_FALSE( |
| 303 | port_input_0_->MatchCardPass1(*port_input_0_alt_midi_device_.get())); |
| 304 | } |
| 305 | |
| 306 | TEST_F(MidiManagerAlsaTest, MatchCard2) { |
| 307 | // The query can be disconnected or connected, but the target |
| 308 | // must be disonnected. |
| 309 | EXPECT_FALSE(port_input_0_->MatchCardPass2(*port_input_1_.get())); |
| 310 | port_input_0_->set_connected(false); |
| 311 | EXPECT_TRUE(port_input_0_->MatchCardPass2(*port_input_1_.get())); |
| 312 | |
| 313 | // Differing types. |
| 314 | EXPECT_FALSE(port_input_0_->MatchCardPass2(*port_output_0_.get())); |
| 315 | |
| 316 | // Tests matches differing in 1 field. |
| 317 | // client_name, port_name, path, client_id are ok to differ. |
| 318 | EXPECT_TRUE(port_input_0_->MatchCardPass2(*port_input_0_alt_path_.get())); |
| 319 | EXPECT_FALSE(port_input_0_->MatchCardPass2(*port_input_0_alt_id_.get())); |
| 320 | EXPECT_TRUE( |
| 321 | port_input_0_->MatchCardPass2(*port_input_0_alt_client_name_.get())); |
| 322 | EXPECT_TRUE( |
| 323 | port_input_0_->MatchCardPass2(*port_input_0_alt_port_name_.get())); |
| 324 | EXPECT_TRUE( |
| 325 | port_input_0_->MatchCardPass2(*port_input_0_alt_client_id_.get())); |
| 326 | EXPECT_FALSE(port_input_0_->MatchCardPass2(*port_input_0_alt_port_id_.get())); |
| 327 | EXPECT_FALSE( |
| 328 | port_input_0_->MatchCardPass2(*port_input_0_alt_midi_device_.get())); |
| 329 | } |
| 330 | |
| 331 | TEST_F(MidiManagerAlsaTest, MatchNoCard1) { |
| 332 | // The query can be disconnected or connected, but the target |
| 333 | // must be disonnected. |
| 334 | // path and id must be empty. midi_device must be -1. |
| 335 | EXPECT_FALSE(port_input_0_no_card_->MatchNoCardPass1(*port_input_1_.get())); |
| 336 | port_input_0_no_card_->set_connected(false); |
| 337 | EXPECT_FALSE(port_input_0_no_card_->MatchNoCardPass1(*port_input_1_.get())); |
| 338 | EXPECT_TRUE( |
| 339 | port_input_0_no_card_->MatchNoCardPass1(*port_input_1_no_card_.get())); |
| 340 | |
| 341 | // Differing types. |
| 342 | EXPECT_FALSE( |
| 343 | port_input_0_no_card_->MatchNoCardPass1(*port_output_0_no_card_.get())); |
| 344 | |
| 345 | // Tests matches differing in 1 field. |
| 346 | EXPECT_FALSE(port_input_0_no_card_->MatchNoCardPass1( |
| 347 | *port_input_0_no_card_alt_client_name_.get())); |
| 348 | EXPECT_FALSE(port_input_0_no_card_->MatchNoCardPass1( |
| 349 | *port_input_0_no_card_alt_port_name_.get())); |
| 350 | EXPECT_FALSE(port_input_0_no_card_->MatchNoCardPass1( |
| 351 | *port_input_0_no_card_alt_client_id_.get())); |
| 352 | EXPECT_FALSE(port_input_0_no_card_->MatchNoCardPass1( |
| 353 | *port_input_0_no_card_alt_port_id_.get())); |
| 354 | } |
| 355 | |
| 356 | TEST_F(MidiManagerAlsaTest, MatchNoCard2) { |
| 357 | // The query can be disconnected or connected, but the target |
| 358 | // must be disonnected. |
| 359 | // path and id must be empty. midi_device must be -1. |
| 360 | EXPECT_FALSE(port_input_0_no_card_->MatchNoCardPass2(*port_input_1_.get())); |
| 361 | port_input_0_no_card_->set_connected(false); |
| 362 | EXPECT_FALSE(port_input_0_no_card_->MatchNoCardPass2(*port_input_1_.get())); |
| 363 | EXPECT_TRUE( |
| 364 | port_input_0_no_card_->MatchNoCardPass2(*port_input_1_no_card_.get())); |
| 365 | |
| 366 | // Differing types. |
| 367 | EXPECT_FALSE( |
| 368 | port_input_0_no_card_->MatchNoCardPass2(*port_output_0_no_card_.get())); |
| 369 | |
| 370 | // Tests matches differing in 1 field. |
| 371 | // client_id ok to differ. |
| 372 | EXPECT_FALSE(port_input_0_no_card_->MatchNoCardPass2( |
| 373 | *port_input_0_no_card_alt_client_name_.get())); |
| 374 | EXPECT_FALSE(port_input_0_no_card_->MatchNoCardPass2( |
| 375 | *port_input_0_no_card_alt_port_name_.get())); |
| 376 | EXPECT_TRUE(port_input_0_no_card_->MatchNoCardPass2( |
| 377 | *port_input_0_no_card_alt_client_id_.get())); |
| 378 | EXPECT_FALSE(port_input_0_no_card_->MatchNoCardPass2( |
| 379 | *port_input_0_no_card_alt_port_id_.get())); |
| 380 | } |
| 381 | |
| 382 | // Tests that MidiPorts start connected. |
| 383 | TEST_F(MidiManagerAlsaTest, PortStartsConnected) { |
| 384 | EXPECT_TRUE(port_output_0_->connected()); |
| 385 | EXPECT_TRUE(port_input_0_->connected()); |
| 386 | } |
| 387 | |
| 388 | // Tests that the web_port_index gets updated by MidiPortState. |
| 389 | TEST_F(MidiManagerAlsaTest, PortIndexSet) { |
| 390 | auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 391 | auto* port_output_0_tracking_pointer = port_output_0_.get(); |
| 392 | auto* port_input_1_tracking_pointer = port_input_1_.get(); |
| 393 | auto* port_output_1_tracking_pointer = port_input_1_.get(); |
| 394 | |
| 395 | // Explicitly initialize web_port_index. |
| 396 | port_input_1_->set_web_port_index(5000); |
| 397 | port_output_1_->set_web_port_index(5000); |
| 398 | |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 399 | midi_port_state_0_.push_back(std::move(port_input_0_)); |
| 400 | midi_port_state_0_.push_back(std::move(port_output_0_)); |
| 401 | midi_port_state_0_.push_back(std::move(port_input_1_)); |
| 402 | midi_port_state_0_.push_back(std::move(port_output_1_)); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 403 | |
| 404 | // First port of each type has index of 0. |
| 405 | EXPECT_EQ(0U, port_input_0_tracking_pointer->web_port_index()); |
| 406 | EXPECT_EQ(0U, port_output_0_tracking_pointer->web_port_index()); |
| 407 | // Second port of each type has index of 1. |
| 408 | EXPECT_EQ(1U, port_input_1_tracking_pointer->web_port_index()); |
| 409 | EXPECT_EQ(1U, port_output_1_tracking_pointer->web_port_index()); |
| 410 | } |
| 411 | |
| 412 | // Tests that the web_port_index is not updated by TemporaryMidiPortState. |
| 413 | TEST_F(MidiManagerAlsaTest, PortIndexNotSet) { |
| 414 | auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 415 | auto* port_output_0_tracking_pointer = port_output_0_.get(); |
| 416 | auto* port_input_1_tracking_pointer = port_input_1_.get(); |
| 417 | auto* port_output_1_tracking_pointer = port_input_1_.get(); |
| 418 | |
| 419 | // Explicitly initialize web_port_index. |
| 420 | port_input_1_->set_web_port_index(5000); |
| 421 | port_output_1_->set_web_port_index(5000); |
| 422 | |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 423 | temporary_midi_port_state_0_.push_back(std::move(port_input_0_)); |
| 424 | temporary_midi_port_state_0_.push_back(std::move(port_output_0_)); |
| 425 | temporary_midi_port_state_0_.push_back(std::move(port_input_1_)); |
| 426 | temporary_midi_port_state_0_.push_back(std::move(port_output_1_)); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 427 | |
| 428 | // web_port_index is untouched. |
| 429 | EXPECT_EQ(0U, port_input_0_tracking_pointer->web_port_index()); |
| 430 | EXPECT_EQ(0U, port_output_0_tracking_pointer->web_port_index()); |
| 431 | EXPECT_EQ(5000U, port_input_1_tracking_pointer->web_port_index()); |
| 432 | EXPECT_EQ(5000U, port_output_1_tracking_pointer->web_port_index()); |
| 433 | } |
| 434 | |
| 435 | // Tests that inputs and outputs stay separate in MidiPortState. |
| 436 | TEST_F(MidiManagerAlsaTest, SeparateInputOutput) { |
| 437 | auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 438 | auto* port_output_0_tracking_pointer = port_output_0_.get(); |
| 439 | auto* port_input_1_tracking_pointer = port_input_1_.get(); |
| 440 | auto* port_output_1_tracking_pointer = port_input_1_.get(); |
| 441 | |
| 442 | // First port of each type has index of 0. |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 443 | EXPECT_EQ(0U, midi_port_state_0_.push_back(std::move(port_input_0_))); |
| 444 | EXPECT_EQ(0U, midi_port_state_0_.push_back(std::move(port_output_0_))); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 445 | |
| 446 | // Second port of each type has index of 1. |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 447 | EXPECT_EQ(1U, midi_port_state_0_.push_back(std::move(port_input_1_))); |
| 448 | EXPECT_EQ(1U, midi_port_state_0_.push_back(std::move(port_output_1_))); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 449 | |
| 450 | // Check again that the field matches what was returned. |
| 451 | EXPECT_EQ(0U, port_input_0_tracking_pointer->web_port_index()); |
| 452 | EXPECT_EQ(0U, port_output_0_tracking_pointer->web_port_index()); |
| 453 | EXPECT_EQ(1U, port_input_1_tracking_pointer->web_port_index()); |
| 454 | EXPECT_EQ(1U, port_output_1_tracking_pointer->web_port_index()); |
| 455 | } |
| 456 | |
| 457 | // Tests FindConnected. |
| 458 | TEST_F(MidiManagerAlsaTest, FindConnected) { |
| 459 | auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 460 | auto* port_input_1_tracking_pointer = port_input_1_.get(); |
| 461 | |
| 462 | // Insert port_input_0. |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 463 | midi_port_state_0_.push_back(std::move(port_input_0_)); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 464 | // Look for port_input_1 (every field matches port_input_0). |
| 465 | auto it = midi_port_state_0_.FindConnected(*port_input_1_tracking_pointer); |
agoode | 5ebc493 | 2015-12-01 08:25:12 -0800 | [diff] [blame] | 466 | EXPECT_EQ(port_input_0_tracking_pointer, it->get()); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 467 | // Look for something else that we won't find. |
| 468 | EXPECT_EQ(midi_port_state_0_.end(), |
| 469 | midi_port_state_0_.FindConnected(*port_input_0_alt_path_)); |
| 470 | } |
| 471 | |
| 472 | TEST_F(MidiManagerAlsaTest, FindConnected2) { |
| 473 | auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 474 | auto* port_input_1_tracking_pointer = port_input_1_.get(); |
| 475 | |
| 476 | // Insert some stuff. |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 477 | midi_port_state_0_.push_back(std::move(port_input_0_alt_path_)); |
| 478 | midi_port_state_0_.push_back(std::move(port_input_0_alt_id_)); |
| 479 | midi_port_state_0_.push_back(std::move(port_input_0_alt_client_name_)); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 480 | // Insert port_input_0. |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 481 | midi_port_state_0_.push_back(std::move(port_input_0_)); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 482 | // Insert some more stuff. |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 483 | midi_port_state_0_.push_back(std::move(port_input_0_alt_port_id_)); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 484 | // Look for port_input_1 (matches to port_input_0). |
| 485 | auto it = midi_port_state_0_.FindConnected(*port_input_1_tracking_pointer); |
agoode | 5ebc493 | 2015-12-01 08:25:12 -0800 | [diff] [blame] | 486 | EXPECT_EQ(port_input_0_tracking_pointer, it->get()); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 487 | // Look for something else that we won't find. |
| 488 | EXPECT_EQ(midi_port_state_0_.end(), |
| 489 | midi_port_state_0_.FindConnected(*port_input_minimal_)); |
| 490 | } |
| 491 | |
| 492 | TEST_F(MidiManagerAlsaTest, FindConnected3) { |
| 493 | // midi_port_state_0_ is empty to start. |
| 494 | EXPECT_EQ(midi_port_state_0_.end(), |
| 495 | midi_port_state_0_.FindConnected(*port_input_minimal_)); |
| 496 | } |
| 497 | |
| 498 | // Tests FindDisconnected. |
| 499 | TEST_F(MidiManagerAlsaTest, FindDisconnected) { |
| 500 | // midi_port_state_0_ is empty to start. |
| 501 | EXPECT_EQ(midi_port_state_0_.end(), |
| 502 | midi_port_state_0_.FindDisconnected(*port_input_minimal_)); |
| 503 | } |
| 504 | |
| 505 | TEST_F(MidiManagerAlsaTest, FindDisconnected2) { |
| 506 | auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 507 | auto* port_input_1_tracking_pointer = port_input_1_.get(); |
| 508 | auto* port_input_1_no_card_tracking_pointer = port_input_1_no_card_.get(); |
| 509 | |
| 510 | // Ports need to be disconnected to find them. |
| 511 | port_input_0_alt_id_->set_connected(false); |
| 512 | port_input_0_alt_path_->set_connected(false); |
| 513 | port_input_0_->set_connected(false); |
| 514 | |
| 515 | // Insert some stuff. |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 516 | midi_port_state_0_.push_back(std::move(port_input_0_alt_id_)); |
| 517 | midi_port_state_0_.push_back(std::move(port_input_0_alt_path_)); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 518 | // Insert port_input_0. |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 519 | midi_port_state_0_.push_back(std::move(port_input_0_)); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 520 | |
| 521 | // Add "no card" stuff. |
| 522 | port_input_1_no_card_->set_connected(false); |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 523 | midi_port_state_0_.push_back(std::move(port_input_1_no_card_)); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 524 | |
| 525 | // Insert some more stuff. |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 526 | midi_port_state_0_.push_back(std::move(port_input_0_alt_port_id_)); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 527 | |
| 528 | // Look for port_input_1, should trigger exact match. |
agoode | 5ebc493 | 2015-12-01 08:25:12 -0800 | [diff] [blame] | 529 | EXPECT_EQ(port_input_0_tracking_pointer, |
| 530 | midi_port_state_0_.FindDisconnected(*port_input_1_tracking_pointer) |
| 531 | ->get()); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 532 | |
| 533 | // Look for no card exact match. |
agoode | 5ebc493 | 2015-12-01 08:25:12 -0800 | [diff] [blame] | 534 | EXPECT_EQ( |
| 535 | port_input_1_no_card_tracking_pointer, |
| 536 | midi_port_state_0_.FindDisconnected(*port_input_0_no_card_.get())->get()); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 537 | |
| 538 | // Look for something else that we won't find. |
| 539 | EXPECT_EQ(midi_port_state_0_.end(), |
| 540 | midi_port_state_0_.FindDisconnected(*port_input_minimal_)); |
| 541 | } |
| 542 | |
| 543 | TEST_F(MidiManagerAlsaTest, FindDisconnected3) { |
| 544 | auto* port_input_0_tracking_pointer = port_input_0_.get(); |
| 545 | auto* port_input_0_alt_path_tracking_pointer = port_input_0_alt_path_.get(); |
| 546 | auto* port_input_1_no_card_tracking_pointer = port_input_1_no_card_.get(); |
| 547 | |
| 548 | // Ports need to be disconnected to find them. |
| 549 | port_input_0_alt_path_->set_connected(false); |
| 550 | port_input_0_->set_connected(false); |
| 551 | |
| 552 | // Insert some stuff. |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 553 | midi_port_state_0_.push_back(std::move(port_input_0_alt_path_)); |
| 554 | midi_port_state_0_.push_back(std::move(port_input_0_alt_id_)); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 555 | |
| 556 | // Add no card stuff. |
| 557 | port_input_1_no_card_->set_connected(false); |
dcheng | c2aeece | 2015-12-27 00:54:00 -0800 | [diff] [blame] | 558 | midi_port_state_0_.push_back(std::move(port_input_1_no_card_)); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 559 | |
| 560 | // Look for port_input_0, should find port_input_0_alt_path. |
agoode | 5ebc493 | 2015-12-01 08:25:12 -0800 | [diff] [blame] | 561 | EXPECT_EQ(port_input_0_alt_path_tracking_pointer, |
| 562 | midi_port_state_0_.FindDisconnected(*port_input_0_tracking_pointer) |
| 563 | ->get()); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 564 | |
| 565 | // Look for no card partial match. |
| 566 | EXPECT_EQ(port_input_1_no_card_tracking_pointer, |
agoode | 5ebc493 | 2015-12-01 08:25:12 -0800 | [diff] [blame] | 567 | midi_port_state_0_.FindDisconnected( |
| 568 | *port_input_0_no_card_alt_client_id_.get()) |
| 569 | ->get()); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 570 | |
| 571 | // Won't find this. |
| 572 | EXPECT_EQ(midi_port_state_0_.end(), |
| 573 | midi_port_state_0_.FindDisconnected( |
| 574 | *port_input_0_no_card_alt_port_id_.get())); |
| 575 | |
| 576 | // Look for something else that we won't find. |
| 577 | EXPECT_EQ(midi_port_state_0_.end(), |
| 578 | midi_port_state_0_.FindDisconnected(*port_input_minimal_)); |
| 579 | } |
| 580 | |
| 581 | // Tests AlsaSeqState -> MidiPortState. |
| 582 | TEST_F(MidiManagerAlsaTest, ToMidiPortState) { |
| 583 | // Empty state. |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 584 | EXPECT_EQ(0, |
| 585 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 586 | |
| 587 | // Still empty, because there are no ports yet. |
| 588 | alsa_seq_state_0_.ClientStart(0, "0", SND_SEQ_KERNEL_CLIENT); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 589 | EXPECT_EQ(0, |
| 590 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 591 | |
| 592 | // Add a port, now it has 1 item when converted. |
| 593 | alsa_seq_state_0_.PortStart( |
| 594 | 0, 0, "0:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kInput, true); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 595 | EXPECT_EQ(1, |
| 596 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 597 | |
| 598 | // Close client. This closes its ports and returns count to 0. |
| 599 | alsa_seq_state_0_.ClientExit(0); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 600 | EXPECT_EQ(0, |
| 601 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 602 | |
| 603 | // Add another port, without client. This does nothing. |
| 604 | alsa_seq_state_0_.PortStart( |
| 605 | 0, 0, "0:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kInput, true); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 606 | EXPECT_EQ(0, |
| 607 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 608 | |
| 609 | // Close client again. This does nothing. |
| 610 | alsa_seq_state_0_.ClientExit(0); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 611 | EXPECT_EQ(0, |
| 612 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 613 | |
| 614 | // Add duplex port. This will add 2 ports when converted. |
| 615 | alsa_seq_state_0_.ClientStart(0, "0", SND_SEQ_KERNEL_CLIENT); |
| 616 | alsa_seq_state_0_.PortStart( |
| 617 | 0, 0, "0:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kDuplex, true); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 618 | EXPECT_EQ(2, |
| 619 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 620 | |
| 621 | // Add an output port. Now we are at 3. |
| 622 | alsa_seq_state_0_.PortStart( |
| 623 | 0, 1, "0:1", MidiManagerAlsa::AlsaSeqState::PortDirection::kOutput, true); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 624 | EXPECT_EQ(3, |
| 625 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 626 | |
| 627 | // Add another client. Still at 3. |
| 628 | alsa_seq_state_0_.ClientStart(1, "1", SND_SEQ_KERNEL_CLIENT); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 629 | EXPECT_EQ(3, |
| 630 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 631 | |
| 632 | // Add a port. Now at 4. |
| 633 | alsa_seq_state_0_.PortStart( |
| 634 | 1, 0, "1:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kInput, true); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 635 | EXPECT_EQ(4, |
| 636 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 637 | |
| 638 | // Add a duplicate port. Still at 4. |
| 639 | alsa_seq_state_0_.PortStart( |
| 640 | 1, 0, "1:0", MidiManagerAlsa::AlsaSeqState::PortDirection::kInput, true); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 641 | EXPECT_EQ(4, |
| 642 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 643 | |
| 644 | // Add a duplicate client. This will close the ports from the previous client. |
| 645 | alsa_seq_state_0_.ClientStart(1, "1", SND_SEQ_KERNEL_CLIENT); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 646 | EXPECT_EQ(3, |
| 647 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 648 | |
| 649 | // Remove a duplex port. This reduces count by 2. |
| 650 | alsa_seq_state_0_.PortExit(0, 0); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 651 | EXPECT_EQ(1, |
| 652 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 653 | |
| 654 | // Remove a non-existent port. No change. |
| 655 | alsa_seq_state_0_.PortExit(0, 0); |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 656 | EXPECT_EQ(1, |
| 657 | CountPorts(*alsa_seq_state_0_.ToMidiPortState(alsa_cards_).get())); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 658 | |
| 659 | // Verify the last entry. |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 660 | EXPECT_TRUE((*alsa_seq_state_0_.ToMidiPortState(alsa_cards_)->begin()) |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 661 | ->MatchConnected(MidiManagerAlsa::MidiPort( |
agoode | d87fc0f | 2015-05-21 08:29:31 -0700 | [diff] [blame] | 662 | "", MidiManagerAlsa::MidiPort::Id(), 0, 1, -1, "0", "0:1", |
| 663 | "", "", MidiManagerAlsa::MidiPort::Type::kOutput))); |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 664 | } |
| 665 | |
agoode | b09423b | 2015-05-11 11:39:57 -0700 | [diff] [blame] | 666 | // Tests card_client_count of AlsaSeqState. |
| 667 | TEST_F(MidiManagerAlsaTest, CardClientCount) { |
| 668 | EXPECT_EQ(0, alsa_seq_state_0_.card_client_count()); |
| 669 | |
| 670 | // Add a kernel client. |
| 671 | alsa_seq_state_0_.ClientStart(16, "16", SND_SEQ_KERNEL_CLIENT); |
| 672 | EXPECT_EQ(1, alsa_seq_state_0_.card_client_count()); |
| 673 | |
| 674 | // Add a duplicate kernel client. |
| 675 | alsa_seq_state_0_.ClientStart(16, "16", SND_SEQ_KERNEL_CLIENT); |
| 676 | EXPECT_EQ(1, alsa_seq_state_0_.card_client_count()); |
| 677 | |
| 678 | // Add a duplicate user client. |
| 679 | alsa_seq_state_0_.ClientStart(16, "16", SND_SEQ_USER_CLIENT); |
| 680 | EXPECT_EQ(0, alsa_seq_state_0_.card_client_count()); |
| 681 | |
| 682 | // Add 2 more kernel clients. |
| 683 | alsa_seq_state_0_.ClientStart(17, "17", SND_SEQ_KERNEL_CLIENT); |
| 684 | alsa_seq_state_0_.ClientStart(18, "18", SND_SEQ_KERNEL_CLIENT); |
| 685 | EXPECT_EQ(2, alsa_seq_state_0_.card_client_count()); |
| 686 | |
| 687 | // Add another user client. |
| 688 | alsa_seq_state_0_.ClientStart(101, "101", SND_SEQ_USER_CLIENT); |
| 689 | EXPECT_EQ(2, alsa_seq_state_0_.card_client_count()); |
| 690 | |
| 691 | // Remove kernel client. |
| 692 | alsa_seq_state_0_.ClientExit(17); |
| 693 | EXPECT_EQ(1, alsa_seq_state_0_.card_client_count()); |
| 694 | |
| 695 | // Remove user client. |
| 696 | alsa_seq_state_0_.ClientExit(16); |
| 697 | EXPECT_EQ(1, alsa_seq_state_0_.card_client_count()); |
| 698 | |
| 699 | // Remove kernel client. |
| 700 | alsa_seq_state_0_.ClientExit(18); |
| 701 | EXPECT_EQ(0, alsa_seq_state_0_.card_client_count()); |
| 702 | |
| 703 | // Add a duplicate kernel client. |
| 704 | alsa_seq_state_0_.ClientStart(101, "101", SND_SEQ_KERNEL_CLIENT); |
| 705 | EXPECT_EQ(1, alsa_seq_state_0_.card_client_count()); |
| 706 | |
| 707 | // Add a low kernel client. |
| 708 | alsa_seq_state_0_.ClientStart(1, "1", SND_SEQ_KERNEL_CLIENT); |
| 709 | EXPECT_EQ(1, alsa_seq_state_0_.card_client_count()); |
| 710 | |
| 711 | // Remove low kernel client. |
| 712 | alsa_seq_state_0_.ClientExit(1); |
| 713 | EXPECT_EQ(1, alsa_seq_state_0_.card_client_count()); |
| 714 | } |
| 715 | |
| 716 | TEST_F(MidiManagerAlsaTest, AlsaCards) { |
| 717 | // TODO(agoode): test add/remove of alsa cards. |
| 718 | } |
| 719 | |
agoode | 99d6329 | 2015-04-13 08:39:25 -0700 | [diff] [blame] | 720 | // TODO(agoode): Test old -> new state event generation, using mocks. |
| 721 | |
toyoshim | e147c5e | 2015-05-07 21:58:31 -0700 | [diff] [blame] | 722 | } // namespace midi |