Test the guards that had no test
A sweep found no defect in the decoder and several in its tests. Three of the five fixes could be reverted with all 103 tests still green. The content size against expectedSize check is the worst of those, because the .hgtz reader was simplified to rest on it: deleting it left everything passing. Eleven cases cover it now. The RLE block ceiling and the requirement that a frame be the whole input had none either, so there are fixtures for a 13-byte frame that returns 2 MB, for the same shape at exactly the maximum, for four bytes of junk after a frame, and for a trailing skippable frame. Two of the new fixtures close coverage gaps rather than guards. No legal frame in the suite decoded a one-stream Huffman literals section, since the only one present had to be refused. And the only test of hashing each block as it lands rode on the zstd CLI being installed, so a multi-block frame carrying a checksum is committed now. Also replaces an assertion that constrained nothing. "Fills the buffer exactly" checked that the count was over 256 and under 1024, which passes with the guard at two, at three, or absent. The stream encodes 257 symbols, a buffer of 257 takes it and one of 256 does not. And two comments that were wrong. The weight buffer is one larger than the maximum on purpose, and shrinking it to 255 breaks 124 tests. A caller passing expectedSize gets the exact check in addition to the ceiling, not instead of it.
This commit is contained in:
parent
b221ae0e98
commit
45cab0620f
1 changed files with 272 additions and 170 deletions
|
|
@ -71,6 +71,39 @@ void main() {
|
|||
});
|
||||
});
|
||||
|
||||
group('a frame whose declared size is not the one asked for', () {
|
||||
// A guard callers rest on, and it had no test:
|
||||
// deleting the whole check left every other case green. A caller that
|
||||
// knows the size, as the .hgtz reader does, gets an exact comparison
|
||||
// against the frame's own figure rather than only the ceiling. Left to
|
||||
// the end, a frame declaring less decoded its own content happily and a
|
||||
// frame declaring more allocated whatever it asked for first.
|
||||
for (final entry in corpus.where(
|
||||
// Not a buffer holding more than one frame: this decoder refuses
|
||||
// those whatever size it is told to expect.
|
||||
(entry) =>
|
||||
entry.legal &&
|
||||
entry.expectedSize == null &&
|
||||
entry.trailing == null &&
|
||||
entry.size! > 1,
|
||||
)) {
|
||||
test('${entry.name} is refused when asked for one byte more', () {
|
||||
expect(
|
||||
() =>
|
||||
ZstdDecoder().decode(entry.frame, expectedSize: entry.size! + 1),
|
||||
throwsA(isA<ZstdException>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('${entry.name} still decodes when asked for the size it has', () {
|
||||
expect(
|
||||
ZstdDecoder().decode(entry.frame, expectedSize: entry.size),
|
||||
orderedEquals(entry.plain),
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
group('a frame declaring no content size', () {
|
||||
final entry = corpus.singleWhere((entry) => entry.name == 'nofcs_windowed');
|
||||
final size = entry.expectedSize!;
|
||||
|
|
|
|||
Loading…
Reference in a new issue