• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <fcntl.h>
2 #include <gtest/gtest.h>
3 #include <stdlib.h>
4 #include <sys/auxv.h>
5 #include <sys/uio.h>
6 #include <unistd.h>
7 
8 using namespace testing::ext;
9 
10 constexpr size_t BUF_SIZE = 2;
11 
12 class UnistdPwrite64Test : public testing::Test {
SetUp()13     void SetUp() override {}
TearDown()14     void TearDown() override {}
15 };
16 
17 /**
18  * @tc.name: pwrite64_001
19  * @tc.desc: checks whether the pwrite64 function behaves correctly when writing data to a file opened in write-only
20  *           mode and when attempting to write data to a file opened in read-only mode.
21  * @tc.type: FUNC
22  * */
23 HWTEST_F(UnistdPwrite64Test, pwrite64_001, TestSize.Level1)
24 {
25     char buf[1];
26     int fd = open("/data/pwrite64.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
27     ASSERT_NE(-1, fd);
28     EXPECT_EQ(BUF_SIZE, pwrite64(fd, buf, BUF_SIZE, 0));
29     close(fd);
30     fd = open("/data/pwrite64.txt", O_RDONLY);
31     ASSERT_NE(-1, fd);
32     int ret = pwrite64(fd, buf, BUF_SIZE, 0);
33     EXPECT_EQ(-1, ret);
34     close(fd);
35     remove("/data/pwrite64.txt");
36 }