| 135 | } |
| 136 | |
| 137 | void SC::ZLibStreamTest::syncDecompression(ZLibStream::Algorithm algorithm, const StringView referenceString, |
| 138 | const Span<const uint8_t> compressedReference) |
| 139 | { |
| 140 | const Span<const char> reference = compressedReference.reinterpret_as_span_of<const char>(); |
| 141 | |
| 142 | ZLibStream compressor; |
| 143 | SC_TEST_EXPECT(compressor.init(algorithm)); |
| 144 | |
| 145 | char writableBufferData[32]; |
| 146 | Span<char> writableBuffer = writableBufferData; |
| 147 | |
| 148 | // Process first half of the input data |
| 149 | Span<const char> sourceData; |
| 150 | SC_TEST_EXPECT(reference.sliceStartLength(0, reference.sizeInElements() / 2, sourceData)); |
| 151 | Span<char> destination = writableBuffer; |
| 152 | SC_TEST_EXPECT(compressor.process(sourceData, destination)); |
| 153 | SC_TEST_EXPECT(sourceData.empty()); |
| 154 | |
| 155 | // Process second half of the input data, but only give a single byte of additional output space |
| 156 | SC_TEST_EXPECT(reference.sliceStart(reference.sizeInElements() / 2, sourceData)); |
| 157 | Span<char> singleByte; |
| 158 | SC_TEST_EXPECT(destination.sliceStartLength(0, 1, singleByte)); |
| 159 | SC_TEST_EXPECT(compressor.process(sourceData, singleByte)); |
| 160 | SC_TEST_EXPECT(destination.sliceStart(1 - singleByte.sizeInBytes(), destination)); |
| 161 | SC_TEST_EXPECT(singleByte.empty()); // Byte must have been consumed |
| 162 | |
| 163 | // Process all the rest |
| 164 | SC_TEST_EXPECT(compressor.process(sourceData, destination)); |
| 165 | SC_TEST_EXPECT(sourceData.empty()); // All input data consumed |
| 166 | |
| 167 | // Try finalizing with a single byte of additional space, but the stream should not end |
| 168 | bool streamEnded = false; |
| 169 | SC_TEST_EXPECT(compressor.finalize(destination, streamEnded)); |
| 170 | SC_TEST_EXPECT(streamEnded); |
| 171 | |
| 172 | // Check that the output is same as expected |
| 173 | Span<char> output; |
| 174 | SC_TEST_EXPECT(detail::sliceFromStartUntil(writableBuffer, destination, output)); |
| 175 | SC_TEST_EXPECT(StringView(output, false, StringEncoding::Ascii) == referenceString); |
| 176 | } |
| 177 | namespace SC |
| 178 | { |
| 179 | void runZLibStreamTest(SC::TestReport& report) { ZLibStreamTest test(report); } |
nothing calls this directly
no test coverage detected