• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <dirent.h>
2 #include <errno.h>
3 #include <gtest/gtest.h>
4 #include <set>
5 
6 using namespace testing::ext;
7 
8 class DirentReaddir64Test : public testing::Test {
SetUp()9     void SetUp() override {}
TearDown()10     void TearDown() override {}
11 };
12 
13 /**
14  * @tc.name: readdir64_001
15  * @tc.desc: Verify that when using the readdir64 function to read the file entries in the directory one by one, the
16  *file names can be correctly obtained and the expected set of file names can be obtained.
17  * @tc.type: FUNC
18  */
19 HWTEST_F(DirentReaddir64Test, readdir64_001, TestSize.Level1)
20 {
21     DIR* dir = opendir("/data");
22     ASSERT_NE(dir, nullptr);
23     std::set<std::string> fileNames;
24     errno = 0;
25     dirent64* entry;
26     while ((entry = readdir64(dir)) != nullptr) {
27         fileNames.insert(entry->d_name);
28     }
29     EXPECT_EQ(0, errno);
30     EXPECT_EQ(closedir(dir), 0);
31     ASSERT_NE(fileNames.find("."), fileNames.end());
32     ASSERT_NE(fileNames.find(".."), fileNames.end());
33 }