2020-03-08 09:00:02 +01:00
|
|
|
|
using LibHac.Common;
|
|
|
|
|
using LibHac.Fs;
|
2020-06-10 07:55:59 +02:00
|
|
|
|
using LibHac.Fs.Fsa;
|
2020-01-28 08:55:39 +01:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace LibHac.Tests.Fs.IFileSystemTestBase
|
|
|
|
|
{
|
|
|
|
|
public abstract partial class IFileSystemTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateDirectory_EntryIsAdded()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateDirectory("/dir".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-07-06 17:37:34 +02:00
|
|
|
|
Assert.Success(fs.GetEntryType(out DirectoryEntryType type, "/dir".ToU8Span()));
|
2020-01-28 08:55:39 +01:00
|
|
|
|
Assert.Equal(DirectoryEntryType.Directory, type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateDirectory_DirectoryExists_ReturnsPathAlreadyExists()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateDirectory("/dir".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rc = fs.CreateDirectory("/dir".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-07-06 17:37:34 +02:00
|
|
|
|
Assert.Result(ResultFs.PathAlreadyExists, rc);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateDirectory_FileExists_ReturnsPathAlreadyExists()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateFile("/file".ToU8Span(), 0, CreateFileOptions.None);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rc = fs.CreateDirectory("/file".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-07-06 17:37:34 +02:00
|
|
|
|
Assert.Result(ResultFs.PathAlreadyExists, rc);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateDirectory_ParentDoesNotExist_ReturnsPathNotFound()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rc = fs.CreateFile("/dir1/dir2".ToU8Span(), 0, CreateFileOptions.None);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-07-06 17:37:34 +02:00
|
|
|
|
Assert.Result(ResultFs.PathNotFound, rc);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateDirectory_WithTrailingSeparator_EntryIsAdded()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateDirectory("/dir/".ToU8Span());
|
|
|
|
|
Result rc = fs.GetEntryType(out DirectoryEntryType type, "/dir/".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-07-06 17:37:34 +02:00
|
|
|
|
Assert.Success(rc);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
Assert.Equal(DirectoryEntryType.Directory, type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateDirectory_MultipleSiblings()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateDirectory("/dir1".ToU8Span());
|
|
|
|
|
fs.CreateDirectory("/dir2".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rc1 = fs.GetEntryType(out DirectoryEntryType type1, "/dir1".ToU8Span());
|
|
|
|
|
Result rc2 = fs.GetEntryType(out DirectoryEntryType type2, "/dir2".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-07-06 17:37:34 +02:00
|
|
|
|
Assert.Success(rc1);
|
|
|
|
|
Assert.Success(rc2);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
Assert.Equal(DirectoryEntryType.Directory, type1);
|
|
|
|
|
Assert.Equal(DirectoryEntryType.Directory, type2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreateDirectory_InChildDirectory()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateDirectory("/dir1".ToU8Span());
|
|
|
|
|
fs.CreateDirectory("/dir2".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateDirectory("/dir1/dir1a".ToU8Span());
|
|
|
|
|
fs.CreateDirectory("/dir2/dir2a".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rc1 = fs.GetEntryType(out DirectoryEntryType type1, "/dir1/dir1a".ToU8Span());
|
|
|
|
|
Result rc2 = fs.GetEntryType(out DirectoryEntryType type2, "/dir2/dir2a".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-07-06 17:37:34 +02:00
|
|
|
|
Assert.Success(rc1);
|
|
|
|
|
Assert.Success(rc2);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
Assert.Equal(DirectoryEntryType.Directory, type1);
|
|
|
|
|
Assert.Equal(DirectoryEntryType.Directory, type2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|