From 59366fd5a7a1ea7a457cece0550ac79a20c458b6 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Fri, 16 Dec 2022 13:12:06 -0600 Subject: [PATCH] rss_expanded_image_2_string_test_case pass --- .../RSSExpandedImage2stringTestCase.java | 212 ------------------ src/oned/rss/expanded/mod.rs | 3 + .../rss_expanded_image_2_string_test_case.rs | 191 ++++++++++++++++ 3 files changed, 194 insertions(+), 212 deletions(-) delete mode 100644 src/oned/rss/expanded/RSSExpandedImage2stringTestCase.java create mode 100644 src/oned/rss/expanded/rss_expanded_image_2_string_test_case.rs diff --git a/src/oned/rss/expanded/RSSExpandedImage2stringTestCase.java b/src/oned/rss/expanded/RSSExpandedImage2stringTestCase.java deleted file mode 100644 index 915b321..0000000 --- a/src/oned/rss/expanded/RSSExpandedImage2stringTestCase.java +++ /dev/null @@ -1,212 +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. - */ - -/* - * 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", led 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 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.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 RSSExpandedImage2stringTestCase extends Assert { - - @Test - public void testDecodeRow2string1() throws Exception { - assertCorrectImage2string("1.png", "(11)100224(17)110224(3102)000100"); - } - - @Test - public void testDecodeRow2string2() throws Exception { - assertCorrectImage2string("2.png", "(01)90012345678908(3103)001750"); - } - - @Test - public void testDecodeRow2string3() throws Exception { - assertCorrectImage2string("3.png", "(10)12A"); - } - - @Test - public void testDecodeRow2string4() throws Exception { - assertCorrectImage2string("4.png", "(01)98898765432106(3202)012345(15)991231"); - } - - @Test - public void testDecodeRow2string5() throws Exception { - assertCorrectImage2string("5.png", "(01)90614141000015(3202)000150"); - } - - @Test - public void testDecodeRow2string7() throws Exception { - assertCorrectImage2string("7.png", "(10)567(11)010101"); - } - - @Test - public void testDecodeRow2string10() throws Exception { - String expected = "(01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456(423)012345678901"; - assertCorrectImage2string("10.png", expected); - } - - @Test - public void testDecodeRow2string11() throws Exception { - assertCorrectImage2string("11.png", "(01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456"); - } - - @Test - public void testDecodeRow2string12() throws Exception { - assertCorrectImage2string("12.png", "(01)98898765432106(3103)001750"); - } - - @Test - public void testDecodeRow2string13() throws Exception { - assertCorrectImage2string("13.png", "(01)90012345678908(3922)795"); - } - - @Test - public void testDecodeRow2string14() throws Exception { - assertCorrectImage2string("14.png", "(01)90012345678908(3932)0401234"); - } - - @Test - public void testDecodeRow2string15() throws Exception { - assertCorrectImage2string("15.png", "(01)90012345678908(3102)001750(11)100312"); - } - - @Test - public void testDecodeRow2string16() throws Exception { - assertCorrectImage2string("16.png", "(01)90012345678908(3202)001750(11)100312"); - } - - @Test - public void testDecodeRow2string17() throws Exception { - assertCorrectImage2string("17.png", "(01)90012345678908(3102)001750(13)100312"); - } - - @Test - public void testDecodeRow2string18() throws Exception { - assertCorrectImage2string("18.png", "(01)90012345678908(3202)001750(13)100312"); - } - - @Test - public void testDecodeRow2string19() throws Exception { - assertCorrectImage2string("19.png", "(01)90012345678908(3102)001750(15)100312"); - } - - @Test - public void testDecodeRow2string20() throws Exception { - assertCorrectImage2string("20.png", "(01)90012345678908(3202)001750(15)100312"); - } - - @Test - public void testDecodeRow2string21() throws Exception { - assertCorrectImage2string("21.png", "(01)90012345678908(3102)001750(17)100312"); - } - - @Test - public void testDecodeRow2string22() throws Exception { - assertCorrectImage2string("22.png", "(01)90012345678908(3202)001750(17)100312"); - } - - @Test - public void testDecodeRow2string25() throws Exception { - assertCorrectImage2string("25.png", "(10)123"); - } - - @Test - public void testDecodeRow2string26() throws Exception { - assertCorrectImage2string("26.png", "(10)5678(11)010101"); - } - - @Test - public void testDecodeRow2string27() throws Exception { - assertCorrectImage2string("27.png", "(10)1098-1234"); - } - - @Test - public void testDecodeRow2string28() throws Exception { - assertCorrectImage2string("28.png", "(10)1098/1234"); - } - - @Test - public void testDecodeRow2string29() throws Exception { - assertCorrectImage2string("29.png", "(10)1098.1234"); - } - - @Test - public void testDecodeRow2string30() throws Exception { - assertCorrectImage2string("30.png", "(10)1098*1234"); - } - - @Test - public void testDecodeRow2string31() throws Exception { - assertCorrectImage2string("31.png", "(10)1098,1234"); - } - - @Test - public void testDecodeRow2string32() throws Exception { - assertCorrectImage2string("32.png", "(15)991231(3103)001750(10)12A(422)123(21)123456(423)0123456789012"); - } - - private static void assertCorrectImage2string(String fileName, String 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 result; - try { - RSSExpandedReader rssExpandedReader = new RSSExpandedReader(); - result = rssExpandedReader.decodeRow(rowNumber, row, null); - } catch (ReaderException re) { - fail(re.toString()); - return; - } - - assertSame(BarcodeFormat.RSS_EXPANDED, result.getBarcodeFormat()); - assertEquals(expected, result.getText()); - } - -} diff --git a/src/oned/rss/expanded/mod.rs b/src/oned/rss/expanded/mod.rs index c36dc01..80e87e8 100644 --- a/src/oned/rss/expanded/mod.rs +++ b/src/oned/rss/expanded/mod.rs @@ -23,3 +23,6 @@ mod rss_expanded_image_2_binary_test_tase; #[cfg(test)] mod rss_expanded_image_2_result_test_case; + +#[cfg(test)] +mod rss_expanded_image_2_string_test_case; diff --git a/src/oned/rss/expanded/rss_expanded_image_2_string_test_case.rs b/src/oned/rss/expanded/rss_expanded_image_2_string_test_case.rs new file mode 100644 index 0000000..133c9c2 --- /dev/null +++ b/src/oned/rss/expanded/rss_expanded_image_2_string_test_case.rs @@ -0,0 +1,191 @@ +/* + * 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. + */ + +/* + * 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", led by Treelogic + * ( http://www.treelogic.com/ ): + * + * http://www.piramidepse.com/ + */ + +use std::{rc::Rc, collections::HashMap}; + +use crate::{BinaryBitmap, common::{GlobalHistogramBinarizer, BitArray}, BufferedImageLuminanceSource, oned::{rss::expanded::RSSExpandedReader, OneDReader}, BarcodeFormat}; + + +/** + * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) + * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es) + */ + + #[test] + fn testDecodeRow2string1() { + assertCorrectImage2string("1.png", "(11)100224(17)110224(3102)000100"); + } + + #[test] + fn testDecodeRow2string2() { + assertCorrectImage2string("2.png", "(01)90012345678908(3103)001750"); + } + + #[test] + fn testDecodeRow2string3() { + assertCorrectImage2string("3.png", "(10)12A"); + } + + #[test] + fn testDecodeRow2string4() { + assertCorrectImage2string("4.png", "(01)98898765432106(3202)012345(15)991231"); + } + + #[test] + fn testDecodeRow2string5() { + assertCorrectImage2string("5.png", "(01)90614141000015(3202)000150"); + } + + #[test] + fn testDecodeRow2string7() { + assertCorrectImage2string("7.png", "(10)567(11)010101"); + } + + #[test] + fn testDecodeRow2string10() { + let expected = "(01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456(423)012345678901"; + assertCorrectImage2string("10.png", expected); + } + + #[test] + fn testDecodeRow2string11() { + assertCorrectImage2string("11.png", "(01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456"); + } + + #[test] + fn testDecodeRow2string12() { + assertCorrectImage2string("12.png", "(01)98898765432106(3103)001750"); + } + + #[test] + fn testDecodeRow2string13() { + assertCorrectImage2string("13.png", "(01)90012345678908(3922)795"); + } + + #[test] + fn testDecodeRow2string14() { + assertCorrectImage2string("14.png", "(01)90012345678908(3932)0401234"); + } + + #[test] + fn testDecodeRow2string15() { + assertCorrectImage2string("15.png", "(01)90012345678908(3102)001750(11)100312"); + } + + #[test] + fn testDecodeRow2string16() { + assertCorrectImage2string("16.png", "(01)90012345678908(3202)001750(11)100312"); + } + + #[test] + fn testDecodeRow2string17() { + assertCorrectImage2string("17.png", "(01)90012345678908(3102)001750(13)100312"); + } + + #[test] + fn testDecodeRow2string18() { + assertCorrectImage2string("18.png", "(01)90012345678908(3202)001750(13)100312"); + } + + #[test] + fn testDecodeRow2string19() { + assertCorrectImage2string("19.png", "(01)90012345678908(3102)001750(15)100312"); + } + + #[test] + fn testDecodeRow2string20() { + assertCorrectImage2string("20.png", "(01)90012345678908(3202)001750(15)100312"); + } + + #[test] + fn testDecodeRow2string21() { + assertCorrectImage2string("21.png", "(01)90012345678908(3102)001750(17)100312"); + } + + #[test] + fn testDecodeRow2string22() { + assertCorrectImage2string("22.png", "(01)90012345678908(3202)001750(17)100312"); + } + + #[test] + fn testDecodeRow2string25() { + assertCorrectImage2string("25.png", "(10)123"); + } + + #[test] + fn testDecodeRow2string26() { + assertCorrectImage2string("26.png", "(10)5678(11)010101"); + } + + #[test] + fn testDecodeRow2string27() { + assertCorrectImage2string("27.png", "(10)1098-1234"); + } + + #[test] + fn testDecodeRow2string28() { + assertCorrectImage2string("28.png", "(10)1098/1234"); + } + + #[test] + fn testDecodeRow2string29() { + assertCorrectImage2string("29.png", "(10)1098.1234"); + } + + #[test] + fn testDecodeRow2string30() { + assertCorrectImage2string("30.png", "(10)1098*1234"); + } + + #[test] + fn testDecodeRow2string31() { + assertCorrectImage2string("31.png", "(10)1098,1234"); + } + + #[test] + fn testDecodeRow2string32() { + assertCorrectImage2string("32.png", "(15)991231(3103)001750(10)12A(422)123(21)123456(423)0123456789012"); + } + + fn assertCorrectImage2string( fileName:&str, expected:&str) + { + let path = format!("test_resources/blackbox/rssexpanded-1/{}",fileName); + + let image = image::open(path).expect("load image"); + let binaryMap = + BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(BufferedImageLuminanceSource::new(image))))); + let rowNumber = binaryMap.getHeight() / 2; + let row = binaryMap.getBlackRow(rowNumber, &mut BitArray::new()).expect("get row"); + + let mut rssExpandedReader = RSSExpandedReader::new(); + let result = rssExpandedReader.decodeRow(rowNumber as u32, &row, &HashMap::new()).expect("should decode"); + + + + assert_eq!(&BarcodeFormat::RSS_EXPANDED, result.getBarcodeFormat()); + assert_eq!(expected, result.getText()); + } +