rss_expanded_image_2_result test case pass

This commit is contained in:
Henry Schimke
2022-12-16 13:04:55 -06:00
parent c0ffa2bb1c
commit 54d68c174d
19 changed files with 118 additions and 109 deletions

View File

@@ -1,102 +0,0 @@
/*
* Copyright (C) 2010 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This software consists of contributions made by many individuals,
* listed below:
*
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
*
* These authors would like to acknowledge the Spanish Ministry of Industry,
* Tourism and Trade, for the support in the project TSI020301-2008-2
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
* Mobile Dynamic Environments", leaded by Treelogic
* ( http://www.treelogic.com/ ):
*
* http://www.piramidepse.com/
*
*/
package com.google.zxing.oned.rss.expanded;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import javax.imageio.ImageIO;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.BufferedImageLuminanceSource;
import com.google.zxing.NotFoundException;
import com.google.zxing.ReaderException;
import com.google.zxing.RXingResult;
import com.google.zxing.client.result.ExpandedProductParsedRXingResult;
import com.google.zxing.client.result.ParsedRXingResult;
import com.google.zxing.client.result.RXingResultParser;
import com.google.zxing.common.AbstractBlackBoxTestCase;
import com.google.zxing.common.BitArray;
import com.google.zxing.common.GlobalHistogramBinarizer;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
*/
public final class RSSExpandedImage2resultTestCase extends Assert {
@Test
public void testDecodeRow2result2() throws Exception {
// (01)90012345678908(3103)001750
ExpandedProductParsedRXingResult expected =
new ExpandedProductParsedRXingResult("(01)90012345678908(3103)001750",
"90012345678908",
null, null, null, null, null, null,
"001750",
ExpandedProductParsedRXingResult.KILOGRAM,
"3", null, null, null, new HashMap<>());
assertCorrectImage2result("2.png", expected);
}
private static void assertCorrectImage2result(String fileName, ExpandedProductParsedRXingResult expected)
throws IOException, NotFoundException {
Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName);
BufferedImage image = ImageIO.read(path.toFile());
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
RXingResult theRXingResult;
try {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
theRXingResult = rssExpandedReader.decodeRow(rowNumber, row, null);
} catch (ReaderException re) {
fail(re.toString());
return;
}
assertSame(BarcodeFormat.RSS_EXPANDED, theRXingResult.getBarcodeFormat());
ParsedRXingResult result = RXingResultParser.parseRXingResult(theRXingResult);
assertEquals(expected, result);
}
}

View File

@@ -20,3 +20,6 @@ mod rss_expanded_internal_test_case;
#[cfg(test)]
mod rss_expanded_image_2_binary_test_tase;
#[cfg(test)]
mod rss_expanded_image_2_result_test_case;

View File

@@ -0,0 +1,80 @@
/*
* Copyright (C) 2010 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This software consists of contributions made by many individuals,
* listed below:
*
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
*
* These authors would like to acknowledge the Spanish Ministry of Industry,
* Tourism and Trade, for the support in the project TSI020301-2008-2
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
* Mobile Dynamic Environments", leaded by Treelogic
* ( http://www.treelogic.com/ ):
*
* http://www.piramidepse.com/
*
*/
use std::{rc::Rc, collections::HashMap};
use crate::{client::result::{ExpandedProductParsedRXingResult, ParsedClientResult}, common::{BitArray, GlobalHistogramBinarizer}, BinaryBitmap, BufferedImageLuminanceSource, BarcodeFormat, oned::{rss::expanded::RSSExpandedReader, OneDReader}};
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
*/
#[test]
fn testDecodeRow2result2() {
// (01)90012345678908(3103)001750
let expected =
ExpandedProductParsedRXingResult::new("(01)90012345678908(3103)001750".to_owned(),
"90012345678908".to_owned(),
"".to_owned(), "".to_owned(), "".to_owned(), "".to_owned(), "".to_owned(), "".to_owned(),
"001750".to_owned(),
ExpandedProductParsedRXingResult::KILOGRAM.to_owned(),
"3".to_owned(), "".to_owned(), "".to_owned(), "".to_owned(), HashMap::new());
assertCorrectImage2result("2.png", expected);
}
fn assertCorrectImage2result( fileName:&str, expected:ExpandedProductParsedRXingResult)
{
let path = format!("test_resources/blackbox/rssexpanded-1/{}",fileName);
let image = image::open(path).expect("image must exist");
let binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(BufferedImageLuminanceSource::new(image)))));
let rowNumber = binaryMap.getHeight() as usize / 2;
let row = binaryMap.getBlackRow(rowNumber, &mut BitArray::new()).expect("get row");
let mut rssExpandedReader = RSSExpandedReader::new();
let theRXingResult= rssExpandedReader.decodeRow(rowNumber as u32, &row, &HashMap::new()).expect("must decode");
assert_eq!(&BarcodeFormat::RSS_EXPANDED, theRXingResult.getBarcodeFormat());
let ParsedClientResult::ExpandedProductResult(result) = crate::client::result::parseRXingResult(&theRXingResult) else {
panic!("incorrect result type found");
};
assert_eq!(expected, result);
}

View File

@@ -582,7 +582,7 @@ impl RSSExpandedReader {
// for i in 1..self.pairs.len() {
// for (int i = 1; i < this.pairs.size(); ++i) {
for currentPair in &self.pairs {
for currentPair in self.pairs.iter().skip(1) {
// let currentPair = self.pairs.get(i).unwrap();
checksum += currentPair.getLeftChar().unwrap().getChecksumPortion();
s += 1;