1 #include <fcntl.h> 2 #include <gtest/gtest.h> 3 #include <sys/stat.h> 4 5 using namespace testing::ext; 6 7 class StatLstatTest : public testing::Test { SetUp()8 void SetUp() override {} TearDown()9 void TearDown() override {} 10 }; 11 12 /** 13 * @tc.name: lstat_001 14 * @tc.desc: Verify that the "lstat" function correctly retrieves file-related information such as file size, 15 * file permissions, timestamps, and other attributes associated with the specified file path. 16 * @tc.type: FUNC 17 **/ 18 HWTEST_F(StatLstatTest, lstat_001, TestSize.Level1) 19 { 20 const char* dirname = "test_lstat"; 21 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; 22 23 ASSERT_NE(-1, mkdir(dirname, mode)); 24 25 const char* path = "test_lstat"; 26 struct stat fileStat; 27 EXPECT_NE(-1, lstat(path, &fileStat)); 28 remove("test_lstat"); 29 } 30 31 /** 32 * @tc.name: lstat_002 33 * @tc.desc: Verify the functionality of the lstat() function by checking if it correctly returns an error when 34 * attempting to retrieve information about a non-existing file. 35 * @tc.type: FUNC 36 **/ 37 HWTEST_F(StatLstatTest, lstat_002, TestSize.Level1) 38 { 39 const char* filename = "not_exist.txt"; 40 struct stat fileStat; 41 EXPECT_EQ(-1, lstat(filename, &fileStat)); 42 }