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

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 uint8 data[] = {
Takashi Toyoshima 2013/12/19 05:54:23 It's better to have a comment that describes summa
yhirano 2013/12/19 07:15:05 Done.
31 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07,
32 0x24, 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01,
33 0x01,
34 };
35 EXPECT_TRUE(parser.jacks().empty());
36 EXPECT_FALSE(parser.Parse(NULL, data, arraysize(data)));
37 EXPECT_TRUE(parser.jacks().empty());
38 }
39
40 TEST(UsbMidiDescriptorParserTest,
41 JacksShouldBeIgnoredWhenParserIsNotParsingAnInterface) {
42 UsbMidiDescriptorParser parser;
43 uint8 data[] = {
Takashi Toyoshima 2013/12/19 05:54:23 ditto
yhirano 2013/12/19 07:15:05 Done.
44 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05,
45 0x25, 0x01, 0x01, 0x07,
46 };
47 EXPECT_TRUE(parser.jacks().empty());
48 EXPECT_TRUE(parser.Parse(NULL, data, arraysize(data)));
Takashi Toyoshima 2013/12/19 05:54:23 So, here is a question for the function design. Wh
yhirano 2013/12/19 07:15:05 Done.
Takashi Toyoshima 2013/12/19 07:48:48 Ah, my original question was wrong. I'm not sure i
yhirano 2013/12/19 08:05:47 Sorry, I mis-read your comment. There is no specia
49 EXPECT_TRUE(parser.jacks().empty());
50 }
51
52 TEST(UsbMidiDescriptorParserTest, Parse) {
53 UsbMidiDescriptorParser parser;
54 uint8 data[] = {
Takashi Toyoshima 2013/12/19 05:54:23 ditto
yhirano 2013/12/19 07:15:05 Done.
55 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
56 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
57 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
58 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
59 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
60 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
61 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
62 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
63 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
64 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03,
65 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02,
66 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
67 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
68 0x05, 0x25, 0x01, 0x01, 0x07,
69 };
70 EXPECT_TRUE(parser.jacks().empty());
71 EXPECT_TRUE(parser.Parse(NULL, data, arraysize(data)));
72 ASSERT_EQ(3u, parser.jacks().size());
73
74 EXPECT_EQ(2u, parser.jacks()[0].jack_id);
75 EXPECT_EQ(0u, parser.jacks()[0].cable_number);
76 EXPECT_EQ(2u, parser.jacks()[0].GetEndpointNumber());
77 EXPECT_EQ(UsbMidiJack::OUT, parser.jacks()[0].GetDirection());
78 EXPECT_EQ(NULL, parser.jacks()[0].device);
79
80 EXPECT_EQ(3u, parser.jacks()[1].jack_id);
81 EXPECT_EQ(1u, parser.jacks()[1].cable_number);
82 EXPECT_EQ(2u, parser.jacks()[1].GetEndpointNumber());
83 EXPECT_EQ(UsbMidiJack::OUT, parser.jacks()[1].GetDirection());
84 EXPECT_EQ(NULL, parser.jacks()[1].device);
85
86 EXPECT_EQ(7u, parser.jacks()[2].jack_id);
87 EXPECT_EQ(0u, parser.jacks()[2].cable_number);
88 EXPECT_EQ(2u, parser.jacks()[2].GetEndpointNumber());
89 EXPECT_EQ(UsbMidiJack::IN, parser.jacks()[2].GetDirection());
90 EXPECT_EQ(NULL, parser.jacks()[2].device);
91 }
92
93 } // namespace
94
95 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698