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

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

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 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
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 namespace midi { 10 namespace midi {
11 11
12 namespace { 12 namespace {
13 13
14 TEST(UsbMidiDescriptorParserTest, ParseEmpty) { 14 TEST(UsbMidiDescriptorParserTest, ParseEmpty) {
15 UsbMidiDescriptorParser parser; 15 UsbMidiDescriptorParser parser;
16 std::vector<UsbMidiJack> jacks; 16 std::vector<UsbMidiJack> jacks;
17 EXPECT_TRUE(parser.Parse(nullptr, nullptr, 0, &jacks)); 17 EXPECT_TRUE(parser.Parse(nullptr, nullptr, 0, &jacks));
18 EXPECT_TRUE(jacks.empty()); 18 EXPECT_TRUE(jacks.empty());
19 } 19 }
20 20
21 TEST(UsbMidiDescriptorParserTest, InvalidSize) { 21 TEST(UsbMidiDescriptorParserTest, InvalidSize) {
22 UsbMidiDescriptorParser parser; 22 UsbMidiDescriptorParser parser;
23 std::vector<UsbMidiJack> jacks; 23 std::vector<UsbMidiJack> jacks;
24 uint8 data[] = {0x04}; 24 uint8_t data[] = {0x04};
25 EXPECT_FALSE(parser.Parse(nullptr, data, arraysize(data), &jacks)); 25 EXPECT_FALSE(parser.Parse(nullptr, data, arraysize(data), &jacks));
26 EXPECT_TRUE(jacks.empty()); 26 EXPECT_TRUE(jacks.empty());
27 } 27 }
28 28
29 TEST(UsbMidiDescriptorParserTest, NonExistingJackIsAssociated) { 29 TEST(UsbMidiDescriptorParserTest, NonExistingJackIsAssociated) {
30 UsbMidiDescriptorParser parser; 30 UsbMidiDescriptorParser parser;
31 std::vector<UsbMidiJack> jacks; 31 std::vector<UsbMidiJack> jacks;
32 // Jack id=1 is found in a CS_ENDPOINT descriptor, but there is no definition 32 // Jack id=1 is found in a CS_ENDPOINT descriptor, but there is no definition
33 // for the jack. 33 // for the jack.
34 uint8 data[] = { 34 uint8_t data[] = {
35 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07, 35 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07, 0x24,
36 0x24, 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01, 36 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01, 0x01,
37 0x01,
38 }; 37 };
39 EXPECT_FALSE(parser.Parse(nullptr, data, arraysize(data), &jacks)); 38 EXPECT_FALSE(parser.Parse(nullptr, data, arraysize(data), &jacks));
40 EXPECT_TRUE(jacks.empty()); 39 EXPECT_TRUE(jacks.empty());
41 } 40 }
42 41
43 TEST(UsbMidiDescriptorParserTest, 42 TEST(UsbMidiDescriptorParserTest,
44 JacksShouldBeIgnoredWhenParserIsNotParsingMidiInterface) { 43 JacksShouldBeIgnoredWhenParserIsNotParsingMidiInterface) {
45 UsbMidiDescriptorParser parser; 44 UsbMidiDescriptorParser parser;
46 std::vector<UsbMidiJack> jacks; 45 std::vector<UsbMidiJack> jacks;
47 // a NON-MIDI INTERFACE descriptor followed by ENDPOINT and CS_ENDPOINT 46 // a NON-MIDI INTERFACE descriptor followed by ENDPOINT and CS_ENDPOINT
48 // descriptors (Compare with the previous test case). 47 // descriptors (Compare with the previous test case).
49 uint8 data[] = { 48 uint8_t data[] = {
50 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x02, 0x00, 0x00, 0x07, 49 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x02, 0x00, 0x00, 0x07, 0x24,
51 0x24, 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01, 50 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01, 0x01,
52 0x01,
53 }; 51 };
54 EXPECT_TRUE(parser.Parse(nullptr, data, arraysize(data), &jacks)); 52 EXPECT_TRUE(parser.Parse(nullptr, data, arraysize(data), &jacks));
55 EXPECT_TRUE(jacks.empty()); 53 EXPECT_TRUE(jacks.empty());
56 } 54 }
57 55
58 TEST(UsbMidiDescriptorParserTest, Parse) { 56 TEST(UsbMidiDescriptorParserTest, Parse) {
59 UsbMidiDescriptorParser parser; 57 UsbMidiDescriptorParser parser;
60 std::vector<UsbMidiJack> jacks; 58 std::vector<UsbMidiJack> jacks;
61 // A complete device descriptor. 59 // A complete device descriptor.
62 uint8 data[] = { 60 uint8_t data[] = {
63 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 61 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a, 0x2d, 0x75,
64 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 62 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02, 0x75, 0x00, 0x02, 0x01,
65 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 63 0x00, 0x80, 0x30, 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00,
66 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00, 64 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01,
67 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02, 65 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
68 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51, 66 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 0x01, 0x03,
69 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02, 67 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 0x24, 0x03, 0x01, 0x07,
70 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09, 68 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 0x03, 0x02, 0x04, 0x01, 0x02, 0x01,
71 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24, 69 0x00, 0x09, 0x24, 0x03, 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05,
72 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03, 70 0x02, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
73 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02, 71 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05, 0x25,
74 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02, 72 0x01, 0x01, 0x07,
75 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
76 0x05, 0x25, 0x01, 0x01, 0x07,
77 }; 73 };
78 EXPECT_TRUE(parser.Parse(nullptr, data, arraysize(data), &jacks)); 74 EXPECT_TRUE(parser.Parse(nullptr, data, arraysize(data), &jacks));
79 ASSERT_EQ(3u, jacks.size()); 75 ASSERT_EQ(3u, jacks.size());
80 76
81 EXPECT_EQ(2u, jacks[0].jack_id); 77 EXPECT_EQ(2u, jacks[0].jack_id);
82 EXPECT_EQ(0u, jacks[0].cable_number); 78 EXPECT_EQ(0u, jacks[0].cable_number);
83 EXPECT_EQ(2u, jacks[0].endpoint_number()); 79 EXPECT_EQ(2u, jacks[0].endpoint_number());
84 EXPECT_EQ(UsbMidiJack::DIRECTION_OUT, jacks[0].direction()); 80 EXPECT_EQ(UsbMidiJack::DIRECTION_OUT, jacks[0].direction());
85 EXPECT_EQ(nullptr, jacks[0].device); 81 EXPECT_EQ(nullptr, jacks[0].device);
86 82
(...skipping 12 matching lines...) Expand all
99 95
100 TEST(UsbMidiDescriptorParserTest, ParseDeviceInfoEmpty) { 96 TEST(UsbMidiDescriptorParserTest, ParseDeviceInfoEmpty) {
101 UsbMidiDescriptorParser parser; 97 UsbMidiDescriptorParser parser;
102 UsbMidiDescriptorParser::DeviceInfo info; 98 UsbMidiDescriptorParser::DeviceInfo info;
103 EXPECT_FALSE(parser.ParseDeviceInfo(nullptr, 0, &info)); 99 EXPECT_FALSE(parser.ParseDeviceInfo(nullptr, 0, &info));
104 } 100 }
105 101
106 TEST(UsbMidiDescriptorParserTest, ParseDeviceInfo) { 102 TEST(UsbMidiDescriptorParserTest, ParseDeviceInfo) {
107 UsbMidiDescriptorParser parser; 103 UsbMidiDescriptorParser parser;
108 UsbMidiDescriptorParser::DeviceInfo info; 104 UsbMidiDescriptorParser::DeviceInfo info;
109 uint8 data[] = { 105 uint8_t data[] = {
110 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, 0x23, 106 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01,
111 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x0a, 107 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x0a,
112 }; 108 };
113 EXPECT_TRUE(parser.ParseDeviceInfo(data, arraysize(data), &info)); 109 EXPECT_TRUE(parser.ParseDeviceInfo(data, arraysize(data), &info));
114 110
115 EXPECT_EQ(0x2301, info.vendor_id); 111 EXPECT_EQ(0x2301, info.vendor_id);
116 EXPECT_EQ(0x6745, info.product_id); 112 EXPECT_EQ(0x6745, info.product_id);
117 EXPECT_EQ(0xab89, info.bcd_device_version); 113 EXPECT_EQ(0xab89, info.bcd_device_version);
118 EXPECT_EQ(0xcd, info.manufacturer_index); 114 EXPECT_EQ(0xcd, info.manufacturer_index);
119 EXPECT_EQ(0xef, info.product_index); 115 EXPECT_EQ(0xef, info.product_index);
120 } 116 }
121 117
122 } // namespace 118 } // namespace
123 119
124 } // namespace midi 120 } // namespace midi
125 } // namespace media 121 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698