2022-12-01 07:28:02 +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;
|
2021-12-19 09:35:45 +01:00
|
|
|
|
using LibHac.Tools.Fs;
|
2020-02-10 22:06:00 +01:00
|
|
|
|
using Xunit;
|
2020-02-03 08:44:50 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
namespace LibHac.Tests.Fs;
|
|
|
|
|
|
|
|
|
|
public class SubdirectoryFileSystemTests : IFileSystemTests
|
2020-02-03 08:44:50 +01:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
protected override IFileSystem CreateFileSystem()
|
2020-02-03 08:44:50 +01:00
|
|
|
|
{
|
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");
|
2020-02-03 08:44:50 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
using var rootPath = new Path();
|
2022-12-01 07:28:02 +01:00
|
|
|
|
PathFunctions.SetUpFixedPath(ref rootPath.Ref(), "/sub/path"u8);
|
2021-07-22 21:05:58 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
var subFs = new SubdirectoryFileSystem(baseFs);
|
|
|
|
|
subFs.Initialize(in rootPath).ThrowIfFailure();
|
2020-09-07 09:32:28 +02:00
|
|
|
|
|
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);
|
2020-02-03 08:44:50 +01:00
|
|
|
|
|
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);
|
2020-02-03 08:44:50 +01:00
|
|
|
|
}
|
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()
|
2020-02-03 08:44:50 +01:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
var baseFs = new InMemoryFileSystem();
|
2020-02-03 08:44:50 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
using var rootPath = new Path();
|
2022-12-01 07:28:02 +01:00
|
|
|
|
PathFunctions.SetUpFixedPath(ref rootPath.Ref(), "/"u8);
|
2021-07-22 21:05:58 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
var subFs = new SubdirectoryFileSystem(baseFs);
|
|
|
|
|
subFs.Initialize(in rootPath).ThrowIfFailure();
|
|
|
|
|
return subFs;
|
2020-02-03 08:44:50 +01:00
|
|
|
|
}
|
2021-12-19 09:35:45 +01:00
|
|
|
|
}
|