LibHac/tests/LibHac.Tests/Fs/SubdirectoryFileSystemTests.cs

68 lines
1.9 KiB
C#
Raw Normal View History

using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSystem;
using LibHac.Tests.Fs.IFileSystemTestBase;
using LibHac.Tools.Fs;
2020-02-10 22:06:00 +01:00
using Xunit;
2021-11-14 20:08:57 +01:00
namespace LibHac.Tests.Fs;
public class SubdirectoryFileSystemTests : IFileSystemTests
{
2021-11-14 20:08:57 +01:00
protected override IFileSystem CreateFileSystem()
{
2021-11-14 20:08:57 +01:00
return CreateFileSystemInternal().subDirFs;
}
2020-02-10 22:06:00 +01:00
2021-11-14 20:08:57 +01:00
private (IFileSystem baseFs, IFileSystem subDirFs) CreateFileSystemInternal()
{
var baseFs = new InMemoryFileSystem();
baseFs.CreateDirectory("/sub");
baseFs.CreateDirectory("/sub/path");
2021-11-14 20:08:57 +01:00
using var rootPath = new Path();
PathFunctions.SetUpFixedPath(ref rootPath.Ref(), "/sub/path"u8);
2021-11-14 20:08:57 +01:00
var subFs = new SubdirectoryFileSystem(baseFs);
subFs.Initialize(in rootPath).ThrowIfFailure();
2021-11-14 20:08:57 +01:00
return (baseFs, subFs);
}
2020-02-10 22:06:00 +01:00
2021-11-14 20:08:57 +01:00
[Fact]
public void CreateFile_CreatedInBaseFileSystem()
{
(IFileSystem baseFs, IFileSystem subDirFs) = CreateFileSystemInternal();
2020-02-10 22:06:00 +01:00
2021-11-14 20:08:57 +01:00
subDirFs.CreateFile("/file", 0, CreateFileOptions.None);
2021-11-14 20:08:57 +01:00
Assert.Success(baseFs.GetEntryType(out DirectoryEntryType type, "/sub/path/file"));
Assert.Equal(DirectoryEntryType.File, type);
}
2020-02-10 22:06:00 +01:00
2021-11-14 20:08:57 +01:00
[Fact]
public void CreateDirectory_CreatedInBaseFileSystem()
{
(IFileSystem baseFs, IFileSystem subDirFs) = CreateFileSystemInternal();
2020-02-10 22:06:00 +01:00
2021-11-14 20:08:57 +01:00
subDirFs.CreateDirectory("/dir");
2020-02-10 22:06:00 +01:00
2021-11-14 20:08:57 +01:00
Assert.Success(baseFs.GetEntryType(out DirectoryEntryType type, "/sub/path/dir"));
Assert.Equal(DirectoryEntryType.Directory, type);
}
2021-11-14 20:08:57 +01:00
}
2020-02-10 22:06:00 +01:00
2021-11-14 20:08:57 +01:00
public class SubdirectoryFileSystemTestsRoot : IFileSystemTests
{
protected override IFileSystem CreateFileSystem()
{
2021-11-14 20:08:57 +01:00
var baseFs = new InMemoryFileSystem();
2021-11-14 20:08:57 +01:00
using var rootPath = new Path();
PathFunctions.SetUpFixedPath(ref rootPath.Ref(), "/"u8);
2021-11-14 20:08:57 +01:00
var subFs = new SubdirectoryFileSystem(baseFs);
subFs.Initialize(in rootPath).ThrowIfFailure();
return subFs;
}
}