2020-03-08 09:00:02 +01:00
|
|
|
|
using LibHac.Common;
|
|
|
|
|
using LibHac.Fs;
|
2020-06-10 07:55:59 +02:00
|
|
|
|
using LibHac.Fs.Fsa;
|
2020-01-28 08:55:39 +01:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace LibHac.Tests.Fs.IFileSystemTestBase
|
|
|
|
|
{
|
|
|
|
|
public abstract partial class IFileSystemTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DeleteFile_DoesNotExist_ReturnsPathNotFound()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rc = fs.DeleteFile("/file".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
Assert.Equal(ResultFs.PathNotFound.Value, rc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DeleteFile_FileExists_FileEntryIsRemoved()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateFile("/file".ToU8Span(), 0, CreateFileOptions.None);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rcDelete = fs.DeleteFile("/file".ToU8Span());
|
|
|
|
|
Result rcEntry = fs.GetEntryType(out _, "/file".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
|
|
|
|
Assert.True(rcDelete.IsSuccess());
|
|
|
|
|
Assert.Equal(ResultFs.PathNotFound.Value, rcEntry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DeleteFile_PathIsDirectory_ReturnsPathNotFound()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateDirectory("/dir".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rc = fs.DeleteFile("/dir".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
|
|
|
|
Assert.Equal(ResultFs.PathNotFound.Value, rc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DeleteFile_HasOlderSibling_SiblingNotDeleted()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateFile("/file1".ToU8Span(), 0, CreateFileOptions.None);
|
|
|
|
|
fs.CreateFile("/file2".ToU8Span(), 0, CreateFileOptions.None);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rcDelete = fs.DeleteFile("/file2".ToU8Span());
|
|
|
|
|
Result rcEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/file1".ToU8Span());
|
|
|
|
|
Result rcEntry2 = fs.GetEntryType(out _, "/file2".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
|
|
|
|
Assert.True(rcDelete.IsSuccess());
|
|
|
|
|
Assert.True(rcEntry1.IsSuccess());
|
|
|
|
|
Assert.Equal(ResultFs.PathNotFound.Value, rcEntry2);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(DirectoryEntryType.File, dir1Type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DeleteFile_HasYoungerSibling_SiblingNotDeleted()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateFile("/file2".ToU8Span(), 0, CreateFileOptions.None);
|
|
|
|
|
fs.CreateFile("/file1".ToU8Span(), 0, CreateFileOptions.None);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rcDelete = fs.DeleteFile("/file2".ToU8Span());
|
|
|
|
|
Result rcEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/file1".ToU8Span());
|
|
|
|
|
Result rcEntry2 = fs.GetEntryType(out _, "/file2".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
|
|
|
|
Assert.True(rcDelete.IsSuccess());
|
|
|
|
|
Assert.True(rcEntry1.IsSuccess());
|
|
|
|
|
Assert.Equal(ResultFs.PathNotFound.Value, rcEntry2);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(DirectoryEntryType.File, dir1Type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|