UnitTests/FS: Add ReadDirectory ordering test (issue 10234)

This commit is contained in:
Léo Lam 2019-12-29 21:19:11 +01:00
parent 8789a6ddb3
commit af416c60b0
1 changed files with 25 additions and 0 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <algorithm>
#include <array> #include <array>
#include <memory> #include <memory>
#include <string> #include <string>
@ -389,3 +390,27 @@ TEST_F(FileSystemTest, ReadDirectoryOnFile)
ASSERT_FALSE(result.Succeeded()); ASSERT_FALSE(result.Succeeded());
EXPECT_EQ(result.Error(), ResultCode::Invalid); EXPECT_EQ(result.Error(), ResultCode::Invalid);
} }
TEST_F(FileSystemTest, ReadDirectoryOrdering)
{
ASSERT_EQ(m_fs->CreateDirectory(Uid{0}, Gid{0}, "/tmp/o", 0, modes), ResultCode::Success);
// Randomly generated file names in no particular order.
const std::array<std::string, 5> file_names{{
"Rkj62lGwHp",
"XGDQTDJMea",
"1z5M43WeFw",
"YAY39VuMRd",
"hxJ86nkoBX",
}};
// Create the files.
for (const auto& name : file_names)
ASSERT_EQ(m_fs->CreateFile(Uid{0}, Gid{0}, "/tmp/o/" + name, 0, modes), ResultCode::Success);
// Verify that ReadDirectory returns a file list that is ordered by descending creation date
// (issue 10234).
const Result<std::vector<std::string>> result = m_fs->ReadDirectory(Uid{0}, Gid{0}, "/tmp/o");
ASSERT_TRUE(result.Succeeded());
ASSERT_EQ(result->size(), file_names.size());
EXPECT_TRUE(std::equal(result->begin(), result->end(), file_names.rbegin()));
}