All instances of addresses as void* are changed to uintptr_t in
[chromium-blink-merge.git] / media / midi / usb_midi_descriptor_parser_unittest.cc
blobc0e569dd72b2f8437a3827f90c7b2a9f01d7423c
1 // Copyright 2014 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.
5 #include "media/midi/usb_midi_descriptor_parser.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace media {
10 namespace midi {
12 namespace {
14 TEST(UsbMidiDescriptorParserTest, ParseEmpty) {
15 UsbMidiDescriptorParser parser;
16 std::vector<UsbMidiJack> jacks;
17 EXPECT_TRUE(parser.Parse(nullptr, nullptr, 0, &jacks));
18 EXPECT_TRUE(jacks.empty());
21 TEST(UsbMidiDescriptorParserTest, InvalidSize) {
22 UsbMidiDescriptorParser parser;
23 std::vector<UsbMidiJack> jacks;
24 uint8 data[] = {0x04};
25 EXPECT_FALSE(parser.Parse(nullptr, data, arraysize(data), &jacks));
26 EXPECT_TRUE(jacks.empty());
29 TEST(UsbMidiDescriptorParserTest, NonExistingJackIsAssociated) {
30 UsbMidiDescriptorParser parser;
31 std::vector<UsbMidiJack> jacks;
32 // Jack id=1 is found in a CS_ENDPOINT descriptor, but there is no definition
33 // for the jack.
34 uint8 data[] = {
35 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07,
36 0x24, 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01,
37 0x01,
39 EXPECT_FALSE(parser.Parse(nullptr, data, arraysize(data), &jacks));
40 EXPECT_TRUE(jacks.empty());
43 TEST(UsbMidiDescriptorParserTest,
44 JacksShouldBeIgnoredWhenParserIsNotParsingMidiInterface) {
45 UsbMidiDescriptorParser parser;
46 std::vector<UsbMidiJack> jacks;
47 // a NON-MIDI INTERFACE descriptor followed by ENDPOINT and CS_ENDPOINT
48 // descriptors (Compare with the previous test case).
49 uint8 data[] = {
50 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x02, 0x00, 0x00, 0x07,
51 0x24, 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01,
52 0x01,
54 EXPECT_TRUE(parser.Parse(nullptr, data, arraysize(data), &jacks));
55 EXPECT_TRUE(jacks.empty());
58 TEST(UsbMidiDescriptorParserTest, Parse) {
59 UsbMidiDescriptorParser parser;
60 std::vector<UsbMidiJack> jacks;
61 // A complete device descriptor.
62 uint8 data[] = {
63 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
64 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
65 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
66 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
67 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
68 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
69 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
70 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
71 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
72 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03,
73 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02,
74 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
75 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
76 0x05, 0x25, 0x01, 0x01, 0x07,
78 EXPECT_TRUE(parser.Parse(nullptr, data, arraysize(data), &jacks));
79 ASSERT_EQ(3u, jacks.size());
81 EXPECT_EQ(2u, jacks[0].jack_id);
82 EXPECT_EQ(0u, jacks[0].cable_number);
83 EXPECT_EQ(2u, jacks[0].endpoint_number());
84 EXPECT_EQ(UsbMidiJack::DIRECTION_OUT, jacks[0].direction());
85 EXPECT_EQ(nullptr, jacks[0].device);
87 EXPECT_EQ(3u, jacks[1].jack_id);
88 EXPECT_EQ(1u, jacks[1].cable_number);
89 EXPECT_EQ(2u, jacks[1].endpoint_number());
90 EXPECT_EQ(UsbMidiJack::DIRECTION_OUT, jacks[1].direction());
91 EXPECT_EQ(nullptr, jacks[1].device);
93 EXPECT_EQ(7u, jacks[2].jack_id);
94 EXPECT_EQ(0u, jacks[2].cable_number);
95 EXPECT_EQ(2u, jacks[2].endpoint_number());
96 EXPECT_EQ(UsbMidiJack::DIRECTION_IN, jacks[2].direction());
97 EXPECT_EQ(nullptr, jacks[2].device);
100 TEST(UsbMidiDescriptorParserTest, ParseDeviceInfoEmpty) {
101 UsbMidiDescriptorParser parser;
102 UsbMidiDescriptorParser::DeviceInfo info;
103 EXPECT_FALSE(parser.ParseDeviceInfo(nullptr, 0, &info));
106 TEST(UsbMidiDescriptorParserTest, ParseDeviceInfo) {
107 UsbMidiDescriptorParser parser;
108 UsbMidiDescriptorParser::DeviceInfo info;
109 uint8 data[] = {
110 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, 0x23,
111 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x0a,
113 EXPECT_TRUE(parser.ParseDeviceInfo(data, arraysize(data), &info));
115 EXPECT_EQ(0x2301, info.vendor_id);
116 EXPECT_EQ(0x6745, info.product_id);
117 EXPECT_EQ(0xab89, info.bcd_device_version);
118 EXPECT_EQ(0xcd, info.manufacturer_index);
119 EXPECT_EQ(0xef, info.product_index);
122 } // namespace
124 } // namespace midi
125 } // namespace media