1 #include <gtest/gtest.h> 2 #include <sys/stat.h> 3 using namespace testing::ext; 4 5 class StatMkdirTest : public testing::Test { SetUp()6 void SetUp() override {} TearDown()7 void TearDown() override {} 8 }; 9 10 /** 11 * @tc.name: mkdir_001 12 * @tc.desc: Verify the ability to create a directory with specific permissions and to ensure that it can be 13 * subsequently removed without errors. 14 * @tc.type: FUNC 15 **/ 16 HWTEST_F(StatMkdirTest, mkdir_001, TestSize.Level1) 17 { 18 const char* dirname = "test_mkdir"; 19 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; 20 EXPECT_NE(-1, mkdir(dirname, mode)); 21 remove("test_mkdir"); 22 } 23 24 /** 25 * @tc.name: mkdir_002 26 * @tc.desc: Verify the error handling of the mkdir() function when attempting to create a directory that already 27 * exists, and it checks if the appropriate error code (-1) is returned. 28 * @tc.type: FUNC 29 **/ 30 HWTEST_F(StatMkdirTest, mkdir_002, TestSize.Level1) 31 { 32 const char* dirname = "test_mkdir"; 33 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; 34 mkdir(dirname, mode); 35 EXPECT_EQ(-1, mkdir(dirname, mode)); 36 remove("test_mkdir"); 37 }