xref: /aosp_15_r20/external/webrtc/modules/rtp_rtcp/source/rtcp_packet/remote_estimate_unittest.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2019 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 #include "modules/rtp_rtcp/source/rtcp_packet/remote_estimate.h"
11 
12 #include "test/gtest.h"
13 
14 namespace webrtc {
15 namespace rtcp {
TEST(RemoteEstimateTest,EncodesCapacityBounds)16 TEST(RemoteEstimateTest, EncodesCapacityBounds) {
17   NetworkStateEstimate src;
18   src.link_capacity_lower = DataRate::KilobitsPerSec(10);
19   src.link_capacity_upper = DataRate::KilobitsPerSec(1000000);
20   rtc::Buffer data = GetRemoteEstimateSerializer()->Serialize(src);
21   NetworkStateEstimate dst;
22   EXPECT_TRUE(GetRemoteEstimateSerializer()->Parse(data, &dst));
23   EXPECT_EQ(src.link_capacity_lower, dst.link_capacity_lower);
24   EXPECT_EQ(src.link_capacity_upper, dst.link_capacity_upper);
25 }
26 
TEST(RemoteEstimateTest,ExpandsToPlusInfinity)27 TEST(RemoteEstimateTest, ExpandsToPlusInfinity) {
28   NetworkStateEstimate src;
29   // White box testing: We know that the value is stored in an unsigned 24 int
30   // with kbps resolution. We expected it be represented as plus infinity.
31   src.link_capacity_lower = DataRate::KilobitsPerSec(2 << 24);
32   src.link_capacity_upper = DataRate::PlusInfinity();
33   rtc::Buffer data = GetRemoteEstimateSerializer()->Serialize(src);
34 
35   NetworkStateEstimate dst;
36   EXPECT_TRUE(GetRemoteEstimateSerializer()->Parse(data, &dst));
37   EXPECT_TRUE(dst.link_capacity_lower.IsPlusInfinity());
38   EXPECT_TRUE(dst.link_capacity_upper.IsPlusInfinity());
39 }
40 
TEST(RemoteEstimateTest,DoesNotEncodeNegative)41 TEST(RemoteEstimateTest, DoesNotEncodeNegative) {
42   NetworkStateEstimate src;
43   src.link_capacity_lower = DataRate::MinusInfinity();
44   src.link_capacity_upper = DataRate::MinusInfinity();
45   rtc::Buffer data = GetRemoteEstimateSerializer()->Serialize(src);
46   // Since MinusInfinity can't be represented, the buffer should be empty.
47   EXPECT_EQ(data.size(), 0u);
48   NetworkStateEstimate dst;
49   dst.link_capacity_lower = DataRate::KilobitsPerSec(300);
50   EXPECT_TRUE(GetRemoteEstimateSerializer()->Parse(data, &dst));
51   // The fields will be left unchanged by the parser as they were not encoded.
52   EXPECT_EQ(dst.link_capacity_lower, DataRate::KilobitsPerSec(300));
53   EXPECT_TRUE(dst.link_capacity_upper.IsMinusInfinity());
54 }
55 }  // namespace rtcp
56 }  // namespace webrtc
57