From b1684ac698ec43d8518045b53ef6aa41ffac8f6a Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Sat, 10 Dec 2022 17:43:58 -0600 Subject: [PATCH] integration tests --- src/oned/ean_8_reader.rs | 4 ++-- src/oned/itf_reader.rs | 2 +- src/oned/mod.rs | 3 +++ src/oned/one_d_reader.rs | 19 ++++++++++----- src/oned/upc_e_reader.rs | 7 ++++-- src/oned/upc_ean_reader.rs | 26 ++++++++------------- tests/InvertedDataMatrixBlackBoxTestCase.rs | 21 ++++++++++------- 7 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/oned/ean_8_reader.rs b/src/oned/ean_8_reader.rs index 8535527..89648ef 100644 --- a/src/oned/ean_8_reader.rs +++ b/src/oned/ean_8_reader.rs @@ -86,6 +86,6 @@ impl UPCEANReader for EAN8Reader { impl Default for EAN8Reader { fn default() -> Self { - Self { } + Self {} } -} \ No newline at end of file +} diff --git a/src/oned/itf_reader.rs b/src/oned/itf_reader.rs index cc5f960..48bc21f 100644 --- a/src/oned/itf_reader.rs +++ b/src/oned/itf_reader.rs @@ -405,7 +405,7 @@ impl ITFReader { * @return The decoded digit * @throws NotFoundException if digit cannot be decoded */ - fn decodeDigit(&self,counters: &[u32]) -> Result { + fn decodeDigit(&self, counters: &[u32]) -> Result { let mut bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept let mut bestMatch = -1_isize; let max = PATTERNS.len(); diff --git a/src/oned/mod.rs b/src/oned/mod.rs index f46d2cc..027cb44 100644 --- a/src/oned/mod.rs +++ b/src/oned/mod.rs @@ -55,3 +55,6 @@ pub use coda_bar_writer::*; mod multi_format_upc_ean_reader; pub use multi_format_upc_ean_reader::*; + +mod code_39_writer; +pub use code_39_writer::*; diff --git a/src/oned/one_d_reader.rs b/src/oned/one_d_reader.rs index 3bf28fe..7fd4110 100644 --- a/src/oned/one_d_reader.rs +++ b/src/oned/one_d_reader.rs @@ -159,8 +159,12 @@ pub trait OneDReader: Reader { * @throws NotFoundException if counters cannot be filled entirely from row before running out * of pixels */ - fn recordPattern(&self, row: &BitArray, start: usize, counters: &mut [u32]) -> Result<(), Exceptions> - { + fn recordPattern( + &self, + row: &BitArray, + start: usize, + counters: &mut [u32], + ) -> Result<(), Exceptions> { let numCounters = counters.len(); // Arrays.fill(counters, 0, numCounters, 0); counters.fill(0); @@ -198,8 +202,7 @@ pub trait OneDReader: Reader { row: &BitArray, start: usize, counters: &mut [u32], - ) -> Result<(), Exceptions> - { + ) -> Result<(), Exceptions> { let mut start = start; // This could be more efficient I guess let mut numTransitionsLeft = counters.len() as isize; @@ -229,8 +232,12 @@ pub trait OneDReader: Reader { * @param maxIndividualVariance The most any counter can differ before we give up * @return ratio of total variance between counters and pattern compared to total pattern size */ - fn patternMatchVariance(&self, counters: &[u32], pattern: &[u32], maxIndividualVariance: f32) -> f32 - { + fn patternMatchVariance( + &self, + counters: &[u32], + pattern: &[u32], + maxIndividualVariance: f32, + ) -> f32 { let mut maxIndividualVariance = maxIndividualVariance; let numCounters = counters.len(); let mut total = 0.0; diff --git a/src/oned/upc_e_reader.rs b/src/oned/upc_e_reader.rs index e2dd22f..e0e1ba6 100644 --- a/src/oned/upc_e_reader.rs +++ b/src/oned/upc_e_reader.rs @@ -75,8 +75,11 @@ impl UPCEANReader for UPCEReader { self.checkStandardUPCEANChecksum(&convertUPCEtoUPCA(s)) } - fn decodeEnd(&self, row: &crate::common::BitArray, endStart: usize) -> Result<[usize; 2], Exceptions> - { + fn decodeEnd( + &self, + row: &crate::common::BitArray, + endStart: usize, + ) -> Result<[usize; 2], Exceptions> { self.findGuardPattern(row, endStart, true, &Self::MIDDLE_END_PATTERN) } } diff --git a/src/oned/upc_ean_reader.rs b/src/oned/upc_ean_reader.rs index 437f45d..46e0eaa 100644 --- a/src/oned/upc_ean_reader.rs +++ b/src/oned/upc_ean_reader.rs @@ -116,8 +116,7 @@ pub trait UPCEANReader: OneDReader { // eanManSupport = new EANManufacturerOrgSupport(); // } - fn findStartGuardPattern(&self, row: &BitArray) -> Result<[usize; 2], Exceptions> - { + fn findStartGuardPattern(&self, row: &BitArray) -> Result<[usize; 2], Exceptions> { let mut foundStart = false; let mut startRange = [0; 2]; //= null; let mut nextStart = 0; @@ -172,8 +171,7 @@ pub trait UPCEANReader: OneDReader { row: &BitArray, startGuardRange: &[usize; 2], hints: &crate::DecodingHintDictionary, - ) -> Result - { + ) -> Result { let resultPointCallback = hints.get(&DecodeHintType::NEED_RESULT_POINT_CALLBACK); let mut symbologyIdentifier = 0; @@ -380,19 +378,17 @@ pub trait UPCEANReader: OneDReader { Ok(((1000 - sum) % 10) as u32) } - fn decodeEnd(&self, row: &BitArray, endStart: usize) -> Result<[usize; 2], Exceptions> - { + fn decodeEnd(&self, row: &BitArray, endStart: usize) -> Result<[usize; 2], Exceptions> { self.findGuardPattern(row, endStart, false, &START_END_PATTERN) } fn findGuardPattern( - &self, + &self, row: &BitArray, rowOffset: usize, whiteFirst: bool, pattern: &[u32], - ) -> Result<[usize; 2], Exceptions> - { + ) -> Result<[usize; 2], Exceptions> { self.findGuardPatternWithCounters( row, rowOffset, @@ -414,14 +410,13 @@ pub trait UPCEANReader: OneDReader { * @throws NotFoundException if pattern is not found */ fn findGuardPatternWithCounters( - &self, + &self, row: &BitArray, rowOffset: usize, whiteFirst: bool, pattern: &[u32], counters: &mut [u32], - ) -> Result<[usize; 2], Exceptions> - { + ) -> Result<[usize; 2], Exceptions> { let width = row.getSize(); let rowOffset = if whiteFirst { row.getNextUnset(rowOffset) @@ -474,13 +469,12 @@ pub trait UPCEANReader: OneDReader { * @throws NotFoundException if digit cannot be decoded */ fn decodeDigit( - &self, + &self, row: &BitArray, counters: &mut [u32; 4], rowOffset: usize, patterns: &[[u32; 4]], - ) -> Result - { + ) -> Result { self.recordPattern(row, rowOffset, counters)?; let mut bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept let mut bestMatch = -1_isize; @@ -567,4 +561,4 @@ impl Reader for StandInStruct { } } -pub(crate) const StandIn : StandInStruct = StandInStruct{}; \ No newline at end of file +pub(crate) const StandIn: StandInStruct = StandInStruct {}; diff --git a/tests/InvertedDataMatrixBlackBoxTestCase.rs b/tests/InvertedDataMatrixBlackBoxTestCase.rs index 90d07f0..a6efffd 100644 --- a/tests/InvertedDataMatrixBlackBoxTestCase.rs +++ b/tests/InvertedDataMatrixBlackBoxTestCase.rs @@ -14,26 +14,29 @@ * limitations under the License. */ -use rxing::{MultiFormatReader, DecodeHintType, DecodeHintValue}; +use rxing::{DecodeHintType, DecodeHintValue, MultiFormatReader}; - mod common; +mod common; /** * Inverted barcodes */ #[test] - fn inverted_data_matrix_black_box_test_case() { +fn inverted_data_matrix_black_box_test_case() { let mut tester = common::AbstractBlackBoxTestCase::new( - "test_resources/blackbox/inverted", - MultiFormatReader::default(), - rxing::BarcodeFormat::DATA_MATRIX, - ); + "test_resources/blackbox/inverted", + MultiFormatReader::default(), + rxing::BarcodeFormat::DATA_MATRIX, + ); // super("src/test/resources/blackbox/inverted", new MultiFormatReader(), BarcodeFormat.DATA_MATRIX); - tester.add_hint(DecodeHintType::ALSO_INVERTED, DecodeHintValue::AlsoInverted(true)); + tester.add_hint( + DecodeHintType::ALSO_INVERTED, + DecodeHintValue::AlsoInverted(true), + ); tester.add_test(1, 1, 0.0); tester.add_test(1, 1, 90.0); tester.add_test(1, 1, 180.0); tester.add_test(1, 1, 270.0); tester.test_black_box(); - } +}