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,62 @@
|
||||
/*
|
||||
* Copyright 2011 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author dsbnatut@gmail.com (Kazuki Nishiura)
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class CodaBarWriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
doTest("B515-3/B",
|
||||
"00000" +
|
||||
"1001001011" + "0110101001" + "0101011001" + "0110101001" + "0101001101" +
|
||||
"0110010101" + "01101101011" + "01001001011" +
|
||||
"00000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode2() {
|
||||
doTest("T123T",
|
||||
"00000" +
|
||||
"1011001001" + "0101011001" + "0101001011" + "0110010101" + "01011001001" +
|
||||
"00000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAltStartEnd() {
|
||||
assertEquals(encode("T123456789-$T"), encode("A123456789-$A"));
|
||||
}
|
||||
|
||||
private static void doTest(String input, CharSequence expected) {
|
||||
BitMatrix result = encode(input);
|
||||
assertEquals(expected, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
private static BitMatrix encode(String input) {
|
||||
return new CodaBarWriter().encode(input, BarcodeFormat.CODABAR, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class CodabarBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public CodabarBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/codabar-1", new MultiFormatReader(), BarcodeFormat.CODABAR);
|
||||
addTest(11, 11, 0.0f);
|
||||
addTest(11, 11, 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class Code128BlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code128BlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/code128-1", new MultiFormatReader(), BarcodeFormat.CODE_128);
|
||||
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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class Code128BlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code128BlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/code128-2", new MultiFormatReader(), BarcodeFormat.CODE_128);
|
||||
addTest(36, 39, 0.0f);
|
||||
addTest(36, 39, 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class Code128BlackBox3TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code128BlackBox3TestCase() {
|
||||
super("src/test/resources/blackbox/code128-3", new MultiFormatReader(), BarcodeFormat.CODE_128);
|
||||
addTest(2, 2, 0.0f);
|
||||
addTest(2, 2, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
359
java_test/java/com/google/zxing/oned/Code128WriterTestCase.java
Normal file
359
java_test/java/com/google/zxing/oned/Code128WriterTestCase.java
Normal file
@@ -0,0 +1,359 @@
|
||||
/*
|
||||
* Copyright 2014 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;
|
||||
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.Writer;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.EnumMap;
|
||||
|
||||
/**
|
||||
* Tests {@link Code128Writer}.
|
||||
*/
|
||||
public class Code128WriterTestCase extends Assert {
|
||||
|
||||
private static final String FNC1 = "11110101110";
|
||||
private static final String FNC2 = "11110101000";
|
||||
private static final String FNC3 = "10111100010";
|
||||
private static final String FNC4A = "11101011110";
|
||||
private static final String FNC4B = "10111101110";
|
||||
private static final String START_CODE_A = "11010000100";
|
||||
private static final String START_CODE_B = "11010010000";
|
||||
private static final String START_CODE_C = "11010011100";
|
||||
private static final String SWITCH_CODE_A = "11101011110";
|
||||
private static final String SWITCH_CODE_B = "10111101110";
|
||||
private static final String QUIET_SPACE = "00000";
|
||||
private static final String STOP = "1100011101011";
|
||||
private static final String LF = "10000110010";
|
||||
|
||||
private Writer writer;
|
||||
private Code128Reader reader;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
writer = new Code128Writer();
|
||||
reader = new Code128Reader();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithFunc3() throws Exception {
|
||||
String toEncode = "\u00f3" + "123";
|
||||
String expected = QUIET_SPACE + START_CODE_B + FNC3 +
|
||||
// "1" "2" "3" check digit 51
|
||||
"10011100110" + "11001110010" + "11001011100" + "11101000110" + STOP + QUIET_SPACE;
|
||||
|
||||
BitMatrix result = encode(toEncode, false, "123");
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(expected, actual);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, "123");
|
||||
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithFunc2() throws Exception {
|
||||
String toEncode = "\u00f2" + "123";
|
||||
String expected = QUIET_SPACE + START_CODE_B + FNC2 +
|
||||
// "1" "2" "3" check digit 56
|
||||
"10011100110" + "11001110010" + "11001011100" + "11100010110" + STOP + QUIET_SPACE;
|
||||
|
||||
BitMatrix result = encode(toEncode, false, "123");
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(expected, actual);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, "123");
|
||||
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithFunc1() throws Exception {
|
||||
String toEncode = "\u00f1" + "123";
|
||||
String expected = QUIET_SPACE + START_CODE_C + FNC1 +
|
||||
// "12" "3" check digit 92
|
||||
"10110011100" + SWITCH_CODE_B + "11001011100" + "10101111000" + STOP + QUIET_SPACE;
|
||||
|
||||
BitMatrix result = encode(toEncode, false, "123");
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(expected, actual);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, "123");
|
||||
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoundtrip() throws Exception {
|
||||
String toEncode = "\u00f1" + "10958" + "\u00f1" + "17160526";
|
||||
String expected = "1095817160526";
|
||||
|
||||
BitMatrix encResult = encode(toEncode, false, expected);
|
||||
|
||||
int width = encResult.getWidth();
|
||||
encResult = encode(toEncode, true, expected);
|
||||
//Compact encoding has one latch less and encodes as STARTA,FNC1,1,CODEC,09,58,FNC1,17,16,05,26
|
||||
assertEquals(width, encResult.getWidth() + 11);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongCompact() throws Exception {
|
||||
//test longest possible input
|
||||
String toEncode = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
|
||||
encode(toEncode, true, toEncode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShift() throws Exception {
|
||||
//compare fast to compact
|
||||
String toEncode = "a\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\n";
|
||||
BitMatrix result = encode(toEncode, false, toEncode);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, toEncode);
|
||||
|
||||
//big difference since the fast algoritm doesn't make use of SHIFT
|
||||
assertEquals(width, result.getWidth() + 253);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDigitMixCompaction() throws Exception {
|
||||
//compare fast to compact
|
||||
String toEncode = "A1A12A123A1234A12345AA1AA12AA123AA1234AA1235";
|
||||
BitMatrix result = encode(toEncode, false, toEncode);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, toEncode);
|
||||
|
||||
//very good, no difference
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompaction1() throws Exception {
|
||||
//compare fast to compact
|
||||
String toEncode = "AAAAAAAAAAA12AAAAAAAAA";
|
||||
BitMatrix result = encode(toEncode, false, toEncode);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, toEncode);
|
||||
|
||||
//very good, no difference
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompaction2() throws Exception {
|
||||
//compare fast to compact
|
||||
String toEncode = "AAAAAAAAAAA1212aaaaaaaaa";
|
||||
BitMatrix result = encode(toEncode, false, toEncode);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, toEncode);
|
||||
|
||||
//very good, no difference
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithFunc4() throws Exception {
|
||||
String toEncode = "\u00f4" + "123";
|
||||
String expected = QUIET_SPACE + START_CODE_B + FNC4B +
|
||||
// "1" "2" "3" check digit 59
|
||||
"10011100110" + "11001110010" + "11001011100" + "11100011010" + STOP + QUIET_SPACE;
|
||||
|
||||
BitMatrix result = encode(toEncode, false, null);
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(expected, actual);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, null);
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithFncsAndNumberInCodesetA() throws Exception {
|
||||
String toEncode = "\n" + "\u00f1" + "\u00f4" + "1" + "\n";
|
||||
|
||||
String expected = QUIET_SPACE + START_CODE_A + LF + FNC1 + FNC4A +
|
||||
"10011100110" + LF + "10101111000" + STOP + QUIET_SPACE;
|
||||
|
||||
BitMatrix result = encode(toEncode, false, null);
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, null);
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeSwitchBetweenCodesetsAAndB() throws Exception {
|
||||
// start with A switch to B and back to A
|
||||
testEncode("\0ABab\u0010", QUIET_SPACE + START_CODE_A +
|
||||
// "\0" "A" "B" Switch to B "a" "b"
|
||||
"10100001100" + "10100011000" + "10001011000" + SWITCH_CODE_B + "10010110000" + "10010000110" +
|
||||
// Switch to A "\u0010" check digit
|
||||
SWITCH_CODE_A + "10100111100" + "11001110100" + STOP + QUIET_SPACE);
|
||||
|
||||
// start with B switch to A and back to B
|
||||
// the compact encoder encodes this shorter as STARTB,a,b,SHIFT,NUL,a,b
|
||||
testEncode("ab\0ab", QUIET_SPACE + START_CODE_B +
|
||||
// "a" "b" Switch to A "\0" Switch to B
|
||||
"10010110000" + "10010000110" + SWITCH_CODE_A + "10100001100" + SWITCH_CODE_B +
|
||||
// "a" "b" check digit
|
||||
"10010110000" + "10010000110" + "11010001110" + STOP + QUIET_SPACE);
|
||||
}
|
||||
|
||||
private void testEncode(String toEncode, String expected) throws Exception {
|
||||
BitMatrix result = encode(toEncode, false, toEncode);
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(toEncode, expected, actual);
|
||||
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, toEncode);
|
||||
assertTrue(result.getWidth() <= width);
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetABadCharacter() throws Exception {
|
||||
// Lower case characters should not be accepted when the code set is forced to A.
|
||||
String toEncode = "ASDFx0123";
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "A");
|
||||
writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetBBadCharacter() throws Exception {
|
||||
String toEncode = "ASdf\00123"; // \0 (ascii value 0)
|
||||
// Characters with ASCII value below 32 should not be accepted when the code set is forced to B.
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "B");
|
||||
writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetCBadCharactersNonNum() throws Exception {
|
||||
String toEncode = "123a5678";
|
||||
// Non-digit characters should not be accepted when the code set is forced to C.
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "C");
|
||||
writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetCBadCharactersFncCode() throws Exception {
|
||||
String toEncode = "123\u00f2a678";
|
||||
// Function codes other than 1 should not be accepted when the code set is forced to C.
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "C");
|
||||
writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetCWrongAmountOfDigits() throws Exception {
|
||||
String toEncode = "123456789";
|
||||
// An uneven amount of digits should not be accepted when the code set is forced to C.
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "C");
|
||||
writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetA() throws Exception {
|
||||
String toEncode = "AB123";
|
||||
// would default to B "A" "B" "1"
|
||||
String expected = QUIET_SPACE + START_CODE_A + "10100011000" + "10001011000" + "10011100110" +
|
||||
// "2" "3" check digit 10
|
||||
"11001110010" + "11001011100" + "11001000100" + STOP + QUIET_SPACE;
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "A");
|
||||
BitMatrix result = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetB() throws Exception {
|
||||
String toEncode = "1234";
|
||||
// would default to C "1" "2" "3"
|
||||
String expected = QUIET_SPACE + START_CODE_B + "10011100110" + "11001110010" + "11001011100" +
|
||||
// "4" check digit 88
|
||||
"11001001110" + "11110010010" + STOP + QUIET_SPACE;
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "B");
|
||||
BitMatrix result = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
private BitMatrix encode(String toEncode, boolean compact, String expectedLoopback) throws Exception {
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
if (compact) {
|
||||
hints.put(EncodeHintType.CODE128_COMPACT, Boolean.TRUE);
|
||||
}
|
||||
BitMatrix encResult = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
if (expectedLoopback != null) {
|
||||
BitArray row = encResult.getRow(0, null);
|
||||
Result rtResult = reader.decodeRow(0, row, null);
|
||||
String actual = rtResult.getText();
|
||||
assertEquals(expectedLoopback, actual);
|
||||
}
|
||||
if (compact) {
|
||||
//check that what is encoded compactly yields the same on loopback as what was encoded fast.
|
||||
BitArray row = encResult.getRow(0, null);
|
||||
Result rtResult = reader.decodeRow(0, row, null);
|
||||
String actual = rtResult.getText();
|
||||
BitMatrix encResultFast = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0);
|
||||
row = encResultFast.getRow(0, null);
|
||||
rtResult = reader.decodeRow(0, row, null);
|
||||
assertEquals(rtResult.getText(), actual);
|
||||
}
|
||||
return encResult;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class Code39BlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code39BlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/code39-1", new MultiFormatReader(), BarcodeFormat.CODE_39);
|
||||
addTest(4, 4, 0.0f);
|
||||
addTest(4, 4, 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class Code39BlackBox3TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code39BlackBox3TestCase() {
|
||||
super("src/test/resources/blackbox/code39-3", new MultiFormatReader(), BarcodeFormat.CODE_39);
|
||||
addTest(17, 17, 0.0f);
|
||||
addTest(17, 17, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class Code39ExtendedBlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code39ExtendedBlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/code39-2", new Code39Reader(false, true), BarcodeFormat.CODE_39);
|
||||
addTest(2, 2, 0.0f);
|
||||
addTest(2, 2, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2017 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;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.ChecksumException;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* @author Michael Jahn
|
||||
*/
|
||||
public final class Code39ExtendedModeTestCase extends Assert {
|
||||
|
||||
@SuppressWarnings("checkstyle:lineLength")
|
||||
@Test
|
||||
public void testDecodeExtendedMode() throws FormatException, ChecksumException, NotFoundException {
|
||||
doTest("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f",
|
||||
"000001001011011010101001001001011001010101101001001001010110101001011010010010010101011010010110100100100101011011010010101001001001010101011001011010010010010101101011001010100100100101010110110010101001001001010101010011011010010010010101101010011010100100100101010110100110101001001001010101011001101010010010010101101010100110100100100101010110101001101001001001010110110101001010010010010101010110100110100100100101011010110100101001001001010101101101001010010010010101010101100110100100100101011010101100101001001001010101101011001010010010010101010110110010100100100101011001010101101001001001010100110101011010010010010101100110101010100100100101010010110101101001001001010110010110101010010010010101001101101010101001001001011010100101101010010010010101101001011010100100100101101101001010101001001001010101100101101010010010010110101100101010010110110100000");
|
||||
doTest(" !\"#$%&'()*+,-./0123456789:;<=>?",
|
||||
"00000100101101101010011010110101001001010010110101001011010010010100101011010010110100100101001011011010010101001001010010101011001011010010010100101101011001010100100101001010110110010101001001010010101010011011010010010100101101010011010100100101001010110100110101001001010010101011001101010010010100101101010100110100100101001010110101001101001010110110110010101101010010010100101101011010010101001101101011010010101101011001010110110110010101010100110101101101001101010101100110101010100101101101101001011010101100101101010010010100101001101101010101001001001010110110010101010010010010101010011011010100100100101101010011010101001001001010110100110101010010010010101011001101010010110110100000");
|
||||
doTest("@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_",
|
||||
"000010010110110101010010010010100110101011011010100101101011010010110110110100101010101100101101101011001010101101100101010101001101101101010011010101101001101010101100110101101010100110101101010011011011010100101010110100110110101101001010110110100101010101100110110101011001010110101100101010110110010110010101011010011010101101100110101010100101101011011001011010101001101101010101001001001011010101001101010010010010101101010011010100100100101101101010010101001001001010101101001101010010010010110101101001010010110110100000");
|
||||
doTest("`abcdefghijklmnopqrstuvwxyz{|}~",
|
||||
"000001001011011010101001001001011001101010101001010010010110101001011010010100100101011010010110100101001001011011010010101001010010010101011001011010010100100101101011001010100101001001010110110010101001010010010101010011011010010100100101101010011010100101001001010110100110101001010010010101011001101010010100100101101010100110100101001001010110101001101001010010010110110101001010010100100101010110100110100101001001011010110100101001010010010101101101001010010100100101010101100110100101001001011010101100101001010010010101101011001010010100100101010110110010100101001001011001010101101001010010010100110101011010010100100101100110101010100101001001010010110101101001010010010110010110101010010100100101001101101010101001001001010110110100101010010010010101010110011010100100100101101010110010101001001001010110101100101010010010010101011011001010010110110100000");
|
||||
}
|
||||
|
||||
private static void doTest(String expectedResult, String encodedResult)
|
||||
throws FormatException, ChecksumException, NotFoundException {
|
||||
Code39Reader sut = new Code39Reader(false, true);
|
||||
BitMatrix matrix = BitMatrix.parse(encodedResult, "1", "0");
|
||||
BitArray row = new BitArray(matrix.getWidth());
|
||||
matrix.getRow(0, row);
|
||||
Result result = sut.decodeRow(0, row, null);
|
||||
assertEquals(expectedResult, result.getText());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2016 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link Code39Writer}.
|
||||
*/
|
||||
public final class Code39WriterTestCase extends Assert {
|
||||
|
||||
@SuppressWarnings("checkstyle:lineLength")
|
||||
@Test
|
||||
public void testEncode() {
|
||||
doTest("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
||||
"000001001011011010110101001011010110100101101101101001010101011001011011010110010101" +
|
||||
"011011001010101010011011011010100110101011010011010101011001101011010101001101011010" +
|
||||
"100110110110101001010101101001101101011010010101101101001010101011001101101010110010" +
|
||||
"101101011001010101101100101100101010110100110101011011001101010101001011010110110010" +
|
||||
"110101010011011010101010011011010110100101011010110010101101101100101010101001101011" +
|
||||
"01101001101010101100110101010100101101101101001011010101100101101010010110110100000");
|
||||
|
||||
// extended mode blocks
|
||||
doTest("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f",
|
||||
"000001001011011010101001001001011001010101101001001001010110101001011010010010010101" +
|
||||
"011010010110100100100101011011010010101001001001010101011001011010010010010101101011" +
|
||||
"001010100100100101010110110010101001001001010101010011011010010010010101101010011010" +
|
||||
"100100100101010110100110101001001001010101011001101010010010010101101010100110100100" +
|
||||
"100101010110101001101001001001010110110101001010010010010101010110100110100100100101" +
|
||||
"011010110100101001001001010101101101001010010010010101010101100110100100100101011010" +
|
||||
"101100101001001001010101101011001010010010010101010110110010100100100101011001010101" +
|
||||
"101001001001010100110101011010010010010101100110101010100100100101010010110101101001" +
|
||||
"001001010110010110101010010010010101001101101010101001001001011010100101101010010010" +
|
||||
"010101101001011010100100100101101101001010101001001001010101100101101010010010010110" +
|
||||
"101100101010010110110100000");
|
||||
|
||||
doTest(" !\"#$%&'()*+,-./0123456789:;<=>?",
|
||||
"000001001011011010100110101101010010010100101101010010110100100101001010110100101101" +
|
||||
"001001010010110110100101010010010100101010110010110100100101001011010110010101001001" +
|
||||
"010010101101100101010010010100101010100110110100100101001011010100110101001001010010" +
|
||||
"101101001101010010010100101010110011010100100101001011010101001101001001010010101101" +
|
||||
"010011010010101101101100101011010100100101001011010110100101010011011010110100101011" +
|
||||
"010110010101101101100101010101001101011011010011010101011001101010101001011011011010" +
|
||||
"010110101011001011010100100101001010011011010101010010010010101101100101010100100100" +
|
||||
"101010100110110101001001001011010100110101010010010010101101001101010100100100101010" +
|
||||
"11001101010010110110100000");
|
||||
|
||||
doTest("@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_",
|
||||
"0000010010110110101010010010010100110101011011010100101101011010010110110110100101010" +
|
||||
"101100101101101011001010101101100101010101001101101101010011010101101001101010101100" +
|
||||
"110101101010100110101101010011011011010100101010110100110110101101001010110110100101" +
|
||||
"010101100110110101011001010110101100101010110110010110010101011010011010101101100110" +
|
||||
"101010100101101011011001011010101001101101010101001001001011010101001101010010010010" +
|
||||
"101101010011010100100100101101101010010101001001001010101101001101010010010010110101" +
|
||||
"101001010010110110100000");
|
||||
|
||||
doTest("`abcdefghijklmnopqrstuvwxyz{|}~",
|
||||
"000001001011011010101001001001011001101010101001010010010110101001011010010100100101" +
|
||||
"011010010110100101001001011011010010101001010010010101011001011010010100100101101011" +
|
||||
"001010100101001001010110110010101001010010010101010011011010010100100101101010011010" +
|
||||
"100101001001010110100110101001010010010101011001101010010100100101101010100110100101" +
|
||||
"001001010110101001101001010010010110110101001010010100100101010110100110100101001001" +
|
||||
"011010110100101001010010010101101101001010010100100101010101100110100101001001011010" +
|
||||
"101100101001010010010101101011001010010100100101010110110010100101001001011001010101" +
|
||||
"101001010010010100110101011010010100100101100110101010100101001001010010110101101001" +
|
||||
"010010010110010110101010010100100101001101101010101001001001010110110100101010010010" +
|
||||
"010101010110011010100100100101101010110010101001001001010110101100101010010010010101" +
|
||||
"011011001010010110110100000");
|
||||
}
|
||||
|
||||
private static void doTest(String input, CharSequence expected) {
|
||||
BitMatrix result = new Code39Writer().encode(input, BarcodeFormat.CODE_39, 0, 0);
|
||||
assertEquals(input, expected, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class Code93BlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code93BlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/code93-1", new MultiFormatReader(), BarcodeFormat.CODE_93);
|
||||
addTest(3, 3, 0.0f);
|
||||
addTest(3, 3, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2018 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;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.ChecksumException;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* @author Daisuke Makiuchi
|
||||
*/
|
||||
public final class Code93ReaderTestCase extends Assert {
|
||||
|
||||
@SuppressWarnings("checkstyle:lineLength")
|
||||
@Test
|
||||
public void testDecode() throws FormatException, ChecksumException, NotFoundException {
|
||||
doTest("Code93!\n$%/+ :\u001b;[{\u007f\u0000@`\u007f\u007f\u007f",
|
||||
"0000001010111101101000101001100101001011001001100101100101001001100101100100101000010101010000101110101101101010001001001101001101001110010101101011101011011101011101101110100101110101101001110101110110101101010001110110101100010101110110101000110101110110101000101101110110101101001101110110101100101101110110101100110101110110101011011001110110101011001101110110101001101101110110101001110101001100101101010001010111101111");
|
||||
}
|
||||
|
||||
private static void doTest(String expectedResult, String encodedResult)
|
||||
throws FormatException, ChecksumException, NotFoundException {
|
||||
Code93Reader sut = new Code93Reader();
|
||||
BitMatrix matrix = BitMatrix.parse(encodedResult, "1", "0");
|
||||
BitArray row = new BitArray(matrix.getWidth());
|
||||
matrix.getRow(0, row);
|
||||
Result result = sut.decodeRow(0, row, null);
|
||||
assertEquals(expectedResult, result.getText());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2016 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link Code93Writer}.
|
||||
*/
|
||||
public final class Code93WriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
doTest("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
||||
"000001010111101101010001101001001101000101100101001100100101100010101011010001011001" +
|
||||
"001011000101001101001000110101010110001010011001010001101001011001000101101101101001" +
|
||||
"101100101101011001101001101100101101100110101011011001011001101001101101001110101000" +
|
||||
"101001010010001010001001010000101001010001001001001001000101010100001000100101000010" +
|
||||
"10100111010101000010101011110100000");
|
||||
|
||||
doTest("\u0000\u0001\u001a\u001b\u001f $%+!,09:;@AZ[_`az{\u007f",
|
||||
"00000" + "101011110" +
|
||||
"111011010" + "110010110" + "100100110" + "110101000" + // bU aA
|
||||
"100100110" + "100111010" + "111011010" + "110101000" + // aZ bA
|
||||
"111011010" + "110010010" + "111010010" + "111001010" + // bE space $
|
||||
"110101110" + "101110110" + "111010110" + "110101000" + // % + cA
|
||||
"111010110" + "101011000" + "100010100" + "100001010" + // cL 0 9
|
||||
"111010110" + "100111010" + "111011010" + "110001010" + // cZ bF
|
||||
"111011010" + "110011010" + "110101000" + "100111010" + // bV A Z
|
||||
"111011010" + "100011010" + "111011010" + "100101100" + // bK bO
|
||||
"111011010" + "101101100" + "100110010" + "110101000" + // bW dA
|
||||
"100110010" + "100111010" + "111011010" + "100010110" + // dZ bP
|
||||
"111011010" + "110100110" + // bT
|
||||
"110100010" + "110101100" + // checksum: 12 28
|
||||
"101011110" + "100000");
|
||||
}
|
||||
|
||||
private static void doTest(String input, CharSequence expected) {
|
||||
BitMatrix result = new Code93Writer().encode(input, BarcodeFormat.CODE_93, 0, 0);
|
||||
assertEquals(expected, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertToExtended() {
|
||||
// non-extended chars are not changed.
|
||||
String src = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
|
||||
String dst = Code93Writer.convertToExtended(src);
|
||||
assertEquals(src, dst);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class EAN13BlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public EAN13BlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/ean13-1", new MultiFormatReader(), BarcodeFormat.EAN_13);
|
||||
addTest(30, 32, 0.0f);
|
||||
addTest(27, 32, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* This is a set of mobile image taken at 480x360 with difficult lighting.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class EAN13BlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public EAN13BlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/ean13-2", new MultiFormatReader(), BarcodeFormat.EAN_13);
|
||||
addTest(12, 17, 0, 1, 0.0f);
|
||||
addTest(11, 17, 0, 1, 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class EAN13BlackBox3TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public EAN13BlackBox3TestCase() {
|
||||
super("src/test/resources/blackbox/ean13-3", new MultiFormatReader(), BarcodeFormat.EAN_13);
|
||||
addTest(53, 55, 0.0f);
|
||||
addTest(55, 55, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2009 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A very difficult set of images taken with extreme shadows and highlights.
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class EAN13BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public EAN13BlackBox4TestCase() {
|
||||
super("src/test/resources/blackbox/ean13-4", new MultiFormatReader(), BarcodeFormat.EAN_13);
|
||||
addTest(6, 13, 1, 1, 0.0f);
|
||||
addTest(7, 13, 1, 1, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2011 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A set of blurry images taken with a fixed-focus device.
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class EAN13BlackBox5BlurryTestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public EAN13BlackBox5BlurryTestCase() {
|
||||
super("src/test/resources/blackbox/ean13-5", new MultiFormatReader(), BarcodeFormat.EAN_13);
|
||||
addTest(0, 0, 0.0f);
|
||||
addTest(0, 0, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2009 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Ari Pollak
|
||||
*/
|
||||
public final class EAN13WriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
String testStr =
|
||||
"00001010001011010011101100110010011011110100111010101011001101101100100001010111001001110100010010100000";
|
||||
BitMatrix result = new EAN13Writer().encode("5901234123457", BarcodeFormat.EAN_13, testStr.length(), 0);
|
||||
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddChecksumAndEncode() {
|
||||
String testStr =
|
||||
"00001010001011010011101100110010011011110100111010101011001101101100100001010111001001110100010010100000";
|
||||
BitMatrix result = new EAN13Writer().encode("590123412345", BarcodeFormat.EAN_13, testStr.length(), 0);
|
||||
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeIllegalCharacters() {
|
||||
new EAN13Writer().encode("5901234123abc", BarcodeFormat.EAN_13, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class EAN8BlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public EAN8BlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/ean8-1", new MultiFormatReader(), BarcodeFormat.EAN_8);
|
||||
addTest(8, 8, 0.0f);
|
||||
addTest(8, 8, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
48
java_test/java/com/google/zxing/oned/EAN8WriterTestCase.java
Normal file
48
java_test/java/com/google/zxing/oned/EAN8WriterTestCase.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2009 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Ari Pollak
|
||||
*/
|
||||
public final class EAN8WriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
String testStr = "0000001010001011010111101111010110111010101001110111001010001001011100101000000";
|
||||
BitMatrix result = new EAN8Writer().encode("96385074", BarcodeFormat.EAN_8, testStr.length(), 0);
|
||||
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddChecksumAndEncode() {
|
||||
String testStr = "0000001010001011010111101111010110111010101001110111001010001001011100101000000";
|
||||
BitMatrix result = new EAN8Writer().encode("9638507", BarcodeFormat.EAN_8, testStr.length(), 0);
|
||||
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeIllegalCharacters() {
|
||||
new EAN8Writer().encode("96385abc", BarcodeFormat.EAN_8, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link EANManufacturerOrgSupport}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class EANManufacturerOrgSupportTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void testLookup() {
|
||||
EANManufacturerOrgSupport support = new EANManufacturerOrgSupport();
|
||||
assertNull(support.lookupCountryIdentifier("472000"));
|
||||
assertEquals("US/CA", support.lookupCountryIdentifier("000000"));
|
||||
assertEquals("MO", support.lookupCountryIdentifier("958000"));
|
||||
assertEquals("GB", support.lookupCountryIdentifier("500000"));
|
||||
assertEquals("GB", support.lookupCountryIdentifier("509000"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author kevin.osullivan@sita.aero
|
||||
*/
|
||||
public final class ITFBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public ITFBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/itf-1", new MultiFormatReader(), BarcodeFormat.ITF);
|
||||
addTest(14, 14, 0.0f);
|
||||
addTest(14, 14, 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class ITFBlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public ITFBlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/itf-2", new MultiFormatReader(), BarcodeFormat.ITF);
|
||||
addTest(13, 13, 0.0f);
|
||||
addTest(13, 13, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
47
java_test/java/com/google/zxing/oned/ITFWriterTestCase.java
Normal file
47
java_test/java/com/google/zxing/oned/ITFWriterTestCase.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2017 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link ITFWriter}.
|
||||
*/
|
||||
public final class ITFWriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
doTest("00123456789012",
|
||||
"0000010101010111000111000101110100010101110001110111010001010001110100011" +
|
||||
"100010101000101011100011101011101000111000101110100010101110001110100000");
|
||||
}
|
||||
|
||||
private static void doTest(String input, CharSequence expected) {
|
||||
BitMatrix result = new ITFWriter().encode(input, BarcodeFormat.ITF, 0, 0);
|
||||
assertEquals(expected, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeIllegalCharacters() {
|
||||
new ITFWriter().encode("00123456789abc", BarcodeFormat.ITF, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class UPCABlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCABlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/upca-1", new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||
addTest(14, 18, 0, 1, 0.0f);
|
||||
addTest(16, 18, 0, 1, 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCABlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCABlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/upca-2", new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||
addTest(28, 36, 0, 2, 0.0f);
|
||||
addTest(29, 36, 0, 2, 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCABlackBox3ReflectiveTestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCABlackBox3ReflectiveTestCase() {
|
||||
super("src/test/resources/blackbox/upca-3", new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||
addTest(7, 9, 0, 2, 0.0f);
|
||||
addTest(8, 9, 0, 2, 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCABlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCABlackBox4TestCase() {
|
||||
super("src/test/resources/blackbox/upca-4", new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||
addTest(9, 11, 0, 1, 0.0f);
|
||||
addTest(9, 11, 0, 1, 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCABlackBox5TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCABlackBox5TestCase() {
|
||||
super("src/test/resources/blackbox/upca-5", new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||
addTest(20, 23, 0, 0, 0.0f);
|
||||
addTest(22, 23, 0, 0, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A set of blurry images taken with a fixed-focus device.
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCABlackBox6BlurryTestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCABlackBox6BlurryTestCase() {
|
||||
super("src/test/resources/blackbox/upca-6", new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||
addTest(0, 0, 0.0f);
|
||||
addTest(0, 0, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
47
java_test/java/com/google/zxing/oned/UPCAWriterTestCase.java
Normal file
47
java_test/java/com/google/zxing/oned/UPCAWriterTestCase.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 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.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author qwandor@google.com (Andrew Walbran)
|
||||
*/
|
||||
public final class UPCAWriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
String testStr =
|
||||
"00001010100011011011101100010001011010111101111010101011100101110100100111011001101101100101110010100000";
|
||||
BitMatrix result = new UPCAWriter().encode("485963095124", BarcodeFormat.UPC_A, testStr.length(), 0);
|
||||
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddChecksumAndEncode() {
|
||||
String testStr =
|
||||
"00001010011001001001101111010100011011000101011110101010001001001000111010011100101100110110110010100000";
|
||||
BitMatrix result = new UPCAWriter().encode("12345678901", BarcodeFormat.UPC_A, testStr.length(), 0);
|
||||
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class UPCEANExtensionBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCEANExtensionBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/upcean-extension-1", new MultiFormatReader(), BarcodeFormat.EAN_13);
|
||||
addTest(2, 2, 0.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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class UPCEBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCEBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/upce-1", new MultiFormatReader(), BarcodeFormat.UPC_E);
|
||||
addTest(3, 3, 0.0f);
|
||||
addTest(3, 3, 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCEBlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCEBlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/upce-2", new MultiFormatReader(), BarcodeFormat.UPC_E);
|
||||
addTest(31, 35, 0, 1, 0.0f);
|
||||
addTest(31, 35, 1, 1, 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCEBlackBox3ReflectiveTestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCEBlackBox3ReflectiveTestCase() {
|
||||
super("src/test/resources/blackbox/upce-3", new MultiFormatReader(), BarcodeFormat.UPC_E);
|
||||
addTest(6, 8, 0.0f);
|
||||
addTest(6, 8, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
57
java_test/java/com/google/zxing/oned/UPCEWriterTestCase.java
Normal file
57
java_test/java/com/google/zxing/oned/UPCEWriterTestCase.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2016 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;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link UPCEWriter}.
|
||||
*/
|
||||
public final class UPCEWriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
doTest("05096893",
|
||||
"0000000000010101110010100111000101101011110110111001011101010100000000000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeSystem1() {
|
||||
doTest("12345670",
|
||||
"0000000000010100100110111101010001101110010000101001000101010100000000000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddChecksumAndEncode() {
|
||||
doTest("0509689",
|
||||
"0000000000010101110010100111000101101011110110111001011101010100000000000");
|
||||
}
|
||||
|
||||
private static void doTest(String content, String encoding) {
|
||||
BitMatrix result = new UPCEWriter().encode(content, BarcodeFormat.UPC_E, encoding.length(), 0);
|
||||
assertEquals(encoding, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeIllegalCharacters() {
|
||||
new UPCEWriter().encode("05096abc", BarcodeFormat.UPC_E, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -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