brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · c578cf2 Raw
35 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/fcntl/creat.h"10#include "src/fcntl/open.h"11#include "src/unistd/close.h"12#include "test/UnitTest/ErrnoCheckingTest.h"13#include "test/UnitTest/ErrnoSetterMatcher.h"14#include "test/UnitTest/Test.h"15 16#include <sys/stat.h>17 18using LlvmLibcCreatTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;19 20TEST_F(LlvmLibcCreatTest, CreatAndOpen) {21  using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;22  constexpr const char *TEST_FILE = "testdata/creat.test";23  int fd = LIBC_NAMESPACE::creat(TEST_FILE, S_IRWXU);24  ASSERT_ERRNO_SUCCESS();25  ASSERT_GT(fd, 0);26  ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));27 28  fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);29  ASSERT_ERRNO_SUCCESS();30  ASSERT_GT(fd, 0);31  ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));32 33  // TODO: 'remove' the test file at the end.34}35