2020-02-10 22:06:00 +01:00
|
|
|
|
using LibHac.Common;
|
2020-02-03 08:44:50 +01:00
|
|
|
|
using LibHac.Fs;
|
2020-06-10 07:55:59 +02:00
|
|
|
|
using LibHac.Fs.Fsa;
|
2020-02-03 08:44:50 +01:00
|
|
|
|
using LibHac.FsSystem;
|
|
|
|
|
using LibHac.Tests.Fs.IFileSystemTestBase;
|
2020-02-10 22:06:00 +01:00
|
|
|
|
using Xunit;
|
2020-02-03 08:44:50 +01:00
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2020-02-03 08:44:50 +01:00
|
|
|
|
var baseFs = new InMemoryFileSystem();
|
2021-07-19 22:16:11 +02:00
|
|
|
|
baseFs.CreateDirectory("/sub");
|
|
|
|
|
baseFs.CreateDirectory("/sub/path");
|
2020-02-03 08:44:50 +01:00
|
|
|
|
|
2021-07-22 21:05:58 +02:00
|
|
|
|
var rootPath = new Path();
|
|
|
|
|
PathFunctions.SetUpFixedPath(ref rootPath, "/sub/path".ToU8String());
|
|
|
|
|
|
2020-09-07 09:32:28 +02:00
|
|
|
|
var subFs = new SubdirectoryFileSystem(baseFs);
|
2021-07-22 21:05:58 +02:00
|
|
|
|
subFs.Initialize(in rootPath).ThrowIfFailure();
|
2020-09-07 09:32:28 +02:00
|
|
|
|
|
2020-02-10 22:06:00 +01:00
|
|
|
|
return (baseFs, subFs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateFile_CreatedInBaseFileSystem()
|
|
|
|
|
{
|
|
|
|
|
(IFileSystem baseFs, IFileSystem subDirFs) = CreateFileSystemInternal();
|
|
|
|
|
|
2021-07-19 22:16:11 +02:00
|
|
|
|
subDirFs.CreateFile("/file", 0, CreateFileOptions.None);
|
2020-02-03 08:44:50 +01:00
|
|
|
|
|
2021-07-19 22:16:11 +02:00
|
|
|
|
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();
|
|
|
|
|
|
2021-07-19 22:16:11 +02:00
|
|
|
|
subDirFs.CreateDirectory("/dir");
|
2020-02-10 22:06:00 +01:00
|
|
|
|
|
2021-07-19 22:16:11 +02: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-03 08:44:50 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-10 22:06:00 +01:00
|
|
|
|
|
2020-02-03 08:44:50 +01:00
|
|
|
|
public class SubdirectoryFileSystemTestsRoot : IFileSystemTests
|
|
|
|
|
{
|
|
|
|
|
protected override IFileSystem CreateFileSystem()
|
|
|
|
|
{
|
|
|
|
|
var baseFs = new InMemoryFileSystem();
|
|
|
|
|
|
2021-07-22 21:05:58 +02:00
|
|
|
|
var rootPath = new Path();
|
|
|
|
|
PathFunctions.SetUpFixedPath(ref rootPath, "/".ToU8String());
|
|
|
|
|
|
2020-09-07 09:32:28 +02:00
|
|
|
|
var subFs = new SubdirectoryFileSystem(baseFs);
|
2021-07-22 21:05:58 +02:00
|
|
|
|
subFs.Initialize(in rootPath).ThrowIfFailure();
|
2020-02-03 08:44:50 +01:00
|
|
|
|
return subFs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|