xref: /aosp_15_r20/external/pigweed/pw_bluetooth_sapphire/host/l2cap/channel_test.cc (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2023 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_sapphire/internal/host/l2cap/channel.h"
16 
17 #include "pw_bluetooth_sapphire/internal/host/l2cap/fake_channel.h"
18 #include "pw_unit_test/framework.h"
19 
20 namespace bt::l2cap::testing {
21 
TEST(ChannelTest,UniqueId)22 TEST(ChannelTest, UniqueId) {
23   // Same handle + Same local id = Same unique id
24   auto channel = std::make_unique<FakeChannel>(
25       /*id=*/1, /*remote_id=*/1, /*handle=*/1, bt::LinkType::kACL);
26   auto chan_diff_remote = std::make_unique<FakeChannel>(
27       /*id=*/1, /*remote_id=*/2, /*handle=*/1, bt::LinkType::kACL);
28   ASSERT_EQ(channel->unique_id(), chan_diff_remote->unique_id());
29 
30   // Same handle + Different local id = Different unique id
31   auto chan_diff_local = std::make_unique<FakeChannel>(
32       /*id=*/2, /*remote_id=*/1, /*handle=*/1, bt::LinkType::kACL);
33   ASSERT_NE(channel->unique_id(), chan_diff_local->unique_id());
34 
35   // Same handle + Same local id = Same unique id
36   auto chan_same = std::make_unique<FakeChannel>(
37       /*id=*/1, /*remote_id=*/1, /*handle=*/1, bt::LinkType::kACL);
38   ASSERT_EQ(channel->unique_id(), chan_same->unique_id());
39 
40   // Different handle + Same local id = Different unique id
41   auto chan_diff_conn = std::make_unique<FakeChannel>(
42       /*id=*/1, /*remote_id=*/1, /*handle=*/2, bt::LinkType::kACL);
43   ASSERT_NE(channel->unique_id(), chan_diff_conn->unique_id());
44 
45   // Different handle + Different local id = Different unique id
46   auto chan_diff = std::make_unique<FakeChannel>(
47       /*id=*/1, /*remote_id=*/2, /*handle=*/2, bt::LinkType::kACL);
48   ASSERT_NE(channel->unique_id(), chan_diff->unique_id());
49 }
50 
51 }  // namespace bt::l2cap::testing
52