VoE: VoENetwork unit test

Changes:
1. Added MockTransport.
2. Added VoiceEngineFixture class to be used in VoE unit tests. This class is in no way final as it is - it will grow as we add more unit tests and our understanding of the Voice Engine grows.
3. Modified VoEBase unit test to use VoiceEngineFixture.
4. Added VoENetwork unit test.

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

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

Cr-Commit-Position: refs/heads/master@{#9118}
This commit is contained in:
Jelena Marusic
2015-04-30 10:57:10 +02:00
parent 3cfa756f37
commit 46bd31b994
6 changed files with 260 additions and 29 deletions

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_VOICE_ENGINE_MOCK_TRANSPORT_H_
#define WEBRTC_VOICE_ENGINE_MOCK_TRANSPORT_H_
#include "testing/gmock/include/gmock/gmock.h"
#include "webrtc/common_types.h"
namespace webrtc {
class MockTransport : public Transport {
public:
MOCK_METHOD3(SendPacket, int(int channel, const void* data, size_t len));
MOCK_METHOD3(SendRTCPPacket, int(int channel, const void* data, size_t len));
};
} // namespace webrtc
#endif // WEBRTC_VOICE_ENGINE_MOCK_TRANSPORT_H_

View File

@ -11,57 +11,36 @@
#include "webrtc/voice_engine/include/voe_base.h"
#include "testing/gtest/include/gtest/gtest.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"
#include "webrtc/voice_engine/voice_engine_fixture.h"
namespace webrtc {
class VoEBaseTest : public ::testing::Test {
protected:
VoEBaseTest() :
voe_(VoiceEngine::Create()),
base_(VoEBase::GetInterface(voe_)) {
EXPECT_NE(nullptr, base_);
EXPECT_EQ(0, base_->RegisterVoiceEngineObserver(observer_));
}
class VoEBaseFixture : public VoiceEngineFixture {};
~VoEBaseTest() {
EXPECT_EQ(0, base_->DeRegisterVoiceEngineObserver());
EXPECT_EQ(0, base_->Terminate());
EXPECT_EQ(1, base_->Release());
EXPECT_TRUE(VoiceEngine::Delete(voe_));
}
VoiceEngine* voe_;
VoEBase* base_;
MockVoEObserver observer_;
FakeAudioDeviceModule adm_;
};
TEST_F(VoEBaseTest, InitWithExternalAudioDeviceAndAudioProcessing) {
TEST_F(VoEBaseFixture, InitWithExternalAudioDeviceAndAudioProcessing) {
AudioProcessing* audioproc = AudioProcessing::Create();
EXPECT_EQ(0, base_->Init(&adm_, audioproc));
EXPECT_EQ(audioproc, base_->audio_processing());
EXPECT_EQ(0, base_->LastError());
}
TEST_F(VoEBaseTest, InitWithExternalAudioDevice) {
TEST_F(VoEBaseFixture, 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) {
TEST_F(VoEBaseFixture, CreateChannelBeforeInitShouldFail) {
int channelID = base_->CreateChannel();
EXPECT_EQ(-1, channelID);
EXPECT_EQ(channelID, -1);
}
TEST_F(VoEBaseTest, CreateChannelAfterInitShouldPass) {
TEST_F(VoEBaseFixture, CreateChannelAfterInit) {
EXPECT_EQ(0, base_->Init(&adm_, nullptr));
int channelID = base_->CreateChannel();
EXPECT_NE(-1, channelID);
EXPECT_NE(channelID, -1);
EXPECT_EQ(0, base_->DeleteChannel(channelID));
}

View File

@ -0,0 +1,157 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/voice_engine/include/voe_network.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/voice_engine/include/voe_errors.h"
#include "webrtc/voice_engine/voice_engine_fixture.h"
namespace webrtc {
enum {
kSizeTooSmallForRtcp = 2, // Minimum size of a valid RTCP packet is 4.
kSizeTooSmallForRtp = 10, // Minimum size of a valid RTP packet is 12.
kSizeGood = 12, // Acceptable size for both RTP and RTCP packets.
kSizeTooLarge = 1300 // Maximum size of a valid RTP packet is 1292.
};
// A packet with a valid header for both RTP and RTCP.
// Methods that are tested here are checking only packet header.
static const uint8_t kPacket[kSizeGood] = {0x80};
static const uint8_t kPacketJunk[kSizeGood] = {};
static const int kNonExistingChannel = 1234;
class VoENetworkFixture : public VoiceEngineFixture {
protected:
int CreateChannelAndRegisterExternalTransport() {
EXPECT_EQ(0, base_->Init(&adm_, nullptr));
int channelID = base_->CreateChannel();
EXPECT_NE(channelID, -1);
EXPECT_EQ(0, network_->RegisterExternalTransport(channelID, transport_));
return channelID;
}
};
TEST_F(VoENetworkFixture, RegisterExternalTransport) {
int channelID = CreateChannelAndRegisterExternalTransport();
EXPECT_EQ(0, network_->DeRegisterExternalTransport(channelID));
}
TEST_F(VoENetworkFixture, RegisterExternalTransportBeforeInitShouldFail) {
EXPECT_NE(
0, network_->RegisterExternalTransport(kNonExistingChannel, transport_));
}
TEST_F(VoENetworkFixture, DeRegisterExternalTransportBeforeInitShouldFail) {
EXPECT_NE(0, network_->DeRegisterExternalTransport(kNonExistingChannel));
}
TEST_F(VoENetworkFixture,
RegisterExternalTransportOnNonExistingChannelShouldFail) {
EXPECT_EQ(0, base_->Init(&adm_, nullptr));
EXPECT_NE(
0, network_->RegisterExternalTransport(kNonExistingChannel, transport_));
}
TEST_F(VoENetworkFixture,
DeRegisterExternalTransportOnNonExistingChannelShouldFail) {
EXPECT_EQ(0, base_->Init(&adm_, nullptr));
EXPECT_NE(0, network_->DeRegisterExternalTransport(kNonExistingChannel));
}
TEST_F(VoENetworkFixture, DeRegisterExternalTransportBeforeRegister) {
EXPECT_EQ(0, base_->Init(&adm_, nullptr));
int channelID = base_->CreateChannel();
EXPECT_NE(channelID, -1);
EXPECT_EQ(0, network_->DeRegisterExternalTransport(channelID));
}
TEST_F(VoENetworkFixture, ReceivedRTPPacketWithJunkDataShouldFail) {
int channelID = CreateChannelAndRegisterExternalTransport();
EXPECT_EQ(-1, network_->ReceivedRTPPacket(channelID, kPacketJunk,
sizeof(kPacketJunk)));
}
TEST_F(VoENetworkFixture, ReceivedRTPPacketBeforeInitShouldFail) {
EXPECT_EQ(-1, network_->ReceivedRTPPacket(0, kPacket, sizeof(kPacket)));
}
TEST_F(VoENetworkFixture, ReceivedRTPPacketOnNonExistingChannelShouldFail) {
EXPECT_EQ(0, base_->Init(&adm_, nullptr));
EXPECT_EQ(-1, network_->ReceivedRTPPacket(kNonExistingChannel, kPacket,
sizeof(kPacket)));
}
TEST_F(VoENetworkFixture,
ReceivedRTPPacketOnChannelWithoutTransportShouldFail) {
EXPECT_EQ(0, base_->Init(&adm_, nullptr));
int channelID = base_->CreateChannel();
EXPECT_NE(channelID, -1);
EXPECT_EQ(-1,
network_->ReceivedRTPPacket(channelID, kPacket, sizeof(kPacket)));
}
TEST_F(VoENetworkFixture, ReceivedTooSmallRTPPacketShouldFail) {
int channelID = CreateChannelAndRegisterExternalTransport();
EXPECT_EQ(
-1, network_->ReceivedRTPPacket(channelID, kPacket, kSizeTooSmallForRtp));
}
TEST_F(VoENetworkFixture, ReceivedTooLargeRTPPacketShouldFail) {
int channelID = CreateChannelAndRegisterExternalTransport();
EXPECT_EQ(-1, network_->ReceivedRTPPacket(channelID, kPacket, kSizeTooLarge));
}
TEST_F(VoENetworkFixture, ReceivedRTPPacketWithNullDataShouldFail) {
int channelID = CreateChannelAndRegisterExternalTransport();
EXPECT_EQ(-1, network_->ReceivedRTPPacket(channelID, nullptr, 0));
}
TEST_F(VoENetworkFixture, ReceivedRTCPPacketWithJunkDataShouldFail) {
int channelID = CreateChannelAndRegisterExternalTransport();
EXPECT_EQ(0, network_->ReceivedRTCPPacket(channelID, kPacketJunk,
sizeof(kPacketJunk)));
EXPECT_EQ(VE_SOCKET_TRANSPORT_MODULE_ERROR, base_->LastError());
}
TEST_F(VoENetworkFixture, ReceivedRTCPPacketBeforeInitShouldFail) {
EXPECT_EQ(-1, network_->ReceivedRTCPPacket(kNonExistingChannel, kPacket,
sizeof(kPacket)));
}
TEST_F(VoENetworkFixture, ReceivedRTCPPacketOnNonExistingChannelShouldFail) {
EXPECT_EQ(0, base_->Init(&adm_, nullptr));
EXPECT_EQ(-1, network_->ReceivedRTCPPacket(kNonExistingChannel, kPacket,
sizeof(kPacket)));
}
TEST_F(VoENetworkFixture,
ReceivedRTCPPacketOnChannelWithoutTransportShouldFail) {
EXPECT_EQ(0, base_->Init(&adm_, nullptr));
int channelID = base_->CreateChannel();
EXPECT_NE(channelID, -1);
EXPECT_EQ(-1,
network_->ReceivedRTCPPacket(channelID, kPacket, sizeof(kPacket)));
}
TEST_F(VoENetworkFixture, ReceivedTooSmallRTCPPacket4ShouldFail) {
int channelID = CreateChannelAndRegisterExternalTransport();
EXPECT_EQ(-1, network_->ReceivedRTCPPacket(channelID, kPacket,
kSizeTooSmallForRtcp));
}
TEST_F(VoENetworkFixture, ReceivedRTCPPacketWithNullDataShouldFail) {
int channelID = CreateChannelAndRegisterExternalTransport();
EXPECT_EQ(-1, network_->ReceivedRTCPPacket(channelID, nullptr, 0));
}
} // namespace webrtc

View File

@ -129,6 +129,9 @@
'voe_audio_processing_unittest.cc',
'voe_base_unittest.cc',
'voe_codec_unittest.cc',
'voe_network_unittest.cc',
'voice_engine_fixture.cc',
'voice_engine_fixture.h',
],
'conditions': [
['OS=="android"', {

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/voice_engine/voice_engine_fixture.h"
namespace webrtc {
VoiceEngineFixture::VoiceEngineFixture()
: voe_(VoiceEngine::Create()),
base_(VoEBase::GetInterface(voe_)),
network_(VoENetwork::GetInterface(voe_)) {
EXPECT_NE(nullptr, base_);
EXPECT_NE(nullptr, network_);
EXPECT_EQ(0, base_->RegisterVoiceEngineObserver(observer_));
}
VoiceEngineFixture::~VoiceEngineFixture() {
EXPECT_EQ(2, network_->Release());
EXPECT_EQ(0, base_->DeRegisterVoiceEngineObserver());
EXPECT_EQ(0, base_->Terminate());
EXPECT_EQ(1, base_->Release());
EXPECT_TRUE(VoiceEngine::Delete(voe_));
}
} // namespace webrtc

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/modules/audio_device/include/fake_audio_device.h"
#include "webrtc/voice_engine/include/voe_base.h"
#include "webrtc/voice_engine/include/voe_network.h"
#include "webrtc/voice_engine/mock/mock_transport.h"
#include "webrtc/voice_engine/mock/mock_voe_observer.h"
namespace webrtc {
class VoiceEngineFixture : public ::testing::Test {
protected:
VoiceEngineFixture();
~VoiceEngineFixture();
VoiceEngine* voe_;
VoEBase* base_;
VoENetwork* network_;
MockVoEObserver observer_;
FakeAudioDeviceModule adm_;
MockTransport transport_;
};
} // namespace webrtc