aboutsummaryrefslogtreecommitdiff
path: root/libc/test/src/arpa/inet/inet_addr_test.cpp
blob: 3f0ea0fc3b3f3157a91411fec61ef681a7b613af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//===-- Unittests for inet_addr -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/arpa/inet/htonl.h"
#include "src/arpa/inet/inet_addr.h"
#include "test/UnitTest/Test.h"

namespace LIBC_NAMESPACE_DECL {

TEST(LlvmLibcInetAddr, ValidTest) {
  ASSERT_EQ(htonl(0x7f010204), inet_addr("127.1.2.4"));
  ASSERT_EQ(htonl(0x7f010004), inet_addr("127.1.4"));
}

TEST(LlvmLibcInetAddr, InvalidTest) {
  ASSERT_EQ(htonl(0xffffffff), inet_addr(""));
  ASSERT_EQ(htonl(0xffffffff), inet_addr("x"));
}

} // namespace LIBC_NAMESPACE_DECL