Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zxing-cpp/wrappers/rust/src/tests.rs @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* | |
| 2 * Copyright 2024 Axel Waggershauser | |
| 3 */ | |
| 4 // SPDX-License-Identifier: Apache-2.0 | |
| 5 | |
| 6 #[cfg(test)] | |
| 7 mod tests { | |
| 8 use crate::*; | |
| 9 | |
| 10 #[test] | |
| 11 fn barcode_formats_from_str_valid() { | |
| 12 let formats = BarcodeFormats::from_str("qrcode,linearcodes").unwrap(); | |
| 13 assert_eq!(formats, BarcodeFormat::QRCode | BarcodeFormat::LinearCodes); | |
| 14 } | |
| 15 | |
| 16 #[test] | |
| 17 fn barcode_reader_new() { | |
| 18 let mut o1 = BarcodeReader::new(); | |
| 19 assert_eq!(o1.get_formats(), BarcodeFormat::None); | |
| 20 assert_eq!(o1.get_try_harder(), true); | |
| 21 o1.set_formats(BarcodeFormat::EAN8); | |
| 22 assert_eq!(o1.get_formats(), BarcodeFormat::EAN8); | |
| 23 o1.set_try_harder(false); | |
| 24 assert_eq!(o1.get_try_harder(), false); | |
| 25 | |
| 26 o1 = BarcodeReader::new().is_pure(true).text_mode(TextMode::Hex); | |
| 27 assert_eq!(o1.get_formats(), BarcodeFormat::None); | |
| 28 assert_eq!(o1.get_try_harder(), true); | |
| 29 assert_eq!(o1.get_is_pure(), true); | |
| 30 assert_eq!(o1.get_text_mode(), TextMode::Hex); | |
| 31 } | |
| 32 | |
| 33 #[test] | |
| 34 fn barcode_creator_new() { | |
| 35 let mut o1 = BarcodeCreator::new(BarcodeFormat::QRCode); | |
| 36 assert_eq!(o1.get_reader_init(), false); | |
| 37 o1.set_reader_init(true); | |
| 38 assert_eq!(o1.get_reader_init(), true); | |
| 39 } | |
| 40 | |
| 41 #[test] | |
| 42 #[should_panic] | |
| 43 fn barcode_formats_from_str_invalid() { | |
| 44 let _ = BarcodeFormats::from_str("qrcoder").unwrap(); | |
| 45 } | |
| 46 | |
| 47 #[test] | |
| 48 fn create_from_str() { | |
| 49 let str = "123456"; | |
| 50 let res = create(BarcodeFormat::QRCode).ec_level("Q").from_str(str).unwrap(); | |
| 51 | |
| 52 assert_eq!(res.is_valid(), true); | |
| 53 assert_eq!(res.format(), BarcodeFormat::QRCode); | |
| 54 assert_eq!(res.text(), str); | |
| 55 assert_eq!(res.bytes(), str.as_bytes()); | |
| 56 assert_eq!(res.has_eci(), false); | |
| 57 assert_eq!(res.content_type(), ContentType::Text); | |
| 58 assert!(matches!(res.error(), BarcodeError::None())); | |
| 59 assert_eq!(res.error().to_string(), ""); | |
| 60 } | |
| 61 | |
| 62 #[test] | |
| 63 fn create_from_slice() { | |
| 64 let data = [1, 2, 3, 4, 5]; | |
| 65 let res = create(BarcodeFormat::QRCode).reader_init(true).from_slice(&data).unwrap(); | |
| 66 | |
| 67 assert_eq!(res.is_valid(), true); | |
| 68 assert_eq!(res.format(), BarcodeFormat::QRCode); | |
| 69 assert_eq!(res.bytes(), data); | |
| 70 assert_eq!(res.has_eci(), true); | |
| 71 // assert_eq!(res.reader_init(), true); // TODO | |
| 72 assert_eq!(res.content_type(), ContentType::Binary); | |
| 73 assert!(matches!(res.error(), BarcodeError::None())); | |
| 74 assert_eq!(res.error().to_string(), ""); | |
| 75 } | |
| 76 | |
| 77 #[test] | |
| 78 fn read_pure() { | |
| 79 let mut data = Vec::<u8>::new(); | |
| 80 for v in "0000101000101101011110111101011011101010100111011100101000100101110010100000".chars() { | |
| 81 data.push(if v == '0' { 255 } else { 0 }); | |
| 82 } | |
| 83 let iv = ImageView::from_slice(&data, data.len(), 1, ImageFormat::Lum).unwrap(); | |
| 84 let res = read().binarizer(Binarizer::BoolCast).from(&iv).unwrap(); | |
| 85 | |
| 86 let expected = "96385074"; | |
| 87 | |
| 88 assert_eq!(res.len(), 1); | |
| 89 assert_eq!(res[0].is_valid(), true); | |
| 90 assert_eq!(res[0].format(), BarcodeFormat::EAN8); | |
| 91 assert_eq!(res[0].text(), expected); | |
| 92 assert_eq!(res[0].bytes(), expected.as_bytes()); | |
| 93 assert_eq!(res[0].has_eci(), false); | |
| 94 assert_eq!(res[0].content_type(), ContentType::Text); | |
| 95 assert_eq!(res[0].orientation(), 0); | |
| 96 assert_eq!(res[0].position().top_left, PointI { x: 4, y: 0 }); | |
| 97 assert_eq!(res[0].line_count(), 1); | |
| 98 assert!(matches!(res[0].error(), BarcodeError::None())); | |
| 99 assert_eq!(res[0].error().to_string(), ""); | |
| 100 } | |
| 101 } |
