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 "bta/test/bta_test_fixtures.h"
23 #include "types/bluetooth/uuid.h"
24 
25 using bluetooth::Uuid;
26 
27 namespace {
28   uint32_t handle1 = 1;
29   uint32_t handle2 = 2;
30   static const Uuid uuid1 = Uuid::From128BitBE(
31     Uuid::UUID128Bit{{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
32                       0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}});
33   static const Uuid uuid2 = Uuid::From128BitBE(
34     Uuid::UUID128Bit{{0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x33,
35                       0x33, 0x55, 0x55, 0x55, 0x55, 0x55, 0x59}});
36 }
37 
38 // Test we can remove/add 128 bit custom UUID from/to bta_dm_cb.bta_custom_uuid
TEST_F(BtaWithMocksTest,test_add_remove_cust_uuid)39 TEST_F(BtaWithMocksTest, test_add_remove_cust_uuid) {
40   tBTA_CUSTOM_UUID& curr0 = bta_dm_cb.bta_custom_uuid[0];
41   tBTA_CUSTOM_UUID& curr1 = bta_dm_cb.bta_custom_uuid[1];
42   tBTA_CUSTOM_UUID curr0_expect = {uuid1, handle1};
43   tBTA_CUSTOM_UUID curr1_expect = {uuid2, handle2};
44   // Add first 128 bit custom UUID
45   bta_dm_eir_update_cust_uuid(curr0_expect, true);
46   ASSERT_STREQ(uuid1.ToString().c_str(), curr0.custom_uuid.ToString().c_str());
47   // Add second 128 bit custom UUID
48   bta_dm_eir_update_cust_uuid(curr1_expect, true);
49   ASSERT_STREQ(uuid2.ToString().c_str(), curr1.custom_uuid.ToString().c_str());
50 
51   curr0_expect.custom_uuid.UpdateUuid(Uuid::kEmpty);
52   curr1_expect.custom_uuid.UpdateUuid(Uuid::kEmpty);
53   // Remove first 128 bit custom UUID
54   bta_dm_eir_update_cust_uuid(curr0_expect, false);
55   ASSERT_STREQ(Uuid::kEmpty.ToString().c_str(), curr0.custom_uuid.ToString().c_str());
56   // Remove second 128 bit custom UUID
57   bta_dm_eir_update_cust_uuid(curr1_expect, false);
58   ASSERT_STREQ(Uuid::kEmpty.ToString().c_str(), curr1.custom_uuid.ToString().c_str());
59 }
60