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

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

Issue 105043008: Introduce USB MIDI descriptor parser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years 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
(Empty)
1 // Copyright (c) 2013 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/usb_midi_descriptor_parser.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace media {
10
11 namespace {
12
13 TEST(UsbMidiDescriptorParserTest, ParseEmpty) {
14 UsbMidiDescriptorParser parser;
15 EXPECT_TRUE(parser.jacks().empty());
16 EXPECT_TRUE(parser.Parse(NULL, NULL, 0));
17 EXPECT_TRUE(parser.jacks().empty());
18 }
19
20 TEST(UsbMidiDescriptorParserTest, InvalidSize) {
21 UsbMidiDescriptorParser parser;
22 uint8 data[] = {0x04};
23 EXPECT_TRUE(parser.jacks().empty());
24 EXPECT_FALSE(parser.Parse(NULL, data, arraysize(data)));
25 EXPECT_TRUE(parser.jacks().empty());
26 }
27
28 TEST(UsbMidiDescriptorParserTest, NonExistingJackIsAssociated) {
29 UsbMidiDescriptorParser parser;
30 // Jack id=1 is found in a CS_ENDPOINT descriptor, but there is no definition
31 // for the jack.
32 uint8 data[] = {
33 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07,
34 0x24, 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01,
35 0x01,
36 };
37 EXPECT_TRUE(parser.jacks().empty());
38 EXPECT_FALSE(parser.Parse(NULL, data, arraysize(data)));
39 EXPECT_TRUE(parser.jacks().empty());
40 }
41
42 TEST(UsbMidiDescriptorParserTest,
43 JacksShouldBeIgnoredWhenParserIsNotParsingAnInterface) {
44 UsbMidiDescriptorParser parser;
45 // ENDPOINT and CS_ENDPOINT descriptors without an INTERFACE descriptor.
46 uint8 data[] = {
47 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05,
48 0x25, 0x01, 0x01, 0x07,
49 };
50 EXPECT_TRUE(parser.jacks().empty());
51 EXPECT_TRUE(parser.Parse(NULL, data, arraysize(data)));
52 EXPECT_TRUE(parser.jacks().empty());
53 }
54
55 TEST(UsbMidiDescriptorParserTest, Parse) {
56 UsbMidiDescriptorParser parser;
57 // A complete device descriptor.
58 uint8 data[] = {
59 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
60 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
61 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
62 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
63 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
64 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
65 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
66 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
67 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
68 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03,
69 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02,
70 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
71 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
72 0x05, 0x25, 0x01, 0x01, 0x07,
73 };
74 EXPECT_TRUE(parser.jacks().empty());
75 EXPECT_TRUE(parser.Parse(NULL, data, arraysize(data)));
76 ASSERT_EQ(3u, parser.jacks().size());
77
78 EXPECT_EQ(2u, parser.jacks()[0].jack_id);
79 EXPECT_EQ(0u, parser.jacks()[0].cable_number);
80 EXPECT_EQ(2u, parser.jacks()[0].GetEndpointNumber());
81 EXPECT_EQ(UsbMidiJack::OUT, parser.jacks()[0].GetDirection());
82 EXPECT_EQ(NULL, parser.jacks()[0].device);
83
84 EXPECT_EQ(3u, parser.jacks()[1].jack_id);
85 EXPECT_EQ(1u, parser.jacks()[1].cable_number);
86 EXPECT_EQ(2u, parser.jacks()[1].GetEndpointNumber());
87 EXPECT_EQ(UsbMidiJack::OUT, parser.jacks()[1].GetDirection());
88 EXPECT_EQ(NULL, parser.jacks()[1].device);
89
90 EXPECT_EQ(7u, parser.jacks()[2].jack_id);
91 EXPECT_EQ(0u, parser.jacks()[2].cable_number);
92 EXPECT_EQ(2u, parser.jacks()[2].GetEndpointNumber());
93 EXPECT_EQ(UsbMidiJack::IN, parser.jacks()[2].GetDirection());
94 EXPECT_EQ(NULL, parser.jacks()[2].device);
95 }
96
97 } // namespace
98
99 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698