LibHac/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateDirectory.cs

103 lines
2.7 KiB
C#
Raw Normal View History

using LibHac.Fs;
using LibHac.Fs.Fsa;
using Xunit;
2021-11-14 20:08:57 +01:00
namespace LibHac.Tests.Fs.IFileSystemTestBase;
public abstract partial class IFileSystemTests
{
2021-11-14 20:08:57 +01:00
[Fact]
public void CreateDirectory_EntryIsAdded()
{
2021-11-14 20:08:57 +01:00
IFileSystem fs = CreateFileSystem();
2021-11-14 20:08:57 +01:00
fs.CreateDirectory("/dir");
2021-11-14 20:08:57 +01:00
Assert.Success(fs.GetEntryType(out DirectoryEntryType type, "/dir"));
Assert.Equal(DirectoryEntryType.Directory, type);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void CreateDirectory_DirectoryExists_ReturnsPathAlreadyExists()
{
IFileSystem fs = CreateFileSystem();
2021-11-14 20:08:57 +01:00
fs.CreateDirectory("/dir");
2021-11-14 20:08:57 +01:00
Result rc = fs.CreateDirectory("/dir");
2021-11-14 20:08:57 +01:00
Assert.Result(ResultFs.PathAlreadyExists, rc);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void CreateDirectory_FileExists_ReturnsPathAlreadyExists()
{
IFileSystem fs = CreateFileSystem();
2021-11-14 20:08:57 +01:00
fs.CreateFile("/file", 0, CreateFileOptions.None);
2021-11-14 20:08:57 +01:00
Result rc = fs.CreateDirectory("/file");
2021-11-14 20:08:57 +01:00
Assert.Result(ResultFs.PathAlreadyExists, rc);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void CreateDirectory_ParentDoesNotExist_ReturnsPathNotFound()
{
IFileSystem fs = CreateFileSystem();
2021-11-14 20:08:57 +01:00
Result rc = fs.CreateFile("/dir1/dir2", 0, CreateFileOptions.None);
2021-11-14 20:08:57 +01:00
Assert.Result(ResultFs.PathNotFound, rc);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void CreateDirectory_WithTrailingSeparator_EntryIsAdded()
{
IFileSystem fs = CreateFileSystem();
2021-11-14 20:08:57 +01:00
fs.CreateDirectory("/dir/");
Result rc = fs.GetEntryType(out DirectoryEntryType type, "/dir/");
2021-11-14 20:08:57 +01:00
Assert.Success(rc);
Assert.Equal(DirectoryEntryType.Directory, type);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void CreateDirectory_MultipleSiblings()
{
IFileSystem fs = CreateFileSystem();
2021-11-14 20:08:57 +01:00
fs.CreateDirectory("/dir1");
fs.CreateDirectory("/dir2");
2021-11-14 20:08:57 +01:00
Result rc1 = fs.GetEntryType(out DirectoryEntryType type1, "/dir1");
Result rc2 = fs.GetEntryType(out DirectoryEntryType type2, "/dir2");
2021-11-14 20:08:57 +01:00
Assert.Success(rc1);
Assert.Success(rc2);
Assert.Equal(DirectoryEntryType.Directory, type1);
Assert.Equal(DirectoryEntryType.Directory, type2);
}
2021-11-14 20:08:57 +01:00
[Fact]
public void CreateDirectory_InChildDirectory()
{
IFileSystem fs = CreateFileSystem();
2021-11-14 20:08:57 +01:00
fs.CreateDirectory("/dir1");
fs.CreateDirectory("/dir2");
2021-11-14 20:08:57 +01:00
fs.CreateDirectory("/dir1/dir1a");
fs.CreateDirectory("/dir2/dir2a");
2021-11-14 20:08:57 +01:00
Result rc1 = fs.GetEntryType(out DirectoryEntryType type1, "/dir1/dir1a");
Result rc2 = fs.GetEntryType(out DirectoryEntryType type2, "/dir2/dir2a");
2021-11-14 20:08:57 +01:00
Assert.Success(rc1);
Assert.Success(rc2);
Assert.Equal(DirectoryEntryType.Directory, type1);
Assert.Equal(DirectoryEntryType.Directory, type2);
}
2021-11-14 20:08:57 +01:00
}