Something went wrong. Try again.
Brotli (RFC 7932) compression and decompression for Zig 0.17, with sans-I/O streaming cores and std.Io adapters.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! The reference implementation's synthetic streams, each decompressed whole//! and again a byte at a time.
const std = @import("std");const drive = @import("drive.zig");const synth = @import("synth.zig");
test "synthetic streams" { const gpa = std.testing.allocator; var failed: usize = 0; for (synth.cases) |c| { const want = try c.expected(gpa); defer gpa.free(want); // A byte of output at a time is slow for the 16 MiB cases and adds // nothing a few KiB at a time does not. const out_small: usize = if (want.len > 1 << 16) 4093 else 1; const runs = [_][2]usize{ .{ c.compressed.len, want.len + 1 }, .{ 1, out_small }, .{ 3, 7 } }; for (runs) |run| { const got = drive.decompress(gpa, c.compressed, run[0], run[1], if (c.skipped_upstream) .allow else .reject) catch |err| { if (c.ok) { std.debug.print("{s} (in {d}, out {d}): unexpected {t}\n", .{ c.name, run[0], run[1], err }); failed += 1; } continue; }; defer gpa.free(got); if (!c.ok) { std.debug.print("{s} (in {d}, out {d}): accepted an invalid stream\n", .{ c.name, run[0], run[1] }); failed += 1; } else if (!std.mem.eql(u8, got, want)) { std.debug.print("{s} (in {d}, out {d}): wrong output ({d} bytes, want {d})\n", .{ c.name, run[0], run[1], got.len, want.len }); failed += 1; } } } try std.testing.expectEqual(0, failed);}