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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <memory> | |
8 #include <string> | 7 #include <string> |
9 | 8 |
10 #include "base/macros.h" | 9 #include "base/macros.h" |
11 #include "base/run_loop.h" | |
12 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
13 #include "base/test/test_message_loop.h" | |
14 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
15 #include "base/thread_task_runner_handle.h" | |
16 #include "base/time/time.h" | 12 #include "base/time/time.h" |
17 #include "media/audio/cras/audio_manager_cras.h" | 13 #include "media/audio/cras/audio_manager_cras.h" |
18 #include "media/audio/fake_audio_log_factory.h" | 14 #include "media/audio/fake_audio_log_factory.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
21 | 17 |
22 // cras_util.h defines custom min/max macros which break compilation, so ensure | 18 // cras_util.h defines custom min/max macros which break compilation, so ensure |
23 // it's not included until last. #if avoids presubmit errors. | 19 // it's not included until last. #if avoids presubmit errors. |
24 #if defined(USE_CRAS) | 20 #if defined(USE_CRAS) |
25 #include "media/audio/cras/cras_input.h" | 21 #include "media/audio/cras/cras_input.h" |
26 #endif | 22 #endif |
27 | 23 |
28 using testing::_; | 24 using testing::_; |
29 using testing::AtLeast; | 25 using testing::AtLeast; |
30 using testing::Ge; | 26 using testing::Ge; |
31 using testing::InvokeWithoutArgs; | 27 using testing::InvokeWithoutArgs; |
32 using testing::StrictMock; | 28 using testing::StrictMock; |
33 | 29 |
34 namespace media { | 30 namespace media { |
35 | 31 |
36 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { | 32 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { |
37 public: | 33 public: |
38 MOCK_METHOD4(OnData, | 34 MOCK_METHOD4(OnData, |
39 void(AudioInputStream*, const AudioBus*, uint32_t, double)); | 35 void(AudioInputStream*, const AudioBus*, uint32_t, double)); |
40 MOCK_METHOD1(OnError, void(AudioInputStream*)); | 36 MOCK_METHOD1(OnError, void(AudioInputStream*)); |
41 }; | 37 }; |
42 | 38 |
43 class MockAudioManagerCrasInput : public AudioManagerCras { | 39 class MockAudioManagerCrasInput : public AudioManagerCras { |
44 public: | 40 public: |
45 MockAudioManagerCrasInput() | 41 MockAudioManagerCrasInput() : AudioManagerCras(&fake_audio_log_factory_) {} |
46 : AudioManagerCras(base::ThreadTaskRunnerHandle::Get(), | |
47 base::ThreadTaskRunnerHandle::Get(), | |
48 &fake_audio_log_factory_) {} | |
49 | 42 |
50 // We need to override this function in order to skip checking the number | 43 // We need to override this function in order to skip checking the number |
51 // of active output streams. It is because the number of active streams | 44 // of active output streams. It is because the number of active streams |
52 // is managed inside MakeAudioInputStream, and we don't use | 45 // is managed inside MakeAudioInputStream, and we don't use |
53 // MakeAudioInputStream to create the stream in the tests. | 46 // MakeAudioInputStream to create the stream in the tests. |
54 void ReleaseInputStream(AudioInputStream* stream) override { | 47 void ReleaseInputStream(AudioInputStream* stream) override { |
55 DCHECK(stream); | 48 DCHECK(stream); |
56 delete stream; | 49 delete stream; |
57 } | 50 } |
58 | 51 |
59 private: | 52 private: |
60 FakeAudioLogFactory fake_audio_log_factory_; | 53 FakeAudioLogFactory fake_audio_log_factory_; |
61 }; | 54 }; |
62 | 55 |
63 class CrasInputStreamTest : public testing::Test { | 56 class CrasInputStreamTest : public testing::Test { |
64 protected: | 57 protected: |
65 CrasInputStreamTest() { | 58 CrasInputStreamTest() { |
66 mock_manager_.reset(new StrictMock<MockAudioManagerCrasInput>()); | 59 mock_manager_.reset(new StrictMock<MockAudioManagerCrasInput>()); |
67 base::RunLoop().RunUntilIdle(); | |
68 } | 60 } |
69 | 61 |
70 ~CrasInputStreamTest() override {} | 62 virtual ~CrasInputStreamTest() { |
| 63 } |
71 | 64 |
72 CrasInputStream* CreateStream(ChannelLayout layout) { | 65 CrasInputStream* CreateStream(ChannelLayout layout) { |
73 return CreateStream(layout, kTestFramesPerPacket); | 66 return CreateStream(layout, kTestFramesPerPacket); |
74 } | 67 } |
75 | 68 |
76 CrasInputStream* CreateStream(ChannelLayout layout, | 69 CrasInputStream* CreateStream(ChannelLayout layout, |
77 int32_t samples_per_packet) { | 70 int32_t samples_per_packet) { |
78 return CreateStream(layout, samples_per_packet, | 71 return CreateStream(layout, samples_per_packet, |
79 AudioManagerBase::kDefaultDeviceId); | 72 AudioManagerBase::kDefaultDeviceId); |
80 } | 73 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 test_stream->Close(); | 108 test_stream->Close(); |
116 } | 109 } |
117 | 110 |
118 static const unsigned int kTestBitsPerSample; | 111 static const unsigned int kTestBitsPerSample; |
119 static const unsigned int kTestCaptureDurationMs; | 112 static const unsigned int kTestCaptureDurationMs; |
120 static const ChannelLayout kTestChannelLayout; | 113 static const ChannelLayout kTestChannelLayout; |
121 static const AudioParameters::Format kTestFormat; | 114 static const AudioParameters::Format kTestFormat; |
122 static const uint32_t kTestFramesPerPacket; | 115 static const uint32_t kTestFramesPerPacket; |
123 static const int kTestSampleRate; | 116 static const int kTestSampleRate; |
124 | 117 |
125 base::TestMessageLoop message_loop_; | 118 scoped_ptr<StrictMock<MockAudioManagerCrasInput> > mock_manager_; |
126 std::unique_ptr<StrictMock<MockAudioManagerCrasInput>, AudioManagerDeleter> | |
127 mock_manager_; | |
128 | 119 |
129 private: | 120 private: |
130 DISALLOW_COPY_AND_ASSIGN(CrasInputStreamTest); | 121 DISALLOW_COPY_AND_ASSIGN(CrasInputStreamTest); |
131 }; | 122 }; |
132 | 123 |
133 const unsigned int CrasInputStreamTest::kTestBitsPerSample = 16; | 124 const unsigned int CrasInputStreamTest::kTestBitsPerSample = 16; |
134 const unsigned int CrasInputStreamTest::kTestCaptureDurationMs = 250; | 125 const unsigned int CrasInputStreamTest::kTestCaptureDurationMs = 250; |
135 const ChannelLayout CrasInputStreamTest::kTestChannelLayout = | 126 const ChannelLayout CrasInputStreamTest::kTestChannelLayout = |
136 CHANNEL_LAYOUT_STEREO; | 127 CHANNEL_LAYOUT_STEREO; |
137 const AudioParameters::Format CrasInputStreamTest::kTestFormat = | 128 const AudioParameters::Format CrasInputStreamTest::kTestFormat = |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 TEST_F(CrasInputStreamTest, CaptureLoopback) { | 211 TEST_F(CrasInputStreamTest, CaptureLoopback) { |
221 CrasInputStream* test_stream = CreateStream( | 212 CrasInputStream* test_stream = CreateStream( |
222 CHANNEL_LAYOUT_STEREO, | 213 CHANNEL_LAYOUT_STEREO, |
223 kTestFramesPerPacket, | 214 kTestFramesPerPacket, |
224 AudioManagerBase::kLoopbackInputDeviceId); | 215 AudioManagerBase::kLoopbackInputDeviceId); |
225 EXPECT_TRUE(test_stream->Open()); | 216 EXPECT_TRUE(test_stream->Open()); |
226 test_stream->Close(); | 217 test_stream->Close(); |
227 } | 218 } |
228 | 219 |
229 } // namespace media | 220 } // namespace media |
OLD | NEW |