mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
datamatrix library pass
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
assert!(tooSmall < matrix.getWidth() as i32);
|
||||
assert!(tooSmall < matrix.getHeight() as i32);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ impl SymbolInfo {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getErrorLengthForInterleavedBlock(&self, index: u32) -> u32 {
|
||||
pub fn getErrorLengthForInterleavedBlock(&self, _index: u32) -> u32 {
|
||||
self.rsBlockError
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T: Reader> AbstractBlackBoxTestCase<T> {
|
||||
&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<T: Reader> AbstractBlackBoxTestCase<T> {
|
||||
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<T: Reader> AbstractBlackBoxTestCase<T> {
|
||||
}
|
||||
|
||||
fn decode(
|
||||
&self,
|
||||
&mut self,
|
||||
source: &BinaryBitmap,
|
||||
rotation: f32,
|
||||
expected_text: &str,
|
||||
|
||||
Reference in New Issue
Block a user