open-standards/wai/wai-rs/tests/scene_map.rs
Transaction Science 6daafc502c wai: scene carriage — WAI worlds, audio scenes and timed media onto ISO/IEC 23090-14 scene description and a USD layer, both ways (work in progress)
wai-rs scene_map (feature scene_map): a bundle (a WWLD world, a WSCN audio
scene, timed media items by content hash) exported as a glTF 2.0 document
with MPEG_media, MPEG_buffer_circular, MPEG_accessor_timed,
MPEG_audio_spatial and MPEG_texture_video, and as a USDA layer of the USD
Core Specification v1.0.1 (prims, translate ops, time samples, asset
references by urn:wai:asset), each carrying the bundle's bytes exactly;
imports read a WAI-written document back to the same bundle (refused
unless re-exporting gives the same bytes) and a foreign one to new WAI
bytes, refused where a value would not carry exactly. Corpus generator
wai_scene_vectors and tests/scene_map.rs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-22 07:43:34 -04:00

41 lines
1.8 KiB
Rust

//! Scene carriage (`extensions/scene-carriage.md`): the committed corpus regenerates byte for
//! byte (every export written, every import read back to its bundle or refused as stated), and
//! the extension's §8 lists the codes the reference reports.
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use wai::scene_map::{corpus, CODES};
fn root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("../live-conformance/scene")
}
fn walk(root: &Path, rel: &str, out: &mut BTreeMap<String, Vec<u8>>) {
for e in std::fs::read_dir(root.join(rel)).unwrap().flatten() {
let name = e.file_name().to_string_lossy().into_owned();
let key = if rel.is_empty() { name } else { format!("{rel}/{name}") };
if e.path().is_dir() {
walk(root, &key, out);
} else if key != "README.md" && key != ".gitattributes" {
out.insert(key, std::fs::read(e.path()).unwrap());
}
}
}
#[test]
fn the_committed_corpus_regenerates_byte_for_byte() {
let mut files = BTreeMap::new();
walk(&root(), "", &mut files);
let inputs: BTreeMap<String, Vec<u8>> = corpus::INPUT_FILES.iter().map(|(p, _)| (p.to_string(), std::fs::read(root().join(p)).unwrap())).collect();
let bad = corpus::verify(&files, &inputs);
assert!(bad.is_empty(), "{bad:#?}");
}
#[test]
fn the_extension_lists_every_code_the_reference_reports() {
let text = std::fs::read_to_string(Path::new(env!("CARGO_MANIFEST_DIR")).join("../extensions/scene-carriage.md")).unwrap();
let sec = text.split("\n## 8.").nth(1).expect("§8").split("\n## ").next().unwrap();
let listed: Vec<&str> = sec.lines().filter_map(|l| l.strip_prefix("| `")).filter_map(|l| l.split('`').next()).collect();
assert_eq!(listed, CODES, "§8's table, in order");
}