diff options
author | dalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-30 21:53:48 +0000 |
---|---|---|
committer | dalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-30 21:53:48 +0000 |
commit | c10660540a92b9b9871c123061303b4c1b7118d2 (patch) | |
tree | 7128dcf4b96ad903279161109017410a489257e3 /media/audio | |
parent | dcd5d4d3c3bc357d98a143a4e91c59257f86f482 (diff) | |
download | chromium_src-c10660540a92b9b9871c123061303b4c1b7118d2.zip chromium_src-c10660540a92b9b9871c123061303b4c1b7118d2.tar.gz chromium_src-c10660540a92b9b9871c123061303b4c1b7118d2.tar.bz2 |
Factorize MockAudioSourceCallback out of many unittests.
BUG=none
TEST=tests still pass.
Review URL: https://codereview.chromium.org/140613007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248043 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio')
-rw-r--r-- | media/audio/alsa/alsa_output_unittest.cc | 11 | ||||
-rw-r--r-- | media/audio/android/audio_android_unittest.cc | 35 | ||||
-rw-r--r-- | media/audio/cras/cras_unified_unittest.cc | 11 | ||||
-rw-r--r-- | media/audio/mac/audio_auhal_mac_unittest.cc | 11 | ||||
-rw-r--r-- | media/audio/mock_audio_source_callback.cc | 12 | ||||
-rw-r--r-- | media/audio/mock_audio_source_callback.h | 31 | ||||
-rw-r--r-- | media/audio/win/audio_low_latency_output_win_unittest.cc | 11 | ||||
-rw-r--r-- | media/audio/win/audio_output_win_unittest.cc | 29 | ||||
-rw-r--r-- | media/audio/win/audio_unified_win_unittest.cc | 16 |
9 files changed, 72 insertions, 95 deletions
diff --git a/media/audio/alsa/alsa_output_unittest.cc b/media/audio/alsa/alsa_output_unittest.cc index da7924f..07ce8ea 100644 --- a/media/audio/alsa/alsa_output_unittest.cc +++ b/media/audio/alsa/alsa_output_unittest.cc @@ -7,6 +7,7 @@ #include "media/audio/alsa/alsa_wrapper.h" #include "media/audio/alsa/audio_manager_alsa.h" #include "media/audio/fake_audio_log_factory.h" +#include "media/audio/mock_audio_source_callback.h" #include "media/base/data_buffer.h" #include "media/base/seekable_buffer.h" #include "testing/gmock/include/gmock/gmock.h" @@ -66,16 +67,6 @@ class MockAlsaWrapper : public AlsaWrapper { MOCK_METHOD1(StrError, const char*(int errnum)); }; -class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { - public: - MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus, - AudioBuffersState buffers_state)); - MOCK_METHOD3(OnMoreIOData, int(AudioBus* source, - AudioBus* dest, - AudioBuffersState buffers_state)); - MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); -}; - class MockAudioManagerAlsa : public AudioManagerAlsa { public: MockAudioManagerAlsa() : AudioManagerAlsa(&fake_audio_log_factory_) {} diff --git a/media/audio/android/audio_android_unittest.cc b/media/audio/android/audio_android_unittest.cc index 688a940..91bf5d8 100644 --- a/media/audio/android/audio_android_unittest.cc +++ b/media/audio/android/audio_android_unittest.cc @@ -17,6 +17,7 @@ #include "media/audio/android/audio_manager_android.h" #include "media/audio/audio_io.h" #include "media/audio/audio_manager_base.h" +#include "media/audio/mock_audio_source_callback.h" #include "media/base/decoder_buffer.h" #include "media/base/seekable_buffer.h" #include "media/base/test_data_util.h" @@ -120,6 +121,12 @@ static void CheckDeviceNames(const AudioDeviceNames& device_names) { } } +// We clear the data bus to ensure that the test does not cause noise. +static int RealOnMoreData(AudioBus* dest, AudioBuffersState buffers_state) { + dest->Zero(); + return dest->frames(); +} + std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { using namespace std; os << endl << "format: " << FormatToString(params.format()) << endl @@ -149,24 +156,6 @@ class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { MOCK_METHOD1(OnError, void(AudioInputStream* stream)); }; -// Gmock implementation of AudioOutputStream::AudioSourceCallback. -class MockAudioOutputCallback : public AudioOutputStream::AudioSourceCallback { - public: - MOCK_METHOD2(OnMoreData, - int(AudioBus* dest, AudioBuffersState buffers_state)); - MOCK_METHOD3(OnMoreIOData, - int(AudioBus* source, - AudioBus* dest, - AudioBuffersState buffers_state)); - MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); - - // We clear the data bus to ensure that the test does not cause noise. - int RealOnMoreData(AudioBus* dest, AudioBuffersState buffers_state) { - dest->Zero(); - return dest->frames(); - } -}; - // Implements AudioOutputStream::AudioSourceCallback and provides audio data // by reading from a data file. class FileAudioSource : public AudioOutputStream::AudioSourceCallback { @@ -453,13 +442,13 @@ class AudioAndroidOutputTest : public testing::Test { EXPECT_TRUE(stream); int count = 0; - MockAudioOutputCallback source; + MockAudioSourceCallback source; EXPECT_CALL(source, OnMoreData(NotNull(), _)) .Times(AtLeast(num_callbacks)) .WillRepeatedly( DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), - Invoke(&source, &MockAudioOutputCallback::RealOnMoreData))); + Invoke(RealOnMoreData))); EXPECT_CALL(source, OnError(stream)).Times(0); EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); @@ -791,10 +780,10 @@ TEST_P(AudioAndroidInputTest, DISABLED_RunDuplexInputStreamWithFileAsSink) { base::WaitableEvent event(false, false); FileAudioSink sink(&event, in_params, file_name); - MockAudioOutputCallback source; + MockAudioSourceCallback source; - EXPECT_CALL(source, OnMoreData(NotNull(), _)).WillRepeatedly( - Invoke(&source, &MockAudioOutputCallback::RealOnMoreData)); + EXPECT_CALL(source, OnMoreData(NotNull(), _)) + .WillRepeatedly(Invoke(RealOnMoreData)); EXPECT_CALL(source, OnError(aos)).Times(0); EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); diff --git a/media/audio/cras/cras_unified_unittest.cc b/media/audio/cras/cras_unified_unittest.cc index 01bbe13..ee36b10 100644 --- a/media/audio/cras/cras_unified_unittest.cc +++ b/media/audio/cras/cras_unified_unittest.cc @@ -9,6 +9,7 @@ #include "base/time/time.h" #include "media/audio/cras/audio_manager_cras.h" #include "media/audio/fake_audio_log_factory.h" +#include "media/audio/mock_audio_source_callback.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -27,16 +28,6 @@ using testing::StrictMock; namespace media { -class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { - public: - MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus, - AudioBuffersState buffers_state)); - MOCK_METHOD3(OnMoreIOData, int(AudioBus* source, - AudioBus* dest, - AudioBuffersState buffers_state)); - MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); -}; - class MockAudioManagerCras : public AudioManagerCras { public: MockAudioManagerCras() : AudioManagerCras(&fake_audio_log_factory_) {} diff --git a/media/audio/mac/audio_auhal_mac_unittest.cc b/media/audio/mac/audio_auhal_mac_unittest.cc index 4279435..9babd80 100644 --- a/media/audio/mac/audio_auhal_mac_unittest.cc +++ b/media/audio/mac/audio_auhal_mac_unittest.cc @@ -9,6 +9,7 @@ #include "base/synchronization/waitable_event.h" #include "media/audio/audio_io.h" #include "media/audio/audio_manager.h" +#include "media/audio/mock_audio_source_callback.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -29,16 +30,6 @@ ACTION_P(SignalEvent, event) { event->Signal(); } -class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { - public: - MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus, - AudioBuffersState buffers_state)); - MOCK_METHOD3(OnMoreIOData, int(AudioBus* source, - AudioBus* dest, - AudioBuffersState buffers_state)); - MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); -}; - class AUHALStreamTest : public testing::Test { public: AUHALStreamTest() diff --git a/media/audio/mock_audio_source_callback.cc b/media/audio/mock_audio_source_callback.cc new file mode 100644 index 0000000..da2be1c --- /dev/null +++ b/media/audio/mock_audio_source_callback.cc @@ -0,0 +1,12 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/audio/mock_audio_source_callback.h" + +namespace media { + +MockAudioSourceCallback::MockAudioSourceCallback() {} +MockAudioSourceCallback::~MockAudioSourceCallback() {} + +} // namespace media diff --git a/media/audio/mock_audio_source_callback.h b/media/audio/mock_audio_source_callback.h new file mode 100644 index 0000000..cbd3850 --- /dev/null +++ b/media/audio/mock_audio_source_callback.h @@ -0,0 +1,31 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MEDIA_AUDIO_MOCK_AUDIO_SOURCE_CALLBACK_H_ +#define MEDIA_AUDIO_MOCK_AUDIO_SOURCE_CALLBACK_H_ + +#include "media/audio/audio_io.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace media { + +class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { + public: + MockAudioSourceCallback(); + virtual ~MockAudioSourceCallback(); + + MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus, + AudioBuffersState buffers_state)); + MOCK_METHOD3(OnMoreIOData, int(AudioBus* source, + AudioBus* dest, + AudioBuffersState buffers_state)); + MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); + + private: + DISALLOW_COPY_AND_ASSIGN(MockAudioSourceCallback); +}; + +} // namespace media + +#endif // MEDIA_AUDIO_MOCK_AUDIO_SOURCE_CALLBACK_H_ diff --git a/media/audio/win/audio_low_latency_output_win_unittest.cc b/media/audio/win/audio_low_latency_output_win_unittest.cc index 5fda4b1..66d3891 100644 --- a/media/audio/win/audio_low_latency_output_win_unittest.cc +++ b/media/audio/win/audio_low_latency_output_win_unittest.cc @@ -16,6 +16,7 @@ #include "base/win/scoped_com_initializer.h" #include "media/audio/audio_io.h" #include "media/audio/audio_manager.h" +#include "media/audio/mock_audio_source_callback.h" #include "media/audio/win/audio_low_latency_output_win.h" #include "media/audio/win/core_audio_util_win.h" #include "media/base/decoder_buffer.h" @@ -60,16 +61,6 @@ ACTION_P(QuitLoop, loop) { loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); } -class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { - public: - MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus, - AudioBuffersState buffers_state)); - MOCK_METHOD3(OnMoreIOData, int(AudioBus* source, - AudioBus* dest, - AudioBuffersState buffers_state)); - MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); -}; - // This audio source implementation should be used for manual tests only since // it takes about 20 seconds to play out a file. class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback { diff --git a/media/audio/win/audio_output_win_unittest.cc b/media/audio/win/audio_output_win_unittest.cc index 2b8036d..dcb5ca3 100644 --- a/media/audio/win/audio_output_win_unittest.cc +++ b/media/audio/win/audio_output_win_unittest.cc @@ -15,6 +15,7 @@ #include "media/base/limits.h" #include "media/audio/audio_io.h" #include "media/audio/audio_manager.h" +#include "media/audio/mock_audio_source_callback.h" #include "media/audio/simple_sources.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -36,6 +37,11 @@ namespace media { static const wchar_t kAudioFile1_16b_m_16K[] = L"media\\test\\data\\sweep02_16b_mono_16KHz.raw"; +static int ClearData(AudioBus* audio_bus, AudioBuffersState buffers_state) { + audio_bus->Zero(); + return audio_bus->frames(); +} + // This class allows to find out if the callbacks are occurring as // expected and if any error has been reported. class TestSourceBasic : public AudioOutputStream::AudioSourceCallback { @@ -102,21 +108,6 @@ class TestSourceLaggy : public TestSourceBasic { int lag_in_ms_; }; -class MockAudioSource : public AudioOutputStream::AudioSourceCallback { - public: - MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus, - AudioBuffersState buffers_state)); - MOCK_METHOD3(OnMoreIOData, int(AudioBus* source, - AudioBus* dest, - AudioBuffersState buffers_state)); - MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); - - static int ClearData(AudioBus* audio_bus, AudioBuffersState buffers_state) { - audio_bus->Zero(); - return audio_bus->frames(); - } -}; - // Helper class to memory map an entire file. The mapping is read-only. Don't // use for gigabyte-sized files. Attempts to write to this memory generate // memory access violations. @@ -522,7 +513,7 @@ TEST(WinAudioTest, PCMWaveStreamPendingBytes) { std::string(), std::string()); ASSERT_TRUE(NULL != oas); - NiceMock<MockAudioSource> source; + NiceMock<MockAudioSourceCallback> source; EXPECT_TRUE(oas->Open()); uint32 bytes_100_ms = samples_100_ms * 2; @@ -537,18 +528,18 @@ TEST(WinAudioTest, PCMWaveStreamPendingBytes) { EXPECT_CALL(source, OnMoreData(NotNull(), Field(&AudioBuffersState::pending_bytes, 0))) - .WillOnce(Invoke(MockAudioSource::ClearData)); + .WillOnce(Invoke(ClearData)); // Note: If AudioManagerWin::NumberOfWaveOutBuffers() ever changes, or if this // test is run on Vista, these expectations will fail. EXPECT_CALL(source, OnMoreData(NotNull(), Field(&AudioBuffersState::pending_bytes, bytes_100_ms))) - .WillOnce(Invoke(MockAudioSource::ClearData)); + .WillOnce(Invoke(ClearData)); EXPECT_CALL(source, OnMoreData(NotNull(), Field(&AudioBuffersState::pending_bytes, 2 * bytes_100_ms))) - .WillOnce(Invoke(MockAudioSource::ClearData)); + .WillOnce(Invoke(ClearData)); EXPECT_CALL(source, OnMoreData(NotNull(), Field(&AudioBuffersState::pending_bytes, 2 * bytes_100_ms))) diff --git a/media/audio/win/audio_unified_win_unittest.cc b/media/audio/win/audio_unified_win_unittest.cc index 15573ae..fadec61 100644 --- a/media/audio/win/audio_unified_win_unittest.cc +++ b/media/audio/win/audio_unified_win_unittest.cc @@ -12,6 +12,7 @@ #include "base/win/scoped_com_initializer.h" #include "media/audio/audio_io.h" #include "media/audio/audio_manager.h" +#include "media/audio/mock_audio_source_callback.h" #include "media/audio/win/audio_unified_win.h" #include "media/audio/win/core_audio_util_win.h" #include "media/base/channel_mixer.h" @@ -44,17 +45,6 @@ ACTION_P(QuitLoop, loop) { loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); } -class MockUnifiedSourceCallback - : public AudioOutputStream::AudioSourceCallback { - public: - MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus, - AudioBuffersState buffers_state)); - MOCK_METHOD3(OnMoreIOData, int(AudioBus* source, - AudioBus* dest, - AudioBuffersState buffers_state)); - MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); -}; - // AudioOutputStream::AudioSourceCallback implementation which enables audio // play-through. It also creates a text file that contains times between two // successive callbacks. Units are in milliseconds. This file can be used for @@ -295,7 +285,7 @@ TEST(WASAPIUnifiedStreamTest, OpenStartAndClose) { if (!CanRunUnifiedAudioTests(audio_manager.get())) return; - MockUnifiedSourceCallback source; + MockAudioSourceCallback source; AudioUnifiedStreamWrapper ausw(audio_manager.get()); WASAPIUnifiedStream* wus = ausw.Create(); @@ -316,7 +306,7 @@ TEST(WASAPIUnifiedStreamTest, StartLoopbackAudio) { return; base::MessageLoopForUI loop; - MockUnifiedSourceCallback source; + MockAudioSourceCallback source; AudioUnifiedStreamWrapper ausw(audio_manager.get()); WASAPIUnifiedStream* wus = ausw.Create(); |