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

Side by Side Diff: media/audio/alsa/alsa_output_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/stringprintf.h" 5 #include "base/strings/stringprintf.h"
6 #include "media/audio/alsa/alsa_output.h" 6 #include "media/audio/alsa/alsa_output.h"
7 #include "media/audio/alsa/alsa_wrapper.h" 7 #include "media/audio/alsa/alsa_wrapper.h"
8 #include "media/audio/alsa/audio_manager_alsa.h" 8 #include "media/audio/alsa/audio_manager_alsa.h"
9 #include "media/audio/fake_audio_log_factory.h" 9 #include "media/audio/fake_audio_log_factory.h"
10 #include "media/audio/mock_audio_source_callback.h" 10 #include "media/audio/mock_audio_source_callback.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 107 }
108 108
109 virtual ~AlsaPcmOutputStreamTest() { 109 virtual ~AlsaPcmOutputStreamTest() {
110 } 110 }
111 111
112 AlsaPcmOutputStream* CreateStream(ChannelLayout layout) { 112 AlsaPcmOutputStream* CreateStream(ChannelLayout layout) {
113 return CreateStream(layout, kTestFramesPerPacket); 113 return CreateStream(layout, kTestFramesPerPacket);
114 } 114 }
115 115
116 AlsaPcmOutputStream* CreateStream(ChannelLayout layout, 116 AlsaPcmOutputStream* CreateStream(ChannelLayout layout,
117 int32 samples_per_packet) { 117 int32_t samples_per_packet) {
118 AudioParameters params(kTestFormat, layout, kTestSampleRate, 118 AudioParameters params(kTestFormat, layout, kTestSampleRate,
119 kTestBitsPerSample, samples_per_packet); 119 kTestBitsPerSample, samples_per_packet);
120 return new AlsaPcmOutputStream(kTestDeviceName, 120 return new AlsaPcmOutputStream(kTestDeviceName,
121 params, 121 params,
122 &mock_alsa_wrapper_, 122 &mock_alsa_wrapper_,
123 mock_manager_.get()); 123 mock_manager_.get());
124 } 124 }
125 125
126 // Helper function to malloc the string returned by DeviceNameHint for NAME. 126 // Helper function to malloc the string returned by DeviceNameHint for NAME.
127 static char* EchoHint(const void* name, Unused) { 127 static char* EchoHint(const void* name, Unused) {
(...skipping 15 matching lines...) Expand all
143 test_stream->buffer_->Append(packet_.get()); 143 test_stream->buffer_->Append(packet_.get());
144 } 144 }
145 145
146 static const ChannelLayout kTestChannelLayout; 146 static const ChannelLayout kTestChannelLayout;
147 static const int kTestSampleRate; 147 static const int kTestSampleRate;
148 static const int kTestBitsPerSample; 148 static const int kTestBitsPerSample;
149 static const int kTestBytesPerFrame; 149 static const int kTestBytesPerFrame;
150 static const AudioParameters::Format kTestFormat; 150 static const AudioParameters::Format kTestFormat;
151 static const char kTestDeviceName[]; 151 static const char kTestDeviceName[];
152 static const char kDummyMessage[]; 152 static const char kDummyMessage[];
153 static const uint32 kTestFramesPerPacket; 153 static const uint32_t kTestFramesPerPacket;
154 static const int kTestPacketSize; 154 static const int kTestPacketSize;
155 static const int kTestFailedErrno; 155 static const int kTestFailedErrno;
156 static snd_pcm_t* const kFakeHandle; 156 static snd_pcm_t* const kFakeHandle;
157 157
158 // Used to simulate DeviceNameHint. 158 // Used to simulate DeviceNameHint.
159 static char kSurround40[]; 159 static char kSurround40[];
160 static char kSurround41[]; 160 static char kSurround41[];
161 static char kSurround50[]; 161 static char kSurround50[];
162 static char kSurround51[]; 162 static char kSurround51[];
163 static char kSurround70[]; 163 static char kSurround70[];
(...skipping 15 matching lines...) Expand all
179 const int AlsaPcmOutputStreamTest::kTestSampleRate = 179 const int AlsaPcmOutputStreamTest::kTestSampleRate =
180 AudioParameters::kAudioCDSampleRate; 180 AudioParameters::kAudioCDSampleRate;
181 const int AlsaPcmOutputStreamTest::kTestBitsPerSample = 8; 181 const int AlsaPcmOutputStreamTest::kTestBitsPerSample = 8;
182 const int AlsaPcmOutputStreamTest::kTestBytesPerFrame = 182 const int AlsaPcmOutputStreamTest::kTestBytesPerFrame =
183 AlsaPcmOutputStreamTest::kTestBitsPerSample / 8 * 183 AlsaPcmOutputStreamTest::kTestBitsPerSample / 8 *
184 ChannelLayoutToChannelCount(AlsaPcmOutputStreamTest::kTestChannelLayout); 184 ChannelLayoutToChannelCount(AlsaPcmOutputStreamTest::kTestChannelLayout);
185 const AudioParameters::Format AlsaPcmOutputStreamTest::kTestFormat = 185 const AudioParameters::Format AlsaPcmOutputStreamTest::kTestFormat =
186 AudioParameters::AUDIO_PCM_LINEAR; 186 AudioParameters::AUDIO_PCM_LINEAR;
187 const char AlsaPcmOutputStreamTest::kTestDeviceName[] = "TestDevice"; 187 const char AlsaPcmOutputStreamTest::kTestDeviceName[] = "TestDevice";
188 const char AlsaPcmOutputStreamTest::kDummyMessage[] = "dummy"; 188 const char AlsaPcmOutputStreamTest::kDummyMessage[] = "dummy";
189 const uint32 AlsaPcmOutputStreamTest::kTestFramesPerPacket = 1000; 189 const uint32_t AlsaPcmOutputStreamTest::kTestFramesPerPacket = 1000;
190 const int AlsaPcmOutputStreamTest::kTestPacketSize = 190 const int AlsaPcmOutputStreamTest::kTestPacketSize =
191 AlsaPcmOutputStreamTest::kTestFramesPerPacket * 191 AlsaPcmOutputStreamTest::kTestFramesPerPacket *
192 AlsaPcmOutputStreamTest::kTestBytesPerFrame; 192 AlsaPcmOutputStreamTest::kTestBytesPerFrame;
193 const int AlsaPcmOutputStreamTest::kTestFailedErrno = -EACCES; 193 const int AlsaPcmOutputStreamTest::kTestFailedErrno = -EACCES;
194 snd_pcm_t* const AlsaPcmOutputStreamTest::kFakeHandle = 194 snd_pcm_t* const AlsaPcmOutputStreamTest::kFakeHandle =
195 reinterpret_cast<snd_pcm_t*>(1); 195 reinterpret_cast<snd_pcm_t*>(1);
196 196
197 char AlsaPcmOutputStreamTest::kSurround40[] = "surround40:CARD=foo,DEV=0"; 197 char AlsaPcmOutputStreamTest::kSurround40[] = "surround40:CARD=foo,DEV=0";
198 char AlsaPcmOutputStreamTest::kSurround41[] = "surround41:CARD=foo,DEV=0"; 198 char AlsaPcmOutputStreamTest::kSurround41[] = "surround41:CARD=foo,DEV=0";
199 char AlsaPcmOutputStreamTest::kSurround50[] = "surround50:CARD=foo,DEV=0"; 199 char AlsaPcmOutputStreamTest::kSurround50[] = "surround50:CARD=foo,DEV=0";
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)).WillOnce(Return(0)); 266 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)).WillOnce(Return(0));
267 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) 267 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle))
268 .WillOnce(Return(kTestDeviceName)); 268 .WillOnce(Return(kTestDeviceName));
269 test_stream->Close(); 269 test_stream->Close();
270 270
271 Mock::VerifyAndClear(&mock_alsa_wrapper_); 271 Mock::VerifyAndClear(&mock_alsa_wrapper_);
272 Mock::VerifyAndClear(mock_manager_.get()); 272 Mock::VerifyAndClear(mock_manager_.get());
273 273
274 // Test that having more packets ends up with a latency based on packet size. 274 // Test that having more packets ends up with a latency based on packet size.
275 const int kOverMinLatencyPacketSize = kPacketFramesInMinLatency + 1; 275 const int kOverMinLatencyPacketSize = kPacketFramesInMinLatency + 1;
276 int64 expected_micros = AlsaPcmOutputStream::FramesToTimeDelta( 276 int64_t expected_micros = AlsaPcmOutputStream::FramesToTimeDelta(
277 kOverMinLatencyPacketSize * 2, kTestSampleRate).InMicroseconds(); 277 kOverMinLatencyPacketSize * 2, kTestSampleRate)
278 .InMicroseconds();
278 279
279 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _)) 280 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _))
280 .WillOnce(DoAll(SetArgumentPointee<0>(kFakeHandle), Return(0))); 281 .WillOnce(DoAll(SetArgumentPointee<0>(kFakeHandle), Return(0)));
281 EXPECT_CALL(mock_alsa_wrapper_, 282 EXPECT_CALL(mock_alsa_wrapper_,
282 PcmSetParams(_, _, _, _, _, _, expected_micros)) 283 PcmSetParams(_, _, _, _, _, _, expected_micros))
283 .WillOnce(Return(0)); 284 .WillOnce(Return(0));
284 EXPECT_CALL(mock_alsa_wrapper_, PcmGetParams(_, _, _)) 285 EXPECT_CALL(mock_alsa_wrapper_, PcmGetParams(_, _, _))
285 .WillOnce(DoAll(SetArgumentPointee<1>(kTestFramesPerPacket), 286 .WillOnce(DoAll(SetArgumentPointee<1>(kTestFramesPerPacket),
286 SetArgumentPointee<2>(kTestFramesPerPacket / 2), 287 SetArgumentPointee<2>(kTestFramesPerPacket / 2),
287 Return(0))); 288 Return(0)));
288 289
289 test_stream = CreateStream(kTestChannelLayout, 290 test_stream = CreateStream(kTestChannelLayout,
290 kOverMinLatencyPacketSize); 291 kOverMinLatencyPacketSize);
291 ASSERT_TRUE(test_stream->Open()); 292 ASSERT_TRUE(test_stream->Open());
292 293
293 // Now close it and test that everything was released. 294 // Now close it and test that everything was released.
294 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)) 295 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle))
295 .WillOnce(Return(0)); 296 .WillOnce(Return(0));
296 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) 297 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle))
297 .WillOnce(Return(kTestDeviceName)); 298 .WillOnce(Return(kTestDeviceName));
298 test_stream->Close(); 299 test_stream->Close();
299 300
300 Mock::VerifyAndClear(&mock_alsa_wrapper_); 301 Mock::VerifyAndClear(&mock_alsa_wrapper_);
301 Mock::VerifyAndClear(mock_manager_.get()); 302 Mock::VerifyAndClear(mock_manager_.get());
302 } 303 }
303 304
304 TEST_F(AlsaPcmOutputStreamTest, OpenClose) { 305 TEST_F(AlsaPcmOutputStreamTest, OpenClose) {
305 int64 expected_micros = AlsaPcmOutputStream::FramesToTimeDelta( 306 int64_t expected_micros = AlsaPcmOutputStream::FramesToTimeDelta(
306 2 * kTestFramesPerPacket, kTestSampleRate).InMicroseconds(); 307 2 * kTestFramesPerPacket, kTestSampleRate)
308 .InMicroseconds();
307 309
308 // Open() call opens the playback device, sets the parameters, posts a task 310 // Open() call opens the playback device, sets the parameters, posts a task
309 // with the resulting configuration data, and transitions the object state to 311 // with the resulting configuration data, and transitions the object state to
310 // kIsOpened. 312 // kIsOpened.
311 EXPECT_CALL(mock_alsa_wrapper_, 313 EXPECT_CALL(mock_alsa_wrapper_,
312 PcmOpen(_, StrEq(kTestDeviceName), 314 PcmOpen(_, StrEq(kTestDeviceName),
313 SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)) 315 SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK))
314 .WillOnce(DoAll(SetArgumentPointee<0>(kFakeHandle), 316 .WillOnce(DoAll(SetArgumentPointee<0>(kFakeHandle),
315 Return(0))); 317 Return(0)));
316 EXPECT_CALL(mock_alsa_wrapper_, 318 EXPECT_CALL(mock_alsa_wrapper_,
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 850
849 // TODO(ajwong): Find a way to test whether or not another task has been 851 // TODO(ajwong): Find a way to test whether or not another task has been
850 // posted so we can verify that the Alsa code will indeed break the task 852 // posted so we can verify that the Alsa code will indeed break the task
851 // posting loop. 853 // posting loop.
852 854
853 test_stream->TransitionTo(AlsaPcmOutputStream::kIsClosed); 855 test_stream->TransitionTo(AlsaPcmOutputStream::kIsClosed);
854 test_stream->Close(); 856 test_stream->Close();
855 } 857 }
856 858
857 } // namespace media 859 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698