mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
std.compress.lzma: tests passing
This commit is contained in:
parent
58e60697e2
commit
8523cbef0e
2 changed files with 22 additions and 4 deletions
|
|
@ -696,6 +696,7 @@ pub const Decompress = struct {
|
|||
.vtable = &.{
|
||||
.readVec = readVec,
|
||||
.stream = stream,
|
||||
.discard = discard,
|
||||
},
|
||||
.seek = 0,
|
||||
.end = 0,
|
||||
|
|
@ -746,12 +747,22 @@ pub const Decompress = struct {
|
|||
return readIndirect(r);
|
||||
}
|
||||
|
||||
fn discard(r: *Reader, limit: std.Io.Limit) Reader.Error!usize {
|
||||
const d: *Decompress = @alignCast(@fieldParentPtr("reader", r));
|
||||
_ = d;
|
||||
_ = limit;
|
||||
@panic("TODO");
|
||||
}
|
||||
|
||||
fn readIndirect(r: *Reader) Reader.Error!usize {
|
||||
const d: *Decompress = @alignCast(@fieldParentPtr("reader", r));
|
||||
const gpa = d.gpa;
|
||||
var allocating = Writer.Allocating.initOwnedSlice(gpa, r.buffer);
|
||||
allocating.writer.end = r.end;
|
||||
defer r.end = allocating.writer.end;
|
||||
defer {
|
||||
r.buffer = allocating.writer.buffer;
|
||||
r.end = allocating.writer.end;
|
||||
}
|
||||
if (d.decode.state == math.maxInt(usize)) return error.EndOfStream;
|
||||
d.decode.process(d.input, &allocating, &d.buffer, &d.range_decoder) catch |err| switch (err) {
|
||||
error.WriteFailed => {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,14 @@ fn testDecompressEqual(expected: []const u8, compressed: []const u8) !void {
|
|||
}
|
||||
|
||||
fn testDecompressError(expected: anyerror, compressed: []const u8) !void {
|
||||
return std.testing.expectError(expected, testDecompress(compressed));
|
||||
const gpa = std.testing.allocator;
|
||||
var stream: std.Io.Reader = .fixed(compressed);
|
||||
|
||||
var decompressor = try lzma.Decompress.initOptions(&stream, gpa, &.{}, .{}, std.math.maxInt(u32));
|
||||
defer decompressor.deinit();
|
||||
|
||||
try std.testing.expectError(error.ReadFailed, decompressor.reader.allocRemaining(gpa, .unlimited));
|
||||
try std.testing.expectEqual(expected, decompressor.err orelse return error.TestFailed);
|
||||
}
|
||||
|
||||
test "decompress empty world" {
|
||||
|
|
@ -76,14 +83,14 @@ test "known size with end of payload marker" {
|
|||
|
||||
test "too big uncompressed size in header" {
|
||||
try testDecompressError(
|
||||
error.CorruptInput,
|
||||
error.DecompressedSizeMismatch,
|
||||
@embedFile("testdata/bad-too_big_size-with_eopm.lzma"),
|
||||
);
|
||||
}
|
||||
|
||||
test "too small uncompressed size in header" {
|
||||
try testDecompressError(
|
||||
error.CorruptInput,
|
||||
error.DecompressedSizeMismatch,
|
||||
@embedFile("testdata/bad-too_small_size-without_eopm-3.lzma"),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue