Skip to content

Commit

Permalink
UnitTests/FS: Add ReadDirectory ordering test (issue 10234)
Browse files Browse the repository at this point in the history
  • Loading branch information
leoetlino committed Jan 25, 2020
1 parent 8789a6d commit af416c6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <algorithm>
#include <array>
#include <memory>
#include <string>
Expand Down Expand Up @@ -389,3 +390,27 @@ TEST_F(FileSystemTest, ReadDirectoryOnFile)
ASSERT_FALSE(result.Succeeded());
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()));
}

0 comments on commit af416c6

Please sign in to comment.