Chromium Code Reviews| 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 kCumulativeLostValid = 0x111213; | |
| 27 const uint32_t kCumulativeLostInvalid = 0x1000000; | |
| 28 const uint32_t kExtHighestSeqNum = 0x22232425; | |
| 29 const uint32_t kJitter = 0x33343536; | |
| 30 const uint32_t kLastSr = 0x44454647; | |
| 31 const uint32_t kDelayLastSr = 0x55565758; | |
| 32 const size_t kBufferLength = ReportBlock::kLength; | |
| 33 | |
| 34 TEST(RtcpPacketTest, ReportBlock_InvalidParse) { | |
|
åsapersson
2015/11/12 14:26:25
maybe rename RtcpPacketTest to RtcpPacketReportBlo
danilchap
2015/11/12 15:30:46
Done.
| |
| 35 uint8_t buffer[kBufferLength]; | |
| 36 // Fill buffer with semi-random data. | |
| 37 test::Random generator(testing::FLAGS_gtest_random_seed); | |
| 38 for (size_t i = 0; i < kBufferLength; ++i) | |
| 39 buffer[i] = static_cast<uint8_t>(generator.Rand(0, 0xff)); | |
| 40 | |
| 41 ReportBlock rb; | |
| 42 EXPECT_FALSE(rb.Parse(nullptr, kBufferLength)); | |
| 43 EXPECT_FALSE(rb.Parse(buffer, kBufferLength - 1)); | |
| 44 // Any data is valid for parsing, as long as there is some. | |
|
åsapersson
2015/11/12 14:26:25
Maybe move to separate test or rename test.
danilchap
2015/11/12 15:30:46
Done, other tests are also renamed to better match
| |
| 45 EXPECT_TRUE(rb.Parse(buffer, kBufferLength)); | |
| 46 } | |
| 47 | |
| 48 TEST(RtcpPacketTest, ReportBlock_Valid) { | |
| 49 ReportBlock rb; | |
| 50 rb.To(kRemoteSsrc); | |
| 51 rb.WithFractionLost(kFractionLost); | |
| 52 rb.WithCumulativeLost(kCumulativeLostValid); | |
| 53 rb.WithExtHighestSeqNum(kExtHighestSeqNum); | |
| 54 rb.WithJitter(kJitter); | |
| 55 rb.WithLastSr(kLastSr); | |
| 56 rb.WithDelayLastSr(kDelayLastSr); | |
| 57 | |
| 58 uint8_t buffer[kBufferLength]; | |
| 59 EXPECT_EQ(kBufferLength, rb.Create(buffer)); | |
| 60 | |
| 61 ReportBlock parsed; | |
| 62 EXPECT_TRUE(parsed.Parse(buffer, kBufferLength)); | |
| 63 | |
| 64 EXPECT_EQ(kRemoteSsrc, parsed.source_ssrc()); | |
| 65 EXPECT_EQ(kFractionLost, parsed.fraction_lost()); | |
| 66 EXPECT_EQ(kCumulativeLostValid, parsed.cumulative_lost()); | |
| 67 EXPECT_EQ(kExtHighestSeqNum, parsed.extended_high_seq_num()); | |
| 68 EXPECT_EQ(kJitter, parsed.jitter()); | |
| 69 EXPECT_EQ(kLastSr, parsed.last_sr()); | |
| 70 EXPECT_EQ(kDelayLastSr, parsed.delay_since_last_sr()); | |
| 71 } | |
| 72 | |
| 73 TEST(RtcpPacketTest, ReportBlock_InvalidData) { | |
| 74 ReportBlock rb; | |
| 75 rb.To(kRemoteSsrc); | |
| 76 rb.WithFractionLost(kFractionLost); | |
| 77 rb.WithCumulativeLost(kCumulativeLostInvalid); | |
| 78 rb.WithExtHighestSeqNum(kExtHighestSeqNum); | |
| 79 rb.WithJitter(kJitter); | |
| 80 rb.WithLastSr(kLastSr); | |
| 81 rb.WithDelayLastSr(kDelayLastSr); | |
| 82 | |
| 83 uint8_t buffer[kBufferLength]; | |
| 84 | |
| 85 EXPECT_EQ(0u, rb.Create(buffer)); | |
| 86 } | |
| 87 | |
| 88 } // namespace | |
| 89 } // namespace webrtc | |
| OLD | NEW |