1 #include <fcntl.h> 2 #include <gtest/gtest.h> 3 #include <sys/stat.h> 4 5 #define TEST_LEN 10 6 7 using namespace testing::ext; 8 9 class FcntlPosixfallocate64Test : public testing::Test { SetUp()10 void SetUp() override {} TearDown()11 void TearDown() override {} 12 }; 13 14 /** 15 * @tc.name: fcntl_posix_fallocate64_001 16 * @tc.desc: Verify whether the specified size of space can be successfully allocated when using the fcntl function for 17 * file allocation, and determine whether the allocation result is correct through assertion. 18 * @tc.type: FUNC 19 * */ 20 HWTEST_F(FcntlPosixfallocate64Test, fcntl_posix_fallocate64_001, TestSize.Level1) 21 { 22 struct stat sb; 23 FILE* fp = tmpfile(); 24 if (!fp) { 25 return; 26 } 27 int fd = fileno(fp); 28 if (fd == -1) { 29 fclose(fp); 30 return; 31 } 32 int result = posix_fallocate64(fd, 0, TEST_LEN); 33 EXPECT_EQ(0, result); 34 EXPECT_EQ(0, fstat(fd, &sb)); 35 EXPECT_EQ(sb.st_size, TEST_LEN); 36 fclose(fp); 37 }