OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.h" |
12 | 12 |
13 #include <limits> | 13 #include <limits> |
14 | 14 |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webrtc/test/random.h" | 16 #include "webrtc/base/random.h" |
17 | 17 |
18 using webrtc::rtcp::ReportBlock; | 18 using webrtc::rtcp::ReportBlock; |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 namespace { | 21 namespace { |
22 | 22 |
23 const uint32_t kRemoteSsrc = 0x23456789; | 23 const uint32_t kRemoteSsrc = 0x23456789; |
24 const uint8_t kFractionLost = 55; | 24 const uint8_t kFractionLost = 55; |
25 // Use values that are streamed differently LE and BE. | 25 // Use values that are streamed differently LE and BE. |
26 const uint32_t kCumulativeLost = 0x111213; | 26 const uint32_t kCumulativeLost = 0x111213; |
27 const uint32_t kExtHighestSeqNum = 0x22232425; | 27 const uint32_t kExtHighestSeqNum = 0x22232425; |
28 const uint32_t kJitter = 0x33343536; | 28 const uint32_t kJitter = 0x33343536; |
29 const uint32_t kLastSr = 0x44454647; | 29 const uint32_t kLastSr = 0x44454647; |
30 const uint32_t kDelayLastSr = 0x55565758; | 30 const uint32_t kDelayLastSr = 0x55565758; |
31 const size_t kBufferLength = ReportBlock::kLength; | 31 const size_t kBufferLength = ReportBlock::kLength; |
32 | 32 |
33 TEST(RtcpPacketReportBlockTest, ParseChecksLength) { | 33 TEST(RtcpPacketReportBlockTest, ParseChecksLength) { |
34 uint8_t buffer[kBufferLength]; | 34 uint8_t buffer[kBufferLength]; |
35 memset(buffer, 0, sizeof(buffer)); | 35 memset(buffer, 0, sizeof(buffer)); |
36 | 36 |
37 ReportBlock rb; | 37 ReportBlock rb; |
38 EXPECT_FALSE(rb.Parse(buffer, kBufferLength - 1)); | 38 EXPECT_FALSE(rb.Parse(buffer, kBufferLength - 1)); |
39 EXPECT_TRUE(rb.Parse(buffer, kBufferLength)); | 39 EXPECT_TRUE(rb.Parse(buffer, kBufferLength)); |
40 } | 40 } |
41 | 41 |
42 TEST(RtcpPacketReportBlockTest, ParseAnyData) { | 42 TEST(RtcpPacketReportBlockTest, ParseAnyData) { |
43 uint8_t buffer[kBufferLength]; | 43 uint8_t buffer[kBufferLength]; |
44 // Fill buffer with semi-random data. | 44 // Fill buffer with semi-random data. |
45 test::Random generator(testing::FLAGS_gtest_random_seed); | 45 Random generator(0x256F8A285EC829ull); |
46 for (size_t i = 0; i < kBufferLength; ++i) | 46 for (size_t i = 0; i < kBufferLength; ++i) |
47 buffer[i] = static_cast<uint8_t>(generator.Rand(0, 0xff)); | 47 buffer[i] = static_cast<uint8_t>(generator.Rand(0, 0xff)); |
48 | 48 |
49 ReportBlock rb; | 49 ReportBlock rb; |
50 EXPECT_TRUE(rb.Parse(buffer, kBufferLength)); | 50 EXPECT_TRUE(rb.Parse(buffer, kBufferLength)); |
51 } | 51 } |
52 | 52 |
53 TEST(RtcpPacketReportBlockTest, ParseMatchCreate) { | 53 TEST(RtcpPacketReportBlockTest, ParseMatchCreate) { |
54 ReportBlock rb; | 54 ReportBlock rb; |
55 rb.To(kRemoteSsrc); | 55 rb.To(kRemoteSsrc); |
(...skipping 21 matching lines...) Expand all Loading... |
77 | 77 |
78 TEST(RtcpPacketReportBlockTest, ValidateCumulativeLost) { | 78 TEST(RtcpPacketReportBlockTest, ValidateCumulativeLost) { |
79 const uint32_t kMaxCumulativeLost = 0xffffff; | 79 const uint32_t kMaxCumulativeLost = 0xffffff; |
80 ReportBlock rb; | 80 ReportBlock rb; |
81 EXPECT_FALSE(rb.WithCumulativeLost(kMaxCumulativeLost + 1)); | 81 EXPECT_FALSE(rb.WithCumulativeLost(kMaxCumulativeLost + 1)); |
82 EXPECT_TRUE(rb.WithCumulativeLost(kMaxCumulativeLost)); | 82 EXPECT_TRUE(rb.WithCumulativeLost(kMaxCumulativeLost)); |
83 } | 83 } |
84 | 84 |
85 } // namespace | 85 } // namespace |
86 } // namespace webrtc | 86 } // namespace webrtc |
OLD | NEW |