Home | History | Annotate | Download | only in test
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2014 Google, Inc.
      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 "btcore/include/bdaddr.h"
     22 
     23 static const char* test_addr = "12:34:56:78:9a:bc";
     24 static const char* test_addr2 = "cb:a9:87:65:43:21";
     25 
     26 TEST(BdaddrTest, test_empty) {
     27   bt_bdaddr_t empty;
     28   string_to_bdaddr("00:00:00:00:00:00", &empty);
     29   ASSERT_TRUE(bdaddr_is_empty(&empty));
     30 
     31   bt_bdaddr_t not_empty;
     32   string_to_bdaddr("00:00:00:00:00:01", &not_empty);
     33   ASSERT_FALSE(bdaddr_is_empty(&not_empty));
     34 }
     35 
     36 TEST(BdaddrTest, test_to_from_str) {
     37   char ret[19];
     38   bt_bdaddr_t bdaddr;
     39   string_to_bdaddr(test_addr, &bdaddr);
     40 
     41   ASSERT_EQ(0x12, bdaddr.address[0]);
     42   ASSERT_EQ(0x34, bdaddr.address[1]);
     43   ASSERT_EQ(0x56, bdaddr.address[2]);
     44   ASSERT_EQ(0x78, bdaddr.address[3]);
     45   ASSERT_EQ(0x9A, bdaddr.address[4]);
     46   ASSERT_EQ(0xBC, bdaddr.address[5]);
     47 
     48   bdaddr_to_string(&bdaddr, ret, sizeof(ret));
     49 
     50   ASSERT_STREQ(test_addr, ret);
     51 }
     52 
     53 TEST(BdaddrTest, test_equals) {
     54   bt_bdaddr_t bdaddr1;
     55   bt_bdaddr_t bdaddr2;
     56   bt_bdaddr_t bdaddr3;
     57   string_to_bdaddr(test_addr, &bdaddr1);
     58   string_to_bdaddr(test_addr, &bdaddr2);
     59   EXPECT_TRUE(bdaddr_equals(&bdaddr1, &bdaddr2));
     60 
     61   string_to_bdaddr(test_addr2, &bdaddr3);
     62   EXPECT_FALSE(bdaddr_equals(&bdaddr2, &bdaddr3));
     63 }
     64 
     65 TEST(BdaddrTest, test_copy) {
     66   bt_bdaddr_t bdaddr1;
     67   bt_bdaddr_t bdaddr2;
     68   string_to_bdaddr(test_addr, &bdaddr1);
     69   bdaddr_copy(&bdaddr2, &bdaddr1);
     70 
     71   EXPECT_TRUE(bdaddr_equals(&bdaddr1, &bdaddr2));
     72 }
     73