1 // Copyright 2024 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14
15 #include "pw_bluetooth_proxy/internal/rfcomm_fcs.h"
16
17 #include "pw_bluetooth/emboss_util.h"
18 #include "pw_unit_test/framework.h" // IWYU pragma: keep
19
20 namespace pw::bluetooth::proxy {
21
22 namespace {
23
TEST(RfcommFcsTest,Uih)24 TEST(RfcommFcsTest, Uih) {
25 std::array<uint8_t, 2> uih{
26 0x19,
27 0xEF,
28 };
29 auto view = emboss::MakeRfcommFrameView(uih.data(), uih.size());
30 EXPECT_EQ(RfcommFcs(view), 0x55);
31 }
32
TEST(RfcommFcsTest,Sabm)33 TEST(RfcommFcsTest, Sabm) {
34 std::array<uint8_t, 3> sabm{
35 0x19,
36 0x2F,
37 0x01,
38 };
39 auto view = emboss::MakeRfcommFrameView(sabm.data(), sabm.size());
40 EXPECT_EQ(RfcommFcs(view), 0xA7);
41 }
42
TEST(RfcommFcsTest,SabmExtended)43 TEST(RfcommFcsTest, SabmExtended) {
44 std::array<uint8_t, 4> sabm_extended_length{
45 0x19,
46 0x2F,
47 0x00,
48 0x01,
49 };
50 auto view = emboss::MakeRfcommFrameView(sabm_extended_length.data(),
51 sabm_extended_length.size());
52 EXPECT_EQ(RfcommFcs(view), 0x61);
53 }
54
55 } // namespace
56
57 } // namespace pw::bluetooth::proxy
58