mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
stacked test internal
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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.util.List;
|
||||
|
||||
import com.google.zxing.oned.OneDReader;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* Tests {@link RSSExpandedReader} handling of stacked RSS barcodes.
|
||||
*/
|
||||
public final class RSSExpandedStackedInternalTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testDecodingRowByRow() throws Exception {
|
||||
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
|
||||
|
||||
BinaryBitmap binaryMap = TestCaseUtil.getBinaryBitmap("src/test/resources/blackbox/rssexpandedstacked-2/1000.png");
|
||||
|
||||
int firstRowNumber = binaryMap.getHeight() / 3;
|
||||
BitArray firstRow = binaryMap.getBlackRow(firstRowNumber, null);
|
||||
try {
|
||||
rssExpandedReader.decodeRow2pairs(firstRowNumber, firstRow);
|
||||
fail(NotFoundException.class.getName() + " expected");
|
||||
} catch (NotFoundException nfe) {
|
||||
// ok
|
||||
}
|
||||
|
||||
assertEquals(1, rssExpandedReader.getRows().size());
|
||||
ExpandedRow firstExpandedRow = rssExpandedReader.getRows().get(0);
|
||||
assertEquals(firstRowNumber, firstExpandedRow.getRowNumber());
|
||||
|
||||
assertEquals(2, firstExpandedRow.getPairs().size());
|
||||
|
||||
firstExpandedRow.getPairs().get(1).getFinderPattern().getStartEnd()[1] = 0;
|
||||
|
||||
int secondRowNumber = 2 * binaryMap.getHeight() / 3;
|
||||
BitArray secondRow = binaryMap.getBlackRow(secondRowNumber, null);
|
||||
secondRow.reverse();
|
||||
|
||||
List<ExpandedPair> totalPairs = rssExpandedReader.decodeRow2pairs(secondRowNumber, secondRow);
|
||||
|
||||
RXingResult result = RSSExpandedReader.constructRXingResult(totalPairs);
|
||||
assertEquals("(01)98898765432106(3202)012345(15)991231", result.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompleteDecode() throws Exception {
|
||||
OneDReader rssExpandedReader = new RSSExpandedReader();
|
||||
|
||||
BinaryBitmap binaryMap = TestCaseUtil.getBinaryBitmap("src/test/resources/blackbox/rssexpandedstacked-2/1000.png");
|
||||
|
||||
RXingResult result = rssExpandedReader.decode(binaryMap);
|
||||
assertEquals("(01)98898765432106(3202)012345(15)991231", result.getText());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -63,6 +63,11 @@ impl ExpandedPair {
|
||||
&self.finderPattern
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn getFinderPatternMut(&mut self) -> &mut Option<FinderPattern> {
|
||||
&mut self.finderPattern
|
||||
}
|
||||
|
||||
pub fn mustBeLast(&self) -> bool {
|
||||
self.rightChar.is_none()
|
||||
}
|
||||
|
||||
@@ -35,6 +35,11 @@ impl ExpandedRow {
|
||||
&self.pairs
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn getPairsMut(&mut self) -> &mut [ExpandedPair]{
|
||||
&mut self.pairs
|
||||
}
|
||||
|
||||
pub fn getRowNumber(&self) -> u32 {
|
||||
self.rowNumber
|
||||
}
|
||||
|
||||
@@ -26,3 +26,9 @@ mod rss_expanded_image_2_result_test_case;
|
||||
|
||||
#[cfg(test)]
|
||||
mod rss_expanded_image_2_string_test_case;
|
||||
|
||||
#[cfg(test)]
|
||||
mod rss_expanded_stacked_internal_test_case;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_case_util;
|
||||
@@ -142,8 +142,8 @@ pub struct RSSExpandedReader {
|
||||
oddCounts: [u32; 4],
|
||||
evenCounts: [u32; 4],
|
||||
|
||||
pairs: Vec<ExpandedPair>, //new ArrayList<>(MAX_PAIRS);
|
||||
rows: Vec<ExpandedRow>, // new ArrayList<>();
|
||||
pub(super) pairs: Vec<ExpandedPair>, //new ArrayList<>(MAX_PAIRS);
|
||||
pub(super) rows: Vec<ExpandedRow>, // new ArrayList<>();
|
||||
startEnd: [u32; 2], // new int[2];
|
||||
startFromEven: bool,
|
||||
}
|
||||
@@ -529,12 +529,17 @@ impl RSSExpandedReader {
|
||||
}
|
||||
|
||||
// Only used for unit testing
|
||||
fn getRows(&self) -> &[ExpandedRow] {
|
||||
&self.rows
|
||||
#[cfg(test)]
|
||||
pub(crate) fn getRowsMut(&mut self) -> &mut [ExpandedRow] {
|
||||
&mut self.rows
|
||||
}
|
||||
#[cfg(test)]
|
||||
pub(crate) fn getRows(& self) -> & [ExpandedRow] {
|
||||
& self.rows
|
||||
}
|
||||
|
||||
// Not private for unit testing
|
||||
fn constructRXingResult(pairs: &[ExpandedPair]) -> Result<RXingResult, Exceptions> {
|
||||
pub(crate) fn constructRXingResult(pairs: &[ExpandedPair]) -> Result<RXingResult, Exceptions> {
|
||||
let binary = bit_array_builder::buildBitArray(&pairs.to_vec());
|
||||
|
||||
let mut decoder = abstract_expanded_decoder::createDecoder(&binary)?;
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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 crate::{Exceptions, common::BitArray, oned::rss::expanded::ExpandedPair, Reader};
|
||||
|
||||
use super::{RSSExpandedReader, test_case_util};
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link RSSExpandedReader} handling of stacked RSS barcodes.
|
||||
*/
|
||||
|
||||
|
||||
#[test]
|
||||
fn testDecodingRowByRow() {
|
||||
let mut rssExpandedReader = RSSExpandedReader::new();
|
||||
|
||||
let binaryMap = test_case_util::getBinaryBitmap("1000.png");
|
||||
|
||||
let firstRowNumber = binaryMap.getHeight() / 3;
|
||||
let firstRow = binaryMap.getBlackRow(firstRowNumber, &mut BitArray::new()).expect("get row");
|
||||
|
||||
// let tester = ;
|
||||
|
||||
assert!(|| -> Result<Vec<ExpandedPair>,Exceptions> {
|
||||
rssExpandedReader.decodeRow2pairs(firstRowNumber as u32, &firstRow)
|
||||
// fail(NotFoundException.class.getName() + " expected");
|
||||
}().is_err());
|
||||
|
||||
|
||||
assert_eq!(1, rssExpandedReader.getRows().len());
|
||||
let firstExpandedRow = &mut rssExpandedReader.rows[0]; //&mut rssExpandedReader.getRowsMut()[0];//.expect("not None");
|
||||
|
||||
assert_eq!(firstRowNumber as u32, firstExpandedRow.getRowNumber());
|
||||
|
||||
assert_eq!(2, firstExpandedRow.getPairs().len());
|
||||
|
||||
firstExpandedRow.getPairsMut()[1].getFinderPatternMut().as_mut().unwrap().getStartEndMut()[1] = 0;
|
||||
rssExpandedReader.pairs.last_mut().as_mut().unwrap().getFinderPatternMut().as_mut().unwrap().getStartEndMut()[1] = 0;
|
||||
|
||||
let secondRowNumber = 2 * binaryMap.getHeight() / 3;
|
||||
let mut secondRow = binaryMap.getBlackRow(secondRowNumber, &mut BitArray::new()).expect("get row");
|
||||
secondRow.reverse();
|
||||
|
||||
let totalPairs = rssExpandedReader.decodeRow2pairs(secondRowNumber as u32, &secondRow).expect("decode pairs");
|
||||
|
||||
let result = RSSExpandedReader::constructRXingResult(&totalPairs).expect("construct");
|
||||
assert_eq!("(01)98898765432106(3202)012345(15)991231", result.getText());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn testCompleteDecode() {
|
||||
let mut rssExpandedReader = RSSExpandedReader::new();
|
||||
|
||||
let binaryMap = test_case_util::getBinaryBitmap("1000.png");
|
||||
|
||||
let result = rssExpandedReader.decode(&binaryMap).expect("decode");
|
||||
assert_eq!("(01)98898765432106(3202)012345(15)991231", result.getText());
|
||||
}
|
||||
|
||||
@@ -24,33 +24,25 @@
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded;
|
||||
use std::rc::Rc;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
use image::DynamicImage;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
use crate::{BinaryBitmap, common::GlobalHistogramBinarizer, BufferedImageLuminanceSource};
|
||||
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
import com.google.zxing.common.GlobalHistogramBinarizer;
|
||||
|
||||
final class TestCaseUtil {
|
||||
fn getBufferedImage( fileName:&str) -> DynamicImage {
|
||||
let path = format!("test_resources/blackbox/rssexpandedstacked-2/{}",fileName);
|
||||
|
||||
private TestCaseUtil() {
|
||||
let image = image::open(path).expect("load image");
|
||||
|
||||
image
|
||||
}
|
||||
|
||||
private static BufferedImage getBufferedImage(String path) throws IOException {
|
||||
Path file = AbstractBlackBoxTestCase.buildTestBase(path);
|
||||
return ImageIO.read(file.toFile());
|
||||
pub(crate) fn getBinaryBitmap( fileName:&str) -> BinaryBitmap {
|
||||
let bufferedImage = getBufferedImage(fileName);
|
||||
let binaryMap =
|
||||
BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(BufferedImageLuminanceSource::new(bufferedImage)))));
|
||||
|
||||
binaryMap
|
||||
}
|
||||
|
||||
static BinaryBitmap getBinaryBitmap(String path) throws IOException {
|
||||
BufferedImage bufferedImage = getBufferedImage(path);
|
||||
BufferedImageLuminanceSource luminanceSource = new BufferedImageLuminanceSource(bufferedImage);
|
||||
return new BinaryBitmap(new GlobalHistogramBinarizer(luminanceSource));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,6 +48,11 @@ impl FinderPattern {
|
||||
&self.startEnd
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate)fn getStartEndMut(&mut self) -> &mut [usize]{
|
||||
&mut self.startEnd
|
||||
}
|
||||
|
||||
pub fn getRXingResultPoints(&self) -> &[RXingResultPoint] {
|
||||
&self.resultPoints
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user