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

116 lines
4.6 KiB
C#
Raw Normal View History

using System.Linq;
using LibHac.Fs;
using LibHac.Fs.Shim;
using Xunit;
namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
{
public class SaveDataManagement
{
[Fact]
public void CreateCacheStorage_InUserSaveSpace_StorageIsCreated()
{
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, SaveDataFlags.None));
fs.OpenSaveDataIterator(out SaveDataIterator iterator, SaveDataSpaceId.User);
var info = new SaveDataInfo[2];
iterator.ReadSaveDataInfo(out long entriesRead, info);
Assert.Equal(1, entriesRead);
Assert.Equal(applicationId, info[0].ProgramId);
}
[Fact]
public void CreateCacheStorage_InSdCacheSaveSpace_StorageIsCreated()
{
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None));
fs.OpenSaveDataIterator(out SaveDataIterator iterator, SaveDataSpaceId.SdCache);
var info = new SaveDataInfo[2];
iterator.ReadSaveDataInfo(out long entriesRead, info);
Assert.Equal(1, entriesRead);
Assert.Equal(applicationId, info[0].ProgramId);
}
[Fact]
public void CreateCacheStorage_InSdCacheSaveSpaceWhenNoSdCard_ReturnsSdCardNotFound()
{
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(false);
Assert.Result(ResultFs.SdCardNotFound, fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None));
}
[Fact]
public void CreateCacheStorage_AlreadyExists_ReturnsPathAlreadyExists()
{
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, SaveDataFlags.None));
Assert.Result(ResultFs.PathAlreadyExists, fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, SaveDataFlags.None));
}
[Fact]
public void CreateCacheStorage_WithIndex_CreatesMultiple()
{
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, 0, SaveDataFlags.None));
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 1, 0, 0, SaveDataFlags.None));
fs.OpenSaveDataIterator(out SaveDataIterator iterator, SaveDataSpaceId.User);
var info = new SaveDataInfo[3];
iterator.ReadSaveDataInfo(out long entriesRead, info);
Assert.Equal(2, entriesRead);
Assert.Equal(applicationId, info[0].ProgramId);
Assert.Equal(applicationId, info[1].ProgramId);
var expectedIndexes = new short[] { 0, 1 };
short[] actualIndexes = info.Take(2).Select(x => x.Index).OrderBy(x => x).ToArray();
Assert.Equal(expectedIndexes, actualIndexes);
}
2020-04-04 23:19:36 +02:00
[Fact]
public void CreateBcatSaveData_DoesNotExist_SaveIsCreated()
{
var applicationId = new Ncm.ApplicationId(1);
2020-04-04 23:19:36 +02:00
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateBcatSaveData(applicationId, 0x400000));
fs.OpenSaveDataIterator(out SaveDataIterator iterator, SaveDataSpaceId.User);
var info = new SaveDataInfo[2];
iterator.ReadSaveDataInfo(out long entriesRead, info);
Assert.Equal(1, entriesRead);
Assert.Equal(applicationId, info[0].ProgramId);
2020-04-04 23:19:36 +02:00
Assert.Equal(SaveDataType.Bcat, info[0].Type);
}
[Fact]
public void CreateBcatSaveData_AlreadyExists_ReturnsPathAlreadyExists()
{
var applicationId = new Ncm.ApplicationId(1);
2020-04-04 23:19:36 +02:00
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateBcatSaveData(applicationId, 0x400000));
Assert.Result(ResultFs.PathAlreadyExists, fs.CreateBcatSaveData(applicationId, 0x400000));
}
}
}