Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet/dlrr_unittest.cc

Issue 1453973005: [rtp_rtcp] rtcp::Dlrr block moved into own file and got Parse function (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Dlrr is now movable but not copyable Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 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 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
12
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
åsapersson 2015/12/15 12:20:55 nit: new line
danilchap 2015/12/15 13:02:17 Done.
16 using webrtc::rtcp::Dlrr;
17
18 namespace webrtc {
19 namespace {
20
21 const uint32_t kSsrc = 0x12345678;
22 const uint32_t kLastRR = 0x23344556;
23 const uint32_t kDelay = 0x33343536;
24 const uint8_t kBlock[] = {0x05, 0x00, 0x00, 0x03, 0x12, 0x34, 0x56, 0x78,
25 0x23, 0x34, 0x45, 0x56, 0x33, 0x34, 0x35, 0x36};
26 const size_t kBlockLength = sizeof(kBlock);
åsapersson 2015/12/15 12:20:55 kBlockSizeBytes (as in other tests)
danilchap 2015/12/15 13:02:17 Done.
27
28 TEST(RtcpPacketDlrrTest, Empty) {
29 Dlrr dlrr;
30
31 EXPECT_EQ(0u, dlrr.BlockLength());
32 }
33
34 TEST(RtcpPacketDlrrTest, Create) {
35 Dlrr dlrr;
36 EXPECT_TRUE(dlrr.WithDlrrItem(kSsrc, kLastRR, kDelay));
37
38 ASSERT_EQ(kBlockLength, dlrr.BlockLength());
39 uint8_t buffer[kBlockLength];
40
41 dlrr.Create(buffer);
42 EXPECT_EQ(0, memcmp(buffer, kBlock, kBlockLength));
43 }
44
45 TEST(RtcpPacketDlrrTest, Parse) {
46 Dlrr dlrr;
47 uint16_t block_length = ByteReader<uint16_t>::ReadBigEndian(&kBlock[2]);
48 EXPECT_TRUE(dlrr.Parse(kBlock, block_length));
49
50 EXPECT_EQ(1u, dlrr.sub_blocks().size());
51 const Dlrr::SubBlock& block = dlrr.sub_blocks().front();
52 EXPECT_EQ(kSsrc, block.ssrc);
53 EXPECT_EQ(kLastRR, block.last_rr);
54 EXPECT_EQ(kDelay, block.delay_since_last_rr);
55 }
56
57 TEST(RtcpPacketDlrrTest, ParseFailsOnBadSize) {
58 const size_t kBigBufferSize = 0x100; // More than enough.
59 uint8_t buffer[kBigBufferSize];
60 buffer[0] = 5; // BlockType.
åsapersson 2015/12/15 12:20:55 Dlrr::kBlockType
danilchap 2015/12/15 13:02:17 Done.
61 buffer[1] = 0; // Reserved.
62 buffer[2] = 0; // Most significant size byte.
63 for (uint8_t size = 3; size < 6; ++size) {
64 buffer[3] = size;
65 Dlrr dlrr;
66 // Parse should be succesful only when size is multiple of 3.
åsapersson 2015/12/15 12:20:55 s/succesful/successful
danilchap 2015/12/15 13:02:17 Done.
67 EXPECT_EQ(size % 3 == 0, dlrr.Parse(buffer, (uint16_t)size));
åsapersson 2015/12/15 12:20:55 static_cast<uint16_t>
danilchap 2015/12/15 13:02:17 Done.
68 }
69 }
70
71 TEST(RtcpPacketDlrrTest, FailsOnTooManySubBlocks) {
72 Dlrr dlrr;
73 const size_t kSubBlockLimit = 100;
åsapersson 2015/12/15 12:20:55 Dlrr::kMaxNumberOfDlrrItems
danilchap 2015/12/15 13:02:17 Done.
74 for (size_t i = 1; i <= kSubBlockLimit; ++i) {
75 EXPECT_TRUE(dlrr.WithDlrrItem(kSsrc + i, kLastRR + i, kDelay + i));
76 }
77 EXPECT_FALSE(dlrr.WithDlrrItem(kSsrc, kLastRR, kDelay));
78 }
79
80 TEST(RtcpPacketDlrrTest, CreateAndParseMaxSize) {
åsapersson 2015/12/15 12:20:55 maybe CreateAndParseMaxSubBlocks
danilchap 2015/12/15 13:02:17 Done.
81 const size_t kSubBlockLimit = 100;
åsapersson 2015/12/15 12:20:55 Dlrr::kMaxNumberOfDlrrItems
danilchap 2015/12/15 13:02:17 Done.
82 const size_t kBufferSize = 0x1000; // More than enough.
83 uint8_t buffer[kBufferSize];
84 size_t used_buffer_size = 0;
85 { // Create.
86 Dlrr dlrr;
87 for (size_t i = 1; i <= kSubBlockLimit; ++i) {
88 EXPECT_TRUE(dlrr.WithDlrrItem(kSsrc + i, kLastRR + i, kDelay + i));
89 }
90 used_buffer_size = dlrr.BlockLength();
91 ASSERT_LE(used_buffer_size, kBufferSize);
92 dlrr.Create(buffer);
93 }
åsapersson 2015/12/15 12:20:55 {} needed? and below
danilchap 2015/12/15 13:02:17 used to show that Create and Parse parts use only
94
95 { // Parse.
96 Dlrr parsed;
97 uint16_t block_length = ByteReader<uint16_t>::ReadBigEndian(&buffer[2]);
98 EXPECT_EQ(used_buffer_size, (block_length + 1) * 4u);
99 EXPECT_TRUE(parsed.Parse(buffer, block_length));
100 EXPECT_EQ(kSubBlockLimit, parsed.sub_blocks().size());
101 }
102 }
103
104 } // namespace
105 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698