2020-02-14 01:21:24 +01:00
|
|
|
|
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()
|
|
|
|
|
{
|
2020-07-10 06:22:04 +02:00
|
|
|
|
var applicationId = new Ncm.ApplicationId(1);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
|
|
|
|
|
|
2020-07-10 06:22:04 +02:00
|
|
|
|
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, SaveDataFlags.None));
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
|
|
|
|
fs.OpenSaveDataIterator(out SaveDataIterator iterator, SaveDataSpaceId.User);
|
|
|
|
|
|
|
|
|
|
var info = new SaveDataInfo[2];
|
|
|
|
|
iterator.ReadSaveDataInfo(out long entriesRead, info);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(1, entriesRead);
|
2020-07-10 06:22:04 +02:00
|
|
|
|
Assert.Equal(applicationId, info[0].ProgramId);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateCacheStorage_InSdCacheSaveSpace_StorageIsCreated()
|
|
|
|
|
{
|
2020-07-10 06:22:04 +02:00
|
|
|
|
var applicationId = new Ncm.ApplicationId(1);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
|
|
|
|
|
|
2020-07-10 06:22:04 +02:00
|
|
|
|
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None));
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
|
|
|
|
fs.OpenSaveDataIterator(out SaveDataIterator iterator, SaveDataSpaceId.SdCache);
|
|
|
|
|
|
|
|
|
|
var info = new SaveDataInfo[2];
|
|
|
|
|
iterator.ReadSaveDataInfo(out long entriesRead, info);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(1, entriesRead);
|
2020-07-10 06:22:04 +02:00
|
|
|
|
Assert.Equal(applicationId, info[0].ProgramId);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateCacheStorage_InSdCacheSaveSpaceWhenNoSdCard_ReturnsSdCardNotFound()
|
|
|
|
|
{
|
2020-07-10 06:22:04 +02:00
|
|
|
|
var applicationId = new Ncm.ApplicationId(1);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(false);
|
|
|
|
|
|
2020-07-10 06:22:04 +02:00
|
|
|
|
Assert.Result(ResultFs.SdCardNotFound, fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None));
|
2020-02-14 01:21:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateCacheStorage_AlreadyExists_ReturnsPathAlreadyExists()
|
|
|
|
|
{
|
2020-07-10 06:22:04 +02:00
|
|
|
|
var applicationId = new Ncm.ApplicationId(1);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
|
|
|
|
|
|
2020-07-10 06:22:04 +02:00
|
|
|
|
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));
|
2020-02-14 01:21:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateCacheStorage_WithIndex_CreatesMultiple()
|
|
|
|
|
{
|
2020-07-10 06:22:04 +02:00
|
|
|
|
var applicationId = new Ncm.ApplicationId(1);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
|
|
|
|
|
|
2020-07-10 06:22:04 +02:00
|
|
|
|
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));
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
|
|
|
|
fs.OpenSaveDataIterator(out SaveDataIterator iterator, SaveDataSpaceId.User);
|
|
|
|
|
|
|
|
|
|
var info = new SaveDataInfo[3];
|
|
|
|
|
iterator.ReadSaveDataInfo(out long entriesRead, info);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(2, entriesRead);
|
2020-07-10 06:22:04 +02:00
|
|
|
|
Assert.Equal(applicationId, info[0].ProgramId);
|
|
|
|
|
Assert.Equal(applicationId, info[1].ProgramId);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2020-07-10 06:22:04 +02:00
|
|
|
|
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);
|
2020-07-10 06:22:04 +02:00
|
|
|
|
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()
|
|
|
|
|
{
|
2020-07-10 06:22:04 +02:00
|
|
|
|
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));
|
|
|
|
|
}
|
2020-02-14 01:21:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|