2021-08-10 23:44:58 +02: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;
|
|
|
|
|
|
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 CreateFile_EntryIsAdded()
|
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
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
fs.CreateFile("/file", 0, CreateFileOptions.None);
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Result res = fs.GetEntryType(out DirectoryEntryType type, "/file");
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Assert.Success(res);
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Equal(DirectoryEntryType.File, type);
|
|
|
|
|
}
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateFile_DirectoryExists_ReturnsPathAlreadyExists()
|
|
|
|
|
{
|
|
|
|
|
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.CreateFile("/dir", 0, CreateFileOptions.None);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Assert.Result(ResultFs.PathAlreadyExists, 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 CreateFile_FileExists_ReturnsPathAlreadyExists()
|
|
|
|
|
{
|
|
|
|
|
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 res = fs.CreateFile("/file", 0, CreateFileOptions.None);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Assert.Result(ResultFs.PathAlreadyExists, 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 CreateFile_ParentDoesNotExist_ReturnsPathNotFound()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Result res = fs.CreateFile("/dir/file", 0, CreateFileOptions.None);
|
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 CreateFile_WithTrailingSeparator_EntryIsAdded()
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Success(fs.GetEntryType(out DirectoryEntryType type, "/file/"));
|
|
|
|
|
Assert.Equal(DirectoryEntryType.File, type);
|
|
|
|
|
}
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateFile_WithSize_SizeIsSet()
|
|
|
|
|
{
|
|
|
|
|
const long expectedSize = 12345;
|
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
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
fs.CreateFile("/file", expectedSize, CreateFileOptions.None);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
using var file = new UniqueRef<IFile>();
|
2022-12-03 20:53:30 +01:00
|
|
|
|
fs.OpenFile(ref file.Ref, "/file", OpenMode.Read);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Success(file.Get.GetSize(out long fileSize));
|
|
|
|
|
Assert.Equal(expectedSize, fileSize);
|
|
|
|
|
}
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateFile_MultipleSiblings()
|
|
|
|
|
{
|
|
|
|
|
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 result1 = fs.GetEntryType(out DirectoryEntryType type1, "/file1");
|
|
|
|
|
Result result2 = fs.GetEntryType(out DirectoryEntryType type2, "/file2");
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Assert.Success(result1);
|
|
|
|
|
Assert.Success(result2);
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Equal(DirectoryEntryType.File, type1);
|
|
|
|
|
Assert.Equal(DirectoryEntryType.File, type2);
|
|
|
|
|
}
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateFile_InChildDirectory()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
fs.CreateDirectory("/dir1");
|
|
|
|
|
fs.CreateDirectory("/dir2");
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
fs.CreateFile("/dir1/file1", 0, CreateFileOptions.None);
|
|
|
|
|
fs.CreateFile("/dir2/file2", 0, CreateFileOptions.None);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Result result1 = fs.GetEntryType(out DirectoryEntryType type1, "/dir1/file1");
|
|
|
|
|
Result result2 = fs.GetEntryType(out DirectoryEntryType type2, "/dir2/file2");
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Assert.Success(result1);
|
|
|
|
|
Assert.Success(result2);
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Equal(DirectoryEntryType.File, type1);
|
|
|
|
|
Assert.Equal(DirectoryEntryType.File, type2);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
}
|
2022-11-12 02:21:07 +01:00
|
|
|
|
}
|