• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <fcntl.h>
2 #include <gtest/gtest.h>
3 #include <sys/stat.h>
4 
5 using namespace testing::ext;
6 
7 class StatFstatatTest : public testing::Test {
SetUp()8     void SetUp() override {}
TearDown()9     void TearDown() override {}
10 };
11 
12 /**
13  * @tc.name: fstatat64_001
14  * @tc.desc: Verify the functionality of the fstatat64() function by creating a directory, retrieving the file status
15  *           information using fstatat64() with the AT_SYMLINK_NOFOLLOW flag to ensure that any symbolic links in the
16  *           path are not followed, comparing the file permissions with the expected value, and performing checks to
17  *           ensure successful execution of each step.
18  * @tc.type: FUNC
19  **/
20 HWTEST_F(StatFstatatTest, fstatat64_001, TestSize.Level1)
21 {
22     const char* dirName = "test_fstatat64.txt";
23     mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
24     int result = mkdir(dirName, mode);
25     ASSERT_NE(-1, result);
26     struct stat64 st;
27     const char* linkName = "test_fstatat64.txt";
28     EXPECT_EQ(0, fstatat64(AT_FDCWD, linkName, &st, AT_NO_AUTOMOUNT));
29     mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO;
30     EXPECT_EQ(0755 & mask, static_cast<mode_t>(st.st_mode) & mask);
31     remove("test_fstatat64.txt");
32 }
33 
34 /**
35  * @tc.name: fstatat64_002
36  * @tc.desc: Verify the functionality of the fstatat64() function by creating a directory, retrieving the file status
37  *           information using fstatat64() with the AT_SYMLINK_NOFOLLOW flag to ensure that any symbolic links in the
38  *           path are not followed, comparing the file permissions with the expected value, and performing checks to
39  *           ensure successful execution of each step.
40  * @tc.type: FUNC
41  **/
42 HWTEST_F(StatFstatatTest, fstatat64_002, TestSize.Level1)
43 {
44     const char* dirName = "test_fstatat64.txt";
45     mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
46     int result = mkdir(dirName, mode);
47     ASSERT_NE(-1, result);
48     struct stat64 st;
49     const char* linkName = "test_fstatat64.txt";
50     int ret = fstatat64(AT_FDCWD, linkName, &st, AT_SYMLINK_NOFOLLOW);
51     EXPECT_EQ(0, ret);
52     mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO;
53     EXPECT_EQ(0755 & mask, static_cast<mode_t>(st.st_mode) & mask);
54     remove("test_fstatat64.txt");
55 }
56 
57 /**
58  * @tc.name: fstatat64_003
59  * @tc.desc: Verify the functionality of the fstatat64() function by creating a directory, retrieving the file status
60  *           information using fstatat64() with the AT_EMPTY_PATH flag to specify that the path refers to the current
61  *           directory, comparing the file permissions with the expected value, and performing checks to ensure
62  *           successful execution of each step.
63  * @tc.type: FUNC
64  **/
65 HWTEST_F(StatFstatatTest, fstatat64_003, TestSize.Level1)
66 {
67     const char* dirName = "test_fstatat64.txt";
68     mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
69     int result = mkdir(dirName, mode);
70     ASSERT_NE(-1, result);
71     struct stat64 st;
72     const char* linkName = "test_fstatat64.txt";
73     int ret = fstatat64(AT_FDCWD, linkName, &st, AT_EMPTY_PATH);
74     EXPECT_EQ(0, ret);
75     mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO;
76     EXPECT_EQ(0755 & mask, static_cast<mode_t>(st.st_mode) & mask);
77     remove("test_fstatat64.txt");
78 }