LibHac/tests/LibHac.Tests/Fs/IFileSystemTestBase/IAttributeFileSystemTests.cs

133 lines
4.1 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 class IAttributeFileSystemTests : IFileSystemTests
{
2021-11-14 20:08:57 +01:00
protected abstract IAttributeFileSystem CreateAttributeFileSystem();
2021-11-14 20:08:57 +01:00
[Fact]
public void CreateDirectory_WithoutArchiveAttribute_ArchiveFlagIsNotSet()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
2021-11-14 20:08:57 +01:00
Assert.Success(fs.CreateDirectory("/dir", NxFileAttributes.None));
2021-11-14 20:08:57 +01:00
Assert.Success(fs.GetFileAttributes(out NxFileAttributes attributes, "/dir"));
Assert.Equal(NxFileAttributes.Directory, attributes);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void CreateDirectory_WithArchiveAttribute_ArchiveFlagIsSet()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
2021-11-14 20:08:57 +01:00
Assert.Success(fs.CreateDirectory("/dir", NxFileAttributes.Archive));
2021-11-14 20:08:57 +01:00
Assert.Success(fs.GetFileAttributes(out NxFileAttributes attributes, "/dir"));
Assert.Equal(NxFileAttributes.Directory | NxFileAttributes.Archive, attributes);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void GetFileAttributes_AttributesOnNewFileAreEmpty()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
fs.CreateFile("/file", 0, CreateFileOptions.None);
2021-11-14 20:08:57 +01:00
Assert.Success(fs.GetFileAttributes(out NxFileAttributes attributes, "/file"));
Assert.Equal(NxFileAttributes.None, attributes);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void GetFileAttributes_AttributesOnNewDirHaveOnlyDirFlagSet()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
fs.CreateDirectory("/dir");
2021-11-14 20:08:57 +01:00
Assert.Success(fs.GetFileAttributes(out NxFileAttributes attributes, "/dir"));
Assert.Equal(NxFileAttributes.Directory, attributes);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void GetFileAttributes_PathDoesNotExist_ReturnsPathNotFound()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
2021-11-14 20:08:57 +01:00
Result rc = fs.GetFileAttributes(out _, "/path");
2021-11-14 20:08:57 +01:00
Assert.Result(ResultFs.PathNotFound, rc);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void SetFileAttributes_PathDoesNotExist_ReturnsPathNotFound()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
2021-11-14 20:08:57 +01:00
Result rc = fs.SetFileAttributes("/path", NxFileAttributes.None);
2021-11-14 20:08:57 +01:00
Assert.Result(ResultFs.PathNotFound, rc);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void SetFileAttributes_SetAttributeOnFile()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
fs.CreateFile("/file", 0, CreateFileOptions.None);
2021-11-14 20:08:57 +01:00
Result rcSet = fs.SetFileAttributes("/file", NxFileAttributes.Archive);
Result rcGet = fs.GetFileAttributes(out NxFileAttributes attributes, "/file");
2021-11-14 20:08:57 +01:00
Assert.Success(rcSet);
Assert.Success(rcGet);
Assert.Equal(NxFileAttributes.Archive, attributes);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void SetFileAttributes_SetAttributeOnDirectory()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
fs.CreateDirectory("/dir");
2021-11-14 20:08:57 +01:00
Result rcSet = fs.SetFileAttributes("/dir", NxFileAttributes.Archive);
Result rcGet = fs.GetFileAttributes(out NxFileAttributes attributes, "/dir");
2021-11-14 20:08:57 +01:00
Assert.Success(rcSet);
Assert.Success(rcGet);
Assert.Equal(NxFileAttributes.Directory | NxFileAttributes.Archive, attributes);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void GetFileSize_ReadNewFileSize()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
2021-11-14 20:08:57 +01:00
fs.CreateFile("/file", 845, CreateFileOptions.None);
2021-11-14 20:08:57 +01:00
Assert.Success(fs.GetFileSize(out long fileSize, "/file"));
Assert.Equal(845, fileSize);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void GetFileSize_PathDoesNotExist_ReturnsPathNotFound()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
2021-11-14 20:08:57 +01:00
Result rc = fs.GetFileSize(out _, "/path");
2021-11-14 20:08:57 +01:00
Assert.Result(ResultFs.PathNotFound, rc);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void GetFileSize_PathIsDirectory_ReturnsPathNotFound()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
fs.CreateDirectory("/dir");
2021-11-14 20:08:57 +01:00
Result rc = fs.GetFileSize(out _, "/dir");
2021-11-14 20:08:57 +01:00
Assert.Result(ResultFs.PathNotFound, rc);
}
}