| 1 | //===-- Unittests for writev ----------------------------------------------===// |
| 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 "hdr/types/struct_iovec.h" |
| 10 | #include "src/fcntl/open.h" |
| 11 | #include "src/sys/uio/writev.h" |
| 12 | #include "src/unistd/close.h" |
| 13 | #include "src/unistd/unlink.h" |
| 14 | #include "test/UnitTest/ErrnoSetterMatcher.h" |
| 15 | #include "test/UnitTest/Test.h" |
| 16 | |
| 17 | using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; |
| 18 | |
| 19 | TEST(LlvmLibcSysUioWritevTest, SmokeTest) { |
| 20 | const char *filename = "./LlvmLibcSysUioWritevTest" ; |
| 21 | int fd = LIBC_NAMESPACE::open(filename, O_WRONLY | O_CREAT, 0644); |
| 22 | ASSERT_THAT(fd, returns(GT(0)).with_errno(EQ(0))); |
| 23 | const char *data = "Hello, World!\n" ; |
| 24 | struct iovec iov[2]; |
| 25 | iov[0].iov_base = const_cast<char *>(data); |
| 26 | iov[0].iov_len = 7; |
| 27 | iov[1].iov_base = const_cast<char *>(data + 7); |
| 28 | iov[1].iov_len = 8; |
| 29 | ASSERT_THAT(LIBC_NAMESPACE::writev(fd, iov, 2), |
| 30 | returns(EQ(ssize_t(15))).with_errno(EQ(0))); |
| 31 | ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds()); |
| 32 | ASSERT_THAT(LIBC_NAMESPACE::unlink(filename), |
| 33 | returns(EQ(ssize_t(0))).with_errno(EQ(0))); |
| 34 | } |
| 35 | |