1 //
2 //  Copyright (C) 2015 Google, Inc.
3 //
4 //  Licensed under the Apache License, Version 2.0 (the "License");
5 //  you may not use this file except in compliance with the License.
6 //  You may obtain a copy of the License at:
7 //
8 //  http://www.apache.org/licenses/LICENSE-2.0
9 //
10 //  Unless required by applicable law or agreed to in writing, software
11 //  distributed under the License is distributed on an "AS IS" BASIS,
12 //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 //  See the License for the specific language governing permissions and
14 //  limitations under the License.
15 //
16 
17 #include <gtest/gtest.h>
18 
19 #include "service/common/bluetooth/util/address_helper.h"
20 
21 namespace util {
22 
TEST(UtilTest,IsAddressValid)23 TEST(UtilTest, IsAddressValid) {
24   EXPECT_FALSE(IsAddressValid(""));
25   EXPECT_FALSE(IsAddressValid("000000000000"));
26   EXPECT_FALSE(IsAddressValid("00:00:00:00:0000"));
27   EXPECT_FALSE(IsAddressValid("00:00:00:00:00:0"));
28   EXPECT_FALSE(IsAddressValid("00:00:00:00:00:0;"));
29   EXPECT_TRUE(IsAddressValid("00:00:00:00:00:00"));
30   EXPECT_FALSE(IsAddressValid("aB:cD:eF:Gh:iJ:Kl"));
31 }
32 
TEST(UtilTest,BdAddrFromString)33 TEST(UtilTest, BdAddrFromString) {
34   bt_bdaddr_t addr;
35   memset(&addr, 0, sizeof(addr));
36 
37   EXPECT_TRUE(BdAddrFromString("00:00:00:00:00:00", &addr));
38   const bt_bdaddr_t result0 = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
39   EXPECT_EQ(0, memcmp(&addr, &result0, sizeof(addr)));
40 
41   EXPECT_TRUE(BdAddrFromString("ab:01:4C:d5:21:9f", &addr));
42   const bt_bdaddr_t result1 = {{0xab, 0x01, 0x4c, 0xd5, 0x21, 0x9f}};
43   EXPECT_EQ(0, memcmp(&addr, &result1, sizeof(addr)));
44 }
45 
46 }  // namespace util
47