test_reader.rs (2094B)
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 mod common; 15 use c2pa::{Error, Reader, Result}; 16 use common::{assert_err, compare_to_known_good, fixture_stream}; 17 18 #[test] 19 #[cfg(feature = "file_io")] 20 fn test_reader_not_found() -> Result<()> { 21 let result = Reader::from_file("not_found.png"); 22 assert_err!(result, Err(Error::IoError(_))); 23 Ok(()) 24 } 25 26 #[test] 27 fn test_reader_no_jumbf() -> Result<()> { 28 let (format, mut stream) = fixture_stream("sample1.png")?; 29 let result = Reader::from_stream(&format, &mut stream); 30 assert_err!(result, Err(Error::JumbfNotFound)); 31 Ok(()) 32 } 33 34 #[test] 35 fn test_reader_ca_jpg() -> Result<()> { 36 let (format, mut stream) = fixture_stream("CA.jpg")?; 37 let reader = Reader::from_stream(&format, &mut stream)?; 38 compare_to_known_good(&reader, "CA.json") 39 } 40 41 #[test] 42 fn test_reader_c_jpg() -> Result<()> { 43 let (format, mut stream) = fixture_stream("C.jpg")?; 44 let reader = Reader::from_stream(&format, &mut stream)?; 45 compare_to_known_good(&reader, "C.json") 46 } 47 48 #[test] 49 fn test_reader_xca_jpg() -> Result<()> { 50 let (format, mut stream) = fixture_stream("XCA.jpg")?; 51 let reader = Reader::from_stream(&format, &mut stream)?; 52 compare_to_known_good(&reader, "XCA.json") 53 } 54 55 #[test] 56 #[ignore] 57 /// Generates the known good for the above tests 58 /// This is ignored by default 59 /// to call use test -- --ignored 60 fn write_known_goods() -> Result<()> { 61 let filenames = ["CA.jpg", "C.jpg", "XCA.jpg"]; 62 for filename in &filenames { 63 common::write_known_good(filename)?; 64 } 65 Ok(()) 66 }