2020-03-08 09:00:02 +01:00
|
|
|
|
using LibHac.Common;
|
|
|
|
|
using LibHac.Fs;
|
2020-01-28 08:55:39 +01:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace LibHac.Tests.Fs.IFileSystemTestBase
|
|
|
|
|
{
|
|
|
|
|
public abstract partial class IFileSystemTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RenameDirectory_EntriesAreMoved()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateDirectory("/dir1".ToU8Span());
|
|
|
|
|
Result rcRename = fs.RenameDirectory("/dir1".ToU8Span(), "/dir2".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rcDir2 = fs.GetEntryType(out DirectoryEntryType dir2Type, "/dir2".ToU8Span());
|
|
|
|
|
Result rcDir1 = fs.GetEntryType(out _, "/dir1".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
|
|
|
|
Assert.True(rcRename.IsSuccess());
|
|
|
|
|
|
|
|
|
|
Assert.True(rcDir2.IsSuccess());
|
|
|
|
|
Assert.Equal(DirectoryEntryType.Directory, dir2Type);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(ResultFs.PathNotFound.Value, rcDir1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RenameDirectory_HasChildren_NewChildPathExists()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateDirectory("/dir1".ToU8Span());
|
|
|
|
|
fs.CreateDirectory("/dir1/dirC".ToU8Span());
|
|
|
|
|
fs.CreateFile("/dir1/file1".ToU8Span(), 0, CreateFileOptions.None);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rcRename = fs.RenameDirectory("/dir1".ToU8Span(), "/dir2".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
|
|
|
|
// Check that renamed structure exists
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rcDir2 = fs.GetEntryType(out DirectoryEntryType dir2Type, "/dir2".ToU8Span());
|
|
|
|
|
Result rcDirC = fs.GetEntryType(out DirectoryEntryType dir1CType, "/dir2/dirC".ToU8Span());
|
|
|
|
|
Result rcFile1 = fs.GetEntryType(out DirectoryEntryType file1Type, "/dir2/file1".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
|
|
|
|
// Check that old structure doesn't exist
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rcDir1 = fs.GetEntryType(out _, "/dir1".ToU8Span());
|
|
|
|
|
Result rcDirCOld = fs.GetEntryType(out _, "/dir1/dirC".ToU8Span());
|
|
|
|
|
Result rcFile1Old = fs.GetEntryType(out _, "/dir1/file1".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
|
|
|
|
Assert.True(rcRename.IsSuccess());
|
|
|
|
|
|
|
|
|
|
Assert.True(rcDir2.IsSuccess());
|
|
|
|
|
Assert.True(rcDirC.IsSuccess());
|
|
|
|
|
Assert.True(rcFile1.IsSuccess());
|
|
|
|
|
|
|
|
|
|
Assert.Equal(DirectoryEntryType.Directory, dir2Type);
|
|
|
|
|
Assert.Equal(DirectoryEntryType.Directory, dir1CType);
|
|
|
|
|
Assert.Equal(DirectoryEntryType.File, file1Type);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(ResultFs.PathNotFound.Value, rcDir1);
|
|
|
|
|
Assert.Equal(ResultFs.PathNotFound.Value, rcDirCOld);
|
|
|
|
|
Assert.Equal(ResultFs.PathNotFound.Value, rcFile1Old);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RenameDirectory_DestHasDifferentParentDirectory()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
fs.CreateDirectory("/parent1".ToU8Span());
|
|
|
|
|
fs.CreateDirectory("/parent2".ToU8Span());
|
|
|
|
|
fs.CreateDirectory("/parent1/dir1".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rcRename = fs.RenameDirectory("/parent1/dir1".ToU8Span(), "/parent2/dir2".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rcDir2 = fs.GetEntryType(out DirectoryEntryType dir2Type, "/parent2/dir2".ToU8Span());
|
|
|
|
|
Result rcDir1 = fs.GetEntryType(out _, "/parent1/dir1".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
|
|
|
|
Assert.True(rcRename.IsSuccess());
|
|
|
|
|
|
|
|
|
|
Assert.Equal(Result.Success, rcDir2);
|
|
|
|
|
Assert.True(rcDir2.IsSuccess());
|
|
|
|
|
Assert.Equal(DirectoryEntryType.Directory, dir2Type);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(ResultFs.PathNotFound.Value, rcDir1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RenameDirectory_DestExists_ReturnsPathAlreadyExists()
|
|
|
|
|
{
|
|
|
|
|
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 rcRename = fs.RenameDirectory("/dir1".ToU8Span(), "/dir2".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2020-03-08 09:00:02 +01:00
|
|
|
|
Result rcDir1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/dir1".ToU8Span());
|
|
|
|
|
Result rcDir2 = fs.GetEntryType(out DirectoryEntryType dir2Type, "/dir2".ToU8Span());
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
|
|
|
|
Assert.Equal(ResultFs.PathAlreadyExists.Value, rcRename);
|
|
|
|
|
|
|
|
|
|
Assert.True(rcDir1.IsSuccess());
|
|
|
|
|
Assert.True(rcDir2.IsSuccess());
|
|
|
|
|
Assert.Equal(DirectoryEntryType.Directory, dir1Type);
|
|
|
|
|
Assert.Equal(DirectoryEntryType.Directory, dir2Type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|