blob: ee921d9d029c0ee6cc25501f2b0b367b8eefc902 [file] [log] [blame]
Elliott Hughesc6190a92016-05-16 13:24:31 -07001/*
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
21TEST(netinet_ether, ether_aton__ether_ntoa) {
22 ether_addr* a = ether_aton("12-34-56-78-9A-BC");
23 ASSERT_EQ(0x12, a->ether_addr_octet[0]);
24 ASSERT_EQ(0x34, a->ether_addr_octet[1]);
25 ASSERT_EQ(0x56, a->ether_addr_octet[2]);
26 ASSERT_EQ(0x78, a->ether_addr_octet[3]);
27 ASSERT_EQ(0x9a, a->ether_addr_octet[4]);
28 ASSERT_EQ(0xbc, a->ether_addr_octet[5]);
29
30 ASSERT_STREQ("12-34-56-78-9A-BC", ether_ntoa(a));
31}
32
33TEST(netinet_ether, ether_aton_r__ether_ntoa_r) {
34 ether_addr addr;
35 memset(&addr, 0, sizeof(addr));
36 ether_addr* a = ether_aton_r("12-34-56-78-9A-BC", &addr);
37 ASSERT_EQ(&addr, a);
38 ASSERT_EQ(0x12, addr.ether_addr_octet[0]);
39 ASSERT_EQ(0x34, addr.ether_addr_octet[1]);
40 ASSERT_EQ(0x56, addr.ether_addr_octet[2]);
41 ASSERT_EQ(0x78, addr.ether_addr_octet[3]);
42 ASSERT_EQ(0x9a, addr.ether_addr_octet[4]);
43 ASSERT_EQ(0xbc, addr.ether_addr_octet[5]);
44
45 char buf[32];
46 memset(buf, 0, sizeof(buf));
47 char* p = ether_ntoa_r(&addr, buf);
48 ASSERT_EQ(buf, p);
49 ASSERT_STREQ("12-34-56-78-9A-BC", buf);
50}