• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "emboss_util.h"
16 
17 #include "pw_bluetooth/hci_test.emb.h"
18 #include "pw_unit_test/framework.h"  // IWYU pragma: keep
19 
20 namespace pw::bluetooth::proxy {
21 namespace {
22 
TEST(EmbossUtilTest,CreateH4Subspan)23 TEST(EmbossUtilTest, CreateH4Subspan) {
24   std::array<uint8_t, 4> buffer = {0x00, 0x01, 0x02, 0x03};
25   auto span = H4HciSubspan(buffer);
26   EXPECT_EQ(span.front(), buffer[1]);
27   EXPECT_EQ(span.back(), buffer[3]);
28   EXPECT_EQ(span.size(), buffer.size() - 1);
29 }
30 
TEST(EmbossUtilTest,MakeViewFromSpan)31 TEST(EmbossUtilTest, MakeViewFromSpan) {
32   std::array<uint8_t, 4> buffer = {0x00, 0x01, 0x02, 0x03};
33   auto span = pw::span(buffer);
34   auto view = MakeEmboss<emboss::TestCommandPacketView>(span);
35   EXPECT_TRUE(view.IsComplete());
36   EXPECT_EQ(view.payload().Read(), 0x03);
37 }
38 
TEST(EmbossUtilTest,MakeWriterFromSpan)39 TEST(EmbossUtilTest, MakeWriterFromSpan) {
40   std::array<uint8_t, 4> buffer = {0x00, 0x01, 0x02, 0x03};
41   auto span = pw::span(buffer);
42   auto view = MakeEmboss<emboss::TestCommandPacketWriter>(span);
43   EXPECT_TRUE(view.IsComplete());
44   EXPECT_EQ(view.payload().Read(), 0x03);
45 }
46 
TEST(EmbossUtilTest,MakeViewFromSubspan)47 TEST(EmbossUtilTest, MakeViewFromSubspan) {
48   std::array<uint8_t, 5> buffer = {0x00, 0x01, 0x02, 0x03, 0x04};
49   auto view = MakeEmboss<emboss::TestCommandPacketView>(H4HciSubspan(buffer));
50   EXPECT_TRUE(view.IsComplete());
51   EXPECT_EQ(view.payload().Read(), 0x04);
52 }
53 
TEST(EmbossUtilTest,MakeWriterFromSubspan)54 TEST(EmbossUtilTest, MakeWriterFromSubspan) {
55   std::array<uint8_t, 5> buffer = {0x00, 0x01, 0x02, 0x03, 0x04};
56   auto view = MakeEmboss<emboss::TestCommandPacketWriter>(H4HciSubspan(buffer));
57   EXPECT_TRUE(view.IsComplete());
58   EXPECT_EQ(view.payload().Read(), 0x04);
59 }
60 
61 }  // namespace
62 }  // namespace pw::bluetooth::proxy
63