Remove voe_auto_test and add new tests to cover the missing cases.

BUG=webrtc:4690

Review-Url: https://codereview.webrtc.org/3007383002
Cr-Commit-Position: refs/heads/master@{#19865}
This commit is contained in:
solenberg 2017-09-15 09:56:08 -07:00 committed by Commit Bot
parent 8b891cecf7
commit 18f5427e4c
26 changed files with 241 additions and 1573 deletions

View File

@ -338,9 +338,6 @@ if (!build_with_chromium) {
} else {
deps += [ "modules/video_capture:video_capture_tests" ]
}
if (!is_ios) {
deps += [ "voice_engine:voe_auto_test" ]
}
if (rtc_enable_protobuf) {
deps += [
"audio:low_bandwidth_audio_test",

View File

@ -95,6 +95,7 @@ if (rtc_include_tests) {
sources = [
"audio_receive_stream_unittest.cc",
"audio_send_stream_tests.cc",
"audio_send_stream_unittest.cc",
"audio_state_unittest.cc",
"time_interval_unittest.cc",

View File

@ -0,0 +1,238 @@
/*
* Copyright (c) 2017 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/call_test.h"
#include "test/gtest.h"
#include "test/rtcp_packet_parser.h"
namespace webrtc {
namespace test {
namespace {
class AudioSendTest : public SendTest {
public:
AudioSendTest() : SendTest(CallTest::kDefaultTimeoutMs) {}
size_t GetNumVideoStreams() const override {
return 0;
}
size_t GetNumAudioStreams() const override {
return 1;
}
size_t GetNumFlexfecStreams() const override {
return 0;
}
};
} // namespace
using AudioSendStreamCallTest = CallTest;
TEST_F(AudioSendStreamCallTest, SupportsCName) {
static std::string kCName = "PjqatC14dGfbVwGPUOA9IH7RlsFDbWl4AhXEiDsBizo=";
class CNameObserver : public AudioSendTest {
public:
CNameObserver() = default;
private:
Action OnSendRtcp(const uint8_t* packet, size_t length) override {
RtcpPacketParser parser;
EXPECT_TRUE(parser.Parse(packet, length));
if (parser.sdes()->num_packets() > 0) {
EXPECT_EQ(1u, parser.sdes()->chunks().size());
EXPECT_EQ(kCName, parser.sdes()->chunks()[0].cname);
observation_complete_.Set();
}
return SEND_PACKET;
}
void ModifyAudioConfigs(
AudioSendStream::Config* send_config,
std::vector<AudioReceiveStream::Config>* receive_configs) override {
send_config->rtp.c_name = kCName;
}
void PerformTest() override {
EXPECT_TRUE(Wait()) << "Timed out while waiting for RTCP with CNAME.";
}
} test;
RunBaseTest(&test);
}
TEST_F(AudioSendStreamCallTest, NoExtensionsByDefault) {
class NoExtensionsObserver : public AudioSendTest {
public:
NoExtensionsObserver() = default;
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
RTPHeader header;
EXPECT_TRUE(parser_->Parse(packet, length, &header));
EXPECT_FALSE(header.extension.hasTransmissionTimeOffset);
EXPECT_FALSE(header.extension.hasAbsoluteSendTime);
EXPECT_FALSE(header.extension.hasTransportSequenceNumber);
EXPECT_FALSE(header.extension.hasAudioLevel);
EXPECT_FALSE(header.extension.hasVideoRotation);
EXPECT_FALSE(header.extension.hasVideoContentType);
observation_complete_.Set();
return SEND_PACKET;
}
void ModifyAudioConfigs(
AudioSendStream::Config* send_config,
std::vector<AudioReceiveStream::Config>* receive_configs) override {
send_config->rtp.extensions.clear();
}
void PerformTest() override {
EXPECT_TRUE(Wait()) << "Timed out while waiting for a single RTP packet.";
}
} test;
RunBaseTest(&test);
}
TEST_F(AudioSendStreamCallTest, SupportsAudioLevel) {
class AudioLevelObserver : public AudioSendTest {
public:
AudioLevelObserver() : AudioSendTest() {
EXPECT_TRUE(parser_->RegisterRtpHeaderExtension(
kRtpExtensionAudioLevel, test::kAudioLevelExtensionId));
}
Action OnSendRtp(const uint8_t* packet, size_t length) override {
RTPHeader header;
EXPECT_TRUE(parser_->Parse(packet, length, &header));
EXPECT_TRUE(header.extension.hasAudioLevel);
if (header.extension.audioLevel != 0) {
// Wait for at least one packet with a non-zero level.
observation_complete_.Set();
} else {
LOG(LS_WARNING) << "Got a packet with zero audioLevel - waiting"
" for another packet...";
}
return SEND_PACKET;
}
void ModifyAudioConfigs(
AudioSendStream::Config* send_config,
std::vector<AudioReceiveStream::Config>* receive_configs) override {
send_config->rtp.extensions.clear();
send_config->rtp.extensions.push_back(RtpExtension(
RtpExtension::kAudioLevelUri, test::kAudioLevelExtensionId));
}
void PerformTest() override {
EXPECT_TRUE(Wait()) << "Timed out while waiting for single RTP packet.";
}
} test;
RunBaseTest(&test);
}
TEST_F(AudioSendStreamCallTest, SupportsTransportWideSequenceNumbers) {
static const uint8_t kExtensionId = test::kTransportSequenceNumberExtensionId;
class TransportWideSequenceNumberObserver : public AudioSendTest {
public:
TransportWideSequenceNumberObserver() : AudioSendTest() {
EXPECT_TRUE(parser_->RegisterRtpHeaderExtension(
kRtpExtensionTransportSequenceNumber, kExtensionId));
}
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
RTPHeader header;
EXPECT_TRUE(parser_->Parse(packet, length, &header));
EXPECT_TRUE(header.extension.hasTransportSequenceNumber);
EXPECT_FALSE(header.extension.hasTransmissionTimeOffset);
EXPECT_FALSE(header.extension.hasAbsoluteSendTime);
observation_complete_.Set();
return SEND_PACKET;
}
void ModifyAudioConfigs(
AudioSendStream::Config* send_config,
std::vector<AudioReceiveStream::Config>* receive_configs) override {
send_config->rtp.extensions.clear();
send_config->rtp.extensions.push_back(RtpExtension(
RtpExtension::kTransportSequenceNumberUri, kExtensionId));
}
void PerformTest() override {
EXPECT_TRUE(Wait()) << "Timed out while waiting for a single RTP packet.";
}
} test;
RunBaseTest(&test);
}
TEST_F(AudioSendStreamCallTest, SendDtmf) {
static const uint8_t kDtmfPayloadType = 120;
static const int kDtmfPayloadFrequency = 8000;
static const int kDtmfEventFirst = 12;
static const int kDtmfEventLast = 31;
static const int kDtmfDuration = 50;
class DtmfObserver : public AudioSendTest {
public:
DtmfObserver() = default;
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
RTPHeader header;
EXPECT_TRUE(parser_->Parse(packet, length, &header));
if (header.payloadType == kDtmfPayloadType) {
EXPECT_EQ(12u, header.headerLength);
EXPECT_EQ(16u, length);
const int event = packet[12];
if (event != expected_dtmf_event_) {
++expected_dtmf_event_;
EXPECT_EQ(event, expected_dtmf_event_);
if (expected_dtmf_event_ == kDtmfEventLast) {
observation_complete_.Set();
}
}
}
return SEND_PACKET;
}
void OnAudioStreamsCreated(
AudioSendStream* send_stream,
const std::vector<AudioReceiveStream*>& receive_streams) override {
// Need to start stream here, else DTMF events are dropped.
send_stream->Start();
for (int event = kDtmfEventFirst; event <= kDtmfEventLast; ++event) {
send_stream->SendTelephoneEvent(kDtmfPayloadType, kDtmfPayloadFrequency,
event, kDtmfDuration);
}
}
void PerformTest() override {
EXPECT_TRUE(Wait()) << "Timed out while waiting for DTMF stream.";
}
int expected_dtmf_event_ = kDtmfEventFirst;
} test;
RunBaseTest(&test);
}
} // namespace test
} // namespace webrtc

View File

@ -13,6 +13,7 @@
namespace webrtc {
namespace test {
const int kAudioLevelExtensionId = 5;
const int kTOffsetExtensionId = 6;
const int kAbsSendTimeExtensionId = 7;
const int kTransportSequenceNumberExtensionId = 8;

View File

@ -11,6 +11,7 @@
namespace webrtc {
namespace test {
extern const int kAudioLevelExtensionId;
extern const int kTOffsetExtensionId;
extern const int kAbsSendTimeExtensionId;
extern const int kTransportSequenceNumberExtensionId;

View File

@ -240,71 +240,4 @@ if (rtc_include_tests) {
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}
}
if (!is_ios) {
rtc_executable("voe_auto_test") {
testonly = true
deps = [
":voice_engine",
"..:webrtc_common",
"../logging:rtc_event_log_api",
"../modules:module_api",
"../modules/audio_device:audio_device",
"../modules/audio_processing:audio_processing",
"../modules/rtp_rtcp:rtp_rtcp",
"../modules/video_capture",
"../rtc_base:rtc_base_approved",
"../system_wrappers",
"../system_wrappers/:system_wrappers_default",
"../test/:test_common",
"../test/:test_support",
"../test/:video_test_common",
"//testing/gmock",
"//testing/gtest",
]
sources = [
"test/auto_test/automated_mode.cc",
"test/auto_test/fixtures/after_initialization_fixture.cc",
"test/auto_test/fixtures/after_initialization_fixture.h",
"test/auto_test/fixtures/after_streaming_fixture.cc",
"test/auto_test/fixtures/after_streaming_fixture.h",
"test/auto_test/fixtures/before_initialization_fixture.cc",
"test/auto_test/fixtures/before_initialization_fixture.h",
"test/auto_test/fixtures/before_streaming_fixture.cc",
"test/auto_test/fixtures/before_streaming_fixture.h",
"test/auto_test/standard/codec_before_streaming_test.cc",
"test/auto_test/standard/codec_test.cc",
"test/auto_test/standard/dtmf_test.cc",
"test/auto_test/standard/rtp_rtcp_before_streaming_test.cc",
"test/auto_test/standard/rtp_rtcp_extensions.cc",
"test/auto_test/standard/rtp_rtcp_test.cc",
"test/auto_test/voe_standard_test.cc",
"test/auto_test/voe_standard_test.h",
"test/auto_test/voe_test_defines.h",
]
defines = []
if (rtc_enable_protobuf) {
defines = [ "ENABLE_RTC_EVENT_LOG" ]
}
if (is_win) {
defines += [ "WEBRTC_DRIFT_COMPENSATION_SUPPORTED" ]
cflags = [
"/wd4267", # size_t to int truncation.
"/wd4373", # Virtual function override.
# TODO(kjellander): Bug 261: fix this warning.
]
}
if (!build_with_chromium && is_clang) {
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}
}
}
}

View File

@ -1,28 +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 "test/gtest.h"
#include "test/testsupport/fileutils.h"
namespace webrtc {
namespace voetest {
void InitializeGoogleTest(int* argc, char** argv) {
// Initialize WebRTC testing framework so paths to resources can be resolved.
webrtc::test::SetExecutablePath(argv[0]);
testing::InitGoogleTest(argc, argv);
}
int RunInAutomatedMode() {
return RUN_ALL_TESTS();
}
} // namespace voetest
} // namespace webrtc

View File

@ -1,23 +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.
*/
#ifndef SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_AUTOMATED_MODE_H_
#define SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_AUTOMATED_MODE_H_
namespace webrtc {
namespace voetest {
void InitializeGoogleTest(int* argc, char** argv);
int RunInAutomatedMode();
} // namespace voetest
} // namespace webrtc
#endif // SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_AUTOMATED_MODE_H_

View File

@ -1,36 +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 "modules/audio_processing/include/audio_processing.h"
#include "voice_engine/test/auto_test/fixtures/after_initialization_fixture.h"
class TestErrorObserver : public webrtc::VoiceEngineObserver {
public:
TestErrorObserver() {}
virtual ~TestErrorObserver() {}
void CallbackOnError(int channel, int error_code) {
ADD_FAILURE() << "Unexpected error on channel " << channel <<
": error code " << error_code;
}
};
AfterInitializationFixture::AfterInitializationFixture()
: error_observer_(new TestErrorObserver()) {
webrtc::Config config;
config.Set<webrtc::ExperimentalAgc>(new webrtc::ExperimentalAgc(false));
webrtc::AudioProcessing* audioproc = webrtc::AudioProcessing::Create(config);
EXPECT_EQ(0, voe_base_->Init(NULL, audioproc));
EXPECT_EQ(0, voe_base_->RegisterVoiceEngineObserver(*error_observer_));
}
AfterInitializationFixture::~AfterInitializationFixture() {
EXPECT_EQ(0, voe_base_->DeRegisterVoiceEngineObserver());
}

View File

@ -1,169 +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.
*/
#ifndef SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_AFTER_INIT_H_
#define SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_AFTER_INIT_H_
#include <deque>
#include <memory>
#include "common_types.h" // NOLINT(build/include)
#include "modules/rtp_rtcp/source/byte_io.h"
#include "rtc_base/criticalsection.h"
#include "rtc_base/platform_thread.h"
#include "system_wrappers/include/atomic32.h"
#include "system_wrappers/include/event_wrapper.h"
#include "system_wrappers/include/sleep.h"
#include "voice_engine/test/auto_test/fixtures/before_initialization_fixture.h"
class TestErrorObserver;
class LoopBackTransport : public webrtc::Transport {
public:
LoopBackTransport(webrtc::VoENetwork* voe_network, int channel)
: packet_event_(webrtc::EventWrapper::Create()),
thread_(NetworkProcess, this, "LoopBackTransport"),
channel_(channel),
voe_network_(voe_network),
transmitted_packets_(0) {
thread_.Start();
}
~LoopBackTransport() { thread_.Stop(); }
bool SendRtp(const uint8_t* data,
size_t len,
const webrtc::PacketOptions& options) override {
StorePacket(Packet::Rtp, data, len);
return true;
}
bool SendRtcp(const uint8_t* data, size_t len) override {
StorePacket(Packet::Rtcp, data, len);
return true;
}
void WaitForTransmittedPackets(int32_t packet_count) {
enum {
kSleepIntervalMs = 10
};
int32_t limit = transmitted_packets_.Value() + packet_count;
while (transmitted_packets_.Value() < limit) {
webrtc::SleepMs(kSleepIntervalMs);
}
}
void AddChannel(uint32_t ssrc, int channel) {
rtc::CritScope lock(&crit_);
channels_[ssrc] = channel;
}
private:
struct Packet {
enum Type { Rtp, Rtcp, } type;
Packet() : len(0) {}
Packet(Type type, const void* data, size_t len)
: type(type), len(len) {
assert(len <= 1500);
memcpy(this->data, data, len);
}
uint8_t data[1500];
size_t len;
};
void StorePacket(Packet::Type type,
const void* data,
size_t len) {
{
rtc::CritScope lock(&crit_);
packet_queue_.push_back(Packet(type, data, len));
}
packet_event_->Set();
}
static bool NetworkProcess(void* transport) {
return static_cast<LoopBackTransport*>(transport)->SendPackets();
}
bool SendPackets() {
switch (packet_event_->Wait(10)) {
case webrtc::kEventSignaled:
break;
case webrtc::kEventTimeout:
break;
case webrtc::kEventError:
// TODO(pbos): Log a warning here?
return true;
}
while (true) {
Packet p;
int channel = channel_;
{
rtc::CritScope lock(&crit_);
if (packet_queue_.empty())
break;
p = packet_queue_.front();
packet_queue_.pop_front();
if (p.type == Packet::Rtp) {
uint32_t ssrc =
webrtc::ByteReader<uint32_t>::ReadBigEndian(&p.data[8]);
if (channels_[ssrc] != 0)
channel = channels_[ssrc];
}
// TODO(pbos): Add RTCP SSRC muxing/demuxing if anything requires it.
}
// Minimum RTP header size.
if (p.len < 12)
continue;
switch (p.type) {
case Packet::Rtp:
voe_network_->ReceivedRTPPacket(channel, p.data, p.len,
webrtc::PacketTime());
break;
case Packet::Rtcp:
voe_network_->ReceivedRTCPPacket(channel, p.data, p.len);
break;
}
++transmitted_packets_;
}
return true;
}
rtc::CriticalSection crit_;
const std::unique_ptr<webrtc::EventWrapper> packet_event_;
rtc::PlatformThread thread_;
std::deque<Packet> packet_queue_ RTC_GUARDED_BY(crit_);
const int channel_;
std::map<uint32_t, int> channels_ RTC_GUARDED_BY(crit_);
webrtc::VoENetwork* const voe_network_;
webrtc::Atomic32 transmitted_packets_;
};
// This fixture initializes the voice engine in addition to the work
// done by the before-initialization fixture. It also registers an error
// observer which will fail tests on error callbacks. This fixture is
// useful to tests that want to run before we have started any form of
// streaming through the voice engine.
class AfterInitializationFixture : public BeforeInitializationFixture {
public:
AfterInitializationFixture();
virtual ~AfterInitializationFixture();
protected:
std::unique_ptr<TestErrorObserver> error_observer_;
};
#endif // SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_AFTER_INIT_H_

View File

@ -1,21 +0,0 @@
/*
* Copyright (c) 2012 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 "voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
#include "voice_engine/voice_engine_impl.h"
AfterStreamingFixture::AfterStreamingFixture()
: BeforeStreamingFixture() {
webrtc::VoiceEngineImpl* voe_impl =
static_cast<webrtc::VoiceEngineImpl*>(voice_engine_);
channel_proxy_ = voe_impl->GetChannelProxy(channel_);
channel_proxy_->RegisterLegacyReceiveCodecs();
ResumePlaying();
}

View File

@ -1,30 +0,0 @@
/*
* Copyright (c) 2012 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_AFTER_STREAMING_H_
#define SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_AFTER_STREAMING_H_
#include <memory>
#include "voice_engine/channel_proxy.h"
#include "voice_engine/test/auto_test/fixtures/before_streaming_fixture.h"
// This fixture will, in addition to the work done by its superclasses,
// start play back on construction.
class AfterStreamingFixture : public BeforeStreamingFixture {
public:
AfterStreamingFixture();
virtual ~AfterStreamingFixture() {}
protected:
std::unique_ptr<webrtc::voe::ChannelProxy> channel_proxy_;
};
#endif // SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_AFTER_STREAMING_H_

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2012 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 "voice_engine/test/auto_test/fixtures/before_initialization_fixture.h"
#include "system_wrappers/include/sleep.h"
BeforeInitializationFixture::BeforeInitializationFixture()
: 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_rtp_rtcp_ = webrtc::VoERTP_RTCP::GetInterface(voice_engine_);
voe_network_ = webrtc::VoENetwork::GetInterface(voice_engine_);
voe_file_ = webrtc::VoEFile::GetInterface(voice_engine_);
}
BeforeInitializationFixture::~BeforeInitializationFixture() {
voe_base_->Release();
voe_codec_->Release();
voe_rtp_rtcp_->Release();
voe_network_->Release();
voe_file_->Release();
EXPECT_TRUE(webrtc::VoiceEngine::Delete(voice_engine_));
}
void BeforeInitializationFixture::Sleep(long milliseconds) {
webrtc::SleepMs(milliseconds);
}

View File

@ -1,54 +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.
*/
#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 "common_types.h" // NOLINT(build/include)
#include "test/gmock.h"
#include "test/gtest.h"
#include "typedefs.h" // NOLINT(build/include)
#include "voice_engine/include/voe_base.h"
#include "voice_engine/include/voe_codec.h"
#include "voice_engine/include/voe_errors.h"
#include "voice_engine/include/voe_file.h"
#include "voice_engine/include/voe_network.h"
#include "voice_engine/include/voe_rtp_rtcp.h"
#include "voice_engine/test/auto_test/voe_test_common.h"
// This convenient fixture sets up all voice engine 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.
// It will not call any init methods.
//
// Implementation note:
// 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.
class BeforeInitializationFixture : public testing::Test {
public:
BeforeInitializationFixture();
virtual ~BeforeInitializationFixture();
protected:
// Use this sleep function to sleep in tests.
void Sleep(long milliseconds);
webrtc::VoiceEngine* voice_engine_;
webrtc::VoEBase* voe_base_;
webrtc::VoECodec* voe_codec_;
webrtc::VoERTP_RTCP* voe_rtp_rtcp_;
webrtc::VoENetwork* voe_network_;
webrtc::VoEFile* voe_file_;
};
#endif // SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_H_

View File

@ -1,78 +0,0 @@
/*
* Copyright (c) 2014 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/testsupport/fileutils.h"
#include "voice_engine/test/auto_test/fixtures/before_streaming_fixture.h"
BeforeStreamingFixture::BeforeStreamingFixture()
: channel_(voe_base_->CreateChannel()),
transport_(NULL) {
EXPECT_GE(channel_, 0);
fake_microphone_input_file_ =
webrtc::test::ResourcePath("voice_engine/audio_long16", "pcm");
SetUpLocalPlayback();
RestartFakeMicrophone();
}
BeforeStreamingFixture::~BeforeStreamingFixture() {
voe_file_->StopPlayingFileAsMicrophone(channel_);
PausePlaying();
EXPECT_EQ(0, voe_network_->DeRegisterExternalTransport(channel_));
voe_base_->DeleteChannel(channel_);
delete transport_;
}
void BeforeStreamingFixture::SwitchToManualMicrophone() {
EXPECT_EQ(0, voe_file_->StopPlayingFileAsMicrophone(channel_));
TEST_LOG("You need to speak manually into the microphone for this test.\n");
TEST_LOG("Please start speaking now.\n");
Sleep(1000);
}
void BeforeStreamingFixture::RestartFakeMicrophone() {
EXPECT_EQ(0, voe_file_->StartPlayingFileAsMicrophone(
channel_, fake_microphone_input_file_.c_str(), true, true));
}
void BeforeStreamingFixture::PausePlaying() {
EXPECT_EQ(0, voe_base_->StopSend(channel_));
EXPECT_EQ(0, voe_base_->StopPlayout(channel_));
}
void BeforeStreamingFixture::ResumePlaying() {
EXPECT_EQ(0, voe_base_->StartPlayout(channel_));
EXPECT_EQ(0, voe_base_->StartSend(channel_));
}
void BeforeStreamingFixture::WaitForTransmittedPackets(int32_t packet_count) {
transport_->WaitForTransmittedPackets(packet_count);
}
void BeforeStreamingFixture::SetUpLocalPlayback() {
transport_ = new LoopBackTransport(voe_network_, channel_);
EXPECT_EQ(0, voe_network_->RegisterExternalTransport(channel_, *transport_));
webrtc::CodecInst codec;
codec.channels = 1;
codec.pacsize = 160;
codec.plfreq = 8000;
codec.pltype = 0;
codec.rate = 64000;
#if defined(_MSC_VER) && defined(_WIN32)
_snprintf(codec.plname, RTP_PAYLOAD_NAME_SIZE - 1, "PCMU");
#else
snprintf(codec.plname, RTP_PAYLOAD_NAME_SIZE, "PCMU");
#endif
voe_codec_->SetSendCodec(channel_, codec);
}

View File

@ -1,52 +0,0 @@
/*
* Copyright (c) 2014 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_BEFORE_STREAMING_H_
#define SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_BEFORE_STREAMING_H_
#include <string>
#include "voice_engine/test/auto_test/fixtures/after_initialization_fixture.h"
// This fixture will, in addition to the work done by its superclasses,
// create a channel and prepare playing a file through the fake microphone
// to simulate microphone input. The purpose is to make it convenient
// to write tests that require microphone input.
class BeforeStreamingFixture : public AfterInitializationFixture {
public:
BeforeStreamingFixture();
virtual ~BeforeStreamingFixture();
protected:
int channel_;
std::string fake_microphone_input_file_;
// Shuts off the fake microphone for this test.
void SwitchToManualMicrophone();
// Restarts the fake microphone if it's been shut off earlier.
void RestartFakeMicrophone();
// Stops all sending and playout.
void PausePlaying();
// Resumes all sending and playout.
void ResumePlaying();
// Waits until packet_count packetes have been processed by recipient.
void WaitForTransmittedPackets(int32_t packet_count);
private:
void SetUpLocalPlayback();
LoopBackTransport* transport_;
};
#endif // SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_BEFORE_STREAMING_H_

View File

@ -1,88 +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 "voice_engine/channel_proxy.h"
#include "voice_engine/test/auto_test/fixtures/after_initialization_fixture.h"
#include "voice_engine/voice_engine_impl.h"
class CodecBeforeStreamingTest : public AfterInitializationFixture {
protected:
void SetUp() {
memset(&codec_instance_, 0, sizeof(codec_instance_));
codec_instance_.channels = 1;
codec_instance_.plfreq = 16000;
codec_instance_.pacsize = 480;
channel_ = voe_base_->CreateChannel();
static_cast<webrtc::VoiceEngineImpl*>(voice_engine_)
->GetChannelProxy(channel_)
->RegisterLegacyReceiveCodecs();
}
void TearDown() {
voe_base_->DeleteChannel(channel_);
}
webrtc::CodecInst codec_instance_;
int channel_;
};
// TODO(phoglund): add test which verifies default pltypes for various codecs.
TEST_F(CodecBeforeStreamingTest, GetRecPayloadTypeFailsForInvalidCodecName) {
strcpy(codec_instance_.plname, "SomeInvalidCodecName");
// Should fail since the codec name is invalid.
EXPECT_NE(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
}
TEST_F(CodecBeforeStreamingTest, GetRecPayloadTypeRecognizesISAC) {
strcpy(codec_instance_.plname, "iSAC");
EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
strcpy(codec_instance_.plname, "ISAC");
EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
}
TEST_F(CodecBeforeStreamingTest, SetRecPayloadTypeCanChangeISACPayloadType) {
strcpy(codec_instance_.plname, "ISAC");
codec_instance_.rate = 32000;
codec_instance_.pltype = 123;
EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance_));
EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
EXPECT_EQ(123, codec_instance_.pltype);
codec_instance_.pltype = 104;
EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance_));
EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
EXPECT_EQ(104, codec_instance_.pltype);
}
TEST_F(CodecBeforeStreamingTest, SetRecPayloadTypeCanChangeILBCPayloadType) {
strcpy(codec_instance_.plname, "iLBC");
codec_instance_.plfreq = 8000;
codec_instance_.pacsize = 240;
codec_instance_.rate = 13300;
EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
int original_pltype = codec_instance_.pltype;
codec_instance_.pltype = 123;
EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance_));
EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
EXPECT_EQ(123, codec_instance_.pltype);
codec_instance_.pltype = original_pltype;
EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance_));
EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
EXPECT_EQ(original_pltype, codec_instance_.pltype);
}

View File

@ -1,216 +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 <stdio.h>
#include <string>
#include "test/testsupport/fileutils.h"
#include "voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
#include "voice_engine/voice_engine_defines.h"
class CodecTest : public AfterStreamingFixture {
protected:
void SetUp() {
memset(&codec_instance_, 0, sizeof(codec_instance_));
apm_ = webrtc::AudioProcessing::Create();
voe_base_->Init(nullptr, apm_.get(), nullptr);
}
void SetArbitrarySendCodec() {
// Just grab the first codec.
EXPECT_EQ(0, voe_codec_->GetCodec(0, codec_instance_));
EXPECT_EQ(0, voe_codec_->SetSendCodec(channel_, codec_instance_));
}
rtc::scoped_refptr<webrtc::AudioProcessing> apm_;
webrtc::CodecInst codec_instance_;
};
static void SetRateIfILBC(webrtc::CodecInst* codec_instance, int packet_size) {
if (!STR_CASE_CMP(codec_instance->plname, "ilbc")) {
if (packet_size == 160 || packet_size == 320) {
codec_instance->rate = 15200;
} else {
codec_instance->rate = 13300;
}
}
}
static bool IsNotViableSendCodec(const char* codec_name) {
return !STR_CASE_CMP(codec_name, "CN") ||
!STR_CASE_CMP(codec_name, "telephone-event") ||
!STR_CASE_CMP(codec_name, "red");
}
TEST_F(CodecTest, PcmuIsDefaultCodecAndHasTheRightValues) {
EXPECT_EQ(0, voe_codec_->GetSendCodec(channel_, codec_instance_));
EXPECT_EQ(1u, codec_instance_.channels);
EXPECT_EQ(160, codec_instance_.pacsize);
EXPECT_EQ(8000, codec_instance_.plfreq);
EXPECT_EQ(0, codec_instance_.pltype);
EXPECT_EQ(64000, codec_instance_.rate);
EXPECT_STRCASEEQ("PCMU", codec_instance_.plname);
}
TEST_F(CodecTest, VoiceActivityDetectionIsOffByDefault) {
bool vad_enabled = false;
bool dtx_disabled = false;
webrtc::VadModes vad_mode = webrtc::kVadAggressiveMid;
voe_codec_->GetVADStatus(channel_, vad_enabled, vad_mode, dtx_disabled);
EXPECT_FALSE(vad_enabled);
EXPECT_TRUE(dtx_disabled);
EXPECT_EQ(webrtc::kVadConventional, vad_mode);
}
TEST_F(CodecTest, VoiceActivityDetectionCanBeEnabled) {
EXPECT_EQ(0, voe_codec_->SetVADStatus(channel_, true));
bool vad_enabled = false;
bool dtx_disabled = false;
webrtc::VadModes vad_mode = webrtc::kVadAggressiveMid;
voe_codec_->GetVADStatus(channel_, vad_enabled, vad_mode, dtx_disabled);
EXPECT_TRUE(vad_enabled);
EXPECT_EQ(webrtc::kVadConventional, vad_mode);
EXPECT_FALSE(dtx_disabled);
}
TEST_F(CodecTest, VoiceActivityDetectionTypeSettingsCanBeChanged) {
bool vad_enabled = false;
bool dtx_disabled = false;
webrtc::VadModes vad_mode = webrtc::kVadAggressiveMid;
EXPECT_EQ(0, voe_codec_->SetVADStatus(
channel_, true, webrtc::kVadAggressiveLow, false));
EXPECT_EQ(0, voe_codec_->GetVADStatus(
channel_, vad_enabled, vad_mode, dtx_disabled));
EXPECT_EQ(vad_mode, webrtc::kVadAggressiveLow);
EXPECT_FALSE(dtx_disabled);
EXPECT_EQ(0, voe_codec_->SetVADStatus(
channel_, true, webrtc::kVadAggressiveMid, false));
EXPECT_EQ(0, voe_codec_->GetVADStatus(
channel_, vad_enabled, vad_mode, dtx_disabled));
EXPECT_EQ(vad_mode, webrtc::kVadAggressiveMid);
EXPECT_FALSE(dtx_disabled);
// The fourth argument is the DTX disable flag, which is always supposed to
// be false.
EXPECT_EQ(0, voe_codec_->SetVADStatus(channel_, true,
webrtc::kVadAggressiveHigh, false));
EXPECT_EQ(0, voe_codec_->GetVADStatus(
channel_, vad_enabled, vad_mode, dtx_disabled));
EXPECT_EQ(vad_mode, webrtc::kVadAggressiveHigh);
EXPECT_FALSE(dtx_disabled);
EXPECT_EQ(0, voe_codec_->SetVADStatus(channel_, true,
webrtc::kVadConventional, false));
EXPECT_EQ(0, voe_codec_->GetVADStatus(
channel_, vad_enabled, vad_mode, dtx_disabled));
EXPECT_EQ(vad_mode, webrtc::kVadConventional);
}
TEST_F(CodecTest, VoiceActivityDetectionCanBeTurnedOff) {
EXPECT_EQ(0, voe_codec_->SetVADStatus(channel_, true));
// VAD is always on when DTX is on, so we need to turn off DTX too.
EXPECT_EQ(0, voe_codec_->SetVADStatus(
channel_, false, webrtc::kVadConventional, true));
bool vad_enabled = false;
bool dtx_disabled = false;
webrtc::VadModes vad_mode = webrtc::kVadAggressiveMid;
voe_codec_->GetVADStatus(channel_, vad_enabled, vad_mode, dtx_disabled);
EXPECT_FALSE(vad_enabled);
EXPECT_TRUE(dtx_disabled);
EXPECT_EQ(webrtc::kVadConventional, vad_mode);
}
TEST_F(CodecTest, OpusMaxPlaybackRateCanBeSet) {
for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) {
voe_codec_->GetCodec(i, codec_instance_);
if (STR_CASE_CMP("opus", codec_instance_.plname)) {
continue;
}
voe_codec_->SetSendCodec(channel_, codec_instance_);
// SetOpusMaxPlaybackRate can handle any integer as the bandwidth. Following
// tests some most commonly used numbers.
EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 48000));
EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 32000));
EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 16000));
EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 8000));
}
}
TEST_F(CodecTest, OpusDtxCanBeSetForOpus) {
for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) {
voe_codec_->GetCodec(i, codec_instance_);
if (STR_CASE_CMP("opus", codec_instance_.plname)) {
continue;
}
voe_codec_->SetSendCodec(channel_, codec_instance_);
EXPECT_EQ(0, voe_codec_->SetOpusDtx(channel_, false));
EXPECT_EQ(0, voe_codec_->SetOpusDtx(channel_, true));
}
}
TEST_F(CodecTest, OpusDtxCannotBeSetForNonOpus) {
for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) {
voe_codec_->GetCodec(i, codec_instance_);
if (!STR_CASE_CMP("opus", codec_instance_.plname)) {
continue;
}
voe_codec_->SetSendCodec(channel_, codec_instance_);
EXPECT_EQ(-1, voe_codec_->SetOpusDtx(channel_, true));
}
}
// TODO(xians, phoglund): Re-enable when issue 372 is resolved.
TEST_F(CodecTest, DISABLED_ManualVerifySendCodecsForAllPacketSizes) {
for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) {
voe_codec_->GetCodec(i, codec_instance_);
if (IsNotViableSendCodec(codec_instance_.plname)) {
TEST_LOG("Skipping %s.\n", codec_instance_.plname);
continue;
}
EXPECT_NE(-1, codec_instance_.pltype) <<
"The codec database should suggest a payload type.";
// Test with default packet size:
TEST_LOG("%s (pt=%d): default packet size(%d), accepts sizes ",
codec_instance_.plname, codec_instance_.pltype,
codec_instance_.pacsize);
voe_codec_->SetSendCodec(channel_, codec_instance_);
Sleep(CODEC_TEST_TIME);
// Now test other reasonable packet sizes:
bool at_least_one_succeeded = false;
for (int packet_size = 80; packet_size < 1000; packet_size += 80) {
SetRateIfILBC(&codec_instance_, packet_size);
codec_instance_.pacsize = packet_size;
if (voe_codec_->SetSendCodec(channel_, codec_instance_) != -1) {
// Note that it's fine for SetSendCodec to fail - what packet sizes
// it accepts depends on the codec. It should accept one at minimum.
TEST_LOG("%d ", packet_size);
TEST_LOG_FLUSH;
at_least_one_succeeded = true;
Sleep(CODEC_TEST_TIME);
}
}
TEST_LOG("\n");
EXPECT_TRUE(at_least_one_succeeded);
}
}

View File

@ -1,66 +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 "voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
#include "voice_engine/voice_engine_defines.h"
class DtmfTest : public AfterStreamingFixture {
protected:
void RunSixteenDtmfEvents() {
TEST_LOG("Sending telephone events:\n");
for (int i = 0; i < 16; i++) {
TEST_LOG("%d ", i);
TEST_LOG_FLUSH;
EXPECT_TRUE(channel_proxy_->SendTelephoneEventOutband(i, 160));
Sleep(500);
}
TEST_LOG("\n");
}
};
TEST_F(DtmfTest, ManualSuccessfullySendsOutOfBandTelephoneEvents) {
RunSixteenDtmfEvents();
}
TEST_F(DtmfTest, TestTwoNonDtmfEvents) {
EXPECT_TRUE(channel_proxy_->SendTelephoneEventOutband(32, 160));
EXPECT_TRUE(channel_proxy_->SendTelephoneEventOutband(110, 160));
}
// This test modifies the DTMF payload type from the default 106 to 88
// and then runs through 16 DTMF out.of-band events.
TEST_F(DtmfTest, ManualCanChangeDtmfPayloadType) {
webrtc::CodecInst codec_instance = webrtc::CodecInst();
TEST_LOG("Changing DTMF payload type.\n");
// Start by modifying the receiving side.
for (int i = 0; i < voe_codec_->NumOfCodecs(); i++) {
EXPECT_EQ(0, voe_codec_->GetCodec(i, codec_instance));
if (!STR_CASE_CMP("telephone-event", codec_instance.plname)) {
codec_instance.pltype = 88; // Use 88 instead of default 106.
EXPECT_EQ(0, voe_base_->StopSend(channel_));
EXPECT_EQ(0, voe_base_->StopPlayout(channel_));
EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance));
EXPECT_EQ(0, voe_base_->StartPlayout(channel_));
EXPECT_EQ(0, voe_base_->StartSend(channel_));
break;
}
}
Sleep(500);
// Next, we must modify the sending side as well.
EXPECT_TRUE(
channel_proxy_->SetSendTelephoneEventPayloadType(codec_instance.pltype,
codec_instance.plfreq));
RunSixteenDtmfEvents();
}

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 2012 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 "voice_engine/test/auto_test/fixtures/after_initialization_fixture.h"
using namespace webrtc;
using namespace testing;
class RtpRtcpBeforeStreamingTest : public AfterInitializationFixture {
protected:
void SetUp();
void TearDown();
int channel_;
};
void RtpRtcpBeforeStreamingTest::SetUp() {
EXPECT_THAT(channel_ = voe_base_->CreateChannel(), Not(Lt(0)));
}
void RtpRtcpBeforeStreamingTest::TearDown() {
EXPECT_EQ(0, voe_base_->DeleteChannel(channel_));
}
TEST_F(RtpRtcpBeforeStreamingTest,
GetRtcpStatusReturnsTrueByDefaultAndObeysSetRtcpStatus) {
bool on = false;
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, 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

@ -1,120 +0,0 @@
/*
* Copyright (c) 2014 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 <memory>
#include "modules/include/module_common_types.h"
#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "system_wrappers/include/atomic32.h"
#include "system_wrappers/include/sleep.h"
#include "voice_engine/test/auto_test/fixtures/before_streaming_fixture.h"
using ::testing::_;
using ::testing::AtLeast;
using ::testing::Eq;
using ::testing::Field;
class ExtensionVerifyTransport : public webrtc::Transport {
public:
ExtensionVerifyTransport()
: parser_(webrtc::RtpHeaderParser::Create()),
received_packets_(0),
bad_packets_(0),
audio_level_id_(-1),
absolute_sender_time_id_(-1) {}
bool SendRtp(const uint8_t* data,
size_t len,
const webrtc::PacketOptions& options) override {
webrtc::RTPHeader header;
if (parser_->Parse(reinterpret_cast<const uint8_t*>(data), len, &header)) {
bool ok = true;
if (audio_level_id_ >= 0 &&
!header.extension.hasAudioLevel) {
ok = false;
}
if (absolute_sender_time_id_ >= 0 &&
!header.extension.hasAbsoluteSendTime) {
ok = false;
}
if (!ok) {
// bad_packets_ count packets we expected to have an extension but
// didn't have one.
++bad_packets_;
}
}
// received_packets_ count all packets we receive.
++received_packets_;
return true;
}
bool SendRtcp(const uint8_t* data, size_t len) override {
return true;
}
void SetAudioLevelId(int id) {
audio_level_id_ = id;
parser_->RegisterRtpHeaderExtension(webrtc::kRtpExtensionAudioLevel, id);
}
void SetAbsoluteSenderTimeId(int id) {
absolute_sender_time_id_ = id;
parser_->RegisterRtpHeaderExtension(webrtc::kRtpExtensionAbsoluteSendTime,
id);
}
bool Wait() {
// Wait until we've received to specified number of packets.
while (received_packets_.Value() < kPacketsExpected) {
webrtc::SleepMs(kSleepIntervalMs);
}
// Check whether any were 'bad' (didn't contain an extension when they
// where supposed to).
return bad_packets_.Value() == 0;
}
private:
enum {
kPacketsExpected = 10,
kSleepIntervalMs = 10
};
std::unique_ptr<webrtc::RtpHeaderParser> parser_;
webrtc::Atomic32 received_packets_;
webrtc::Atomic32 bad_packets_;
int audio_level_id_;
int absolute_sender_time_id_;
};
class SendRtpRtcpHeaderExtensionsTest : public BeforeStreamingFixture {
protected:
void SetUp() override {
EXPECT_EQ(0, voe_network_->DeRegisterExternalTransport(channel_));
EXPECT_EQ(0, voe_network_->RegisterExternalTransport(channel_,
verifying_transport_));
}
void TearDown() override { PausePlaying(); }
ExtensionVerifyTransport verifying_transport_;
};
TEST_F(SendRtpRtcpHeaderExtensionsTest, SentPacketsIncludeNoAudioLevel) {
verifying_transport_.SetAudioLevelId(0);
ResumePlaying();
EXPECT_FALSE(verifying_transport_.Wait());
}
TEST_F(SendRtpRtcpHeaderExtensionsTest, SentPacketsIncludeAudioLevel) {
EXPECT_EQ(0, voe_rtp_rtcp_->SetSendAudioLevelIndicationStatus(channel_, true,
9));
verifying_transport_.SetAudioLevelId(9);
ResumePlaying();
EXPECT_TRUE(verifying_transport_.Wait());
}

View File

@ -1,120 +0,0 @@
/*
* Copyright (c) 2012 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 <memory>
#include "rtc_base/criticalsection.h"
#include "rtc_base/flags.h"
#include "system_wrappers/include/event_wrapper.h"
#include "test/testsupport/fileutils.h"
#include "voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
#include "voice_engine/test/auto_test/voe_standard_test.h"
DECLARE_bool(include_timing_dependent_tests);
class TestRtpObserver : public webrtc::VoERTPObserver {
public:
TestRtpObserver() : changed_ssrc_event_(webrtc::EventWrapper::Create()) {}
virtual ~TestRtpObserver() {}
virtual void OnIncomingCSRCChanged(int channel,
unsigned int CSRC,
bool added) {}
virtual void OnIncomingSSRCChanged(int channel,
unsigned int SSRC);
void WaitForChangedSsrc() {
// 10 seconds should be enough.
EXPECT_EQ(webrtc::kEventSignaled, changed_ssrc_event_->Wait(10*1000));
}
void SetIncomingSsrc(unsigned int ssrc) {
rtc::CritScope lock(&crit_);
incoming_ssrc_ = ssrc;
}
public:
rtc::CriticalSection crit_;
unsigned int incoming_ssrc_;
std::unique_ptr<webrtc::EventWrapper> changed_ssrc_event_;
};
void TestRtpObserver::OnIncomingSSRCChanged(int channel,
unsigned int SSRC) {
char msg[128];
sprintf(msg, "\n=> OnIncomingSSRCChanged(channel=%d, SSRC=%u)\n", channel,
SSRC);
TEST_LOG("%s", msg);
{
rtc::CritScope lock(&crit_);
if (incoming_ssrc_ == SSRC)
changed_ssrc_event_->Set();
}
}
static const char* const RTCP_CNAME = "Whatever";
class RtpRtcpTest : public AfterStreamingFixture {
protected:
void SetUp() {
// We need a second channel for this test, so set it up.
second_channel_ = voe_base_->CreateChannel();
EXPECT_GE(second_channel_, 0);
transport_ = new LoopBackTransport(voe_network_, second_channel_);
EXPECT_EQ(0, voe_network_->RegisterExternalTransport(second_channel_,
*transport_));
EXPECT_EQ(0, voe_base_->StartPlayout(second_channel_));
EXPECT_EQ(0, voe_rtp_rtcp_->SetLocalSSRC(second_channel_, 5678));
EXPECT_EQ(0, voe_base_->StartSend(second_channel_));
// We'll set up the RTCP CNAME and SSRC to something arbitrary here.
voe_rtp_rtcp_->SetRTCP_CNAME(channel_, RTCP_CNAME);
}
void TearDown() {
EXPECT_EQ(0, voe_network_->DeRegisterExternalTransport(second_channel_));
voe_base_->DeleteChannel(second_channel_);
delete transport_;
}
int second_channel_;
LoopBackTransport* transport_;
};
TEST_F(RtpRtcpTest, RemoteRtcpCnameHasPropagatedToRemoteSide) {
if (!FLAG_include_timing_dependent_tests) {
TEST_LOG("Skipping test - running in slow execution environment...\n");
return;
}
// We need to sleep a bit here for the name to propagate. For
// instance, 200 milliseconds is not enough, 1 second still flaky,
// so we'll go with five seconds here.
Sleep(5000);
char char_buffer[256];
voe_rtp_rtcp_->GetRemoteRTCP_CNAME(channel_, char_buffer);
EXPECT_STREQ(RTCP_CNAME, char_buffer);
}
TEST_F(RtpRtcpTest, SSRCPropagatesCorrectly) {
unsigned int local_ssrc = 1234;
EXPECT_EQ(0, voe_base_->StopSend(channel_));
EXPECT_EQ(0, voe_rtp_rtcp_->SetLocalSSRC(channel_, local_ssrc));
EXPECT_EQ(0, voe_base_->StartSend(channel_));
Sleep(1000);
unsigned int ssrc;
EXPECT_EQ(0, voe_rtp_rtcp_->GetLocalSSRC(channel_, ssrc));
EXPECT_EQ(local_ssrc, ssrc);
EXPECT_EQ(0, voe_rtp_rtcp_->GetRemoteSSRC(channel_, ssrc));
EXPECT_EQ(local_ssrc, ssrc);
}

View File

@ -1,120 +0,0 @@
/*
* Copyright (c) 2012 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 "voice_engine/test/auto_test/voe_standard_test.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "rtc_base/flags.h"
#include "system_wrappers/include/event_wrapper.h"
#include "typedefs.h" // NOLINT(build/include)
#include "voice_engine/test/auto_test/automated_mode.h"
#include "voice_engine/test/auto_test/voe_test_defines.h"
#include "voice_engine/voice_engine_defines.h"
DEFINE_bool(include_timing_dependent_tests, true,
"If true, we will include tests / parts of tests that are known "
"to break in slow execution environments (such as valgrind).");
DEFINE_bool(automated, false,
"If true, we'll run the automated tests we have in noninteractive "
"mode.");
DEFINE_bool(help, false, "Print this message.");
namespace webrtc {
namespace voetest {
int dummy = 0; // Dummy used in different functions to avoid warnings
void SubAPIManager::DisplayStatus() const {
TEST_LOG("Supported sub APIs:\n\n");
if (_base)
TEST_LOG(" Base\n");
if (_codec)
TEST_LOG(" Codec\n");
if (_file)
TEST_LOG(" File\n");
if (_hardware)
TEST_LOG(" Hardware\n");
if (_network)
TEST_LOG(" Network\n");
if (_rtp_rtcp)
TEST_LOG(" RTP_RTCP\n");
if (_apm)
TEST_LOG(" AudioProcessing\n");
ANL();
TEST_LOG("Excluded sub APIs:\n\n");
if (!_base)
TEST_LOG(" Base\n");
if (!_codec)
TEST_LOG(" Codec\n");
if (!_file)
TEST_LOG(" File\n");
if (!_hardware)
TEST_LOG(" Hardware\n");
if (!_network)
TEST_LOG(" Network\n");
if (!_rtp_rtcp)
TEST_LOG(" RTP_RTCP\n");
if (!_apm)
TEST_LOG(" AudioProcessing\n");
ANL();
}
int RunInManualMode() {
SubAPIManager api_manager;
api_manager.DisplayStatus();
printf("----------------------------\n");
printf("Select type of test\n\n");
printf(" (0) Quit\n");
printf(" (1) Standard test\n");
printf("\n: ");
int selection(0);
dummy = scanf("%d", &selection);
switch (selection) {
case 0:
return 0;
case 1:
TEST_LOG("\n\n+++ Running standard tests +++\n\n");
// Currently, all googletest-rewritten tests are in the "automated" suite.
return RunInAutomatedMode();
default:
TEST_LOG("Invalid selection!\n");
return 0;
}
}
} // namespace voetest
} // namespace webrtc
#if !defined(WEBRTC_IOS)
int main(int argc, char** argv) {
// This function and RunInAutomatedMode is defined in automated_mode.cc
// to avoid macro clashes with googletest (for instance ASSERT_TRUE).
webrtc::voetest::InitializeGoogleTest(&argc, argv);
if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) {
return 1;
}
if (FLAG_help) {
rtc::FlagList::Print(nullptr, false);
return 0;
}
if (FLAG_automated) {
return webrtc::voetest::RunInAutomatedMode();
}
return webrtc::voetest::RunInManualMode();
}
#endif //#if !defined(WEBRTC_IOS)

View File

@ -1,52 +0,0 @@
/*
* Copyright (c) 2012 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 VOICE_ENGINE_VOE_STANDARD_TEST_H_
#define VOICE_ENGINE_VOE_STANDARD_TEST_H_
#include <stdio.h>
#include <string>
#include "test/testsupport/fileutils.h"
#include "voice_engine/test/auto_test/voe_test_common.h"
namespace webrtc {
namespace voetest {
class SubAPIManager {
public:
SubAPIManager()
: _base(true),
_codec(false),
_file(false),
_hardware(false),
_network(false),
_rtp_rtcp(false),
_apm(false) {
_codec = true;
_file = true;
_hardware = true;
_network = true;
_rtp_rtcp = true;
_apm = true;
}
void DisplayStatus() const;
private:
bool _base, _codec;
bool _file, _hardware;
bool _network, _rtp_rtcp, _apm;
};
} // namespace voetest
} // namespace webrtc
#endif // VOICE_ENGINE_VOE_STANDARD_TEST_H_

View File

@ -1,31 +0,0 @@
/*
* Copyright (c) 2012 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 VOICE_ENGINE_VOE_TEST_COMMON_H_
#define VOICE_ENGINE_VOE_TEST_COMMON_H_
#ifdef WEBRTC_ANDROID
#include <android/log.h>
#define ANDROID_LOG_TAG "VoiceEngine Auto Test"
#define TEST_LOG(...) \
__android_log_print(ANDROID_LOG_DEBUG, ANDROID_LOG_TAG, __VA_ARGS__)
#define TEST_LOG_ERROR(...) \
__android_log_print(ANDROID_LOG_ERROR, ANDROID_LOG_TAG, __VA_ARGS__)
#define TEST_LOG_FLUSH
#else
#define TEST_LOG printf
#define TEST_LOG_ERROR printf
#define TEST_LOG_FLUSH fflush(NULL)
#endif
// Time in ms to test each packet size for each codec
#define CODEC_TEST_TIME 400
#endif // VOICE_ENGINE_VOE_TEST_COMMON_H_

View File

@ -1,111 +0,0 @@
/*
* Copyright (c) 2012 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 VOICE_ENGINE_VOE_TEST_DEFINES_H_
#define VOICE_ENGINE_VOE_TEST_DEFINES_H_
#include "voice_engine/test/auto_test/voe_test_common.h"
// Select the tests to execute, list order below is same as they will be
// executed. Note that, all settings below will be overriden by sub-API
// settings in voice_engine_configurations.h.
#define _TEST_BASE_
#define _TEST_RTP_RTCP_
#define _TEST_CODEC_
#define _TEST_FILE_
#define _TEST_NETWORK_
// Enable this when running instrumentation of some kind to exclude tests
// that will not pass due to slowed down execution.
// #define _INSTRUMENTATION_TESTING_
// Some parts can cause problems while running Insure
#ifdef __INSURE__
#define _INSTRUMENTATION_TESTING_
#endif
#define MARK() TEST_LOG("."); fflush(NULL); // Add test marker
#define ANL() TEST_LOG("\n") // Add New Line
#define AOK() TEST_LOG("[Test is OK]"); fflush(NULL); // Add OK
#if defined(_WIN32)
#define PAUSE \
{ \
TEST_LOG("Press any key to continue..."); \
_getch(); \
TEST_LOG("\n"); \
}
#else
#define PAUSE \
{ \
TEST_LOG("Continuing (pause not supported)\n"); \
}
#endif
#define TEST(s) \
{ \
TEST_LOG("Testing: %s", #s); \
} \
#ifdef _INSTRUMENTATION_TESTING_
// Don't stop execution if error occurs
#define TEST_MUSTPASS(expr) \
{ \
if ((expr)) \
{ \
TEST_LOG_ERROR("Error at line:%i, %s \n",__LINE__, #expr); \
TEST_LOG_ERROR("Error code: %i\n",voe_base_->LastError()); \
} \
}
#define TEST_ERROR(code) \
{ \
int err = voe_base_->LastError(); \
if (err != code) \
{ \
TEST_LOG_ERROR("Invalid error code (%d, should be %d) at line %d\n",
code, err, __LINE__);
}
}
#else
#define ASSERT_TRUE(expr) TEST_MUSTPASS(!(expr))
#define ASSERT_FALSE(expr) TEST_MUSTPASS(expr)
#define TEST_MUSTFAIL(expr) TEST_MUSTPASS(!((expr) == -1))
#define TEST_MUSTPASS(expr) \
{ \
if ((expr)) \
{ \
TEST_LOG_ERROR("\nError at line:%i, %s \n",__LINE__, #expr); \
TEST_LOG_ERROR("Error code: %i\n", voe_base_->LastError()); \
PAUSE \
return -1; \
} \
}
#define TEST_ERROR(code) \
{ \
int err = voe_base_->LastError(); \
if (err != code) \
{ \
TEST_LOG_ERROR("Invalid error code (%d, should be %d) at line %d\n", \
err, code, __LINE__); \
PAUSE \
return -1; \
} \
}
#endif // #ifdef _INSTRUMENTATION_TESTING_
#define EXCLUDE() \
{ \
TEST_LOG("\n>>> Excluding test at line: %i <<<\n\n",__LINE__); \
}
#define INCOMPLETE() \
{ \
TEST_LOG("\n>>> Incomplete test at line: %i <<<\n\n",__LINE__); \
}
#endif // VOICE_ENGINE_VOE_TEST_DEFINES_H_