Index: webrtc/call/rtp_rtcp_demuxer_helper_unittest.cc |
diff --git a/webrtc/call/rtp_rtcp_demuxer_helper_unittest.cc b/webrtc/call/rtp_rtcp_demuxer_helper_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0416e68c386f824dc78746f701b202da63645250 |
--- /dev/null |
+++ b/webrtc/call/rtp_rtcp_demuxer_helper_unittest.cc |
@@ -0,0 +1,102 @@ |
+/* |
+ * Copyright (c) 2017 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 <cstdio> |
+ |
+#include "webrtc/call/rtp_rtcp_demuxer_helper.h" |
+ |
+#include "webrtc/base/arraysize.h" |
+#include "webrtc/base/buffer.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_jitter_report.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" |
+#include "webrtc/test/gtest.h" |
+ |
+namespace webrtc { |
+ |
+namespace { |
+constexpr uint32_t kSsrc = 8374; |
+} // namespace |
+ |
+TEST(RtpRtcpDemuxerHelperTest, ParseRtcpPacketSenderSsrc_CorrectOutputForBye) { |
danilchap
2017/06/19 13:31:56
CorrectOutput are probably redundant words.
ParseR
eladalon
2017/06/19 14:35:17
I'll go with ParseRtcpPacketSenderSsrc_ByePacket,
|
+ webrtc::rtcp::Bye rtcp_packet; |
+ rtcp_packet.SetSenderSsrc(kSsrc); |
+ rtc::Buffer raw_packet = rtcp_packet.Build(); |
+ |
+ rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(raw_packet); |
+ EXPECT_TRUE(ssrc); |
danilchap
2017/06/19 13:31:56
if you'll keep it, use ASSERT_TRUE
may be (to be a
eladalon
2017/06/19 14:35:17
I prefer without the .has_true(), as that's what's
danilchap
2017/06/19 16:24:54
.has_value was added only recently, that's one of
eladalon
2017/06/19 19:13:48
Acknowledged.
|
+ EXPECT_EQ(*ssrc, kSsrc); |
danilchap
2017/06/19 13:31:56
you may replace these two EXPECTs with single one:
eladalon
2017/06/19 14:35:17
1. Still need to assert before.
2. I'm used to rel
danilchap
2017/06/19 16:24:54
1. No
2. std::optional<T> allowed to be compared t
eladalon
2017/06/19 19:13:48
I see now that it prints "empty optional" when com
|
+} |
+ |
+TEST(RtpRtcpDemuxerHelperTest, ParseRtcpPacketSenderSsrc_CorrectOutputForPsfb) { |
+ webrtc::rtcp::Pli rtcp_packet; // Psfb is abstract; use a subclass. |
+ rtcp_packet.SetSenderSsrc(kSsrc); |
+ rtc::Buffer raw_packet = rtcp_packet.Build(); |
+ |
+ rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(raw_packet); |
+ EXPECT_TRUE(ssrc); |
+ EXPECT_EQ(*ssrc, kSsrc); |
+} |
+ |
+TEST(RtpRtcpDemuxerHelperTest, |
+ ParseRtcpPacketSenderSsrc_CorrectOutputForReceiverReport) { |
+ webrtc::rtcp::ReceiverReport rtcp_packet; |
+ rtcp_packet.SetSenderSsrc(kSsrc); |
+ rtc::Buffer raw_packet = rtcp_packet.Build(); |
+ |
+ rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(raw_packet); |
+ EXPECT_TRUE(ssrc); |
+ EXPECT_EQ(*ssrc, kSsrc); |
+} |
+ |
+TEST(RtpRtcpDemuxerHelperTest, |
+ ParseRtcpPacketSenderSsrc_CorrectOutputForRtpfb) { |
+ // Rtpfb is abstract; use a subclass. |
+ webrtc::rtcp::RapidResyncRequest rtcp_packet; |
+ rtcp_packet.SetSenderSsrc(kSsrc); |
+ rtc::Buffer raw_packet = rtcp_packet.Build(); |
+ |
+ rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(raw_packet); |
+ EXPECT_TRUE(ssrc); |
+ EXPECT_EQ(*ssrc, kSsrc); |
+} |
+ |
+TEST(RtpRtcpDemuxerHelperTest, |
+ ParseRtcpPacketSenderSsrc_CorrectOutputForSenderReport) { |
+ webrtc::rtcp::SenderReport rtcp_packet; |
+ rtcp_packet.SetSenderSsrc(kSsrc); |
+ rtc::Buffer raw_packet = rtcp_packet.Build(); |
+ |
+ rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(raw_packet); |
+ EXPECT_TRUE(ssrc); |
+ EXPECT_EQ(*ssrc, kSsrc); |
+} |
+ |
+TEST(RtpRtcpDemuxerHelperTest, ParseRtcpPacketSenderSsrc_BadRtcpPacket) { |
+ uint8_t garbage[100]; |
+ memset(&garbage[0], 0, arraysize(garbage)); |
+ |
+ rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(garbage); |
+ EXPECT_FALSE(ssrc); |
+} |
+ |
+TEST(RtpRtcpDemuxerHelperTest, |
+ ParseRtcpPacketSenderSsrc_RtcpMessageWithoutSenderSsrc) { |
+ webrtc::rtcp::ExtendedJitterReport rtcp_packet; // Has no sender SSRC. |
+ rtc::Buffer raw_packet = rtcp_packet.Build(); |
+ |
+ rtc::Optional<uint32_t> ssrc = ParseRtcpPacketSenderSsrc(raw_packet); |
+ EXPECT_FALSE(ssrc); |
+} |
+ |
+} // namespace webrtc |