Skip to content

Commit 86e6afb

Browse files
committed
Add unit tests for nl_types.
1 parent aab915d commit 86e6afb

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

libc/test/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ add_subdirectory(assert)
9696
add_subdirectory(compiler)
9797
add_subdirectory(dirent)
9898
add_subdirectory(locale)
99+
add_subdirectory(nl_types)
99100
add_subdirectory(signal)
100101
add_subdirectory(spawn)
101102

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
add_custom_target(libc-nl-types-tests)
2+
3+
add_libc_test(
4+
nl_types_test
5+
SUITE
6+
libc-nl-types-tests
7+
SRCS
8+
nl_types_test.cpp
9+
DEPENDS
10+
libc.include.llvm-libc-types.nl_catd
11+
libc.src.nl_types.catopen
12+
libc.src.nl_types.catclose
13+
libc.src.nl_types.catgets
14+
)
15+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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

Comments
 (0)