Index: webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block_unittest.cc |
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b97592d15726d178a47440cf5fd26bb7c432f95e |
--- /dev/null |
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block_unittest.cc |
@@ -0,0 +1,89 @@ |
+/* |
+ * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.h" |
+ |
+#include <limits> |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "webrtc/test/random.h" |
+ |
+using webrtc::rtcp::ReportBlock; |
+ |
+namespace webrtc { |
+namespace { |
+ |
+const uint32_t kRemoteSsrc = 0x23456789; |
+const uint8_t kFractionLost = 55; |
+// Use values that are streamed differently LE and BE. |
+const uint32_t kCumulativeLostValid = 0x111213; |
+const uint32_t kCumulativeLostInvalid = 0x1000000; |
+const uint32_t kExtHighestSeqNum = 0x22232425; |
+const uint32_t kJitter = 0x33343536; |
+const uint32_t kLastSr = 0x44454647; |
+const uint32_t kDelayLastSr = 0x55565758; |
+const size_t kBufferLength = ReportBlock::kLength; |
+ |
+TEST(RtcpPacketTest, ReportBlock_InvalidParse) { |
åsapersson
2015/11/12 14:26:25
maybe rename RtcpPacketTest to RtcpPacketReportBlo
danilchap
2015/11/12 15:30:46
Done.
|
+ uint8_t buffer[kBufferLength]; |
+ // Fill buffer with semi-random data. |
+ test::Random generator(testing::FLAGS_gtest_random_seed); |
+ for (size_t i = 0; i < kBufferLength; ++i) |
+ buffer[i] = static_cast<uint8_t>(generator.Rand(0, 0xff)); |
+ |
+ ReportBlock rb; |
+ EXPECT_FALSE(rb.Parse(nullptr, kBufferLength)); |
+ EXPECT_FALSE(rb.Parse(buffer, kBufferLength - 1)); |
+ // 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
|
+ EXPECT_TRUE(rb.Parse(buffer, kBufferLength)); |
+} |
+ |
+TEST(RtcpPacketTest, ReportBlock_Valid) { |
+ ReportBlock rb; |
+ rb.To(kRemoteSsrc); |
+ rb.WithFractionLost(kFractionLost); |
+ rb.WithCumulativeLost(kCumulativeLostValid); |
+ rb.WithExtHighestSeqNum(kExtHighestSeqNum); |
+ rb.WithJitter(kJitter); |
+ rb.WithLastSr(kLastSr); |
+ rb.WithDelayLastSr(kDelayLastSr); |
+ |
+ uint8_t buffer[kBufferLength]; |
+ EXPECT_EQ(kBufferLength, rb.Create(buffer)); |
+ |
+ ReportBlock parsed; |
+ EXPECT_TRUE(parsed.Parse(buffer, kBufferLength)); |
+ |
+ EXPECT_EQ(kRemoteSsrc, parsed.source_ssrc()); |
+ EXPECT_EQ(kFractionLost, parsed.fraction_lost()); |
+ EXPECT_EQ(kCumulativeLostValid, parsed.cumulative_lost()); |
+ EXPECT_EQ(kExtHighestSeqNum, parsed.extended_high_seq_num()); |
+ EXPECT_EQ(kJitter, parsed.jitter()); |
+ EXPECT_EQ(kLastSr, parsed.last_sr()); |
+ EXPECT_EQ(kDelayLastSr, parsed.delay_since_last_sr()); |
+} |
+ |
+TEST(RtcpPacketTest, ReportBlock_InvalidData) { |
+ ReportBlock rb; |
+ rb.To(kRemoteSsrc); |
+ rb.WithFractionLost(kFractionLost); |
+ rb.WithCumulativeLost(kCumulativeLostInvalid); |
+ rb.WithExtHighestSeqNum(kExtHighestSeqNum); |
+ rb.WithJitter(kJitter); |
+ rb.WithLastSr(kLastSr); |
+ rb.WithDelayLastSr(kDelayLastSr); |
+ |
+ uint8_t buffer[kBufferLength]; |
+ |
+ EXPECT_EQ(0u, rb.Create(buffer)); |
+} |
+ |
+} // namespace |
+} // namespace webrtc |