• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <fcntl.h>
2 #include <gtest/gtest.h>
3 #include <sys/stat.h>
4 using namespace testing::ext;
5 
6 class StatChmodTest : public testing::Test {
SetUp()7     void SetUp() override {}
TearDown()8     void TearDown() override {}
9 };
10 
11 /**
12  * @tc.name: chmod_001
13  * @tc.desc: Verify that the "chmod" function successfully changes the permission bits of a file without
14  *           encountering any errors or exceptions.
15  * @tc.type: FUNC
16  **/
17 HWTEST_F(StatChmodTest, chmod_001, TestSize.Level1)
18 {
19     mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
20     int fd = open("test_chmod", O_RDWR | O_CREAT, 0755);
21     EXPECT_GE(fd, 0);
22     EXPECT_EQ(chmod("test_chmod", mode), 0);
23     remove("test_chmod");
24 }
25 
26 /**
27  * @tc.name: chmod_002
28  * @tc.desc: Assist in the verification and validation of software that relies on the "chmod" function for file
29  *           permission management.
30  * @tc.type: FUNC
31  **/
32 HWTEST_F(StatChmodTest, chmod_002, TestSize.Level1)
33 {
34     EXPECT_EQ(-1, chmod(nullptr, 0));
35 }