diff --git a/webrtc/voice_engine/include/voe_base.h b/webrtc/voice_engine/include/voe_base.h index b99f36aa81..4881939478 100644 --- a/webrtc/voice_engine/include/voe_base.h +++ b/webrtc/voice_engine/include/voe_base.h @@ -109,11 +109,11 @@ public: virtual int Release() = 0; // 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; // Removes and disables the observer class for runtime error control - // and warning notifications. + // and warning notifications. Returns 0. virtual int DeRegisterVoiceEngineObserver() = 0; // Initializes all common parts of the VoiceEngine; e.g. all @@ -125,6 +125,7 @@ public: // - The AudioProcessing module handles capture-side processing. VoiceEngine // takes ownership of this object. // 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. virtual int Init(AudioDeviceModule* external_adm = NULL, AudioProcessing* audioproc = NULL) = 0; @@ -132,16 +133,19 @@ public: // Returns NULL before Init() is called. 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; // Creates a new channel and allocates the required resources for it. // One can use |config| to configure the channel. Currently that is used for // 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(const Config& config) = 0; // Deletes an existing channel and releases the utilized resources. + // Returns -1 in case of an error, 0 otherwise. virtual int DeleteChannel(int channel) = 0; // Prepares and initiates the VoiceEngine for reception of diff --git a/webrtc/voice_engine/voe_base_unittest.cc b/webrtc/voice_engine/voe_base_unittest.cc index 69aba712ef..ea90bbae1d 100644 --- a/webrtc/voice_engine/voe_base_unittest.cc +++ b/webrtc/voice_engine/voe_base_unittest.cc @@ -11,9 +11,9 @@ #include "webrtc/voice_engine/include/voe_base.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_processing/include/audio_processing.h" +#include "webrtc/voice_engine/mock/mock_voe_observer.h" namespace webrtc { @@ -21,30 +21,48 @@ class VoEBaseTest : public ::testing::Test { protected: VoEBaseTest() : voe_(VoiceEngine::Create()), - base_(VoEBase::GetInterface(voe_)), - adm_(new FakeAudioDeviceModule) { + base_(VoEBase::GetInterface(voe_)) { + EXPECT_NE(nullptr, base_); + EXPECT_EQ(0, base_->RegisterVoiceEngineObserver(observer_)); } ~VoEBaseTest() { - base_->Release(); - VoiceEngine::Delete(voe_); + EXPECT_EQ(0, base_->DeRegisterVoiceEngineObserver()); + EXPECT_EQ(0, base_->Terminate()); + EXPECT_EQ(1, base_->Release()); + EXPECT_TRUE(VoiceEngine::Delete(voe_)); } VoiceEngine* voe_; VoEBase* base_; - rtc::scoped_ptr adm_; + MockVoEObserver observer_; + FakeAudioDeviceModule adm_; }; -TEST_F(VoEBaseTest, AcceptsAudioProcessingPtr) { +TEST_F(VoEBaseTest, InitWithExternalAudioDeviceAndAudioProcessing) { 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(0, base_->LastError()); } -TEST_F(VoEBaseTest, AudioProcessingCreatedAfterInit) { - EXPECT_TRUE(base_->audio_processing() == NULL); - EXPECT_EQ(0, base_->Init(adm_.get(), NULL)); - EXPECT_TRUE(base_->audio_processing() != NULL); +TEST_F(VoEBaseTest, InitWithExternalAudioDevice) { + EXPECT_EQ(nullptr, base_->audio_processing()); + EXPECT_EQ(0, base_->Init(&adm_, nullptr)); + 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 diff --git a/webrtc/voice_engine/voice_engine.gyp b/webrtc/voice_engine/voice_engine.gyp index c6f3619baa..55d5b71638 100644 --- a/webrtc/voice_engine/voice_engine.gyp +++ b/webrtc/voice_engine/voice_engine.gyp @@ -106,6 +106,7 @@ 'type': '<(gtest_target_type)', 'dependencies': [ 'voice_engine', + '<(DEPTH)/testing/gmock.gyp:gmock', '<(DEPTH)/testing/gtest.gyp:gtest', # The rest are to satisfy the unittests' include chain. # This would be unnecessary if we used qualified includes.