• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <errno.h>
2 #include <gtest/gtest.h>
3 #include <sys/stat.h>
4 using namespace testing::ext;
5 
6 class StatStatTest : public testing::Test {
SetUp()7     void SetUp() override {}
TearDown()8     void TearDown() override {}
9 };
10 
11 /**
12  * @tc.name: stat_001
13  * @tc.desc: Aiming to confirm that the stat function can successfully retrieve information about the "test.txt" file
14  *           and that no error occurs during this process.
15  * @tc.type: FUNC
16  **/
17 HWTEST_F(StatStatTest, stat_001, TestSize.Level1)
18 {
19     const char* dirname = "test_stat";
20     mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
21     ASSERT_NE(-1, mkdir(dirname, mode));
22     const char* path = "test_stat";
23     struct stat fileStat;
24     EXPECT_EQ(0, stat(path, &fileStat));
25     remove("test_stat");
26 }
27 
28 /**
29  * @tc.name: stat_002
30  * @tc.desc: Verify that the stat function correctly handles the case of a non-existent file and sets the
31  *           appropriate error code.
32  * @tc.type: FUNC
33  **/
34 HWTEST_F(StatStatTest, stat_002, TestSize.Level1)
35 {
36     const char* path = "not_exist.txt";
37     struct stat fileStat;
38     errno = 0;
39     EXPECT_EQ(-1, stat(path, &fileStat));
40     EXPECT_EQ(ENOENT, errno);
41 }