| OLD | NEW |
| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
| 12 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "media/audio/cras/audio_manager_cras.h" | 14 #include "media/audio/cras/audio_manager_cras.h" |
| 14 #include "media/audio/fake_audio_log_factory.h" | 15 #include "media/audio/fake_audio_log_factory.h" |
| 15 #include "media/audio/mock_audio_source_callback.h" | 16 #include "media/audio/mock_audio_source_callback.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 // cras_util.h defines custom min/max macros which break compilation, so ensure | 20 // cras_util.h defines custom min/max macros which break compilation, so ensure |
| 20 // it's not included until last. #if avoids presubmit errors. | 21 // it's not included until last. #if avoids presubmit errors. |
| 21 #if defined(USE_CRAS) | 22 #if defined(USE_CRAS) |
| 22 #include "media/audio/cras/cras_unified.h" | 23 #include "media/audio/cras/cras_unified.h" |
| 23 #endif | 24 #endif |
| 24 | 25 |
| 25 using testing::_; | 26 using testing::_; |
| 26 using testing::DoAll; | 27 using testing::DoAll; |
| 27 using testing::InvokeWithoutArgs; | 28 using testing::InvokeWithoutArgs; |
| 28 using testing::Return; | 29 using testing::Return; |
| 29 using testing::SetArgumentPointee; | 30 using testing::SetArgumentPointee; |
| 30 using testing::StrictMock; | 31 using testing::StrictMock; |
| 31 | 32 |
| 32 namespace media { | 33 namespace media { |
| 33 | 34 |
| 34 class MockAudioManagerCras : public AudioManagerCras { | 35 class MockAudioManagerCras : public AudioManagerCras { |
| 35 public: | 36 public: |
| 36 MockAudioManagerCras() : AudioManagerCras(&fake_audio_log_factory_) {} | 37 MockAudioManagerCras() |
| 38 : AudioManagerCras(base::ThreadTaskRunnerHandle::Get(), |
| 39 base::ThreadTaskRunnerHandle::Get(), |
| 40 &fake_audio_log_factory_) {} |
| 37 | 41 |
| 38 MOCK_METHOD0(Init, void()); | 42 MOCK_METHOD0(Init, void()); |
| 39 MOCK_METHOD0(HasAudioOutputDevices, bool()); | 43 MOCK_METHOD0(HasAudioOutputDevices, bool()); |
| 40 MOCK_METHOD0(HasAudioInputDevices, bool()); | 44 MOCK_METHOD0(HasAudioInputDevices, bool()); |
| 41 MOCK_METHOD1(MakeLinearOutputStream, AudioOutputStream*( | 45 MOCK_METHOD1(MakeLinearOutputStream, AudioOutputStream*( |
| 42 const AudioParameters& params)); | 46 const AudioParameters& params)); |
| 43 MOCK_METHOD2(MakeLowLatencyOutputStream, | 47 MOCK_METHOD2(MakeLowLatencyOutputStream, |
| 44 AudioOutputStream*(const AudioParameters& params, | 48 AudioOutputStream*(const AudioParameters& params, |
| 45 const std::string& device_id)); | 49 const std::string& device_id)); |
| 46 MOCK_METHOD2(MakeLinearOutputStream, AudioInputStream*( | 50 MOCK_METHOD2(MakeLinearOutputStream, AudioInputStream*( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 MockAudioManagerCras& mock_manager() { | 88 MockAudioManagerCras& mock_manager() { |
| 85 return *(mock_manager_.get()); | 89 return *(mock_manager_.get()); |
| 86 } | 90 } |
| 87 | 91 |
| 88 static const ChannelLayout kTestChannelLayout; | 92 static const ChannelLayout kTestChannelLayout; |
| 89 static const int kTestSampleRate; | 93 static const int kTestSampleRate; |
| 90 static const int kTestBitsPerSample; | 94 static const int kTestBitsPerSample; |
| 91 static const AudioParameters::Format kTestFormat; | 95 static const AudioParameters::Format kTestFormat; |
| 92 static const uint32_t kTestFramesPerPacket; | 96 static const uint32_t kTestFramesPerPacket; |
| 93 | 97 |
| 94 scoped_ptr<StrictMock<MockAudioManagerCras> > mock_manager_; | 98 base::MessageLoop message_loop_; |
| 99 scoped_ptr<StrictMock<MockAudioManagerCras>, AudioManagerDeleter> |
| 100 mock_manager_; |
| 95 | 101 |
| 96 private: | 102 private: |
| 97 DISALLOW_COPY_AND_ASSIGN(CrasUnifiedStreamTest); | 103 DISALLOW_COPY_AND_ASSIGN(CrasUnifiedStreamTest); |
| 98 }; | 104 }; |
| 99 | 105 |
| 100 const ChannelLayout CrasUnifiedStreamTest::kTestChannelLayout = | 106 const ChannelLayout CrasUnifiedStreamTest::kTestChannelLayout = |
| 101 CHANNEL_LAYOUT_STEREO; | 107 CHANNEL_LAYOUT_STEREO; |
| 102 const int CrasUnifiedStreamTest::kTestSampleRate = | 108 const int CrasUnifiedStreamTest::kTestSampleRate = |
| 103 AudioParameters::kAudioCDSampleRate; | 109 AudioParameters::kAudioCDSampleRate; |
| 104 const int CrasUnifiedStreamTest::kTestBitsPerSample = 16; | 110 const int CrasUnifiedStreamTest::kTestBitsPerSample = 16; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 160 |
| 155 // Wait for samples to be captured. | 161 // Wait for samples to be captured. |
| 156 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); | 162 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); |
| 157 | 163 |
| 158 test_stream->Stop(); | 164 test_stream->Stop(); |
| 159 | 165 |
| 160 test_stream->Close(); | 166 test_stream->Close(); |
| 161 } | 167 } |
| 162 | 168 |
| 163 } // namespace media | 169 } // namespace media |
| OLD | NEW |