mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-10-26 14:57:54 +03:00
Tests: Add a test for LZMA repetition lengths beyond the distance
This commit is contained in:
parent
68c313dcd9
commit
f47f5ff473
Notes:
sideshowbarker
2024-07-17 17:06:59 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/f47f5ff473 Pull-request: https://github.com/SerenityOS/serenity/pull/18375 Reviewed-by: https://github.com/linusg
@ -9,6 +9,28 @@
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <LibCompress/Lzma.h>
|
||||
|
||||
TEST_CASE(repetition_length_beyond_distance)
|
||||
{
|
||||
// This test exists to ensure correctness when repeating data from the dictionary that has been
|
||||
// written earlier during the same repetition.
|
||||
// While this test case is not large enough to testify how well this is optimized, it may still
|
||||
// be a constellation that is improperly implemented as a whole.
|
||||
|
||||
Array<u8, 21> const compressed {
|
||||
0x5D, // Model properties (lc = 3, lp = 0, pb = 2)
|
||||
0x00, 0x10, 0x00, 0x00, // Dictionary size (4 KB)
|
||||
0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Uncompressed size (7)
|
||||
|
||||
// Encode a literal 'A' and a literal 'B', followed by a repetition from (real) distance 2 with a (real) length of 5.
|
||||
0x00, 0x20, 0x90, 0x9F, 0x04, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
auto stream = MUST(try_make<FixedMemoryStream>(compressed));
|
||||
auto decompressor = MUST(Compress::LzmaDecompressor::create_from_container(move(stream)));
|
||||
auto buffer = TRY_OR_FAIL(decompressor->read_until_eof(PAGE_SIZE));
|
||||
EXPECT_EQ("ABABABA"sv.bytes(), buffer.span());
|
||||
}
|
||||
|
||||
// The following tests are based on test files from the LZMA specification, which has been placed in the public domain.
|
||||
// LZMA Specification Draft (2015): https://www.7-zip.org/a/lzma-specification.7z
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user