diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-15 08:34:06 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-15 08:34:06 +0000 |
commit | 74532a5880470f854def44a862a79af012bfd395 (patch) | |
tree | bfd5181457430fc88f39246364cb575f1593bc92 /media/audio/fake_audio_input_stream_unittest.cc | |
parent | 9ea053e87d2141867ee3429d8917809fe2e33c80 (diff) | |
download | chromium_src-74532a5880470f854def44a862a79af012bfd395.zip chromium_src-74532a5880470f854def44a862a79af012bfd395.tar.gz chromium_src-74532a5880470f854def44a862a79af012bfd395.tar.bz2 |
Add a fake audio input stream for testing purposes.
This will be used by unit tests in subsequent patches.
BUG=none
TEST=no new features added and nothing new to test
Review URL: http://codereview.chromium.org/2909015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52464 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/fake_audio_input_stream_unittest.cc')
-rw-r--r-- | media/audio/fake_audio_input_stream_unittest.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/media/audio/fake_audio_input_stream_unittest.cc b/media/audio/fake_audio_input_stream_unittest.cc new file mode 100644 index 0000000..16e86a4 --- /dev/null +++ b/media/audio/fake_audio_input_stream_unittest.cc @@ -0,0 +1,51 @@ +// Copyright (c) 2010 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 "base/basictypes.h" +#include "base/platform_thread.h" +#include "media/audio/audio_io.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +using ::testing::_; +using ::testing::AtLeast; +using ::testing::Exactly; +using ::testing::NotNull; + +namespace { + +class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { + public: + MockAudioInputCallback() {} + + MOCK_METHOD1(OnClose, void(AudioInputStream* stream)); + MOCK_METHOD2(OnError, void(AudioInputStream* stream, int error_code)); + MOCK_METHOD3(OnData, void(AudioInputStream* stream, const uint8* src, + uint32 size)); + private: + DISALLOW_COPY_AND_ASSIGN(MockAudioInputCallback); +}; + +} + +// ============================================================================ +// Validate that the AudioManager::AUDIO_MOCK callbacks work. +TEST(FakeAudioInputTest, BasicCallbacks) { + MockAudioInputCallback callback; + EXPECT_CALL(callback, OnData(NotNull(), _, _)).Times(AtLeast(5)); + EXPECT_CALL(callback, OnError(NotNull(), _)).Times(Exactly(0)); + + AudioManager* audio_man = AudioManager::GetAudioManager(); + ASSERT_TRUE(NULL != audio_man); + // Ask for one recorded packet every 50ms. + AudioInputStream* stream = audio_man->MakeAudioInputStream( + AudioManager::AUDIO_MOCK, 2, 8000, 8, 400); + ASSERT_TRUE(NULL != stream); + EXPECT_TRUE(stream->Open()); + stream->Start(&callback); + PlatformThread::Sleep(340); // Give sufficient time to receive 5 / 6 packets. + stream->Stop(); + stream->Close(); +} + |