Skip to content

Commit

Permalink
Expand test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik White committed Jan 20, 2024
1 parent 64ef272 commit 15ccf94
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Library/DiscUtils.Wim/WimFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ private DirectoryEntry GetEntry(string path)
path = Path.DirectorySeparatorChar + path;
}

return GetEntry(GetDirectory(0), path.AsMemory().Split(Utilities.PathSeparators).ToArray());
return GetEntry(GetDirectory(0), path.AsMemory().Split('/', '\\').ToArray());
}

private DirectoryEntry GetEntry(List<DirectoryEntry> dir, ReadOnlyMemory<char>[] path)
Expand Down
47 changes: 44 additions & 3 deletions Tests/LibraryTests/Wim/WimFileSystemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,57 @@
namespace LibraryTests.Wim;

public class WinFileSystemTest

{
private static string testDataPath = Path.Combine("..", "..", "LibraryTests", "Wim", "Data", "TestData.wim");

[Fact]
public void ReadRootDirectory()
public void ReadRootDirectoryFiles()
{
using var fileStream = File.OpenRead(Path.Combine("..", "..", "LibraryTests", "Wim", "Data", "TestData.wim"));
using var fileStream = File.OpenRead(testDataPath);
var wimFile = new WimFile(fileStream);
var image = wimFile.GetImage(0);

var files = image.GetFiles(image.Root.FullName, "*.*", SearchOption.AllDirectories).ToList();

Assert.Equal(3, files.Count);
}

[Fact]
public void ReadSubDirectoryFiles()
{
using var fileStream = File.OpenRead(testDataPath);
var wimFile = new WimFile(fileStream);
var image = wimFile.GetImage(0);

var files = image.GetFiles("\\TestData", "*.*", SearchOption.AllDirectories).ToList();

Assert.Equal(3, files.Count);
}

[Fact]
public void ReadFilteredDirectory()
{
const string ExpectedDirectoryPath = "\\TestData\\Foo";

using var fileStream = File.OpenRead(testDataPath);
var wimFile = new WimFile(fileStream);
var image = wimFile.GetImage(0);

var directories = image.GetDirectories(image.Root.FullName, "Foo.*", SearchOption.AllDirectories).ToList();

Assert.Single(directories);
Assert.Equal(ExpectedDirectoryPath, directories[0]);
}

[Fact]
public void ReadFilteredFile()
{
using var fileStream = File.OpenRead(testDataPath);
var wimFile = new WimFile(fileStream);
var image = wimFile.GetImage(0);

var files = image.GetFiles("\\TestData\\Foo", "Lorem.*", SearchOption.AllDirectories).ToList();

Assert.Equal(2, files.Count);
}
}

0 comments on commit 15ccf94

Please sign in to comment.