1//===-- Unittests for unlink ----------------------------------------------===//
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/open.h"
10#include "src/unistd/close.h"
11#include "src/unistd/unlink.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 LlvmLibcUnlinkTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
19
20TEST_F(LlvmLibcUnlinkTest, CreateAndUnlink) {
21 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
22 constexpr const char *FILENAME = "unlink.test";
23 auto TEST_FILE = libc_make_test_file_path(FILENAME);
24 int write_fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
25 ASSERT_ERRNO_SUCCESS();
26 ASSERT_GT(write_fd, 0);
27
28 ASSERT_THAT(LIBC_NAMESPACE::close(write_fd), Succeeds(0));
29 ASSERT_THAT(LIBC_NAMESPACE::unlink(TEST_FILE), Succeeds(0));
30}
31
32TEST_F(LlvmLibcUnlinkTest, UnlinkNonExistentFile) {
33 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
34 ASSERT_THAT(LIBC_NAMESPACE::unlink("non-existent-file"), Fails(ENOENT));
35}
36

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of libc/test/src/unistd/unlink_test.cpp