Skip to content

Commit

Permalink
more testing of out buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
nhz2 committed Jul 27, 2024
1 parent 0cc6399 commit 67ecedc
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 8 deletions.
10 changes: 6 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ include("test_errors.jl")
@test de64compress_bytes(p7zip_64compress(d)) == d
@test_throws DecompressionError de64compress(p7zip_64compress(d)[begin:end-1])

for n in 65536-1000:65536+1000
d = [thing; zeros(UInt8, n); thing]
@test decompress(p7zip_64compress(d)) == d
@test_throws DecompressionError de64compress(p7zip_64compress(d)[begin:end-1])
for n_start in [0, 65536-100, 65536*3]
for n in 65536-400:65536+400
d = [zeros(UInt8, n_start); thing; zeros(UInt8, n); thing]
@test de64compress(p7zip_64compress(d)) == d
@test_throws DecompressionError de64compress(p7zip_64compress(d)[begin:end-1])
end
end

for n in [0:1000; 1000000;]
Expand Down
114 changes: 110 additions & 4 deletions test/test_errors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,121 @@ include("utils.jl")

# LIT_LEN_DIST_OP
@test_throws DecompressionError("unknown len op") decompress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header(
);
bits_dynamic_huffman_header();
[1,1,0,0,0,1,1,1,];
]))
@test_throws DecompressionError("unknown len op") decompress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header(
);
bits_dynamic_huffman_header();
[1,1,0,0,0,1,1,0,];
]))
@test_throws DecompressionError("unknown len op") decompress(bitvector_to_bytes(Bool[
[1,1,0];
[1,1,0,0,0,1,1,1,];
]))
@test_throws DecompressionError("unknown len op") decompress(bitvector_to_bytes(Bool[
[1,1,0];
[1,1,0,0,0,1,1,0,];
]))

# Reading before the beginning of the buffer
@test UInt8[] == decompress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header();
[0,0,0,0,0,0,0,];
]))
@test_throws DecompressionError("cannot read before beginning of out buffer") decompress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header();
[0,0,0,0,0,0,1,];
[0,0,0,0,0,];
]))
@test_throws DecompressionError("cannot read before beginning of out buffer") decompress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header();
[0,0,0,0,0,0,1,];
[1,1,1,1,1,];
bit_digits(0x3FFF,14);
]))
@test fill(0x8F, 4) == decompress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header();
[1,0,1,1,1,1,1,1,]; # lit 8F
[0,0,0,0,0,0,1,];
[0,0,0,0,0,];
[0,0,0,0,0,0,0,];
]))
@test fill(0x8F, 259) == decompress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header();
[1,0,1,1,1,1,1,1,]; # lit 8F
[1,1,0,0,0,1,0,1,];
[0,0,0,0,0,];
[0,0,0,0,0,0,0,];
]))
@test fill(0x8F, 4) == de64compress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header();
[1,0,1,1,1,1,1,1,]; # lit 8F
[1,1,0,0,0,1,0,1,];
bit_digits(0, 16);
[0,0,0,0,0,];
[0,0,0,0,0,0,0,];
]))
@test fill(0x8F, 1+3+0xFFFF) == de64compress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header();
[1,0,1,1,1,1,1,1,]; # lit 8F
[1,1,0,0,0,1,0,1,];
bit_digits(0xFFFF, 16);
[0,0,0,0,0,];
[0,0,0,0,0,0,0,];
]))
@test_throws DecompressionError("cannot read before beginning of out buffer") de64compress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header();
[1,1,0,0,0,1,0,1,];
bit_digits(0, 16);
[0,0,0,0,0,];
[0,0,0,0,0,0,0,];
]))
@test_throws DecompressionError("cannot read before beginning of out buffer") de64compress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header();
[1,1,0,0,0,1,0,1,];
bit_digits(0xFFFF, 16);
[0,0,0,0,0,];
[0,0,0,0,0,0,0,];
]))
@test_throws DecompressionError("cannot read before beginning of out buffer") de64compress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header();
[1,1,0,0,0,1,0,1,];
bit_digits(0xFFFF, 16);
[1,1,1,1,1,];
bit_digits(0x3FFF,14);
[0,0,0,0,0,0,0,];
]))
@test_throws DecompressionError("cannot read before beginning of out buffer") de64compress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header();
[1,1,0,0,0,1,0,1,];
bit_digits(0xFFFF-3, 16);
[1,1,1,1,1,];
bit_digits(0x3FFF,14);
[0,0,0,0,0,0,0,];
]))
@test fill(0x8F, 2^16 + 2^16+2) == de64compress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header();
[1,0,1,1,1,1,1,1,]; # lit 8F
[1,1,0,0,0,1,0,1,];
bit_digits(0xFFFF-3, 16);
[0,0,0,0,0,];
[1,1,0,0,0,1,0,1,];
bit_digits(0xFFFF, 16);
[1,1,1,1,1,];
bit_digits(0x3FFF,14);
[0,0,0,0,0,0,0,];
]))
@test_throws DecompressionError("cannot read before beginning of out buffer") de64compress(bitvector_to_bytes(Bool[
bits_dynamic_huffman_header();
[1,0,1,1,1,1,1,1,]; # lit 8F
[1,1,0,0,0,1,0,1,];
bit_digits(0xFFFF-4, 16);
[0,0,0,0,0,];
[1,1,0,0,0,1,0,1,];
bit_digits(0xFFFF, 16);
[1,1,1,1,1,];
bit_digits(0x3FFF,14);
[0,0,0,0,0,0,0,];
]))

end

0 comments on commit 67ecedc

Please sign in to comment.