14abfe47eSSiva Chandra Reddy //===-- Unittest for creat ------------------------------------------------===// 24abfe47eSSiva Chandra Reddy // 34abfe47eSSiva Chandra Reddy // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 44abfe47eSSiva Chandra Reddy // See https://llvm.org/LICENSE.txt for license information. 54abfe47eSSiva Chandra Reddy // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 64abfe47eSSiva Chandra Reddy // 74abfe47eSSiva Chandra Reddy //===----------------------------------------------------------------------===// 84abfe47eSSiva Chandra Reddy 9d49b993fSSiva Chandra Reddy #include "src/errno/libc_errno.h" 104abfe47eSSiva Chandra Reddy #include "src/fcntl/creat.h" 114abfe47eSSiva Chandra Reddy #include "src/fcntl/open.h" 124abfe47eSSiva Chandra Reddy #include "src/unistd/close.h" 134f1fe19dSSiva Chandra Reddy #include "test/UnitTest/ErrnoSetterMatcher.h" 14af1315c2SSiva Chandra Reddy #include "test/UnitTest/Test.h" 154abfe47eSSiva Chandra Reddy 16c0ad6e2fSNick Desaulniers #include <sys/stat.h> 17c0ad6e2fSNick Desaulniers TEST(LlvmLibcCreatTest,CreatAndOpen)184abfe47eSSiva Chandra ReddyTEST(LlvmLibcCreatTest, CreatAndOpen) { 19b6bc9d72SGuillaume Chatelet using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; 204abfe47eSSiva Chandra Reddy constexpr const char *TEST_FILE = "testdata/creat.test"; 21b6bc9d72SGuillaume Chatelet int fd = LIBC_NAMESPACE::creat(TEST_FILE, S_IRWXU); 22*73874f7aSGuillaume Chatelet ASSERT_ERRNO_SUCCESS(); 234abfe47eSSiva Chandra Reddy ASSERT_GT(fd, 0); 24b6bc9d72SGuillaume Chatelet ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0)); 254abfe47eSSiva Chandra Reddy 26b6bc9d72SGuillaume Chatelet fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY); 27*73874f7aSGuillaume Chatelet ASSERT_ERRNO_SUCCESS(); 284abfe47eSSiva Chandra Reddy ASSERT_GT(fd, 0); 29b6bc9d72SGuillaume Chatelet ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0)); 304abfe47eSSiva Chandra Reddy 314abfe47eSSiva Chandra Reddy // TODO: 'remove' the test file at the end. 324abfe47eSSiva Chandra Reddy } 33