LibHac/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectory.cs

96 lines
2.5 KiB
C#
Raw Normal View History

using LibHac.Fs;
using LibHac.Fs.Fsa;
using Xunit;
2021-11-14 20:08:57 +01:00
namespace LibHac.Tests.Fs.IFileSystemTestBase;
public abstract partial class IFileSystemTests
{
2021-11-14 20:08:57 +01:00
[Fact]
public void DeleteDirectory_DoesNotExist_ReturnsPathNotFound()
{
2021-11-14 20:08:57 +01:00
IFileSystem fs = CreateFileSystem();
2021-11-14 20:08:57 +01:00
Result rc = fs.DeleteDirectory("/dir");
2021-11-14 20:08:57 +01:00
Assert.Result(ResultFs.PathNotFound, rc);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void DeleteDirectory_DirectoryExists_EntryIsRemoved()
{
IFileSystem fs = CreateFileSystem();
2021-11-14 20:08:57 +01:00
fs.CreateDirectory("/dir");
2021-11-14 20:08:57 +01:00
Result rcDelete = fs.DeleteDirectory("/dir");
Result rcEntry = fs.GetEntryType(out _, "/dir");
2021-11-14 20:08:57 +01:00
Assert.Success(rcDelete);
Assert.Result(ResultFs.PathNotFound, rcEntry);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void DeleteDirectory_PathIsFile_ReturnsPathNotFound()
{
IFileSystem fs = CreateFileSystem();
2021-11-14 20:08:57 +01:00
fs.CreateFile("/file", 0, CreateFileOptions.None);
2021-11-14 20:08:57 +01:00
Result rc = fs.DeleteDirectory("/file");
2021-11-14 20:08:57 +01:00
Assert.Result(ResultFs.PathNotFound, rc);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void DeleteDirectory_HasOlderSibling_SiblingNotDeleted()
{
IFileSystem fs = CreateFileSystem();
2021-11-14 20:08:57 +01:00
fs.CreateDirectory("/dir1");
fs.CreateDirectory("/dir2");
2021-11-14 20:08:57 +01:00
Result rcDelete = fs.DeleteDirectory("/dir2");
Result rcEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/dir1");
Result rcEntry2 = fs.GetEntryType(out _, "/dir2");
2021-11-14 20:08:57 +01:00
Assert.Success(rcDelete);
Assert.Success(rcEntry1);
Assert.Result(ResultFs.PathNotFound, rcEntry2);
2021-11-14 20:08:57 +01:00
Assert.Equal(DirectoryEntryType.Directory, dir1Type);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void DeleteDirectory_HasYoungerSibling_SiblingNotDeleted()
{
IFileSystem fs = CreateFileSystem();
2021-11-14 20:08:57 +01:00
fs.CreateDirectory("/dir2");
fs.CreateDirectory("/dir1");
2021-11-14 20:08:57 +01:00
Result rcDelete = fs.DeleteDirectory("/dir2");
Result rcEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/dir1");
Result rcEntry2 = fs.GetEntryType(out _, "/dir2");
2021-11-14 20:08:57 +01:00
Assert.Success(rcDelete);
Assert.Success(rcEntry1);
Assert.Result(ResultFs.PathNotFound, rcEntry2);
2021-11-14 20:08:57 +01:00
Assert.Equal(DirectoryEntryType.Directory, dir1Type);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void DeleteDirectory_NotEmpty_ReturnsDirectoryNotEmpty()
{
IFileSystem fs = CreateFileSystem();
2021-11-14 20:08:57 +01:00
fs.CreateDirectory("/dir");
fs.CreateFile("/dir/file", 0, CreateFileOptions.None);
2021-11-14 20:08:57 +01:00
Result rc = fs.DeleteDirectory("/dir");
2021-11-14 20:08:57 +01:00
Assert.Result(ResultFs.DirectoryNotEmpty, rc);
}
2021-11-14 20:08:57 +01:00
}