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

70 lines
2.1 KiB
C#
Raw Normal View History

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