blob: 0b0230941fc63d1196a40d01502bddcdd840a39f [file] [log] [blame]
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +00001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "video/report_block_stats.h"
Jonas Olssona4d87372019-07-05 19:08:33 +020012
Yves Gerey665174f2018-06-19 15:03:05 +020013#include "test/gtest.h"
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000014
15namespace webrtc {
16
17class ReportBlockStatsTest : public ::testing::Test {
18 protected:
Åsa Persson5e155a62019-08-01 17:38:01 +020019 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;
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000032 }
33
Åsa Persson5e155a62019-08-01 17:38:01 +020034 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_;
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000041};
42
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000043TEST_F(ReportBlockStatsTest, StoreAndGetFractionLost) {
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000044 ReportBlockStats stats;
asapersson@webrtc.orge7358ea2015-01-21 09:00:19 +000045 EXPECT_EQ(-1, stats.FractionLostInPercent());
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000046
Åsa Persson5e155a62019-08-01 17:38:01 +020047 // First report.
48 stats.Store(kSsrc1, stats1_1_);
asapersson@webrtc.orge7358ea2015-01-21 09:00:19 +000049 EXPECT_EQ(-1, stats.FractionLostInPercent());
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000050 // fl: 100 * (15-10) / (24100-24000) = 5%
Åsa Persson5e155a62019-08-01 17:38:01 +020051 stats.Store(kSsrc1, stats1_2_);
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000052 EXPECT_EQ(5, stats.FractionLostInPercent());
53 // fl: 100 * (50-10) / (24200-24000) = 20%
Åsa Persson5e155a62019-08-01 17:38:01 +020054 stats.Store(kSsrc1, stats1_3_);
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000055 EXPECT_EQ(20, stats.FractionLostInPercent());
56}
57
Åsa Persson5e155a62019-08-01 17:38:01 +020058TEST_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
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000077} // namespace webrtc