| 1 | //===-- Unittests for mkdirat ---------------------------------------------===// |
| 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 "src/sys/stat/mkdirat.h" |
| 10 | #include "src/unistd/rmdir.h" |
| 11 | #include "test/UnitTest/ErrnoCheckingTest.h" |
| 12 | #include "test/UnitTest/ErrnoSetterMatcher.h" |
| 13 | #include "test/UnitTest/Test.h" |
| 14 | |
| 15 | #include "hdr/fcntl_macros.h" |
| 16 | |
| 17 | using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; |
| 18 | using LlvmLibcMkdiratTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest; |
| 19 | |
| 20 | TEST_F(LlvmLibcMkdiratTest, CreateAndRemove) { |
| 21 | constexpr const char *FILENAME = "testdata/mkdirat.testdir" ; |
| 22 | auto TEST_DIR = libc_make_test_file_path(FILENAME); |
| 23 | ASSERT_THAT(LIBC_NAMESPACE::mkdirat(AT_FDCWD, TEST_DIR, S_IRWXU), |
| 24 | Succeeds(0)); |
| 25 | ASSERT_THAT(LIBC_NAMESPACE::rmdir(TEST_DIR), Succeeds(0)); |
| 26 | } |
| 27 | |
| 28 | TEST_F(LlvmLibcMkdiratTest, BadPath) { |
| 29 | ASSERT_THAT( |
| 30 | LIBC_NAMESPACE::mkdirat(AT_FDCWD, "non-existent-dir/test" , S_IRWXU), |
| 31 | Fails(ENOENT)); |
| 32 | } |
| 33 | |