Elliott Hughes | 6a41b0f | 2014-05-13 16:05:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 <arpa/inet.h> |
| 20 | |
| 21 | TEST(arpa_inet, inet_addr) { |
| 22 | ASSERT_EQ((htonl)(0x7f000001), inet_addr("127.0.0.1")); |
| 23 | } |
| 24 | |
| 25 | TEST(arpa_inet, inet_aton) { |
| 26 | in_addr a; |
| 27 | ASSERT_EQ(1, inet_aton("127.0.0.1", &a)); |
| 28 | ASSERT_EQ((htonl)(0x7f000001), a.s_addr); |
| 29 | } |
| 30 | |
| 31 | TEST(arpa_inet, inet_lnaof) { |
| 32 | in_addr a = { htonl(0x12345678) }; |
| 33 | ASSERT_EQ(0x00345678U, inet_lnaof(a)); |
| 34 | } |
| 35 | |
| 36 | TEST(arpa_inet, inet_makeaddr) { |
| 37 | in_addr a = inet_makeaddr(0x12U, 0x345678); |
| 38 | ASSERT_EQ((htonl)(0x12345678), a.s_addr); |
| 39 | } |
| 40 | |
| 41 | TEST(arpa_inet, inet_netof) { |
| 42 | in_addr a = { htonl(0x12345678) }; |
| 43 | ASSERT_EQ(0x12U, inet_netof(a)); |
| 44 | } |
| 45 | |
| 46 | TEST(arpa_inet, inet_network) { |
| 47 | ASSERT_EQ(0x7f000001U, inet_network("127.0.0.1")); |
| 48 | } |
| 49 | |
| 50 | TEST(arpa_inet, inet_ntoa) { |
| 51 | in_addr a = { (htonl)(0x7f000001) }; |
| 52 | ASSERT_STREQ("127.0.0.1", inet_ntoa(a)); |
| 53 | } |
| 54 | |
| 55 | TEST(arpa_inet, inet_pton__inet_ntop) { |
| 56 | sockaddr_storage ss; |
| 57 | ASSERT_EQ(1, inet_pton(AF_INET, "127.0.0.1", &ss)); |
| 58 | |
| 59 | char s[INET_ADDRSTRLEN]; |
| 60 | ASSERT_STREQ("127.0.0.1", inet_ntop(AF_INET, &ss, s, INET_ADDRSTRLEN)); |
| 61 | } |