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

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 6 years, 11 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 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..4961e5368d924fafcb2154781c4ec4334a34e179
--- /dev/null
+++ b/media/midi/usb_midi_descriptor_parser_unittest.cc
@@ -0,0 +1,101 @@
+// Copyright 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;
+ std::vector<UsbMidiJack> jacks;
+ EXPECT_TRUE(parser.Parse(NULL, NULL, 0, &jacks));
+ EXPECT_TRUE(jacks.empty());
+}
+
+TEST(UsbMidiDescriptorParserTest, InvalidSize) {
+ UsbMidiDescriptorParser parser;
+ std::vector<UsbMidiJack> jacks;
+ uint8 data[] = {0x04};
+ EXPECT_FALSE(parser.Parse(NULL, data, arraysize(data), &jacks));
+ EXPECT_TRUE(jacks.empty());
+}
+
+TEST(UsbMidiDescriptorParserTest, NonExistingJackIsAssociated) {
+ UsbMidiDescriptorParser parser;
+ std::vector<UsbMidiJack> jacks;
+ // 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_FALSE(parser.Parse(NULL, data, arraysize(data), &jacks));
+ EXPECT_TRUE(jacks.empty());
+}
+
+TEST(UsbMidiDescriptorParserTest,
+ JacksShouldBeIgnoredWhenParserIsNotParsingMIDIInterface) {
+ UsbMidiDescriptorParser parser;
+ std::vector<UsbMidiJack> jacks;
+ // a NON-MIDI INTERFACE descriptor followed by ENDPOINT and CS_ENDPOINT
+ // descriptors (Compare with the previous test case).
+ uint8 data[] = {
+ 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x02, 0x00, 0x00, 0x07,
+ 0x24, 0x01, 0x00, 0x01, 0x07, 0x00, 0x05, 0x25, 0x01, 0x01,
+ 0x01,
+ };
+ EXPECT_TRUE(parser.Parse(NULL, data, arraysize(data), &jacks));
+ EXPECT_TRUE(jacks.empty());
+}
+
+TEST(UsbMidiDescriptorParserTest, Parse) {
+ UsbMidiDescriptorParser parser;
+ std::vector<UsbMidiJack> jacks;
+ // 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.Parse(NULL, data, arraysize(data), &jacks));
+ ASSERT_EQ(3u, jacks.size());
+
+ EXPECT_EQ(2u, jacks[0].jack_id);
+ EXPECT_EQ(0u, jacks[0].cable_number);
+ EXPECT_EQ(2u, jacks[0].endpoint_number());
+ EXPECT_EQ(UsbMidiJack::OUT, jacks[0].direction());
+ EXPECT_EQ(NULL, jacks[0].device);
+
+ EXPECT_EQ(3u, jacks[1].jack_id);
+ EXPECT_EQ(1u, jacks[1].cable_number);
+ EXPECT_EQ(2u, jacks[1].endpoint_number());
+ EXPECT_EQ(UsbMidiJack::OUT, jacks[1].direction());
+ EXPECT_EQ(NULL, jacks[1].device);
+
+ EXPECT_EQ(7u, jacks[2].jack_id);
+ EXPECT_EQ(0u, jacks[2].cable_number);
+ EXPECT_EQ(2u, jacks[2].endpoint_number());
+ EXPECT_EQ(UsbMidiJack::IN, jacks[2].direction());
+ EXPECT_EQ(NULL, jacks[2].device);
+}
+
+} // namespace
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698