|
| 1 | +//===-- Unittests for nl_types --------------------------------------------===// |
| 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-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "include/llvm-libc-types/nl_catd.h" |
| 10 | +#include "src/nl_types/catclose.h" |
| 11 | +#include "src/nl_types/catgets.h" |
| 12 | +#include "src/nl_types/catopen.h" |
| 13 | +#include "test/UnitTest/ErrnoCheckingTest.h" |
| 14 | + |
| 15 | +using LlvmLibcNlTypesTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest; |
| 16 | + |
| 17 | +TEST_F(LlvmLibcNlTypesTest, CatopenFails) { |
| 18 | + ASSERT_EQ(LIBC_NAMESPACE::catopen("/somepath", 0), |
| 19 | + reinterpret_cast<nl_catd>(-1)); |
| 20 | + ASSERT_ERRNO_EQ(EINVAL); |
| 21 | +} |
| 22 | + |
| 23 | +TEST_F(LlvmLibcNlTypesTest, CatcloseFails) { |
| 24 | + ASSERT_EQ(LIBC_NAMESPACE::catclose(nullptr), -1); |
| 25 | +} |
| 26 | + |
| 27 | +TEST_F(LlvmLibcNlTypesTest, CatgetsFails) { |
| 28 | + const char* message = "message"; |
| 29 | + // Note that we test for pointer equality here, since catgets |
| 30 | + // is expected to return the input argument as-is. |
| 31 | + ASSERT_EQ(LIBC_NAMESPACE::catgets(nullptr, 0, 0, message), |
| 32 | + const_cast<char*>(message)); |
| 33 | +} |
0 commit comments