• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "bta/sdp/bta_sdp_act.cc"
21 #include "stack/sdp/sdp_api.cc"
22 
23 namespace {
24 const RawAddress bdaddr({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
25 }  // namespace
26 
27 extern tBTA_SDP_CB bta_sdp_cb;
28 extern tBTA_SDP_CFG* p_bta_sdp_cfg;
29 
30 static tSDP_DISC_ATTR g_attr_service_class_id_list;
31 static tSDP_DISC_ATTR g_sub_attr;
32 static tSDP_DISC_ATTR g_attr_spec_id;
33 static tSDP_DISC_ATTR g_attr_vendor_id;
34 static tSDP_DISC_ATTR g_attr_vendor_id_src;
35 static tSDP_DISC_ATTR g_attr_vendor_product_id;
36 static tSDP_DISC_ATTR g_attr_vendor_product_version;
37 static tSDP_DISC_ATTR g_attr_vendor_product_primary_record;
38 static tSDP_DISC_REC g_rec;
39 
sdpu_compare_uuid_with_attr(const Uuid & uuid,tSDP_DISC_ATTR * p_attr)40 bool sdpu_compare_uuid_with_attr(const Uuid& uuid, tSDP_DISC_ATTR* p_attr) {
41   return true;
42 }
43 
sdp_dm_cback(tBTA_SDP_EVT event,tBTA_SDP * p_data,void * user_data)44 static void sdp_dm_cback(tBTA_SDP_EVT event, tBTA_SDP* p_data,
45                          void* user_data) {
46   return;
47 }
48 
49 class BtaDipTest : public ::testing::Test {
50  protected:
SetUp()51   void SetUp() override {
52     g_attr_service_class_id_list.p_next_attr = &g_attr_spec_id;
53     g_attr_service_class_id_list.attr_id = ATTR_ID_SERVICE_CLASS_ID_LIST;
54     g_attr_service_class_id_list.attr_len_type = (DATA_ELE_SEQ_DESC_TYPE<<12)|2;
55     g_attr_service_class_id_list.attr_value.v.p_sub_attr = &g_sub_attr;
56     g_sub_attr.attr_len_type = (UUID_DESC_TYPE<<12)|2;
57     g_sub_attr.attr_value.v.u16 = 0x1200;
58 
59     g_attr_spec_id.p_next_attr = &g_attr_vendor_id;
60     g_attr_spec_id.attr_id = ATTR_ID_SPECIFICATION_ID;
61     g_attr_spec_id.attr_len_type = (UINT_DESC_TYPE<<12)|2;
62     g_attr_spec_id.attr_value.v.u16 = 0x0103;
63 
64     g_attr_vendor_id.p_next_attr = &g_attr_vendor_id_src;
65     g_attr_vendor_id.attr_id = ATTR_ID_VENDOR_ID;
66     g_attr_vendor_id.attr_len_type = (UINT_DESC_TYPE<<12)|2;
67     g_attr_vendor_id.attr_value.v.u16 = 0x18d1;
68 
69     // Allocation should succeed
70     g_attr_vendor_id_src.p_next_attr = &g_attr_vendor_product_id;
71     g_attr_vendor_id_src.attr_id = ATTR_ID_VENDOR_ID_SOURCE;
72     g_attr_vendor_id_src.attr_len_type = (UINT_DESC_TYPE<<12)|2;
73     g_attr_vendor_id_src.attr_value.v.u16 = 1;
74 
75     g_attr_vendor_product_id.p_next_attr = &g_attr_vendor_product_version;
76     g_attr_vendor_product_id.attr_id = ATTR_ID_PRODUCT_ID;
77     g_attr_vendor_product_id.attr_len_type = (UINT_DESC_TYPE<<12)|2;
78     g_attr_vendor_product_id.attr_value.v.u16 = 0x1234;
79 
80     g_attr_vendor_product_version.p_next_attr = &g_attr_vendor_product_primary_record;
81     g_attr_vendor_product_version.attr_id = ATTR_ID_PRODUCT_VERSION;
82     g_attr_vendor_product_version.attr_len_type = (UINT_DESC_TYPE<<12)|2;
83     g_attr_vendor_product_version.attr_value.v.u16 = 0x0100;
84 
85     g_attr_vendor_product_primary_record.p_next_attr = &g_attr_vendor_product_primary_record;
86     g_attr_vendor_product_primary_record.attr_id = ATTR_ID_PRIMARY_RECORD;
87     g_attr_vendor_product_primary_record.attr_len_type = (BOOLEAN_DESC_TYPE<<12);
88     g_attr_vendor_product_primary_record.attr_value.v.u8 = 1;
89 
90     g_rec.p_first_attr = &g_attr_service_class_id_list;
91     g_rec.p_next_rec = nullptr;
92     g_rec.remote_bd_addr = bdaddr;
93     g_rec.time_read = 0;
94 
95     bta_sdp_cb.p_dm_cback = sdp_dm_cback;
96     bta_sdp_cb.remote_addr = bdaddr;
97 
98     p_bta_sdp_cfg->p_sdp_db->p_first_rec = &g_rec;
99   }
100 
TearDown()101   void TearDown() override {}
102 };
103 
104 // Test that bta_create_dip_sdp_record can parse sdp record to bluetooth_sdp_record correctly
TEST_F(BtaDipTest,test_bta_create_dip_sdp_record)105 TEST_F(BtaDipTest, test_bta_create_dip_sdp_record) {
106   bluetooth_sdp_record record;
107 
108   bta_create_dip_sdp_record(&record, &g_rec);
109 
110   ASSERT_EQ(record.dip.spec_id, 0x0103);
111   ASSERT_EQ(record.dip.vendor, 0x18d1);
112   ASSERT_EQ(record.dip.vendor_id_source, 1);
113   ASSERT_EQ(record.dip.product, 0x1234);
114   ASSERT_EQ(record.dip.version, 0x0100);
115   ASSERT_EQ(record.dip.primary_record, true);
116 }
117 
TEST_F(BtaDipTest,test_bta_sdp_search_cback)118 TEST_F(BtaDipTest, test_bta_sdp_search_cback) {
119   Uuid* userdata = (Uuid*)malloc(sizeof(Uuid));
120 
121   memcpy(userdata, &UUID_DIP, sizeof(UUID_DIP));
122   bta_sdp_search_cback(SDP_SUCCESS, userdata);
123 }
124 
125