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/error_cause/protocol_violation_cause.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/error_cause/error_cause.h"
19 #include "net/dcsctp/packet/tlv_trait.h"
20 #include "net/dcsctp/testing/testing_macros.h"
21 #include "rtc_base/gunit.h"
22 #include "test/gmock.h"
23
24 namespace dcsctp {
25 namespace {
26 using ::testing::SizeIs;
27
TEST(ProtocolViolationCauseTest,EmptyReason)28 TEST(ProtocolViolationCauseTest, EmptyReason) {
29 Parameters causes =
30 Parameters::Builder().Add(ProtocolViolationCause("")).Build();
31
32 ASSERT_HAS_VALUE_AND_ASSIGN(Parameters deserialized,
33 Parameters::Parse(causes.data()));
34 ASSERT_THAT(deserialized.descriptors(), SizeIs(1));
35 EXPECT_EQ(deserialized.descriptors()[0].type, ProtocolViolationCause::kType);
36
37 ASSERT_HAS_VALUE_AND_ASSIGN(
38 ProtocolViolationCause cause,
39 ProtocolViolationCause::Parse(deserialized.descriptors()[0].data));
40
41 EXPECT_EQ(cause.additional_information(), "");
42 }
43
TEST(ProtocolViolationCauseTest,SetReason)44 TEST(ProtocolViolationCauseTest, SetReason) {
45 Parameters causes = Parameters::Builder()
46 .Add(ProtocolViolationCause("Reason goes here"))
47 .Build();
48
49 ASSERT_HAS_VALUE_AND_ASSIGN(Parameters deserialized,
50 Parameters::Parse(causes.data()));
51 ASSERT_THAT(deserialized.descriptors(), SizeIs(1));
52 EXPECT_EQ(deserialized.descriptors()[0].type, ProtocolViolationCause::kType);
53
54 ASSERT_HAS_VALUE_AND_ASSIGN(
55 ProtocolViolationCause cause,
56 ProtocolViolationCause::Parse(deserialized.descriptors()[0].data));
57
58 EXPECT_EQ(cause.additional_information(), "Reason goes here");
59 }
60 } // namespace
61 } // namespace dcsctp
62