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
17 class ReportBlockStatsTest : public ::testing::Test {
18 protected:
ReportBlockStatsTest()19 ReportBlockStatsTest() {
20 // kSsrc1: report 1-3.
21 stats1_1_.packets_lost = 10;
22 stats1_1_.extended_highest_sequence_number = 24000;
23 stats1_2_.packets_lost = 15;
24 stats1_2_.extended_highest_sequence_number = 24100;
25 stats1_3_.packets_lost = 50;
26 stats1_3_.extended_highest_sequence_number = 24200;
27 // kSsrc2: report 1,2.
28 stats2_1_.packets_lost = 111;
29 stats2_1_.extended_highest_sequence_number = 8500;
30 stats2_2_.packets_lost = 136;
31 stats2_2_.extended_highest_sequence_number = 8800;
32 }
33
34 const uint32_t kSsrc1 = 123;
35 const uint32_t kSsrc2 = 234;
36 RtcpStatistics stats1_1_;
37 RtcpStatistics stats1_2_;
38 RtcpStatistics stats1_3_;
39 RtcpStatistics stats2_1_;
40 RtcpStatistics stats2_2_;
41 };
42
TEST_F(ReportBlockStatsTest,StoreAndGetFractionLost)43 TEST_F(ReportBlockStatsTest, StoreAndGetFractionLost) {
44 ReportBlockStats stats;
45 EXPECT_EQ(-1, stats.FractionLostInPercent());
46
47 // First report.
48 stats.Store(kSsrc1, stats1_1_);
49 EXPECT_EQ(-1, stats.FractionLostInPercent());
50 // fl: 100 * (15-10) / (24100-24000) = 5%
51 stats.Store(kSsrc1, stats1_2_);
52 EXPECT_EQ(5, stats.FractionLostInPercent());
53 // fl: 100 * (50-10) / (24200-24000) = 20%
54 stats.Store(kSsrc1, stats1_3_);
55 EXPECT_EQ(20, stats.FractionLostInPercent());
56 }
57
TEST_F(ReportBlockStatsTest,StoreAndGetFractionLost_TwoSsrcs)58 TEST_F(ReportBlockStatsTest, StoreAndGetFractionLost_TwoSsrcs) {
59 ReportBlockStats stats;
60 EXPECT_EQ(-1, stats.FractionLostInPercent());
61
62 // First report.
63 stats.Store(kSsrc1, stats1_1_);
64 EXPECT_EQ(-1, stats.FractionLostInPercent());
65 // fl: 100 * (15-10) / (24100-24000) = 5%
66 stats.Store(kSsrc1, stats1_2_);
67 EXPECT_EQ(5, stats.FractionLostInPercent());
68
69 // First report, kSsrc2.
70 stats.Store(kSsrc2, stats2_1_);
71 EXPECT_EQ(5, stats.FractionLostInPercent());
72 // fl: 100 * ((15-10) + (136-111)) / ((24100-24000) + (8800-8500)) = 7%
73 stats.Store(kSsrc2, stats2_2_);
74 EXPECT_EQ(7, stats.FractionLostInPercent());
75 }
76
77 } // namespace webrtc
78