| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 static const int kTsIncrement = kFrameSizeMs * kFs / 1000; | 32 static const int kTsIncrement = kFrameSizeMs * kFs / 1000; |
| 33 | 33 |
| 34 DelayManagerTest(); | 34 DelayManagerTest(); |
| 35 virtual void SetUp(); | 35 virtual void SetUp(); |
| 36 virtual void TearDown(); | 36 virtual void TearDown(); |
| 37 void SetPacketAudioLength(int lengt_ms); | 37 void SetPacketAudioLength(int lengt_ms); |
| 38 void InsertNextPacket(); | 38 void InsertNextPacket(); |
| 39 void IncreaseTime(int inc_ms); | 39 void IncreaseTime(int inc_ms); |
| 40 | 40 |
| 41 DelayManager* dm_; | 41 DelayManager* dm_; |
| 42 TickTimer tick_timer_; |
| 42 MockDelayPeakDetector detector_; | 43 MockDelayPeakDetector detector_; |
| 43 uint16_t seq_no_; | 44 uint16_t seq_no_; |
| 44 uint32_t ts_; | 45 uint32_t ts_; |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 DelayManagerTest::DelayManagerTest() | 48 DelayManagerTest::DelayManagerTest() |
| 48 : dm_(NULL), | 49 : dm_(NULL), detector_(&tick_timer_), seq_no_(0x1234), ts_(0x12345678) {} |
| 49 seq_no_(0x1234), | |
| 50 ts_(0x12345678) { | |
| 51 } | |
| 52 | 50 |
| 53 void DelayManagerTest::SetUp() { | 51 void DelayManagerTest::SetUp() { |
| 54 EXPECT_CALL(detector_, Reset()) | 52 EXPECT_CALL(detector_, Reset()) |
| 55 .Times(1); | 53 .Times(1); |
| 56 dm_ = new DelayManager(kMaxNumberOfPackets, &detector_); | 54 dm_ = new DelayManager(kMaxNumberOfPackets, &detector_); |
| 57 } | 55 } |
| 58 | 56 |
| 59 void DelayManagerTest::SetPacketAudioLength(int lengt_ms) { | 57 void DelayManagerTest::SetPacketAudioLength(int lengt_ms) { |
| 60 EXPECT_CALL(detector_, SetPacketAudioLength(lengt_ms)); | 58 EXPECT_CALL(detector_, SetPacketAudioLength(lengt_ms)); |
| 61 dm_->SetPacketAudioLength(lengt_ms); | 59 dm_->SetPacketAudioLength(lengt_ms); |
| 62 } | 60 } |
| 63 | 61 |
| 64 void DelayManagerTest::InsertNextPacket() { | 62 void DelayManagerTest::InsertNextPacket() { |
| 65 EXPECT_EQ(0, dm_->Update(seq_no_, ts_, kFs)); | 63 EXPECT_EQ(0, dm_->Update(seq_no_, ts_, kFs)); |
| 66 seq_no_ += 1; | 64 seq_no_ += 1; |
| 67 ts_ += kTsIncrement; | 65 ts_ += kTsIncrement; |
| 68 } | 66 } |
| 69 | 67 |
| 70 void DelayManagerTest::IncreaseTime(int inc_ms) { | 68 void DelayManagerTest::IncreaseTime(int inc_ms) { |
| 71 for (int t = 0; t < inc_ms; t += kTimeStepMs) { | 69 for (int t = 0; t < inc_ms; t += kTimeStepMs) { |
| 72 EXPECT_CALL(detector_, IncrementCounter(kTimeStepMs)) | |
| 73 .Times(1); | |
| 74 dm_->UpdateCounters(kTimeStepMs); | 70 dm_->UpdateCounters(kTimeStepMs); |
| 71 tick_timer_.Increment(); |
| 75 } | 72 } |
| 76 } | 73 } |
| 77 void DelayManagerTest::TearDown() { | 74 void DelayManagerTest::TearDown() { |
| 78 EXPECT_CALL(detector_, Die()); | 75 EXPECT_CALL(detector_, Die()); |
| 79 delete dm_; | 76 delete dm_; |
| 80 } | 77 } |
| 81 | 78 |
| 82 TEST_F(DelayManagerTest, CreateAndDestroy) { | 79 TEST_F(DelayManagerTest, CreateAndDestroy) { |
| 83 // Nothing to do here. The test fixture creates and destroys the DelayManager | 80 // Nothing to do here. The test fixture creates and destroys the DelayManager |
| 84 // object. | 81 // object. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 108 // Expect DelayManager to pass on the question to the detector. | 105 // Expect DelayManager to pass on the question to the detector. |
| 109 // Call twice, and let the detector return true the first time and false the | 106 // Call twice, and let the detector return true the first time and false the |
| 110 // second time. | 107 // second time. |
| 111 EXPECT_CALL(detector_, peak_found()) | 108 EXPECT_CALL(detector_, peak_found()) |
| 112 .WillOnce(Return(true)) | 109 .WillOnce(Return(true)) |
| 113 .WillOnce(Return(false)); | 110 .WillOnce(Return(false)); |
| 114 EXPECT_TRUE(dm_->PeakFound()); | 111 EXPECT_TRUE(dm_->PeakFound()); |
| 115 EXPECT_FALSE(dm_->PeakFound()); | 112 EXPECT_FALSE(dm_->PeakFound()); |
| 116 } | 113 } |
| 117 | 114 |
| 118 TEST_F(DelayManagerTest, UpdateCounters) { | |
| 119 // Expect DelayManager to pass on the counter update to the detector. | |
| 120 EXPECT_CALL(detector_, IncrementCounter(kTimeStepMs)) | |
| 121 .Times(1); | |
| 122 dm_->UpdateCounters(kTimeStepMs); | |
| 123 } | |
| 124 | |
| 125 TEST_F(DelayManagerTest, UpdateNormal) { | 115 TEST_F(DelayManagerTest, UpdateNormal) { |
| 126 SetPacketAudioLength(kFrameSizeMs); | 116 SetPacketAudioLength(kFrameSizeMs); |
| 127 // First packet arrival. | 117 // First packet arrival. |
| 128 InsertNextPacket(); | 118 InsertNextPacket(); |
| 129 // Advance time by one frame size. | 119 // Advance time by one frame size. |
| 130 IncreaseTime(kFrameSizeMs); | 120 IncreaseTime(kFrameSizeMs); |
| 131 // Second packet arrival. | 121 // Second packet arrival. |
| 132 // Expect detector update method to be called once with inter-arrival time | 122 // Expect detector update method to be called once with inter-arrival time |
| 133 // equal to 1 packet, and (base) target level equal to 1 as well. | 123 // equal to 1 packet, and (base) target level equal to 1 as well. |
| 134 // Return false to indicate no peaks found. | 124 // Return false to indicate no peaks found. |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 EXPECT_TRUE(dm_->SetMaximumDelay(10)); | 278 EXPECT_TRUE(dm_->SetMaximumDelay(10)); |
| 289 EXPECT_FALSE(dm_->SetMinimumDelay(20)); | 279 EXPECT_FALSE(dm_->SetMinimumDelay(20)); |
| 290 | 280 |
| 291 // Maximum delay less than minimum delay is not accepted. | 281 // Maximum delay less than minimum delay is not accepted. |
| 292 EXPECT_TRUE(dm_->SetMaximumDelay(100)); | 282 EXPECT_TRUE(dm_->SetMaximumDelay(100)); |
| 293 EXPECT_TRUE(dm_->SetMinimumDelay(80)); | 283 EXPECT_TRUE(dm_->SetMinimumDelay(80)); |
| 294 EXPECT_FALSE(dm_->SetMaximumDelay(60)); | 284 EXPECT_FALSE(dm_->SetMaximumDelay(60)); |
| 295 } | 285 } |
| 296 | 286 |
| 297 } // namespace webrtc | 287 } // namespace webrtc |
| OLD | NEW |