summaryrefslogtreecommitdiff
path: root/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2019-12-29 21:19:11 +0100
committerLéo Lam <leo@leolam.fr>2020-01-25 17:54:58 +0100
commitaf416c60b054277603fa4386a253517801a55111 (patch)
tree684fef6a481772b4440bfdbece8f65d002b54c44 /Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp
parent8789a6ddb38df1559201582c2fe946479643e14b (diff)
UnitTests/FS: Add ReadDirectory ordering test (issue 10234)
Diffstat (limited to 'Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp')
-rw-r--r--Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp b/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp
index 39936678b8..b39e4a48cb 100644
--- a/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp
+++ b/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp
@@ -2,6 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
+#include <algorithm>
#include <array>
#include <memory>
#include <string>
@@ -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()));
+}