Rewrote hardware-before-init and rtp-rtcp-before-streaming test code to gtest.

BUG=
TEST=

Review URL: http://webrtc-codereview.appspot.com/322003

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1161 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
phoglund@webrtc.org 2011-12-12 16:24:23 +00:00
parent 1480f02faf
commit 6418a24795
7 changed files with 296 additions and 175 deletions

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2011 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 "common_types.h"
#include "test_base.h"
using namespace webrtc;
class HardwareBeforeInitializingTest : public TestBase {
};
TEST_F(HardwareBeforeInitializingTest,
SetAudioDeviceLayerAcceptsPlatformDefaultBeforeInitializing) {
AudioLayers wanted_layer = kAudioPlatformDefault;
AudioLayers given_layer;
EXPECT_EQ(0, voe_hardware_->SetAudioDeviceLayer(wanted_layer));
EXPECT_EQ(0, voe_hardware_->GetAudioDeviceLayer(given_layer));
EXPECT_EQ(wanted_layer, given_layer) <<
"These should be the same before initializing.";
}

View File

@ -0,0 +1,156 @@
/*
* Copyright (c) 2011 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 "test_base.h"
using namespace webrtc;
using namespace testing;
class TestErrorObserver : public VoiceEngineObserver {
public:
TestErrorObserver() {}
virtual ~TestErrorObserver() {}
void CallbackOnError(const int channel, const int error_code) {
ADD_FAILURE() << "Unexpected error on channel " << channel <<
": error code " << error_code;
}
};
class RtpRtcpBeforeStreamingTest : public TestBase {
protected:
TestErrorObserver error_observer_;
void SetUp();
void TearDown();
int channel_;
};
void RtpRtcpBeforeStreamingTest::SetUp() {
#if defined BLACKFIN
EXPECT_EQ(0, voe_base_->Init(0, LINUX_AUDIO_OSS));
#else
EXPECT_EQ(0, voe_base_->Init());
#endif
#if defined(WEBRTC_ANDROID)
EXPECT_EQ(0, voe_hardware_->SetLoudspeakerStatus(false));
#endif
// Ensure we have an error observer and a channel up.
EXPECT_EQ(0, voe_base_->RegisterVoiceEngineObserver(error_observer_));
EXPECT_THAT(channel_ = voe_base_->CreateChannel(), Not(Lt(0)));
}
void RtpRtcpBeforeStreamingTest::TearDown() {
EXPECT_EQ(0, voe_base_->DeleteChannel(channel_));
EXPECT_EQ(0, voe_base_->DeRegisterVoiceEngineObserver());
}
TEST_F(RtpRtcpBeforeStreamingTest, MaxNumChannelsIsBiggerThanZero) {
EXPECT_GT(voe_base_->MaxNumOfChannels(), 0);
}
TEST_F(RtpRtcpBeforeStreamingTest, GetVersionPrintsSomeUsefulInformation) {
char char_buffer[1024];
EXPECT_EQ(0, voe_base_->GetVersion(char_buffer));
EXPECT_THAT(char_buffer, ContainsRegex("VoiceEngine [0-9].[0-9].[0-9]"));
}
TEST_F(RtpRtcpBeforeStreamingTest,
GetRtcpStatusReturnsTrueByDefaultAndObeysSetRtcpStatus) {
bool on;
EXPECT_EQ(0, voe_rtp_rtcp_->GetRTCPStatus(channel_, on));
EXPECT_TRUE(on);
EXPECT_EQ(0, voe_rtp_rtcp_->SetRTCPStatus(channel_, false));
EXPECT_EQ(0, voe_rtp_rtcp_->GetRTCPStatus(channel_, on));
EXPECT_FALSE(on);
EXPECT_EQ(0, voe_rtp_rtcp_->SetRTCPStatus(channel_, true));
EXPECT_EQ(0, voe_rtp_rtcp_->GetRTCPStatus(channel_, on));
EXPECT_TRUE(on);
}
TEST_F(RtpRtcpBeforeStreamingTest, RtpKeepAliveStatusIsOffByDefault) {
unsigned char payload_type;
int delta_seconds;
bool on;
// Should be off by default.
EXPECT_EQ(0, voe_rtp_rtcp_->GetRTPKeepaliveStatus(
channel_, on, payload_type, delta_seconds));
EXPECT_FALSE(on);
EXPECT_EQ(255, payload_type);
EXPECT_EQ(0, delta_seconds);
}
TEST_F(RtpRtcpBeforeStreamingTest, SetRtpKeepAliveDealsWithInvalidParameters) {
unsigned char payload_type;
int delta_seconds;
bool on;
// Verify invalid input parameters.
EXPECT_NE(0, voe_rtp_rtcp_->GetRTPKeepaliveStatus(
-1, on, payload_type, delta_seconds)) <<
"Should fail for invalid channel -1.";
EXPECT_NE(0, voe_rtp_rtcp_->SetRTPKeepaliveStatus(
-1, true, 0, 15)) <<
"Should fail for invalid channel -1.";
EXPECT_NE(0, voe_rtp_rtcp_->SetRTPKeepaliveStatus(
channel_, true, -1, 15)) <<
"Should fail for invalid payload -1.";
EXPECT_NE(0, voe_rtp_rtcp_->SetRTPKeepaliveStatus(
channel_, true, 0, 61)) <<
"The delta time must be [1, 60] seconds.";
EXPECT_EQ(0, voe_rtp_rtcp_->GetRTPKeepaliveStatus(
channel_, on, payload_type, delta_seconds));
EXPECT_NE(0, voe_rtp_rtcp_->SetRTPKeepaliveStatus(
channel_, true, 0));
// Should still be off, default 0 used by PCMU.
EXPECT_FALSE(on);
}
TEST_F(RtpRtcpBeforeStreamingTest,
GetRtpKeepaliveStatusObeysSetRtpKeepaliveStatus) {
EXPECT_EQ(0, voe_rtp_rtcp_->SetRTCP_CNAME(channel_, "SomeName"));
// Try valid settings.
EXPECT_EQ(0, voe_rtp_rtcp_->SetRTPKeepaliveStatus(
channel_, true, 1));
unsigned char payload_type;
int delta_seconds;
bool on;
EXPECT_EQ(0, voe_rtp_rtcp_->GetRTPKeepaliveStatus(
0, on, payload_type, delta_seconds));
EXPECT_TRUE(on);
EXPECT_EQ(1, payload_type);
EXPECT_EQ(15, delta_seconds) << "15 seconds delta is default.";
// Set the keep-alive payload to 60, which the codecs can't use.
EXPECT_EQ(0, voe_rtp_rtcp_->SetRTPKeepaliveStatus(
channel_, true, 60, 3));
EXPECT_EQ(0, voe_rtp_rtcp_->GetRTPKeepaliveStatus(
channel_, on, payload_type, delta_seconds));
EXPECT_TRUE(on);
EXPECT_EQ(60, payload_type);
EXPECT_EQ(3, delta_seconds);
EXPECT_EQ(0, voe_rtp_rtcp_->SetRTPKeepaliveStatus(
channel_, false, 60));
}
TEST_F(RtpRtcpBeforeStreamingTest, GetLocalSsrcObeysSetLocalSsrc) {
EXPECT_EQ(0, voe_rtp_rtcp_->SetLocalSSRC(channel_, 1234));
unsigned int result = 0;
EXPECT_EQ(0, voe_rtp_rtcp_->GetLocalSSRC(channel_, result));
EXPECT_EQ(1234u, result);
}

View File

@ -0,0 +1,108 @@
/*
* Copyright (c) 2011 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 SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_H_
#define SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_H_
#include <assert.h>
#include "common_types.h"
#include "voe_audio_processing.h"
#include "voe_base.h"
#include "voe_call_report.h"
#include "voe_codec.h"
#include "voe_dtmf.h"
#include "voe_encryption.h"
#include "voe_errors.h"
#include "voe_external_media.h"
#include "voe_file.h"
#include "voe_hardware.h"
#include "voe_neteq_stats.h"
#include "voe_network.h"
#include "voe_rtp_rtcp.h"
#include "voe_test_defines.h"
#include "voe_video_sync.h"
#include "voe_volume_control.h"
// TODO(qhogpat): Remove these undefs once the clashing macros are gone.
#undef TEST
#undef ASSERT_TRUE
#undef ASSERT_FALSE
#include "gtest/gtest.h"
#include "gmock/gmock.h"
// This convenience class sets up all the VoE interfaces automatically for
// use by testing subclasses. It allocates each interface and releases it once
// which means that if a tests allocates additional interfaces from the voice
// engine and forgets to release it, this test will fail in the destructor.
class TestBase : public testing::Test {
public:
// The interface fetching is done in the constructor and not SetUp() since
// this relieves our subclasses from calling SetUp in the superclass if they
// choose to override SetUp() themselves. This is fine as googletest will
// construct new test objects for each method.
TestBase() {
voice_engine_ = webrtc::VoiceEngine::Create();
EXPECT_TRUE(voice_engine_ != NULL);
voe_base_ = webrtc::VoEBase::GetInterface(voice_engine_);
voe_codec_ = webrtc::VoECodec::GetInterface(voice_engine_);
voe_volume_control_ = webrtc::VoEVolumeControl::GetInterface(voice_engine_);
voe_dtmf_ = webrtc::VoEDtmf::GetInterface(voice_engine_);
voe_rtp_rtcp_ = webrtc::VoERTP_RTCP::GetInterface(voice_engine_);
voe_apm_ = webrtc::VoEAudioProcessing::GetInterface(voice_engine_);
voe_network_ = webrtc::VoENetwork::GetInterface(voice_engine_);
voe_file_ = webrtc::VoEFile::GetInterface(voice_engine_);
voe_vsync_ = webrtc::VoEVideoSync::GetInterface(voice_engine_);
voe_encrypt_ = webrtc::VoEEncryption::GetInterface(voice_engine_);
voe_hardware_ = webrtc::VoEHardware::GetInterface(voice_engine_);
voe_xmedia_ = webrtc::VoEExternalMedia::GetInterface(voice_engine_);
voe_call_report_ = webrtc::VoECallReport::GetInterface(voice_engine_);
voe_neteq_stats_ = webrtc::VoENetEqStats::GetInterface(voice_engine_);
}
virtual ~TestBase() {
EXPECT_EQ(0, voe_base_->Release());
EXPECT_EQ(0, voe_codec_->Release());
EXPECT_EQ(0, voe_volume_control_->Release());
EXPECT_EQ(0, voe_dtmf_->Release());
EXPECT_EQ(0, voe_rtp_rtcp_->Release());
EXPECT_EQ(0, voe_apm_->Release());
EXPECT_EQ(0, voe_network_->Release());
EXPECT_EQ(0, voe_file_->Release());
EXPECT_EQ(0, voe_vsync_->Release());
EXPECT_EQ(0, voe_encrypt_->Release());
EXPECT_EQ(0, voe_hardware_->Release());
EXPECT_EQ(0, voe_xmedia_->Release());
EXPECT_EQ(0, voe_call_report_->Release());
EXPECT_EQ(0, voe_neteq_stats_->Release());
EXPECT_TRUE(webrtc::VoiceEngine::Delete(voice_engine_));
}
protected:
webrtc::VoiceEngine* voice_engine_;
webrtc::VoEBase* voe_base_;
webrtc::VoECodec* voe_codec_;
webrtc::VoEVolumeControl* voe_volume_control_;
webrtc::VoEDtmf* voe_dtmf_;
webrtc::VoERTP_RTCP* voe_rtp_rtcp_;
webrtc::VoEAudioProcessing* voe_apm_;
webrtc::VoENetwork* voe_network_;
webrtc::VoEFile* voe_file_;
webrtc::VoEVideoSync* voe_vsync_;
webrtc::VoEEncryption* voe_encrypt_;
webrtc::VoEHardware* voe_hardware_;
webrtc::VoEExternalMedia* voe_xmedia_;
webrtc::VoECallReport* voe_call_report_;
webrtc::VoENetEqStats* voe_neteq_stats_;
};
#endif // SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_H_

View File

@ -1,45 +0,0 @@
/*
* Copyright (c) 2011 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 "voe_standard_test.h"
// These symbols clash with gtest, so undef them:
#undef TEST
#undef ASSERT_TRUE
#undef ASSERT_FALSE
#include "gtest/gtest.h"
namespace {
class VoEStandardIntegrationTest: public testing::Test {
public:
virtual ~VoEStandardIntegrationTest() {}
// Initializes the test manager.
virtual void SetUp() {
ASSERT_TRUE(test_manager_.Init());
test_manager_.GetInterfaces();
}
// Releases anything allocated by SetUp.
virtual void TearDown() {
ASSERT_EQ(0, test_manager_.ReleaseInterfaces());
}
protected:
voetest::VoETestManager test_manager_;
};
TEST_F(VoEStandardIntegrationTest, RunsStandardTestWithoutErrors) {
ASSERT_EQ(0, test_manager_.DoStandardTest());
}
} // namespace

View File

@ -897,73 +897,11 @@ int VoETestManager::ReleaseInterfaces() {
return (releaseOK == true) ? 0 : -1;
}
int VoETestManager::TestTraceApi() {
// Test trace callbacks.
TEST_LOG("Enabling the trace callback => default trace messages "
"shall be printed... \n\n");
MyTraceCallback* callback = new MyTraceCallback();
VoiceEngine::SetTraceCallback(callback);
// Test the remaining trace APIs.
TEST_MUSTPASS(VoiceEngine::SetTraceFile(GetFilename("webrtc_voe_trace.txt"),
true));
TEST_MUSTPASS(VoiceEngine::SetTraceFile(NULL));
TEST_MUSTPASS(VoiceEngine::SetTraceFile(GetFilename(
"webrtc_voe_trace.txt")));
VoiceEngine* extra = VoiceEngine::Create();
TEST_LOG("\nVerify that the VoE ID is now changed from 1 to 2\n\n");
TEST_MUSTPASS(VoiceEngine::SetTraceFile(NULL));
TEST_MUSTPASS(VoiceEngine::SetTraceFile(GetFilename(
"webrtc_voe_trace.txt")));
TEST_MUSTPASS(VoiceEngine::SetTraceFile(NULL));
VoiceEngine::Delete(extra);
SLEEP(10);
TEST_LOG("\nVerify that the VoE ID is now changed back to 1\n");
TEST_LOG("NOTE: Currently it will still be 2, this is OK\n\n");
// The API below shall be the first line in the stored trace file
// (verify after test).
TEST_MUSTPASS(VoiceEngine::SetTraceFile(GetFilename(
"webrtc_voe_trace.txt")));
VoiceEngine::SetTraceCallback(NULL);
delete callback;
TEST_LOG("\n...the trace callback is now disabled.\n\n");
return 0;
}
int VoETestManager::TestHardwareBeforeInitializing() {
#ifdef _TEST_HARDWARE_
TEST_LOG("Set/Get audio device layer\n");
AudioLayers wantedLayer = TESTED_AUDIO_LAYER;
AudioLayers givenLayer;
TEST_MUSTPASS(voe_hardware_->SetAudioDeviceLayer(wantedLayer));
TEST_MUSTPASS(voe_hardware_->GetAudioDeviceLayer(givenLayer));
TEST_MUSTPASS(wantedLayer != givenLayer); // Should be same before init
#endif //_TEST_HARDWARE_
TEST_LOG("Init \n");
#if defined BLACKFIN
TEST_MUSTPASS(voe_base_->Init(0,LINUX_AUDIO_OSS));
#else
TEST_MUSTPASS(voe_base_->Init());
#endif
#if defined(WEBRTC_ANDROID)
TEST_LOG("Setting loudspeaker status to false \n");
TEST_MUSTPASS(voe_hardware_->SetLoudspeakerStatus(false));
#endif
#ifndef __INSURE__
TEST_LOG("Enabling the observer \n");
TEST_MUSTPASS(voe_base_->RegisterVoiceEngineObserver(obs));
#endif
return 0;
}
int VoETestManager::SetUp() {
char char_buffer[1024];
TEST_MUSTPASS(voe_base_->Init());
TEST_LOG("Get version \n");
TEST_MUSTPASS(voe_base_->GetVersion(char_buffer));
TEST_LOG("--------------------\n%s\n--------------------\n", char_buffer);
@ -973,66 +911,7 @@ int VoETestManager::SetUp() {
TEST_MUSTPASS(!(nChannels > 0));
TEST_LOG("Max number of channels = %d \n", nChannels);
TEST_MUSTPASS(voe_base_->CreateChannel());
return 0;
}
int VoETestManager::TestRtpRtcpBeforeStreaming() {
#ifdef _TEST_RTP_RTCP_
TEST_LOG("\n\n+++ RTP/RTCP tests +++\n\n");
TEST_LOG("Set/Get RTCP and CName \n");
bool on;
// Should be on by default.
TEST_MUSTPASS(voe_rtp_rtcp_->GetRTCPStatus(0, on));
TEST_MUSTPASS(on != true);
TEST_MUSTPASS(voe_rtp_rtcp_->SetRTCPStatus(0, false));
TEST_MUSTPASS(voe_rtp_rtcp_->GetRTCPStatus(0, on));
TEST_MUSTPASS(on != false);
TEST_MUSTPASS(voe_rtp_rtcp_->SetRTCPStatus(0, true));
TEST_MUSTPASS(voe_rtp_rtcp_->GetRTCPStatus(0, on));
TEST_MUSTPASS(on != true);
TEST_MUSTPASS(voe_rtp_rtcp_->SetRTCP_CNAME(0, "Niklas"));
TEST_LOG("Set/Get RTP Keepalive\n");
unsigned char pt;
int dt;
TEST_MUSTPASS(!voe_rtp_rtcp_->GetRTPKeepaliveStatus(-1, on, pt, dt));
// Should be off by default.
TEST_MUSTPASS(voe_rtp_rtcp_->GetRTPKeepaliveStatus(0, on, pt, dt));
TEST_MUSTPASS(on != false);
TEST_MUSTPASS(pt != 255);
TEST_MUSTPASS(dt != 0);
// Verify invalid input parameters.
TEST_MUSTPASS(!voe_rtp_rtcp_->SetRTPKeepaliveStatus(-1, true, 0, 15));
TEST_MUSTPASS(!voe_rtp_rtcp_->SetRTPKeepaliveStatus(0, true, -1, 15));
TEST_MUSTPASS(!voe_rtp_rtcp_->SetRTPKeepaliveStatus(0, true, 0, 61));
// Should still be off.
TEST_MUSTPASS(voe_rtp_rtcp_->GetRTPKeepaliveStatus(0, on, pt, dt));
TEST_MUSTPASS(!voe_rtp_rtcp_->SetRTPKeepaliveStatus(0, true, 0));
// Should fail since default 0 is used bu PCMU.
TEST_MUSTPASS(on != false);
// Try valid settings.
TEST_MUSTPASS(voe_rtp_rtcp_->SetRTPKeepaliveStatus(0, true, 1));
TEST_MUSTPASS(voe_rtp_rtcp_->SetRTPKeepaliveStatus(0, true, 1));
// Should be on now.
TEST_MUSTPASS(voe_rtp_rtcp_->GetRTPKeepaliveStatus(0, on, pt, dt));
TEST_MUSTPASS(on != true);TEST_MUSTPASS(pt != 1);TEST_MUSTPASS(dt != 15);
// Set the Keep alive payload to 60, and this payloadtype could not used
// by the codecs.
TEST_MUSTPASS(voe_rtp_rtcp_->SetRTPKeepaliveStatus(0, true, 60, 3));
TEST_MUSTPASS(voe_rtp_rtcp_->GetRTPKeepaliveStatus(0, on, pt, dt));
TEST_MUSTPASS(on != true);TEST_MUSTPASS(pt != 60);TEST_MUSTPASS(dt != 3);
TEST_MUSTPASS(voe_rtp_rtcp_->SetRTPKeepaliveStatus(0, false, 60));
TEST_LOG("Set and get SSRC \n");
TEST_MUSTPASS(voe_rtp_rtcp_->SetLocalSSRC(0, 1234));
unsigned int send_ssrc = 0;
TEST_MUSTPASS(voe_rtp_rtcp_->GetLocalSSRC(0, send_ssrc));
TEST_MUSTPASS(1234 != send_ssrc);
#else
TEST_LOG("\n\n+++ RTP/RTCP tests NOT ENABLED +++\n");
#endif
return 0;
}
@ -1720,12 +1599,8 @@ int VoETestManager::TestCodecs() {
int VoETestManager::DoStandardTest() {
TEST_LOG("\n\n+++ Base tests +++\n\n");
if (TestTraceApi() != 0) return -1;
if (TestHardwareBeforeInitializing() != 0) return -1;
if (SetUp() != 0) return -1;
if (TestRtpRtcpBeforeStreaming() != 0) return -1;
if (TestHardwareBeforeStreaming() != 0) return -1;
if (TestCodecsBeforeStreaming() != 0) return -1;
if (TestNetworkBeforeStreaming() != 0) return -1;

View File

@ -334,10 +334,7 @@ class VoETestManager {
#endif
private:
int TestTraceApi();
int TestHardwareBeforeInitializing();
int SetUp();
int TestRtpRtcpBeforeStreaming();
int TestHardwareBeforeStreaming();
int TestCodecsBeforeStreaming();
int TestNetworkBeforeStreaming();

View File

@ -17,6 +17,7 @@
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
'<(webrtc_root)/../test/test.gyp:test_support',
'<(webrtc_root)/../testing/gtest.gyp:gtest',
'<(webrtc_root)/../testing/gmock.gyp:gmock',
],
'include_dirs': [
'auto_test',
@ -25,6 +26,8 @@
],
'sources': [
'auto_test/automated_mode.cc',
'auto_test/standard/hardware_before_initializing_test.cc',
'auto_test/standard/rtp_rtcp_before_streaming_test.cc',
'auto_test/voe_cpu_test.cc',
'auto_test/voe_cpu_test.h',
'auto_test/voe_extended_test.cc',