1 #include <fcntl.h> 2 #include <gtest/gtest.h> 3 4 using namespace testing::ext; 5 6 constexpr int BUF_SIZE = 128; 7 8 class TempMkostemp64Test : public testing::Test { SetUp()9 void SetUp() override {} TearDown()10 void TearDown() override {} 11 }; 12 13 /** 14 * @tc.name: mkostemp64_001 15 * @tc.desc: Verify mkostemp process success. Provide the correct template and no fixed suffix, 16 * specified in flags: O_APPEND, create a temporary file. 17 * @tc.type: FUNC 18 * */ 19 HWTEST_F(TempMkostemp64Test, mkostemp64_001, TestSize.Level1) 20 { 21 char tmpFile[] = "/data/mkostemp64_XXXXXX"; 22 int fd = mkostemp64(tmpFile, O_APPEND); 23 EXPECT_NE(-1, fd); 24 if (fd != -1) { 25 int cnt = write(fd, tmpFile, strlen(tmpFile)); 26 EXPECT_TRUE(cnt == strlen(tmpFile)); 27 close(fd); 28 char rmFile[BUF_SIZE]; 29 int len = sprintf(rmFile, "rm %s", tmpFile); 30 if (len > 0) { 31 system(rmFile); 32 } 33 } 34 }