From ba025126952cb71b3dc6f3f1f2727180decaeff2 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Sun, 27 Nov 2022 12:16:04 -0600 Subject: [PATCH] datamatrix library pass --- src/datamatrix/data_matrix_writer.rs | 103 ++++++++++++------- src/datamatrix/encoder/symbol_info.rs | 2 +- tests/common/abstract_black_box_test_case.rs | 8 +- 3 files changed, 71 insertions(+), 42 deletions(-) diff --git a/src/datamatrix/data_matrix_writer.rs b/src/datamatrix/data_matrix_writer.rs index 66a7cce..b18ba80 100644 --- a/src/datamatrix/data_matrix_writer.rs +++ b/src/datamatrix/data_matrix_writer.rs @@ -156,7 +156,7 @@ impl Writer for DataMatrixWriter { } let symbol_lookup = SymbolInfoLookup::new(); - let Some(symbolInfo) = symbol_lookup.lookup_with_codewords_shape_size_fail(encoded.len() as u32, *shape, &minSize, &maxSize, true)? else { + let Some(symbolInfo) = symbol_lookup.lookup_with_codewords_shape_size_fail(encoded.chars().count() as u32, *shape, &minSize, &maxSize, true)? else { return Err(Exceptions::NotFoundException("symbol info is bad".to_owned())) }; @@ -308,47 +308,76 @@ impl DataMatrixWriter { } #[cfg(test)] -mod tests{ +mod tests { use std::collections::HashMap; - use crate::{EncodeHintType, BarcodeFormat, datamatrix::{encoder::SymbolShapeHint, DataMatrixWriter}, Writer, EncodeHintValue}; + use crate::{ + datamatrix::{encoder::SymbolShapeHint, DataMatrixWriter}, + BarcodeFormat, EncodeHintType, EncodeHintValue, Writer, + }; + #[test] + fn testDataMatrixImageWriter() { + let mut hints = HashMap::new(); + hints.insert( + EncodeHintType::DATA_MATRIX_SHAPE, + EncodeHintValue::DataMatrixShape(SymbolShapeHint::FORCE_SQUARE), + ); - #[test] - fn testDataMatrixImageWriter() { + let bigEnough = 64; + let writer = DataMatrixWriter {}; + let matrix = writer + .encode_with_hints( + "Hello Google", + &BarcodeFormat::DATA_MATRIX, + bigEnough, + bigEnough, + &hints, + ) + .expect("must encode"); + assert!(bigEnough >= matrix.getWidth() as i32); + assert!(bigEnough >= matrix.getHeight() as i32); + } - let mut hints = HashMap::new(); - hints.insert(EncodeHintType::DATA_MATRIX_SHAPE, EncodeHintValue::DataMatrixShape(SymbolShapeHint::FORCE_SQUARE)); + #[test] + fn testDataMatrixWriter() { + let mut hints = HashMap::new(); + hints.insert( + EncodeHintType::DATA_MATRIX_SHAPE, + EncodeHintValue::DataMatrixShape(SymbolShapeHint::FORCE_SQUARE), + ); - let bigEnough = 64; - let writer = DataMatrixWriter{}; - let matrix = writer.encode_with_hints("Hello Google", &BarcodeFormat::DATA_MATRIX, bigEnough, bigEnough, &hints).expect("must encode"); - assert!(bigEnough >= matrix.getWidth() as i32); - assert!(bigEnough >= matrix.getHeight() as i32); - } + let bigEnough = 14; + let writer = DataMatrixWriter {}; + let matrix = writer + .encode_with_hints( + "Hello Me", + &BarcodeFormat::DATA_MATRIX, + bigEnough, + bigEnough, + &hints, + ) + .expect("must encode"); + assert_eq!(bigEnough, matrix.getWidth() as i32); + assert_eq!(bigEnough, matrix.getHeight() as i32); + } - #[test] - fn testDataMatrixWriter() { + #[test] + fn testDataMatrixTooSmall() { + // The DataMatrix will not fit in this size, so the matrix should come back bigger + let tooSmall = 8; + let writer = DataMatrixWriter {}; + let matrix = writer + .encode_with_hints( + "http://www.google.com/", + &BarcodeFormat::DATA_MATRIX, + tooSmall, + tooSmall, + &HashMap::new(), + ) + .expect("must encode"); - let mut hints = HashMap::new(); - hints.insert(EncodeHintType::DATA_MATRIX_SHAPE, EncodeHintValue::DataMatrixShape(SymbolShapeHint::FORCE_SQUARE)); - - let bigEnough = 14; - let writer = DataMatrixWriter{}; - let matrix = writer.encode_with_hints("Hello Me", &BarcodeFormat::DATA_MATRIX, bigEnough, bigEnough, &hints).expect("must encode"); - assert_eq!(bigEnough, matrix.getWidth() as i32); - assert_eq!(bigEnough, matrix.getHeight() as i32); - } - - #[test] - fn testDataMatrixTooSmall() { - // The DataMatrix will not fit in this size, so the matrix should come back bigger - let tooSmall = 8; - let writer = DataMatrixWriter{}; - let matrix = writer.encode_with_hints("http://www.google.com/", &BarcodeFormat::DATA_MATRIX, tooSmall, tooSmall, &HashMap::new()).expect("must encode"); - - assert!(tooSmall < matrix.getWidth() as i32); - assert!(tooSmall < matrix.getHeight() as i32); - } - -} \ No newline at end of file + assert!(tooSmall < matrix.getWidth() as i32); + assert!(tooSmall < matrix.getHeight() as i32); + } +} diff --git a/src/datamatrix/encoder/symbol_info.rs b/src/datamatrix/encoder/symbol_info.rs index b3a2fbb..8afbbc7 100644 --- a/src/datamatrix/encoder/symbol_info.rs +++ b/src/datamatrix/encoder/symbol_info.rs @@ -219,7 +219,7 @@ impl SymbolInfo { } } - pub fn getErrorLengthForInterleavedBlock(&self, index: u32) -> u32 { + pub fn getErrorLengthForInterleavedBlock(&self, _index: u32) -> u32 { self.rsBlockError } diff --git a/tests/common/abstract_black_box_test_case.rs b/tests/common/abstract_black_box_test_case.rs index 2c721e2..64d84e6 100644 --- a/tests/common/abstract_black_box_test_case.rs +++ b/tests/common/abstract_black_box_test_case.rs @@ -17,7 +17,7 @@ use std::{ collections::HashMap, fs::{read_dir, read_to_string}, - path::{Path, PathBuf}, + path::{Path, PathBuf}, rc::Rc, }; use rxing::{ @@ -131,7 +131,7 @@ impl AbstractBlackBoxTestCase { &self.barcode_reader } - pub fn test_black_box(&self) { + pub fn test_black_box(&mut self) { assert!(!self.test_rxing_results.is_empty()); let image_files = self.get_image_files(); @@ -230,7 +230,7 @@ impl AbstractBlackBoxTestCase { let rotation = self.test_rxing_results.get(x).unwrap().get_rotation(); let rotated_image = Self::rotate_image(&image, rotation); let source = BufferedImageLuminanceSource::new(rotated_image); - let bitmap = BinaryBitmap::new(Box::new(HybridBinarizer::new(Box::new(source)))); + let bitmap = BinaryBitmap::new(Rc::new(HybridBinarizer::new(Box::new(source)))); // if file_base_name == "15" { // let mut f = File::create("test_file_output.txt").unwrap(); @@ -396,7 +396,7 @@ impl AbstractBlackBoxTestCase { } fn decode( - &self, + &mut self, source: &BinaryBitmap, rotation: f32, expected_text: &str,