Index: webrtc/modules/rtp_rtcp/source/sample_parser_unittest2.cc |
diff --git a/webrtc/modules/rtp_rtcp/source/sample_parser_unittest2.cc b/webrtc/modules/rtp_rtcp/source/sample_parser_unittest2.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c7f87cd6ee18facb6dd6d2c868f75ccb25dcdfb9 |
--- /dev/null |
+++ b/webrtc/modules/rtp_rtcp/source/sample_parser_unittest2.cc |
@@ -0,0 +1,78 @@ |
+/* |
+ * 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_parser2.h" |
+ |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/compound_packet.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" |
+ |
+using testing::_; |
+using testing::StrictMock; |
+using webrtc::rtcp::App; |
+using webrtc::rtcp::Bye; |
+using webrtc::rtcp::CommonHeader; |
+using webrtc::rtcp::CompoundPacket; |
+using webrtc::rtcp::Parser2; |
+using webrtc::rtcp::Pli; |
+using webrtc::rtcp::ReceiverReport; |
+ |
+namespace webrtc { |
+ |
+class MockParser2 : public Parser2 { |
+ public: |
+ MOCK_METHOD1(HandleApp, void(const App&)); |
+ MOCK_METHOD1(HandleBye, void(const Bye&)); |
+ MOCK_METHOD1(HandlePli, void(const Pli&)); |
+ MOCK_METHOD1(HandleUnknown, void(const CommonHeader&)); |
+ MOCK_METHOD0(HandleInvalid, void()); |
+}; |
+ |
+TEST(RtcpParser2, ThreePacketsAndUnknown) { |
+ CompoundPacket compound; |
+ App app; |
+ Bye bye; |
+ Pli pli; |
+ ReceiverReport report; |
+ compound.Append(&app); |
+ compound.Append(&bye); |
+ compound.Append(&pli); |
+ compound.Append(&report); |
+ auto raw = compound.Build(); |
+ |
+ StrictMock<MockParser2> parser; |
+ EXPECT_CALL(parser, HandleApp(_)).Times(1); |
+ EXPECT_CALL(parser, HandleBye(_)).Times(1); |
+ EXPECT_CALL(parser, HandlePli(_)).Times(1); |
+ EXPECT_CALL(parser, HandleUnknown(_)).Times(1); |
+ parser.Parse(raw.data(), raw.size()); |
+} |
+ |
+TEST(RtcpParser2, InvalidParseCallsHandleInvalid) { |
+ CompoundPacket compound; |
+ Bye bye; |
+ Pli pli; |
+ compound.Append(&bye); |
+ compound.Append(&pli); |
+ auto raw = compound.Build(); |
+ // Damage Bye packet: increase ssrc cound by 1. |
+ raw[0]++; |
+ |
+ StrictMock<MockParser2> parser; |
+ EXPECT_CALL(parser, HandleBye(_)).Times(0); |
+ EXPECT_CALL(parser, HandlePli(_)).Times(1); |
+ EXPECT_CALL(parser, HandleInvalid()).Times(1); |
+ parser.Parse(raw.data(), raw.size()); |
+} |
+ |
+} // namespace webrtc |