Files
sharpcompress/tests/SharpCompress.Test/ReaderTests.cs

53 lines
1.9 KiB
C#
Raw Permalink Normal View History

2015-12-30 11:19:42 +00:00
using System.Collections.Generic;
using System.IO;
using SharpCompress.Common;
2018-04-22 11:19:11 +01:00
using SharpCompress.IO;
2016-09-26 11:49:49 +01:00
using SharpCompress.Readers;
2015-12-30 11:19:42 +00:00
using Xunit;
namespace SharpCompress.Test
{
public class ReaderTests : TestBase
{
protected void Read(string testArchive, CompressionType expectedCompression)
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
Read(testArchive.AsEnumerable(), expectedCompression);
}
protected void Read(IEnumerable<string> testArchives, CompressionType expectedCompression)
{
foreach (var path in testArchives)
{
2018-04-22 11:19:11 +01:00
using (var stream = new NonDisposingStream(new ForwardOnlyStream(File.OpenRead(path)), true))
using (var reader = ReaderFactory.Open(stream, new ReaderOptions()
{
LeaveStreamOpen = true
}))
2015-12-30 11:19:42 +00:00
{
UseReader(this, reader, expectedCompression);
2018-04-22 11:19:11 +01:00
stream.ThrowOnDispose = false;
2015-12-30 11:19:42 +00:00
}
}
}
public static void UseReader(TestBase test, IReader reader, CompressionType expectedCompression)
{
test.ResetScratch();
while (reader.MoveToNextEntry())
{
if (!reader.Entry.IsDirectory)
{
Assert.Equal(reader.Entry.CompressionType, expectedCompression);
2016-09-27 11:08:54 +01:00
reader.WriteEntryToDirectory(test.SCRATCH_FILES_PATH, new ExtractionOptions()
{
ExtractFullPath = true,
Overwrite = true
});
2015-12-30 11:19:42 +00:00
}
}
test.VerifyFiles();
}
}
}