From 54d68c174d45f54102f04af30696a511b88a5f18 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Fri, 16 Dec 2022 13:04:55 -0600 Subject: [PATCH] rss_expanded_image_2_result test case pass --- src/client/result/AddressBookParsedResult.rs | 1 + src/client/result/CalendarParsedResult.rs | 9 ++ src/client/result/EmailAddressParsedResult.rs | 1 + .../result/ExpandedProductParsedResult.rs | 8 +- .../result/ExpandedProductResultParser.rs | 4 +- src/client/result/GeoParsedResult.rs | 8 ++ src/client/result/ISBNParsedResult.rs | 1 + src/client/result/ProductParsedResult.rs | 1 + src/client/result/SMSParsedResult.rs | 1 + src/client/result/TelParsedResult.rs | 1 + src/client/result/TextParsedResult.rs | 1 + src/client/result/URIParsedResult.rs | 1 + src/client/result/VINParsedResult.rs | 1 + src/client/result/WifiParsedResult.rs | 1 + src/client/result/mod.rs | 1 + .../RSSExpandedImage2resultTestCase.java | 102 ------------------ src/oned/rss/expanded/mod.rs | 3 + .../rss_expanded_image_2_result_test_case.rs | 80 ++++++++++++++ src/oned/rss/expanded/rss_expanded_reader.rs | 2 +- 19 files changed, 118 insertions(+), 109 deletions(-) delete mode 100644 src/oned/rss/expanded/RSSExpandedImage2resultTestCase.java create mode 100644 src/oned/rss/expanded/rss_expanded_image_2_result_test_case.rs diff --git a/src/client/result/AddressBookParsedResult.rs b/src/client/result/AddressBookParsedResult.rs index 651efa9..142727c 100644 --- a/src/client/result/AddressBookParsedResult.rs +++ b/src/client/result/AddressBookParsedResult.rs @@ -26,6 +26,7 @@ use super::{ParsedRXingResult, ParsedRXingResultType, ResultParser}; * * @author Sean Owen */ +#[derive(PartialEq, Eq,Hash,Debug)] pub struct AddressBookParsedRXingResult { names: Vec, nicknames: Vec, diff --git a/src/client/result/CalendarParsedResult.rs b/src/client/result/CalendarParsedResult.rs index 7daf8ff..fe629c9 100644 --- a/src/client/result/CalendarParsedResult.rs +++ b/src/client/result/CalendarParsedResult.rs @@ -59,6 +59,7 @@ lazy_static! { * * @author Sean Owen */ +#[derive(Debug)] pub struct CalendarParsedRXingResult { summary: String, start: i64, @@ -363,3 +364,11 @@ impl CalendarParsedRXingResult { self.longitude } } + +impl PartialEq for CalendarParsedRXingResult { + fn eq(&self, other: &Self) -> bool { + self.summary == other.summary && self.start == other.start && self.startAllDay == other.startAllDay && self.end == other.end && self.endAllDay == other.endAllDay && self.location == other.location && self.organizer == other.organizer && self.attendees == other.attendees && self.description == other.description && self.latitude == other.latitude && self.longitude == other.longitude + } +} + +impl Eq for CalendarParsedRXingResult {} \ No newline at end of file diff --git a/src/client/result/EmailAddressParsedResult.rs b/src/client/result/EmailAddressParsedResult.rs index d6b4e87..afda562 100644 --- a/src/client/result/EmailAddressParsedResult.rs +++ b/src/client/result/EmailAddressParsedResult.rs @@ -24,6 +24,7 @@ use super::{ParsedRXingResult, ParsedRXingResultType, ResultParser}; * * @author Sean Owen */ +#[derive(PartialEq, Eq,Hash,Debug)] pub struct EmailAddressParsedRXingResult { tos: Vec, ccs: Vec, diff --git a/src/client/result/ExpandedProductParsedResult.rs b/src/client/result/ExpandedProductParsedResult.rs index 7a0a607..0040900 100644 --- a/src/client/result/ExpandedProductParsedResult.rs +++ b/src/client/result/ExpandedProductParsedResult.rs @@ -33,9 +33,6 @@ use std::collections::HashMap; use super::{ParsedRXingResult, ParsedRXingResultType}; -pub const KILOGRAM: &'static str = "KG"; -pub const POUND: &'static str = "LB"; - /** * Represents a parsed result that encodes extended product information as encoded * by the RSS format, like weight, price, dates, etc. @@ -43,7 +40,7 @@ pub const POUND: &'static str = "LB"; * @author Antonio Manuel Benjumea Conde, Servinform, S.A. * @author Agustín Delgado, Servinform, S.A. */ -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq,Debug)] pub struct ExpandedProductParsedRXingResult { rawText: String, productID: String, @@ -73,6 +70,9 @@ impl ParsedRXingResult for ExpandedProductParsedRXingResult { } impl ExpandedProductParsedRXingResult { + pub const KILOGRAM: &'static str = "KG"; +pub const POUND: &'static str = "LB"; + pub fn new( rawText: String, productID: String, diff --git a/src/client/result/ExpandedProductResultParser.rs b/src/client/result/ExpandedProductResultParser.rs index f7cfe78..b927e2d 100644 --- a/src/client/result/ExpandedProductResultParser.rs +++ b/src/client/result/ExpandedProductResultParser.rs @@ -92,13 +92,13 @@ pub fn parse(result: &crate::RXingResult) -> Option { "3100" | "3101" | "3102" | "3103" | "3104" | "3105" | "3106" | "3107" | "3108" | "3109" => { weight = value; - weightType = ExpandedProductParsedResult::KILOGRAM.into(); + weightType = ExpandedProductParsedRXingResult::KILOGRAM.into(); weightIncrement = ai[3..].to_owned() } "3200" | "3201" | "3202" | "3203" | "3204" | "3205" | "3206" | "3207" | "3208" | "3209" => { weight = value; - weightType = ExpandedProductParsedResult::POUND.into(); + weightType = ExpandedProductParsedRXingResult::POUND.into(); weightIncrement = ai[3..].to_owned(); } "3920" | "3921" | "3922" | "3923" => { diff --git a/src/client/result/GeoParsedResult.rs b/src/client/result/GeoParsedResult.rs index b507fc4..80846af 100644 --- a/src/client/result/GeoParsedResult.rs +++ b/src/client/result/GeoParsedResult.rs @@ -24,6 +24,7 @@ use super::{ParsedRXingResult, ParsedRXingResultType}; * * @author Sean Owen */ +#[derive(Debug)] pub struct GeoParsedRXingResult { latitude: f64, longitude: f64, @@ -116,3 +117,10 @@ impl GeoParsedRXingResult { &self.query } } + +impl PartialEq for GeoParsedRXingResult { + fn eq(&self, other: &Self) -> bool { + self.latitude == other.latitude && self.longitude == other.longitude && self.altitude == other.altitude && self.query == other.query + } +} +impl Eq for GeoParsedRXingResult{} \ No newline at end of file diff --git a/src/client/result/ISBNParsedResult.rs b/src/client/result/ISBNParsedResult.rs index 5dc1136..5344455 100644 --- a/src/client/result/ISBNParsedResult.rs +++ b/src/client/result/ISBNParsedResult.rs @@ -23,6 +23,7 @@ use super::ParsedRXingResult; * * @author jbreiden@google.com (Jeff Breidenbach) */ +#[derive(PartialEq, Eq,Hash,Debug)] pub struct ISBNParsedRXingResult { isbn: String, } diff --git a/src/client/result/ProductParsedResult.rs b/src/client/result/ProductParsedResult.rs index 7f79a6b..498c1e6 100644 --- a/src/client/result/ProductParsedResult.rs +++ b/src/client/result/ProductParsedResult.rs @@ -23,6 +23,7 @@ use super::{ParsedRXingResult, ParsedRXingResultType}; * * @author dswitkin@google.com (Daniel Switkin) */ +#[derive(PartialEq, Eq,Hash,Debug)] pub struct ProductParsedRXingResult { product_id: String, normalized_product_id: String, diff --git a/src/client/result/SMSParsedResult.rs b/src/client/result/SMSParsedResult.rs index bc1cef0..380a1bd 100644 --- a/src/client/result/SMSParsedResult.rs +++ b/src/client/result/SMSParsedResult.rs @@ -24,6 +24,7 @@ use super::{ParsedRXingResult, ParsedRXingResultType, ResultParser}; * * @author Sean Owen */ +#[derive(PartialEq, Eq,Hash,Debug)] pub struct SMSParsedRXingResult { numbers: Vec, vias: Vec, diff --git a/src/client/result/TelParsedResult.rs b/src/client/result/TelParsedResult.rs index f8bfddd..fdb61bc 100644 --- a/src/client/result/TelParsedResult.rs +++ b/src/client/result/TelParsedResult.rs @@ -23,6 +23,7 @@ use super::{ParsedRXingResult, ParsedRXingResultType}; * * @author Sean Owen */ +#[derive(PartialEq, Eq,Hash,Debug)] pub struct TelParsedRXingResult { number: String, telURI: String, diff --git a/src/client/result/TextParsedResult.rs b/src/client/result/TextParsedResult.rs index 8306f2b..6986fd3 100644 --- a/src/client/result/TextParsedResult.rs +++ b/src/client/result/TextParsedResult.rs @@ -24,6 +24,7 @@ use super::{ParsedRXingResult, ParsedRXingResultType}; * * @author Sean Owen */ +#[derive(PartialEq, Eq,Hash, Debug)] pub struct TextParsedRXingResult { text: String, language: String, diff --git a/src/client/result/URIParsedResult.rs b/src/client/result/URIParsedResult.rs index 7b332f7..fa144b2 100644 --- a/src/client/result/URIParsedResult.rs +++ b/src/client/result/URIParsedResult.rs @@ -23,6 +23,7 @@ use super::{ParsedRXingResult, ParsedRXingResultType, ResultParser, URIResultPar * * @author Sean Owen */ +#[derive(PartialEq, Eq,Hash,Debug)] pub struct URIParsedRXingResult { uri: String, title: String, diff --git a/src/client/result/VINParsedResult.rs b/src/client/result/VINParsedResult.rs index 52273ff..21e56a4 100644 --- a/src/client/result/VINParsedResult.rs +++ b/src/client/result/VINParsedResult.rs @@ -21,6 +21,7 @@ use super::{ParsedRXingResult, ParsedRXingResultType}; /** * Represents a parsed result that encodes a Vehicle Identification Number (VIN). */ +#[derive(PartialEq, Eq,Hash,Debug)] pub struct VINParsedRXingResult { vin: String, world_manufacturer_id: String, diff --git a/src/client/result/WifiParsedResult.rs b/src/client/result/WifiParsedResult.rs index 4e0d8d1..82cf65d 100644 --- a/src/client/result/WifiParsedResult.rs +++ b/src/client/result/WifiParsedResult.rs @@ -23,6 +23,7 @@ use super::{ParsedRXingResult, ParsedRXingResultType, ResultParser}; * * @author Vikram Aggarwal */ +#[derive(PartialEq, Eq,Hash,Debug)] pub struct WifiParsedRXingResult { ssid: String, networkEncryption: String, diff --git a/src/client/result/mod.rs b/src/client/result/mod.rs index 880e84a..b247e35 100644 --- a/src/client/result/mod.rs +++ b/src/client/result/mod.rs @@ -87,6 +87,7 @@ mod VINParsedResultTestCase; #[cfg(test)] mod WifiParsedResultTestCase; +#[derive(PartialEq, Eq, Debug)] pub enum ParsedClientResult { TextResult(TextParsedRXingResult), TelResult(TelParsedRXingResult), diff --git a/src/oned/rss/expanded/RSSExpandedImage2resultTestCase.java b/src/oned/rss/expanded/RSSExpandedImage2resultTestCase.java deleted file mode 100644 index 56aa228..0000000 --- a/src/oned/rss/expanded/RSSExpandedImage2resultTestCase.java +++ /dev/null @@ -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); - } - -} diff --git a/src/oned/rss/expanded/mod.rs b/src/oned/rss/expanded/mod.rs index 12f5cfa..c36dc01 100644 --- a/src/oned/rss/expanded/mod.rs +++ b/src/oned/rss/expanded/mod.rs @@ -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; diff --git a/src/oned/rss/expanded/rss_expanded_image_2_result_test_case.rs b/src/oned/rss/expanded/rss_expanded_image_2_result_test_case.rs new file mode 100644 index 0000000..e90155c --- /dev/null +++ b/src/oned/rss/expanded/rss_expanded_image_2_result_test_case.rs @@ -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); + } + + diff --git a/src/oned/rss/expanded/rss_expanded_reader.rs b/src/oned/rss/expanded/rss_expanded_reader.rs index 6bc9c14..b6b1adf 100644 --- a/src/oned/rss/expanded/rss_expanded_reader.rs +++ b/src/oned/rss/expanded/rss_expanded_reader.rs @@ -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;