mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
moved java files for pre-convert
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 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.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class RSS14BlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public RSS14BlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/rss14-1", new MultiFormatReader(), BarcodeFormat.RSS_14);
|
||||
addTest(6, 6, 0.0f);
|
||||
addTest(6, 6, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 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.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class RSS14BlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public RSS14BlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/rss14-2", new MultiFormatReader(), BarcodeFormat.RSS_14);
|
||||
addTest(4, 8, 1, 1, 0.0f);
|
||||
addTest(3, 8, 0, 1, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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 com.google.zxing.common.BitArray;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
public final class BinaryUtil {
|
||||
|
||||
private static final Pattern ONE = Pattern.compile("1");
|
||||
private static final Pattern ZERO = Pattern.compile("0");
|
||||
private static final Pattern SPACE = Pattern.compile(" ");
|
||||
|
||||
private BinaryUtil() {
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructs a BitArray from a String like the one returned from BitArray.toString()
|
||||
*/
|
||||
public static BitArray buildBitArrayFromString(CharSequence data) {
|
||||
CharSequence dotsAndXs = ZERO.matcher(ONE.matcher(data).replaceAll("X")).replaceAll(".");
|
||||
BitArray binary = new BitArray(SPACE.matcher(dotsAndXs).replaceAll("").length());
|
||||
int counter = 0;
|
||||
|
||||
for (int i = 0; i < dotsAndXs.length(); ++i) {
|
||||
if (i % 9 == 0) { // spaces
|
||||
if (dotsAndXs.charAt(i) != ' ') {
|
||||
throw new IllegalStateException("space expected");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
char currentChar = dotsAndXs.charAt(i);
|
||||
if (currentChar == 'X' || currentChar == 'x') {
|
||||
binary.set(counter);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
return binary;
|
||||
}
|
||||
|
||||
public static BitArray buildBitArrayFromStringWithoutSpaces(CharSequence data) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
CharSequence dotsAndXs = ZERO.matcher(ONE.matcher(data).replaceAll("X")).replaceAll(".");
|
||||
int current = 0;
|
||||
while (current < dotsAndXs.length()) {
|
||||
sb.append(' ');
|
||||
for (int i = 0; i < 8 && current < dotsAndXs.length(); ++i) {
|
||||
sb.append(dotsAndXs.charAt(current));
|
||||
current++;
|
||||
}
|
||||
}
|
||||
return buildBitArrayFromString(sb.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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 com.google.zxing.common.BitArray;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
public final class BinaryUtilTest extends Assert {
|
||||
|
||||
private static final Pattern SPACE = Pattern.compile(" ");
|
||||
|
||||
@Test
|
||||
public void testBuildBitArrayFromString() {
|
||||
|
||||
CharSequence data = " ..X..X.. ..XXX... XXXXXXXX ........";
|
||||
check(data);
|
||||
|
||||
data = " XXX..X..";
|
||||
check(data);
|
||||
|
||||
data = " XX";
|
||||
check(data);
|
||||
|
||||
data = " ....XX.. ..XX";
|
||||
check(data);
|
||||
|
||||
data = " ....XX.. ..XX..XX ....X.X. ........";
|
||||
check(data);
|
||||
}
|
||||
|
||||
private static void check(CharSequence data) {
|
||||
BitArray binary = BinaryUtil.buildBitArrayFromString(data);
|
||||
assertEquals(data, binary.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildBitArrayFromStringWithoutSpaces() {
|
||||
CharSequence data = " ..X..X.. ..XXX... XXXXXXXX ........";
|
||||
checkWithoutSpaces(data);
|
||||
|
||||
data = " XXX..X..";
|
||||
checkWithoutSpaces(data);
|
||||
|
||||
data = " XX";
|
||||
checkWithoutSpaces(data);
|
||||
|
||||
data = " ....XX.. ..XX";
|
||||
checkWithoutSpaces(data);
|
||||
|
||||
data = " ....XX.. ..XX..XX ....X.X. ........";
|
||||
checkWithoutSpaces(data);
|
||||
}
|
||||
|
||||
private static void checkWithoutSpaces(CharSequence data) {
|
||||
CharSequence dataWithoutSpaces = SPACE.matcher(data).replaceAll("");
|
||||
BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(dataWithoutSpaces);
|
||||
assertEquals(data, binary.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.oned.rss.DataCharacter;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
public final class BitArrayBuilderTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void testBuildBitArray1() {
|
||||
int[][] pairValues = {{19}, {673, 16}};
|
||||
|
||||
String expected = " .......X ..XX..X. X.X....X .......X ....";
|
||||
|
||||
checkBinary(pairValues, expected);
|
||||
}
|
||||
|
||||
private static void checkBinary(int[][] pairValues, String expected) {
|
||||
BitArray binary = buildBitArray(pairValues);
|
||||
assertEquals(expected, binary.toString());
|
||||
}
|
||||
|
||||
private static BitArray buildBitArray(int[][] pairValues) {
|
||||
List<ExpandedPair> pairs = new ArrayList<>();
|
||||
for (int i = 0; i < pairValues.length; ++i) {
|
||||
int [] pair = pairValues[i];
|
||||
|
||||
DataCharacter leftChar;
|
||||
if (i == 0) {
|
||||
leftChar = null;
|
||||
} else {
|
||||
leftChar = new DataCharacter(pair[0], 0);
|
||||
}
|
||||
|
||||
DataCharacter rightChar;
|
||||
if (i == 0) {
|
||||
rightChar = new DataCharacter(pair[0], 0);
|
||||
} else if (pair.length == 2) {
|
||||
rightChar = new DataCharacter(pair[1], 0);
|
||||
} else {
|
||||
rightChar = null;
|
||||
}
|
||||
|
||||
ExpandedPair expandedPair = new ExpandedPair(leftChar, rightChar, null);
|
||||
pairs.add(expandedPair);
|
||||
}
|
||||
|
||||
return BitArrayBuilder.buildBitArray(pairs);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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 com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.oned.rss.expanded.decoders.AbstractExpandedDecoder;
|
||||
|
||||
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 ExpandedInformationDecoderTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void testNoAi() throws Exception {
|
||||
BitArray information = BinaryUtil.buildBitArrayFromString(" .......X ..XX..X. X.X....X .......X ....");
|
||||
|
||||
AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(information);
|
||||
String decoded = decoder.parseInformation();
|
||||
assertEquals("(10)12A", decoded);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A test of {@link RSSExpandedReader} against a fixed test set of images.
|
||||
*/
|
||||
public final class RSSExpandedBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public RSSExpandedBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/rssexpanded-1", new MultiFormatReader(), BarcodeFormat.RSS_EXPANDED);
|
||||
addTest(32, 32, 0.0f);
|
||||
addTest(32, 32, 180.0f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A test of {@link RSSExpandedReader} against a fixed test set of images.
|
||||
*/
|
||||
public final class RSSExpandedBlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public RSSExpandedBlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/rssexpanded-2", new MultiFormatReader(), BarcodeFormat.RSS_EXPANDED);
|
||||
addTest(21, 23, 0.0f);
|
||||
addTest(21, 23, 180.0f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A test of {@link RSSExpandedReader} against a fixed test set of images.
|
||||
*/
|
||||
public final class RSSExpandedBlackBox3TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public RSSExpandedBlackBox3TestCase() {
|
||||
super("src/test/resources/blackbox/rssexpanded-3", new MultiFormatReader(), BarcodeFormat.RSS_EXPANDED);
|
||||
addTest(117, 117, 0.0f);
|
||||
addTest(117, 117, 180.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* 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 java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.ReaderException;
|
||||
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 RSSExpandedImage2binaryTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary1() throws Exception {
|
||||
// (11)100224(17)110224(3102)000100
|
||||
assertCorrectImage2binary("1.png",
|
||||
" ...X...X .X....X. .XX...X. X..X...X ...XX.X. ..X.X... ..X.X..X ...X..X. X.X....X .X....X. .....X.. X...X...");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary2() throws Exception {
|
||||
// (01)90012345678908(3103)001750
|
||||
assertCorrectImage2binary("2.png", " ..X..... ......X. .XXX.X.X .X...XX. XXXXX.XX XX.X.... .XX.XX.X .XX.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary3() throws Exception {
|
||||
// (10)12A
|
||||
assertCorrectImage2binary("3.png", " .......X ..XX..X. X.X....X .......X ....");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary4() throws Exception {
|
||||
// (01)98898765432106(3202)012345(15)991231
|
||||
assertCorrectImage2binary(
|
||||
"4.png", " ..XXXX.X XX.XXXX. .XXX.XX. XX..X... .XXXXX.. XX.X..X. ..XX..XX XX.X.XXX X..XX..X .X.XXXXX XXXX");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary5() throws Exception {
|
||||
// (01)90614141000015(3202)000150
|
||||
assertCorrectImage2binary(
|
||||
"5.png", " ..X.X... .XXXX.X. XX..XXXX ....XX.. X....... ....X... ....X..X .XX.");
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:lineLength")
|
||||
@Test
|
||||
public void testDecodeRow2binary10() throws Exception {
|
||||
// (01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456(423)0123456789012
|
||||
assertCorrectImage2binary("10.png",
|
||||
" .X.XX..X XX.XXXX. .XXX.XX. XX..X... .XXXXX.. XX.X..X. ..XX...X XX.X.... X.X.X.X. X.X..X.X .X....X. XX...X.. ...XX.X. .XXXXXX. .X..XX.. X.X.X... .X...... XXXX.... XX.XX... XXXXX.X. ...XXXXX .....X.X ...X.... X.XXX..X X.X.X... XX.XX..X .X..X..X .X.X.X.X X.XX...X .XX.XXX. XXX.X.XX ..X.");
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:lineLength")
|
||||
@Test
|
||||
public void testDecodeRow2binary11() throws Exception {
|
||||
// (01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456
|
||||
assertCorrectImage2binary("11.png",
|
||||
" .X.XX..X XX.XXXX. .XXX.XX. XX..X... .XXXXX.. XX.X..X. ..XX...X XX.X.... X.X.X.X. X.X..X.X .X....X. XX...X.. ...XX.X. .XXXXXX. .X..XX.. X.X.X... .X...... XXXX.... XX.XX... XXXXX.X. ...XXXXX .....X.X ...X.... X.XXX..X X.X.X... ....");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary12() throws Exception {
|
||||
// (01)98898765432106(3103)001750
|
||||
assertCorrectImage2binary(
|
||||
"12.png", " ..X..XX. XXXX..XX X.XX.XX. .X....XX XXX..XX. X..X.... .XX.XX.X .XX.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary13() throws Exception {
|
||||
// (01)90012345678908(3922)795
|
||||
assertCorrectImage2binary(
|
||||
"13.png", " ..XX..X. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. X.X.XXXX .X..X..X ......X.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary14() throws Exception {
|
||||
// (01)90012345678908(3932)0401234
|
||||
assertCorrectImage2binary(
|
||||
"14.png", " ..XX.X.. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. X.....X. X.....X. X.X.X.XX .X...... X...");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary15() throws Exception {
|
||||
// (01)90012345678908(3102)001750(11)100312
|
||||
assertCorrectImage2binary(
|
||||
"15.png", " ..XXX... ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary16() throws Exception {
|
||||
// (01)90012345678908(3202)001750(11)100312
|
||||
assertCorrectImage2binary(
|
||||
"16.png", " ..XXX..X ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary17() throws Exception {
|
||||
// (01)90012345678908(3102)001750(13)100312
|
||||
assertCorrectImage2binary(
|
||||
"17.png", " ..XXX.X. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary18() throws Exception {
|
||||
// (01)90012345678908(3202)001750(13)100312
|
||||
assertCorrectImage2binary(
|
||||
"18.png", " ..XXX.XX ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary19() throws Exception {
|
||||
// (01)90012345678908(3102)001750(15)100312
|
||||
assertCorrectImage2binary(
|
||||
"19.png", " ..XXXX.. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary20() throws Exception {
|
||||
// (01)90012345678908(3202)001750(15)100312
|
||||
assertCorrectImage2binary(
|
||||
"20.png", " ..XXXX.X ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary21() throws Exception {
|
||||
// (01)90012345678908(3102)001750(17)100312
|
||||
assertCorrectImage2binary(
|
||||
"21.png", " ..XXXXX. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2binary22() throws Exception {
|
||||
// (01)90012345678908(3202)001750(17)100312
|
||||
assertCorrectImage2binary(
|
||||
"22.png", " ..XXXXXX ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..");
|
||||
}
|
||||
|
||||
private static void assertCorrectImage2binary(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);
|
||||
|
||||
List<ExpandedPair> pairs;
|
||||
try {
|
||||
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
|
||||
pairs = rssExpandedReader.decodeRow2pairs(rowNumber, row);
|
||||
} catch (ReaderException re) {
|
||||
fail(re.toString());
|
||||
return;
|
||||
}
|
||||
BitArray binary = BitArrayBuilder.buildBitArray(pairs);
|
||||
assertEquals(expected, binary.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.Result;
|
||||
import com.google.zxing.client.result.ExpandedProductParsedResult;
|
||||
import com.google.zxing.client.result.ParsedResult;
|
||||
import com.google.zxing.client.result.ResultParser;
|
||||
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
|
||||
ExpandedProductParsedResult expected =
|
||||
new ExpandedProductParsedResult("(01)90012345678908(3103)001750",
|
||||
"90012345678908",
|
||||
null, null, null, null, null, null,
|
||||
"001750",
|
||||
ExpandedProductParsedResult.KILOGRAM,
|
||||
"3", null, null, null, new HashMap<>());
|
||||
|
||||
assertCorrectImage2result("2.png", expected);
|
||||
}
|
||||
|
||||
private static void assertCorrectImage2result(String fileName, ExpandedProductParsedResult 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);
|
||||
|
||||
Result theResult;
|
||||
try {
|
||||
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
|
||||
theResult = rssExpandedReader.decodeRow(rowNumber, row, null);
|
||||
} catch (ReaderException re) {
|
||||
fail(re.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
assertSame(BarcodeFormat.RSS_EXPANDED, theResult.getBarcodeFormat());
|
||||
|
||||
ParsedResult result = ResultParser.parseResult(theResult);
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* 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.Result;
|
||||
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);
|
||||
|
||||
Result 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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.common.GlobalHistogramBinarizer;
|
||||
import com.google.zxing.oned.rss.DataCharacter;
|
||||
import com.google.zxing.oned.rss.FinderPattern;
|
||||
|
||||
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 RSSExpandedInternalTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testFindFinderPatterns() throws Exception {
|
||||
BufferedImage image = readImage("2.png");
|
||||
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
|
||||
int rowNumber = binaryMap.getHeight() / 2;
|
||||
BitArray row = binaryMap.getBlackRow(rowNumber, null);
|
||||
List<ExpandedPair> previousPairs = new ArrayList<>();
|
||||
|
||||
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
|
||||
ExpandedPair pair1 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
|
||||
previousPairs.add(pair1);
|
||||
FinderPattern finderPattern = pair1.getFinderPattern();
|
||||
assertNotNull(finderPattern);
|
||||
assertEquals(0, finderPattern.getValue());
|
||||
|
||||
ExpandedPair pair2 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
|
||||
previousPairs.add(pair2);
|
||||
finderPattern = pair2.getFinderPattern();
|
||||
assertNotNull(finderPattern);
|
||||
assertEquals(1, finderPattern.getValue());
|
||||
|
||||
ExpandedPair pair3 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
|
||||
previousPairs.add(pair3);
|
||||
finderPattern = pair3.getFinderPattern();
|
||||
assertNotNull(finderPattern);
|
||||
assertEquals(1, finderPattern.getValue());
|
||||
|
||||
try {
|
||||
rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
|
||||
// the previous was the last pair
|
||||
fail(NotFoundException.class.getName() + " expected");
|
||||
} catch (NotFoundException nfe) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveNextPairPatterns() throws Exception {
|
||||
BufferedImage image = readImage("3.png");
|
||||
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
|
||||
int rowNumber = binaryMap.getHeight() / 2;
|
||||
BitArray row = binaryMap.getBlackRow(rowNumber, null);
|
||||
List<ExpandedPair> previousPairs = new ArrayList<>();
|
||||
|
||||
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
|
||||
ExpandedPair pair1 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
|
||||
previousPairs.add(pair1);
|
||||
FinderPattern finderPattern = pair1.getFinderPattern();
|
||||
assertNotNull(finderPattern);
|
||||
assertEquals(0, finderPattern.getValue());
|
||||
|
||||
ExpandedPair pair2 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
|
||||
previousPairs.add(pair2);
|
||||
finderPattern = pair2.getFinderPattern();
|
||||
assertNotNull(finderPattern);
|
||||
assertEquals(0, finderPattern.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeCheckCharacter() throws Exception {
|
||||
BufferedImage image = readImage("3.png");
|
||||
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
|
||||
BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);
|
||||
|
||||
int[] startEnd = {145, 243}; //image pixels where the A1 pattern starts (at 124) and ends (at 214)
|
||||
int value = 0; // A
|
||||
FinderPattern finderPatternA1 = new FinderPattern(value, startEnd, startEnd[0], startEnd[1], image.getHeight() / 2);
|
||||
//{1, 8, 4, 1, 1};
|
||||
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
|
||||
DataCharacter dataCharacter = rssExpandedReader.decodeDataCharacter(row, finderPatternA1, true, true);
|
||||
|
||||
assertEquals(98, dataCharacter.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeDataCharacter() throws Exception {
|
||||
BufferedImage image = readImage("3.png");
|
||||
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
|
||||
BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);
|
||||
|
||||
int[] startEnd = {145, 243}; //image pixels where the A1 pattern starts (at 124) and ends (at 214)
|
||||
int value = 0; // A
|
||||
FinderPattern finderPatternA1 = new FinderPattern(value, startEnd, startEnd[0], startEnd[1], image.getHeight() / 2);
|
||||
//{1, 8, 4, 1, 1};
|
||||
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
|
||||
DataCharacter dataCharacter = rssExpandedReader.decodeDataCharacter(row, finderPatternA1, true, false);
|
||||
|
||||
assertEquals(19, dataCharacter.getValue());
|
||||
assertEquals(1007, dataCharacter.getChecksumPortion());
|
||||
}
|
||||
|
||||
private static BufferedImage readImage(String fileName) throws IOException {
|
||||
Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName);
|
||||
return ImageIO.read(path.toFile());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A test of {@link RSSExpandedReader} against a fixed test set of images including
|
||||
* stacked RSS barcodes.
|
||||
*/
|
||||
public final class RSSExpandedStackedBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public RSSExpandedStackedBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/rssexpandedstacked-1", new MultiFormatReader(), BarcodeFormat.RSS_EXPANDED);
|
||||
addTest(59, 64, 0.0f);
|
||||
addTest(59, 64, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A test of {@link RSSExpandedReader} against a fixed test set of images including
|
||||
* stacked RSS barcodes.
|
||||
*/
|
||||
public final class RSSExpandedStackedBlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public RSSExpandedStackedBlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/rssexpandedstacked-2", new MultiFormatReader(), BarcodeFormat.RSS_EXPANDED);
|
||||
addTest(2, 7, 0.0f);
|
||||
addTest(2, 7, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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.Result;
|
||||
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);
|
||||
|
||||
Result result = RSSExpandedReader.constructResult(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");
|
||||
|
||||
Result result = rssExpandedReader.decode(binaryMap);
|
||||
assertEquals("(01)98898765432106(3202)012345(15)991231", result.getText());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
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 {
|
||||
|
||||
private TestCaseUtil() {
|
||||
}
|
||||
|
||||
private static BufferedImage getBufferedImage(String path) throws IOException {
|
||||
Path file = AbstractBlackBoxTestCase.buildTestBase(path);
|
||||
return ImageIO.read(file.toFile());
|
||||
}
|
||||
|
||||
static BinaryBitmap getBinaryBitmap(String path) throws IOException {
|
||||
BufferedImage bufferedImage = getBufferedImage(path);
|
||||
BufferedImageLuminanceSource luminanceSource = new BufferedImageLuminanceSource(bufferedImage);
|
||||
return new BinaryBitmap(new GlobalHistogramBinarizer(luminanceSource));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.decoders;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
public final class AI013103DecoderTest extends AbstractDecoderTest {
|
||||
|
||||
private static final String header = "..X..";
|
||||
|
||||
@Test
|
||||
public void test0131031() throws Exception {
|
||||
CharSequence data = header + compressedGtin900123456798908 + compressed15bitWeight1750;
|
||||
String expected = "(01)90012345678908(3103)001750";
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test0131032() throws Exception {
|
||||
CharSequence data = header + compressedGtin900000000000008 + compressed15bitWeight0;
|
||||
String expected = "(01)90000000000003(3103)000000";
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test(expected = NotFoundException.class)
|
||||
public void test013103invalid() throws Exception {
|
||||
CharSequence data = header + compressedGtin900123456798908 + compressed15bitWeight1750 + "..";
|
||||
assertCorrectBinaryString(data, "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.decoders;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
public final class AI0132023203DecoderTest extends AbstractDecoderTest {
|
||||
|
||||
private static final String header = "..X.X";
|
||||
|
||||
@Test
|
||||
public void test0132021() throws Exception {
|
||||
CharSequence data = header + compressedGtin900123456798908 + compressed15bitWeight1750;
|
||||
String expected = "(01)90012345678908(3202)001750";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test0132031() throws Exception {
|
||||
CharSequence data = header + compressedGtin900123456798908 + compressed15bitWeight11750;
|
||||
String expected = "(01)90012345678908(3203)001750";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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.decoders;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
public final class AI013X0X1XDecoderTest extends AbstractDecoderTest {
|
||||
|
||||
private static final String header310x11 = "..XXX...";
|
||||
private static final String header320x11 = "..XXX..X";
|
||||
private static final String header310x13 = "..XXX.X.";
|
||||
private static final String header320x13 = "..XXX.XX";
|
||||
private static final String header310x15 = "..XXXX..";
|
||||
private static final String header320x15 = "..XXXX.X";
|
||||
private static final String header310x17 = "..XXXXX.";
|
||||
private static final String header320x17 = "..XXXXXX";
|
||||
|
||||
@Test
|
||||
public void test01310X1XendDate() throws Exception {
|
||||
CharSequence data = header310x11 + compressedGtin900123456798908 + compressed20bitWeight1750 + compressedDateEnd;
|
||||
String expected = "(01)90012345678908(3100)001750";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01310X111() throws Exception {
|
||||
CharSequence data = header310x11 + compressedGtin900123456798908 + compressed20bitWeight1750 +
|
||||
compressedDateMarch12th2010;
|
||||
String expected = "(01)90012345678908(3100)001750(11)100312";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01320X111() throws Exception {
|
||||
CharSequence data = header320x11 + compressedGtin900123456798908 + compressed20bitWeight1750 +
|
||||
compressedDateMarch12th2010;
|
||||
String expected = "(01)90012345678908(3200)001750(11)100312";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01310X131() throws Exception {
|
||||
CharSequence data = header310x13 + compressedGtin900123456798908 + compressed20bitWeight1750 +
|
||||
compressedDateMarch12th2010;
|
||||
String expected = "(01)90012345678908(3100)001750(13)100312";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01320X131() throws Exception {
|
||||
CharSequence data = header320x13 + compressedGtin900123456798908 + compressed20bitWeight1750 +
|
||||
compressedDateMarch12th2010;
|
||||
String expected = "(01)90012345678908(3200)001750(13)100312";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01310X151() throws Exception {
|
||||
CharSequence data = header310x15 + compressedGtin900123456798908 + compressed20bitWeight1750 +
|
||||
compressedDateMarch12th2010;
|
||||
String expected = "(01)90012345678908(3100)001750(15)100312";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01320X151() throws Exception {
|
||||
CharSequence data = header320x15 + compressedGtin900123456798908 + compressed20bitWeight1750 +
|
||||
compressedDateMarch12th2010;
|
||||
String expected = "(01)90012345678908(3200)001750(15)100312";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01310X171() throws Exception {
|
||||
CharSequence data = header310x17 + compressedGtin900123456798908 + compressed20bitWeight1750 +
|
||||
compressedDateMarch12th2010;
|
||||
String expected = "(01)90012345678908(3100)001750(17)100312";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01320X171() throws Exception {
|
||||
CharSequence data = header320x17 + compressedGtin900123456798908 + compressed20bitWeight1750 +
|
||||
compressedDateMarch12th2010;
|
||||
String expected = "(01)90012345678908(3200)001750(17)100312";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.oned.rss.expanded.BinaryUtil;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
abstract class AbstractDecoderTest extends Assert {
|
||||
|
||||
static final String numeric10 = "..X..XX";
|
||||
static final String numeric12 = "..X.X.X";
|
||||
static final String numeric1FNC1 = "..XXX.X";
|
||||
// static final String numericFNC11 = "XXX.XXX";
|
||||
|
||||
static final String numeric2alpha = "....";
|
||||
|
||||
static final String alphaA = "X.....";
|
||||
static final String alphaFNC1 = ".XXXX";
|
||||
static final String alpha2numeric = "...";
|
||||
static final String alpha2isoiec646 = "..X..";
|
||||
|
||||
static final String i646B = "X.....X";
|
||||
static final String i646C = "X....X.";
|
||||
static final String i646FNC1 = ".XXXX";
|
||||
static final String isoiec6462alpha = "..X..";
|
||||
|
||||
static final String compressedGtin900123456798908 = ".........X..XXX.X.X.X...XX.XXXXX.XXXX.X.";
|
||||
static final String compressedGtin900000000000008 = "........................................";
|
||||
|
||||
static final String compressed15bitWeight1750 = "....XX.XX.X.XX.";
|
||||
static final String compressed15bitWeight11750 = ".X.XX.XXXX..XX.";
|
||||
static final String compressed15bitWeight0 = "...............";
|
||||
|
||||
static final String compressed20bitWeight1750 = ".........XX.XX.X.XX.";
|
||||
|
||||
static final String compressedDateMarch12th2010 = "....XXXX.X..XX..";
|
||||
static final String compressedDateEnd = "X..X.XX.........";
|
||||
|
||||
static void assertCorrectBinaryString(CharSequence binaryString,
|
||||
String expectedNumber) throws NotFoundException, FormatException {
|
||||
BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(binaryString);
|
||||
AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(binary);
|
||||
String result = decoder.parseInformation();
|
||||
assertEquals(expectedNumber, result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.decoders;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
public final class AnyAIDecoderTest extends AbstractDecoderTest {
|
||||
|
||||
private static final String header = ".....";
|
||||
|
||||
@Test
|
||||
public void testAnyAIDecoder1() throws Exception {
|
||||
CharSequence data = header + numeric10 + numeric12 + numeric2alpha + alphaA + alpha2numeric + numeric12;
|
||||
String expected = "(10)12A12";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyAIDecoder2() throws Exception {
|
||||
CharSequence data = header + numeric10 + numeric12 + numeric2alpha + alphaA + alpha2isoiec646 + i646B;
|
||||
String expected = "(10)12AB";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyAIDecoder3() throws Exception {
|
||||
CharSequence data = header + numeric10 + numeric2alpha + alpha2isoiec646 + i646B + i646C + isoiec6462alpha +
|
||||
alphaA + alpha2numeric + numeric10;
|
||||
String expected = "(10)BCA10";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyAIDecodernumericFNC1secondDigit() throws Exception {
|
||||
CharSequence data = header + numeric10 + numeric1FNC1;
|
||||
String expected = "(10)1";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyAIDecoderalphaFNC1() throws Exception {
|
||||
CharSequence data = header + numeric10 + numeric2alpha + alphaA + alphaFNC1;
|
||||
String expected = "(10)A";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyAIDecoder646FNC1() throws Exception {
|
||||
CharSequence data = header + numeric10 + numeric2alpha + alphaA + isoiec6462alpha + i646B + i646FNC1;
|
||||
String expected = "(10)AB";
|
||||
|
||||
assertCorrectBinaryString(data, expected);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.decoders;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
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 FieldParserTest extends Assert {
|
||||
|
||||
private static void checkFields(String expected) throws NotFoundException {
|
||||
String field = expected.replace("(", "").replace(")","");
|
||||
String actual = FieldParser.parseFieldsInGeneralPurpose(field);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseField() throws Exception {
|
||||
checkFields("(15)991231(3103)001750(10)12A");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseField2() throws Exception {
|
||||
checkFields("(15)991231(15)991231(3103)001750(10)12A");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user