Don't send a SHChangeNotify for creating an app icon when creating a shortcut.
[chromium-blink-merge.git] / media / midi / midi_message_queue_unittest.cc
blob08f1a0bf7487ab25e26b72fa135bbe53fd2441ff
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/midi/midi_message_queue.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace media {
10 namespace {
12 const uint8 kGMOn[] = { 0xf0, 0x7e, 0x7f, 0x09, 0x01, 0xf7 };
13 const uint8 kGSOn[] = {
14 0xf0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7f, 0x00, 0x41, 0xf7,
16 const uint8 kNoteOn[] = { 0x90, 0x3c, 0x7f };
17 const uint8 kNoteOnWithRunningStatus[] = {
18 0x90, 0x3c, 0x7f, 0x3c, 0x7f, 0x3c, 0x7f,
20 const uint8 kChannelPressure[] = { 0xd0, 0x01 };
21 const uint8 kChannelPressureWithRunningStatus[] = {
22 0xd0, 0x01, 0x01, 0x01,
24 const uint8 kTimingClock[] = { 0xf8 };
25 const uint8 kMTCFrame[] = { 0xf1, 0x00 };
26 const uint8 kBrokenData1[] = { 0x90 };
27 const uint8 kBrokenData2[] = { 0xf7 };
28 const uint8 kBrokenData3[] = { 0xf2, 0x00 };
29 const uint8 kDataByte0[] = { 0x00 };
31 template <typename T, size_t N>
32 void Add(MidiMessageQueue* queue, const T(&array)[N]) {
33 queue->Add(array, N);
36 template <typename T, size_t N>
37 ::testing::AssertionResult ExpectEqualSequence(
38 const char* expr1, const char* expr2,
39 const T(&expected)[N], const std::vector<T>& actual) {
40 if (actual.size() != N) {
41 return ::testing::AssertionFailure()
42 << "expected: " << ::testing::PrintToString(expected)
43 << ", actual: " << ::testing::PrintToString(actual);
45 for (size_t i = 0; i < N; ++i) {
46 if (expected[i] != actual[i]) {
47 return ::testing::AssertionFailure()
48 << "expected: " << ::testing::PrintToString(expected)
49 << ", actual: " << ::testing::PrintToString(actual);
52 return ::testing::AssertionSuccess();
55 #define EXPECT_MESSAGE(expected, actual) \
56 EXPECT_PRED_FORMAT2(ExpectEqualSequence, expected, actual)
58 TEST(MidiMessageQueueTest, EmptyData) {
59 MidiMessageQueue queue(false);
60 std::vector<uint8> message;
61 queue.Get(&message);
62 EXPECT_TRUE(message.empty());
65 TEST(MidiMessageQueueTest, RunningStatusDisabled) {
66 MidiMessageQueue queue(false);
67 Add(&queue, kGMOn);
68 Add(&queue, kBrokenData1);
69 Add(&queue, kNoteOnWithRunningStatus);
70 Add(&queue, kBrokenData2);
71 Add(&queue, kChannelPressureWithRunningStatus);
72 Add(&queue, kBrokenData3);
73 Add(&queue, kNoteOn);
74 Add(&queue, kBrokenData1);
75 Add(&queue, kGSOn);
76 Add(&queue, kBrokenData2);
77 Add(&queue, kTimingClock);
78 Add(&queue, kBrokenData3);
80 std::vector<uint8> message;
81 queue.Get(&message);
82 EXPECT_MESSAGE(kGMOn, message);
83 queue.Get(&message);
84 EXPECT_MESSAGE(kNoteOn, message) << "Running status should be ignored";
85 queue.Get(&message);
86 EXPECT_MESSAGE(kChannelPressure, message)
87 << "Running status should be ignored";
88 queue.Get(&message);
89 EXPECT_MESSAGE(kNoteOn, message);
90 queue.Get(&message);
91 EXPECT_MESSAGE(kGSOn, message);
92 queue.Get(&message);
93 EXPECT_MESSAGE(kTimingClock, message);
94 queue.Get(&message);
95 EXPECT_TRUE(message.empty());
98 TEST(MidiMessageQueueTest, RunningStatusEnabled) {
99 MidiMessageQueue queue(true);
100 Add(&queue, kGMOn);
101 Add(&queue, kBrokenData1);
102 Add(&queue, kNoteOnWithRunningStatus);
103 Add(&queue, kBrokenData2);
104 Add(&queue, kChannelPressureWithRunningStatus);
105 Add(&queue, kBrokenData3);
106 Add(&queue, kNoteOn);
107 Add(&queue, kBrokenData1);
108 Add(&queue, kGSOn);
109 Add(&queue, kBrokenData2);
110 Add(&queue, kTimingClock);
111 Add(&queue, kDataByte0);
113 std::vector<uint8> message;
114 queue.Get(&message);
115 EXPECT_MESSAGE(kGMOn, message);
116 queue.Get(&message);
117 EXPECT_MESSAGE(kNoteOn, message);
118 queue.Get(&message);
119 EXPECT_MESSAGE(kNoteOn, message)
120 << "Running status should be converted into a canonical MIDI message";
121 queue.Get(&message);
122 EXPECT_MESSAGE(kNoteOn, message)
123 << "Running status should be converted into a canonical MIDI message";
124 queue.Get(&message);
125 EXPECT_MESSAGE(kChannelPressure, message);
126 queue.Get(&message);
127 EXPECT_MESSAGE(kChannelPressure, message)
128 << "Running status should be converted into a canonical MIDI message";
129 queue.Get(&message);
130 EXPECT_MESSAGE(kChannelPressure, message)
131 << "Running status should be converted into a canonical MIDI message";
132 queue.Get(&message);
133 EXPECT_MESSAGE(kNoteOn, message);
134 queue.Get(&message);
135 EXPECT_MESSAGE(kGSOn, message);
136 queue.Get(&message);
137 EXPECT_MESSAGE(kTimingClock, message);
138 queue.Get(&message);
139 EXPECT_TRUE(message.empty())
140 << "Running status must not be applied to real time messages";
143 TEST(MidiMessageQueueTest, RunningStatusEnabledWithRealTimeEvent) {
144 MidiMessageQueue queue(true);
145 const uint8 kNoteOnWithRunningStatusWithTimingClock[] = {
146 0x90, 0xf8, 0x3c, 0xf8, 0x7f, 0xf8, 0x3c, 0xf8, 0x7f, 0xf8, 0x3c, 0xf8,
147 0x7f,
149 Add(&queue, kNoteOnWithRunningStatusWithTimingClock);
150 std::vector<uint8> message;
151 queue.Get(&message);
152 EXPECT_MESSAGE(kTimingClock, message);
153 queue.Get(&message);
154 EXPECT_MESSAGE(kTimingClock, message);
155 queue.Get(&message);
156 EXPECT_MESSAGE(kNoteOn, message);
157 queue.Get(&message);
158 EXPECT_MESSAGE(kTimingClock, message);
159 queue.Get(&message);
160 EXPECT_MESSAGE(kTimingClock, message);
161 queue.Get(&message);
162 EXPECT_MESSAGE(kNoteOn, message);
163 queue.Get(&message);
164 EXPECT_MESSAGE(kTimingClock, message);
165 queue.Get(&message);
166 EXPECT_MESSAGE(kTimingClock, message);
167 queue.Get(&message);
168 EXPECT_MESSAGE(kNoteOn, message);
169 queue.Get(&message);
170 EXPECT_TRUE(message.empty());
173 TEST(MidiMessageQueueTest, RunningStatusEnabledWithSystemCommonMessage) {
174 MidiMessageQueue queue(true);
175 const uint8 kNoteOnWithRunningStatusWithSystemCommonMessage[] = {
176 0x90, 0x3c, 0x7f, 0xf1, 0x00, 0x3c, 0x7f, 0xf8, 0x90, 0x3c, 0x7f,
178 Add(&queue, kNoteOnWithRunningStatusWithSystemCommonMessage);
179 std::vector<uint8> message;
180 queue.Get(&message);
181 EXPECT_MESSAGE(kNoteOn, message);
182 queue.Get(&message);
183 EXPECT_MESSAGE(kMTCFrame, message);
184 queue.Get(&message);
185 EXPECT_MESSAGE(kTimingClock, message) << "Running status should be reset";
186 queue.Get(&message);
187 EXPECT_MESSAGE(kNoteOn, message);
188 queue.Get(&message);
189 EXPECT_TRUE(message.empty());
192 } // namespace
193 } // namespace media