From 6d84ab8fd66cb250b32302794b3ac2c685ebf295 Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 29 Nov 2024 00:48:42 +0000 Subject: [PATCH] Verbose assertions for is_none() --- internal/crypto/src/tests/ocsp.rs | 2 +- sdk/examples/v2api.rs | 2 +- sdk/src/asset_handlers/gif_io.rs | 2 +- sdk/src/asset_handlers/mp3_io.rs | 2 +- sdk/src/asset_handlers/pdf.rs | 2 +- sdk/src/asset_handlers/pdf_io.rs | 2 +- sdk/src/builder.rs | 12 ++++---- sdk/src/ingredient.rs | 46 +++++++++++++++---------------- sdk/src/jumbf/labels.rs | 2 +- sdk/src/manifest.rs | 18 ++++++------ sdk/src/manifest_store.rs | 12 ++++---- sdk/src/store.rs | 2 +- sdk/tests/v2_api_integration.rs | 2 +- 13 files changed, 53 insertions(+), 53 deletions(-) diff --git a/internal/crypto/src/tests/ocsp.rs b/internal/crypto/src/tests/ocsp.rs index f67a2e7bf..2167161cd 100644 --- a/internal/crypto/src/tests/ocsp.rs +++ b/internal/crypto/src/tests/ocsp.rs @@ -30,7 +30,7 @@ fn good() { let ocsp_data = OcspResponse::from_der_checked(rsp_data, Some(test_time), &mut validation_log).unwrap(); - assert!(ocsp_data.revoked_at.is_none()); + assert_eq!(ocsp_data.revoked_at, None); assert!(ocsp_data.ocsp_certs.is_some()); } diff --git a/sdk/examples/v2api.rs b/sdk/examples/v2api.rs index ac2dd503e..540292a6d 100644 --- a/sdk/examples/v2api.rs +++ b/sdk/examples/v2api.rs @@ -151,7 +151,7 @@ fn main() -> Result<()> { } println!("{}", reader.json()); - assert!(reader.validation_status().is_none()); + assert_eq!(reader.validation_status(), None); assert_eq!(reader.active_manifest().unwrap().title().unwrap(), title); Ok(()) diff --git a/sdk/src/asset_handlers/gif_io.rs b/sdk/src/asset_handlers/gif_io.rs index b1c165418..8c5bba258 100644 --- a/sdk/src/asset_handlers/gif_io.rs +++ b/sdk/src/asset_handlers/gif_io.rs @@ -1459,7 +1459,7 @@ mod tests { let gif_io = GifIO {}; - assert!(gif_io.read_xmp(&mut stream).is_none()); + assert_eq!(gif_io.read_xmp(&mut stream), None); let mut output_stream1 = Cursor::new(Vec::with_capacity(SAMPLE1.len())); gif_io.embed_reference_to_stream( diff --git a/sdk/src/asset_handlers/mp3_io.rs b/sdk/src/asset_handlers/mp3_io.rs index 371f9e6c0..0fd28f955 100644 --- a/sdk/src/asset_handlers/mp3_io.rs +++ b/sdk/src/asset_handlers/mp3_io.rs @@ -592,7 +592,7 @@ pub mod tests { let mp3_io = Mp3IO::new("mp3"); let mut stream = File::open(fixture_path("sample1.mp3"))?; - assert!(mp3_io.read_xmp(&mut stream).is_none()); + assert_eq!(mp3_io.read_xmp(&mut stream), None); stream.rewind()?; let mut output_stream1 = Cursor::new(Vec::new()); diff --git a/sdk/src/asset_handlers/pdf.rs b/sdk/src/asset_handlers/pdf.rs index 96d290c89..370b1ee96 100644 --- a/sdk/src/asset_handlers/pdf.rs +++ b/sdk/src/asset_handlers/pdf.rs @@ -740,7 +740,7 @@ mod tests { #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_read_xmp_on_pdf_with_none() { let pdf = Pdf::from_bytes(include_bytes!("../../tests/fixtures/basic-no-xmp.pdf")).unwrap(); - assert!(pdf.read_xmp().is_none()); + assert_eq!(pdf.read_xmp(), None); } #[cfg_attr(not(target_arch = "wasm32"), test)] diff --git a/sdk/src/asset_handlers/pdf_io.rs b/sdk/src/asset_handlers/pdf_io.rs index a56e35fb2..0210b611a 100644 --- a/sdk/src/asset_handlers/pdf_io.rs +++ b/sdk/src/asset_handlers/pdf_io.rs @@ -199,7 +199,7 @@ pub mod tests { mock_pdf.expect_read_xmp().returning(|| None); let pdf_io = PdfIO::new("pdf"); - assert!(pdf_io.read_xmp_from_pdf(mock_pdf).is_none()); + assert_eq!(pdf_io.read_xmp_from_pdf(mock_pdf), None); } #[test] diff --git a/sdk/src/builder.rs b/sdk/src/builder.rs index beff52879..6dfad3197 100644 --- a/sdk/src/builder.rs +++ b/sdk/src/builder.rs @@ -1315,7 +1315,7 @@ mod tests { let manifest_store = Reader::from_stream(format, &mut dest).expect("from_bytes"); println!("{}", manifest_store); - assert!(manifest_store.validation_status().is_none()); + assert_eq!(manifest_store.validation_status(), None); assert!(manifest_store.active_manifest().is_some()); let manifest = manifest_store.active_manifest().unwrap(); assert_eq!(manifest.title().unwrap(), "Test_Manifest"); @@ -1344,7 +1344,7 @@ mod tests { let manifest_store = Reader::from_file(&dest).expect("from_bytes"); println!("{}", manifest_store); - assert!(manifest_store.validation_status().is_none()); + assert_eq!(manifest_store.validation_status(), None); assert_eq!( manifest_store.active_manifest().unwrap().title().unwrap(), "Test_Manifest" @@ -1401,7 +1401,7 @@ mod tests { println!("{}", manifest_store); if format != "c2pa" { // c2pa files will not validate since they have no associated asset - assert!(manifest_store.validation_status().is_none()); + assert_eq!(manifest_store.validation_status(), None); } assert_eq!( manifest_store.active_manifest().unwrap().title().unwrap(), @@ -1488,7 +1488,7 @@ mod tests { .expect("from_bytes"); println!("{}", reader.json()); - assert!(reader.validation_status().is_none()); + assert_eq!(reader.validation_status(), None); } #[test] @@ -1547,7 +1547,7 @@ mod tests { let reader = crate::Reader::from_stream("image/jpeg", output_stream).unwrap(); println!("{reader}"); #[cfg(not(target_arch = "wasm32"))] // skip this until we get wasm async signing working - assert!(reader.validation_status().is_none()); + assert_eq!(reader.validation_status(), None); } #[cfg_attr(not(target_arch = "wasm32"), actix::test)] @@ -1643,7 +1643,7 @@ mod tests { let reader = Reader::from_stream("image/jpeg", &mut dest).expect("from_bytes"); //println!("{}", reader); - assert!(reader.validation_status().is_none()); + assert_eq!(reader.validation_status(), None); assert_eq!( reader .active_manifest() diff --git a/sdk/src/ingredient.rs b/sdk/src/ingredient.rs index 4702e7f26..a677a5ff4 100644 --- a/sdk/src/ingredient.rs +++ b/sdk/src/ingredient.rs @@ -1530,13 +1530,13 @@ mod tests { assert_eq!(&ingredient.title, title); assert_eq!(ingredient.format(), format); assert!(ingredient.manifest_data().is_some()); - assert!(ingredient.metadata().is_none()); + assert_eq!(ingredient.metadata(), None); #[cfg(target_arch = "wasm32")] web_sys::console::debug_2( &"ingredient_from_memory_async:".into(), &ingredient.to_string().into(), ); - assert!(ingredient.validation_status().is_none()); + assert_eq!(ingredient.validation_status(), None); } #[cfg_attr(not(target_arch = "wasm32"), test)] @@ -1553,8 +1553,8 @@ mod tests { assert_eq!(&ingredient.title, title); assert_eq!(ingredient.format(), format); assert!(ingredient.manifest_data().is_some()); - assert!(ingredient.metadata().is_none()); - assert!(ingredient.validation_status().is_none()); + assert_eq!(ingredient.metadata(), None); + assert_eq!(ingredient.validation_status(), None); } #[cfg_attr(not(target_arch = "wasm32"), actix::test)] @@ -1574,7 +1574,7 @@ mod tests { #[cfg(feature = "add_thumbnails")] assert!(ingredient.thumbnail().is_some()); assert!(ingredient.manifest_data().is_some()); - assert!(ingredient.metadata().is_none()); + assert_eq!(ingredient.metadata(), None); assert!(ingredient.validation_status().is_some()); assert_eq!( ingredient.validation_status().unwrap()[0].code(), @@ -1597,7 +1597,7 @@ mod tests { assert!(ingredient.provenance().is_some()); assert!(ingredient.provenance().unwrap().starts_with("https:")); assert!(ingredient.manifest_data().is_some()); - assert!(ingredient.validation_status().is_none()); + assert_eq!(ingredient.validation_status(), None); } #[allow(dead_code)] @@ -1619,7 +1619,7 @@ mod tests { .url() .unwrap() .starts_with("http")); - assert!(ingredient.manifest_data().is_none()); + assert_eq!(ingredient.manifest_data(), None); } #[cfg_attr(not(target_arch = "wasm32"), actix::test)] @@ -1640,7 +1640,7 @@ mod tests { &"ingredient_from_memory_async:".into(), &ingredient.to_string().into(), ); - assert!(ingredient.validation_status().is_none()); + assert_eq!(ingredient.validation_status(), None); assert!(ingredient.manifest_data().is_some()); assert!(ingredient.provenance().is_some()); } @@ -1685,7 +1685,7 @@ mod tests_file_io { assert!(ingredient.thumbnail().is_some()); assert_eq!(ingredient.thumbnail().unwrap().0, format); } else { - assert!(ingredient.thumbnail().is_none()); + assert_eq!(ingredient.thumbnail(), None); } } @@ -1701,8 +1701,8 @@ mod tests_file_io { println!("ingredient = {ingredient}"); assert_eq!(ingredient.title(), "Purple Square.psd"); assert_eq!(ingredient.format(), "image/vnd.adobe.photoshop"); - assert!(ingredient.thumbnail().is_none()); // should always be none - assert!(ingredient.manifest_data().is_none()); + assert_eq!(ingredient.thumbnail(), None); // should always be none + assert_eq!(ingredient.manifest_data(), None); } #[test] @@ -1722,7 +1722,7 @@ mod tests_file_io { .identifier .starts_with("self#jumbf=")); assert!(ingredient.manifest_data().is_some()); - assert!(ingredient.metadata().is_none()); + assert_eq!(ingredient.metadata(), None); } #[test] @@ -1736,9 +1736,9 @@ mod tests_file_io { assert_eq!(&ingredient.title, NO_MANIFEST_JPEG); assert_eq!(ingredient.format(), "image/jpeg"); test_thumbnail(&ingredient, "image/jpeg"); - assert!(ingredient.provenance().is_none()); - assert!(ingredient.manifest_data().is_none()); - assert!(ingredient.metadata().is_none()); + assert_eq!(ingredient.provenance(), None); + assert_eq!(ingredient.manifest_data(), None); + assert_eq!(ingredient.metadata(), None); assert!(ingredient.instance_id().starts_with("xmp.iid:")); #[cfg(feature = "add_thumbnails")] assert!(ingredient @@ -1774,8 +1774,8 @@ mod tests_file_io { assert_eq!(ingredient.format(), "image/jpeg"); assert_eq!(ingredient.hash(), Some("1234568abcdef")); assert_eq!(ingredient.thumbnail_ref().unwrap().format, "image/foo"); // always generated - assert!(ingredient.manifest_data().is_none()); - assert!(ingredient.metadata().is_none()); + assert_eq!(ingredient.manifest_data(), None); + assert_eq!(ingredient.metadata(), None); } #[test] @@ -1788,8 +1788,8 @@ mod tests_file_io { println!("ingredient = {ingredient}"); assert_eq!(ingredient.title(), "libpng-test.png"); test_thumbnail(&ingredient, "image/png"); - assert!(ingredient.provenance().is_none()); - assert!(ingredient.manifest_data.is_none()); + assert_eq!(ingredient.provenance(), None); + assert_eq!(ingredient.manifest_data, None); } #[test] @@ -1824,7 +1824,7 @@ mod tests_file_io { assert_eq!(ingredient.format(), "image/jpeg"); test_thumbnail(&ingredient, "image/jpeg"); assert!(ingredient.provenance().is_some()); - assert!(ingredient.manifest_data().is_none()); + assert_eq!(ingredient.manifest_data(), None); assert!(ingredient.validation_status().is_some()); assert_eq!( ingredient.validation_status().unwrap()[0].code(), @@ -1838,7 +1838,7 @@ mod tests_file_io { let ap = fixture_path("CIE-sig-CA.jpg"); let ingredient = Ingredient::from_file(ap).expect("from_file"); // println!("ingredient = {ingredient}"); - assert!(ingredient.validation_status().is_none()); + assert_eq!(ingredient.validation_status(), None); assert!(ingredient.manifest_data().is_some()); } @@ -1890,11 +1890,11 @@ mod tests_file_io { let mut ingredient = Ingredient::new("title", "format", "instance_id"); ingredient.resources.set_base_path(folder); - assert!(ingredient.thumbnail_ref().is_none()); + assert_eq!(ingredient.thumbnail_ref(), None); // assert!(ingredient // .set_manifest_data_ref(ResourceRef::new("image/jpg", "foo")) // .is_err()); - assert!(ingredient.manifest_data_ref().is_none()); + assert_eq!(ingredient.manifest_data_ref(), None); // verify we can set a reference assert!(ingredient .set_thumbnail_ref(ResourceRef::new("image/jpg", "C.jpg")) diff --git a/sdk/src/jumbf/labels.rs b/sdk/src/jumbf/labels.rs index 335915f13..4af28319b 100644 --- a/sdk/src/jumbf/labels.rs +++ b/sdk/src/jumbf/labels.rs @@ -258,7 +258,7 @@ pub mod tests { Some(assertion.to_string()), assertion_label_from_uri(&assertion_uri) ); - assert_eq!(None, assertion_label_from_uri(&absolute_uri)); + assert_eq!(assertion_label_from_uri(&absolute_uri), None); let assertion_relative = to_relative_uri(&assertion_uri); diff --git a/sdk/src/manifest.rs b/sdk/src/manifest.rs index 774798e6f..f4a40ff3a 100644 --- a/sdk/src/manifest.rs +++ b/sdk/src/manifest.rs @@ -1612,7 +1612,7 @@ pub(crate) mod tests { if cfg!(feature = "add_thumbnails") { assert!(manifest.thumbnail().is_some()); } else { - assert!(manifest.thumbnail().is_none()); + assert_eq!(manifest.thumbnail(), None); } let ingredient = Ingredient::from_file(&test_output).expect("load_from_asset"); assert!(ingredient.active_manifest().is_some()); @@ -1816,7 +1816,7 @@ pub(crate) mod tests { let redacted_uri = &claim2.redactions().unwrap()[0]; let claim1 = store3.get_claim(&claim1_label).unwrap(); - assert!(claim1.get_claim_assertion(redacted_uri, 0).is_none()); + assert_eq!(claim1.get_claim_assertion(redacted_uri, 0), None); } #[test] @@ -2587,7 +2587,7 @@ pub(crate) mod tests { assert!(manifest .set_thumbnail_ref(ResourceRef::new("image/jpg", "foo")) .is_err()); - assert!(manifest.thumbnail_ref().is_none()); + assert_eq!(manifest.thumbnail_ref(), None); // verify we can set a references that do exist assert!(manifest .set_thumbnail_ref(ResourceRef::new("image/jpeg", "C.jpg")) @@ -2619,7 +2619,7 @@ pub(crate) mod tests { // verify there is a thumbnail ref assert!(manifest.thumbnail_ref().is_some()); // verify there is no thumbnail - assert!(manifest.thumbnail().is_none()); + assert_eq!(manifest.thumbnail(), None); let signer = temp_signer(); manifest @@ -2629,8 +2629,8 @@ pub(crate) mod tests { let manifest_store = Reader::from_file(&output).expect("from_file"); println!("{manifest_store}"); let active_manifest = manifest_store.active_manifest().unwrap(); - assert!(active_manifest.thumbnail_ref().is_none()); - assert!(active_manifest.thumbnail().is_none()); + assert_eq!(active_manifest.thumbnail_ref(), None); + assert_eq!(active_manifest.thumbnail(), None); } #[test] @@ -2715,7 +2715,7 @@ pub(crate) mod tests { let manifest_store = Reader::from_file(&output).expect("from_file"); println!("{manifest_store}"); - assert!(manifest_store.validation_status().is_none()); + assert_eq!(manifest_store.validation_status(), None); } #[cfg(all(feature = "file_io", feature = "openssl_sign"))] @@ -2774,7 +2774,7 @@ pub(crate) mod tests { let manifest_store = Reader::from_file(&output).expect("from_file"); println!("{manifest_store}"); - assert!(manifest_store.validation_status().is_none()); + assert_eq!(manifest_store.validation_status(), None); } #[test] @@ -2807,6 +2807,6 @@ pub(crate) mod tests { .unwrap(); println!("{reader}"); assert!(reader.active_manifest().is_some()); - assert!(reader.validation_status().is_none()); + assert_eq!(reader.validation_status(), None); } } diff --git a/sdk/src/manifest_store.rs b/sdk/src/manifest_store.rs index 5ac0d989f..3c072e632 100644 --- a/sdk/src/manifest_store.rs +++ b/sdk/src/manifest_store.rs @@ -628,7 +628,7 @@ mod tests { assert!(manifest_store.active_label().is_some()); assert!(manifest_store.get_active().is_some()); assert!(!manifest_store.manifests().is_empty()); - assert!(manifest_store.validation_status().is_none()); + assert_eq!(manifest_store.validation_status(), None); let manifest = manifest_store.get_active().unwrap(); assert!(!manifest.ingredients().is_empty()); assert_eq!(manifest.issuer().unwrap(), "C2PA Test Signing Cert"); @@ -650,7 +650,7 @@ mod tests { assert!(manifest_store.active_label().is_some()); assert!(manifest_store.get_active().is_some()); assert!(!manifest_store.manifests().is_empty()); - assert!(manifest_store.validation_status().is_none()); + assert_eq!(manifest_store.validation_status(), None); let manifest = manifest_store.get_active().unwrap(); assert!(!manifest.ingredients().is_empty()); assert_eq!(manifest.issuer().unwrap(), "C2PA Test Signing Cert"); @@ -668,7 +668,7 @@ mod tests { assert!(manifest_store.active_label().is_some()); assert!(manifest_store.get_active().is_some()); assert!(!manifest_store.manifests().is_empty()); - assert!(manifest_store.validation_status().is_none()); + assert_eq!(manifest_store.validation_status(), None); let manifest = manifest_store.get_active().unwrap(); assert!(!manifest.ingredients().is_empty()); assert_eq!(manifest.issuer().unwrap(), "C2PA Test Signing Cert"); @@ -691,7 +691,7 @@ mod tests { .await .unwrap(); assert!(!manifest_store.manifests().is_empty()); - assert!(manifest_store.validation_status().is_none()); + assert_eq!(manifest_store.validation_status(), None); println!("{manifest_store}"); } @@ -710,7 +710,7 @@ mod tests { assert!(manifest_store.active_label().is_some()); assert!(manifest_store.get_active().is_some()); assert!(!manifest_store.manifests().is_empty()); - assert!(manifest_store.validation_status().is_none()); + assert_eq!(manifest_store.validation_status(), None); let manifest = manifest_store.get_active().unwrap(); assert!(!manifest.ingredients().is_empty()); assert_eq!(manifest.issuer().unwrap(), "C2PA Test Signing Cert"); @@ -729,7 +729,7 @@ mod tests { assert!(manifest_store.active_label().is_some()); assert!(manifest_store.get_active().is_some()); assert!(!manifest_store.manifests().is_empty()); - assert!(manifest_store.validation_status().is_none()); + assert_eq!(manifest_store.validation_status(), None); let manifest = manifest_store.get_active().unwrap(); assert!(!manifest.ingredients().is_empty()); assert_eq!(manifest.issuer().unwrap(), "C2PA Test Signing Cert"); diff --git a/sdk/src/store.rs b/sdk/src/store.rs index 29084246d..eba10a32f 100644 --- a/sdk/src/store.rs +++ b/sdk/src/store.rs @@ -3953,7 +3953,7 @@ pub mod tests { // original data should not be in file anymore check for first 1k let buf = fs::read(&op).unwrap(); - assert!(memmem::find(&buf, &original_jumbf[0..1024]).is_none()); + assert_eq!(memmem::find(&buf, &original_jumbf[0..1024]), None); } #[actix::test] diff --git a/sdk/tests/v2_api_integration.rs b/sdk/tests/v2_api_integration.rs index cbeebd0cc..79fbf11f0 100644 --- a/sdk/tests/v2_api_integration.rs +++ b/sdk/tests/v2_api_integration.rs @@ -169,7 +169,7 @@ mod integration_v2 { } println!("{}", reader.json()); - assert!(reader.validation_status().is_none()); + assert_eq!(reader.validation_status(), None); assert_eq!(reader.active_manifest().unwrap().title().unwrap(), title); Ok(())