LibHac/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/Bis.cs

95 lines
3.4 KiB
C#
Raw Normal View History

using LibHac.Fs;
using LibHac.Fs.Fsa;
2020-04-03 06:57:08 +02:00
using LibHac.Fs.Shim;
using Xunit;
2021-11-14 20:08:57 +01:00
namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests;
public class Bis
2020-04-03 06:57:08 +02:00
{
2021-11-14 20:08:57 +01:00
[Fact]
public void MountBis_MountCalibrationPartition_OpensCorrectDirectory()
2020-04-03 06:57:08 +02:00
{
2021-11-14 20:08:57 +01:00
FileSystemClient fs = FileSystemServerFactory.CreateClient(out IFileSystem rootFs);
2020-04-03 06:57:08 +02:00
Assert.Success(fs.MountBis("calib"u8, BisPartitionId.CalibrationFile));
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
// Create a file in the opened file system
Assert.Success(fs.CreateFile("calib:/file"u8, 0));
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
// Make sure the file exists on the root file system
Assert.Success(rootFs.GetEntryType(out DirectoryEntryType type, "/bis/cal/file"u8));
2021-11-14 20:08:57 +01:00
Assert.Equal(DirectoryEntryType.File, type);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void MountBis_MountSafePartition_OpensCorrectDirectory()
{
FileSystemClient fs = FileSystemServerFactory.CreateClient(out IFileSystem rootFs);
2020-04-03 06:57:08 +02:00
Assert.Success(fs.MountBis("safe"u8, BisPartitionId.SafeMode));
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
// Create a file in the opened file system
Assert.Success(fs.CreateFile("safe:/file"u8, 0));
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
// Make sure the file exists on the root file system
Assert.Success(rootFs.GetEntryType(out DirectoryEntryType type, "/bis/safe/file"u8));
2021-11-14 20:08:57 +01:00
Assert.Equal(DirectoryEntryType.File, type);
}
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
[Fact]
public void MountBis_MountSystemPartition_OpensCorrectDirectory()
{
FileSystemClient fs = FileSystemServerFactory.CreateClient(out IFileSystem rootFs);
2020-04-03 06:57:08 +02:00
Assert.Success(fs.MountBis("system"u8, BisPartitionId.System));
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
// Create a file in the opened file system
Assert.Success(fs.CreateFile("system:/file"u8, 0));
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
// Make sure the file exists on the root file system
Assert.Success(rootFs.GetEntryType(out DirectoryEntryType type, "/bis/system/file"u8));
2021-11-14 20:08:57 +01:00
Assert.Equal(DirectoryEntryType.File, type);
}
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
[Fact]
public void MountBis_MountUserPartition_OpensCorrectDirectory()
{
FileSystemClient fs = FileSystemServerFactory.CreateClient(out IFileSystem rootFs);
2020-04-03 06:57:08 +02:00
Assert.Success(fs.MountBis("user"u8, BisPartitionId.User));
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
// Create a file in the opened file system
Assert.Success(fs.CreateFile("user:/file"u8, 0));
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
// Make sure the file exists on the root file system
Assert.Success(rootFs.GetEntryType(out DirectoryEntryType type, "/bis/user/file"u8));
2021-11-14 20:08:57 +01:00
Assert.Equal(DirectoryEntryType.File, type);
}
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
[Fact]
public void MountBis_WithRootPath_IgnoresRootPath()
{
FileSystemClient fs = FileSystemServerFactory.CreateClient(out IFileSystem rootFs);
2020-04-03 06:57:08 +02:00
Assert.Success(fs.MountBis(BisPartitionId.User, "/sub"u8));
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
// Create a file in the opened file system
Assert.Success(fs.CreateFile("@User:/file"u8, 0));
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
// Make sure the file wasn't created in the sub path
Assert.Result(ResultFs.PathNotFound, rootFs.GetEntryType(out _, "/bis/user/sub/file"u8));
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
// Make sure the file was created in the main path
Assert.Success(rootFs.GetEntryType(out DirectoryEntryType type, "/bis/user/file"u8));
2021-11-14 20:08:57 +01:00
Assert.Equal(DirectoryEntryType.File, type);
}
2020-04-03 06:57:08 +02:00
2021-11-14 20:08:57 +01:00
[Fact]
public void MountBis_InvalidPartition_ReturnsInvalidArgument()
{
FileSystemClient fs = FileSystemServerFactory.CreateClient(out IFileSystem _);
2020-04-03 06:57:08 +02:00
Assert.Result(ResultFs.InvalidArgument, fs.MountBis("boot1"u8, BisPartitionId.BootPartition1Root));
2020-04-03 06:57:08 +02:00
}
}