Expand description
Conformance test harness for zencodec codec implementations.
A codec crate adds this as a dev-dependency and runs the check_*
functions against its own EncoderConfig / DecoderConfig to verify it
honors the shared contract — especially the parts that are easy to get
subtly wrong and expensive to ship wrong:
check_metadata_no_leak— aMetadataPolicymust never leak what it discards. The privacy guarantee.check_cross_path_pixel_equivalence— every still encode/decode path (one-shot,push_rows+ pullencode_fromencode; one-shot, push-sink, streaming decode) must produce identical pixels.check_animation_cross_path_equivalence— every animation decode path (borrowed, owned, push-sink) must yield identical frames, matching the input.check_orientation_roundtrip— an orientation survives a keeping policy exactly once (no loss, no double-application).check_color_context_consistency— whateverColorContexta decoder attaches to its output buffers is class-valid (an ICC only rides a layout its device class describes) and identical across the one-shot, streaming, and animation (borrowed + owned) paths — strip/scratch buffers are where a context silently dies. Lenient about whether one is attached;check_color_context_attachedis the strict, opt-in positive direction (a decoder that read colour back must attach it).check_color_authority_spec— theColorAuthoritya decoder names insource_coloris the one its format’s spec assigns for the colour fields it read back (PNG/JXL/HEIC: CICP outranks ICC; AVIF: MIAF order; the rest: ICC).check_source_color_authorityis the unit form for a codec’s own fixtures,expected_color_authoritythe answer key.check_native_hdr_roundtrip— when both ends declarehdr, BT.2100 PQ and HLG survive aPreserveExactround trip: the CICP, the HDR envelope (content light level + mastering display), 16-bit pixels where both ends are natively 16-bit, and the decoded buffer is labelled PQ/HLG rather than sRGB. Phase 0 of the gain-map/HDR delivery scope.check_gain_map_roundtrip— the gain-map encode/decode contract: an undeclared encoder rejectswith_gain_map_pixelsloudly withUnsupportedOperation::GainMapEncode; a declared one embeds 1- and 3-channel maps (forward and backward direction) that a declared decoder reports fromprobe(), surfaces only on request (Components/with_extract_gain_map), never under the defaultBaseOnly, falls back honestly onReconstructHdrwithoutreconstructs_hdr, and that survive a decode →with_gain_map_pixelstranscode. Phases 1, 2 (test matrix) and 4 (the testkit cross-path check) of that scope.check_fidelity_honesty—resolved_target_fidelity()tells the truth: a declaredlosslesshonours aLosslessrequest byte-exactly, a codec withoutlossynever reportsLossy(it promotes and says so), a codec withlossynever answers a lossy request withLossless, and the legacyis_lossless()agrees. The cross-codecFidelitycontract.check_inventory— a declared structural inventory covers every byte, reports appended junk as unconsumed, and survives every truncation.check_capability_honesty— every declared capability works and every undeclared optional path cleanly returnsUnsupportedOperation. Both directions for the structural paths and (where the decoder can observe them) the metadata channels, so a codec can’t claim a feature it lacks or hide one it has; see the fn docs for the exact per-flag scope.check_decode_error_envelope/assert_uses_codec_error_envelope— a codec’sErrorCategoryand codec name survive dyn-dispatch type erasure (theAt<CodecError>envelope contract). Opt-in, and not incheck_all: only for codecs that return the envelopetype Error(the testkit’s ownreferenceis a Pattern-A foil that deliberately fails it).check_decode_truncation_series— a truncated (incomplete) input must categorize as an incomplete-input category (never anInternal5xx, anOutOfMemory, anIoerror, or a caller-fault), and must never panic or silently decode a truncated header. Enforces the one part of the taxonomy that is broadly distinguishable. Opt-in, not incheck_all; on the dyn-erased path a Pattern-A codec fails it the same way the envelope check does (the allowed/denied category policy is documented oncheck_decode_truncation_series).
check_all runs them all with default inputs — the one-call entry point.
The reference module ships a faithful codec (declares and
honors every capability) the harness is validated against — it doubles as a
worked example; an internal minimal codec (every optional capability
declared false) validates the false-direction branches.
Re-exports§
pub use reference::RefError;pub use reference::ReferenceDecoderConfig;pub use reference::ReferenceEncoderConfig;pub use reference::ReferenceZcrDecoderConfig;pub use reference::ZCR_FORMAT;
Modules§
- reference
- A faithful in-memory reference codec.
Structs§
- Failure
- A conformance-check failure, naming the check and a human-readable detail.
- Prefix
Case - A meaningful prefix boundary, not a fraction of the total file length.
- Test
Image - A deterministic test image with contiguous (tightly-packed) rows.
- Timing
Case - One frame submission and its independent encoded result. Accepted frames have an expected native decode representation; this can differ from input for an explicitly lossy encode. Use distinct pixels to expose frame reordering.
Enums§
- Expected
Error - A specific error that constitutes an expected refusal.
- Prefix
Outcome - Caller-specified expected result at a structural prefix boundary.
Functions§
- assert_
uses_ codec_ error_ envelope - Statically assert a codec returns the shared
At<CodecError>envelope from every encode/decode trait boundary — the Pattern-B error contract. - check_
all - Run every conformance check with sensible default inputs, returning the first
failure. The one-call entry point for a codec’s test suite; for control over
image sizes or animation frames, call the individual
check_*functions. - check_
animation_ cases - Strict counterpart to
check_animation_timing: requires typed errors and verifies independently specified frame pixels, as well as duration and index. Accepted frames on both sides of a rejection expose timing/state corruption. - check_
animation_ cross_ path_ equivalence - Every animation decode path yields identical frames, matching the input.
- check_
animation_ durations - Verify source timing through borrowed, owned and erased animation decoders.
expectednames every displayed frame; zero-duration compositing helpers belong in the codec fixture’s expected display sequence, not an inferred count. The sink API returns onlyOutputInfo, so cannot expose frame timing. - check_
animation_ streaming_ output_ honesty - Verify the
AnimationOutputTimingan animation encoder’sbeginreports. - check_
animation_ timing - Exercise exact or ordinary timing through both generic and erased encoders.
Each pair is
(requested, expected_encoded);Nonerequires rejection. Include accepted frames before and after rejected inputs to detect state mutation. Expected rounded durations must come from the destination clock, independently of the codec/quantizer under test. At least two must succeed. For exact mode each successful duration must equal its request. - check_
animation_ timing_ unsupported - Verify the conservative compatibility default for an animation adapter that
has not adopted rational encoding. Both timing methods must reject with
AnimationTiming, leave buffered frames intact, and allow legacy encoding to continue. A false timing capability must not silently quantize requests. - check_
capability_ honesty - Declared capabilities match real behavior.
- check_
color_ authority_ spec - Decoded colour authority follows the format spec on every metadata mix.
- check_
color_ context_ attached - A decoder that read colour back attaches it to the output buffer — the strict, positive direction of the decoded-buffer convention.
- check_
color_ context_ consistency - Whatever [
ColorContext] a decoder attaches to its output pixels is class-valid and the same on every decode path. - check_
cross_ path_ pixel_ equivalence - Every advertised feeding mode produces identical pixels.
- check_
decode_ error_ envelope - A codec’s
ErrorCategoryand originating codec name survive dyn-dispatch type erasure — the runtime half of the Pattern-B contract. - check_
decode_ policy_ admission - Verify checked decode-policy admission, typed rejection, and unchanged output after rejection. Supply explicit expected metadata to test supported metadata denials. All paths decode the same caller-provided fixture.
- check_
decode_ prefix_ cases - Exercise explicit complete-payload/truncation boundaries through one-shot and sink dispatch. Successful recovery must produce the expected pixels. The caller supplies strict/compatibility configuration separately. No prefix is silently omitted; out-of-range fixture boundaries are errors.
- check_
decode_ truncation_ series - A truncated (incomplete) input is categorized as incomplete client data — never mis-attributed as an internal bug, an OOM, an I/O error, or a caller fault — and never panics or silently decodes.
- check_
encode_ policy_ admission - Verify checked encode-policy admission and rejection atomicity.
initialmust be supported;requestmust matchaccepted. Decode observations must equalexpectedmetadata, making preservation and denial explicit instead of treating a successful setter as proof of delivery.metadatais the unfiltered input. Color/fidelity observations remain codec-specific. - check_
fidelity_ honesty - The resolved
Fidelityreport is honest against the declared capabilities and against the pixels that actually come back. - check_
gain_ map_ roundtrip - The gain-map encode/decode contract (
docs/gainmap-pipeline-scope-2026-06-08.mdPhases 1, 2 and 4, tracked in zencodec#24), for every declared/undeclared combination ofEncodeCapabilities::gain_mapandDecodeCapabilities::gain_map: - check_
incremental_ capability_ honesty - Verify the
incrementalcapability flag in both directions, then runcheck_incremental_contracton a declared incremental decoder. - check_
incremental_ contract - Exercise a decoder’s
IncrementalDecodecontract through the erased decoder callers receive (dyn_incremental_decoder), against the one-shot pixels ofdata: - check_
incremental_ decoder check_incremental_contractfor any decoder factory, againstone_shot, the decoder’s one-shot decode of any bytes: for incremental decoders not reached through a codec’sDecoderConfig, such as one built withzencodec::helpers::WholeFileIncremental.- check_
inventory - The structural inventory is honest and complete.
- check_
inventory_ dispatch - Check inventory parity through generic and dynamic dispatch under the same
configuration. Unlike
check_all, erased config dispatch requires a'staticconfig. Native error types need no additional bounds. - check_
inventory_ input_ limit - Verify the inventory input-byte boundary and typed errors in both dispatch
paths. This is opt-in for inventory-enabled builds; disabled builds use
check_inventory_dispatch. It does not equate a part cap with a memory cap. - check_
metadata_ no_ leak - A retention policy never leaks what it discards.
- check_
metadata_ rewrite - Exercise a codec’s metadata-only rewrite entry point with caller-owned fixtures. The observer must independently verify image payloads, timing, rendering metadata and requested retention (prefer a third-party reader). Checks plan materialization, report ranges, deterministic output, typed input, output and carrier limits, and pre-cancellation. Services are retained.
- check_
native_ hdr_ roundtrip - Native HDR survives a round trip: for BT.2100 PQ and HLG, the CICP,
the HDR envelope (content light level + mastering display), the pixels, and
the decoded buffer’s HDR labelling all come back from a
PreserveExactencode → decode. - check_
orientation_ roundtrip - The displayed image is preserved through a policy that keeps orientation.
- check_
pixel_ roundtrip - A round trip through one-shot encode → one-shot decode reproduces the input pixels exactly. The smallest sanity check; a failure here means nothing else is trustworthy.
- check_
read_ at_ contract - Verify a
DynReadAtdriver source against the bytes it claims to serve: length, exact reads at the edges and middle, one batched out-of-order multi-range read, and an error (never a short or zero-filled read) past the end. - check_
seekable_ capability_ honesty - Verify the
seekablecapability flag in both directions. A decoder declaring it must decodedatathroughpush_decoder_from_sourceover a slice source with the same pixels as the one-shot path; one not declaring it must reject withUnsupportedOperation::SeekableDecode. - check_
source_ color_ authority - A decoded
SourceColornames the authority its format’s spec assigns. - check_
streaming_ output_ honesty - Verify the
OutputTimingan encoder’sbeginreports, andEncodeCapabilities::streaming_outputbehind it. - expected_
color_ authority - The [
ColorAuthority] a format’s specification assigns, given which colour fields the decoder actually read back.
Type Aliases§
- Conformance
- The result of a conformance check.