Chromium Code Reviews| Index: webrtc/modules/rtp_rtcp/source/rtp_format_video_generic_unittest.cc |
| diff --git a/webrtc/modules/rtp_rtcp/source/rtp_format_video_generic_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_format_video_generic_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..129ae24d904486a11c9357c0dce4bd525c5bed5b |
| --- /dev/null |
| +++ b/webrtc/modules/rtp_rtcp/source/rtp_format_video_generic_unittest.cc |
| @@ -0,0 +1,80 @@ |
| +/* |
| + * 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 <memory> |
| +#include <vector> |
| + |
| +#include "webrtc/base/array_view.h" |
| +#include "webrtc/modules/include/module_common_types.h" |
| +#include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" |
| +#include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| +#include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h" |
| +#include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" |
| +#include "webrtc/test/gmock.h" |
| +#include "webrtc/test/gtest.h" |
| + |
| +namespace webrtc { |
| +namespace RtpFormatVideoGeneric { |
|
danilchap
2017/05/12 18:56:15
do not use this namespace
ilnik
2017/05/15 09:38:33
Done.
|
| +namespace { |
| + |
| +using ::testing::ElementsAreArray; |
| + |
| +constexpr RtpPacketToSend::ExtensionManager* kNoExtensions = nullptr; |
| +const size_t kMaxPayloadSize = 1200; |
| +// const size_t kGenericHeaderLen = 1; |
| + |
| +uint8_t test_payload_buffer[kMaxPayloadSize]; |
| + |
| +void VerifyPacketsSizes(size_t payload_length, size_t max_payload_length, |
| + size_t extensions_length, |
| + std::vector<size_t> expected_sizes) { |
|
danilchap
2017/05/12 18:56:15
Likely it is more readable when helpers do not con
ilnik
2017/05/15 09:38:33
Done.
|
| + size_t total_expected_bytes = 0; |
| + for (size_t i = 0; i < expected_sizes.size(); i++) |
| + total_expected_bytes += expected_sizes[i] - 1; |
| + RTC_CHECK_EQ(total_expected_bytes, payload_length) << "Incorrect unittest. " |
| + "Sum of packets sizes, sans 1-byte headers, should be equal to payload " |
| + "length"; |
| + RtpPacketizerGeneric packetizer(kVideoFrameKey, |
| + max_payload_length, |
| + extensions_length); |
| + size_t num_packets = |
| + packetizer.SetPayloadData(test_payload_buffer, payload_length, nullptr); |
| + ASSERT_EQ(num_packets, expected_sizes.size()); |
| + RtpPacketToSend packet(kNoExtensions); |
|
danilchap
2017/05/12 18:56:15
alternative ways are
... packet(nullptr /* extensi
ilnik
2017/05/15 09:38:33
Done.
|
| + for (size_t i = 0; i < num_packets; i++) { |
| + EXPECT_TRUE(packetizer.NextPacket(&packet)); |
| + EXPECT_EQ(packet.payload_size(), expected_sizes[i]); |
| + } |
| + EXPECT_FALSE(packetizer.NextPacket(&packet)); |
| +} |
| + |
| +} // namespace |
| + |
| + |
| +TEST(RtpPacketizerVideoGeneric, FourPackets) { |
| + VerifyPacketsSizes(12, 5, 2, {5, 5, 4, 2}); |
| +} |
| + |
| +TEST(RtpPacketizerVideoGeneric, NoExtensions) { |
| + VerifyPacketsSizes(12, 5, 0, {5, 5, 5}); |
| +} |
| + |
| +TEST(RtpPacketizerVideoGeneric, FitsInSinglePacket) { |
| + VerifyPacketsSizes(12, 16, 0, {13}); |
| +} |
| + |
| +TEST(RtpPacketizerVideoGeneric, ExtensionforsesSecondPacket) { |
| + VerifyPacketsSizes(12, 16, 4, {9, 5}); |
| +} |
| + |
| + |
| + |
| +} // namespace RtpFormatVideoGeneric |
| +} // namespace webrtc |