henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "pc/dtmfsender.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 13 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 14 | #include <set> |
| 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
Patrik Höglund | 563934e | 2017-09-15 09:04:28 +0200 | [diff] [blame] | 18 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "pc/audiotrack.h" |
| 20 | #include "rtc_base/fakeclock.h" |
| 21 | #include "rtc_base/gunit.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "rtc_base/timeutils.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 23 | |
| 24 | using webrtc::AudioTrackInterface; |
| 25 | using webrtc::AudioTrack; |
| 26 | using webrtc::DtmfProviderInterface; |
| 27 | using webrtc::DtmfSender; |
| 28 | using webrtc::DtmfSenderObserverInterface; |
| 29 | |
| 30 | static const char kTestAudioLabel[] = "test_audio_track"; |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 31 | // TODO(deadbeef): Even though this test now uses a fake clock, it has a |
| 32 | // generous 3-second timeout for every test case. The timeout could be tuned |
| 33 | // to each test based on the tones sent, instead. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 34 | static const int kMaxWaitMs = 3000; |
| 35 | |
Magnus Jedvert | fc95084 | 2015-10-12 16:10:43 +0200 | [diff] [blame] | 36 | class FakeDtmfObserver : public DtmfSenderObserverInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | public: |
| 38 | FakeDtmfObserver() : completed_(false) {} |
| 39 | |
| 40 | // Implements DtmfSenderObserverInterface. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 41 | void OnToneChange(const std::string& tone) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | tones_.push_back(tone); |
| 43 | if (tone.empty()) { |
| 44 | completed_ = true; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // getters |
| 49 | const std::vector<std::string>& tones() const { |
| 50 | return tones_; |
| 51 | } |
| 52 | bool completed() const { |
| 53 | return completed_; |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | std::vector<std::string> tones_; |
| 58 | bool completed_; |
| 59 | }; |
| 60 | |
| 61 | class FakeDtmfProvider : public DtmfProviderInterface { |
| 62 | public: |
| 63 | struct DtmfInfo { |
| 64 | DtmfInfo(int code, int duration, int gap) |
| 65 | : code(code), |
| 66 | duration(duration), |
| 67 | gap(gap) {} |
| 68 | int code; |
| 69 | int duration; |
| 70 | int gap; |
| 71 | }; |
| 72 | |
| 73 | FakeDtmfProvider() : last_insert_dtmf_call_(0) {} |
| 74 | |
| 75 | ~FakeDtmfProvider() { |
| 76 | SignalDestroyed(); |
| 77 | } |
| 78 | |
| 79 | // Implements DtmfProviderInterface. |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 80 | bool CanInsertDtmf() override { return can_insert_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 81 | |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 82 | bool InsertDtmf(int code, int duration) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | int gap = 0; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 84 | // TODO(ronghuawu): Make the timer (basically the rtc::TimeNanos) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | // mockable and use a fake timer in the unit tests. |
| 86 | if (last_insert_dtmf_call_ > 0) { |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 87 | gap = static_cast<int>(rtc::TimeMillis() - last_insert_dtmf_call_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 88 | } |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 89 | last_insert_dtmf_call_ = rtc::TimeMillis(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | dtmf_info_queue_.push_back(DtmfInfo(code, duration, gap)); |
| 92 | return true; |
| 93 | } |
| 94 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 95 | sigslot::signal0<>* GetOnDestroyedSignal() override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 96 | return &SignalDestroyed; |
| 97 | } |
| 98 | |
| 99 | // getter and setter |
| 100 | const std::vector<DtmfInfo>& dtmf_info_queue() const { |
| 101 | return dtmf_info_queue_; |
| 102 | } |
| 103 | |
| 104 | // helper functions |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 105 | void SetCanInsertDtmf(bool can_insert) { can_insert_ = can_insert; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 106 | |
| 107 | private: |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 108 | bool can_insert_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 109 | std::vector<DtmfInfo> dtmf_info_queue_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 110 | int64_t last_insert_dtmf_call_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 111 | sigslot::signal0<> SignalDestroyed; |
| 112 | }; |
| 113 | |
| 114 | class DtmfSenderTest : public testing::Test { |
| 115 | protected: |
| 116 | DtmfSenderTest() |
| 117 | : track_(AudioTrack::Create(kTestAudioLabel, NULL)), |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 118 | observer_(new rtc::RefCountedObject<FakeDtmfObserver>()), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 119 | provider_(new FakeDtmfProvider()) { |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 120 | provider_->SetCanInsertDtmf(true); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 121 | dtmf_ = DtmfSender::Create(track_, rtc::Thread::Current(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | provider_.get()); |
| 123 | dtmf_->RegisterObserver(observer_.get()); |
| 124 | } |
| 125 | |
| 126 | ~DtmfSenderTest() { |
| 127 | if (dtmf_.get()) { |
| 128 | dtmf_->UnregisterObserver(); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | // Constructs a list of DtmfInfo from |tones|, |duration| and |
| 133 | // |inter_tone_gap|. |
| 134 | void GetDtmfInfoFromString(const std::string& tones, int duration, |
| 135 | int inter_tone_gap, |
| 136 | std::vector<FakeDtmfProvider::DtmfInfo>* dtmfs) { |
| 137 | // Init extra_delay as -inter_tone_gap - duration to ensure the first |
| 138 | // DtmfInfo's gap field will be 0. |
| 139 | int extra_delay = -1 * (inter_tone_gap + duration); |
| 140 | |
| 141 | std::string::const_iterator it = tones.begin(); |
| 142 | for (; it != tones.end(); ++it) { |
| 143 | char tone = *it; |
| 144 | int code = 0; |
| 145 | webrtc::GetDtmfCode(tone, &code); |
| 146 | if (tone == ',') { |
| 147 | extra_delay = 2000; // 2 seconds |
| 148 | } else { |
| 149 | dtmfs->push_back(FakeDtmfProvider::DtmfInfo(code, duration, |
| 150 | duration + inter_tone_gap + extra_delay)); |
| 151 | extra_delay = 0; |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | void VerifyExpectedState(AudioTrackInterface* track, |
| 157 | const std::string& tones, |
| 158 | int duration, int inter_tone_gap) { |
| 159 | EXPECT_EQ(track, dtmf_->track()); |
| 160 | EXPECT_EQ(tones, dtmf_->tones()); |
| 161 | EXPECT_EQ(duration, dtmf_->duration()); |
| 162 | EXPECT_EQ(inter_tone_gap, dtmf_->inter_tone_gap()); |
| 163 | } |
| 164 | |
| 165 | // Verify the provider got all the expected calls. |
| 166 | void VerifyOnProvider(const std::string& tones, int duration, |
| 167 | int inter_tone_gap) { |
| 168 | std::vector<FakeDtmfProvider::DtmfInfo> dtmf_queue_ref; |
| 169 | GetDtmfInfoFromString(tones, duration, inter_tone_gap, &dtmf_queue_ref); |
| 170 | VerifyOnProvider(dtmf_queue_ref); |
| 171 | } |
| 172 | |
| 173 | void VerifyOnProvider( |
| 174 | const std::vector<FakeDtmfProvider::DtmfInfo>& dtmf_queue_ref) { |
| 175 | const std::vector<FakeDtmfProvider::DtmfInfo>& dtmf_queue = |
| 176 | provider_->dtmf_info_queue(); |
| 177 | ASSERT_EQ(dtmf_queue_ref.size(), dtmf_queue.size()); |
| 178 | std::vector<FakeDtmfProvider::DtmfInfo>::const_iterator it_ref = |
| 179 | dtmf_queue_ref.begin(); |
| 180 | std::vector<FakeDtmfProvider::DtmfInfo>::const_iterator it = |
| 181 | dtmf_queue.begin(); |
| 182 | while (it_ref != dtmf_queue_ref.end() && it != dtmf_queue.end()) { |
| 183 | EXPECT_EQ(it_ref->code, it->code); |
| 184 | EXPECT_EQ(it_ref->duration, it->duration); |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 185 | // Allow ~10ms error (can be small since we're using a fake clock). |
| 186 | EXPECT_GE(it_ref->gap, it->gap - 10); |
| 187 | EXPECT_LE(it_ref->gap, it->gap + 10); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 188 | ++it_ref; |
| 189 | ++it; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | // Verify the observer got all the expected callbacks. |
| 194 | void VerifyOnObserver(const std::string& tones_ref) { |
| 195 | const std::vector<std::string>& tones = observer_->tones(); |
| 196 | // The observer will get an empty string at the end. |
| 197 | EXPECT_EQ(tones_ref.size() + 1, tones.size()); |
| 198 | EXPECT_TRUE(tones.back().empty()); |
| 199 | std::string::const_iterator it_ref = tones_ref.begin(); |
| 200 | std::vector<std::string>::const_iterator it = tones.begin(); |
| 201 | while (it_ref != tones_ref.end() && it != tones.end()) { |
| 202 | EXPECT_EQ(*it_ref, it->at(0)); |
| 203 | ++it_ref; |
| 204 | ++it; |
| 205 | } |
| 206 | } |
| 207 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 208 | rtc::scoped_refptr<AudioTrackInterface> track_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 209 | std::unique_ptr<FakeDtmfObserver> observer_; |
| 210 | std::unique_ptr<FakeDtmfProvider> provider_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 211 | rtc::scoped_refptr<DtmfSender> dtmf_; |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 212 | rtc::ScopedFakeClock fake_clock_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | TEST_F(DtmfSenderTest, CanInsertDtmf) { |
| 216 | EXPECT_TRUE(dtmf_->CanInsertDtmf()); |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 217 | provider_->SetCanInsertDtmf(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 218 | EXPECT_FALSE(dtmf_->CanInsertDtmf()); |
| 219 | } |
| 220 | |
| 221 | TEST_F(DtmfSenderTest, InsertDtmf) { |
| 222 | std::string tones = "@1%a&*$"; |
| 223 | int duration = 100; |
| 224 | int inter_tone_gap = 50; |
| 225 | EXPECT_TRUE(dtmf_->InsertDtmf(tones, duration, inter_tone_gap)); |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 226 | EXPECT_TRUE_SIMULATED_WAIT(observer_->completed(), kMaxWaitMs, fake_clock_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 227 | |
| 228 | // The unrecognized characters should be ignored. |
| 229 | std::string known_tones = "1a*"; |
| 230 | VerifyOnProvider(known_tones, duration, inter_tone_gap); |
| 231 | VerifyOnObserver(known_tones); |
| 232 | } |
| 233 | |
| 234 | TEST_F(DtmfSenderTest, InsertDtmfTwice) { |
| 235 | std::string tones1 = "12"; |
| 236 | std::string tones2 = "ab"; |
| 237 | int duration = 100; |
| 238 | int inter_tone_gap = 50; |
| 239 | EXPECT_TRUE(dtmf_->InsertDtmf(tones1, duration, inter_tone_gap)); |
| 240 | VerifyExpectedState(track_, tones1, duration, inter_tone_gap); |
| 241 | // Wait until the first tone got sent. |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 242 | EXPECT_TRUE_SIMULATED_WAIT(observer_->tones().size() == 1, kMaxWaitMs, |
| 243 | fake_clock_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 244 | VerifyExpectedState(track_, "2", duration, inter_tone_gap); |
| 245 | // Insert with another tone buffer. |
| 246 | EXPECT_TRUE(dtmf_->InsertDtmf(tones2, duration, inter_tone_gap)); |
| 247 | VerifyExpectedState(track_, tones2, duration, inter_tone_gap); |
| 248 | // Wait until it's completed. |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 249 | EXPECT_TRUE_SIMULATED_WAIT(observer_->completed(), kMaxWaitMs, fake_clock_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 250 | |
| 251 | std::vector<FakeDtmfProvider::DtmfInfo> dtmf_queue_ref; |
| 252 | GetDtmfInfoFromString("1", duration, inter_tone_gap, &dtmf_queue_ref); |
| 253 | GetDtmfInfoFromString("ab", duration, inter_tone_gap, &dtmf_queue_ref); |
| 254 | VerifyOnProvider(dtmf_queue_ref); |
| 255 | VerifyOnObserver("1ab"); |
| 256 | } |
| 257 | |
| 258 | TEST_F(DtmfSenderTest, InsertDtmfWhileProviderIsDeleted) { |
| 259 | std::string tones = "@1%a&*$"; |
| 260 | int duration = 100; |
| 261 | int inter_tone_gap = 50; |
| 262 | EXPECT_TRUE(dtmf_->InsertDtmf(tones, duration, inter_tone_gap)); |
| 263 | // Wait until the first tone got sent. |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 264 | EXPECT_TRUE_SIMULATED_WAIT(observer_->tones().size() == 1, kMaxWaitMs, |
| 265 | fake_clock_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 266 | // Delete provider. |
| 267 | provider_.reset(); |
| 268 | // The queue should be discontinued so no more tone callbacks. |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 269 | SIMULATED_WAIT(false, 200, fake_clock_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 270 | EXPECT_EQ(1U, observer_->tones().size()); |
| 271 | } |
| 272 | |
| 273 | TEST_F(DtmfSenderTest, InsertDtmfWhileSenderIsDeleted) { |
| 274 | std::string tones = "@1%a&*$"; |
| 275 | int duration = 100; |
| 276 | int inter_tone_gap = 50; |
| 277 | EXPECT_TRUE(dtmf_->InsertDtmf(tones, duration, inter_tone_gap)); |
| 278 | // Wait until the first tone got sent. |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 279 | EXPECT_TRUE_SIMULATED_WAIT(observer_->tones().size() == 1, kMaxWaitMs, |
| 280 | fake_clock_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 281 | // Delete the sender. |
| 282 | dtmf_ = NULL; |
| 283 | // The queue should be discontinued so no more tone callbacks. |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 284 | SIMULATED_WAIT(false, 200, fake_clock_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 285 | EXPECT_EQ(1U, observer_->tones().size()); |
| 286 | } |
| 287 | |
| 288 | TEST_F(DtmfSenderTest, InsertEmptyTonesToCancelPreviousTask) { |
| 289 | std::string tones1 = "12"; |
| 290 | std::string tones2 = ""; |
| 291 | int duration = 100; |
| 292 | int inter_tone_gap = 50; |
| 293 | EXPECT_TRUE(dtmf_->InsertDtmf(tones1, duration, inter_tone_gap)); |
| 294 | // Wait until the first tone got sent. |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 295 | EXPECT_TRUE_SIMULATED_WAIT(observer_->tones().size() == 1, kMaxWaitMs, |
| 296 | fake_clock_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 297 | // Insert with another tone buffer. |
| 298 | EXPECT_TRUE(dtmf_->InsertDtmf(tones2, duration, inter_tone_gap)); |
| 299 | // Wait until it's completed. |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 300 | EXPECT_TRUE_SIMULATED_WAIT(observer_->completed(), kMaxWaitMs, fake_clock_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 301 | |
| 302 | std::vector<FakeDtmfProvider::DtmfInfo> dtmf_queue_ref; |
| 303 | GetDtmfInfoFromString("1", duration, inter_tone_gap, &dtmf_queue_ref); |
| 304 | VerifyOnProvider(dtmf_queue_ref); |
| 305 | VerifyOnObserver("1"); |
| 306 | } |
| 307 | |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 308 | TEST_F(DtmfSenderTest, InsertDtmfWithCommaAsDelay) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 309 | std::string tones = "3,4"; |
| 310 | int duration = 100; |
| 311 | int inter_tone_gap = 50; |
| 312 | EXPECT_TRUE(dtmf_->InsertDtmf(tones, duration, inter_tone_gap)); |
deadbeef | e7fc7d5 | 2016-10-28 13:53:08 -0700 | [diff] [blame] | 313 | EXPECT_TRUE_SIMULATED_WAIT(observer_->completed(), kMaxWaitMs, fake_clock_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 314 | |
| 315 | VerifyOnProvider(tones, duration, inter_tone_gap); |
| 316 | VerifyOnObserver(tones); |
| 317 | } |
| 318 | |
| 319 | TEST_F(DtmfSenderTest, TryInsertDtmfWhenItDoesNotWork) { |
| 320 | std::string tones = "3,4"; |
| 321 | int duration = 100; |
| 322 | int inter_tone_gap = 50; |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 323 | provider_->SetCanInsertDtmf(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 324 | EXPECT_FALSE(dtmf_->InsertDtmf(tones, duration, inter_tone_gap)); |
| 325 | } |
| 326 | |
| 327 | TEST_F(DtmfSenderTest, InsertDtmfWithInvalidDurationOrGap) { |
| 328 | std::string tones = "3,4"; |
dminor | 588101c | 2017-03-28 11:18:32 -0700 | [diff] [blame] | 329 | int duration = 40; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 330 | int inter_tone_gap = 50; |
| 331 | |
| 332 | EXPECT_FALSE(dtmf_->InsertDtmf(tones, 6001, inter_tone_gap)); |
dminor | 588101c | 2017-03-28 11:18:32 -0700 | [diff] [blame] | 333 | EXPECT_FALSE(dtmf_->InsertDtmf(tones, 39, inter_tone_gap)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 334 | EXPECT_FALSE(dtmf_->InsertDtmf(tones, duration, 49)); |
| 335 | |
| 336 | EXPECT_TRUE(dtmf_->InsertDtmf(tones, duration, inter_tone_gap)); |
| 337 | } |