LibHac/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/Bis.cs
Alex Barney cb8b088487
Misc additions and warning fixes (#134)
* Run codegen and fix DeliveryCacheFileMetaEntry layout

* Use KipReader instead of Kip

* Ensure feature parity between U8String structs

* Don't use the obsolete Nacp class

* Add some null checks

* Address ReSharper warnings

* The Result structs should be readonly
2020-05-12 17:06:55 -07:00

95 lines
3.8 KiB
C#

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