2020-01-28 08:55:39 +01:00
|
|
|
|
using System;
|
|
|
|
|
using LibHac.Common;
|
|
|
|
|
using LibHac.Fs;
|
2020-06-10 07:55:59 +02:00
|
|
|
|
using LibHac.Fs.Fsa;
|
2020-10-11 05:17:07 +02:00
|
|
|
|
using LibHac.Util;
|
2020-01-28 08:55:39 +01:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
namespace LibHac.Tests.Fs.IFileSystemTestBase;
|
|
|
|
|
|
|
|
|
|
public abstract partial class IFileSystemTests
|
2020-01-28 08:55:39 +01:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void IDirectoryRead_EmptyFs_NoEntriesAreRead()
|
2020-01-28 08:55:39 +01:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
Span<DirectoryEntry> entries = stackalloc DirectoryEntry[1];
|
2020-03-04 02:19:11 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
using var directory = new UniqueRef<IDirectory>();
|
|
|
|
|
Assert.Success(fs.OpenDirectory(ref directory.Ref(), "/", OpenDirectoryMode.All));
|
2020-03-04 02:19:11 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Success(directory.Get.Read(out long entriesRead, entries));
|
|
|
|
|
Assert.Equal(0, entriesRead);
|
|
|
|
|
}
|
2020-03-04 02:19:11 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void IDirectoryGetEntryCount_EmptyFs_EntryCountIsZero()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
2020-03-04 02:19:11 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
using var directory = new UniqueRef<IDirectory>();
|
|
|
|
|
Assert.Success(fs.OpenDirectory(ref directory.Ref(), "/", OpenDirectoryMode.All));
|
2020-03-04 02:19:11 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Success(directory.Get.GetEntryCount(out long entryCount));
|
|
|
|
|
Assert.Equal(0, entryCount);
|
|
|
|
|
}
|
2020-03-04 02:19:11 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void IDirectoryRead_AllEntriesAreReturned()
|
|
|
|
|
{
|
|
|
|
|
IFileSystem fs = CreateFileSystem();
|
|
|
|
|
fs.CreateDirectory("/dir");
|
|
|
|
|
fs.CreateDirectory("/dir/dir1");
|
|
|
|
|
fs.CreateFile("/dir/dir1/file1", 0, CreateFileOptions.None);
|
|
|
|
|
fs.CreateFile("/dir/file1", 0, CreateFileOptions.None);
|
|
|
|
|
fs.CreateFile("/dir/file2", 0, CreateFileOptions.None);
|
|
|
|
|
|
|
|
|
|
using var dir = new UniqueRef<IDirectory>();
|
|
|
|
|
Assert.Success(fs.OpenDirectory(ref dir.Ref(), "/dir", OpenDirectoryMode.All));
|
|
|
|
|
|
|
|
|
|
var entry1 = new DirectoryEntry();
|
|
|
|
|
var entry2 = new DirectoryEntry();
|
|
|
|
|
var entry3 = new DirectoryEntry();
|
|
|
|
|
var entry4 = new DirectoryEntry();
|
|
|
|
|
|
|
|
|
|
Assert.Success(dir.Get.Read(out long entriesRead1, SpanHelpers.AsSpan(ref entry1)));
|
|
|
|
|
Assert.Success(dir.Get.Read(out long entriesRead2, SpanHelpers.AsSpan(ref entry2)));
|
|
|
|
|
Assert.Success(dir.Get.Read(out long entriesRead3, SpanHelpers.AsSpan(ref entry3)));
|
|
|
|
|
Assert.Success(dir.Get.Read(out long entriesRead4, SpanHelpers.AsSpan(ref entry4)));
|
|
|
|
|
|
|
|
|
|
Assert.Equal(1, entriesRead1);
|
|
|
|
|
Assert.Equal(1, entriesRead2);
|
|
|
|
|
Assert.Equal(1, entriesRead3);
|
|
|
|
|
Assert.Equal(0, entriesRead4);
|
|
|
|
|
|
|
|
|
|
bool dir1Read = false;
|
|
|
|
|
bool file1Read = false;
|
|
|
|
|
bool file2Read = false;
|
|
|
|
|
|
|
|
|
|
// Entries are not guaranteed to be in any particular order
|
|
|
|
|
CheckEntry(ref entry1);
|
|
|
|
|
CheckEntry(ref entry2);
|
|
|
|
|
CheckEntry(ref entry3);
|
|
|
|
|
|
|
|
|
|
Assert.True(dir1Read);
|
|
|
|
|
Assert.True(file1Read);
|
|
|
|
|
Assert.True(file2Read);
|
|
|
|
|
|
|
|
|
|
void CheckEntry(ref DirectoryEntry entry)
|
2020-01-28 08:55:39 +01:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
switch (StringUtils.Utf8ZToString(entry.Name))
|
2020-01-28 08:55:39 +01:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
case "dir1":
|
|
|
|
|
Assert.False(dir1Read);
|
|
|
|
|
Assert.Equal(DirectoryEntryType.Directory, entry.Type);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
dir1Read = true;
|
|
|
|
|
break;
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
case "file1":
|
|
|
|
|
Assert.False(file1Read);
|
|
|
|
|
Assert.Equal(DirectoryEntryType.File, entry.Type);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
file1Read = true;
|
|
|
|
|
break;
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
case "file2":
|
|
|
|
|
Assert.False(file2Read);
|
|
|
|
|
Assert.Equal(DirectoryEntryType.File, entry.Type);
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
file2Read = true;
|
|
|
|
|
break;
|
2020-01-28 08:55:39 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
2020-01-28 08:55:39 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-12 02:21:07 +01:00
|
|
|
|
}
|