2021-07-19 22:16:11 +02:00
|
|
|
|
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;
|
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
namespace LibHac.Tests.Fs.IFileSystemTestBase;
|
|
|
|
|
|
|
|
|
|
public abstract partial class IFileSystemTests
|
2020-01-28 08:55:39 +01:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void DeleteFile_DoesNotExist_ReturnsPathNotFound()
|
2020-01-28 08:55:39 +01:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Result res = fs.DeleteFile("/file");
|
|
|
|
|
Assert.Result(ResultFs.PathNotFound, res);
|
2021-11-14 20:08:57 +01:00
|
|
|
|
}
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void DeleteFile_FileExists_FileEntryIsRemoved()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
fs.CreateFile("/file", 0, CreateFileOptions.None);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Result resultDelete = fs.DeleteFile("/file");
|
|
|
|
|
Result resultEntry = fs.GetEntryType(out _, "/file");
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Assert.Success(resultDelete);
|
|
|
|
|
Assert.Result(ResultFs.PathNotFound, resultEntry);
|
2021-11-14 20:08:57 +01:00
|
|
|
|
}
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void DeleteFile_PathIsDirectory_ReturnsPathNotFound()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
fs.CreateDirectory("/dir");
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Result res = fs.DeleteFile("/dir");
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Assert.Result(ResultFs.PathNotFound, res);
|
2021-11-14 20:08:57 +01:00
|
|
|
|
}
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void DeleteFile_HasOlderSibling_SiblingNotDeleted()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
fs.CreateFile("/file1", 0, CreateFileOptions.None);
|
|
|
|
|
fs.CreateFile("/file2", 0, CreateFileOptions.None);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Result resultDelete = fs.DeleteFile("/file2");
|
|
|
|
|
Result resultEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/file1");
|
|
|
|
|
Result resultEntry2 = fs.GetEntryType(out _, "/file2");
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Assert.Success(resultDelete);
|
|
|
|
|
Assert.Success(resultEntry1);
|
|
|
|
|
Assert.Result(ResultFs.PathNotFound, resultEntry2);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Equal(DirectoryEntryType.File, dir1Type);
|
|
|
|
|
}
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void DeleteFile_HasYoungerSibling_SiblingNotDeleted()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
fs.CreateFile("/file2", 0, CreateFileOptions.None);
|
|
|
|
|
fs.CreateFile("/file1", 0, CreateFileOptions.None);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Result resultDelete = fs.DeleteFile("/file2");
|
|
|
|
|
Result resultEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/file1");
|
|
|
|
|
Result resultEntry2 = fs.GetEntryType(out _, "/file2");
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Assert.Success(resultDelete);
|
|
|
|
|
Assert.Success(resultEntry1);
|
|
|
|
|
Assert.Result(ResultFs.PathNotFound, resultEntry2);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Equal(DirectoryEntryType.File, dir1Type);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
}
|
2022-11-12 02:21:07 +01:00
|
|
|
|
}
|