Chromium Code Reviews| Index: webrtc/modules/video_coding/nack_module_unittest.cc |
| diff --git a/webrtc/modules/video_coding/nack_module_unittest.cc b/webrtc/modules/video_coding/nack_module_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bc5e0b87c739ab8df4e2ff722ec26fb54306a425 |
| --- /dev/null |
| +++ b/webrtc/modules/video_coding/nack_module_unittest.cc |
| @@ -0,0 +1,154 @@ |
| +/* |
| + * Copyright (c) 2016 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 <cstring> |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "webrtc/modules/video_coding/include/video_coding_defines.h" |
| +#include "webrtc/modules/video_coding/nack_module.h" |
| +#include "webrtc/system_wrappers/include/clock.h" |
| + |
| +namespace webrtc { |
| +class TestNackModule : public ::testing::Test, |
| + public VCMNackSender, |
| + public VCMKeyFrameRequestSender { |
| + protected: |
| + TestNackModule() |
| + : clock_(new SimulatedClock(0)), |
| + nack_module_(CriticalSectionWrapper::CreateCriticalSection(), |
| + clock_.get(), |
| + this, |
| + this), |
| + keyframes_requested_(0) {} |
| + |
| + int32_t SendNack(const uint16_t* sequence_numbers, uint16_t length) override { |
| + for (int s = 0; s < length; ++s) { |
| + sent_nacks_.push_back(sequence_numbers[s]); |
| + } |
| + return 0; |
| + } |
| + |
| + int32_t RequestKeyFrame() override { |
| + ++keyframes_requested_; |
| + return 0; |
| + } |
| + |
| + rtc::scoped_ptr<SimulatedClock> clock_; |
| + NackModule nack_module_; |
| + std::vector<uint16_t> sent_nacks_; |
| + int keyframes_requested_; |
| +}; |
| + |
| +TEST_F(TestNackModule, NackOnePacket) { |
| + VCMPacket packet; |
| + packet.seqNum = 1; |
| + nack_module_.Notify(packet); |
| + packet.seqNum = 3; |
| + nack_module_.Notify(packet); |
| + EXPECT_EQ(1u, sent_nacks_.size()); |
| + EXPECT_EQ(2, sent_nacks_[0]); |
| +} |
| + |
| +TEST_F(TestNackModule, ResendNack) { |
| + VCMPacket packet; |
| + packet.seqNum = 1; |
| + nack_module_.Notify(packet); |
| + packet.seqNum = 3; |
| + nack_module_.Notify(packet); |
| + EXPECT_EQ(1u, sent_nacks_.size()); |
| + EXPECT_EQ(2, sent_nacks_[0]); |
| + |
| + // Default RTT is 100 |
| + clock_->AdvanceTimeMilliseconds(99); |
| + nack_module_.Process(); |
| + EXPECT_EQ(1u, sent_nacks_.size()); |
| + |
| + clock_->AdvanceTimeMilliseconds(1); |
| + nack_module_.Process(); |
| + EXPECT_EQ(2u, sent_nacks_.size()); |
| + |
| + nack_module_.UpdateRtt(50); |
| + clock_->AdvanceTimeMilliseconds(100); |
| + nack_module_.Process(); |
| + EXPECT_EQ(3u, sent_nacks_.size()); |
| + |
| + clock_->AdvanceTimeMilliseconds(50); |
| + nack_module_.Process(); |
| + EXPECT_EQ(4u, sent_nacks_.size()); |
| + |
| + packet.seqNum = 2; |
| + nack_module_.Notify(packet); |
| + clock_->AdvanceTimeMilliseconds(50); |
| + nack_module_.Process(); |
| + EXPECT_EQ(4u, sent_nacks_.size()); |
| +} |
| + |
| +TEST_F(TestNackModule, ResendPacketMaxRetries) { |
| + VCMPacket packet; |
| + packet.seqNum = 1; |
| + nack_module_.Notify(packet); |
| + packet.seqNum = 3; |
| + nack_module_.Notify(packet); |
| + EXPECT_EQ(1u, sent_nacks_.size()); |
| + EXPECT_EQ(2, sent_nacks_[0]); |
| + |
| + for (size_t retries = 1; retries < 10; ++retries) { |
| + clock_->AdvanceTimeMilliseconds(100); |
| + nack_module_.Process(); |
| + EXPECT_EQ(retries+1, sent_nacks_.size()); |
| + } |
| + |
| + clock_->AdvanceTimeMilliseconds(100); |
| + nack_module_.Process(); |
| + EXPECT_EQ(10u, sent_nacks_.size()); |
| +} |
| + |
| +TEST_F(TestNackModule, TooLargeNackList) { |
| + VCMPacket packet; |
| + packet.seqNum = 0; |
| + nack_module_.Notify(packet); |
| + packet.seqNum = 1000; |
| + nack_module_.Notify(packet); |
| + EXPECT_EQ(999u, sent_nacks_.size()); |
| + EXPECT_EQ(0, keyframes_requested_); |
| + packet.seqNum = 1002; |
| + nack_module_.Notify(packet); |
| + EXPECT_EQ(999u, sent_nacks_.size()); |
| + EXPECT_EQ(1, keyframes_requested_); |
| + packet.seqNum = 1003; |
| + nack_module_.Notify(packet); |
| + EXPECT_EQ(999u, sent_nacks_.size()); |
| + EXPECT_EQ(1, keyframes_requested_); |
| +} |
| + |
| +TEST_F(TestNackModule, TooLargeNackListWithKeyFrame) { |
| + VCMPacket packet; |
| + packet.seqNum = 0; |
| + nack_module_.Notify(packet); |
| + packet.seqNum = 1; |
| + packet.isFirstPacket = true; |
| + packet.frameType = kVideoFrameKey; |
| + nack_module_.Notify(packet); |
| + packet.seqNum = 1000; |
| + packet.isFirstPacket = false; |
| + packet.frameType = kVideoFrameKey; |
| + nack_module_.Notify(packet); |
| + EXPECT_EQ(998u, sent_nacks_.size()); |
| + EXPECT_EQ(0, keyframes_requested_); |
| + packet.seqNum = 1002; |
| + nack_module_.Notify(packet); |
| + EXPECT_EQ(999u, sent_nacks_.size()); |
| + EXPECT_EQ(0, keyframes_requested_); |
| + packet.seqNum = 1004; |
| + nack_module_.Notify(packet); |
| + EXPECT_EQ(999u, sent_nacks_.size()); |
| + EXPECT_EQ(1, keyframes_requested_); |
| +} |
| + |
|
stefan-webrtc
2016/02/23 12:29:02
I think it would be good to add more tests where w
|
| +} // namespace webrtc |