xref: /aosp_15_r20/external/webrtc/net/dcsctp/packet/chunk/cookie_ack_chunk_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/chunk/cookie_ack_chunk.h"
11 
12 #include <stdint.h>
13 
14 #include <type_traits>
15 #include <vector>
16 
17 #include "net/dcsctp/testing/testing_macros.h"
18 #include "rtc_base/gunit.h"
19 #include "test/gmock.h"
20 
21 namespace dcsctp {
22 namespace {
23 
TEST(CookieAckChunkTest,FromCapture)24 TEST(CookieAckChunkTest, FromCapture) {
25   /*
26   COOKIE_ACK chunk
27       Chunk type: COOKIE_ACK (11)
28       Chunk flags: 0x00
29       Chunk length: 4
30   */
31 
32   uint8_t data[] = {0x0b, 0x00, 0x00, 0x04};
33 
34   EXPECT_TRUE(CookieAckChunk::Parse(data).has_value());
35 }
36 
TEST(CookieAckChunkTest,SerializeAndDeserialize)37 TEST(CookieAckChunkTest, SerializeAndDeserialize) {
38   CookieAckChunk chunk;
39 
40   std::vector<uint8_t> serialized;
41   chunk.SerializeTo(serialized);
42 
43   ASSERT_HAS_VALUE_AND_ASSIGN(CookieAckChunk deserialized,
44                               CookieAckChunk::Parse(serialized));
45   EXPECT_EQ(deserialized.ToString(), "COOKIE-ACK");
46 }
47 
48 }  // namespace
49 }  // namespace dcsctp
50