mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 20:32:34 +00:00
complete move of all test cases into source tree
This commit is contained in:
83
src/PlanarYUVLuminanceSourceTestCase.java
Normal file
83
src/PlanarYUVLuminanceSourceTestCase.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link PlanarYUVLuminanceSource}.
|
||||
*/
|
||||
public final class PlanarYUVLuminanceSourceTestCase extends Assert {
|
||||
|
||||
private static final byte[] YUV = {
|
||||
0, 1, 1, 2, 3, 5,
|
||||
8, 13, 21, 34, 55, 89,
|
||||
0, -1, -1, -2, -3, -5,
|
||||
-8, -13, -21, -34, -55, -89,
|
||||
127, 127, 127, 127, 127, 127,
|
||||
127, 127, 127, 127, 127, 127,
|
||||
};
|
||||
private static final int COLS = 6;
|
||||
private static final int ROWS = 4;
|
||||
private static final byte[] Y = new byte[COLS * ROWS];
|
||||
static {
|
||||
System.arraycopy(YUV, 0, Y, 0, Y.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCrop() {
|
||||
PlanarYUVLuminanceSource source =
|
||||
new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 0, 0, COLS, ROWS, false);
|
||||
assertEquals(Y, 0, source.getMatrix(), 0, Y.length);
|
||||
for (int r = 0; r < ROWS; r++) {
|
||||
assertEquals(Y, r * COLS, source.getRow(r, null), 0, COLS);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCrop() {
|
||||
PlanarYUVLuminanceSource source =
|
||||
new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 1, 1, COLS - 2, ROWS - 2, false);
|
||||
assertTrue(source.isCropSupported());
|
||||
byte[] cropMatrix = source.getMatrix();
|
||||
for (int r = 0; r < ROWS - 2; r++) {
|
||||
assertEquals(Y, (r + 1) * COLS + 1, cropMatrix, r * (COLS - 2), COLS - 2);
|
||||
}
|
||||
for (int r = 0; r < ROWS - 2; r++) {
|
||||
assertEquals(Y, (r + 1) * COLS + 1, source.getRow(r, null), 0, COLS - 2);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThumbnail() {
|
||||
PlanarYUVLuminanceSource source =
|
||||
new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 0, 0, COLS, ROWS, false);
|
||||
assertArrayEquals(
|
||||
new int[] { 0xFF000000, 0xFF010101, 0xFF030303, 0xFF000000, 0xFFFFFFFF, 0xFFFDFDFD },
|
||||
source.renderThumbnail());
|
||||
}
|
||||
|
||||
private static void assertEquals(byte[] expected, int expectedFrom,
|
||||
byte[] actual, int actualFrom,
|
||||
int length) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
assertEquals(expected[expectedFrom + i], actual[actualFrom + i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
63
src/RGBLuminanceSourceTestCase.java
Normal file
63
src/RGBLuminanceSourceTestCase.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link RGBLuminanceSource}.
|
||||
*/
|
||||
public final class RGBLuminanceSourceTestCase extends Assert {
|
||||
|
||||
private static final RGBLuminanceSource SOURCE = new RGBLuminanceSource(3, 3, new int[] {
|
||||
0x000000, 0x7F7F7F, 0xFFFFFF,
|
||||
0xFF0000, 0x00FF00, 0x0000FF,
|
||||
0x0000FF, 0x00FF00, 0xFF0000});
|
||||
|
||||
@Test
|
||||
public void testCrop() {
|
||||
assertTrue(SOURCE.isCropSupported());
|
||||
LuminanceSource cropped = SOURCE.crop(1, 1, 1, 1);
|
||||
assertEquals(1, cropped.getHeight());
|
||||
assertEquals(1, cropped.getWidth());
|
||||
assertArrayEquals(new byte[] { 0x7F }, cropped.getRow(0, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatrix() {
|
||||
assertArrayEquals(new byte[] { 0x00, 0x7F, (byte) 0xFF, 0x3F, 0x7F, 0x3F, 0x3F, 0x7F, 0x3F },
|
||||
SOURCE.getMatrix());
|
||||
LuminanceSource croppedFullWidth = SOURCE.crop(0, 1, 3, 2);
|
||||
assertArrayEquals(new byte[] { 0x3F, 0x7F, 0x3F, 0x3F, 0x7F, 0x3F },
|
||||
croppedFullWidth.getMatrix());
|
||||
LuminanceSource croppedCorner = SOURCE.crop(1, 1, 2, 2);
|
||||
assertArrayEquals(new byte[] { 0x7F, 0x3F, 0x7F, 0x3F },
|
||||
croppedCorner.getMatrix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRow() {
|
||||
assertArrayEquals(new byte[] { 0x3F, 0x7F, 0x3F }, SOURCE.getRow(2, new byte[3]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("#+ \n#+#\n#+#\n", SOURCE.toString());
|
||||
}
|
||||
|
||||
}
|
||||
61
src/multi/MultiTestCase.java
Normal file
61
src/multi/MultiTestCase.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.multi;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.LuminanceSource;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
import com.google.zxing.common.HybridBinarizer;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link MultipleBarcodeReader}.
|
||||
*/
|
||||
public final class MultiTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testMulti() throws Exception {
|
||||
// Very basic test for now
|
||||
Path testBase = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/multi-1");
|
||||
|
||||
Path testImage = testBase.resolve("1.png");
|
||||
BufferedImage image = ImageIO.read(testImage.toFile());
|
||||
LuminanceSource source = new BufferedImageLuminanceSource(image);
|
||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||
|
||||
MultipleBarcodeReader reader = new GenericMultipleBarcodeReader(new MultiFormatReader());
|
||||
RXingResult[] results = reader.decodeMultiple(bitmap);
|
||||
assertNotNull(results);
|
||||
assertEquals(2, results.length);
|
||||
|
||||
assertEquals("031415926531", results[0].getText());
|
||||
assertEquals(BarcodeFormat.UPC_A, results[0].getBarcodeFormat());
|
||||
|
||||
assertEquals("www.airtable.com/jobs", results[1].getText());
|
||||
assertEquals(BarcodeFormat.QR_CODE, results[1].getBarcodeFormat());
|
||||
}
|
||||
|
||||
}
|
||||
105
src/multi/qrcode/MultiQRCodeTestCase.java
Normal file
105
src/multi/qrcode/MultiQRCodeTestCase.java
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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.multi.qrcode;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.LuminanceSource;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.RXingResultMetadataType;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
import com.google.zxing.common.HybridBinarizer;
|
||||
import com.google.zxing.multi.MultipleBarcodeReader;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link QRCodeMultiReader}.
|
||||
*/
|
||||
public final class MultiQRCodeTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testMultiQRCodes() throws Exception {
|
||||
// Very basic test for now
|
||||
Path testBase = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/multi-qrcode-1");
|
||||
|
||||
Path testImage = testBase.resolve("1.png");
|
||||
BufferedImage image = ImageIO.read(testImage.toFile());
|
||||
LuminanceSource source = new BufferedImageLuminanceSource(image);
|
||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||
|
||||
MultipleBarcodeReader reader = new QRCodeMultiReader();
|
||||
RXingResult[] results = reader.decodeMultiple(bitmap);
|
||||
assertNotNull(results);
|
||||
assertEquals(4, results.length);
|
||||
|
||||
Collection<String> barcodeContents = new HashSet<>();
|
||||
for (RXingResult result : results) {
|
||||
barcodeContents.add(result.getText());
|
||||
assertEquals(BarcodeFormat.QR_CODE, result.getBarcodeFormat());
|
||||
assertNotNull(result.getRXingResultMetadata());
|
||||
}
|
||||
Collection<String> expectedContents = new HashSet<>();
|
||||
expectedContents.add("You earned the class a 5 MINUTE DANCE PARTY!! Awesome! Way to go! Let's boogie!");
|
||||
expectedContents.add("You earned the class 5 EXTRA MINUTES OF RECESS!! Fabulous!! Way to go!!");
|
||||
expectedContents.add(
|
||||
"You get to SIT AT MRS. SIGMON'S DESK FOR A DAY!! Awesome!! Way to go!! Guess I better clean up! :)");
|
||||
expectedContents.add("You get to CREATE OUR JOURNAL PROMPT FOR THE DAY! Yay! Way to go! ");
|
||||
assertEquals(expectedContents, barcodeContents);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessStructuredAppend() {
|
||||
RXingResult sa1 = new RXingResult("SA1", new byte[]{}, new RXingResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
RXingResult sa2 = new RXingResult("SA2", new byte[]{}, new RXingResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
RXingResult sa3 = new RXingResult("SA3", new byte[]{}, new RXingResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
sa1.putMetadata(RXingResultMetadataType.STRUCTURED_APPEND_SEQUENCE, 2);
|
||||
sa1.putMetadata(RXingResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
sa2.putMetadata(RXingResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (1 << 4) + 2);
|
||||
sa2.putMetadata(RXingResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
sa3.putMetadata(RXingResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (2 << 4) + 2);
|
||||
sa3.putMetadata(RXingResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
|
||||
RXingResult nsa = new RXingResult("NotSA", new byte[]{}, new RXingResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
nsa.putMetadata(RXingResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
|
||||
List<RXingResult> inputs = Arrays.asList(sa3, sa1, nsa, sa2);
|
||||
|
||||
List<RXingResult> results = QRCodeMultiReader.processStructuredAppend(inputs);
|
||||
assertNotNull(results);
|
||||
assertEquals(2, results.size());
|
||||
|
||||
Collection<String> barcodeContents = new HashSet<>();
|
||||
for (RXingResult result : results) {
|
||||
barcodeContents.add(result.getText());
|
||||
}
|
||||
Collection<String> expectedContents = new HashSet<>();
|
||||
expectedContents.add("SA1SA2SA3");
|
||||
expectedContents.add("NotSA");
|
||||
assertEquals(expectedContents, barcodeContents);
|
||||
}
|
||||
}
|
||||
62
src/oned/CodaBarWriterTestCase.java
Normal file
62
src/oned/CodaBarWriterTestCase.java
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
359
src/oned/Code128WriterTestCase.java
Normal file
359
src/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.RXingResult;
|
||||
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 encRXingResult = encode(toEncode, false, expected);
|
||||
|
||||
int width = encRXingResult.getWidth();
|
||||
encRXingResult = 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, encRXingResult.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 encRXingResult = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
if (expectedLoopback != null) {
|
||||
BitArray row = encRXingResult.getRow(0, null);
|
||||
RXingResult rtRXingResult = reader.decodeRow(0, row, null);
|
||||
String actual = rtRXingResult.getText();
|
||||
assertEquals(expectedLoopback, actual);
|
||||
}
|
||||
if (compact) {
|
||||
//check that what is encoded compactly yields the same on loopback as what was encoded fast.
|
||||
BitArray row = encRXingResult.getRow(0, null);
|
||||
RXingResult rtRXingResult = reader.decodeRow(0, row, null);
|
||||
String actual = rtRXingResult.getText();
|
||||
BitMatrix encRXingResultFast = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0);
|
||||
row = encRXingResultFast.getRow(0, null);
|
||||
rtRXingResult = reader.decodeRow(0, row, null);
|
||||
assertEquals(rtRXingResult.getText(), actual);
|
||||
}
|
||||
return encRXingResult;
|
||||
}
|
||||
}
|
||||
94
src/oned/Code39WriterTestCase.java
Normal file
94
src/oned/Code39WriterTestCase.java
Normal file
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
51
src/oned/Code93ReaderTestCase.java
Normal file
51
src/oned/Code93ReaderTestCase.java
Normal file
@@ -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.RXingResult;
|
||||
|
||||
/**
|
||||
* @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 expectedRXingResult, String encodedRXingResult)
|
||||
throws FormatException, ChecksumException, NotFoundException {
|
||||
Code93Reader sut = new Code93Reader();
|
||||
BitMatrix matrix = BitMatrix.parse(encodedRXingResult, "1", "0");
|
||||
BitArray row = new BitArray(matrix.getWidth());
|
||||
matrix.getRow(0, row);
|
||||
RXingResult result = sut.decodeRow(0, row, null);
|
||||
assertEquals(expectedRXingResult, result.getText());
|
||||
}
|
||||
|
||||
}
|
||||
69
src/oned/Code93WriterTestCase.java
Normal file
69
src/oned/Code93WriterTestCase.java
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
50
src/oned/EAN13WriterTestCase.java
Normal file
50
src/oned/EAN13WriterTestCase.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
48
src/oned/EAN8WriterTestCase.java
Normal file
48
src/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);
|
||||
}
|
||||
}
|
||||
39
src/oned/EANManufacturerOrgSupportTest.java
Normal file
39
src/oned/EANManufacturerOrgSupportTest.java
Normal file
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
47
src/oned/ITFWriterTestCase.java
Normal file
47
src/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);
|
||||
}
|
||||
|
||||
}
|
||||
47
src/oned/UPCAWriterTestCase.java
Normal file
47
src/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));
|
||||
}
|
||||
|
||||
}
|
||||
57
src/oned/UPCEWriterTestCase.java
Normal file
57
src/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);
|
||||
}
|
||||
}
|
||||
84
src/oned/rss/expanded/BinaryUtil.java
Normal file
84
src/oned/rss/expanded/BinaryUtil.java
Normal file
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
90
src/oned/rss/expanded/BinaryUtilTest.java
Normal file
90
src/oned/rss/expanded/BinaryUtilTest.java
Normal file
@@ -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());
|
||||
}
|
||||
}
|
||||
85
src/oned/rss/expanded/BitArrayBuilderTest.java
Normal file
85
src/oned/rss/expanded/BitArrayBuilderTest.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
50
src/oned/rss/expanded/ExpandedInformationDecoderTest.java
Normal file
50
src/oned/rss/expanded/ExpandedInformationDecoderTest.java
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
198
src/oned/rss/expanded/RSSExpandedImage2binaryTestCase.java
Normal file
198
src/oned/rss/expanded/RSSExpandedImage2binaryTestCase.java
Normal file
@@ -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());
|
||||
}
|
||||
}
|
||||
102
src/oned/rss/expanded/RSSExpandedImage2resultTestCase.java
Normal file
102
src/oned/rss/expanded/RSSExpandedImage2resultTestCase.java
Normal file
@@ -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.RXingResult;
|
||||
import com.google.zxing.client.result.ExpandedProductParsedRXingResult;
|
||||
import com.google.zxing.client.result.ParsedRXingResult;
|
||||
import com.google.zxing.client.result.RXingResultParser;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.common.GlobalHistogramBinarizer;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
public final class RSSExpandedImage2resultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2result2() throws Exception {
|
||||
// (01)90012345678908(3103)001750
|
||||
ExpandedProductParsedRXingResult expected =
|
||||
new ExpandedProductParsedRXingResult("(01)90012345678908(3103)001750",
|
||||
"90012345678908",
|
||||
null, null, null, null, null, null,
|
||||
"001750",
|
||||
ExpandedProductParsedRXingResult.KILOGRAM,
|
||||
"3", null, null, null, new HashMap<>());
|
||||
|
||||
assertCorrectImage2result("2.png", expected);
|
||||
}
|
||||
|
||||
private static void assertCorrectImage2result(String fileName, ExpandedProductParsedRXingResult expected)
|
||||
throws IOException, NotFoundException {
|
||||
Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName);
|
||||
|
||||
BufferedImage image = ImageIO.read(path.toFile());
|
||||
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
|
||||
int rowNumber = binaryMap.getHeight() / 2;
|
||||
BitArray row = binaryMap.getBlackRow(rowNumber, null);
|
||||
|
||||
RXingResult theRXingResult;
|
||||
try {
|
||||
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
|
||||
theRXingResult = rssExpandedReader.decodeRow(rowNumber, row, null);
|
||||
} catch (ReaderException re) {
|
||||
fail(re.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
assertSame(BarcodeFormat.RSS_EXPANDED, theRXingResult.getBarcodeFormat());
|
||||
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(theRXingResult);
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
||||
212
src/oned/rss/expanded/RSSExpandedImage2stringTestCase.java
Normal file
212
src/oned/rss/expanded/RSSExpandedImage2stringTestCase.java
Normal file
@@ -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.RXingResult;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.common.GlobalHistogramBinarizer;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
public final class RSSExpandedImage2stringTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string1() throws Exception {
|
||||
assertCorrectImage2string("1.png", "(11)100224(17)110224(3102)000100");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string2() throws Exception {
|
||||
assertCorrectImage2string("2.png", "(01)90012345678908(3103)001750");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string3() throws Exception {
|
||||
assertCorrectImage2string("3.png", "(10)12A");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string4() throws Exception {
|
||||
assertCorrectImage2string("4.png", "(01)98898765432106(3202)012345(15)991231");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string5() throws Exception {
|
||||
assertCorrectImage2string("5.png", "(01)90614141000015(3202)000150");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string7() throws Exception {
|
||||
assertCorrectImage2string("7.png", "(10)567(11)010101");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string10() throws Exception {
|
||||
String expected = "(01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456(423)012345678901";
|
||||
assertCorrectImage2string("10.png", expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string11() throws Exception {
|
||||
assertCorrectImage2string("11.png", "(01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string12() throws Exception {
|
||||
assertCorrectImage2string("12.png", "(01)98898765432106(3103)001750");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string13() throws Exception {
|
||||
assertCorrectImage2string("13.png", "(01)90012345678908(3922)795");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string14() throws Exception {
|
||||
assertCorrectImage2string("14.png", "(01)90012345678908(3932)0401234");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string15() throws Exception {
|
||||
assertCorrectImage2string("15.png", "(01)90012345678908(3102)001750(11)100312");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string16() throws Exception {
|
||||
assertCorrectImage2string("16.png", "(01)90012345678908(3202)001750(11)100312");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string17() throws Exception {
|
||||
assertCorrectImage2string("17.png", "(01)90012345678908(3102)001750(13)100312");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string18() throws Exception {
|
||||
assertCorrectImage2string("18.png", "(01)90012345678908(3202)001750(13)100312");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string19() throws Exception {
|
||||
assertCorrectImage2string("19.png", "(01)90012345678908(3102)001750(15)100312");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string20() throws Exception {
|
||||
assertCorrectImage2string("20.png", "(01)90012345678908(3202)001750(15)100312");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string21() throws Exception {
|
||||
assertCorrectImage2string("21.png", "(01)90012345678908(3102)001750(17)100312");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string22() throws Exception {
|
||||
assertCorrectImage2string("22.png", "(01)90012345678908(3202)001750(17)100312");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string25() throws Exception {
|
||||
assertCorrectImage2string("25.png", "(10)123");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string26() throws Exception {
|
||||
assertCorrectImage2string("26.png", "(10)5678(11)010101");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string27() throws Exception {
|
||||
assertCorrectImage2string("27.png", "(10)1098-1234");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string28() throws Exception {
|
||||
assertCorrectImage2string("28.png", "(10)1098/1234");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string29() throws Exception {
|
||||
assertCorrectImage2string("29.png", "(10)1098.1234");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string30() throws Exception {
|
||||
assertCorrectImage2string("30.png", "(10)1098*1234");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string31() throws Exception {
|
||||
assertCorrectImage2string("31.png", "(10)1098,1234");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRow2string32() throws Exception {
|
||||
assertCorrectImage2string("32.png", "(15)991231(3103)001750(10)12A(422)123(21)123456(423)0123456789012");
|
||||
}
|
||||
|
||||
private static void assertCorrectImage2string(String fileName, String expected)
|
||||
throws IOException, NotFoundException {
|
||||
Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName);
|
||||
|
||||
BufferedImage image = ImageIO.read(path.toFile());
|
||||
BinaryBitmap binaryMap =
|
||||
new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
|
||||
int rowNumber = binaryMap.getHeight() / 2;
|
||||
BitArray row = binaryMap.getBlackRow(rowNumber, null);
|
||||
|
||||
RXingResult result;
|
||||
try {
|
||||
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
|
||||
result = rssExpandedReader.decodeRow(rowNumber, row, null);
|
||||
} catch (ReaderException re) {
|
||||
fail(re.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
assertSame(BarcodeFormat.RSS_EXPANDED, result.getBarcodeFormat());
|
||||
assertEquals(expected, result.getText());
|
||||
}
|
||||
|
||||
}
|
||||
151
src/oned/rss/expanded/RSSExpandedInternalTestCase.java
Normal file
151
src/oned/rss/expanded/RSSExpandedInternalTestCase.java
Normal file
@@ -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,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.RXingResult;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
* Tests {@link RSSExpandedReader} handling of stacked RSS barcodes.
|
||||
*/
|
||||
public final class RSSExpandedStackedInternalTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testDecodingRowByRow() throws Exception {
|
||||
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
|
||||
|
||||
BinaryBitmap binaryMap = TestCaseUtil.getBinaryBitmap("src/test/resources/blackbox/rssexpandedstacked-2/1000.png");
|
||||
|
||||
int firstRowNumber = binaryMap.getHeight() / 3;
|
||||
BitArray firstRow = binaryMap.getBlackRow(firstRowNumber, null);
|
||||
try {
|
||||
rssExpandedReader.decodeRow2pairs(firstRowNumber, firstRow);
|
||||
fail(NotFoundException.class.getName() + " expected");
|
||||
} catch (NotFoundException nfe) {
|
||||
// ok
|
||||
}
|
||||
|
||||
assertEquals(1, rssExpandedReader.getRows().size());
|
||||
ExpandedRow firstExpandedRow = rssExpandedReader.getRows().get(0);
|
||||
assertEquals(firstRowNumber, firstExpandedRow.getRowNumber());
|
||||
|
||||
assertEquals(2, firstExpandedRow.getPairs().size());
|
||||
|
||||
firstExpandedRow.getPairs().get(1).getFinderPattern().getStartEnd()[1] = 0;
|
||||
|
||||
int secondRowNumber = 2 * binaryMap.getHeight() / 3;
|
||||
BitArray secondRow = binaryMap.getBlackRow(secondRowNumber, null);
|
||||
secondRow.reverse();
|
||||
|
||||
List<ExpandedPair> totalPairs = rssExpandedReader.decodeRow2pairs(secondRowNumber, secondRow);
|
||||
|
||||
RXingResult result = RSSExpandedReader.constructRXingResult(totalPairs);
|
||||
assertEquals("(01)98898765432106(3202)012345(15)991231", result.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompleteDecode() throws Exception {
|
||||
OneDReader rssExpandedReader = new RSSExpandedReader();
|
||||
|
||||
BinaryBitmap binaryMap = TestCaseUtil.getBinaryBitmap("src/test/resources/blackbox/rssexpandedstacked-2/1000.png");
|
||||
|
||||
RXingResult result = rssExpandedReader.decode(binaryMap);
|
||||
assertEquals("(01)98898765432106(3202)012345(15)991231", result.getText());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
56
src/oned/rss/expanded/TestCaseUtil.java
Normal file
56
src/oned/rss/expanded/TestCaseUtil.java
Normal file
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
58
src/oned/rss/expanded/decoders/AI013103DecoderTest.java
Normal file
58
src/oned/rss/expanded/decoders/AI013103DecoderTest.java
Normal file
@@ -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, "");
|
||||
}
|
||||
}
|
||||
53
src/oned/rss/expanded/decoders/AI0132023203DecoderTest.java
Normal file
53
src/oned/rss/expanded/decoders/AI0132023203DecoderTest.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
125
src/oned/rss/expanded/decoders/AI013X0X1XDecoderTest.java
Normal file
125
src/oned/rss/expanded/decoders/AI013X0X1XDecoderTest.java
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
77
src/oned/rss/expanded/decoders/AbstractDecoderTest.java
Normal file
77
src/oned/rss/expanded/decoders/AbstractDecoderTest.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
86
src/oned/rss/expanded/decoders/AnyAIDecoderTest.java
Normal file
86
src/oned/rss/expanded/decoders/AnyAIDecoderTest.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
54
src/oned/rss/expanded/decoders/FieldParserTest.java
Normal file
54
src/oned/rss/expanded/decoders/FieldParserTest.java
Normal file
@@ -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