1 /*
2 * Copyright (c) 2014 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 "video/report_block_stats.h"
12
13 #include "test/gtest.h"
14
15 namespace webrtc {
16 namespace {
17
18 constexpr uint32_t kSsrc1 = 123;
19 constexpr uint32_t kSsrc2 = 234;
20
TEST(ReportBlockStatsTest,StoreAndGetFractionLost)21 TEST(ReportBlockStatsTest, StoreAndGetFractionLost) {
22 ReportBlockStats stats;
23 EXPECT_EQ(-1, stats.FractionLostInPercent());
24
25 // First report.
26 stats.Store(kSsrc1, /*packets_lost=*/10,
27 /*extended_highest_sequence_number=*/24'000);
28 EXPECT_EQ(-1, stats.FractionLostInPercent());
29 // fl: 100 * (15-10) / (24100-24000) = 5%
30 stats.Store(kSsrc1, /*packets_lost=*/15,
31 /*extended_highest_sequence_number=*/24'100);
32 EXPECT_EQ(5, stats.FractionLostInPercent());
33 // fl: 100 * (50-10) / (24200-24000) = 20%
34 stats.Store(kSsrc1, /*packets_lost=*/50,
35 /*extended_highest_sequence_number=*/24'200);
36 EXPECT_EQ(20, stats.FractionLostInPercent());
37 }
38
TEST(ReportBlockStatsTest,StoreAndGetFractionLost_TwoSsrcs)39 TEST(ReportBlockStatsTest, StoreAndGetFractionLost_TwoSsrcs) {
40 ReportBlockStats stats;
41 EXPECT_EQ(-1, stats.FractionLostInPercent());
42
43 // First report.
44 stats.Store(kSsrc1, /*packets_lost=*/10,
45 /*extended_highest_sequence_number=*/24'000);
46 EXPECT_EQ(-1, stats.FractionLostInPercent());
47 // fl: 100 * (15-10) / (24100-24000) = 5%
48 stats.Store(kSsrc1, /*packets_lost=*/15,
49 /*extended_highest_sequence_number=*/24'100);
50 EXPECT_EQ(5, stats.FractionLostInPercent());
51
52 // First report, kSsrc2.
53 stats.Store(kSsrc2, /*packets_lost=*/111,
54 /*extended_highest_sequence_number=*/8'500);
55 EXPECT_EQ(5, stats.FractionLostInPercent());
56 // fl: 100 * ((15-10) + (136-111)) / ((24100-24000) + (8800-8500)) = 7%
57 stats.Store(kSsrc2, /*packets_lost=*/136,
58 /*extended_highest_sequence_number=*/8'800);
59 EXPECT_EQ(7, stats.FractionLostInPercent());
60 }
61
62 } // namespace
63 } // namespace webrtc
64