use std::{collections::HashSet, path::PathBuf};
use crate::{
BarcodeFormat, BinaryBitmap, BufferedImageLuminanceSource, MultiFormatReader,
common::HybridBinarizer,
};
use super::{GenericMultipleBarcodeReader, MultipleBarcodeReader};
#[cfg(feature = "image_formats")]
#[test]
fn testMulti() {
let mut testBase = PathBuf::from("test_resources/blackbox/multi-1");
testBase.push("1.png");
let image = image::ImageReader::open(testBase)
.expect("image must open")
.decode()
.expect("must decode");
let source = BufferedImageLuminanceSource::new(image);
let mut bitmap = BinaryBitmap::new(HybridBinarizer::new(source));
let mut reader = GenericMultipleBarcodeReader::new(MultiFormatReader::default());
let results = reader
.decode_multiple(&mut bitmap)
.expect("must decode multi");
assert_eq!(2, results.len());
assert_eq!("031415926531", results[0].getText());
assert_eq!(&BarcodeFormat::UPC_A, results[0].getBarcodeFormat());
assert_eq!("www.airtable.com/jobs", results[1].getText());
assert_eq!(&BarcodeFormat::QR_CODE, results[1].getBarcodeFormat());
}
#[cfg(feature = "image_formats")]
#[test]
fn testMultiQR() {
let mut testBase = PathBuf::from("test_resources/blackbox/multi-qrcode-1");
testBase.push("1.png");
let image = image::ImageReader::open(testBase)
.expect("image must open")
.decode()
.expect("must decode");
let source = BufferedImageLuminanceSource::new(image);
let mut bitmap = BinaryBitmap::new(HybridBinarizer::new(source));
let mut reader = GenericMultipleBarcodeReader::new(MultiFormatReader::default());
let results = reader
.decode_multiple(&mut bitmap)
.expect("must decode multi");
assert_eq!(4, results.len());
let mut barcodeContents = HashSet::new();
for result in results {
barcodeContents.insert(result.getText().to_owned());
assert_eq!(&BarcodeFormat::QR_CODE, result.getBarcodeFormat());
assert!(!result.getRXingResultMetadata().is_empty());
}
let mut expectedContents = HashSet::new();
expectedContents.insert(
"You earned the class a 5 MINUTE DANCE PARTY!! Awesome! Way to go! Let's boogie!"
.to_owned(),
);
expectedContents.insert(
"You earned the class 5 EXTRA MINUTES OF RECESS!! Fabulous!! Way to go!!".to_owned(),
);
expectedContents.insert(
"You get to SIT AT MRS. SIGMON'S DESK FOR A DAY!! Awesome!! Way to go!! Guess I better clean up! :)".to_owned());
expectedContents
.insert("You get to CREATE OUR JOURNAL PROMPT FOR THE DAY! Yay! Way to go! ".to_owned());
assert_eq!(expectedContents, barcodeContents);
}