OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2017 The WebRTC Project Authors. All rights reserved. |
| 3 * |
| 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. |
| 9 */ |
| 10 |
| 11 #include <utility> |
| 12 |
| 13 #include "webrtc/base/gunit.h" |
| 14 #include "webrtc/p2p/base/packetlossestimator.h" |
| 15 |
| 16 using cricket::PacketLossEstimator; |
| 17 |
| 18 class PacketLossEstimatorTest : public testing::Test {}; |
| 19 |
| 20 TEST_F(PacketLossEstimatorTest, InitialResponseRate) { |
| 21 PacketLossEstimator ple(5, 100); |
| 22 EXPECT_EQ(1.0, ple.get_response_rate()); |
| 23 } |
| 24 |
| 25 TEST_F(PacketLossEstimatorTest, InitialUpdateResponseRate) { |
| 26 PacketLossEstimator ple(5, 100); |
| 27 ple.UpdateResponseRate(10); |
| 28 EXPECT_EQ(1.0, ple.get_response_rate()); |
| 29 } |
| 30 |
| 31 TEST_F(PacketLossEstimatorTest, ResponseReceived) { |
| 32 PacketLossEstimator ple(5, 100); |
| 33 |
| 34 ple.ExpectResponse("a", 0); |
| 35 ple.ReceivedResponse("a", 1); |
| 36 ple.UpdateResponseRate(2); |
| 37 |
| 38 EXPECT_EQ(1.0, ple.get_response_rate()); |
| 39 } |
| 40 |
| 41 TEST_F(PacketLossEstimatorTest, ResponseNotConsideredLostYet) { |
| 42 PacketLossEstimator ple(5, 100); |
| 43 |
| 44 ple.ExpectResponse("a", 0); |
| 45 ple.UpdateResponseRate(2); |
| 46 |
| 47 EXPECT_EQ(1.0, ple.get_response_rate()); |
| 48 } |
| 49 |
| 50 TEST_F(PacketLossEstimatorTest, ResponseConsideredLost) { |
| 51 PacketLossEstimator ple(5, 100); |
| 52 |
| 53 ple.ExpectResponse("a", 0); |
| 54 ple.UpdateResponseRate(10); |
| 55 |
| 56 EXPECT_EQ(0.0, ple.get_response_rate()); |
| 57 } |
| 58 |
| 59 TEST_F(PacketLossEstimatorTest, ResponseLate) { |
| 60 PacketLossEstimator ple(5, 100); |
| 61 |
| 62 ple.ExpectResponse("a", 0); |
| 63 ple.ReceivedResponse("a", 6); |
| 64 ple.UpdateResponseRate(10); |
| 65 |
| 66 EXPECT_EQ(1.0, ple.get_response_rate()); |
| 67 } |
| 68 |
| 69 TEST_F(PacketLossEstimatorTest, ResponseForgotten) { |
| 70 PacketLossEstimator ple(5, 100); |
| 71 ple.ExpectResponse("a", 0); |
| 72 ple.UpdateResponseRate(101); |
| 73 |
| 74 EXPECT_EQ(1.0, ple.get_response_rate()); |
| 75 } |
| 76 |
| 77 TEST_F(PacketLossEstimatorTest, Lost1_Received1) { |
| 78 PacketLossEstimator ple(5, 100); |
| 79 |
| 80 ple.ExpectResponse("a", 0); |
| 81 ple.ExpectResponse("b", 2); |
| 82 ple.ReceivedResponse("b", 6); |
| 83 ple.UpdateResponseRate(7); |
| 84 |
| 85 EXPECT_EQ(0.5, ple.get_response_rate()); |
| 86 } |
| 87 |
| 88 static const std::pair<std::string, int64_t> kFivePackets[5] = {{"a", 0}, |
| 89 {"b", 2}, |
| 90 {"c", 4}, |
| 91 {"d", 6}, |
| 92 {"e", 8}}; |
| 93 |
| 94 // Time: 0 1 2 3 4 5 6 7 8 9 10 |
| 95 // Sent: a b c d e |
| 96 // Recv: b |
| 97 // Wind: --------------> |
| 98 TEST_F(PacketLossEstimatorTest, Lost3_Received1_Waiting1) { |
| 99 PacketLossEstimator ple(3, 100); |
| 100 |
| 101 for (const auto& p : kFivePackets) { |
| 102 ple.ExpectResponse(p.first, p.second); |
| 103 } |
| 104 ple.ReceivedResponse("b", 3); |
| 105 ple.UpdateResponseRate(10); |
| 106 EXPECT_EQ(0.25, ple.get_response_rate()); |
| 107 } |
| 108 |
| 109 // Time: 0 1 2 3 4 5 6 7 8 9 10 |
| 110 // Sent: a b c d e |
| 111 // Recv: c |
| 112 // Wind: <-------> |
| 113 TEST_F(PacketLossEstimatorTest, Forgot2_Received1_Lost1_Waiting1) { |
| 114 PacketLossEstimator ple(3, 7); |
| 115 |
| 116 for (const auto& p : kFivePackets) { |
| 117 ple.ExpectResponse(p.first, p.second); |
| 118 } |
| 119 ple.ReceivedResponse("c", 5); |
| 120 ple.UpdateResponseRate(10); |
| 121 EXPECT_EQ(0.5, ple.get_response_rate()); |
| 122 } |
OLD | NEW |