1 /*
2 * Copyright (c) 2021 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 #include "net/dcsctp/packet/chunk/forward_tsn_chunk.h"
11
12 #include <stdint.h>
13
14 #include <type_traits>
15 #include <vector>
16
17 #include "api/array_view.h"
18 #include "net/dcsctp/packet/chunk/forward_tsn_common.h"
19 #include "net/dcsctp/testing/testing_macros.h"
20 #include "rtc_base/gunit.h"
21 #include "test/gmock.h"
22
23 namespace dcsctp {
24 namespace {
25 using ::testing::ElementsAre;
26
TEST(ForwardTsnChunkTest,FromCapture)27 TEST(ForwardTsnChunkTest, FromCapture) {
28 /*
29 FORWARD_TSN chunk(Cumulative TSN: 1905748778)
30 Chunk type: FORWARD_TSN (192)
31 Chunk flags: 0x00
32 Chunk length: 8
33 New cumulative TSN: 1905748778
34 */
35
36 uint8_t data[] = {0xc0, 0x00, 0x00, 0x08, 0x71, 0x97, 0x6b, 0x2a};
37
38 ASSERT_HAS_VALUE_AND_ASSIGN(ForwardTsnChunk chunk,
39 ForwardTsnChunk::Parse(data));
40 EXPECT_EQ(*chunk.new_cumulative_tsn(), 1905748778u);
41 }
42
TEST(ForwardTsnChunkTest,SerializeAndDeserialize)43 TEST(ForwardTsnChunkTest, SerializeAndDeserialize) {
44 ForwardTsnChunk chunk(
45 TSN(123), {ForwardTsnChunk::SkippedStream(StreamID(1), SSN(23)),
46 ForwardTsnChunk::SkippedStream(StreamID(42), SSN(99))});
47
48 std::vector<uint8_t> serialized;
49 chunk.SerializeTo(serialized);
50
51 ASSERT_HAS_VALUE_AND_ASSIGN(ForwardTsnChunk deserialized,
52 ForwardTsnChunk::Parse(serialized));
53 EXPECT_EQ(*deserialized.new_cumulative_tsn(), 123u);
54 EXPECT_THAT(
55 deserialized.skipped_streams(),
56 ElementsAre(ForwardTsnChunk::SkippedStream(StreamID(1), SSN(23)),
57 ForwardTsnChunk::SkippedStream(StreamID(42), SSN(99))));
58
59 EXPECT_EQ(deserialized.ToString(),
60 "FORWARD-TSN, new_cumulative_tsn=123, skip 1:23, skip 42:99");
61 }
62
63 } // namespace
64 } // namespace dcsctp
65