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

132 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();
Result res = fs.GetFileAttributes(out _, "/path");
Assert.Result(ResultFs.PathNotFound, res);
2021-11-14 20:08:57 +01:00
}
2021-11-14 20:08:57 +01:00
[Fact]
public void SetFileAttributes_PathDoesNotExist_ReturnsPathNotFound()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
Result res = fs.SetFileAttributes("/path", NxFileAttributes.None);
Assert.Result(ResultFs.PathNotFound, res);
2021-11-14 20:08:57 +01:00
}
2021-11-14 20:08:57 +01:00
[Fact]
public void SetFileAttributes_SetAttributeOnFile()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
fs.CreateFile("/file", 0, CreateFileOptions.None);
Result resultSet = fs.SetFileAttributes("/file", NxFileAttributes.Archive);
Result resultGet = fs.GetFileAttributes(out NxFileAttributes attributes, "/file");
Assert.Success(resultSet);
Assert.Success(resultGet);
2021-11-14 20:08:57 +01:00
Assert.Equal(NxFileAttributes.Archive, attributes);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void SetFileAttributes_SetAttributeOnDirectory()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
fs.CreateDirectory("/dir");
Result resultSet = fs.SetFileAttributes("/dir", NxFileAttributes.Archive);
Result resultGet = fs.GetFileAttributes(out NxFileAttributes attributes, "/dir");
Assert.Success(resultSet);
Assert.Success(resultGet);
2021-11-14 20:08:57 +01:00
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();
Result res = fs.GetFileSize(out _, "/path");
Assert.Result(ResultFs.PathNotFound, res);
2021-11-14 20:08:57 +01:00
}
2021-11-14 20:08:57 +01:00
[Fact]
public void GetFileSize_PathIsDirectory_ReturnsPathNotFound()
{
IAttributeFileSystem fs = CreateAttributeFileSystem();
fs.CreateDirectory("/dir");
Result res = fs.GetFileSize(out _, "/dir");
Assert.Result(ResultFs.PathNotFound, res);
}
}