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 "types/bluetooth/uuid.h"
23
24 using bluetooth::Uuid;
25
26 // NOTE:
27 // Local re-implementation of functions to avoid testing of
28 // unrelated functions/features.
BTM_ReadLocalDeviceName(char ** p_name)29 tBTM_STATUS BTM_ReadLocalDeviceName(char** p_name) { return BTM_SUCCESS; }
BTM_GetEirSupportedServices(uint32_t * p_eir_uuid,uint8_t ** p,uint8_t max_num_uuid16,uint8_t * p_num_uuid16)30 uint8_t BTM_GetEirSupportedServices(uint32_t* p_eir_uuid, uint8_t** p,
31 uint8_t max_num_uuid16,
32 uint8_t* p_num_uuid16) {
33 return BT_EIR_FLAGS_TYPE;
34 }
BTM_WriteEIR(BT_HDR * p_buff)35 tBTM_STATUS BTM_WriteEIR(BT_HDR* p_buff) { return BTM_SUCCESS; }
36
37 class BtaCustUuid : public testing::Test {
38 protected:
SetUp()39 void SetUp() override {
40 memset(&bta_dm_cb, 0, sizeof(bta_dm_cb));
41 }
42 };
43
44 namespace {
45 uint32_t handle1 = 1;
46 uint32_t handle2 = 2;
47 static const Uuid uuid1 = Uuid::From128BitBE(
48 Uuid::UUID128Bit{{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
49 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}});
50 static const Uuid uuid2 = Uuid::From128BitBE(
51 Uuid::UUID128Bit{{0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x33,
52 0x33, 0x55, 0x55, 0x55, 0x55, 0x55, 0x59}});
53 }
54
55 // 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)56 TEST_F(BtaCustUuid, test_add_remove_cust_uuid) {
57 tBTA_CUSTOM_UUID& curr0 = bta_dm_cb.bta_custom_uuid[0];
58 tBTA_CUSTOM_UUID& curr1 = bta_dm_cb.bta_custom_uuid[1];
59 tBTA_CUSTOM_UUID curr0_expect = {uuid1, handle1};
60 tBTA_CUSTOM_UUID curr1_expect = {uuid2, handle2};
61 // Add first 128 bit custom UUID
62 bta_dm_eir_update_cust_uuid(curr0_expect, true);
63 ASSERT_STREQ(uuid1.ToString().c_str(), curr0.custom_uuid.ToString().c_str());
64 // Add second 128 bit custom UUID
65 bta_dm_eir_update_cust_uuid(curr1_expect, true);
66 ASSERT_STREQ(uuid2.ToString().c_str(), curr1.custom_uuid.ToString().c_str());
67
68 curr0_expect.custom_uuid.UpdateUuid(Uuid::kEmpty);
69 curr1_expect.custom_uuid.UpdateUuid(Uuid::kEmpty);
70 // Remove first 128 bit custom UUID
71 bta_dm_eir_update_cust_uuid(curr0_expect, false);
72 ASSERT_STREQ(Uuid::kEmpty.ToString().c_str(), curr0.custom_uuid.ToString().c_str());
73 // Remove second 128 bit custom UUID
74 bta_dm_eir_update_cust_uuid(curr1_expect, false);
75 ASSERT_STREQ(Uuid::kEmpty.ToString().c_str(), curr1.custom_uuid.ToString().c_str());
76 }
77