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

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

Issue 1098913003: [WebMIDI] [Android] Set appropriate port properties. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 8 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
« no previous file with comments | « media/midi/usb_midi_descriptor_parser.cc ('k') | media/midi/usb_midi_device.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/midi/usb_midi_descriptor_parser.h" 5 #include "media/midi/usb_midi_descriptor_parser.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace media { 9 namespace media {
10 10
11 namespace { 11 namespace {
12 12
13 TEST(UsbMidiDescriptorParserTest, ParseEmpty) { 13 TEST(UsbMidiDescriptorParserTest, ParseEmpty) {
14 UsbMidiDescriptorParser parser; 14 UsbMidiDescriptorParser parser;
15 std::vector<UsbMidiJack> jacks; 15 std::vector<UsbMidiJack> jacks;
16 EXPECT_TRUE(parser.Parse(NULL, NULL, 0, &jacks)); 16 EXPECT_TRUE(parser.Parse(nullptr, nullptr, 0, &jacks));
17 EXPECT_TRUE(jacks.empty()); 17 EXPECT_TRUE(jacks.empty());
18 } 18 }
19 19
20 TEST(UsbMidiDescriptorParserTest, InvalidSize) { 20 TEST(UsbMidiDescriptorParserTest, InvalidSize) {
21 UsbMidiDescriptorParser parser; 21 UsbMidiDescriptorParser parser;
22 std::vector<UsbMidiJack> jacks; 22 std::vector<UsbMidiJack> jacks;
23 uint8 data[] = {0x04}; 23 uint8 data[] = {0x04};
24 EXPECT_FALSE(parser.Parse(NULL, data, arraysize(data), &jacks)); 24 EXPECT_FALSE(parser.Parse(nullptr, data, arraysize(data), &jacks));
25 EXPECT_TRUE(jacks.empty()); 25 EXPECT_TRUE(jacks.empty());
26 } 26 }
27 27
28 TEST(UsbMidiDescriptorParserTest, NonExistingJackIsAssociated) { 28 TEST(UsbMidiDescriptorParserTest, NonExistingJackIsAssociated) {
29 UsbMidiDescriptorParser parser; 29 UsbMidiDescriptorParser parser;
30 std::vector<UsbMidiJack> jacks; 30 std::vector<UsbMidiJack> jacks;
31 // Jack id=1 is found in a CS_ENDPOINT descriptor, but there is no definition 31 // Jack id=1 is found in a CS_ENDPOINT descriptor, but there is no definition
32 // for the jack. 32 // for the jack.
33 uint8 data[] = { 33 uint8 data[] = {
34 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07, 34 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07,
35 0x24, 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01, 35 0x24, 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01,
36 0x01, 36 0x01,
37 }; 37 };
38 EXPECT_FALSE(parser.Parse(NULL, data, arraysize(data), &jacks)); 38 EXPECT_FALSE(parser.Parse(nullptr, data, arraysize(data), &jacks));
39 EXPECT_TRUE(jacks.empty()); 39 EXPECT_TRUE(jacks.empty());
40 } 40 }
41 41
42 TEST(UsbMidiDescriptorParserTest, 42 TEST(UsbMidiDescriptorParserTest,
43 JacksShouldBeIgnoredWhenParserIsNotParsingMidiInterface) { 43 JacksShouldBeIgnoredWhenParserIsNotParsingMidiInterface) {
44 UsbMidiDescriptorParser parser; 44 UsbMidiDescriptorParser parser;
45 std::vector<UsbMidiJack> jacks; 45 std::vector<UsbMidiJack> jacks;
46 // a NON-MIDI INTERFACE descriptor followed by ENDPOINT and CS_ENDPOINT 46 // a NON-MIDI INTERFACE descriptor followed by ENDPOINT and CS_ENDPOINT
47 // descriptors (Compare with the previous test case). 47 // descriptors (Compare with the previous test case).
48 uint8 data[] = { 48 uint8 data[] = {
49 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x02, 0x00, 0x00, 0x07, 49 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x02, 0x00, 0x00, 0x07,
50 0x24, 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01, 50 0x24, 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01,
51 0x01, 51 0x01,
52 }; 52 };
53 EXPECT_TRUE(parser.Parse(NULL, data, arraysize(data), &jacks)); 53 EXPECT_TRUE(parser.Parse(nullptr, data, arraysize(data), &jacks));
54 EXPECT_TRUE(jacks.empty()); 54 EXPECT_TRUE(jacks.empty());
55 } 55 }
56 56
57 TEST(UsbMidiDescriptorParserTest, Parse) { 57 TEST(UsbMidiDescriptorParserTest, Parse) {
58 UsbMidiDescriptorParser parser; 58 UsbMidiDescriptorParser parser;
59 std::vector<UsbMidiJack> jacks; 59 std::vector<UsbMidiJack> jacks;
60 // A complete device descriptor. 60 // A complete device descriptor.
61 uint8 data[] = { 61 uint8 data[] = {
62 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 62 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
63 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 63 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
64 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 64 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
65 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, 65 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
66 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, 66 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
67 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, 67 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
68 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 68 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
69 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 69 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
70 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 70 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
71 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03, 71 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03,
72 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02, 72 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02,
73 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, 73 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
74 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 74 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
75 0x05, 0x25, 0x01, 0x01, 0x07, 75 0x05, 0x25, 0x01, 0x01, 0x07,
76 }; 76 };
77 EXPECT_TRUE(parser.Parse(NULL, data, arraysize(data), &jacks)); 77 EXPECT_TRUE(parser.Parse(nullptr, data, arraysize(data), &jacks));
78 ASSERT_EQ(3u, jacks.size()); 78 ASSERT_EQ(3u, jacks.size());
79 79
80 EXPECT_EQ(2u, jacks[0].jack_id); 80 EXPECT_EQ(2u, jacks[0].jack_id);
81 EXPECT_EQ(0u, jacks[0].cable_number); 81 EXPECT_EQ(0u, jacks[0].cable_number);
82 EXPECT_EQ(2u, jacks[0].endpoint_number()); 82 EXPECT_EQ(2u, jacks[0].endpoint_number());
83 EXPECT_EQ(UsbMidiJack::DIRECTION_OUT, jacks[0].direction()); 83 EXPECT_EQ(UsbMidiJack::DIRECTION_OUT, jacks[0].direction());
84 EXPECT_EQ(NULL, jacks[0].device); 84 EXPECT_EQ(nullptr, jacks[0].device);
85 85
86 EXPECT_EQ(3u, jacks[1].jack_id); 86 EXPECT_EQ(3u, jacks[1].jack_id);
87 EXPECT_EQ(1u, jacks[1].cable_number); 87 EXPECT_EQ(1u, jacks[1].cable_number);
88 EXPECT_EQ(2u, jacks[1].endpoint_number()); 88 EXPECT_EQ(2u, jacks[1].endpoint_number());
89 EXPECT_EQ(UsbMidiJack::DIRECTION_OUT, jacks[1].direction()); 89 EXPECT_EQ(UsbMidiJack::DIRECTION_OUT, jacks[1].direction());
90 EXPECT_EQ(NULL, jacks[1].device); 90 EXPECT_EQ(nullptr, jacks[1].device);
91 91
92 EXPECT_EQ(7u, jacks[2].jack_id); 92 EXPECT_EQ(7u, jacks[2].jack_id);
93 EXPECT_EQ(0u, jacks[2].cable_number); 93 EXPECT_EQ(0u, jacks[2].cable_number);
94 EXPECT_EQ(2u, jacks[2].endpoint_number()); 94 EXPECT_EQ(2u, jacks[2].endpoint_number());
95 EXPECT_EQ(UsbMidiJack::DIRECTION_IN, jacks[2].direction()); 95 EXPECT_EQ(UsbMidiJack::DIRECTION_IN, jacks[2].direction());
96 EXPECT_EQ(NULL, jacks[2].device); 96 EXPECT_EQ(nullptr, jacks[2].device);
97 }
98
99 TEST(UsbMidiDescriptorParserTest, ParseDeviceInfoEmpty) {
100 UsbMidiDescriptorParser parser;
101 UsbMidiDescriptorParser::DeviceInfo info;
102 EXPECT_FALSE(parser.ParseDeviceInfo(nullptr, 0, &info));
103 }
104
105 TEST(UsbMidiDescriptorParserTest, ParseDeviceInfo) {
106 UsbMidiDescriptorParser parser;
107 UsbMidiDescriptorParser::DeviceInfo info;
108 uint8 data[] = {
109 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, 0x23,
110 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x0a,
111 };
112 EXPECT_TRUE(parser.ParseDeviceInfo(data, arraysize(data), &info));
113
114 EXPECT_EQ(0x2301, info.vendor_id);
115 EXPECT_EQ(0x6745, info.product_id);
116 EXPECT_EQ(0xab89, info.bcd_device_version);
117 EXPECT_EQ(0xcd, info.manufacturer_index);
118 EXPECT_EQ(0xef, info.product_index);
97 } 119 }
98 120
99 } // namespace 121 } // namespace
100 122
101 } // namespace media 123 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/usb_midi_descriptor_parser.cc ('k') | media/midi/usb_midi_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698