OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2015 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 "webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.h" |
| 12 |
| 13 #include <limits> |
| 14 |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "webrtc/test/random.h" |
| 17 |
| 18 using webrtc::rtcp::ReportBlock; |
| 19 |
| 20 namespace webrtc { |
| 21 namespace { |
| 22 |
| 23 const uint32_t kRemoteSsrc = 0x23456789; |
| 24 const uint8_t kFractionLost = 55; |
| 25 // Use values that are streamed differently LE and BE. |
| 26 const uint32_t kCumulativeLost = 0x111213; |
| 27 const uint32_t kExtHighestSeqNum = 0x22232425; |
| 28 const uint32_t kJitter = 0x33343536; |
| 29 const uint32_t kLastSr = 0x44454647; |
| 30 const uint32_t kDelayLastSr = 0x55565758; |
| 31 const size_t kBufferLength = ReportBlock::kLength; |
| 32 |
| 33 TEST(RtcpPacketReportBlockTest, ParseChecksLength) { |
| 34 uint8_t buffer[kBufferLength]; |
| 35 memset(buffer, 0, sizeof(buffer)); |
| 36 |
| 37 ReportBlock rb; |
| 38 EXPECT_FALSE(rb.Parse(buffer, kBufferLength - 1)); |
| 39 EXPECT_TRUE(rb.Parse(buffer, kBufferLength)); |
| 40 } |
| 41 |
| 42 TEST(RtcpPacketReportBlockTest, ParseAnyData) { |
| 43 uint8_t buffer[kBufferLength]; |
| 44 // Fill buffer with semi-random data. |
| 45 test::Random generator(testing::FLAGS_gtest_random_seed); |
| 46 for (size_t i = 0; i < kBufferLength; ++i) |
| 47 buffer[i] = static_cast<uint8_t>(generator.Rand(0, 0xff)); |
| 48 |
| 49 ReportBlock rb; |
| 50 EXPECT_TRUE(rb.Parse(buffer, kBufferLength)); |
| 51 } |
| 52 |
| 53 TEST(RtcpPacketReportBlockTest, ParseMatchCreate) { |
| 54 ReportBlock rb; |
| 55 rb.To(kRemoteSsrc); |
| 56 rb.WithFractionLost(kFractionLost); |
| 57 rb.WithCumulativeLost(kCumulativeLost); |
| 58 rb.WithExtHighestSeqNum(kExtHighestSeqNum); |
| 59 rb.WithJitter(kJitter); |
| 60 rb.WithLastSr(kLastSr); |
| 61 rb.WithDelayLastSr(kDelayLastSr); |
| 62 |
| 63 uint8_t buffer[kBufferLength]; |
| 64 rb.Create(buffer); |
| 65 |
| 66 ReportBlock parsed; |
| 67 EXPECT_TRUE(parsed.Parse(buffer, kBufferLength)); |
| 68 |
| 69 EXPECT_EQ(kRemoteSsrc, parsed.source_ssrc()); |
| 70 EXPECT_EQ(kFractionLost, parsed.fraction_lost()); |
| 71 EXPECT_EQ(kCumulativeLost, parsed.cumulative_lost()); |
| 72 EXPECT_EQ(kExtHighestSeqNum, parsed.extended_high_seq_num()); |
| 73 EXPECT_EQ(kJitter, parsed.jitter()); |
| 74 EXPECT_EQ(kLastSr, parsed.last_sr()); |
| 75 EXPECT_EQ(kDelayLastSr, parsed.delay_since_last_sr()); |
| 76 } |
| 77 |
| 78 TEST(RtcpPacketReportBlockTest, ValidateCumulativeLost) { |
| 79 const uint32_t kMaxCumulativeLost = 0xffffff; |
| 80 ReportBlock rb; |
| 81 EXPECT_FALSE(rb.WithCumulativeLost(kMaxCumulativeLost + 1)); |
| 82 EXPECT_TRUE(rb.WithCumulativeLost(kMaxCumulativeLost)); |
| 83 } |
| 84 |
| 85 } // namespace |
| 86 } // namespace webrtc |
OLD | NEW |