1 /******************************************************************************
2 *
3 * Copyright 2018 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 <base/logging.h>
22 #include <base/strings/string_number_conversions.h>
23 #include "bta/include/bta_gatt_api.h"
24
25 using bluetooth::Uuid;
26
27 /* This test makes sure that v3 cache element is properly encoded into file*/
TEST(GattCacheTest,nv_attr_to_binary_test)28 TEST(GattCacheTest, nv_attr_to_binary_test) {
29 tBTA_GATTC_NV_ATTR attr{
30 .uuid = Uuid::FromString("1800"),
31 .s_handle = 0x0001,
32 .e_handle = 0xFFFF,
33 .attr_type = 0x01,
34 .id = 0x02,
35 .prop = 0x03,
36 .is_primary = false,
37 .incl_srvc_handle = 0x4543,
38 };
39
40 constexpr size_t len = sizeof(tBTA_GATTC_NV_ATTR);
41 uint8_t binary_form[len] = {0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x10,
42 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B,
43 0x34, 0xFB, 0x01, 0x00, 0xFF, 0xFF, 0x01,
44 0x02, 0x03, 0x00, 0x43, 0x45};
45
46 // USEFUL for debugging:
47 // LOG(ERROR) << " " << base::HexEncode(binary_form, len);
48 EXPECT_EQ(memcmp(binary_form, &attr, len), 0);
49 }
50