Some checks failed
nigig-build (CAD) / supply-chain (push) Has been cancelled
nigig-build (CAD) / cad-module (push) Has been cancelled
nigig-build (CAD) / full-crate-check (push) Has been cancelled
nigig-build (CAD) / cad-engine-coverage (push) Has been cancelled
nigig-build (CAD) / doc-workspace-coverage (push) Has been cancelled
nigig-build (CAD) / cad-widget-coverage (push) Has been cancelled
repo hygiene / hygiene (push) Has been cancelled
PDF engine / engine (push) Has been cancelled
PDF engine / makepad-integration (push) Has been cancelled
PDF engine / fuzz (push) Has been cancelled
- pdf-graphics: new cff, truetype, cjk_cmap, disk_cache, document_ai, path, reflow, text_diff modules + port tests (all green); syntax/type fixes for the aarch64 build (stray brace, &u8 derefs, f2dot14 assign). - pdf-document: ocr, pdf_a, xmp modules + roundtrip tests; annotation editor updates. - pdf-makepad: handle RenderCommand::SetOverprint (report via TransparencyError per ADR 0009, no silent drop); renderer/page_view updates for the new recording ops. - matrix_client: nimanyatta native module (ungated; the aarch64 wrapper needs it unconditionally). - pageflipnav home_screen: project_store sync is host-only until cad-ui's Widget Script derive is fixed for aarch64. Verified: cargo check on all four crates clean at fork 66cc4f15f; nigig-pdf-graphics tests pass; pageflipnav aarch64 release links.
69 lines
No EOL
2.9 KiB
Rust
69 lines
No EOL
2.9 KiB
Rust
//! Phase 9 exit criterion: XMP metadata round-trip through a real document.
|
|
//!
|
|
//! The unit tests in `xmp.rs` parse hand-built packets. These go through the
|
|
//! whole write→parse pipeline: a document is built with an XMP packet in its
|
|
//! catalogue `/Metadata` stream, written, re-parsed, and the metadata is read
|
|
//! back off the catalogue — proving the `read_xmp` path navigates the real
|
|
//! trailer→catalog→stream→decode chain, not just the parser.
|
|
//!
|
|
//! See `REVIEWS/adr/0039-pdf-xmp-and-conformance-decisions.md`.
|
|
|
|
use nigig_pdf_cos::writer::PdfDocBuilder;
|
|
use nigig_pdf_document::xmp::XmpMetadata;
|
|
use nigig_pdf_document::PdfDocument;
|
|
|
|
fn sample() -> XmpMetadata {
|
|
XmpMetadata {
|
|
title: Some("XMP Round Trip".into()),
|
|
creators: vec!["Grace Hopper".into(), "Ada Lovelace".into()],
|
|
description: Some("A document with metadata in XMP.".into()),
|
|
keywords: vec!["compiler".into(), "navy".into()],
|
|
creator_tool: Some("Nigig Test".into()),
|
|
producer: Some("nigig-pdf".into()),
|
|
creation_date: Some("2026-09-05T09:30:00Z".into()),
|
|
mod_date: Some("2026-09-05T10:00:00Z".into()),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn xmp_metadata_round_trips_through_a_built_document() {
|
|
let mut builder = PdfDocBuilder::new();
|
|
builder.add_page(100.0, 100.0, b"");
|
|
builder.set_xmp_metadata(sample().to_packet());
|
|
let pdf = builder.finish();
|
|
|
|
let mut doc = PdfDocument::parse(&pdf).expect("parses");
|
|
let read = doc.xmp_metadata().expect("reads metadata");
|
|
|
|
let xmp = read.expect("catalogue has /Metadata");
|
|
assert_eq!(xmp.title.as_deref(), Some("XMP Round Trip"));
|
|
assert_eq!(xmp.creators, vec!["Grace Hopper", "Ada Lovelace"]);
|
|
assert_eq!(xmp.description.as_deref(), Some("A document with metadata in XMP."));
|
|
assert_eq!(xmp.keywords, vec!["compiler", "navy"]);
|
|
assert_eq!(xmp.creator_tool.as_deref(), Some("Nigig Test"));
|
|
assert_eq!(xmp.producer.as_deref(), Some("nigig-pdf"));
|
|
assert_eq!(xmp.creation_date.as_deref(), Some("2026-09-05T09:30:00Z"));
|
|
assert_eq!(xmp.mod_date.as_deref(), Some("2026-09-05T10:00:00Z"));
|
|
}
|
|
|
|
#[test]
|
|
fn a_document_without_metadata_returns_none_not_error() {
|
|
let mut builder = PdfDocBuilder::new();
|
|
builder.add_page(100.0, 100.0, b"");
|
|
let pdf = builder.finish();
|
|
|
|
let mut doc = PdfDocument::parse(&pdf).expect("parses");
|
|
let read = doc.xmp_metadata().expect("reads metadata");
|
|
assert!(read.is_none(), "no /Metadata means Ok(None), not an error");
|
|
}
|
|
|
|
#[test]
|
|
fn the_packet_bridges_onto_document_info() {
|
|
let info = sample().to_document_info();
|
|
assert_eq!(info.title.as_deref(), Some("XMP Round Trip"));
|
|
assert_eq!(info.author.as_deref(), Some("Grace Hopper"));
|
|
assert_eq!(info.subject.as_deref(), Some("A document with metadata in XMP."));
|
|
assert_eq!(info.keywords.as_deref(), Some("compiler, navy"));
|
|
assert_eq!(info.producer.as_deref(), Some("nigig-pdf"));
|
|
assert_eq!(info.creator.as_deref(), Some("Nigig Test"));
|
|
} |