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

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 6 years, 12 months 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 JacksShouldBeIgnoredWhenParserIsNotParsingMIDIInterface) {
44 UsbMidiDescriptorParser parser;
45 // a NON-MIDI INTERFACE descriptor followed by ENDPOINT and CS_ENDPOINT
46 // descriptors (Compare with the previous test case).
47 uint8 data[] = {
48 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x02, 0x00, 0x00, 0x07,
49 0x24, 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01,
50 0x01,
51 };
52 EXPECT_TRUE(parser.jacks().empty());
53 EXPECT_TRUE(parser.Parse(NULL, data, arraysize(data)));
54 EXPECT_TRUE(parser.jacks().empty());
55 }
56
57 TEST(UsbMidiDescriptorParserTest, Parse) {
58 UsbMidiDescriptorParser parser;
59 // A complete device descriptor.
60 uint8 data[] = {
61 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
62 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
63 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
64 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
65 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
66 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
67 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
68 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
69 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
70 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03,
71 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02,
72 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
73 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
74 0x05, 0x25, 0x01, 0x01, 0x07,
75 };
76 EXPECT_TRUE(parser.jacks().empty());
77 EXPECT_TRUE(parser.Parse(NULL, data, arraysize(data)));
78 ASSERT_EQ(3u, parser.jacks().size());
79
80 EXPECT_EQ(2u, parser.jacks()[0].jack_id);
81 EXPECT_EQ(0u, parser.jacks()[0].cable_number);
82 EXPECT_EQ(2u, parser.jacks()[0].GetEndpointNumber());
83 EXPECT_EQ(UsbMidiJack::OUT, parser.jacks()[0].GetDirection());
84 EXPECT_EQ(NULL, parser.jacks()[0].device);
85
86 EXPECT_EQ(3u, parser.jacks()[1].jack_id);
87 EXPECT_EQ(1u, parser.jacks()[1].cable_number);
88 EXPECT_EQ(2u, parser.jacks()[1].GetEndpointNumber());
89 EXPECT_EQ(UsbMidiJack::OUT, parser.jacks()[1].GetDirection());
90 EXPECT_EQ(NULL, parser.jacks()[1].device);
91
92 EXPECT_EQ(7u, parser.jacks()[2].jack_id);
93 EXPECT_EQ(0u, parser.jacks()[2].cable_number);
94 EXPECT_EQ(2u, parser.jacks()[2].GetEndpointNumber());
95 EXPECT_EQ(UsbMidiJack::IN, parser.jacks()[2].GetDirection());
96 EXPECT_EQ(NULL, parser.jacks()[2].device);
97 }
98
99 } // namespace
100
101 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698