VoE: VoEBase unit test

Changes:
1. Documented return values of VoEBase methods.
2. Added/modified VoEBase unit test.

R=henrika@webrtc.org, kwiberg@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/51669004

Cr-Commit-Position: refs/heads/master@{#9038}
This commit is contained in:
Jelena Marusic
2015-04-21 11:39:57 +02:00
parent c4905fb72a
commit 06b08afb67
3 changed files with 38 additions and 15 deletions

View File

@ -109,11 +109,11 @@ public:
virtual int Release() = 0; virtual int Release() = 0;
// Installs the observer class to enable runtime error control and // Installs the observer class to enable runtime error control and
// warning notifications. // warning notifications. Returns -1 in case of an error, 0 otherwise.
virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) = 0; virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) = 0;
// Removes and disables the observer class for runtime error control // Removes and disables the observer class for runtime error control
// and warning notifications. // and warning notifications. Returns 0.
virtual int DeRegisterVoiceEngineObserver() = 0; virtual int DeRegisterVoiceEngineObserver() = 0;
// Initializes all common parts of the VoiceEngine; e.g. all // Initializes all common parts of the VoiceEngine; e.g. all
@ -125,6 +125,7 @@ public:
// - The AudioProcessing module handles capture-side processing. VoiceEngine // - The AudioProcessing module handles capture-side processing. VoiceEngine
// takes ownership of this object. // takes ownership of this object.
// If NULL is passed for any of these, VoiceEngine will create its own. // If NULL is passed for any of these, VoiceEngine will create its own.
// Returns -1 in case of an error, 0 otherwise.
// TODO(ajm): Remove default NULLs. // TODO(ajm): Remove default NULLs.
virtual int Init(AudioDeviceModule* external_adm = NULL, virtual int Init(AudioDeviceModule* external_adm = NULL,
AudioProcessing* audioproc = NULL) = 0; AudioProcessing* audioproc = NULL) = 0;
@ -132,16 +133,19 @@ public:
// Returns NULL before Init() is called. // Returns NULL before Init() is called.
virtual AudioProcessing* audio_processing() = 0; virtual AudioProcessing* audio_processing() = 0;
// Terminates all VoiceEngine functions and releses allocated resources. // Terminates all VoiceEngine functions and releases allocated resources.
// Returns 0.
virtual int Terminate() = 0; virtual int Terminate() = 0;
// Creates a new channel and allocates the required resources for it. // Creates a new channel and allocates the required resources for it.
// One can use |config| to configure the channel. Currently that is used for // One can use |config| to configure the channel. Currently that is used for
// choosing between ACM1 and ACM2, when creating Audio Coding Module. // choosing between ACM1 and ACM2, when creating Audio Coding Module.
// Returns channel ID or -1 in case of an error.
virtual int CreateChannel() = 0; virtual int CreateChannel() = 0;
virtual int CreateChannel(const Config& config) = 0; virtual int CreateChannel(const Config& config) = 0;
// Deletes an existing channel and releases the utilized resources. // Deletes an existing channel and releases the utilized resources.
// Returns -1 in case of an error, 0 otherwise.
virtual int DeleteChannel(int channel) = 0; virtual int DeleteChannel(int channel) = 0;
// Prepares and initiates the VoiceEngine for reception of // Prepares and initiates the VoiceEngine for reception of

View File

@ -11,9 +11,9 @@
#include "webrtc/voice_engine/include/voe_base.h" #include "webrtc/voice_engine/include/voe_base.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/modules/audio_device/include/fake_audio_device.h" #include "webrtc/modules/audio_device/include/fake_audio_device.h"
#include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/audio_processing/include/audio_processing.h"
#include "webrtc/voice_engine/mock/mock_voe_observer.h"
namespace webrtc { namespace webrtc {
@ -21,30 +21,48 @@ class VoEBaseTest : public ::testing::Test {
protected: protected:
VoEBaseTest() : VoEBaseTest() :
voe_(VoiceEngine::Create()), voe_(VoiceEngine::Create()),
base_(VoEBase::GetInterface(voe_)), base_(VoEBase::GetInterface(voe_)) {
adm_(new FakeAudioDeviceModule) { EXPECT_NE(nullptr, base_);
EXPECT_EQ(0, base_->RegisterVoiceEngineObserver(observer_));
} }
~VoEBaseTest() { ~VoEBaseTest() {
base_->Release(); EXPECT_EQ(0, base_->DeRegisterVoiceEngineObserver());
VoiceEngine::Delete(voe_); EXPECT_EQ(0, base_->Terminate());
EXPECT_EQ(1, base_->Release());
EXPECT_TRUE(VoiceEngine::Delete(voe_));
} }
VoiceEngine* voe_; VoiceEngine* voe_;
VoEBase* base_; VoEBase* base_;
rtc::scoped_ptr<FakeAudioDeviceModule> adm_; MockVoEObserver observer_;
FakeAudioDeviceModule adm_;
}; };
TEST_F(VoEBaseTest, AcceptsAudioProcessingPtr) { TEST_F(VoEBaseTest, InitWithExternalAudioDeviceAndAudioProcessing) {
AudioProcessing* audioproc = AudioProcessing::Create(); AudioProcessing* audioproc = AudioProcessing::Create();
EXPECT_EQ(0, base_->Init(adm_.get(), audioproc)); EXPECT_EQ(0, base_->Init(&adm_, audioproc));
EXPECT_EQ(audioproc, base_->audio_processing()); EXPECT_EQ(audioproc, base_->audio_processing());
EXPECT_EQ(0, base_->LastError());
} }
TEST_F(VoEBaseTest, AudioProcessingCreatedAfterInit) { TEST_F(VoEBaseTest, InitWithExternalAudioDevice) {
EXPECT_TRUE(base_->audio_processing() == NULL); EXPECT_EQ(nullptr, base_->audio_processing());
EXPECT_EQ(0, base_->Init(adm_.get(), NULL)); EXPECT_EQ(0, base_->Init(&adm_, nullptr));
EXPECT_TRUE(base_->audio_processing() != NULL); EXPECT_NE(nullptr, base_->audio_processing());
EXPECT_EQ(0, base_->LastError());
}
TEST_F(VoEBaseTest, CreateChannelBeforeInitShouldFail) {
int channelID = base_->CreateChannel();
EXPECT_EQ(-1, channelID);
}
TEST_F(VoEBaseTest, CreateChannelAfterInitShouldPass) {
EXPECT_EQ(0, base_->Init(&adm_, nullptr));
int channelID = base_->CreateChannel();
EXPECT_NE(-1, channelID);
EXPECT_EQ(0, base_->DeleteChannel(channelID));
} }
} // namespace webrtc } // namespace webrtc

View File

@ -106,6 +106,7 @@
'type': '<(gtest_target_type)', 'type': '<(gtest_target_type)',
'dependencies': [ 'dependencies': [
'voice_engine', 'voice_engine',
'<(DEPTH)/testing/gmock.gyp:gmock',
'<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/testing/gtest.gyp:gtest',
# The rest are to satisfy the unittests' include chain. # The rest are to satisfy the unittests' include chain.
# This would be unnecessary if we used qualified includes. # This would be unnecessary if we used qualified includes.