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/iforward_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(IForwardTsnChunkTest,FromCapture)27 TEST(IForwardTsnChunkTest, FromCapture) {
28 /*
29 I_FORWARD_TSN chunk(Cumulative TSN: 3094631148)
30 Chunk type: I_FORWARD_TSN (194)
31 Chunk flags: 0x00
32 Chunk length: 16
33 New cumulative TSN: 3094631148
34 Stream identifier: 1
35 Flags: 0x0000
36 Message identifier: 2
37 */
38
39 uint8_t data[] = {0xc2, 0x00, 0x00, 0x10, 0xb8, 0x74, 0x52, 0xec,
40 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02};
41
42 ASSERT_HAS_VALUE_AND_ASSIGN(IForwardTsnChunk chunk,
43 IForwardTsnChunk::Parse(data));
44 EXPECT_EQ(*chunk.new_cumulative_tsn(), 3094631148u);
45 EXPECT_THAT(chunk.skipped_streams(),
46 ElementsAre(IForwardTsnChunk::SkippedStream(
47 IsUnordered(false), StreamID(1), MID(2))));
48 }
49
TEST(IForwardTsnChunkTest,SerializeAndDeserialize)50 TEST(IForwardTsnChunkTest, SerializeAndDeserialize) {
51 IForwardTsnChunk chunk(
52 TSN(123), {IForwardTsnChunk::SkippedStream(IsUnordered(false),
53 StreamID(1), MID(23)),
54 IForwardTsnChunk::SkippedStream(IsUnordered(true),
55 StreamID(42), MID(99))});
56
57 std::vector<uint8_t> serialized;
58 chunk.SerializeTo(serialized);
59
60 ASSERT_HAS_VALUE_AND_ASSIGN(IForwardTsnChunk deserialized,
61 IForwardTsnChunk::Parse(serialized));
62 EXPECT_EQ(*deserialized.new_cumulative_tsn(), 123u);
63 EXPECT_THAT(deserialized.skipped_streams(),
64 ElementsAre(IForwardTsnChunk::SkippedStream(IsUnordered(false),
65 StreamID(1), MID(23)),
66 IForwardTsnChunk::SkippedStream(
67 IsUnordered(true), StreamID(42), MID(99))));
68
69 EXPECT_EQ(deserialized.ToString(), "I-FORWARD-TSN, new_cumulative_tsn=123");
70 }
71
72 } // namespace
73 } // namespace dcsctp
74