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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: media/midi/usb_midi_descriptor_parser_unittest.cc
diff --git a/media/midi/usb_midi_descriptor_parser_unittest.cc b/media/midi/usb_midi_descriptor_parser_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f9d71af991b60c02980740c59344e2abf9aa46d9
--- /dev/null
+++ b/media/midi/usb_midi_descriptor_parser_unittest.cc
@@ -0,0 +1,99 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/midi/usb_midi_descriptor_parser.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media {
+
+namespace {
+
+TEST(UsbMidiDescriptorParserTest, ParseEmpty) {
+ UsbMidiDescriptorParser parser;
+ EXPECT_TRUE(parser.jacks().empty());
+ EXPECT_TRUE(parser.Parse(NULL, NULL, 0));
+ EXPECT_TRUE(parser.jacks().empty());
+}
+
+TEST(UsbMidiDescriptorParserTest, InvalidSize) {
+ UsbMidiDescriptorParser parser;
+ uint8 data[] = {0x04};
+ EXPECT_TRUE(parser.jacks().empty());
+ EXPECT_FALSE(parser.Parse(NULL, data, arraysize(data)));
+ EXPECT_TRUE(parser.jacks().empty());
+}
+
+TEST(UsbMidiDescriptorParserTest, NonExistingJackIsAssociated) {
+ UsbMidiDescriptorParser parser;
+ // Jack id=1 is found in a CS_ENDPOINT descriptor, but there is no definition
+ // for the jack.
+ uint8 data[] = {
+ 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, 0x07,
+ 0x24, 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01,
+ 0x01,
+ };
+ EXPECT_TRUE(parser.jacks().empty());
+ EXPECT_FALSE(parser.Parse(NULL, data, arraysize(data)));
+ EXPECT_TRUE(parser.jacks().empty());
+}
+
+TEST(UsbMidiDescriptorParserTest,
+ JacksShouldBeIgnoredWhenParserIsNotParsingAnInterface) {
+ UsbMidiDescriptorParser parser;
+ // ENDPOINT and CS_ENDPOINT descriptors without an INTERFACE descriptor.
+ uint8 data[] = {
+ 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x05,
+ 0x25, 0x01, 0x01, 0x07,
+ };
+ EXPECT_TRUE(parser.jacks().empty());
+ EXPECT_TRUE(parser.Parse(NULL, data, arraysize(data)));
+ EXPECT_TRUE(parser.jacks().empty());
+}
+
+TEST(UsbMidiDescriptorParserTest, Parse) {
+ UsbMidiDescriptorParser parser;
+ // A complete device descriptor.
+ uint8 data[] = {
+ 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08, 0x86, 0x1a,
+ 0x2d, 0x75, 0x54, 0x02, 0x00, 0x02, 0x00, 0x01, 0x09, 0x02,
+ 0x75, 0x00, 0x02, 0x01, 0x00, 0x80, 0x30, 0x09, 0x04, 0x00,
+ 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x24, 0x01, 0x00,
+ 0x01, 0x09, 0x00, 0x01, 0x01, 0x09, 0x04, 0x01, 0x00, 0x02,
+ 0x01, 0x03, 0x00, 0x00, 0x07, 0x24, 0x01, 0x00, 0x01, 0x51,
+ 0x00, 0x06, 0x24, 0x02, 0x01, 0x02, 0x00, 0x06, 0x24, 0x02,
+ 0x01, 0x03, 0x00, 0x06, 0x24, 0x02, 0x02, 0x06, 0x00, 0x09,
+ 0x24, 0x03, 0x01, 0x07, 0x01, 0x06, 0x01, 0x00, 0x09, 0x24,
+ 0x03, 0x02, 0x04, 0x01, 0x02, 0x01, 0x00, 0x09, 0x24, 0x03,
+ 0x02, 0x05, 0x01, 0x03, 0x01, 0x00, 0x09, 0x05, 0x02, 0x02,
+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x06, 0x25, 0x01, 0x02, 0x02,
+ 0x03, 0x09, 0x05, 0x82, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
+ 0x05, 0x25, 0x01, 0x01, 0x07,
+ };
+ EXPECT_TRUE(parser.jacks().empty());
+ EXPECT_TRUE(parser.Parse(NULL, data, arraysize(data)));
+ ASSERT_EQ(3u, parser.jacks().size());
+
+ EXPECT_EQ(2u, parser.jacks()[0].jack_id);
+ EXPECT_EQ(0u, parser.jacks()[0].cable_number);
+ EXPECT_EQ(2u, parser.jacks()[0].GetEndpointNumber());
+ EXPECT_EQ(UsbMidiJack::OUT, parser.jacks()[0].GetDirection());
+ EXPECT_EQ(NULL, parser.jacks()[0].device);
+
+ EXPECT_EQ(3u, parser.jacks()[1].jack_id);
+ EXPECT_EQ(1u, parser.jacks()[1].cable_number);
+ EXPECT_EQ(2u, parser.jacks()[1].GetEndpointNumber());
+ EXPECT_EQ(UsbMidiJack::OUT, parser.jacks()[1].GetDirection());
+ EXPECT_EQ(NULL, parser.jacks()[1].device);
+
+ EXPECT_EQ(7u, parser.jacks()[2].jack_id);
+ EXPECT_EQ(0u, parser.jacks()[2].cable_number);
+ EXPECT_EQ(2u, parser.jacks()[2].GetEndpointNumber());
+ EXPECT_EQ(UsbMidiJack::IN, parser.jacks()[2].GetDirection());
+ EXPECT_EQ(NULL, parser.jacks()[2].device);
+}
+
+} // namespace
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698