1 /******************************************************************************
2 *
3 * Copyright 2021 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #include <gtest/gtest.h>
20
21 #include "bta/dm/bta_dm_int.h"
22 #include "stack/include/bt_hdr.h"
23 #include "types/bluetooth/uuid.h"
24
25 using bluetooth::Uuid;
26
27 class BtaCustUuid : public testing::Test {
28 protected:
SetUp()29 void SetUp() override { bta_dm_cb = {}; }
30 };
31
32 namespace {
33 uint32_t handle1 = 1;
34 uint32_t handle2 = 2;
35 static const Uuid uuid1 = Uuid::From128BitBE(
36 Uuid::UUID128Bit{{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
37 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}});
38 static const Uuid uuid2 = Uuid::From128BitBE(
39 Uuid::UUID128Bit{{0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x33,
40 0x33, 0x55, 0x55, 0x55, 0x55, 0x55, 0x59}});
41 }
42
43 // Test we can remove/add 128 bit custom UUID from/to bta_dm_cb.bta_custom_uuid
TEST_F(BtaCustUuid,test_add_remove_cust_uuid)44 TEST_F(BtaCustUuid, test_add_remove_cust_uuid) {
45 tBTA_CUSTOM_UUID& curr0 = bta_dm_cb.bta_custom_uuid[0];
46 tBTA_CUSTOM_UUID& curr1 = bta_dm_cb.bta_custom_uuid[1];
47 tBTA_CUSTOM_UUID curr0_expect = {uuid1, handle1};
48 tBTA_CUSTOM_UUID curr1_expect = {uuid2, handle2};
49 // Add first 128 bit custom UUID
50 bta_dm_eir_update_cust_uuid(curr0_expect, true);
51 ASSERT_STREQ(uuid1.ToString().c_str(), curr0.custom_uuid.ToString().c_str());
52 // Add second 128 bit custom UUID
53 bta_dm_eir_update_cust_uuid(curr1_expect, true);
54 ASSERT_STREQ(uuid2.ToString().c_str(), curr1.custom_uuid.ToString().c_str());
55
56 curr0_expect.custom_uuid.UpdateUuid(Uuid::kEmpty);
57 curr1_expect.custom_uuid.UpdateUuid(Uuid::kEmpty);
58 // Remove first 128 bit custom UUID
59 bta_dm_eir_update_cust_uuid(curr0_expect, false);
60 ASSERT_STREQ(Uuid::kEmpty.ToString().c_str(), curr0.custom_uuid.ToString().c_str());
61 // Remove second 128 bit custom UUID
62 bta_dm_eir_update_cust_uuid(curr1_expect, false);
63 ASSERT_STREQ(Uuid::kEmpty.ToString().c_str(), curr1.custom_uuid.ToString().c_str());
64 }
65