OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
7 #include "media/audio/linux/alsa_output.h" | 7 #include "media/audio/linux/alsa_output.h" |
8 #include "media/audio/linux/alsa_wrapper.h" | 8 #include "media/audio/linux/alsa_wrapper.h" |
9 #include "media/audio/linux/audio_manager_linux.h" | 9 #include "media/audio/linux/audio_manager_linux.h" |
10 #include "media/base/data_buffer.h" | 10 #include "media/base/data_buffer.h" |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 EXPECT_FALSE(test_stream_->buffer_.get()); | 348 EXPECT_FALSE(test_stream_->buffer_.get()); |
349 EXPECT_TRUE(test_stream_->stop_stream_); | 349 EXPECT_TRUE(test_stream_->stop_stream_); |
350 } | 350 } |
351 | 351 |
352 TEST_F(AlsaPcmOutputStreamTest, PcmOpenFailed) { | 352 TEST_F(AlsaPcmOutputStreamTest, PcmOpenFailed) { |
353 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _)) | 353 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _)) |
354 .WillOnce(Return(kTestFailedErrno)); | 354 .WillOnce(Return(kTestFailedErrno)); |
355 EXPECT_CALL(mock_alsa_wrapper_, StrError(kTestFailedErrno)) | 355 EXPECT_CALL(mock_alsa_wrapper_, StrError(kTestFailedErrno)) |
356 .WillOnce(Return(kDummyMessage)); | 356 .WillOnce(Return(kDummyMessage)); |
357 | 357 |
358 ASSERT_TRUE(test_stream_->Open()); | 358 ASSERT_FALSE(test_stream_->Open()); |
359 ASSERT_EQ(AlsaPcmOutputStream::kIsOpened, test_stream_->state()); | 359 ASSERT_EQ(AlsaPcmOutputStream::kInError, test_stream_->state()); |
360 | 360 |
361 // Ensure internal state is set for a no-op stream if PcmOpen() failes. | 361 // Ensure internal state is set for a no-op stream if PcmOpen() failes. |
362 EXPECT_EQ(AlsaPcmOutputStream::kIsOpened, test_stream_->state()); | |
363 EXPECT_TRUE(test_stream_->stop_stream_); | 362 EXPECT_TRUE(test_stream_->stop_stream_); |
364 EXPECT_TRUE(test_stream_->playback_handle_ == NULL); | 363 EXPECT_TRUE(test_stream_->playback_handle_ == NULL); |
365 EXPECT_FALSE(test_stream_->buffer_.get()); | 364 EXPECT_FALSE(test_stream_->buffer_.get()); |
366 | 365 |
367 // Close the stream since we opened it to make destruction happy. | 366 // Close the stream since we opened it to make destruction happy. |
368 EXPECT_CALL(mock_manager(), ReleaseOutputStream(test_stream_.get())); | 367 EXPECT_CALL(mock_manager(), ReleaseOutputStream(test_stream_.get())); |
369 test_stream_->Close(); | 368 test_stream_->Close(); |
370 } | 369 } |
371 | 370 |
372 TEST_F(AlsaPcmOutputStreamTest, PcmSetParamsFailed) { | 371 TEST_F(AlsaPcmOutputStreamTest, PcmSetParamsFailed) { |
373 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _)) | 372 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _)) |
374 .WillOnce(DoAll(SetArgumentPointee<0>(kFakeHandle), | 373 .WillOnce(DoAll(SetArgumentPointee<0>(kFakeHandle), |
375 Return(0))); | 374 Return(0))); |
376 EXPECT_CALL(mock_alsa_wrapper_, PcmSetParams(_, _, _, _, _, _, _)) | 375 EXPECT_CALL(mock_alsa_wrapper_, PcmSetParams(_, _, _, _, _, _, _)) |
377 .WillOnce(Return(kTestFailedErrno)); | 376 .WillOnce(Return(kTestFailedErrno)); |
378 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)) | 377 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)) |
379 .WillOnce(Return(0)); | 378 .WillOnce(Return(0)); |
380 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) | 379 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) |
381 .WillOnce(Return(kTestDeviceName)); | 380 .WillOnce(Return(kTestDeviceName)); |
382 EXPECT_CALL(mock_alsa_wrapper_, StrError(kTestFailedErrno)) | 381 EXPECT_CALL(mock_alsa_wrapper_, StrError(kTestFailedErrno)) |
383 .WillOnce(Return(kDummyMessage)); | 382 .WillOnce(Return(kDummyMessage)); |
384 | 383 |
385 // If open fails, the stream stays in kCreated because it has effectively had | 384 // If open fails, the stream stays in kCreated because it has effectively had |
386 // no changes. | 385 // no changes. |
387 ASSERT_TRUE(test_stream_->Open()); | 386 ASSERT_FALSE(test_stream_->Open()); |
388 EXPECT_EQ(AlsaPcmOutputStream::kIsOpened, test_stream_->state()); | 387 EXPECT_EQ(AlsaPcmOutputStream::kInError, test_stream_->state()); |
389 | 388 |
390 // Ensure internal state is set for a no-op stream if PcmSetParams() failes. | 389 // Ensure internal state is set for a no-op stream if PcmSetParams() failes. |
391 EXPECT_EQ(AlsaPcmOutputStream::kIsOpened, test_stream_->state()); | |
392 EXPECT_TRUE(test_stream_->stop_stream_); | 390 EXPECT_TRUE(test_stream_->stop_stream_); |
393 EXPECT_TRUE(test_stream_->playback_handle_ == NULL); | 391 EXPECT_TRUE(test_stream_->playback_handle_ == NULL); |
394 EXPECT_FALSE(test_stream_->buffer_.get()); | 392 EXPECT_FALSE(test_stream_->buffer_.get()); |
395 | 393 |
396 // Close the stream since we opened it to make destruction happy. | 394 // Close the stream since we opened it to make destruction happy. |
397 EXPECT_CALL(mock_manager(), ReleaseOutputStream(test_stream_.get())); | 395 EXPECT_CALL(mock_manager(), ReleaseOutputStream(test_stream_.get())); |
398 test_stream_->Close(); | 396 test_stream_->Close(); |
399 } | 397 } |
400 | 398 |
401 TEST_F(AlsaPcmOutputStreamTest, StartStop) { | 399 TEST_F(AlsaPcmOutputStreamTest, StartStop) { |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 | 781 |
784 test_stream_->stop_stream_ = true; | 782 test_stream_->stop_stream_ = true; |
785 test_stream_->ScheduleNextWrite(true); | 783 test_stream_->ScheduleNextWrite(true); |
786 | 784 |
787 // TODO(ajwong): Find a way to test whether or not another task has been | 785 // TODO(ajwong): Find a way to test whether or not another task has been |
788 // posted so we can verify that the Alsa code will indeed break the task | 786 // posted so we can verify that the Alsa code will indeed break the task |
789 // posting loop. | 787 // posting loop. |
790 | 788 |
791 test_stream_->TransitionTo(AlsaPcmOutputStream::kIsClosed); | 789 test_stream_->TransitionTo(AlsaPcmOutputStream::kIsClosed); |
792 } | 790 } |
OLD | NEW |