1/* 2 * libjingle 3 * Copyright 2013, Google Inc. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include "talk/app/webrtc/localaudiosource.h" 29 30#include <string> 31#include <vector> 32 33#include "talk/app/webrtc/test/fakeconstraints.h" 34#include "talk/media/base/fakemediaengine.h" 35#include "talk/media/base/fakevideorenderer.h" 36#include "talk/media/devices/fakedevicemanager.h" 37#include "webrtc/base/gunit.h" 38 39using webrtc::LocalAudioSource; 40using webrtc::MediaConstraintsInterface; 41using webrtc::MediaSourceInterface; 42using webrtc::PeerConnectionFactoryInterface; 43 44TEST(LocalAudioSourceTest, SetValidOptions) { 45 webrtc::FakeConstraints constraints; 46 constraints.AddMandatory(MediaConstraintsInterface::kEchoCancellation, false); 47 constraints.AddOptional( 48 MediaConstraintsInterface::kExperimentalEchoCancellation, true); 49 constraints.AddOptional(MediaConstraintsInterface::kAutoGainControl, true); 50 constraints.AddOptional( 51 MediaConstraintsInterface::kExperimentalAutoGainControl, true); 52 constraints.AddMandatory(MediaConstraintsInterface::kNoiseSuppression, false); 53 constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, true); 54 55 rtc::scoped_refptr<LocalAudioSource> source = 56 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), 57 &constraints); 58 59 bool value; 60 EXPECT_TRUE(source->options().echo_cancellation.Get(&value)); 61 EXPECT_FALSE(value); 62 EXPECT_TRUE(source->options().experimental_aec.Get(&value)); 63 EXPECT_TRUE(value); 64 EXPECT_TRUE(source->options().auto_gain_control.Get(&value)); 65 EXPECT_TRUE(value); 66 EXPECT_TRUE(source->options().experimental_agc.Get(&value)); 67 EXPECT_TRUE(value); 68 EXPECT_TRUE(source->options().noise_suppression.Get(&value)); 69 EXPECT_FALSE(value); 70 EXPECT_TRUE(source->options().highpass_filter.Get(&value)); 71 EXPECT_TRUE(value); 72} 73 74TEST(LocalAudioSourceTest, OptionNotSet) { 75 webrtc::FakeConstraints constraints; 76 rtc::scoped_refptr<LocalAudioSource> source = 77 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), 78 &constraints); 79 bool value; 80 EXPECT_FALSE(source->options().highpass_filter.Get(&value)); 81} 82 83TEST(LocalAudioSourceTest, MandatoryOverridesOptional) { 84 webrtc::FakeConstraints constraints; 85 constraints.AddMandatory(MediaConstraintsInterface::kEchoCancellation, false); 86 constraints.AddOptional(MediaConstraintsInterface::kEchoCancellation, true); 87 88 rtc::scoped_refptr<LocalAudioSource> source = 89 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), 90 &constraints); 91 92 bool value; 93 EXPECT_TRUE(source->options().echo_cancellation.Get(&value)); 94 EXPECT_FALSE(value); 95} 96 97TEST(LocalAudioSourceTest, InvalidOptional) { 98 webrtc::FakeConstraints constraints; 99 constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, false); 100 constraints.AddOptional("invalidKey", false); 101 102 rtc::scoped_refptr<LocalAudioSource> source = 103 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), 104 &constraints); 105 106 EXPECT_EQ(MediaSourceInterface::kLive, source->state()); 107 bool value; 108 EXPECT_TRUE(source->options().highpass_filter.Get(&value)); 109 EXPECT_FALSE(value); 110} 111 112TEST(LocalAudioSourceTest, InvalidMandatory) { 113 webrtc::FakeConstraints constraints; 114 constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false); 115 constraints.AddMandatory("invalidKey", false); 116 117 rtc::scoped_refptr<LocalAudioSource> source = 118 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), 119 &constraints); 120 121 EXPECT_EQ(MediaSourceInterface::kLive, source->state()); 122 bool value; 123 EXPECT_TRUE(source->options().highpass_filter.Get(&value)); 124 EXPECT_FALSE(value); 125} 126