1 //===-- Unittest for creat ------------------------------------------------===// 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/fcntl/creat.h" 10 #include "src/fcntl/open.h" 11 #include "src/unistd/close.h" 12 #include "test/ErrnoSetterMatcher.h" 13 #include "utils/UnitTest/Test.h" 14 #include "utils/testutils/FDReader.h" 15 16 #include <errno.h> 17 18 TEST(LlvmLibcCreatTest, CreatAndOpen) { 19 using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; 20 constexpr const char *TEST_FILE = "testdata/creat.test"; 21 int fd = __llvm_libc::creat(TEST_FILE, S_IRWXU); 22 ASSERT_EQ(errno, 0); 23 ASSERT_GT(fd, 0); 24 ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0)); 25 26 fd = __llvm_libc::open(TEST_FILE, O_RDONLY); 27 ASSERT_EQ(errno, 0); 28 ASSERT_GT(fd, 0); 29 ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0)); 30 31 // TODO: 'remove' the test file at the end. 32 } 33