Index: media/midi/usb_midi_output_stream_unittest.cc |
diff --git a/media/midi/usb_midi_output_stream_unittest.cc b/media/midi/usb_midi_output_stream_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..09cefa418b03c6bb8f55fa4e57acc0fb5c383de1 |
--- /dev/null |
+++ b/media/midi/usb_midi_output_stream_unittest.cc |
@@ -0,0 +1,418 @@ |
+// Copyright 2014 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_output_stream.h" |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "media/midi/usb_midi_device.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace media { |
+ |
+namespace { |
+ |
+using ::testing::InSequence; |
+using ::testing::StrictMock; |
+ |
+typedef ::testing::MockFunction<void(int)> Checkpoint; // NOLINT |
+ |
+template<typename T, size_t N> |
+std::vector<T> ToVector(const T((&array)[N])) { |
+ return std::vector<T>(array, array + N); |
+} |
+ |
+class MockUsbMidiDevice : public UsbMidiDevice { |
+ public: |
+ virtual ~MockUsbMidiDevice() {} |
+ MOCK_METHOD0(GetDescriptor, std::vector<uint8>()); |
+ MOCK_METHOD2(Send, void(int, const std::vector<uint8>&)); |
+}; |
+ |
+class UsbMidiOutputStreamTest : public ::testing::Test { |
+ protected: |
+ UsbMidiOutputStreamTest() { |
+ UsbMidiJack jack(&device_, 1, 2, 4); |
+ stream_.reset(new UsbMidiOutputStream(jack)); |
+ } |
+ |
+ StrictMock<MockUsbMidiDevice> device_; |
scherkus (not reviewing)
2014/01/21 21:25:25
think you can update this test to use string-based
yhirano
2014/01/22 02:33:31
Done.
|
+ scoped_ptr<UsbMidiOutputStream> stream_; |
+}; |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendEmpty) { |
+ stream_->Send(std::vector<uint8>()); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendNoteOn) { |
+ uint8 data[] = { 0x90, 0x45, 0x7f}; |
+ uint8 expected[] = { 0x29, 0x90, 0x45, 0x7f }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendNoteOnPending) { |
+ uint8 expected[] = { 0x29, 0x90, 0x45, 0x7f, }; |
+ Checkpoint checkpoint; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(checkpoint, Call(0)); |
+ EXPECT_CALL(checkpoint, Call(1)); |
+ EXPECT_CALL(checkpoint, Call(2)); |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ EXPECT_CALL(checkpoint, Call(3)); |
+ EXPECT_CALL(checkpoint, Call(4)); |
+ EXPECT_CALL(checkpoint, Call(5)); |
+ } |
+ |
+ checkpoint.Call(0); |
+ stream_->Send(std::vector<uint8>(1, 0x90)); |
+ checkpoint.Call(1); |
+ stream_->Send(std::vector<uint8>(1, 0x45)); |
+ checkpoint.Call(2); |
+ stream_->Send(std::vector<uint8>(1, 0x7f)); |
+ checkpoint.Call(3); |
+ stream_->Send(std::vector<uint8>(1, 0x90)); |
+ checkpoint.Call(4); |
+ stream_->Send(std::vector<uint8>(1, 0x45)); |
+ checkpoint.Call(5); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendNoteOnBurst) { |
+ uint8 data1[] = { 0x90, }; |
+ uint8 data2[] = { 0x45, 0x7f, 0x90, 0x45, 0x71, 0x90, 0x45, 0x72, 0x90, }; |
+ uint8 expected[] = { |
+ 0x29, 0x90, 0x45, 0x7f, |
+ 0x29, 0x90, 0x45, 0x71, |
+ 0x29, 0x90, 0x45, 0x72, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data1)); |
+ stream_->Send(ToVector(data2)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendNoteOff) { |
+ uint8 data[] = { 0x80, 0x33, 0x44, }; |
+ uint8 expected[] = { |
+ 0x28, 0x80, 0x33, 0x44, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendPolyphonicKeyPress) { |
+ uint8 data[] = { 0xa0, 0x33, 0x44, }; |
+ uint8 expected[] = { |
+ 0x2a, 0xa0, 0x33, 0x44, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendControlChange) { |
+ uint8 data[] = { 0xb7, 0x33, 0x44, }; |
+ uint8 expected[] = { |
+ 0x2b, 0xb7, 0x33, 0x44, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendProgramChange) { |
+ uint8 data[] = { 0xc2, 0x33, }; |
+ uint8 expected[] = { |
+ 0x2c, 0xc2, 0x33, 0x00, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendChannelPressure) { |
+ uint8 data[] = { 0xd1, 0x33, 0x44, }; |
+ uint8 expected[] = { |
+ 0x2d, 0xd1, 0x33, 0x44, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendPitchWheelChange) { |
+ uint8 data[] = { 0xe4, 0x33, 0x44, }; |
+ uint8 expected[] = { |
+ 0x2e, 0xe4, 0x33, 0x44, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendTwoByteSysEx) { |
+ uint8 data[] = { 0xf0, 0xf7, }; |
+ uint8 expected[] = { |
+ 0x26, 0xf0, 0xf7, 0x00, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendThreeByteSysEx) { |
+ uint8 data[] = { 0xf0, 0x4f, 0xf7, }; |
+ uint8 expected[] = { |
+ 0x27, 0xf0, 0x4f, 0xf7, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendFourByteSysEx) { |
+ uint8 data[] = { 0xf0, 0x00, 0x01, 0xf7, }; |
+ uint8 expected[] = { |
+ 0x24, 0xf0, 0x00, 0x01, |
+ 0x25, 0xf7, 0x00, 0x00, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendFiveByteSysEx) { |
+ uint8 data[] = { 0xf0, 0x00, 0x01, 0x02, 0xf7, }; |
+ uint8 expected[] = { |
+ 0x24, 0xf0, 0x00, 0x01, |
+ 0x26, 0x02, 0xf7, 0x00, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendSixByteSysEx) { |
+ uint8 data[] = { 0xf0, 0x00, 0x01, 0x02, 0x03, 0xf7, }; |
+ uint8 expected[] = { |
+ 0x24, 0xf0, 0x00, 0x01, |
+ 0x27, 0x02, 0x03, 0xf7, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendPendingSysEx) { |
+ uint8 data1[] = { 0xf0, 0x33, }; |
+ uint8 data2[] = { 0x44, 0x55, 0x66, }; |
+ uint8 data3[] = { 0x77, 0x88, 0x99, 0xf7, }; |
+ |
+ uint8 expected1[] = { 0x24, 0xf0, 0x33, 0x44, }; |
+ uint8 expected2[] = { |
+ 0x24, 0x55, 0x66, 0x77, |
+ 0x27, 0x88, 0x99, 0xf7, |
+ }; |
+ |
+ Checkpoint checkpoint; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(checkpoint, Call(0)); |
+ EXPECT_CALL(checkpoint, Call(1)); |
+ EXPECT_CALL(device_, Send(4, ToVector(expected1))); |
+ EXPECT_CALL(checkpoint, Call(2)); |
+ EXPECT_CALL(device_, Send(4, ToVector(expected2))); |
+ EXPECT_CALL(checkpoint, Call(3)); |
+ } |
+ |
+ checkpoint.Call(0); |
+ stream_->Send(ToVector(data1)); |
+ checkpoint.Call(1); |
+ stream_->Send(ToVector(data2)); |
+ checkpoint.Call(2); |
+ stream_->Send(ToVector(data3)); |
+ checkpoint.Call(3); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendNoteOnAfterSysEx) { |
+ uint8 data[] = { 0xf0, 0x00, 0x01, 0x02, 0x03, 0xf7, 0x90, 0x44, 0x33, }; |
+ uint8 expected[] = { |
+ 0x24, 0xf0, 0x00, 0x01, |
+ 0x27, 0x02, 0x03, 0xf7, |
+ 0x29, 0x90, 0x44, 0x33, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendTimeCodeQuarterFrame) { |
+ uint8 data[] = { 0xf1, 0x22, }; |
+ uint8 expected[] = { 0x22, 0xf1, 0x22, 0x00, }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendSongPositionPointer) { |
+ uint8 data[] = { 0xf2, 0x22, 0x33, }; |
+ uint8 expected[] = { 0x23, 0xf2, 0x22, 0x33, }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendSongSelect) { |
+ uint8 data[] = { 0xf3, 0x22, }; |
+ uint8 expected[] = { 0x22, 0xf3, 0x22, 0x00, }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, TuneRequest) { |
+ uint8 data[] = { 0xf6, }; |
+ uint8 expected[] = { 0x25, 0xf6, 0x00, 0x00, }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendSongPositionPointerPending) { |
+ uint8 data1[] = { 0xf2, 0x22, }; |
+ uint8 data2[] = { 0x33, }; |
+ uint8 expected[] = { 0x23, 0xf2, 0x22, 0x33, }; |
+ |
+ Checkpoint checkpoint; |
+ { |
+ InSequence s; |
+ EXPECT_CALL(checkpoint, Call(0)); |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data1)); |
+ checkpoint.Call(0); |
+ stream_->Send(ToVector(data2)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendRealTimeMessages) { |
+ uint8 data[] = { 0xf8, 0xfa, 0xfb, 0xfc, 0xfe, 0xff, }; |
+ uint8 expected[] = { |
+ 0x25, 0xf8, 0x00, 0x00, |
+ 0x25, 0xfa, 0x00, 0x00, |
+ 0x25, 0xfb, 0x00, 0x00, |
+ 0x25, 0xfc, 0x00, 0x00, |
+ 0x25, 0xfe, 0x00, 0x00, |
+ 0x25, 0xff, 0x00, 0x00, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+TEST_F(UsbMidiOutputStreamTest, SendRealTimeInSysExMessage) { |
+ uint8 data[] = { |
+ 0xf0, 0x00, 0x01, 0x02, |
+ 0xf8, 0xfa, |
+ 0x03, 0xf7, |
+ }; |
+ uint8 expected[] = { |
+ 0x24, 0xf0, 0x00, 0x01, |
+ 0x25, 0xf8, 0x00, 0x00, |
+ 0x25, 0xfa, 0x00, 0x00, |
+ 0x27, 0x02, 0x03, 0xf7, |
+ }; |
+ |
+ { |
+ InSequence s; |
+ EXPECT_CALL(device_, Send(4, ToVector(expected))); |
+ } |
+ |
+ stream_->Send(ToVector(data)); |
+} |
+ |
+} // namespace |
+ |
+} // namespace media |