xref: /aosp_15_r20/external/webrtc/net/dcsctp/packet/parameter/reconfiguration_response_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/reconfiguration_response_parameter.h"
11 
12 #include <stdint.h>
13 
14 #include <type_traits>
15 #include <vector>
16 
17 #include "absl/types/optional.h"
18 #include "net/dcsctp/testing/testing_macros.h"
19 #include "rtc_base/gunit.h"
20 #include "test/gmock.h"
21 
22 namespace dcsctp {
23 namespace {
24 
TEST(ReconfigurationResponseParameterTest,SerializeAndDeserializeFirstForm)25 TEST(ReconfigurationResponseParameterTest, SerializeAndDeserializeFirstForm) {
26   ReconfigurationResponseParameter parameter(
27       ReconfigRequestSN(1),
28       ReconfigurationResponseParameter::Result::kSuccessPerformed);
29 
30   std::vector<uint8_t> serialized;
31   parameter.SerializeTo(serialized);
32 
33   ASSERT_HAS_VALUE_AND_ASSIGN(
34       ReconfigurationResponseParameter deserialized,
35       ReconfigurationResponseParameter::Parse(serialized));
36 
37   EXPECT_EQ(*deserialized.response_sequence_number(), 1u);
38   EXPECT_EQ(deserialized.result(),
39             ReconfigurationResponseParameter::Result::kSuccessPerformed);
40   EXPECT_EQ(deserialized.sender_next_tsn(), absl::nullopt);
41   EXPECT_EQ(deserialized.receiver_next_tsn(), absl::nullopt);
42 }
43 
TEST(ReconfigurationResponseParameterTest,SerializeAndDeserializeFirstFormSecondForm)44 TEST(ReconfigurationResponseParameterTest,
45      SerializeAndDeserializeFirstFormSecondForm) {
46   ReconfigurationResponseParameter parameter(
47       ReconfigRequestSN(1),
48       ReconfigurationResponseParameter::Result::kSuccessPerformed, TSN(2),
49       TSN(3));
50 
51   std::vector<uint8_t> serialized;
52   parameter.SerializeTo(serialized);
53 
54   ASSERT_HAS_VALUE_AND_ASSIGN(
55       ReconfigurationResponseParameter deserialized,
56       ReconfigurationResponseParameter::Parse(serialized));
57 
58   EXPECT_EQ(*deserialized.response_sequence_number(), 1u);
59   EXPECT_EQ(deserialized.result(),
60             ReconfigurationResponseParameter::Result::kSuccessPerformed);
61   EXPECT_TRUE(deserialized.sender_next_tsn().has_value());
62   EXPECT_EQ(**deserialized.sender_next_tsn(), 2u);
63   EXPECT_TRUE(deserialized.receiver_next_tsn().has_value());
64   EXPECT_EQ(**deserialized.receiver_next_tsn(), 3u);
65 }
66 
67 }  // namespace
68 }  // namespace dcsctp
69