Remove INJECT_EVENTS permissions from test APKs.
[chromium-blink-merge.git] / media / midi / midi_message_queue_unittest.cc
blobd25a692ad32471096e9de4ba2cfa7eda0755bb80
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 midi {
11 namespace {
13 const uint8 kGMOn[] = { 0xf0, 0x7e, 0x7f, 0x09, 0x01, 0xf7 };
14 const uint8 kGSOn[] = {
15 0xf0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7f, 0x00, 0x41, 0xf7,
17 const uint8 kNoteOn[] = { 0x90, 0x3c, 0x7f };
18 const uint8 kNoteOnWithRunningStatus[] = {
19 0x90, 0x3c, 0x7f, 0x3c, 0x7f, 0x3c, 0x7f,
21 const uint8 kChannelPressure[] = { 0xd0, 0x01 };
22 const uint8 kChannelPressureWithRunningStatus[] = {
23 0xd0, 0x01, 0x01, 0x01,
25 const uint8 kTimingClock[] = { 0xf8 };
26 const uint8 kMTCFrame[] = { 0xf1, 0x00 };
27 const uint8 kBrokenData1[] = { 0x90 };
28 const uint8 kBrokenData2[] = { 0xf7 };
29 const uint8 kBrokenData3[] = { 0xf2, 0x00 };
30 const uint8 kDataByte0[] = { 0x00 };
32 template <typename T, size_t N>
33 void Add(MidiMessageQueue* queue, const T(&array)[N]) {
34 queue->Add(array, N);
37 template <typename T, size_t N>
38 ::testing::AssertionResult ExpectEqualSequence(
39 const char* expr1, const char* expr2,
40 const T(&expected)[N], const std::vector<T>& actual) {
41 if (actual.size() != N) {
42 return ::testing::AssertionFailure()
43 << "expected: " << ::testing::PrintToString(expected)
44 << ", actual: " << ::testing::PrintToString(actual);
46 for (size_t i = 0; i < N; ++i) {
47 if (expected[i] != actual[i]) {
48 return ::testing::AssertionFailure()
49 << "expected: " << ::testing::PrintToString(expected)
50 << ", actual: " << ::testing::PrintToString(actual);
53 return ::testing::AssertionSuccess();
56 #define EXPECT_MESSAGE(expected, actual) \
57 EXPECT_PRED_FORMAT2(ExpectEqualSequence, expected, actual)
59 TEST(MidiMessageQueueTest, EmptyData) {
60 MidiMessageQueue queue(false);
61 std::vector<uint8> message;
62 queue.Get(&message);
63 EXPECT_TRUE(message.empty());
66 TEST(MidiMessageQueueTest, RunningStatusDisabled) {
67 MidiMessageQueue queue(false);
68 Add(&queue, kGMOn);
69 Add(&queue, kBrokenData1);
70 Add(&queue, kNoteOnWithRunningStatus);
71 Add(&queue, kBrokenData2);
72 Add(&queue, kChannelPressureWithRunningStatus);
73 Add(&queue, kBrokenData3);
74 Add(&queue, kNoteOn);
75 Add(&queue, kBrokenData1);
76 Add(&queue, kGSOn);
77 Add(&queue, kBrokenData2);
78 Add(&queue, kTimingClock);
79 Add(&queue, kBrokenData3);
81 std::vector<uint8> message;
82 queue.Get(&message);
83 EXPECT_MESSAGE(kGMOn, message);
84 queue.Get(&message);
85 EXPECT_MESSAGE(kNoteOn, message) << "Running status should be ignored";
86 queue.Get(&message);
87 EXPECT_MESSAGE(kChannelPressure, message)
88 << "Running status should be ignored";
89 queue.Get(&message);
90 EXPECT_MESSAGE(kNoteOn, message);
91 queue.Get(&message);
92 EXPECT_MESSAGE(kGSOn, message);
93 queue.Get(&message);
94 EXPECT_MESSAGE(kTimingClock, message);
95 queue.Get(&message);
96 EXPECT_TRUE(message.empty());
99 TEST(MidiMessageQueueTest, RunningStatusEnabled) {
100 MidiMessageQueue queue(true);
101 Add(&queue, kGMOn);
102 Add(&queue, kBrokenData1);
103 Add(&queue, kNoteOnWithRunningStatus);
104 Add(&queue, kBrokenData2);
105 Add(&queue, kChannelPressureWithRunningStatus);
106 Add(&queue, kBrokenData3);
107 Add(&queue, kNoteOn);
108 Add(&queue, kBrokenData1);
109 Add(&queue, kGSOn);
110 Add(&queue, kBrokenData2);
111 Add(&queue, kTimingClock);
112 Add(&queue, kDataByte0);
114 std::vector<uint8> message;
115 queue.Get(&message);
116 EXPECT_MESSAGE(kGMOn, message);
117 queue.Get(&message);
118 EXPECT_MESSAGE(kNoteOn, message);
119 queue.Get(&message);
120 EXPECT_MESSAGE(kNoteOn, message)
121 << "Running status should be converted into a canonical MIDI message";
122 queue.Get(&message);
123 EXPECT_MESSAGE(kNoteOn, message)
124 << "Running status should be converted into a canonical MIDI message";
125 queue.Get(&message);
126 EXPECT_MESSAGE(kChannelPressure, message);
127 queue.Get(&message);
128 EXPECT_MESSAGE(kChannelPressure, message)
129 << "Running status should be converted into a canonical MIDI message";
130 queue.Get(&message);
131 EXPECT_MESSAGE(kChannelPressure, message)
132 << "Running status should be converted into a canonical MIDI message";
133 queue.Get(&message);
134 EXPECT_MESSAGE(kNoteOn, message);
135 queue.Get(&message);
136 EXPECT_MESSAGE(kGSOn, message);
137 queue.Get(&message);
138 EXPECT_MESSAGE(kTimingClock, message);
139 queue.Get(&message);
140 EXPECT_TRUE(message.empty())
141 << "Running status must not be applied to real time messages";
144 TEST(MidiMessageQueueTest, RunningStatusEnabledWithRealTimeEvent) {
145 MidiMessageQueue queue(true);
146 const uint8 kNoteOnWithRunningStatusWithTimingClock[] = {
147 0x90, 0xf8, 0x3c, 0xf8, 0x7f, 0xf8, 0x3c, 0xf8, 0x7f, 0xf8, 0x3c, 0xf8,
148 0x7f,
150 Add(&queue, kNoteOnWithRunningStatusWithTimingClock);
151 std::vector<uint8> message;
152 queue.Get(&message);
153 EXPECT_MESSAGE(kTimingClock, message);
154 queue.Get(&message);
155 EXPECT_MESSAGE(kTimingClock, message);
156 queue.Get(&message);
157 EXPECT_MESSAGE(kNoteOn, message);
158 queue.Get(&message);
159 EXPECT_MESSAGE(kTimingClock, message);
160 queue.Get(&message);
161 EXPECT_MESSAGE(kTimingClock, message);
162 queue.Get(&message);
163 EXPECT_MESSAGE(kNoteOn, message);
164 queue.Get(&message);
165 EXPECT_MESSAGE(kTimingClock, message);
166 queue.Get(&message);
167 EXPECT_MESSAGE(kTimingClock, message);
168 queue.Get(&message);
169 EXPECT_MESSAGE(kNoteOn, message);
170 queue.Get(&message);
171 EXPECT_TRUE(message.empty());
174 TEST(MidiMessageQueueTest, RunningStatusEnabledWithSystemCommonMessage) {
175 MidiMessageQueue queue(true);
176 const uint8 kNoteOnWithRunningStatusWithSystemCommonMessage[] = {
177 0x90, 0x3c, 0x7f, 0xf1, 0x00, 0x3c, 0x7f, 0xf8, 0x90, 0x3c, 0x7f,
179 Add(&queue, kNoteOnWithRunningStatusWithSystemCommonMessage);
180 std::vector<uint8> message;
181 queue.Get(&message);
182 EXPECT_MESSAGE(kNoteOn, message);
183 queue.Get(&message);
184 EXPECT_MESSAGE(kMTCFrame, message);
185 queue.Get(&message);
186 EXPECT_MESSAGE(kTimingClock, message) << "Running status should be reset";
187 queue.Get(&message);
188 EXPECT_MESSAGE(kNoteOn, message);
189 queue.Get(&message);
190 EXPECT_TRUE(message.empty());
193 } // namespace
194 } // namespace midi
195 } // namespace media