|
1 | 1 | using System; |
2 | | -using System.Collections.Generic; |
3 | 2 | using System.IO; |
4 | | -using System.Linq; |
5 | 3 | using System.Security.Cryptography; |
6 | 4 | using System.Text; |
7 | 5 |
|
@@ -71,5 +69,102 @@ public void Invalid_Header_Should_Throw_Errors() |
71 | 69 | Assert.That(Assert.Throws<InvalidOperationException>(() => IntegrityHelper.DecompressData(compressed)).Message, Is.EqualTo("Invalid flag combination. Try to use newer version of Blazer")); |
72 | 70 | compressed[6]--; |
73 | 71 | } |
| 72 | + |
| 73 | + [Test] |
| 74 | + [TestCase(1, BlazerAlgorithm.NoCompress)] |
| 75 | + [TestCase(1, BlazerAlgorithm.Stream)] |
| 76 | + [TestCase(1, BlazerAlgorithm.Block)] |
| 77 | + [TestCase(2, BlazerAlgorithm.NoCompress)] |
| 78 | + [TestCase(2, BlazerAlgorithm.Stream)] |
| 79 | + [TestCase(2, BlazerAlgorithm.Block)] |
| 80 | + [TestCase(3, BlazerAlgorithm.NoCompress)] |
| 81 | + [TestCase(3, BlazerAlgorithm.Stream)] |
| 82 | + [TestCase(3, BlazerAlgorithm.Block)] |
| 83 | + [TestCase(4, BlazerAlgorithm.NoCompress)] |
| 84 | + [TestCase(4, BlazerAlgorithm.Stream)] |
| 85 | + [TestCase(4, BlazerAlgorithm.Block)] |
| 86 | + public void Small_Block_Sizes_ShouldBe_Handled_WithoutFlush(int blockSize, BlazerAlgorithm algorithm) |
| 87 | + { |
| 88 | + var data = new byte[blockSize]; |
| 89 | + data[0] = (byte)blockSize; |
| 90 | + var blazerCompressionOptions = BlazerCompressionOptions.CreateStream(); |
| 91 | + blazerCompressionOptions.SetEncoderByAlgorithm(algorithm); |
| 92 | + |
| 93 | + var memoryStream = new MemoryStream(); |
| 94 | + const int Count = 10; |
| 95 | + using (var stream = new BlazerInputStream(memoryStream, blazerCompressionOptions)) |
| 96 | + { |
| 97 | + for (var i = 0; i < Count; i++) |
| 98 | + stream.Write(data, 0, data.Length); |
| 99 | + } |
| 100 | + |
| 101 | + var compressed = memoryStream.ToArray(); |
| 102 | + var decompressed = IntegrityHelper.DecompressData(compressed); |
| 103 | + Assert.That(decompressed.Length, Is.EqualTo(Count * data.Length)); |
| 104 | + } |
| 105 | + |
| 106 | + [Test] |
| 107 | + [TestCase(1, BlazerAlgorithm.NoCompress)] |
| 108 | + [TestCase(1, BlazerAlgorithm.Stream)] |
| 109 | + [TestCase(1, BlazerAlgorithm.Block)] |
| 110 | + [TestCase(2, BlazerAlgorithm.NoCompress)] |
| 111 | + [TestCase(2, BlazerAlgorithm.Stream)] |
| 112 | + [TestCase(2, BlazerAlgorithm.Block)] |
| 113 | + [TestCase(3, BlazerAlgorithm.NoCompress)] |
| 114 | + [TestCase(3, BlazerAlgorithm.Stream)] |
| 115 | + [TestCase(3, BlazerAlgorithm.Block)] |
| 116 | + [TestCase(4, BlazerAlgorithm.NoCompress)] |
| 117 | + [TestCase(4, BlazerAlgorithm.Stream)] |
| 118 | + [TestCase(4, BlazerAlgorithm.Block)] |
| 119 | + public void Small_Block_Sizes_ShouldBe_Handled_WithFlush(int blockSize, BlazerAlgorithm algorithm) |
| 120 | + { |
| 121 | + var data = new byte[blockSize]; |
| 122 | + data[0] = (byte)blockSize; |
| 123 | + var blazerCompressionOptions = BlazerCompressionOptions.CreateStream(); |
| 124 | + blazerCompressionOptions.SetEncoderByAlgorithm(algorithm); |
| 125 | + blazerCompressionOptions.RespectFlush = true; |
| 126 | + |
| 127 | + var memoryStream = new MemoryStream(); |
| 128 | + const int Count = 10; |
| 129 | + using (var stream = new BlazerInputStream(memoryStream, blazerCompressionOptions)) |
| 130 | + { |
| 131 | + for (var i = 0; i < Count; i++) |
| 132 | + { |
| 133 | + stream.Write(data, 0, data.Length); |
| 134 | + stream.Flush(); |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + var compressed = memoryStream.ToArray(); |
| 139 | + var decompressed = IntegrityHelper.DecompressData(compressed); |
| 140 | + Assert.That(decompressed.Length, Is.EqualTo(Count * data.Length)); |
| 141 | + Assert.That(decompressed[blockSize], Is.EqualTo(blockSize)); |
| 142 | + } |
| 143 | + |
| 144 | + [Test] |
| 145 | + [TestCase(BlazerAlgorithm.NoCompress)] |
| 146 | + [TestCase(BlazerAlgorithm.Stream)] |
| 147 | + [TestCase(BlazerAlgorithm.Block)] |
| 148 | + public void Zero_Block_Sizes_Should_Not_Cause_Error(BlazerAlgorithm algorithm) |
| 149 | + { |
| 150 | + var data = new byte[0]; |
| 151 | + var blazerCompressionOptions = BlazerCompressionOptions.CreateStream(); |
| 152 | + blazerCompressionOptions.SetEncoderByAlgorithm(algorithm); |
| 153 | + |
| 154 | + var memoryStream = new MemoryStream(); |
| 155 | + const int Count = 10; |
| 156 | + using (var stream = new BlazerInputStream(memoryStream, blazerCompressionOptions)) |
| 157 | + { |
| 158 | + for (var i = 0; i < Count; i++) |
| 159 | + { |
| 160 | + stream.Write(data, 0, data.Length); |
| 161 | + stream.Flush(); |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + var compressed = memoryStream.ToArray(); |
| 166 | + var decompressed = IntegrityHelper.DecompressData(compressed); |
| 167 | + Assert.That(decompressed.Length, Is.EqualTo(0)); |
| 168 | + } |
74 | 169 | } |
75 | 170 | } |
0 commit comments