32 lines · cpp
1//===-- Unittests for gethostname -----------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/unistd/gethostname.h"10 11#include "test/UnitTest/ErrnoCheckingTest.h"12#include "test/UnitTest/Test.h"13 14using LlvmLibcGetHostNameTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;15 16TEST(LlvmLibcGetHostNameTest, GetCurrHostName) {17 char hostbuffer[1024];18 int ret = LIBC_NAMESPACE::gethostname(hostbuffer, sizeof(hostbuffer));19 ASSERT_NE(ret, -1);20 ASSERT_ERRNO_SUCCESS();21 22 ret = LIBC_NAMESPACE::gethostname(hostbuffer, 0);23 ASSERT_EQ(ret, -1);24 ASSERT_ERRNO_EQ(ENAMETOOLONG);25 26 // test for invalid pointer27 char *nptr = nullptr;28 ret = LIBC_NAMESPACE::gethostname(nptr, 1);29 ASSERT_EQ(ret, -1);30 ASSERT_ERRNO_EQ(EFAULT);31}32