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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "media/audio/cras/audio_manager_cras.h" | 10 #include "media/audio/cras/audio_manager_cras.h" |
11 #include "media/audio/cras/cras_unified.h" | 11 #include "media/audio/cras/cras_unified.h" |
| 12 #include "media/audio/fake_audio_log_factory.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 using testing::_; | 16 using testing::_; |
16 using testing::DoAll; | 17 using testing::DoAll; |
17 using testing::InvokeWithoutArgs; | 18 using testing::InvokeWithoutArgs; |
18 using testing::Return; | 19 using testing::Return; |
19 using testing::SetArgumentPointee; | 20 using testing::SetArgumentPointee; |
20 using testing::StrictMock; | 21 using testing::StrictMock; |
21 | 22 |
22 namespace media { | 23 namespace media { |
23 | 24 |
24 class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { | 25 class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { |
25 public: | 26 public: |
26 MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus, | 27 MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus, |
27 AudioBuffersState buffers_state)); | 28 AudioBuffersState buffers_state)); |
28 MOCK_METHOD3(OnMoreIOData, int(AudioBus* source, | 29 MOCK_METHOD3(OnMoreIOData, int(AudioBus* source, |
29 AudioBus* dest, | 30 AudioBus* dest, |
30 AudioBuffersState buffers_state)); | 31 AudioBuffersState buffers_state)); |
31 MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); | 32 MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); |
32 }; | 33 }; |
33 | 34 |
34 class MockAudioManagerCras : public AudioManagerCras { | 35 class MockAudioManagerCras : public AudioManagerCras { |
35 public: | 36 public: |
| 37 MockAudioManagerCras() : AudioManagerCras(&fake_audio_log_factory_) {} |
| 38 |
36 MOCK_METHOD0(Init, void()); | 39 MOCK_METHOD0(Init, void()); |
37 MOCK_METHOD0(HasAudioOutputDevices, bool()); | 40 MOCK_METHOD0(HasAudioOutputDevices, bool()); |
38 MOCK_METHOD0(HasAudioInputDevices, bool()); | 41 MOCK_METHOD0(HasAudioInputDevices, bool()); |
39 MOCK_METHOD1(MakeLinearOutputStream, AudioOutputStream*( | 42 MOCK_METHOD1(MakeLinearOutputStream, AudioOutputStream*( |
40 const AudioParameters& params)); | 43 const AudioParameters& params)); |
41 MOCK_METHOD1(MakeLowLatencyOutputStream, AudioOutputStream*( | 44 MOCK_METHOD1(MakeLowLatencyOutputStream, AudioOutputStream*( |
42 const AudioParameters& params)); | 45 const AudioParameters& params)); |
43 MOCK_METHOD2(MakeLinearOutputStream, AudioInputStream*( | 46 MOCK_METHOD2(MakeLinearOutputStream, AudioInputStream*( |
44 const AudioParameters& params, const std::string& device_id)); | 47 const AudioParameters& params, const std::string& device_id)); |
45 MOCK_METHOD2(MakeLowLatencyInputStream, AudioInputStream*( | 48 MOCK_METHOD2(MakeLowLatencyInputStream, AudioInputStream*( |
46 const AudioParameters& params, const std::string& device_id)); | 49 const AudioParameters& params, const std::string& device_id)); |
47 | 50 |
48 // We need to override this function in order to skip the checking the number | 51 // We need to override this function in order to skip the checking the number |
49 // of active output streams. It is because the number of active streams | 52 // of active output streams. It is because the number of active streams |
50 // is managed inside MakeAudioOutputStream, and we don't use | 53 // is managed inside MakeAudioOutputStream, and we don't use |
51 // MakeAudioOutputStream to create the stream in the tests. | 54 // MakeAudioOutputStream to create the stream in the tests. |
52 virtual void ReleaseOutputStream(AudioOutputStream* stream) OVERRIDE { | 55 virtual void ReleaseOutputStream(AudioOutputStream* stream) OVERRIDE { |
53 DCHECK(stream); | 56 DCHECK(stream); |
54 delete stream; | 57 delete stream; |
55 } | 58 } |
| 59 |
| 60 private: |
| 61 FakeAudioLogFactory fake_audio_log_factory_; |
56 }; | 62 }; |
57 | 63 |
58 class CrasUnifiedStreamTest : public testing::Test { | 64 class CrasUnifiedStreamTest : public testing::Test { |
59 protected: | 65 protected: |
60 CrasUnifiedStreamTest() { | 66 CrasUnifiedStreamTest() { |
61 mock_manager_.reset(new StrictMock<MockAudioManagerCras>()); | 67 mock_manager_.reset(new StrictMock<MockAudioManagerCras>()); |
62 } | 68 } |
63 | 69 |
64 virtual ~CrasUnifiedStreamTest() { | 70 virtual ~CrasUnifiedStreamTest() { |
65 } | 71 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 154 |
149 // Wait for samples to be captured. | 155 // Wait for samples to be captured. |
150 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); | 156 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); |
151 | 157 |
152 test_stream->Stop(); | 158 test_stream->Stop(); |
153 | 159 |
154 test_stream->Close(); | 160 test_stream->Close(); |
155 } | 161 } |
156 | 162 |
157 } // namespace media | 163 } // namespace media |
OLD | NEW |