summaryrefslogtreecommitdiffstats
path: root/media/midi/midi_manager_alsa_unittest.cc
blob: 0e87e07e77adff829965dd7da01fd387b50a799a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/midi/midi_manager_alsa.h"

#include "testing/gtest/include/gtest/gtest.h"

namespace media {

TEST(MidiManagerAlsaTest, ExtractManufacturer) {
  ASSERT_EQ("My\\x20Vendor",
            MidiManagerAlsa::AlsaRawmidi::ExtractManufacturerString(
                "My\\x20Vendor", "1234", "My Vendor, Inc.", "Card",
                "My Vendor Inc Card at bus"));
  ASSERT_EQ("My Vendor",
            MidiManagerAlsa::AlsaRawmidi::ExtractManufacturerString(
                "My Vendor", "1234", "My Vendor, Inc.", "Card",
                "My Vendor Inc Card at bus"));
  ASSERT_EQ("My Vendor, Inc.",
            MidiManagerAlsa::AlsaRawmidi::ExtractManufacturerString(
                "1234", "1234", "My Vendor, Inc.", "Card",
                "My Vendor Inc Card at bus"));
  ASSERT_EQ("My Vendor Inc",
            MidiManagerAlsa::AlsaRawmidi::ExtractManufacturerString(
                "1234", "1234", "", "Card", "My Vendor Inc Card at bus"));
  ASSERT_EQ("My Vendor Inc",
            MidiManagerAlsa::AlsaRawmidi::ExtractManufacturerString(
                "", "", "", "Card", "My Vendor Inc Card at bus"));
  ASSERT_EQ("", MidiManagerAlsa::AlsaRawmidi::ExtractManufacturerString(
                    "1234", "1234", "", "Card", "Longname"));
  ASSERT_EQ("Keystation\\x20Mini\\x2032",
            MidiManagerAlsa::AlsaRawmidi::ExtractManufacturerString(
                "Keystation\\x20Mini\\x2032", "129d",
                "Evolution Electronics, Ltd", "Keystation Mini 32",
                "Keystation Mini 32 Keystation Mini 32 at"
                " usb-0000:00:14.0-2.4.4, full speed"));
  ASSERT_EQ("Keystation Mini 32",
            MidiManagerAlsa::AlsaRawmidi::ExtractManufacturerString(
                "Keystation Mini 32", "129d", "Evolution Electronics, Ltd",
                "Keystation Mini 32",
                "Keystation Mini 32 Keystation Mini 32 at"
                " usb-0000:00:14.0-2.4.4, full speed"));
  ASSERT_EQ("Keystation Mini 32",
            MidiManagerAlsa::AlsaRawmidi::ExtractManufacturerString(
                "", "", "", "Keystation Mini 32",
                "Keystation Mini 32 Keystation Mini 32 at"
                " usb-0000:00:14.0-2.4.4, full speed"));
  ASSERT_EQ("", MidiManagerAlsa::AlsaRawmidi::ExtractManufacturerString(
                    "", "", "", "Serial MIDI (UART16550A)",
                    "Serial MIDI (UART16550A) [Soundcanvas] at 0x3f8, irq 4"));
  ASSERT_EQ("", MidiManagerAlsa::AlsaRawmidi::ExtractManufacturerString(
                    "", "", "", "VirMIDI", "Virtual MIDI Card 1"));
}

TEST(MidiManagerAlsaTest, JSONPortMetadata) {
  snd_seq_addr_t address;
  address.client = 1;
  address.port = 2;

  MidiManagerAlsa::AlsaPortMetadata input(
      "path", "bus", "id", &address, "client_name", "port_name", "card_name",
      "card_longname", MidiManagerAlsa::AlsaPortMetadata::Type::kInput);

  MidiManagerAlsa::AlsaPortMetadata output(
      "path", "bus", "id", &address, "client_name", "port_name", "card_name",
      "card_longname", MidiManagerAlsa::AlsaPortMetadata::Type::kOutput);

  MidiManagerAlsa::AlsaPortMetadata partial(
      "", "", "", &address, "client_name", "port_name", "card_name",
      "card_longname", MidiManagerAlsa::AlsaPortMetadata::Type::kOutput);

  ASSERT_EQ(
      "{\"bus\":\"bus\",\"cardLongname\":\"card_longname\",\"cardName\":\"card_"
      "name\","
      "\"clientAddr\":1,\"clientName\":\"client_name\",\"id\":\"id\",\"path\":"
      "\"path\","
      "\"portAddr\":2,\"portName\":\"port_name\",\"type\":\"input\"}",
      input.JSONValue());

  ASSERT_EQ("6D6186ACF60BB2FD26B5D2E21881CF0541FDB80FAC5BDFFA95CD55739E3BC526",
            input.OpaqueKey());

  ASSERT_EQ(
      "{\"bus\":\"bus\",\"cardLongname\":\"card_longname\",\"cardName\":\"card_"
      "name\","
      "\"clientAddr\":1,\"clientName\":\"client_name\",\"id\":\"id\",\"path\":"
      "\"path\","
      "\"portAddr\":2,\"portName\":\"port_name\",\"type\":\"output\"}",
      output.JSONValue());
  ASSERT_EQ("747E553D40F8388A0C1C51261B82869D5EFA8A54860AAFB2F4F7437744982495",
            output.OpaqueKey());

  ASSERT_EQ(
      "{\"cardLongname\":\"card_longname\",\"cardName\":\"card_"
      "name\","
      "\"clientAddr\":1,\"clientName\":\"client_name\","
      "\"portAddr\":2,\"portName\":\"port_name\",\"type\":\"output\"}",
      partial.JSONValue());
  ASSERT_EQ("51DF7AF543B5BDF83C0B8DE3A00A0BC588DDFCA8600671EF7D59828B40DFF6D3",
            partial.OpaqueKey());
}

}  // namespace media