1 /******************************************************************************
2 *
3 * Copyright 2019 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 "common/link_key.h"
20 #include <gtest/gtest.h>
21 #include "os/log.h"
22
23 using bluetooth::common::LinkKey;
24
25 static const char* test_link_key = "4c68384139f574d836bcf34e9dfb01bf\0";
26
TEST(LinkKeyUnittest,test_constructor_array)27 TEST(LinkKeyUnittest, test_constructor_array) {
28 uint8_t data[LinkKey::kLength] = {0x4c, 0x87, 0x49, 0xe1, 0x2e, 0x55, 0x0f, 0x7f,
29 0x60, 0x8b, 0x4f, 0x96, 0xd7, 0xc5, 0xbc, 0x2a};
30
31 LinkKey link_key(data);
32
33 for (int i = 0; i < LinkKey::kLength; i++) {
34 ASSERT_EQ(data[i], link_key.link_key[i]);
35 }
36 }
37
TEST(LinkKeyUnittest,test_from_str)38 TEST(LinkKeyUnittest, test_from_str) {
39 LinkKey link_key;
40 LinkKey::FromString(test_link_key, link_key);
41
42 for (int i = 0; i < LinkKey::kLength; i++) {
43 ASSERT_EQ(LinkKey::kExample.link_key[i], link_key.link_key[i]);
44 }
45 }
46
TEST(LinkKeyUnittest,test_to_str)47 TEST(LinkKeyUnittest, test_to_str) {
48 std::string str = LinkKey::kExample.ToString();
49 ASSERT_STREQ(str.c_str(), test_link_key);
50 }