xref: /aosp_15_r20/external/webrtc/net/dcsctp/packet/parameter/parameter_test.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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/parameter/parameter.h"
11 
12 #include <cstdint>
13 #include <type_traits>
14 #include <vector>
15 
16 #include "api/array_view.h"
17 #include "net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h"
18 #include "net/dcsctp/packet/tlv_trait.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 using ::testing::SizeIs;
27 
TEST(ParameterTest,SerializeDeserializeParameter)28 TEST(ParameterTest, SerializeDeserializeParameter) {
29   Parameters parameters =
30       Parameters::Builder()
31           .Add(OutgoingSSNResetRequestParameter(ReconfigRequestSN(123),
32                                                 ReconfigRequestSN(456),
33                                                 TSN(789), {StreamID(42)}))
34           .Build();
35 
36   rtc::ArrayView<const uint8_t> serialized = parameters.data();
37 
38   ASSERT_HAS_VALUE_AND_ASSIGN(Parameters parsed, Parameters::Parse(serialized));
39   auto descriptors = parsed.descriptors();
40   ASSERT_THAT(descriptors, SizeIs(1));
41   EXPECT_THAT(descriptors[0].type, OutgoingSSNResetRequestParameter::kType);
42 
43   ASSERT_HAS_VALUE_AND_ASSIGN(
44       OutgoingSSNResetRequestParameter parsed_param,
45       OutgoingSSNResetRequestParameter::Parse(descriptors[0].data));
46   EXPECT_EQ(*parsed_param.request_sequence_number(), 123u);
47   EXPECT_EQ(*parsed_param.response_sequence_number(), 456u);
48   EXPECT_EQ(*parsed_param.sender_last_assigned_tsn(), 789u);
49   EXPECT_THAT(parsed_param.stream_ids(), ElementsAre(StreamID(42)));
50 }
51 
52 }  // namespace
53 }  // namespace dcsctp
54