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