| 87 | }; |
| 88 | |
| 89 | void SC::ZLibStreamTest::syncCompression(ZLibStream::Algorithm compressionAlgorithm, const StringView inputString, |
| 90 | const Span<const uint8_t> compressedReference) |
| 91 | { |
| 92 | ZLibStream compressor; |
| 93 | SC_TEST_EXPECT(compressor.init(compressionAlgorithm)); |
| 94 | |
| 95 | const size_t halfStringLength = inputString.sizeInBytes() / 2; |
| 96 | |
| 97 | char writableBufferData[32]; |
| 98 | Span<char> writableBuffer = writableBufferData; |
| 99 | |
| 100 | // Process first half of the input data |
| 101 | Span<const char> sourceData; |
| 102 | SC_TEST_EXPECT(inputString.toCharSpan().sliceStartLength(0, halfStringLength, sourceData)); |
| 103 | Span<char> destination = writableBuffer; |
| 104 | SC_TEST_EXPECT(compressor.process(sourceData, destination)); |
| 105 | SC_TEST_EXPECT(sourceData.empty()); |
| 106 | |
| 107 | // Process second half of the input data, but only give a single byte of additional output space |
| 108 | SC_TEST_EXPECT(inputString.toCharSpan().sliceStart(halfStringLength, sourceData)); |
| 109 | Span<char> singleByte; |
| 110 | SC_TEST_EXPECT(destination.sliceStartLength(0, 1, singleByte)); |
| 111 | SC_TEST_EXPECT(compressor.process(sourceData, singleByte)); |
| 112 | SC_TEST_EXPECT(destination.sliceStart(1 - singleByte.sizeInBytes(), destination)); |
| 113 | SC_TEST_EXPECT(sourceData.empty()); |
| 114 | |
| 115 | // Try finalizing with a single byte of additional space, but the stream should not end |
| 116 | bool streamEnded = false; |
| 117 | SC_TEST_EXPECT(destination.sliceStartLength(0, 1, singleByte)); |
| 118 | SC_TEST_EXPECT(compressor.finalize(singleByte, streamEnded)); |
| 119 | SC_TEST_EXPECT(destination.sliceStart(1 - singleByte.sizeInBytes(), destination)); |
| 120 | SC_TEST_EXPECT(not streamEnded); |
| 121 | |
| 122 | // Now try finalizing with all the remaining space, expecting the stream to end |
| 123 | SC_TEST_EXPECT(compressor.finalize(destination, streamEnded)); |
| 124 | SC_TEST_EXPECT(streamEnded); |
| 125 | |
| 126 | // Check that the output is same as expected |
| 127 | Span<char> output; |
| 128 | SC_TEST_EXPECT(detail::sliceFromStartUntil(writableBuffer, destination, output)); |
| 129 | if (compressionAlgorithm == ZLibStream::CompressGZip and output.sizeInBytes() > 9 and |
| 130 | compressedReference.sizeInBytes() > 9) |
| 131 | { |
| 132 | output[9] = static_cast<char>(compressedReference[9]); // Operating System ID will differ on different OS. |
| 133 | } |
| 134 | SC_TEST_EXPECT(memcmpSpans(compressedReference, output)); |
| 135 | } |
| 136 | |
| 137 | void SC::ZLibStreamTest::syncDecompression(ZLibStream::Algorithm algorithm, const StringView referenceString, |
| 138 | const Span<const uint8_t> compressedReference) |
nothing calls this directly
no test coverage detected