Skip to content

Commit

Permalink
Add test coverage for strict_aliasing() case
Browse files Browse the repository at this point in the history
  • Loading branch information
scouten-adobe committed Nov 2, 2022
1 parent 856613d commit 6a2ca67
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/tests/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,27 @@ pub(crate) const LOCALIZED_TEXT_EXAMPLE: &str = r#"<rdf:RDF xmlns:rdf="http://ww
</dc:title>
</rdf:Description>
</rdf:RDF>"#;

pub(crate) const INCONSISTENT_RDF: &str = r#"<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<rdf:Description rdf:about='Test:XMPCoreCoverage/kInconsistentRDF'
xmlns:pdf='http://ns.adobe.com/pdf/1.3/'
xmlns:xmp='http://ns.adobe.com/xap/1.0/'
xmlns:dc='http://purl.org/dc/elements/1.1/'>
<pdf:Author>PDF Author</pdf:Author>
<xmp:Author>XMP Author</xmp:Author>
<xmp:Authors>
<rdf:Seq>
<rdf:li>XMP Authors [1]</rdf:li>
</rdf:Seq>
</xmp:Authors>
<dc:creator>
<rdf:Seq>
<rdf:li>DC Creator [1]</rdf:li>
</rdf:Seq>
</dc:creator>
</rdf:Description>
</rdf:RDF>"#;
27 changes: 26 additions & 1 deletion src/tests/xmp_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ mod from_str {
}

mod from_str_with_options {
use crate::{tests::fixtures::*, FromStrOptions, XmpMeta, XmpValue};
use crate::{tests::fixtures::*, FromStrOptions, XmpError, XmpErrorType, XmpMeta, XmpValue};

const NO_META: &str = r#"<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<rdf:Description rdf:about=""
Expand Down Expand Up @@ -289,6 +289,31 @@ mod from_str_with_options {
.is_none());
}

#[test]
fn strict_aliasing_should_fail() {
assert_eq!(
XmpMeta::from_str_with_options(
INCONSISTENT_RDF,
FromStrOptions::default().strict_aliasing()
)
.unwrap_err(),
XmpError {
error_type: XmpErrorType::BadXmp,
debug_message: "Mismatch between alias and base nodes".to_owned()
}
);
}

#[test]
fn strict_aliasing_ignore() {
assert_eq!(
XmpMeta::from_str_with_options(INCONSISTENT_RDF, FromStrOptions::default())
.unwrap()
.to_string(),
"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"XMP Core 6.0.0\"> <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"> <rdf:Description rdf:about=\"Test:XMPCoreCoverage/kInconsistentRDF\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"> <dc:creator> <rdf:Seq> <rdf:li>DC Creator [1]</rdf:li> </rdf:Seq> </dc:creator> </rdf:Description> </rdf:RDF> </x:xmpmeta>"
);
}

#[test]
fn bad_xmp() {
// TXMPMeta::ParseFromBuffer doesn't seem to throw exceptions,
Expand Down

0 comments on commit 6a2ca67

Please sign in to comment.