summaryrefslogtreecommitdiff
path: root/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2019-12-29 22:27:28 +0100
committerLéo Lam <leo@leolam.fr>2020-01-25 17:54:58 +0100
commit031c63eb8a931eb007ec285840f848332a1cf526 (patch)
tree855583dca34ce8121eb4942ecf4b8ed2d499d7d9 /Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp
parent150c832532956ea8494e02b06a61f2a15135d71a (diff)
UnitTests/FS: Improve deletion test
* Test recursive directory deletion * Test "in use" check for both files and directories
Diffstat (limited to 'Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp')
-rw-r--r--Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp b/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp
index b39e4a48cb..79f853f441 100644
--- a/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp
+++ b/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp
@@ -5,6 +5,7 @@
#include <algorithm>
#include <array>
#include <memory>
+#include <optional>
#include <string>
#include <gtest/gtest.h>
@@ -148,6 +149,25 @@ TEST_F(FileSystemTest, Delete)
EXPECT_TRUE(m_fs->ReadDirectory(Uid{0}, Gid{0}, "/tmp").Succeeded());
EXPECT_EQ(m_fs->Delete(Uid{0}, Gid{0}, "/tmp"), ResultCode::Success);
EXPECT_EQ(m_fs->ReadDirectory(Uid{0}, Gid{0}, "/tmp").Error(), ResultCode::NotFound);
+
+ // Test recursive directory deletion.
+ ASSERT_EQ(m_fs->CreateDirectory(Uid{0}, Gid{0}, "/sys/1", 0, modes), ResultCode::Success);
+ ASSERT_EQ(m_fs->CreateDirectory(Uid{0}, Gid{0}, "/sys/1/2", 0, modes), ResultCode::Success);
+ ASSERT_EQ(m_fs->CreateFile(Uid{0}, Gid{0}, "/sys/1/2/3", 0, modes), ResultCode::Success);
+ ASSERT_EQ(m_fs->CreateFile(Uid{0}, Gid{0}, "/sys/1/2/4", 0, modes), ResultCode::Success);
+
+ // Leave a file open. Deletion should fail while the file is in use.
+ auto handle = std::make_optional(m_fs->OpenFile(Uid{0}, Gid{0}, "/sys/1/2/3", Mode::Read));
+ ASSERT_TRUE(handle->Succeeded());
+ EXPECT_EQ(m_fs->Delete(Uid{0}, Gid{0}, "/sys/1/2/3"), ResultCode::InUse);
+ // A directory that contains a file that is in use is considered to be in use,
+ // so this should fail too.
+ EXPECT_EQ(m_fs->Delete(Uid{0}, Gid{0}, "/sys/1"), ResultCode::InUse);
+
+ // With the handle closed, both of these should work:
+ handle.reset();
+ EXPECT_EQ(m_fs->Delete(Uid{0}, Gid{0}, "/sys/1/2/3"), ResultCode::Success);
+ EXPECT_EQ(m_fs->Delete(Uid{0}, Gid{0}, "/sys/1"), ResultCode::Success);
}
TEST_F(FileSystemTest, Rename)