Index: webrtc/modules/rtp_rtcp/source/sample_parser_unittest4.cc |
diff --git a/webrtc/modules/rtp_rtcp/source/sample_parser_unittest4.cc b/webrtc/modules/rtp_rtcp/source/sample_parser_unittest4.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ff2842014dfef06443b087216c6ae65da4410248 |
--- /dev/null |
+++ b/webrtc/modules/rtp_rtcp/source/sample_parser_unittest4.cc |
@@ -0,0 +1,104 @@ |
+/* |
+ * Copyright (c) 2016 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/sample_rtcp_parser4.h" |
+ |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/compound_packet.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h" |
+ |
+namespace webrtc { |
+ |
+using ::testing::_; |
+using ::testing::StrictMock; |
+using ::webrtc::rtcp::App; |
+using ::webrtc::rtcp::Bye; |
+using ::webrtc::rtcp::CommonHeader; |
+using ::webrtc::rtcp::CompoundPacket; |
+using ::webrtc::rtcp::Nack; |
+using ::webrtc::rtcp::Parser4; |
+using ::webrtc::rtcp::Pli; |
+using ::webrtc::rtcp::Remb; |
+using ::webrtc::rtcp::ReceiverReport; |
+using ::webrtc::rtcp::Sli; |
+ |
+TEST(RtcpParser4, ThreePacketsAndUnknown) { |
+ CompoundPacket compound; |
+ App app; |
+ Bye bye; |
+ Pli pli; |
+ Sli sli; |
+ sli.WithPictureId(13); |
+ ReceiverReport report; |
+ compound.Append(&app); |
+ compound.Append(&bye); |
+ compound.Append(&pli); |
+ compound.Append(&pli); |
+ compound.Append(&report); |
+ compound.Append(&sli); |
+ auto raw = compound.Build(); |
+ |
+ size_t app_count = 0; |
+ size_t bye_count = 0; |
+ size_t pli_count = 0; |
+ size_t sli_count = 0; |
+ Parser4() |
+ .Handle<App>([&app_count](const App& app) { ++app_count; }) |
+ .Handle<Bye>([&bye_count](const Bye& bye) { ++bye_count; }) |
+ .Handle<Pli>([&pli_count](const Pli& bye) { ++pli_count; }) |
+ .Handle<Sli>([&sli_count](const Sli& bye) { ++sli_count; }) |
+ .Parse(raw); |
+ EXPECT_EQ(1u, app_count); |
+ EXPECT_EQ(1u, bye_count); |
+ EXPECT_EQ(2u, pli_count); |
+ EXPECT_EQ(1u, sli_count); |
+} |
+ |
+TEST(RtcpParser4, InvalidParseCallsHandleInvalid) { |
+ CompoundPacket compound; |
+ Bye bye; |
+ Nack nack; |
+ uint16_t nacked = 13; |
+ nack.WithList(&nacked, 1); |
+ Pli pli; |
+ Remb remb; |
+ compound.Append(&bye); |
+ compound.Append(&nack); |
+ compound.Append(&pli); |
+ compound.Append(&remb); |
+ auto raw = compound.Build(); |
+ // Damage Bye packet: increase ssrc count by 1. |
+ raw[0]++; |
+ |
+ size_t pli_count = 0; |
+ size_t nack_count = 0; |
+ size_t remb_count = 0; |
+ |
+ Parser4() |
+ .Handle<Bye>([](const Bye&) { ADD_FAILURE() << "Shouldn't parse bye"; }) |
+ .Handle<Pli>([&pli_count](const Pli&) { ++pli_count; }) |
+ .Handle<Nack>([&nack_count](const Nack&) { ++nack_count; }) |
+ .Handle<Remb>([&remb_count](const Remb&) { ++remb_count; }) |
+ .Parse(raw); |
+ EXPECT_EQ(1u, pli_count); |
+ EXPECT_EQ(1u, nack_count); |
+ EXPECT_EQ(1u, remb_count); |
+} |
+ |
+} // namespace webrtc |