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