OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 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 |
| 12 #include "webrtc/modules/rtp_rtcp/source/sample_rtcp_parser4.h" |
| 13 |
| 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h" |
| 18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" |
| 19 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/compound_packet.h" |
| 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h" |
| 21 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h" |
| 22 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h" |
| 23 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" |
| 24 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h" |
| 25 |
| 26 namespace webrtc { |
| 27 |
| 28 using ::testing::_; |
| 29 using ::testing::StrictMock; |
| 30 using ::webrtc::rtcp::App; |
| 31 using ::webrtc::rtcp::Bye; |
| 32 using ::webrtc::rtcp::CommonHeader; |
| 33 using ::webrtc::rtcp::CompoundPacket; |
| 34 using ::webrtc::rtcp::Nack; |
| 35 using ::webrtc::rtcp::Parser4; |
| 36 using ::webrtc::rtcp::Pli; |
| 37 using ::webrtc::rtcp::Remb; |
| 38 using ::webrtc::rtcp::ReceiverReport; |
| 39 using ::webrtc::rtcp::Sli; |
| 40 |
| 41 TEST(RtcpParser4, ThreePacketsAndUnknown) { |
| 42 CompoundPacket compound; |
| 43 App app; |
| 44 Bye bye; |
| 45 Pli pli; |
| 46 Sli sli; |
| 47 sli.WithPictureId(13); |
| 48 ReceiverReport report; |
| 49 compound.Append(&app); |
| 50 compound.Append(&bye); |
| 51 compound.Append(&pli); |
| 52 compound.Append(&pli); |
| 53 compound.Append(&report); |
| 54 compound.Append(&sli); |
| 55 auto raw = compound.Build(); |
| 56 |
| 57 size_t app_count = 0; |
| 58 size_t bye_count = 0; |
| 59 size_t pli_count = 0; |
| 60 size_t sli_count = 0; |
| 61 Parser4() |
| 62 .Handle<App>([&app_count](const App& app) { ++app_count; }) |
| 63 .Handle<Bye>([&bye_count](const Bye& bye) { ++bye_count; }) |
| 64 .Handle<Pli>([&pli_count](const Pli& bye) { ++pli_count; }) |
| 65 .Handle<Sli>([&sli_count](const Sli& bye) { ++sli_count; }) |
| 66 .Parse(raw); |
| 67 EXPECT_EQ(1u, app_count); |
| 68 EXPECT_EQ(1u, bye_count); |
| 69 EXPECT_EQ(2u, pli_count); |
| 70 EXPECT_EQ(1u, sli_count); |
| 71 } |
| 72 |
| 73 TEST(RtcpParser4, InvalidParseCallsHandleInvalid) { |
| 74 CompoundPacket compound; |
| 75 Bye bye; |
| 76 Nack nack; |
| 77 uint16_t nacked = 13; |
| 78 nack.WithList(&nacked, 1); |
| 79 Pli pli; |
| 80 Remb remb; |
| 81 compound.Append(&bye); |
| 82 compound.Append(&nack); |
| 83 compound.Append(&pli); |
| 84 compound.Append(&remb); |
| 85 auto raw = compound.Build(); |
| 86 // Damage Bye packet: increase ssrc count by 1. |
| 87 raw[0]++; |
| 88 |
| 89 size_t pli_count = 0; |
| 90 size_t nack_count = 0; |
| 91 size_t remb_count = 0; |
| 92 |
| 93 Parser4() |
| 94 .Handle<Bye>([](const Bye&) { ADD_FAILURE() << "Shouldn't parse bye"; }) |
| 95 .Handle<Pli>([&pli_count](const Pli&) { ++pli_count; }) |
| 96 .Handle<Nack>([&nack_count](const Nack&) { ++nack_count; }) |
| 97 .Handle<Remb>([&remb_count](const Remb&) { ++remb_count; }) |
| 98 .Parse(raw); |
| 99 EXPECT_EQ(1u, pli_count); |
| 100 EXPECT_EQ(1u, nack_count); |
| 101 EXPECT_EQ(1u, remb_count); |
| 102 } |
| 103 |
| 104 } // namespace webrtc |
OLD | NEW |