diff --git a/SabreTools.IO.Test/Compression/BZip2Tests.cs b/SabreTools.IO.Test/Compression/BZip2Tests.cs new file mode 100644 index 0000000..e3d0f2b --- /dev/null +++ b/SabreTools.IO.Test/Compression/BZip2Tests.cs @@ -0,0 +1,41 @@ +using System; +using System.IO; +using System.Text; +using SabreTools.IO.Compression.BZip2; +using Xunit; + +namespace SabreTools.IO.Test.Compression +{ + public class BZip2Tests + { + [Fact] + public void BZip2InputStreamTest() + { + string path = Path.Combine(Environment.CurrentDirectory, "TestData", "file-to-compress.bin.bz2"); + Stream input = File.OpenRead(path); + byte[] output = new byte[1024]; + + var bzip = new BZip2InputStream(input); + int actual = bzip.Read(output, 0, output.Length); + bzip.Close(); + + Assert.Equal(125, actual); + string str = Encoding.UTF8.GetString(output, 0, 125); + Assert.Equal("This is just a file that has a known set of hashes to make sure that everything with hashing is still working as anticipated.", str); + } + + [Fact] + public void BZip2OutputStreamTest() + { + string path = Path.Combine(Environment.CurrentDirectory, "TestData", "file-to-compress.bin"); + byte[] input = File.ReadAllBytes(path); + MemoryStream output = new MemoryStream(); + + var bzip = new BZip2OutputStream(output, leaveOpen: true); + bzip.Write(input, 0, input.Length); + bzip.Close(); + + Assert.Equal(122, output.Length); + } + } +} \ No newline at end of file diff --git a/SabreTools.IO.Test/TestData/file-to-compress.bin b/SabreTools.IO.Test/TestData/file-to-compress.bin new file mode 100644 index 0000000..7724139 --- /dev/null +++ b/SabreTools.IO.Test/TestData/file-to-compress.bin @@ -0,0 +1 @@ +This is just a file that has a known set of hashes to make sure that everything with hashing is still working as anticipated. \ No newline at end of file diff --git a/SabreTools.IO.Test/TestData/file-to-compress.bin.bz2 b/SabreTools.IO.Test/TestData/file-to-compress.bin.bz2 new file mode 100644 index 0000000..6d498cc Binary files /dev/null and b/SabreTools.IO.Test/TestData/file-to-compress.bin.bz2 differ