1 /*
2  * Copyright (C) 2016 The Android Open Source Project
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 <netinet/ether.h>
20 
TEST(netinet_ether,ether_aton__ether_ntoa)21 TEST(netinet_ether, ether_aton__ether_ntoa) {
22   ether_addr* a = ether_aton("12:34:56:78:9a:bc");
23   ASSERT_NE(nullptr, a);
24   ASSERT_EQ(0x12, a->ether_addr_octet[0]);
25   ASSERT_EQ(0x34, a->ether_addr_octet[1]);
26   ASSERT_EQ(0x56, a->ether_addr_octet[2]);
27   ASSERT_EQ(0x78, a->ether_addr_octet[3]);
28   ASSERT_EQ(0x9a, a->ether_addr_octet[4]);
29   ASSERT_EQ(0xbc, a->ether_addr_octet[5]);
30 
31   ASSERT_STREQ("12:34:56:78:9a:bc", ether_ntoa(a));
32 }
33 
TEST(netinet_ether,ether_aton_r__ether_ntoa_r)34 TEST(netinet_ether, ether_aton_r__ether_ntoa_r) {
35   ether_addr addr;
36   memset(&addr, 0, sizeof(addr));
37   ether_addr* a = ether_aton_r("12:34:56:78:9a:bc", &addr);
38   ASSERT_EQ(&addr, a);
39   ASSERT_EQ(0x12, addr.ether_addr_octet[0]);
40   ASSERT_EQ(0x34, addr.ether_addr_octet[1]);
41   ASSERT_EQ(0x56, addr.ether_addr_octet[2]);
42   ASSERT_EQ(0x78, addr.ether_addr_octet[3]);
43   ASSERT_EQ(0x9a, addr.ether_addr_octet[4]);
44   ASSERT_EQ(0xbc, addr.ether_addr_octet[5]);
45 
46   char buf[32];
47   memset(buf, 0, sizeof(buf));
48   char* p = ether_ntoa_r(&addr, buf);
49   ASSERT_EQ(buf, p);
50   ASSERT_STREQ("12:34:56:78:9a:bc", buf);
51 }
52