test_builder.rs (1474B)
1 // Copyright 2024 Adobe. All rights reserved. 2 // This file is licensed to you under the Apache License, 3 // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) 4 // or the MIT license (http://opensource.org/licenses/MIT), 5 // at your option. 6 7 // Unless required by applicable law or agreed to in writing, 8 // this software is distributed on an "AS IS" BASIS, WITHOUT 9 // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or 10 // implied. See the LICENSE-MIT and LICENSE-APACHE files for the 11 // specific language governing permissions and limitations under 12 // each license. 13 14 use std::io::Cursor; 15 16 use c2pa::{Builder, Result}; 17 18 mod common; 19 use common::{compare_stream_to_known_good, fixtures_path, test_signer}; 20 21 #[test] 22 fn test_builder_ca_jpg() -> Result<()> { 23 let manifest_def = std::fs::read_to_string(fixtures_path("simple_manifest.json"))?; 24 let mut builder = Builder::from_json(&manifest_def)?; 25 26 const TEST_IMAGE: &[u8] = include_bytes!("../tests/fixtures/CA.jpg"); 27 let format = "image/jpeg"; 28 let mut source = Cursor::new(TEST_IMAGE); 29 30 let mut dest = Cursor::new(Vec::new()); 31 32 builder.sign(&test_signer(), format, &mut source, &mut dest)?; 33 34 // dest.set_position(0); 35 // let path = common::known_good_path("CA_test.json"); 36 // let reader = c2pa::Reader::from_stream(format, &mut dest)?; 37 // std::fs::write(path, reader.json())?; 38 39 dest.set_position(0); 40 compare_stream_to_known_good(&mut dest, format, "CA_test.json") 41 }