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