| Elliott Hughes | c6190a9 | 2016-05-16 13:24:31 -0700 | [diff] [blame] | 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 |  | 
|  | 21 | TEST(netinet_ether, ether_aton__ether_ntoa) { | 
| Elliott Hughes | 09e97e6 | 2016-05-16 16:21:37 -0700 | [diff] [blame] | 22 | ether_addr* a = ether_aton("12:34:56:78:9a:bc"); | 
|  | 23 | ASSERT_NE(nullptr, a); | 
| Elliott Hughes | c6190a9 | 2016-05-16 13:24:31 -0700 | [diff] [blame] | 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 |  | 
| Elliott Hughes | 09e97e6 | 2016-05-16 16:21:37 -0700 | [diff] [blame] | 31 | ASSERT_STREQ("12:34:56:78:9a:bc", ether_ntoa(a)); | 
| Elliott Hughes | c6190a9 | 2016-05-16 13:24:31 -0700 | [diff] [blame] | 32 | } | 
|  | 33 |  | 
|  | 34 | TEST(netinet_ether, ether_aton_r__ether_ntoa_r) { | 
|  | 35 | ether_addr addr; | 
|  | 36 | memset(&addr, 0, sizeof(addr)); | 
| Elliott Hughes | 09e97e6 | 2016-05-16 16:21:37 -0700 | [diff] [blame] | 37 | ether_addr* a = ether_aton_r("12:34:56:78:9a:bc", &addr); | 
| Elliott Hughes | c6190a9 | 2016-05-16 13:24:31 -0700 | [diff] [blame] | 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); | 
| Elliott Hughes | 09e97e6 | 2016-05-16 16:21:37 -0700 | [diff] [blame] | 50 | ASSERT_STREQ("12:34:56:78:9a:bc", buf); | 
| Elliott Hughes | c6190a9 | 2016-05-16 13:24:31 -0700 | [diff] [blame] | 51 | } |