Files
craft-libs/crates/prc/tests/proptests.rs
Dylan M. Taylor 7db4645d1f Add craft-prc: the PRC 3D model reader from PdfCraft (#945)
PdfCraft's pdfcraft-prc crate (revision
80e26e674d1aa33078e83c8139875047f3289eb6), moved whole with its tests. It reads
PRC (ISO 14739-1), the model format of PDF 3D annotations: the container, the
bit-level primitives, the schema, tessellations and the product tree.

The code is unchanged. The package and its README are renamed, the doctests
and tests import craft_prc, and the Double code table taken from prc-rs (MIT)
has its row in ATTRIBUTION.md and its licence in licenses/prc-rs.
2026-11-11 18:55:20 -05:00

42 lines
1.4 KiB
Rust

//! Arbitrary bytes through every reader: an error or a value, never a panic.
use craft_prc::{BitReader, PrcFile, Schema};
use proptest::prelude::*;
proptest! {
#[test]
fn any_bytes_parse_or_fail_cleanly(data in proptest::collection::vec(any::<u8>(), 0..512), magic in any::<bool>()) {
let mut data = data;
if magic && data.len() >= 3 {
data[..3].copy_from_slice(b"PRC");
}
let _ = PrcFile::parse_with_limit(&data, 1 << 20);
}
#[test]
fn any_bits_read_or_fail_cleanly(data in proptest::collection::vec(any::<u8>(), 0..64), n in 0u32..40) {
let mut r = BitReader::new(&data);
let _ = r.unsigned_integer();
let _ = r.integer();
let _ = r.integer_vbn(n);
let _ = r.double_vbn(0.5, n);
let _ = r.nbits_then_unsigned();
let _ = r.string();
let _ = r.float_as_bytes();
let _ = r.double();
let _ = r.skip_bits(usize::try_from(n).unwrap_or(0));
prop_assert!(r.position() <= data.len() * 8);
}
#[test]
fn any_schema_runs_or_fails_cleanly(data in proptest::collection::vec(any::<u8>(), 0..256), entity in 0u32..4) {
let mut r = BitReader::new(&data);
if let Ok(schema) = Schema::read(&mut r) {
let types: Vec<u32> = schema.entity_types().chain([entity]).collect();
for t in types {
let _ = schema.skip_added_fields(t, &mut r.clone());
}
}
}
}