mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
moved java files for pre-convert
This commit is contained in:
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.WritableRaster;
|
||||
|
||||
/**
|
||||
* This LuminanceSource implementation is meant for J2SE clients and our blackbox unit tests.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
* @author Sean Owen
|
||||
* @author code@elektrowolle.de (Wolfgang Jung)
|
||||
*/
|
||||
public final class BufferedImageLuminanceSource extends LuminanceSource {
|
||||
|
||||
private static final double MINUS_45_IN_RADIANS = -0.7853981633974483; // Math.toRadians(-45.0)
|
||||
|
||||
private final BufferedImage image;
|
||||
private final int left;
|
||||
private final int top;
|
||||
|
||||
public BufferedImageLuminanceSource(BufferedImage image) {
|
||||
this(image, 0, 0, image.getWidth(), image.getHeight());
|
||||
}
|
||||
|
||||
public BufferedImageLuminanceSource(BufferedImage image, int left, int top, int width, int height) {
|
||||
super(width, height);
|
||||
|
||||
if (image.getType() == BufferedImage.TYPE_BYTE_GRAY) {
|
||||
this.image = image;
|
||||
} else {
|
||||
int sourceWidth = image.getWidth();
|
||||
int sourceHeight = image.getHeight();
|
||||
if (left + width > sourceWidth || top + height > sourceHeight) {
|
||||
throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
|
||||
}
|
||||
|
||||
this.image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY);
|
||||
|
||||
WritableRaster raster = this.image.getRaster();
|
||||
int[] buffer = new int[width];
|
||||
for (int y = top; y < top + height; y++) {
|
||||
image.getRGB(left, y, width, 1, buffer, 0, sourceWidth);
|
||||
for (int x = 0; x < width; x++) {
|
||||
int pixel = buffer[x];
|
||||
|
||||
// The color of fully-transparent pixels is irrelevant. They are often, technically, fully-transparent
|
||||
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
|
||||
// barcode image. Force any such pixel to be white:
|
||||
if ((pixel & 0xFF000000) == 0) {
|
||||
// white, so we know its luminance is 255
|
||||
buffer[x] = 0xFF;
|
||||
} else {
|
||||
// .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
|
||||
// (306*R) >> 10 is approximately equal to R*0.299, and so on.
|
||||
// 0x200 >> 10 is 0.5, it implements rounding.
|
||||
buffer[x] =
|
||||
(306 * ((pixel >> 16) & 0xFF) +
|
||||
601 * ((pixel >> 8) & 0xFF) +
|
||||
117 * (pixel & 0xFF) +
|
||||
0x200) >> 10;
|
||||
}
|
||||
}
|
||||
raster.setPixels(left, y, width, 1, buffer);
|
||||
}
|
||||
|
||||
}
|
||||
this.left = left;
|
||||
this.top = top;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getRow(int y, byte[] row) {
|
||||
if (y < 0 || y >= getHeight()) {
|
||||
throw new IllegalArgumentException("Requested row is outside the image: " + y);
|
||||
}
|
||||
int width = getWidth();
|
||||
if (row == null || row.length < width) {
|
||||
row = new byte[width];
|
||||
}
|
||||
// The underlying raster of image consists of bytes with the luminance values
|
||||
image.getRaster().getDataElements(left, top + y, width, 1, row);
|
||||
return row;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMatrix() {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
int area = width * height;
|
||||
byte[] matrix = new byte[area];
|
||||
// The underlying raster of image consists of area bytes with the luminance values
|
||||
image.getRaster().getDataElements(left, top, width, height, matrix);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCropSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuminanceSource crop(int left, int top, int width, int height) {
|
||||
return new BufferedImageLuminanceSource(image, this.left + left, this.top + top, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is always true, since the image is a gray-scale image.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
@Override
|
||||
public boolean isRotateSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuminanceSource rotateCounterClockwise() {
|
||||
int sourceWidth = image.getWidth();
|
||||
int sourceHeight = image.getHeight();
|
||||
|
||||
// Rotate 90 degrees counterclockwise.
|
||||
AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth);
|
||||
|
||||
// Note width/height are flipped since we are rotating 90 degrees.
|
||||
BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, BufferedImage.TYPE_BYTE_GRAY);
|
||||
|
||||
// Draw the original image into rotated, via transformation
|
||||
Graphics2D g = rotatedImage.createGraphics();
|
||||
g.drawImage(image, transform, null);
|
||||
g.dispose();
|
||||
|
||||
// Maintain the cropped region, but rotate it too.
|
||||
int width = getWidth();
|
||||
return new BufferedImageLuminanceSource(rotatedImage, top, sourceWidth - (left + width), getHeight(), width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuminanceSource rotateCounterClockwise45() {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
|
||||
int oldCenterX = left + width / 2;
|
||||
int oldCenterY = top + height / 2;
|
||||
|
||||
// Rotate 45 degrees counterclockwise.
|
||||
AffineTransform transform = AffineTransform.getRotateInstance(MINUS_45_IN_RADIANS, oldCenterX, oldCenterY);
|
||||
|
||||
int sourceDimension = Math.max(image.getWidth(), image.getHeight());
|
||||
BufferedImage rotatedImage = new BufferedImage(sourceDimension, sourceDimension, BufferedImage.TYPE_BYTE_GRAY);
|
||||
|
||||
// Draw the original image into rotated, via transformation
|
||||
Graphics2D g = rotatedImage.createGraphics();
|
||||
g.drawImage(image, transform, null);
|
||||
g.dispose();
|
||||
|
||||
int halfDimension = Math.max(width, height) / 2;
|
||||
int newLeft = Math.max(0, oldCenterX - halfDimension);
|
||||
int newTop = Math.max(0, oldCenterY - halfDimension);
|
||||
int newRight = Math.min(sourceDimension - 1, oldCenterX + halfDimension);
|
||||
int newBottom = Math.min(sourceDimension - 1, oldCenterY + halfDimension);
|
||||
|
||||
return new BufferedImageLuminanceSource(rotatedImage, newLeft, newTop, newRight - newLeft, newBottom - newTop);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2020 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;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* Tests {@link InvertedLuminanceSource}.
|
||||
*/
|
||||
public final class InvertedLuminanceSourceTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testInverted() {
|
||||
BufferedImage image = new BufferedImage(2, 1, BufferedImage.TYPE_INT_RGB);
|
||||
image.setRGB(0, 0, 0xFFFFFF);
|
||||
LuminanceSource source = new BufferedImageLuminanceSource(image);
|
||||
assertArrayEquals(new byte[] { (byte) 0xFF, 0 }, source.getRow(0, null));
|
||||
LuminanceSource inverted = new InvertedLuminanceSource(source);
|
||||
assertArrayEquals(new byte[] { 0, (byte) 0xFF }, inverted.getRow(0, null));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.aztec;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author David Olivier
|
||||
*/
|
||||
public final class AztecBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public AztecBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/aztec-1", new AztecReader(), BarcodeFormat.AZTEC);
|
||||
addTest(14, 14, 0.0f);
|
||||
addTest(14, 14, 90.0f);
|
||||
addTest(14, 14, 180.0f);
|
||||
addTest(14, 14, 270.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.aztec;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A test of Aztec barcodes under real world lighting conditions, taken with a mobile phone.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class AztecBlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public AztecBlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/aztec-2", new AztecReader(), BarcodeFormat.AZTEC);
|
||||
addTest(5, 5, 0.0f);
|
||||
addTest(4, 4, 90.0f);
|
||||
addTest(6, 6, 180.0f);
|
||||
addTest(3, 3, 270.0f);
|
||||
}
|
||||
|
||||
}
|
||||
226
java_test/java/com/google/zxing/aztec/decoder/DecoderTest.java
Normal file
226
java_test/java/com/google/zxing/aztec/decoder/DecoderTest.java
Normal file
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* 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.aztec.decoder;
|
||||
|
||||
import com.google.zxing.aztec.encoder.EncoderTest;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.aztec.AztecDetectorResult;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import org.junit.Test;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* Tests {@link Decoder}.
|
||||
*/
|
||||
public final class DecoderTest extends Assert {
|
||||
|
||||
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
|
||||
|
||||
@Test
|
||||
public void testHighLevelDecode() throws FormatException {
|
||||
// no ECI codes
|
||||
testHighLevelDecodeString("A. b.",
|
||||
// 'A' P/S '. ' L/L b D/L '.'
|
||||
"...X. ..... ...XX XXX.. ...XX XXXX. XX.X");
|
||||
|
||||
// initial ECI code 26 (switch to UTF-8)
|
||||
testHighLevelDecodeString("Ça",
|
||||
// P/S FLG(n) 2 '2' '6' B/S 2 0xc3 0x87 L/L 'a'
|
||||
"..... ..... .X. .X.. X... XXXXX ...X. XX....XX X....XXX XXX.. ...X.");
|
||||
|
||||
// initial character without ECI (must be interpreted as ISO_8859_1)
|
||||
// followed by ECI code 26 (= UTF-8) and UTF-8 text
|
||||
testHighLevelDecodeString("±Ça",
|
||||
// B/S 1 0xb1 P/S FLG(n) 2 '2' '6' B/S 2 0xc3 0x87 L/L 'a'
|
||||
"XXXXX ....X X.XX...X ..... ..... .X. .X.. X... XXXXX ...X. XX....XX X....XXX XXX.. ...X.");
|
||||
|
||||
// GS1 data
|
||||
testHighLevelDecodeString("101233742",
|
||||
// P/S FLG(n) 0 D/L 1 0 1 2 3 P/S FLG(n) 0 3 7 4 2
|
||||
"..... ..... ... XXXX. ..XX ..X. ..XX .X.. .X.X .... ..... ... .X.X X..X .XX. .X..");
|
||||
}
|
||||
|
||||
private static void testHighLevelDecodeString(String expectedString, String b) throws FormatException {
|
||||
BitArray bits = EncoderTest.toBitArray(EncoderTest.stripSpace(b));
|
||||
assertEquals("highLevelDecode() failed for input bits: " + b,
|
||||
expectedString, Decoder.highLevelDecode(EncoderTest.toBooleanArray(bits)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAztecResult() throws FormatException {
|
||||
BitMatrix matrix = BitMatrix.parse(
|
||||
"X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X \n" +
|
||||
" X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X \n",
|
||||
"X ", " ");
|
||||
AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, false, 30, 2);
|
||||
DecoderResult result = new Decoder().decode(r);
|
||||
assertEquals("88888TTTTTTTTTTTTTTTTTTTTTTTTTTTTTT", result.getText());
|
||||
assertArrayEquals(
|
||||
new byte[] {-11, 85, 85, 117, 107, 90, -42, -75, -83, 107,
|
||||
90, -42, -75, -83, 107, 90, -42, -75, -83, 107,
|
||||
90, -42, -80},
|
||||
result.getRawBytes());
|
||||
assertEquals(180, result.getNumBits());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAztecResultECI() throws FormatException {
|
||||
BitMatrix matrix = BitMatrix.parse(
|
||||
" X X X X X X \n" +
|
||||
" X X X X X X X X X X X X \n" +
|
||||
" X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X \n" +
|
||||
" X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X \n" +
|
||||
" X X X X X X X X X \n" +
|
||||
"X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X \n" +
|
||||
" X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X \n" +
|
||||
" X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X \n",
|
||||
"X ", " ");
|
||||
AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, false, 15, 1);
|
||||
DecoderResult result = new Decoder().decode(r);
|
||||
assertEquals("Français", result.getText());
|
||||
}
|
||||
|
||||
@Test(expected = FormatException.class)
|
||||
public void testDecodeTooManyErrors() throws FormatException {
|
||||
BitMatrix matrix = BitMatrix.parse(""
|
||||
+ "X X . X . . . X X . . . X . . X X X . X . X X X X X . \n"
|
||||
+ "X X . . X X . . . . . X X . . . X X . . . X . X . . X \n"
|
||||
+ "X . . . X X . . X X X . X X . X X X X . X X . . X . . \n"
|
||||
+ ". . . . X . X X . . X X . X X . X . X X X X . X . . X \n"
|
||||
+ "X X X . . X X X X X . . . . . X X . . . X . X . X . X \n"
|
||||
+ "X X . . . . . . . . X . . . X . X X X . X . . X . . . \n"
|
||||
+ "X X . . X . . . . . X X . . . . . X . . . . X . . X X \n"
|
||||
+ ". . . X . X . X . . . . . X X X X X X . . . . . . X X \n"
|
||||
+ "X . . . X . X X X X X X . . X X X . X . X X X X X X . \n"
|
||||
+ "X . . X X X . X X X X X X X X X X X X X . . . X . X X \n"
|
||||
+ ". . . . X X . . . X . . . . . . . X X . . . X X . X . \n"
|
||||
+ ". . . X X X . . X X . X X X X X . X . . X . . . . . . \n"
|
||||
+ "X . . . . X . X . X . X . . . X . X . X X . X X . X X \n"
|
||||
+ "X . X . . X . X . X . X . X . X . X . . . . . X . X X \n"
|
||||
+ "X . X X X . . X . X . X . . . X . X . X X X . . . X X \n"
|
||||
+ "X X X X X X X X . X . X X X X X . X . X . X . X X X . \n"
|
||||
+ ". . . . . . . X . X . . . . . . . X X X X . . . X X X \n"
|
||||
+ "X X . . X . . X . X X X X X X X X X X X X X . . X . X \n"
|
||||
+ "X X X . X X X X . . X X X X . . X . . . . X . . X X X \n"
|
||||
+ ". . . . X . X X X . . . . X X X X . . X X X X . . . . \n"
|
||||
+ ". . X . . X . X . . . X . X X . X X . X . . . X . X . \n"
|
||||
+ "X X . . X . . X X X X X X X . . X . X X X X X X X . . \n"
|
||||
+ "X . X X . . X X . . . . . X . . . . . . X X . X X X . \n"
|
||||
+ "X . . X X . . X X . X . X . . . . X . X . . X . . X . \n"
|
||||
+ "X . X . X . . X . X X X X X X X X . X X X X . . X X . \n"
|
||||
+ "X X X X . . . X . . X X X . X X . . X . . . . X X X . \n"
|
||||
+ "X X . X . X . . . X . X . . . . X X . X . . X X . . . \n",
|
||||
"X ", ". ");
|
||||
AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, true, 16, 4);
|
||||
new Decoder().decode(r);
|
||||
}
|
||||
|
||||
@Test(expected = FormatException.class)
|
||||
public void testDecodeTooManyErrors2() throws FormatException {
|
||||
BitMatrix matrix = BitMatrix.parse(""
|
||||
+ ". X X . . X . X X . . . X . . X X X . . . X X . X X . \n"
|
||||
+ "X X . X X . . X . . . X X . . . X X . X X X . X . X X \n"
|
||||
+ ". . . . X . . . X X X . X X . X X X X . X X . . X . . \n"
|
||||
+ "X . X X . . X . . . X X . X X . X . X X . . . . . X . \n"
|
||||
+ "X X . X . . X . X X . . . . . X X . . . . . X . . . X \n"
|
||||
+ "X . . X . . . . . . X . . . X . X X X X X X X . . . X \n"
|
||||
+ "X . . X X . . X . . X X . . . . . X . . . . . X X X . \n"
|
||||
+ ". . X X X X . X . . . . . X X X X X X . . . . . . X X \n"
|
||||
+ "X . . . X . X X X X X X . . X X X . X . X X X X X X . \n"
|
||||
+ "X . . X X X . X X X X X X X X X X X X X . . . X . X X \n"
|
||||
+ ". . . . X X . . . X . . . . . . . X X . . . X X . X . \n"
|
||||
+ ". . . X X X . . X X . X X X X X . X . . X . . . . . . \n"
|
||||
+ "X . . . . X . X . X . X . . . X . X . X X . X X . X X \n"
|
||||
+ "X . X . . X . X . X . X . X . X . X . . . . . X . X X \n"
|
||||
+ "X . X X X . . X . X . X . . . X . X . X X X . . . X X \n"
|
||||
+ "X X X X X X X X . X . X X X X X . X . X . X . X X X . \n"
|
||||
+ ". . . . . . . X . X . . . . . . . X X X X . . . X X X \n"
|
||||
+ "X X . . X . . X . X X X X X X X X X X X X X . . X . X \n"
|
||||
+ "X X X . X X X X . . X X X X . . X . . . . X . . X X X \n"
|
||||
+ ". . X X X X X . X . . . . X X X X . . X X X . X . X . \n"
|
||||
+ ". . X X . X . X . . . X . X X . X X . . . . X X . . . \n"
|
||||
+ "X . . . X . X . X X X X X X . . X . X X X X X . X . . \n"
|
||||
+ ". X . . . X X X . . . . . X . . . . . X X X X X . X . \n"
|
||||
+ "X . . X . X X X X . X . X . . . . X . X X . X . . X . \n"
|
||||
+ "X . . . X X . X . X X X X X X X X . X X X X . . X X . \n"
|
||||
+ ". X X X X . . X . . X X X . X X . . X . . . . X X X . \n"
|
||||
+ "X X . . . X X . . X . X . . . . X X . X . . X . X . X \n",
|
||||
"X ", ". ");
|
||||
AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, true, 16, 4);
|
||||
new Decoder().decode(r);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawBytes() {
|
||||
boolean[] bool0 = {};
|
||||
boolean[] bool1 = { true };
|
||||
boolean[] bool7 = { true, false, true, false, true, false, true };
|
||||
boolean[] bool8 = { true, false, true, false, true, false, true, false };
|
||||
boolean[] bool9 = { true, false, true, false, true, false, true, false,
|
||||
true };
|
||||
boolean[] bool16 = { false, true, true, false, false, false, true, true,
|
||||
true, true, false, false, false, false, false, true };
|
||||
byte[] byte0 = {};
|
||||
byte[] byte1 = { -128 };
|
||||
byte[] byte7 = { -86 };
|
||||
byte[] byte8 = { -86 };
|
||||
byte[] byte9 = { -86, -128 };
|
||||
byte[] byte16 = { 99, -63 };
|
||||
|
||||
assertArrayEquals(byte0, Decoder.convertBoolArrayToByteArray(bool0));
|
||||
assertArrayEquals(byte1, Decoder.convertBoolArrayToByteArray(bool1));
|
||||
assertArrayEquals(byte7, Decoder.convertBoolArrayToByteArray(bool7));
|
||||
assertArrayEquals(byte8, Decoder.convertBoolArrayToByteArray(bool8));
|
||||
assertArrayEquals(byte9, Decoder.convertBoolArrayToByteArray(bool9));
|
||||
assertArrayEquals(byte16, Decoder.convertBoolArrayToByteArray(bool16));
|
||||
}
|
||||
}
|
||||
189
java_test/java/com/google/zxing/aztec/detector/DetectorTest.java
Normal file
189
java_test/java/com/google/zxing/aztec/detector/DetectorTest.java
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright 2013 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.aztec.detector;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.aztec.AztecDetectorResult;
|
||||
import com.google.zxing.aztec.decoder.Decoder;
|
||||
import com.google.zxing.aztec.detector.Detector.Point;
|
||||
import com.google.zxing.aztec.encoder.AztecCode;
|
||||
import com.google.zxing.aztec.encoder.Encoder;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Tests for the Detector
|
||||
*
|
||||
* @author Frank Yellin
|
||||
*/
|
||||
public final class DetectorTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void testErrorInParameterLocatorZeroZero() throws Exception {
|
||||
// Layers=1, CodeWords=1. So the parameter info and its Reed-Solomon info
|
||||
// will be completely zero!
|
||||
testErrorInParameterLocator("X");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorInParameterLocatorCompact() throws Exception {
|
||||
testErrorInParameterLocator("This is an example Aztec symbol for Wikipedia.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorInParameterLocatorNotCompact() throws Exception {
|
||||
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxyz";
|
||||
testErrorInParameterLocator(alphabet + alphabet + alphabet);
|
||||
}
|
||||
|
||||
// Test that we can tolerate errors in the parameter locator bits
|
||||
private static void testErrorInParameterLocator(String data) throws Exception {
|
||||
AztecCode aztec = Encoder.encode(data, 25, Encoder.DEFAULT_AZTEC_LAYERS);
|
||||
Random random = new Random(aztec.getMatrix().hashCode()); // pseudo-random, but deterministic
|
||||
int layers = aztec.getLayers();
|
||||
boolean compact = aztec.isCompact();
|
||||
List<Point> orientationPoints = getOrientationPoints(aztec);
|
||||
for (boolean isMirror : new boolean[] { false, true }) {
|
||||
for (BitMatrix matrix : getRotations(aztec.getMatrix())) {
|
||||
// Systematically try every possible 1- and 2-bit error.
|
||||
for (int error1 = 0; error1 < orientationPoints.size(); error1++) {
|
||||
for (int error2 = error1; error2 < orientationPoints.size(); error2++) {
|
||||
BitMatrix copy = isMirror ? transpose(matrix) : clone(matrix);
|
||||
copy.flip(orientationPoints.get(error1).getX(), orientationPoints.get(error1).getY());
|
||||
if (error2 > error1) {
|
||||
// if error2 == error1, we only test a single error
|
||||
copy.flip(orientationPoints.get(error2).getX(), orientationPoints.get(error2).getY());
|
||||
}
|
||||
// The detector doesn't seem to work when matrix bits are only 1x1. So magnify.
|
||||
AztecDetectorResult r = new Detector(makeLarger(copy, 3)).detect(isMirror);
|
||||
assertNotNull(r);
|
||||
assertEquals(r.getNbLayers(), layers);
|
||||
assertEquals(r.isCompact(), compact);
|
||||
DecoderResult res = new Decoder().decode(r);
|
||||
assertEquals(data, res.getText());
|
||||
}
|
||||
}
|
||||
// Try a few random three-bit errors;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
BitMatrix copy = clone(matrix);
|
||||
Collection<Integer> errors = new TreeSet<>();
|
||||
while (errors.size() < 3) {
|
||||
// Quick and dirty way of getting three distinct integers between 1 and n.
|
||||
errors.add(random.nextInt(orientationPoints.size()));
|
||||
}
|
||||
for (int error : errors) {
|
||||
copy.flip(orientationPoints.get(error).getX(), orientationPoints.get(error).getY());
|
||||
}
|
||||
try {
|
||||
new Detector(makeLarger(copy, 3)).detect(false);
|
||||
fail("Should not reach here");
|
||||
} catch (NotFoundException expected) {
|
||||
// continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Zooms a bit matrix so that each bit is factor x factor
|
||||
private static BitMatrix makeLarger(BitMatrix input, int factor) {
|
||||
int width = input.getWidth();
|
||||
BitMatrix output = new BitMatrix(width * factor);
|
||||
for (int inputY = 0; inputY < width; inputY++) {
|
||||
for (int inputX = 0; inputX < width; inputX++) {
|
||||
if (input.get(inputX, inputY)) {
|
||||
output.setRegion(inputX * factor, inputY * factor, factor, factor);
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
// Returns a list of the four rotations of the BitMatrix.
|
||||
private static Iterable<BitMatrix> getRotations(BitMatrix matrix0) {
|
||||
BitMatrix matrix90 = rotateRight(matrix0);
|
||||
BitMatrix matrix180 = rotateRight(matrix90);
|
||||
BitMatrix matrix270 = rotateRight(matrix180);
|
||||
return Arrays.asList(matrix0, matrix90, matrix180, matrix270);
|
||||
}
|
||||
|
||||
// Rotates a square BitMatrix to the right by 90 degrees
|
||||
private static BitMatrix rotateRight(BitMatrix input) {
|
||||
int width = input.getWidth();
|
||||
BitMatrix result = new BitMatrix(width);
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < width; y++) {
|
||||
if (input.get(x,y)) {
|
||||
result.set(y, width - x - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Returns the transpose of a bit matrix, which is equivalent to rotating the
|
||||
// matrix to the right, and then flipping it left-to-right
|
||||
private static BitMatrix transpose(BitMatrix input) {
|
||||
int width = input.getWidth();
|
||||
BitMatrix result = new BitMatrix(width);
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < width; y++) {
|
||||
if (input.get(x, y)) {
|
||||
result.set(y, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static BitMatrix clone(BitMatrix input) {
|
||||
int width = input.getWidth();
|
||||
BitMatrix result = new BitMatrix(width);
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < width; y++) {
|
||||
if (input.get(x,y)) {
|
||||
result.set(x,y);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<Point> getOrientationPoints(AztecCode code) {
|
||||
int center = code.getMatrix().getWidth() / 2;
|
||||
int offset = code.isCompact() ? 5 : 7;
|
||||
List<Point> result = new ArrayList<>();
|
||||
for (int xSign = -1; xSign <= 1; xSign += 2) {
|
||||
for (int ySign = -1; ySign <= 1; ySign += 2) {
|
||||
result.add(new Point(center + xSign * offset, center + ySign * offset));
|
||||
result.add(new Point(center + xSign * (offset - 1), center + ySign * offset));
|
||||
result.add(new Point(center + xSign * offset, center + ySign * (offset - 1)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
603
java_test/java/com/google/zxing/aztec/encoder/EncoderTest.java
Normal file
603
java_test/java/com/google/zxing/aztec/encoder/EncoderTest.java
Normal file
@@ -0,0 +1,603 @@
|
||||
/*
|
||||
* Copyright 2013 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.aztec.encoder;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.aztec.AztecDetectorResult;
|
||||
import com.google.zxing.aztec.AztecWriter;
|
||||
import com.google.zxing.aztec.decoder.Decoder;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Aztec 2D generator unit tests.
|
||||
*
|
||||
* @author Rustam Abdullaev
|
||||
* @author Frank Yellin
|
||||
*/
|
||||
public final class EncoderTest extends Assert {
|
||||
|
||||
private static final Charset ISO_8859_1 = StandardCharsets.ISO_8859_1;
|
||||
private static final Charset UTF_8 = StandardCharsets.UTF_8;
|
||||
private static final Charset SHIFT_JIS = Charset.forName("Shift_JIS");
|
||||
private static final Charset ISO_8859_15 = Charset.forName("ISO-8859-15");
|
||||
private static final Charset WINDOWS_1252 = Charset.forName("Windows-1252");
|
||||
|
||||
private static final Pattern DOTX = Pattern.compile("[^.X]");
|
||||
private static final Pattern SPACES = Pattern.compile("\\s+");
|
||||
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
|
||||
|
||||
// real life tests
|
||||
|
||||
@Test
|
||||
public void testEncode1() {
|
||||
testEncode("This is an example Aztec symbol for Wikipedia.", true, 3,
|
||||
"X X X X X X X X \n" +
|
||||
"X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X \n" +
|
||||
" X X X \n" +
|
||||
" X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X \n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode2() {
|
||||
testEncode("Aztec Code is a public domain 2D matrix barcode symbology" +
|
||||
" of nominally square symbols built on a square grid with a " +
|
||||
"distinctive square bullseye pattern at their center.", false, 6,
|
||||
" X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X \n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAztecWriter() throws Exception {
|
||||
testWriter("Espa\u00F1ol", null, 25, true, 1); // Without ECI (implicit ISO-8859-1)
|
||||
testWriter("Espa\u00F1ol", ISO_8859_1, 25, true, 1); // Explicit ISO-8859-1
|
||||
testWriter("\u20AC 1 sample data.", WINDOWS_1252, 25, true, 2); // ISO-8859-1 can't encode Euro; Windows-1252 can
|
||||
testWriter("\u20AC 1 sample data.", ISO_8859_15, 25, true, 2);
|
||||
testWriter("\u20AC 1 sample data.", UTF_8, 25, true, 2);
|
||||
testWriter("\u20AC 1 sample data.", UTF_8, 100, true, 3);
|
||||
testWriter("\u20AC 1 sample data.", UTF_8, 300, true, 4);
|
||||
testWriter("\u20AC 1 sample data.", UTF_8, 500, false, 5);
|
||||
testWriter("The capital of Japan is named \u6771\u4EAC.", SHIFT_JIS, 25, true, 3);
|
||||
// Test AztecWriter defaults
|
||||
String data = "In ut magna vel mauris malesuada";
|
||||
AztecWriter writer = new AztecWriter();
|
||||
BitMatrix matrix = writer.encode(data, BarcodeFormat.AZTEC, 0, 0);
|
||||
AztecCode aztec = Encoder.encode(data,
|
||||
Encoder.DEFAULT_EC_PERCENT, Encoder.DEFAULT_AZTEC_LAYERS);
|
||||
BitMatrix expectedMatrix = aztec.getMatrix();
|
||||
assertEquals(matrix, expectedMatrix);
|
||||
}
|
||||
|
||||
// synthetic tests (encode-decode round-trip)
|
||||
|
||||
@Test
|
||||
public void testEncodeDecode1() throws Exception {
|
||||
testEncodeDecode("Abc123!", true, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeDecode2() throws Exception {
|
||||
testEncodeDecode("Lorem ipsum. http://test/", true, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeDecode3() throws Exception {
|
||||
testEncodeDecode("AAAANAAAANAAAANAAAANAAAANAAAANAAAANAAAANAAAANAAAAN", true, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeDecode4() throws Exception {
|
||||
testEncodeDecode("http://test/~!@#*^%&)__ ;:'\"[]{}\\|-+-=`1029384", true, 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeDecode5() throws Exception {
|
||||
testEncodeDecode("http://test/~!@#*^%&)__ ;:'\"[]{}\\|-+-=`1029384756<>/?abc"
|
||||
+ "Four score and seven our forefathers brought forth", false, 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeDecode10() throws Exception {
|
||||
testEncodeDecode("In ut magna vel mauris malesuada dictum. Nulla ullamcorper metus quis diam" +
|
||||
" cursus facilisis. Sed mollis quam id justo rutrum sagittis. Donec laoreet rutrum" +
|
||||
" est, nec convallis mauris condimentum sit amet. Phasellus gravida, justo et congue" +
|
||||
" auctor, nisi ipsum viverra erat, eget hendrerit felis turpis nec lorem. Nulla" +
|
||||
" ultrices, elit pellentesque aliquet laoreet, justo erat pulvinar nisi, id" +
|
||||
" elementum sapien dolor et diam.", false, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeDecode23() throws Exception {
|
||||
testEncodeDecode("In ut magna vel mauris malesuada dictum. Nulla ullamcorper metus quis diam" +
|
||||
" cursus facilisis. Sed mollis quam id justo rutrum sagittis. Donec laoreet rutrum" +
|
||||
" est, nec convallis mauris condimentum sit amet. Phasellus gravida, justo et congue" +
|
||||
" auctor, nisi ipsum viverra erat, eget hendrerit felis turpis nec lorem. Nulla" +
|
||||
" ultrices, elit pellentesque aliquet laoreet, justo erat pulvinar nisi, id" +
|
||||
" elementum sapien dolor et diam. Donec ac nunc sodales elit placerat eleifend." +
|
||||
" Sed ornare luctus ornare. Vestibulum vehicula, massa at pharetra fringilla, risus" +
|
||||
" justo faucibus erat, nec porttitor nibh tellus sed est. Ut justo diam, lobortis eu" +
|
||||
" tristique ac, p.In ut magna vel mauris malesuada dictum. Nulla ullamcorper metus" +
|
||||
" quis diam cursus facilisis. Sed mollis quam id justo rutrum sagittis. Donec" +
|
||||
" laoreet rutrum est, nec convallis mauris condimentum sit amet. Phasellus gravida," +
|
||||
" justo et congue auctor, nisi ipsum viverra erat, eget hendrerit felis turpis nec" +
|
||||
" lorem. Nulla ultrices, elit pellentesque aliquet laoreet, justo erat pulvinar" +
|
||||
" nisi, id elementum sapien dolor et diam. Donec ac nunc sodales elit placerat" +
|
||||
" eleifend. Sed ornare luctus ornare. Vestibulum vehicula, massa at pharetra" +
|
||||
" fringilla, risus justo faucibus erat, nec porttitor nibh tellus sed est. Ut justo" +
|
||||
" diam, lobortis eu tristique ac, p. In ut magna vel mauris malesuada dictum. Nulla" +
|
||||
" ullamcorper metus quis diam cursus facilisis. Sed mollis quam id justo rutrum" +
|
||||
" sagittis. Donec laoreet rutrum est, nec convallis mauris condimentum sit amet." +
|
||||
" Phasellus gravida, justo et congue auctor, nisi ipsum viverra erat, eget hendrerit" +
|
||||
" felis turpis nec lorem. Nulla ultrices, elit pellentesque aliquet laoreet, justo" +
|
||||
" erat pulvinar nisi, id elementum sapien dolor et diam.", false, 23);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeDecode31() throws Exception {
|
||||
testEncodeDecode("In ut magna vel mauris malesuada dictum. Nulla ullamcorper metus quis diam" +
|
||||
" cursus facilisis. Sed mollis quam id justo rutrum sagittis. Donec laoreet rutrum" +
|
||||
" est, nec convallis mauris condimentum sit amet. Phasellus gravida, justo et congue" +
|
||||
" auctor, nisi ipsum viverra erat, eget hendrerit felis turpis nec lorem. Nulla" +
|
||||
" ultrices, elit pellentesque aliquet laoreet, justo erat pulvinar nisi, id" +
|
||||
" elementum sapien dolor et diam. Donec ac nunc sodales elit placerat eleifend." +
|
||||
" Sed ornare luctus ornare. Vestibulum vehicula, massa at pharetra fringilla, risus" +
|
||||
" justo faucibus erat, nec porttitor nibh tellus sed est. Ut justo diam, lobortis eu" +
|
||||
" tristique ac, p.In ut magna vel mauris malesuada dictum. Nulla ullamcorper metus" +
|
||||
" quis diam cursus facilisis. Sed mollis quam id justo rutrum sagittis. Donec" +
|
||||
" laoreet rutrum est, nec convallis mauris condimentum sit amet. Phasellus gravida," +
|
||||
" justo et congue auctor, nisi ipsum viverra erat, eget hendrerit felis turpis nec" +
|
||||
" lorem. Nulla ultrices, elit pellentesque aliquet laoreet, justo erat pulvinar" +
|
||||
" nisi, id elementum sapien dolor et diam. Donec ac nunc sodales elit placerat" +
|
||||
" eleifend. Sed ornare luctus ornare. Vestibulum vehicula, massa at pharetra" +
|
||||
" fringilla, risus justo faucibus erat, nec porttitor nibh tellus sed est. Ut justo" +
|
||||
" diam, lobortis eu tristique ac, p. In ut magna vel mauris malesuada dictum. Nulla" +
|
||||
" ullamcorper metus quis diam cursus facilisis. Sed mollis quam id justo rutrum" +
|
||||
" sagittis. Donec laoreet rutrum est, nec convallis mauris condimentum sit amet." +
|
||||
" Phasellus gravida, justo et congue auctor, nisi ipsum viverra erat, eget hendrerit" +
|
||||
" felis turpis nec lorem. Nulla ultrices, elit pellentesque aliquet laoreet, justo" +
|
||||
" erat pulvinar nisi, id elementum sapien dolor et diam. Donec ac nunc sodales elit" +
|
||||
" placerat eleifend. Sed ornare luctus ornare. Vestibulum vehicula, massa at" +
|
||||
" pharetra fringilla, risus justo faucibus erat, nec porttitor nibh tellus sed est." +
|
||||
" Ut justo diam, lobortis eu tristique ac, p.In ut magna vel mauris malesuada" +
|
||||
" dictum. Nulla ullamcorper metus quis diam cursus facilisis. Sed mollis quam id" +
|
||||
" justo rutrum sagittis. Donec laoreet rutrum est, nec convallis mauris condimentum" +
|
||||
" sit amet. Phasellus gravida, justo et congue auctor, nisi ipsum viverra erat," +
|
||||
" eget hendrerit felis turpis nec lorem. Nulla ultrices, elit pellentesque aliquet" +
|
||||
" laoreet, justo erat pulvinar nisi, id elementum sapien dolor et diam. Donec ac" +
|
||||
" nunc sodales elit placerat eleifend. Sed ornare luctus ornare. Vestibulum vehicula," +
|
||||
" massa at pharetra fringilla, risus justo faucibus erat, nec porttitor nibh tellus" +
|
||||
" sed est. Ut justo diam, lobortis eu tris. In ut magna vel mauris malesuada dictum." +
|
||||
" Nulla ullamcorper metus quis diam cursus facilisis. Sed mollis quam id justo rutrum" +
|
||||
" sagittis. Donec laoreet rutrum est, nec convallis mauris condimentum sit amet." +
|
||||
" Phasellus gravida, justo et congue auctor, nisi ipsum viverra erat, eget" +
|
||||
" hendrerit felis turpis nec lorem.", false, 31);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateModeMessage() {
|
||||
testModeMessage(true, 2, 29, ".X .XXX.. ...X XX.. ..X .XX. .XX.X");
|
||||
testModeMessage(true, 4, 64, "XX XXXXXX .X.. ...X ..XX .X.. XX..");
|
||||
testModeMessage(false, 21, 660, "X.X.. .X.X..X..XX .XXX ..X.. .XXX. .X... ..XXX");
|
||||
testModeMessage(false, 32, 4096, "XXXXX XXXXXXXXXXX X.X. ..... XXX.X ..X.. X.XXX");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStuffBits() {
|
||||
testStuffBits(5, ".X.X. X.X.X .X.X.",
|
||||
".X.X. X.X.X .X.X.");
|
||||
testStuffBits(5, ".X.X. ..... .X.X",
|
||||
".X.X. ....X ..X.X");
|
||||
testStuffBits(3, "XX. ... ... ..X XXX .X. ..",
|
||||
"XX. ..X ..X ..X ..X .XX XX. .X. ..X");
|
||||
testStuffBits(6, ".X.X.. ...... ..X.XX",
|
||||
".X.X.. .....X. ..X.XX XXXX.");
|
||||
testStuffBits(6, ".X.X.. ...... ...... ..X.X.",
|
||||
".X.X.. .....X .....X ....X. X.XXXX");
|
||||
testStuffBits(6, ".X.X.. XXXXXX ...... ..X.XX",
|
||||
".X.X.. XXXXX. X..... ...X.X XXXXX.");
|
||||
testStuffBits(6,
|
||||
"...... ..XXXX X..XX. .X.... .X.X.X .....X .X.... ...X.X .....X ....XX ..X... ....X. X..XXX X.XX.X",
|
||||
".....X ...XXX XX..XX ..X... ..X.X. X..... X.X... ....X. X..... X....X X..X.. .....X X.X..X XXX.XX .XXXXX");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHighLevelEncode() throws FormatException {
|
||||
testHighLevelEncodeString("A. b.",
|
||||
// 'A' P/S '. ' L/L b D/L '.'
|
||||
"...X. ..... ...XX XXX.. ...XX XXXX. XX.X");
|
||||
testHighLevelEncodeString("Lorem ipsum.",
|
||||
// 'L' L/L 'o' 'r' 'e' 'm' ' ' 'i' 'p' 's' 'u' 'm' D/L '.'
|
||||
".XX.X XXX.. X.... X..XX ..XX. .XXX. ....X .X.X. X...X X.X.. X.XX. .XXX. XXXX. XX.X");
|
||||
testHighLevelEncodeString("Lo. Test 123.",
|
||||
// 'L' L/L 'o' P/S '. ' U/S 'T' 'e' 's' 't' D/L ' ' '1' '2' '3' '.'
|
||||
".XX.X XXX.. X.... ..... ...XX XXX.. X.X.X ..XX. X.X.. X.X.X XXXX. ...X ..XX .X.. .X.X XX.X");
|
||||
testHighLevelEncodeString("Lo...x",
|
||||
// 'L' L/L 'o' D/L '.' '.' '.' U/L L/L 'x'
|
||||
".XX.X XXX.. X.... XXXX. XX.X XX.X XX.X XXX. XXX.. XX..X");
|
||||
testHighLevelEncodeString(". x://abc/.",
|
||||
//P/S '. ' L/L 'x' P/S ':' P/S '/' P/S '/' 'a' 'b' 'c' P/S '/' D/L '.'
|
||||
"..... ...XX XXX.. XX..X ..... X.X.X ..... X.X.. ..... X.X.. ...X. ...XX ..X.. ..... X.X.. XXXX. XX.X");
|
||||
// Uses Binary/Shift rather than Lower/Shift to save two bits.
|
||||
testHighLevelEncodeString("ABCdEFG",
|
||||
//'A' 'B' 'C' B/S =1 'd' 'E' 'F' 'G'
|
||||
"...X. ...XX ..X.. XXXXX ....X .XX..X.. ..XX. ..XXX .X...");
|
||||
|
||||
testHighLevelEncodeString(
|
||||
// Found on an airline boarding pass. Several stretches of Binary shift are
|
||||
// necessary to keep the bitcount so low.
|
||||
"09 UAG ^160MEUCIQC0sYS/HpKxnBELR1uB85R20OoqqwFGa0q2uEi"
|
||||
+ "Ygh6utAIgLl1aBVM4EOTQtMQQYH9M2Z3Dp4qnA/fwWuQ+M8L3V8U=",
|
||||
823);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHighLevelEncodeBinary() throws FormatException {
|
||||
// binary short form single byte
|
||||
testHighLevelEncodeString("N\0N",
|
||||
// 'N' B/S =1 '\0' N
|
||||
".XXXX XXXXX ....X ........ .XXXX"); // Encode "N" in UPPER
|
||||
|
||||
testHighLevelEncodeString("N\0n",
|
||||
// 'N' B/S =2 '\0' 'n'
|
||||
".XXXX XXXXX ...X. ........ .XX.XXX."); // Encode "n" in BINARY
|
||||
|
||||
// binary short form consecutive bytes
|
||||
testHighLevelEncodeString("N\0\u0080 A",
|
||||
// 'N' B/S =2 '\0' \u0080 ' ' 'A'
|
||||
".XXXX XXXXX ...X. ........ X....... ....X ...X.");
|
||||
|
||||
// binary skipping over single character
|
||||
testHighLevelEncodeString("\0a\u00FF\u0080 A",
|
||||
// B/S =4 '\0' 'a' '\3ff' '\200' ' ' 'A'
|
||||
"XXXXX ..X.. ........ .XX....X XXXXXXXX X....... ....X ...X.");
|
||||
|
||||
// getting into binary mode from digit mode
|
||||
testHighLevelEncodeString("1234\0",
|
||||
//D/L '1' '2' '3' '4' U/L B/S =1 \0
|
||||
"XXXX. ..XX .X.. .X.X .XX. XXX. XXXXX ....X ........"
|
||||
);
|
||||
|
||||
// Create a string in which every character requires binary
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i <= 3000; i++) {
|
||||
sb.append((char) (128 + (i % 30)));
|
||||
}
|
||||
// Test the output generated by Binary/Switch, particularly near the
|
||||
// places where the encoding changes: 31, 62, and 2047+31=2078
|
||||
for (int i : new int[] { 1, 2, 3, 10, 29, 30, 31, 32, 33,
|
||||
60, 61, 62, 63, 64, 2076, 2077, 2078, 2079, 2080, 2100 }) {
|
||||
// This is the expected length of a binary string of length "i"
|
||||
int expectedLength = (8 * i) +
|
||||
((i <= 31) ? 10 : (i <= 62) ? 20 : (i <= 2078) ? 21 : 31);
|
||||
// Verify that we are correct about the length.
|
||||
testHighLevelEncodeString(sb.substring(0, i), expectedLength);
|
||||
if (i != 1 && i != 32 && i != 2079) {
|
||||
// The addition of an 'a' at the beginning or end gets merged into the binary code
|
||||
// in those cases where adding another binary character only adds 8 or 9 bits to the result.
|
||||
// So we exclude the border cases i=1,32,2079
|
||||
// A lower case letter at the beginning will be merged into binary mode
|
||||
testHighLevelEncodeString('a' + sb.substring(0, i - 1), expectedLength);
|
||||
// A lower case letter at the end will also be merged into binary mode
|
||||
testHighLevelEncodeString(sb.substring(0, i - 1) + 'a', expectedLength);
|
||||
}
|
||||
// A lower case letter at both ends will enough to latch us into LOWER.
|
||||
testHighLevelEncodeString('a' + sb.substring(0, i) + 'b', expectedLength + 15);
|
||||
}
|
||||
|
||||
sb = new StringBuilder();
|
||||
for (int i = 0; i < 32; i++) {
|
||||
sb.append('§'); // § forces binary encoding
|
||||
}
|
||||
sb.setCharAt(1, 'A');
|
||||
// expect B/S(1) A B/S(30)
|
||||
testHighLevelEncodeString(sb.toString(), 5 + 20 + 31 * 8);
|
||||
|
||||
sb = new StringBuilder();
|
||||
for (int i = 0; i < 31; i++) {
|
||||
sb.append('§');
|
||||
}
|
||||
sb.setCharAt(1, 'A');
|
||||
// expect B/S(31)
|
||||
testHighLevelEncodeString(sb.toString(), 10 + 31 * 8);
|
||||
|
||||
sb = new StringBuilder();
|
||||
for (int i = 0; i < 34; i++) {
|
||||
sb.append('§');
|
||||
}
|
||||
sb.setCharAt(1, 'A');
|
||||
// expect B/S(31) B/S(3)
|
||||
testHighLevelEncodeString(sb.toString(), 20 + 34 * 8);
|
||||
|
||||
sb = new StringBuilder();
|
||||
for (int i = 0; i < 64; i++) {
|
||||
sb.append('§');
|
||||
}
|
||||
sb.setCharAt(30, 'A');
|
||||
// expect B/S(64)
|
||||
testHighLevelEncodeString(sb.toString(), 21 + 64 * 8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHighLevelEncodePairs() throws FormatException {
|
||||
// Typical usage
|
||||
testHighLevelEncodeString("ABC. DEF\r\n",
|
||||
// A B C P/S .<sp> D E F P/S \r\n
|
||||
"...X. ...XX ..X.. ..... ...XX ..X.X ..XX. ..XXX ..... ...X.");
|
||||
|
||||
// We should latch to PUNCT mode, rather than shift. Also check all pairs
|
||||
testHighLevelEncodeString("A. : , \r\n",
|
||||
// 'A' M/L P/L ". " ": " ", " "\r\n"
|
||||
"...X. XXX.X XXXX. ...XX ..X.X ..X.. ...X.");
|
||||
|
||||
// Latch to DIGIT rather than shift to PUNCT
|
||||
testHighLevelEncodeString("A. 1234",
|
||||
// 'A' D/L '.' ' ' '1' '2' '3' '4'
|
||||
"...X. XXXX. XX.X ...X ..XX .X.. .X.X .X X.");
|
||||
// Don't bother leaving Binary Shift.
|
||||
testHighLevelEncodeString("A\200. \200",
|
||||
// 'A' B/S =2 \200 "." " " \200
|
||||
"...X. XXXXX ..X.. X....... ..X.XXX. ..X..... X.......");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testUserSpecifiedLayers() {
|
||||
doTestUserSpecifiedLayers(33);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testUserSpecifiedLayers2() {
|
||||
doTestUserSpecifiedLayers(-1);
|
||||
}
|
||||
|
||||
private void doTestUserSpecifiedLayers(int userSpecifiedLayers) {
|
||||
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
AztecCode aztec = Encoder.encode(alphabet, 25, -2);
|
||||
assertEquals(2, aztec.getLayers());
|
||||
assertTrue(aztec.isCompact());
|
||||
|
||||
aztec = Encoder.encode(alphabet, 25, 32);
|
||||
assertEquals(32, aztec.getLayers());
|
||||
assertFalse(aztec.isCompact());
|
||||
|
||||
Encoder.encode(alphabet, 25, userSpecifiedLayers);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBorderCompact4CaseFailed() {
|
||||
// Compact(4) con hold 608 bits of information, but at most 504 can be data. Rest must
|
||||
// be error correction
|
||||
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
// encodes as 26 * 5 * 4 = 520 bits of data
|
||||
String alphabet4 = alphabet + alphabet + alphabet + alphabet;
|
||||
Encoder.encode(alphabet4, 0, -4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBorderCompact4Case() {
|
||||
// Compact(4) con hold 608 bits of information, but at most 504 can be data. Rest must
|
||||
// be error correction
|
||||
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
// encodes as 26 * 5 * 4 = 520 bits of data
|
||||
String alphabet4 = alphabet + alphabet + alphabet + alphabet;
|
||||
|
||||
// If we just try to encode it normally, it will go to a non-compact 4 layer
|
||||
AztecCode aztecCode = Encoder.encode(alphabet4, 0, Encoder.DEFAULT_AZTEC_LAYERS);
|
||||
assertFalse(aztecCode.isCompact());
|
||||
assertEquals(4, aztecCode.getLayers());
|
||||
|
||||
// But shortening the string to 100 bytes (500 bits of data), compact works fine, even if we
|
||||
// include more error checking.
|
||||
aztecCode = Encoder.encode(alphabet4.substring(0, 100), 10, Encoder.DEFAULT_AZTEC_LAYERS);
|
||||
assertTrue(aztecCode.isCompact());
|
||||
assertEquals(4, aztecCode.getLayers());
|
||||
}
|
||||
|
||||
// Helper routines
|
||||
|
||||
private static void testEncode(String data, boolean compact, int layers, String expected) {
|
||||
AztecCode aztec = Encoder.encode(data, 33, Encoder.DEFAULT_AZTEC_LAYERS);
|
||||
assertEquals("Unexpected symbol format (compact)", compact, aztec.isCompact());
|
||||
assertEquals("Unexpected nr. of layers", layers, aztec.getLayers());
|
||||
BitMatrix matrix = aztec.getMatrix();
|
||||
assertEquals("encode() failed", expected, matrix.toString());
|
||||
}
|
||||
|
||||
private static void testEncodeDecode(String data, boolean compact, int layers) throws Exception {
|
||||
AztecCode aztec = Encoder.encode(data, 25, Encoder.DEFAULT_AZTEC_LAYERS);
|
||||
assertEquals("Unexpected symbol format (compact)", compact, aztec.isCompact());
|
||||
assertEquals("Unexpected nr. of layers", layers, aztec.getLayers());
|
||||
BitMatrix matrix = aztec.getMatrix();
|
||||
AztecDetectorResult r =
|
||||
new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact(), aztec.getCodeWords(), aztec.getLayers());
|
||||
DecoderResult res = new Decoder().decode(r);
|
||||
assertEquals(data, res.getText());
|
||||
// Check error correction by introducing a few minor errors
|
||||
Random random = getPseudoRandom();
|
||||
matrix.flip(random.nextInt(matrix.getWidth()), random.nextInt(2));
|
||||
matrix.flip(random.nextInt(matrix.getWidth()), matrix.getHeight() - 2 + random.nextInt(2));
|
||||
matrix.flip(random.nextInt(2), random.nextInt(matrix.getHeight()));
|
||||
matrix.flip(matrix.getWidth() - 2 + random.nextInt(2), random.nextInt(matrix.getHeight()));
|
||||
r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact(), aztec.getCodeWords(), aztec.getLayers());
|
||||
res = new Decoder().decode(r);
|
||||
assertEquals(data, res.getText());
|
||||
}
|
||||
|
||||
private static void testWriter(String data,
|
||||
Charset charset,
|
||||
int eccPercent,
|
||||
boolean compact,
|
||||
int layers) throws FormatException {
|
||||
// Perform an encode-decode round-trip because it can be lossy.
|
||||
Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
if (null != charset) {
|
||||
hints.put(EncodeHintType.CHARACTER_SET, charset.name());
|
||||
}
|
||||
hints.put(EncodeHintType.ERROR_CORRECTION, eccPercent);
|
||||
AztecWriter writer = new AztecWriter();
|
||||
BitMatrix matrix = writer.encode(data, BarcodeFormat.AZTEC, 0, 0, hints);
|
||||
AztecCode aztec = Encoder.encode(data, eccPercent,
|
||||
Encoder.DEFAULT_AZTEC_LAYERS, charset);
|
||||
assertEquals("Unexpected symbol format (compact)", compact, aztec.isCompact());
|
||||
assertEquals("Unexpected nr. of layers", layers, aztec.getLayers());
|
||||
BitMatrix matrix2 = aztec.getMatrix();
|
||||
assertEquals(matrix, matrix2);
|
||||
AztecDetectorResult r =
|
||||
new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact(), aztec.getCodeWords(), aztec.getLayers());
|
||||
DecoderResult res = new Decoder().decode(r);
|
||||
assertEquals(data, res.getText());
|
||||
// Check error correction by introducing up to eccPercent/2 errors
|
||||
int ecWords = aztec.getCodeWords() * eccPercent / 100 / 2;
|
||||
Random random = getPseudoRandom();
|
||||
for (int i = 0; i < ecWords; i++) {
|
||||
// don't touch the core
|
||||
int x = random.nextBoolean() ?
|
||||
random.nextInt(aztec.getLayers() * 2)
|
||||
: matrix.getWidth() - 1 - random.nextInt(aztec.getLayers() * 2);
|
||||
int y = random.nextBoolean() ?
|
||||
random.nextInt(aztec.getLayers() * 2)
|
||||
: matrix.getHeight() - 1 - random.nextInt(aztec.getLayers() * 2);
|
||||
matrix.flip(x, y);
|
||||
}
|
||||
r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact(), aztec.getCodeWords(), aztec.getLayers());
|
||||
res = new Decoder().decode(r);
|
||||
assertEquals(data, res.getText());
|
||||
}
|
||||
|
||||
private static Random getPseudoRandom() {
|
||||
return new Random(0xDEADBEEF);
|
||||
}
|
||||
|
||||
private static void testModeMessage(boolean compact, int layers, int words, String expected) {
|
||||
BitArray in = Encoder.generateModeMessage(compact, layers, words);
|
||||
assertEquals("generateModeMessage() failed", stripSpace(expected), stripSpace(in.toString()));
|
||||
}
|
||||
|
||||
private static void testStuffBits(int wordSize, String bits, String expected) {
|
||||
BitArray in = toBitArray(bits);
|
||||
BitArray stuffed = Encoder.stuffBits(in, wordSize);
|
||||
assertEquals("stuffBits() failed for input string: " + bits,
|
||||
stripSpace(expected), stripSpace(stuffed.toString()));
|
||||
}
|
||||
|
||||
public static BitArray toBitArray(CharSequence bits) {
|
||||
BitArray in = new BitArray();
|
||||
char[] str = DOTX.matcher(bits).replaceAll("").toCharArray();
|
||||
for (char aStr : str) {
|
||||
in.appendBit(aStr == 'X');
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
public static boolean[] toBooleanArray(BitArray bitArray) {
|
||||
boolean[] result = new boolean[bitArray.getSize()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = bitArray.get(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void testHighLevelEncodeString(String s, String expectedBits) throws FormatException {
|
||||
BitArray bits = new HighLevelEncoder(s.getBytes(StandardCharsets.ISO_8859_1)).encode();
|
||||
String receivedBits = stripSpace(bits.toString());
|
||||
assertEquals("highLevelEncode() failed for input string: " + s, stripSpace(expectedBits), receivedBits);
|
||||
assertEquals(s, Decoder.highLevelDecode(toBooleanArray(bits)));
|
||||
}
|
||||
|
||||
private static void testHighLevelEncodeString(String s, int expectedReceivedBits) throws FormatException {
|
||||
BitArray bits = new HighLevelEncoder(s.getBytes(StandardCharsets.ISO_8859_1)).encode();
|
||||
int receivedBitCount = stripSpace(bits.toString()).length();
|
||||
assertEquals("highLevelEncode() failed for input string: " + s,
|
||||
expectedReceivedBits, receivedBitCount);
|
||||
assertEquals(s, Decoder.highLevelDecode(toBooleanArray(bits)));
|
||||
}
|
||||
|
||||
public static String stripSpace(String s) {
|
||||
return SPACES.matcher(s).replaceAll("");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright 2007 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.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link AddressBookParsedResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class AddressBookParsedResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testAddressBookDocomo() {
|
||||
doTest("MECARD:N:Sean Owen;;", null, new String[] {"Sean Owen"},
|
||||
null, null, null, null, null, null, null, null, null);
|
||||
doTest("MECARD:NOTE:ZXing Team;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;;",
|
||||
null, new String[] {"Sean Owen"}, null, null, new String[] {"srowen@example.org"}, null, null, null,
|
||||
new String[] {"google.com"}, null, "ZXing Team");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddressBookAU() {
|
||||
doTest("MEMORY:foo\r\nNAME1:Sean\r\nTEL1:+12125551212\r\n",
|
||||
null, new String[] {"Sean"}, null, null, null, new String[] {"+12125551212"}, null, null, null, null, "foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCard() {
|
||||
doTest("BEGIN:VCARD\r\nADR;HOME:123 Main St\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
|
||||
null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"},
|
||||
null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCardFullN() {
|
||||
doTest("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Owen;Sean;T;Mr.;Esq.\r\nEND:VCARD",
|
||||
null, new String[] {"Mr. Sean T Owen Esq."}, null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCardFullN2() {
|
||||
doTest("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Owen;Sean;;;\r\nEND:VCARD",
|
||||
null, new String[] {"Sean Owen"}, null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCardFullN3() {
|
||||
doTest("BEGIN:VCARD\r\nVERSION:2.1\r\nN:;Sean;;;\r\nEND:VCARD",
|
||||
null, new String[] {"Sean"}, null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCardCaseInsensitive() {
|
||||
doTest("begin:vcard\r\nadr;HOME:123 Main St\r\nVersion:2.1\r\nn:Owen;Sean\r\nEND:VCARD",
|
||||
null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"},
|
||||
null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEscapedVCard() {
|
||||
doTest("BEGIN:VCARD\r\nADR;HOME:123\\;\\\\ Main\\, St\\nHome\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
|
||||
null, new String[] {"Sean Owen"}, null, new String[] {"123;\\ Main, St\nHome"},
|
||||
null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBizcard() {
|
||||
doTest("BIZCARD:N:Sean;X:Owen;C:Google;A:123 Main St;M:+12125551212;E:srowen@example.org;",
|
||||
null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"}, new String[] {"srowen@example.org"},
|
||||
new String[] {"+12125551212"}, null, "Google", null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSeveralAddresses() {
|
||||
doTest("MECARD:N:Foo Bar;ORG:Company;TEL:5555555555;EMAIL:foo.bar@xyz.com;ADR:City, 10001;" +
|
||||
"ADR:City, 10001;NOTE:This is the memo.;;",
|
||||
null, new String[] {"Foo Bar"}, null, new String[] {"City, 10001", "City, 10001"},
|
||||
new String[] {"foo.bar@xyz.com"},
|
||||
new String[] {"5555555555" }, null, "Company", null, null, "This is the memo.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuotedPrintable() {
|
||||
doTest("BEGIN:VCARD\r\nADR;HOME;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;;" +
|
||||
"=38=38=20=4C=79=6E=62=72=6F=6F=6B=0D=0A=43=\r\n" +
|
||||
"=4F=20=36=39=39=\r\n" +
|
||||
"=39=39;;;\r\nEND:VCARD",
|
||||
null, null, null, new String[] {"88 Lynbrook\r\nCO 69999"},
|
||||
null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCardEscape() {
|
||||
doTest("BEGIN:VCARD\r\nNOTE:foo\\nbar\r\nEND:VCARD",
|
||||
null, null, null, null, null, null, null, null, null, null, "foo\nbar");
|
||||
doTest("BEGIN:VCARD\r\nNOTE:foo\\;bar\r\nEND:VCARD",
|
||||
null, null, null, null, null, null, null, null, null, null, "foo;bar");
|
||||
doTest("BEGIN:VCARD\r\nNOTE:foo\\\\bar\r\nEND:VCARD",
|
||||
null, null, null, null, null, null, null, null, null, null, "foo\\bar");
|
||||
doTest("BEGIN:VCARD\r\nNOTE:foo\\,bar\r\nEND:VCARD",
|
||||
null, null, null, null, null, null, null, null, null, null, "foo,bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCardValueURI() {
|
||||
doTest("BEGIN:VCARD\r\nTEL;VALUE=uri:tel:+1-555-555-1212\r\nEND:VCARD",
|
||||
null, null, null, null, null, new String[] { "+1-555-555-1212" }, new String[] { null },
|
||||
null, null, null, null);
|
||||
|
||||
doTest("BEGIN:VCARD\r\nN;VALUE=text:Owen;Sean\r\nEND:VCARD",
|
||||
null, new String[] {"Sean Owen"}, null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCardTypes() {
|
||||
doTest("BEGIN:VCARD\r\nTEL;HOME:\r\nTEL;WORK:10\r\nTEL:20\r\nTEL;CELL:30\r\nEND:VCARD",
|
||||
null, null, null, null, null, new String[] { "10", "20", "30" },
|
||||
new String[] { "WORK", null, "CELL" }, null, null, null, null);
|
||||
}
|
||||
|
||||
private static void doTest(String contents,
|
||||
String title,
|
||||
String[] names,
|
||||
String pronunciation,
|
||||
String[] addresses,
|
||||
String[] emails,
|
||||
String[] phoneNumbers,
|
||||
String[] phoneTypes,
|
||||
String org,
|
||||
String[] urls,
|
||||
String birthday,
|
||||
String note) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.ADDRESSBOOK, result.getType());
|
||||
AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
|
||||
assertEquals(title, addressResult.getTitle());
|
||||
assertArrayEquals(names, addressResult.getNames());
|
||||
assertEquals(pronunciation, addressResult.getPronunciation());
|
||||
assertArrayEquals(addresses, addressResult.getAddresses());
|
||||
assertArrayEquals(emails, addressResult.getEmails());
|
||||
assertArrayEquals(phoneNumbers, addressResult.getPhoneNumbers());
|
||||
assertArrayEquals(phoneTypes, addressResult.getPhoneTypes());
|
||||
assertEquals(org, addressResult.getOrg());
|
||||
assertArrayEquals(urls, addressResult.getURLs());
|
||||
assertEquals(birthday, addressResult.getBirthday());
|
||||
assertEquals(note, addressResult.getNote());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* Copyright 2007 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.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Tests {@link CalendarParsedResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class CalendarParsedResultTestCase extends Assert {
|
||||
|
||||
private static final double EPSILON = 1.0E-10;
|
||||
|
||||
private static DateFormat makeGMTFormat() {
|
||||
DateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH);
|
||||
format.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
return format;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Locale.setDefault(Locale.ENGLISH);
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartEnd() {
|
||||
doTest(
|
||||
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"DTEND:20080505T234555Z\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
null, null, null, "20080504T123456Z", "20080505T234555Z");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoVCalendar() {
|
||||
doTest(
|
||||
"BEGIN:VEVENT\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"DTEND:20080505T234555Z\r\n" +
|
||||
"END:VEVENT",
|
||||
null, null, null, "20080504T123456Z", "20080505T234555Z");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStart() {
|
||||
doTest(
|
||||
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
null, null, null, "20080504T123456Z", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuration() {
|
||||
doTest(
|
||||
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"DURATION:P1D\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
null, null, null, "20080504T123456Z", "20080505T123456Z");
|
||||
doTest(
|
||||
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"DURATION:P1DT2H3M4S\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
null, null, null, "20080504T123456Z", "20080505T143800Z");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummary() {
|
||||
doTest(
|
||||
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"SUMMARY:foo\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
null, "foo", null, "20080504T123456Z", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocation() {
|
||||
doTest(
|
||||
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"LOCATION:Miami\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
null, null, "Miami", "20080504T123456Z", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDescription() {
|
||||
doTest(
|
||||
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"DESCRIPTION:This is a test\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
"This is a test", null, null, "20080504T123456Z", null);
|
||||
doTest(
|
||||
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"DESCRIPTION:This is a test\r\n\t with a continuation\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
"This is a test with a continuation", null, null, "20080504T123456Z", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeo() {
|
||||
doTest(
|
||||
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"GEO:-12.345;-45.678\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
null, null, null, "20080504T123456Z", null, null, null, -12.345, -45.678);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadGeo() {
|
||||
// Not parsed as VEVENT
|
||||
Result fakeResult = new Result("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"GEO:-12.345\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR", null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.TEXT, result.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrganizer() {
|
||||
doTest(
|
||||
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"ORGANIZER:mailto:bob@example.org\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
null, null, null, "20080504T123456Z", null, "bob@example.org", null, Double.NaN, Double.NaN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttendees() {
|
||||
doTest(
|
||||
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"DTSTART:20080504T123456Z\r\n" +
|
||||
"ATTENDEE:mailto:bob@example.org\r\n" +
|
||||
"ATTENDEE:mailto:alice@example.org\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR",
|
||||
null, null, null, "20080504T123456Z", null, null,
|
||||
new String[] {"bob@example.org", "alice@example.org"}, Double.NaN, Double.NaN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVEventEscapes() {
|
||||
doTest("BEGIN:VEVENT\n" +
|
||||
"CREATED:20111109T110351Z\n" +
|
||||
"LAST-MODIFIED:20111109T170034Z\n" +
|
||||
"DTSTAMP:20111109T170034Z\n" +
|
||||
"UID:0f6d14ef-6cb7-4484-9080-61447ccdf9c2\n" +
|
||||
"SUMMARY:Summary line\n" +
|
||||
"CATEGORIES:Private\n" +
|
||||
"DTSTART;TZID=Europe/Vienna:20111110T110000\n" +
|
||||
"DTEND;TZID=Europe/Vienna:20111110T120000\n" +
|
||||
"LOCATION:Location\\, with\\, escaped\\, commas\n" +
|
||||
"DESCRIPTION:Meeting with a friend\\nlook at homepage first\\n\\n\n" +
|
||||
" \\n\n" +
|
||||
"SEQUENCE:1\n" +
|
||||
"X-MOZ-GENERATION:1\n" +
|
||||
"END:VEVENT",
|
||||
"Meeting with a friend\nlook at homepage first\n\n\n \n",
|
||||
"Summary line",
|
||||
"Location, with, escaped, commas",
|
||||
"20111110T110000Z",
|
||||
"20111110T120000Z");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllDayValueDate() {
|
||||
doTest("BEGIN:VEVENT\n" +
|
||||
"DTSTART;VALUE=DATE:20111110\n" +
|
||||
"DTEND;VALUE=DATE:20111110\n" +
|
||||
"END:VEVENT",
|
||||
null, null, null, "20111110T000000Z", "20111110T000000Z");
|
||||
}
|
||||
|
||||
private static void doTest(String contents,
|
||||
String description,
|
||||
String summary,
|
||||
String location,
|
||||
String startString,
|
||||
String endString) {
|
||||
doTest(contents, description, summary, location, startString, endString, null, null, Double.NaN, Double.NaN);
|
||||
}
|
||||
|
||||
private static void doTest(String contents,
|
||||
String description,
|
||||
String summary,
|
||||
String location,
|
||||
String startString,
|
||||
String endString,
|
||||
String organizer,
|
||||
String[] attendees,
|
||||
double latitude,
|
||||
double longitude) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.CALENDAR, result.getType());
|
||||
CalendarParsedResult calResult = (CalendarParsedResult) result;
|
||||
assertEquals(description, calResult.getDescription());
|
||||
assertEquals(summary, calResult.getSummary());
|
||||
assertEquals(location, calResult.getLocation());
|
||||
DateFormat dateFormat = makeGMTFormat();
|
||||
assertEquals(startString, dateFormat.format(calResult.getStartTimestamp()));
|
||||
assertEquals(endString, calResult.getEndTimestamp() < 0L ? null : dateFormat.format(calResult.getEndTimestamp()));
|
||||
assertEquals(organizer, calResult.getOrganizer());
|
||||
assertArrayEquals(attendees, calResult.getAttendees());
|
||||
assertEqualOrNaN(latitude, calResult.getLatitude());
|
||||
assertEqualOrNaN(longitude, calResult.getLongitude());
|
||||
}
|
||||
|
||||
private static void assertEqualOrNaN(double expected, double actual) {
|
||||
if (Double.isNaN(expected)) {
|
||||
assertTrue(Double.isNaN(actual));
|
||||
} else {
|
||||
assertEquals(expected, actual, EPSILON);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright 2007 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.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link EmailAddressParsedResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class EmailAddressParsedResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEmailAddress() {
|
||||
doTest("srowen@example.org", "srowen@example.org", null, null);
|
||||
doTest("mailto:srowen@example.org", "srowen@example.org", null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTos() {
|
||||
doTest("mailto:srowen@example.org,bob@example.org",
|
||||
new String[] {"srowen@example.org", "bob@example.org"},
|
||||
null, null, null, null);
|
||||
doTest("mailto:?to=srowen@example.org,bob@example.org",
|
||||
new String[] {"srowen@example.org", "bob@example.org"},
|
||||
null, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCCs() {
|
||||
doTest("mailto:?cc=srowen@example.org",
|
||||
null,
|
||||
new String[] {"srowen@example.org"},
|
||||
null, null, null);
|
||||
doTest("mailto:?cc=srowen@example.org,bob@example.org",
|
||||
null,
|
||||
new String[] {"srowen@example.org", "bob@example.org"},
|
||||
null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBCCs() {
|
||||
doTest("mailto:?bcc=srowen@example.org",
|
||||
null, null,
|
||||
new String[] {"srowen@example.org"},
|
||||
null, null);
|
||||
doTest("mailto:?bcc=srowen@example.org,bob@example.org",
|
||||
null, null,
|
||||
new String[] {"srowen@example.org", "bob@example.org"},
|
||||
null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAll() {
|
||||
doTest("mailto:bob@example.org?cc=foo@example.org&bcc=srowen@example.org&subject=baz&body=buzz",
|
||||
new String[] {"bob@example.org"},
|
||||
new String[] {"foo@example.org"},
|
||||
new String[] {"srowen@example.org"},
|
||||
"baz",
|
||||
"buzz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmailDocomo() {
|
||||
doTest("MATMSG:TO:srowen@example.org;;", "srowen@example.org", null, null);
|
||||
doTest("MATMSG:TO:srowen@example.org;SUB:Stuff;;", "srowen@example.org", "Stuff", null);
|
||||
doTest("MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", "srowen@example.org",
|
||||
"Stuff", "This is some text");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSMTP() {
|
||||
doTest("smtp:srowen@example.org", "srowen@example.org", null, null);
|
||||
doTest("SMTP:srowen@example.org", "srowen@example.org", null, null);
|
||||
doTest("smtp:srowen@example.org:foo", "srowen@example.org", "foo", null);
|
||||
doTest("smtp:srowen@example.org:foo:bar", "srowen@example.org", "foo", "bar");
|
||||
}
|
||||
|
||||
private static void doTest(String contents,
|
||||
String to,
|
||||
String subject,
|
||||
String body) {
|
||||
doTest(contents, new String[] {to}, null, null, subject, body);
|
||||
}
|
||||
|
||||
private static void doTest(String contents,
|
||||
String[] tos,
|
||||
String[] ccs,
|
||||
String[] bccs,
|
||||
String subject,
|
||||
String body) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.EMAIL_ADDRESS, result.getType());
|
||||
EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result;
|
||||
assertArrayEquals(tos, emailResult.getTos());
|
||||
assertArrayEquals(ccs, emailResult.getCCs());
|
||||
assertArrayEquals(bccs, emailResult.getBCCs());
|
||||
assertEquals(subject, emailResult.getSubject());
|
||||
assertEquals(body, emailResult.getBody());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Antonio Manuel Benjumea Conde, Servinform, S.A.
|
||||
* @author Agustín Delgado, Servinform, S.A.
|
||||
*/
|
||||
public final class ExpandedProductParsedResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testRSSExpanded() {
|
||||
Map<String,String> uncommonAIs = new HashMap<>();
|
||||
uncommonAIs.put("123", "544654");
|
||||
Result result =
|
||||
new Result("(01)66546(13)001205(3932)4455(3102)6544(123)544654", null, null, BarcodeFormat.RSS_EXPANDED);
|
||||
ExpandedProductParsedResult o = new ExpandedProductResultParser().parse(result);
|
||||
assertNotNull(o);
|
||||
assertEquals("66546", o.getProductID());
|
||||
assertNull(o.getSscc());
|
||||
assertNull(o.getLotNumber());
|
||||
assertNull(o.getProductionDate());
|
||||
assertEquals("001205", o.getPackagingDate());
|
||||
assertNull(o.getBestBeforeDate());
|
||||
assertNull(o.getExpirationDate());
|
||||
assertEquals("6544", o.getWeight());
|
||||
assertEquals("KG", o.getWeightType());
|
||||
assertEquals("2", o.getWeightIncrement());
|
||||
assertEquals("5", o.getPrice());
|
||||
assertEquals("2", o.getPriceIncrement());
|
||||
assertEquals("445", o.getPriceCurrency());
|
||||
assertEquals(uncommonAIs, o.getUncommonAIs());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2007 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.client.result;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link GeoParsedResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class GeoParsedResultTestCase extends Assert {
|
||||
|
||||
private static final double EPSILON = 1.0E-10;
|
||||
|
||||
@Test
|
||||
public void testGeo() {
|
||||
doTest("geo:1,2", 1.0, 2.0, 0.0, null, "geo:1.0,2.0");
|
||||
doTest("geo:80.33,-32.3344,3.35", 80.33, -32.3344, 3.35, null, null);
|
||||
doTest("geo:-20.33,132.3344,0.01", -20.33, 132.3344, 0.01, null, null);
|
||||
doTest("geo:-20.33,132.3344,0.01?q=foobar", -20.33, 132.3344, 0.01, "q=foobar", null);
|
||||
doTest("GEO:-20.33,132.3344,0.01?q=foobar", -20.33, 132.3344, 0.01, "q=foobar", null);
|
||||
}
|
||||
|
||||
private static void doTest(String contents,
|
||||
double latitude,
|
||||
double longitude,
|
||||
double altitude,
|
||||
String query,
|
||||
String uri) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.GEO, result.getType());
|
||||
GeoParsedResult geoResult = (GeoParsedResult) result;
|
||||
assertEquals(latitude, geoResult.getLatitude(), EPSILON);
|
||||
assertEquals(longitude, geoResult.getLongitude(), EPSILON);
|
||||
assertEquals(altitude, geoResult.getAltitude(), EPSILON);
|
||||
assertEquals(query, geoResult.getQuery());
|
||||
assertEquals(uri == null ? contents.toLowerCase(Locale.ENGLISH) : uri, geoResult.getGeoURI());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2007 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.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link ISBNParsedResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class ISBNParsedResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testISBN() {
|
||||
doTest("9784567890123");
|
||||
}
|
||||
|
||||
private static void doTest(String contents) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.EAN_13);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.ISBN, result.getType());
|
||||
ISBNParsedResult isbnResult = (ISBNParsedResult) result;
|
||||
assertEquals(contents, isbnResult.getISBN());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* Copyright 2007 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.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Tests {@link ParsedResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class ParsedReaderResultTestCase extends Assert {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Locale.setDefault(Locale.ENGLISH);
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextType() {
|
||||
doTestResult("", "", ParsedResultType.TEXT);
|
||||
doTestResult("foo", "foo", ParsedResultType.TEXT);
|
||||
doTestResult("Hi.", "Hi.", ParsedResultType.TEXT);
|
||||
doTestResult("This is a test", "This is a test", ParsedResultType.TEXT);
|
||||
doTestResult("This is a test\nwith newlines", "This is a test\nwith newlines",
|
||||
ParsedResultType.TEXT);
|
||||
doTestResult("This: a test with lots of @ nearly-random punctuation! No? OK then.",
|
||||
"This: a test with lots of @ nearly-random punctuation! No? OK then.",
|
||||
ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBookmarkType() {
|
||||
doTestResult("MEBKM:URL:google.com;;", "http://google.com", ParsedResultType.URI);
|
||||
doTestResult("MEBKM:URL:google.com;TITLE:Google;;", "Google\nhttp://google.com",
|
||||
ParsedResultType.URI);
|
||||
doTestResult("MEBKM:TITLE:Google;URL:google.com;;", "Google\nhttp://google.com",
|
||||
ParsedResultType.URI);
|
||||
doTestResult("MEBKM:URL:http://google.com;;", "http://google.com", ParsedResultType.URI);
|
||||
doTestResult("MEBKM:URL:HTTPS://google.com;;", "HTTPS://google.com", ParsedResultType.URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testURLTOType() {
|
||||
doTestResult("urlto:foo:bar.com", "foo\nhttp://bar.com", ParsedResultType.URI);
|
||||
doTestResult("URLTO:foo:bar.com", "foo\nhttp://bar.com", ParsedResultType.URI);
|
||||
doTestResult("URLTO::bar.com", "http://bar.com", ParsedResultType.URI);
|
||||
doTestResult("URLTO::http://bar.com", "http://bar.com", ParsedResultType.URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmailType() {
|
||||
doTestResult("MATMSG:TO:srowen@example.org;;",
|
||||
"srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;;", "srowen@example.org\nStuff",
|
||||
ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
|
||||
"srowen@example.org\nStuff\nThis is some text", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("MATMSG:SUB:Stuff;BODY:This is some text;TO:srowen@example.org;;",
|
||||
"srowen@example.org\nStuff\nThis is some text", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
|
||||
"TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmailAddressType() {
|
||||
doTestResult("srowen@example.org", "srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("mailto:srowen@example.org", "srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("MAILTO:srowen@example.org", "srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("srowen@example", "srowen@example", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("srowen", "srowen", ParsedResultType.TEXT);
|
||||
doTestResult("Let's meet @ 2", "Let's meet @ 2", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddressBookType() {
|
||||
doTestResult("MECARD:N:Sean Owen;;", "Sean Owen", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;;", "Sean Owen\n+12125551212",
|
||||
ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;;",
|
||||
"Sean Owen\n+12125551212\ngoogle.com", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\n+12125551212\nsrowen@example.org\ngoogle.com", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:ADR:76 9th Ave;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\n76 9th Ave\nsrowen@example.org\ngoogle.com", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:BDAY:19760520;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\nsrowen@example.org\ngoogle.com\n19760520", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:ORG:Google;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\nGoogle\nsrowen@example.org\ngoogle.com", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:NOTE:ZXing Team;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\nsrowen@example.org\ngoogle.com\nZXing Team", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("N:Sean Owen;TEL:+12125551212;;", "N:Sean Owen;TEL:+12125551212;;",
|
||||
ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddressBookAUType() {
|
||||
doTestResult("MEMORY:\r\n", "", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MEMORY:foo\r\nNAME1:Sean\r\n", "Sean\nfoo", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("TEL1:+12125551212\r\nMEMORY:\r\n", "+12125551212", ParsedResultType.ADDRESSBOOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBizcard() {
|
||||
doTestResult("BIZCARD:N:Sean;X:Owen;C:Google;A:123 Main St;M:+12225551212;E:srowen@example.org;",
|
||||
"Sean Owen\nGoogle\n123 Main St\n+12225551212\nsrowen@example.org", ParsedResultType.ADDRESSBOOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUPCA() {
|
||||
doTestResult("123456789012", "123456789012", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
|
||||
doTestResult("1234567890123", "1234567890123", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
|
||||
doTestResult("12345678901", "12345678901", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUPCE() {
|
||||
doTestResult("01234565", "01234565", ParsedResultType.PRODUCT, BarcodeFormat.UPC_E);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEAN() {
|
||||
doTestResult("00393157", "00393157", ParsedResultType.PRODUCT, BarcodeFormat.EAN_8);
|
||||
doTestResult("00393158", "00393158", ParsedResultType.TEXT);
|
||||
doTestResult("5051140178499", "5051140178499", ParsedResultType.PRODUCT, BarcodeFormat.EAN_13);
|
||||
doTestResult("5051140178490", "5051140178490", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testISBN() {
|
||||
doTestResult("9784567890123", "9784567890123", ParsedResultType.ISBN, BarcodeFormat.EAN_13);
|
||||
doTestResult("9794567890123", "9794567890123", ParsedResultType.ISBN, BarcodeFormat.EAN_13);
|
||||
doTestResult("97845678901", "97845678901", ParsedResultType.TEXT);
|
||||
doTestResult("97945678901", "97945678901", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testURI() {
|
||||
doTestResult("http://google.com", "http://google.com", ParsedResultType.URI);
|
||||
doTestResult("google.com", "http://google.com", ParsedResultType.URI);
|
||||
doTestResult("https://google.com", "https://google.com", ParsedResultType.URI);
|
||||
doTestResult("HTTP://google.com", "HTTP://google.com", ParsedResultType.URI);
|
||||
doTestResult("http://google.com/foobar", "http://google.com/foobar", ParsedResultType.URI);
|
||||
doTestResult("https://google.com:443/foobar", "https://google.com:443/foobar", ParsedResultType.URI);
|
||||
doTestResult("google.com:443", "http://google.com:443", ParsedResultType.URI);
|
||||
doTestResult("google.com:443/", "http://google.com:443/", ParsedResultType.URI);
|
||||
doTestResult("google.com:443/foobar", "http://google.com:443/foobar", ParsedResultType.URI);
|
||||
doTestResult("http://google.com:443/foobar", "http://google.com:443/foobar", ParsedResultType.URI);
|
||||
doTestResult("https://google.com:443/foobar", "https://google.com:443/foobar", ParsedResultType.URI);
|
||||
doTestResult("ftp://google.com/fake", "ftp://google.com/fake", ParsedResultType.URI);
|
||||
doTestResult("gopher://google.com/obsolete", "gopher://google.com/obsolete", ParsedResultType.URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeo() {
|
||||
doTestResult("geo:1,2", "1.0, 2.0", ParsedResultType.GEO);
|
||||
doTestResult("GEO:1,2", "1.0, 2.0", ParsedResultType.GEO);
|
||||
doTestResult("geo:1,2,3", "1.0, 2.0, 3.0m", ParsedResultType.GEO);
|
||||
doTestResult("geo:80.33,-32.3344,3.35", "80.33, -32.3344, 3.35m", ParsedResultType.GEO);
|
||||
doTestResult("geo", "geo", ParsedResultType.TEXT);
|
||||
doTestResult("geography", "geography", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTel() {
|
||||
doTestResult("tel:+15551212", "+15551212", ParsedResultType.TEL);
|
||||
doTestResult("TEL:+15551212", "+15551212", ParsedResultType.TEL);
|
||||
doTestResult("tel:212 555 1212", "212 555 1212", ParsedResultType.TEL);
|
||||
doTestResult("tel:2125551212", "2125551212", ParsedResultType.TEL);
|
||||
doTestResult("tel:212-555-1212", "212-555-1212", ParsedResultType.TEL);
|
||||
doTestResult("tel", "tel", ParsedResultType.TEXT);
|
||||
doTestResult("telephone", "telephone", ParsedResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCard() {
|
||||
doTestResult("BEGIN:VCARD\r\nEND:VCARD", "", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("BEGIN:VCARD\r\nN:Owen;Sean\r\nEND:VCARD", "Sean Owen",
|
||||
ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD", "Sean Owen",
|
||||
ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("BEGIN:VCARD\r\nADR;HOME:123 Main St\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
|
||||
"Sean Owen\n123 Main St", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("BEGIN:VCARD", "", ParsedResultType.ADDRESSBOOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVEvent() {
|
||||
// UTC times
|
||||
doTestResult("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
|
||||
"DTEND:20080505T234555Z\r\nEND:VEVENT\r\nEND:VCALENDAR",
|
||||
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56) + "\n" + formatTime(2008, 5, 5, 23, 45, 55),
|
||||
ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
|
||||
"DTEND:20080505T234555Z\r\nEND:VEVENT", "foo\n" + formatTime(2008, 5, 4, 12, 34, 56) + "\n" +
|
||||
formatTime(2008, 5, 5, 23, 45, 55),
|
||||
ParsedResultType.CALENDAR);
|
||||
// Local times
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\n" +
|
||||
"DTEND:20080505T234555\r\nEND:VEVENT", "foo\n" + formatTime(2008, 5, 4, 12, 34, 56) + "\n" +
|
||||
formatTime(2008, 5, 5, 23, 45, 55),
|
||||
ParsedResultType.CALENDAR);
|
||||
// Date only (all day event)
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\n" +
|
||||
"DTEND:20080505\r\nEND:VEVENT", "foo\n" + formatDate(2008, 5, 4) + "\n" +
|
||||
formatDate(2008, 5, 5),
|
||||
ParsedResultType.CALENDAR);
|
||||
// Start time only
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\nEND:VEVENT",
|
||||
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56), ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\nEND:VEVENT",
|
||||
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56), ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\nEND:VEVENT",
|
||||
"foo\n" + formatDate(2008, 5, 4), ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT",
|
||||
"BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT", ParsedResultType.TEXT);
|
||||
// Yeah, it's OK that this is thought of as maybe a URI as long as it's not CALENDAR
|
||||
// Make sure illegal entries without newlines don't crash
|
||||
doTestResult(
|
||||
"BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
|
||||
"BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
|
||||
ParsedResultType.URI);
|
||||
}
|
||||
|
||||
private static String formatDate(int year, int month, int day) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.clear();
|
||||
cal.set(year, month - 1, day);
|
||||
return DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).format(cal.getTime());
|
||||
}
|
||||
|
||||
private static String formatTime(int year, int month, int day, int hour, int min, int sec) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.clear();
|
||||
cal.set(year, month - 1, day, hour, min, sec);
|
||||
return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US).format(cal.getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSMS() {
|
||||
doTestResult("sms:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("SMS:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("sms:+15551212;via=999333", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("sms:+15551212?subject=foo&body=bar", "+15551212\nfoo\nbar", ParsedResultType.SMS);
|
||||
doTestResult("sms:+15551212,+12124440101", "+15551212\n+12124440101", ParsedResultType.SMS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSMSTO() {
|
||||
doTestResult("SMSTO:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("smsto:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("smsto:+15551212:subject", "+15551212\nsubject", ParsedResultType.SMS);
|
||||
doTestResult("smsto:+15551212:My message", "+15551212\nMy message", ParsedResultType.SMS);
|
||||
// Need to handle question mark in the subject
|
||||
doTestResult("smsto:+15551212:What's up?", "+15551212\nWhat's up?", ParsedResultType.SMS);
|
||||
// Need to handle colon in the subject
|
||||
doTestResult("smsto:+15551212:Directions: Do this", "+15551212\nDirections: Do this",
|
||||
ParsedResultType.SMS);
|
||||
doTestResult("smsto:212-555-1212:Here's a longer message. Should be fine.",
|
||||
"212-555-1212\nHere's a longer message. Should be fine.",
|
||||
ParsedResultType.SMS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMMS() {
|
||||
doTestResult("mms:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("MMS:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("mms:+15551212;via=999333", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("mms:+15551212?subject=foo&body=bar", "+15551212\nfoo\nbar", ParsedResultType.SMS);
|
||||
doTestResult("mms:+15551212,+12124440101", "+15551212\n+12124440101", ParsedResultType.SMS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMMSTO() {
|
||||
doTestResult("MMSTO:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212:subject", "+15551212\nsubject", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212:My message", "+15551212\nMy message", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212:What's up?", "+15551212\nWhat's up?", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212:Directions: Do this", "+15551212\nDirections: Do this",
|
||||
ParsedResultType.SMS);
|
||||
doTestResult("mmsto:212-555-1212:Here's a longer message. Should be fine.",
|
||||
"212-555-1212\nHere's a longer message. Should be fine.", ParsedResultType.SMS);
|
||||
}
|
||||
|
||||
private static void doTestResult(String contents,
|
||||
String goldenResult,
|
||||
ParsedResultType type) {
|
||||
doTestResult(contents, goldenResult, type, BarcodeFormat.QR_CODE); // QR code is arbitrary
|
||||
}
|
||||
|
||||
private static void doTestResult(String contents,
|
||||
String goldenResult,
|
||||
ParsedResultType type,
|
||||
BarcodeFormat format) {
|
||||
Result fakeResult = new Result(contents, null, null, format);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertNotNull(result);
|
||||
assertSame(type, result.getType());
|
||||
|
||||
String displayResult = result.getDisplayResult();
|
||||
assertEquals(goldenResult, displayResult);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2007 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.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link ProductParsedResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class ProductParsedResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testProduct() {
|
||||
doTest("123456789012", "123456789012", BarcodeFormat.UPC_A);
|
||||
doTest("00393157", "00393157", BarcodeFormat.EAN_8);
|
||||
doTest("5051140178499", "5051140178499", BarcodeFormat.EAN_13);
|
||||
doTest("01234565", "012345000065", BarcodeFormat.UPC_E);
|
||||
}
|
||||
|
||||
private static void doTest(String contents, String normalized, BarcodeFormat format) {
|
||||
Result fakeResult = new Result(contents, null, null, format);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.PRODUCT, result.getType());
|
||||
ProductParsedResult productResult = (ProductParsedResult) result;
|
||||
assertEquals(contents, productResult.getProductID());
|
||||
assertEquals(normalized, productResult.getNormalizedProductID());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2007 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.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link SMSParsedResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class SMSMMSParsedResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testSMS() {
|
||||
doTest("sms:+15551212", "+15551212", null, null, null, "sms:+15551212");
|
||||
doTest("sms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null,
|
||||
"sms:+15551212?body=bar&subject=foo");
|
||||
doTest("sms:+15551212;via=999333", "+15551212", null, null, "999333",
|
||||
"sms:+15551212;via=999333");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMMS() {
|
||||
doTest("mms:+15551212", "+15551212", null, null, null, "sms:+15551212");
|
||||
doTest("mms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null,
|
||||
"sms:+15551212?body=bar&subject=foo");
|
||||
doTest("mms:+15551212;via=999333", "+15551212", null, null, "999333",
|
||||
"sms:+15551212;via=999333");
|
||||
}
|
||||
|
||||
private static void doTest(String contents,
|
||||
String number,
|
||||
String subject,
|
||||
String body,
|
||||
String via,
|
||||
String parsedURI) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.SMS, result.getType());
|
||||
SMSParsedResult smsResult = (SMSParsedResult) result;
|
||||
assertArrayEquals(new String[] { number }, smsResult.getNumbers());
|
||||
assertEquals(subject, smsResult.getSubject());
|
||||
assertEquals(body, smsResult.getBody());
|
||||
assertArrayEquals(new String[] { via }, smsResult.getVias());
|
||||
assertEquals(parsedURI, smsResult.getSMSURI());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2007 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.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link TelParsedResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class TelParsedResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testTel() {
|
||||
doTest("tel:+15551212", "+15551212", null);
|
||||
doTest("tel:2125551212", "2125551212", null);
|
||||
}
|
||||
|
||||
private static void doTest(String contents, String number, String title) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.TEL, result.getType());
|
||||
TelParsedResult telResult = (TelParsedResult) result;
|
||||
assertEquals(number, telResult.getNumber());
|
||||
assertEquals(title, telResult.getTitle());
|
||||
assertEquals("tel:" + number, telResult.getTelURI());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright 2007 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.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link URIParsedResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class URIParsedResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testBookmarkDocomo() {
|
||||
doTest("MEBKM:URL:google.com;;", "http://google.com", null);
|
||||
doTest("MEBKM:URL:http://google.com;;", "http://google.com", null);
|
||||
doTest("MEBKM:URL:google.com;TITLE:Google;", "http://google.com", "Google");
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:lineLength")
|
||||
@Test
|
||||
public void testURI() {
|
||||
doTest("google.com", "http://google.com", null);
|
||||
doTest("123.com", "http://123.com", null);
|
||||
doTest("http://google.com", "http://google.com", null);
|
||||
doTest("https://google.com", "https://google.com", null);
|
||||
doTest("google.com:443", "http://google.com:443", null);
|
||||
doTest("https://www.google.com/calendar/hosted/google.com/embed?mode=AGENDA&force_login=true&src=google.com_726f6f6d5f6265707075@resource.calendar.google.com",
|
||||
"https://www.google.com/calendar/hosted/google.com/embed?mode=AGENDA&force_login=true&src=google.com_726f6f6d5f6265707075@resource.calendar.google.com",
|
||||
null);
|
||||
doTest("otpauth://remoteaccess?devaddr=00%a1b2%c3d4&devname=foo&key=bar",
|
||||
"otpauth://remoteaccess?devaddr=00%a1b2%c3d4&devname=foo&key=bar",
|
||||
null);
|
||||
doTest("s3://amazon.com:8123", "s3://amazon.com:8123", null);
|
||||
doTest("HTTP://R.BEETAGG.COM/?12345", "HTTP://R.BEETAGG.COM/?12345", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotURI() {
|
||||
doTestNotUri("google.c");
|
||||
doTestNotUri(".com");
|
||||
doTestNotUri(":80/");
|
||||
doTestNotUri("ABC,20.3,AB,AD");
|
||||
doTestNotUri("http://google.com?q=foo bar");
|
||||
doTestNotUri("12756.501");
|
||||
doTestNotUri("google.50");
|
||||
doTestNotUri("foo.bar.bing.baz.foo.bar.bing.baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testURLTO() {
|
||||
doTest("urlto::bar.com", "http://bar.com", null);
|
||||
doTest("urlto::http://bar.com", "http://bar.com", null);
|
||||
doTest("urlto:foo:bar.com", "http://bar.com", "foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGarbage() {
|
||||
doTestNotUri("Da65cV1g^>%^f0bAbPn1CJB6lV7ZY8hs0Sm:DXU0cd]GyEeWBz8]bUHLB");
|
||||
doTestNotUri("DEA\u0003\u0019M\u0006\u0000\bå\u0000‡HO\u0000X$\u0001\u0000\u001Fwfc\u0007!þ“˜" +
|
||||
"\u0013\u0013¾Z{ùÎÝڗZ§¨+y_zbñk\u00117¸\u000E†Ü\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000£.ux");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsPossiblyMalicious() {
|
||||
doTestIsPossiblyMalicious("http://google.com", false);
|
||||
doTestIsPossiblyMalicious("http://google.com@evil.com", true);
|
||||
doTestIsPossiblyMalicious("http://google.com:@evil.com", true);
|
||||
doTestIsPossiblyMalicious("google.com:@evil.com", false);
|
||||
doTestIsPossiblyMalicious("https://google.com:443", false);
|
||||
doTestIsPossiblyMalicious("https://google.com:443/", false);
|
||||
doTestIsPossiblyMalicious("https://evil@google.com:443", true);
|
||||
doTestIsPossiblyMalicious("http://google.com/foo@bar", false);
|
||||
doTestIsPossiblyMalicious("http://google.com/@@", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaliciousUnicode() {
|
||||
doTestIsPossiblyMalicious("https://google.com\u2215.evil.com/stuff", true);
|
||||
doTestIsPossiblyMalicious("\u202ehttps://dylankatz.com/moc.elgoog.www//:sptth", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExotic() {
|
||||
doTest("bitcoin:mySD89iqpmptrK3PhHFW9fa7BXiP7ANy3Y", "bitcoin:mySD89iqpmptrK3PhHFW9fa7BXiP7ANy3Y", null);
|
||||
doTest("BTCTX:-TC4TO3$ZYZTC5NC83/SYOV+YGUGK:$BSF0P8/STNTKTKS.V84+JSA$LB+EHCG+8A725.2AZ-NAVX3VBV5K4MH7UL2.2M:" +
|
||||
"F*M9HSL*$2P7T*FX.ZT80GWDRV0QZBPQ+O37WDCNZBRM3EQ0S9SZP+3BPYZG02U/LA*89C2U.V1TS.CT1VF3DIN*HN3W-O-" +
|
||||
"0ZAKOAB32/.8:J501GJJTTWOA+5/6$MIYBERPZ41NJ6-WSG/*Z48ZH*LSAOEM*IXP81L:$F*W08Z60CR*C*P.JEEVI1F02J07L6+" +
|
||||
"W4L1G$/IC*$16GK6A+:I1-:LJ:Z-P3NW6Z6ADFB-F2AKE$2DWN23GYCYEWX9S8L+LF$VXEKH7/R48E32PU+A:9H:8O5",
|
||||
"BTCTX:-TC4TO3$ZYZTC5NC83/SYOV+YGUGK:$BSF0P8/STNTKTKS.V84+JSA$LB+EHCG+8A725.2AZ-NAVX3VBV5K4MH7UL2.2M:" +
|
||||
"F*M9HSL*$2P7T*FX.ZT80GWDRV0QZBPQ+O37WDCNZBRM3EQ0S9SZP+3BPYZG02U/LA*89C2U.V1TS.CT1VF3DIN*HN3W-O-" +
|
||||
"0ZAKOAB32/.8:J501GJJTTWOA+5/6$MIYBERPZ41NJ6-WSG/*Z48ZH*LSAOEM*IXP81L:$F*W08Z60CR*C*P.JEEVI1F02J07L6+" +
|
||||
"W4L1G$/IC*$16GK6A+:I1-:LJ:Z-P3NW6Z6ADFB-F2AKE$2DWN23GYCYEWX9S8L+LF$VXEKH7/R48E32PU+A:9H:8O5",
|
||||
null);
|
||||
doTest("opc.tcp://test.samplehost.com:4841", "opc.tcp://test.samplehost.com:4841", null);
|
||||
}
|
||||
|
||||
private static void doTest(String contents, String uri, String title) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.URI, result.getType());
|
||||
URIParsedResult uriResult = (URIParsedResult) result;
|
||||
assertEquals(uri, uriResult.getURI());
|
||||
assertEquals(title, uriResult.getTitle());
|
||||
}
|
||||
|
||||
private static void doTestNotUri(String text) {
|
||||
Result fakeResult = new Result(text, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.TEXT, result.getType());
|
||||
assertEquals(text, result.getDisplayResult());
|
||||
}
|
||||
|
||||
private static void doTestIsPossiblyMalicious(String uri, boolean malicious) {
|
||||
Result fakeResult = new Result(uri, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(malicious ? ParsedResultType.TEXT : ParsedResultType.URI, result.getType());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link VINParsedResult}.
|
||||
*/
|
||||
public final class VINParsedResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testNotVIN() {
|
||||
Result fakeResult = new Result("1M8GDM9A1KP042788", null, null, BarcodeFormat.CODE_39);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertEquals(ParsedResultType.TEXT, result.getType());
|
||||
fakeResult = new Result("1M8GDM9AXKP042788", null, null, BarcodeFormat.CODE_128);
|
||||
result = ResultParser.parseResult(fakeResult);
|
||||
assertEquals(ParsedResultType.TEXT, result.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVIN() {
|
||||
doTest("1M8GDM9AXKP042788", "1M8", "GDM9AX", "KP042788", "US", "GDM9A", 1989, 'P', "042788");
|
||||
doTest("I1M8GDM9AXKP042788", "1M8", "GDM9AX", "KP042788", "US", "GDM9A", 1989, 'P', "042788");
|
||||
doTest("LJCPCBLCX11000237", "LJC", "PCBLCX", "11000237", "CN", "PCBLC", 2001, '1', "000237");
|
||||
}
|
||||
|
||||
private static void doTest(String contents,
|
||||
String wmi,
|
||||
String vds,
|
||||
String vis,
|
||||
String country,
|
||||
String attributes,
|
||||
int year,
|
||||
char plant,
|
||||
String sequential) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.CODE_39);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.VIN, result.getType());
|
||||
VINParsedResult vinResult = (VINParsedResult) result;
|
||||
assertEquals(wmi, vinResult.getWorldManufacturerID());
|
||||
assertEquals(vds, vinResult.getVehicleDescriptorSection());
|
||||
assertEquals(vis, vinResult.getVehicleIdentifierSection());
|
||||
assertEquals(country, vinResult.getCountryCode());
|
||||
assertEquals(attributes, vinResult.getVehicleAttributes());
|
||||
assertEquals(year, vinResult.getModelYear());
|
||||
assertEquals(plant, vinResult.getPlantCode());
|
||||
assertEquals(sequential, vinResult.getSequentialNumber());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2007 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.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link WifiParsedResult}.
|
||||
*
|
||||
* @author Vikram Aggarwal
|
||||
*/
|
||||
public final class WifiParsedResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testNoPassword() {
|
||||
doTest("WIFI:S:NoPassword;P:;T:;;", "NoPassword", null, "nopass");
|
||||
doTest("WIFI:S:No Password;P:;T:;;", "No Password", null, "nopass");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWep() {
|
||||
doTest("WIFI:S:TenChars;P:0123456789;T:WEP;;", "TenChars", "0123456789", "WEP");
|
||||
doTest("WIFI:S:TenChars;P:abcde56789;T:WEP;;", "TenChars", "abcde56789", "WEP");
|
||||
// Non hex should not fail at this level
|
||||
doTest("WIFI:S:TenChars;P:hellothere;T:WEP;;", "TenChars", "hellothere", "WEP");
|
||||
|
||||
// Escaped semicolons
|
||||
doTest("WIFI:S:Ten\\;\\;Chars;P:0123456789;T:WEP;;", "Ten;;Chars", "0123456789", "WEP");
|
||||
// Escaped colons
|
||||
doTest("WIFI:S:Ten\\:\\:Chars;P:0123456789;T:WEP;;", "Ten::Chars", "0123456789", "WEP");
|
||||
|
||||
// TODO(vikrama) Need a test for SB as well.
|
||||
}
|
||||
|
||||
/**
|
||||
* Put in checks for the length of the password for wep.
|
||||
*/
|
||||
@Test
|
||||
public void testWpa() {
|
||||
doTest("WIFI:S:TenChars;P:wow;T:WPA;;", "TenChars", "wow", "WPA");
|
||||
doTest("WIFI:S:TenChars;P:space is silent;T:WPA;;", "TenChars", "space is silent", "WPA");
|
||||
doTest("WIFI:S:TenChars;P:hellothere;T:WEP;;", "TenChars", "hellothere", "WEP");
|
||||
|
||||
// Escaped semicolons
|
||||
doTest("WIFI:S:TenChars;P:hello\\;there;T:WEP;;", "TenChars", "hello;there", "WEP");
|
||||
// Escaped colons
|
||||
doTest("WIFI:S:TenChars;P:hello\\:there;T:WEP;;", "TenChars", "hello:there", "WEP");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEscape() {
|
||||
doTest("WIFI:T:WPA;S:test;P:my_password\\\\;;", "test", "my_password\\", "WPA");
|
||||
doTest("WIFI:T:WPA;S:My_WiFi_SSID;P:abc123/;;", "My_WiFi_SSID", "abc123/", "WPA");
|
||||
doTest("WIFI:T:WPA;S:\"foo\\;bar\\\\baz\";;", "\"foo;bar\\baz\"", null, "WPA");
|
||||
doTest("WIFI:T:WPA;S:test;P:\\\"abcd\\\";;", "test", "\"abcd\"", "WPA");
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the string contents for the barcode, check that it matches our expectations
|
||||
*/
|
||||
private static void doTest(String contents,
|
||||
String ssid,
|
||||
String password,
|
||||
String type) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
|
||||
// Ensure it is a wifi code
|
||||
assertSame(ParsedResultType.WIFI, result.getType());
|
||||
WifiParsedResult wifiResult = (WifiParsedResult) result;
|
||||
|
||||
assertEquals(ssid, wifiResult.getSsid());
|
||||
assertEquals(password, wifiResult.getPassword());
|
||||
assertEquals(type, wifiResult.getNetworkEncryption());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.common;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.LuminanceSource;
|
||||
import com.google.zxing.Reader;
|
||||
import com.google.zxing.ReaderException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultMetadataType;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.RectangularShape;
|
||||
import java.awt.image.AffineTransformOp;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.BufferedImageOp;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||
|
||||
private static final Logger log = Logger.getLogger(AbstractBlackBoxTestCase.class.getSimpleName());
|
||||
|
||||
private final Path testBase;
|
||||
private final Reader barcodeReader;
|
||||
private final BarcodeFormat expectedFormat;
|
||||
private final List<TestResult> testResults;
|
||||
private final EnumMap<DecodeHintType,Object> hints = new EnumMap<>(DecodeHintType.class);
|
||||
|
||||
public static Path buildTestBase(String testBasePathSuffix) {
|
||||
// A little workaround to prevent aggravation in my IDE
|
||||
Path testBase = Paths.get(testBasePathSuffix);
|
||||
if (!Files.exists(testBase)) {
|
||||
// try starting with 'core' since the test base is often given as the project root
|
||||
testBase = Paths.get("core").resolve(testBasePathSuffix);
|
||||
}
|
||||
return testBase;
|
||||
}
|
||||
|
||||
protected AbstractBlackBoxTestCase(String testBasePathSuffix,
|
||||
Reader barcodeReader,
|
||||
BarcodeFormat expectedFormat) {
|
||||
this.testBase = buildTestBase(testBasePathSuffix);
|
||||
this.barcodeReader = barcodeReader;
|
||||
this.expectedFormat = expectedFormat;
|
||||
testResults = new ArrayList<>();
|
||||
|
||||
System.setProperty("java.util.logging.SimpleFormatter.format", "%4$s: %5$s%6$s%n");
|
||||
}
|
||||
|
||||
protected final Path getTestBase() {
|
||||
return testBase;
|
||||
}
|
||||
|
||||
protected final void addTest(int mustPassCount, int tryHarderCount, float rotation) {
|
||||
addTest(mustPassCount, tryHarderCount, 0, 0, rotation);
|
||||
}
|
||||
|
||||
protected void addHint(DecodeHintType hint) {
|
||||
hints.put(hint, Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new test for the current directory of images.
|
||||
*
|
||||
* @param mustPassCount The number of images which must decode for the test to pass.
|
||||
* @param tryHarderCount The number of images which must pass using the try harder flag.
|
||||
* @param maxMisreads Maximum number of images which can fail due to successfully reading the wrong contents
|
||||
* @param maxTryHarderMisreads Maximum number of images which can fail due to successfully
|
||||
* reading the wrong contents using the try harder flag
|
||||
* @param rotation The rotation in degrees clockwise to use for this test.
|
||||
*/
|
||||
protected final void addTest(int mustPassCount,
|
||||
int tryHarderCount,
|
||||
int maxMisreads,
|
||||
int maxTryHarderMisreads,
|
||||
float rotation) {
|
||||
testResults.add(new TestResult(mustPassCount, tryHarderCount, maxMisreads, maxTryHarderMisreads, rotation));
|
||||
}
|
||||
|
||||
protected final List<Path> getImageFiles() throws IOException {
|
||||
assertTrue("Please download and install test images, and run from the 'core' directory", Files.exists(testBase));
|
||||
List<Path> paths = new ArrayList<>();
|
||||
try (DirectoryStream<Path> pathIt = Files.newDirectoryStream(testBase, "*.{jpg,jpeg,gif,png,JPG,JPEG,GIF,PNG}")) {
|
||||
for (Path path : pathIt) {
|
||||
paths.add(path);
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
final Reader getReader() {
|
||||
return barcodeReader;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlackBox() throws IOException {
|
||||
assertFalse(testResults.isEmpty());
|
||||
|
||||
List<Path> imageFiles = getImageFiles();
|
||||
int testCount = testResults.size();
|
||||
|
||||
int[] passedCounts = new int[testCount];
|
||||
int[] misreadCounts = new int[testCount];
|
||||
int[] tryHarderCounts = new int[testCount];
|
||||
int[] tryHarderMisreadCounts = new int[testCount];
|
||||
|
||||
for (Path testImage : imageFiles) {
|
||||
log.info(String.format("Starting %s", testImage));
|
||||
|
||||
BufferedImage image = ImageIO.read(testImage.toFile());
|
||||
|
||||
String testImageFileName = testImage.getFileName().toString();
|
||||
String fileBaseName = testImageFileName.substring(0, testImageFileName.indexOf('.'));
|
||||
Path expectedTextFile = testBase.resolve(fileBaseName + ".txt");
|
||||
String expectedText;
|
||||
if (Files.exists(expectedTextFile)) {
|
||||
expectedText = readFileAsString(expectedTextFile, StandardCharsets.UTF_8);
|
||||
} else {
|
||||
expectedTextFile = testBase.resolve(fileBaseName + ".bin");
|
||||
assertTrue(Files.exists(expectedTextFile));
|
||||
expectedText = readFileAsString(expectedTextFile, StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
Path expectedMetadataFile = testBase.resolve(fileBaseName + ".metadata.txt");
|
||||
Properties expectedMetadata = new Properties();
|
||||
if (Files.exists(expectedMetadataFile)) {
|
||||
try (BufferedReader reader = Files.newBufferedReader(expectedMetadataFile, StandardCharsets.UTF_8)) {
|
||||
expectedMetadata.load(reader);
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < testCount; x++) {
|
||||
float rotation = testResults.get(x).getRotation();
|
||||
BufferedImage rotatedImage = rotateImage(image, rotation);
|
||||
LuminanceSource source = new BufferedImageLuminanceSource(rotatedImage);
|
||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||
try {
|
||||
if (decode(bitmap, rotation, expectedText, expectedMetadata, false)) {
|
||||
passedCounts[x]++;
|
||||
} else {
|
||||
misreadCounts[x]++;
|
||||
}
|
||||
} catch (ReaderException ignored) {
|
||||
log.fine(String.format("could not read at rotation %f", rotation));
|
||||
}
|
||||
try {
|
||||
if (decode(bitmap, rotation, expectedText, expectedMetadata, true)) {
|
||||
tryHarderCounts[x]++;
|
||||
} else {
|
||||
tryHarderMisreadCounts[x]++;
|
||||
}
|
||||
} catch (ReaderException ignored) {
|
||||
log.fine(String.format("could not read at rotation %f w/TH", rotation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Print the results of all tests first
|
||||
int totalFound = 0;
|
||||
int totalMustPass = 0;
|
||||
int totalMisread = 0;
|
||||
int totalMaxMisread = 0;
|
||||
|
||||
for (int x = 0; x < testResults.size(); x++) {
|
||||
TestResult testResult = testResults.get(x);
|
||||
log.info(String.format("Rotation %d degrees:", (int) testResult.getRotation()));
|
||||
log.info(String.format(" %d of %d images passed (%d required)",
|
||||
passedCounts[x], imageFiles.size(), testResult.getMustPassCount()));
|
||||
int failed = imageFiles.size() - passedCounts[x];
|
||||
log.info(String.format(" %d failed due to misreads, %d not detected",
|
||||
misreadCounts[x], failed - misreadCounts[x]));
|
||||
log.info(String.format(" %d of %d images passed with try harder (%d required)",
|
||||
tryHarderCounts[x], imageFiles.size(), testResult.getTryHarderCount()));
|
||||
failed = imageFiles.size() - tryHarderCounts[x];
|
||||
log.info(String.format(" %d failed due to misreads, %d not detected",
|
||||
tryHarderMisreadCounts[x], failed - tryHarderMisreadCounts[x]));
|
||||
totalFound += passedCounts[x] + tryHarderCounts[x];
|
||||
totalMustPass += testResult.getMustPassCount() + testResult.getTryHarderCount();
|
||||
totalMisread += misreadCounts[x] + tryHarderMisreadCounts[x];
|
||||
totalMaxMisread += testResult.getMaxMisreads() + testResult.getMaxTryHarderMisreads();
|
||||
}
|
||||
|
||||
int totalTests = imageFiles.size() * testCount * 2;
|
||||
log.info(String.format("Decoded %d images out of %d (%d%%, %d required)",
|
||||
totalFound, totalTests, totalFound * 100 / totalTests, totalMustPass));
|
||||
if (totalFound > totalMustPass) {
|
||||
log.warning(String.format("+++ Test too lax by %d images", totalFound - totalMustPass));
|
||||
} else if (totalFound < totalMustPass) {
|
||||
log.warning(String.format("--- Test failed by %d images", totalMustPass - totalFound));
|
||||
}
|
||||
|
||||
if (totalMisread < totalMaxMisread) {
|
||||
log.warning(String.format("+++ Test expects too many misreads by %d images", totalMaxMisread - totalMisread));
|
||||
} else if (totalMisread > totalMaxMisread) {
|
||||
log.warning(String.format("--- Test had too many misreads by %d images", totalMisread - totalMaxMisread));
|
||||
}
|
||||
|
||||
// Then run through again and assert if any failed
|
||||
for (int x = 0; x < testCount; x++) {
|
||||
TestResult testResult = testResults.get(x);
|
||||
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
|
||||
assertTrue(label,
|
||||
passedCounts[x] >= testResult.getMustPassCount());
|
||||
assertTrue("Try harder, " + label,
|
||||
tryHarderCounts[x] >= testResult.getTryHarderCount());
|
||||
label = "Rotation " + testResult.getRotation() + " degrees: Too many images misread";
|
||||
assertTrue(label,
|
||||
misreadCounts[x] <= testResult.getMaxMisreads());
|
||||
assertTrue("Try harder, " + label,
|
||||
tryHarderMisreadCounts[x] <= testResult.getMaxTryHarderMisreads());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean decode(BinaryBitmap source,
|
||||
float rotation,
|
||||
String expectedText,
|
||||
Map<?,?> expectedMetadata,
|
||||
boolean tryHarder) throws ReaderException {
|
||||
|
||||
String suffix = String.format(" (%srotation: %d)", tryHarder ? "try harder, " : "", (int) rotation);
|
||||
|
||||
Map<DecodeHintType,Object> hints = this.hints.clone();
|
||||
if (tryHarder) {
|
||||
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
|
||||
}
|
||||
|
||||
// Try in 'pure' mode mostly to exercise PURE_BARCODE code paths for exceptions;
|
||||
// not expected to pass, generally
|
||||
Result result = null;
|
||||
try {
|
||||
Map<DecodeHintType,Object> pureHints = new EnumMap<>(hints);
|
||||
pureHints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
|
||||
result = barcodeReader.decode(source, pureHints);
|
||||
} catch (ReaderException re) {
|
||||
// continue
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
result = barcodeReader.decode(source, hints);
|
||||
}
|
||||
|
||||
if (expectedFormat != result.getBarcodeFormat()) {
|
||||
log.info(String.format("Format mismatch: expected '%s' but got '%s'%s",
|
||||
expectedFormat, result.getBarcodeFormat(), suffix));
|
||||
return false;
|
||||
}
|
||||
|
||||
String resultText = result.getText();
|
||||
if (!expectedText.equals(resultText)) {
|
||||
log.info(String.format("Content mismatch: expected '%s' but got '%s'%s",
|
||||
expectedText, resultText, suffix));
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<ResultMetadataType,?> resultMetadata = result.getResultMetadata();
|
||||
for (Map.Entry<?,?> metadatum : expectedMetadata.entrySet()) {
|
||||
ResultMetadataType key = ResultMetadataType.valueOf(metadatum.getKey().toString());
|
||||
Object expectedValue = metadatum.getValue();
|
||||
Object actualValue = resultMetadata == null ? null : resultMetadata.get(key);
|
||||
if (!expectedValue.equals(actualValue)) {
|
||||
log.info(String.format("Metadata mismatch for key '%s': expected '%s' but got '%s'",
|
||||
key, expectedValue, actualValue));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static String readFileAsString(Path file, Charset charset) throws IOException {
|
||||
String stringContents = new String(Files.readAllBytes(file), charset);
|
||||
if (stringContents.endsWith("\n")) {
|
||||
log.info("String contents of file " + file + " end with a newline. " +
|
||||
"This may not be intended and cause a test failure");
|
||||
}
|
||||
return stringContents;
|
||||
}
|
||||
|
||||
protected static BufferedImage rotateImage(BufferedImage original, float degrees) {
|
||||
if (degrees == 0.0f) {
|
||||
return original;
|
||||
}
|
||||
|
||||
switch (original.getType()) {
|
||||
case BufferedImage.TYPE_BYTE_INDEXED:
|
||||
case BufferedImage.TYPE_BYTE_BINARY:
|
||||
BufferedImage argb = new BufferedImage(original.getWidth(),
|
||||
original.getHeight(),
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics g = argb.createGraphics();
|
||||
g.drawImage(original, 0, 0, null);
|
||||
g.dispose();
|
||||
original = argb;
|
||||
break;
|
||||
}
|
||||
|
||||
double radians = Math.toRadians(degrees);
|
||||
|
||||
// Transform simply to find out the new bounding box (don't actually run the image through it)
|
||||
AffineTransform at = new AffineTransform();
|
||||
at.rotate(radians, original.getWidth() / 2.0, original.getHeight() / 2.0);
|
||||
BufferedImageOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
|
||||
|
||||
RectangularShape r = op.getBounds2D(original);
|
||||
int width = (int) Math.ceil(r.getWidth());
|
||||
int height = (int) Math.ceil(r.getHeight());
|
||||
|
||||
// Real transform, now that we know the size of the new image and how to translate after we rotate
|
||||
// to keep it centered
|
||||
at = new AffineTransform();
|
||||
at.rotate(radians, width / 2.0, height / 2.0);
|
||||
at.translate((width - original.getWidth()) / 2.0,
|
||||
(height - original.getHeight()) / 2.0);
|
||||
op = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
|
||||
|
||||
return op.filter(original, new BufferedImage(width, height, original.getType()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.common;
|
||||
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.LuminanceSource;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.ReaderException;
|
||||
import com.google.zxing.Result;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* This abstract class looks for negative results, i.e. it only allows a certain number of false
|
||||
* positives in images which should not decode. This helps ensure that we are not too lenient.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public abstract class AbstractNegativeBlackBoxTestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
private static final Logger log = Logger.getLogger(AbstractNegativeBlackBoxTestCase.class.getSimpleName());
|
||||
|
||||
private final List<TestResult> testResults;
|
||||
|
||||
private static final class TestResult {
|
||||
private final int falsePositivesAllowed;
|
||||
private final float rotation;
|
||||
|
||||
TestResult(int falsePositivesAllowed, float rotation) {
|
||||
this.falsePositivesAllowed = falsePositivesAllowed;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
int getFalsePositivesAllowed() {
|
||||
return falsePositivesAllowed;
|
||||
}
|
||||
|
||||
float getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
}
|
||||
|
||||
// Use the multiformat reader to evaluate all decoders in the system.
|
||||
protected AbstractNegativeBlackBoxTestCase(String testBasePathSuffix) {
|
||||
super(testBasePathSuffix, new MultiFormatReader(), null);
|
||||
testResults = new ArrayList<>();
|
||||
}
|
||||
|
||||
protected final void addTest(int falsePositivesAllowed, float rotation) {
|
||||
testResults.add(new TestResult(falsePositivesAllowed, rotation));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testBlackBox() throws IOException {
|
||||
assertFalse(testResults.isEmpty());
|
||||
|
||||
List<Path> imageFiles = getImageFiles();
|
||||
int[] falsePositives = new int[testResults.size()];
|
||||
for (Path testImage : imageFiles) {
|
||||
log.info(String.format("Starting %s", testImage));
|
||||
BufferedImage image = ImageIO.read(testImage.toFile());
|
||||
if (image == null) {
|
||||
throw new IOException("Could not read image: " + testImage);
|
||||
}
|
||||
for (int x = 0; x < testResults.size(); x++) {
|
||||
TestResult testResult = testResults.get(x);
|
||||
if (!checkForFalsePositives(image, testResult.getRotation())) {
|
||||
falsePositives[x]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int totalFalsePositives = 0;
|
||||
int totalAllowed = 0;
|
||||
|
||||
for (int x = 0; x < testResults.size(); x++) {
|
||||
TestResult testResult = testResults.get(x);
|
||||
totalFalsePositives += falsePositives[x];
|
||||
totalAllowed += testResult.getFalsePositivesAllowed();
|
||||
}
|
||||
|
||||
if (totalFalsePositives < totalAllowed) {
|
||||
log.warning(String.format("+++ Test too lax by %d images", totalAllowed - totalFalsePositives));
|
||||
} else if (totalFalsePositives > totalAllowed) {
|
||||
log.warning(String.format("--- Test failed by %d images", totalFalsePositives - totalAllowed));
|
||||
}
|
||||
|
||||
for (int x = 0; x < testResults.size(); x++) {
|
||||
TestResult testResult = testResults.get(x);
|
||||
log.info(String.format("Rotation %d degrees: %d of %d images were false positives (%d allowed)",
|
||||
(int) testResult.getRotation(), falsePositives[x], imageFiles.size(),
|
||||
testResult.getFalsePositivesAllowed()));
|
||||
assertTrue("Rotation " + testResult.getRotation() + " degrees: Too many false positives found",
|
||||
falsePositives[x] <= testResult.getFalsePositivesAllowed());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure ZXing does NOT find a barcode in the image.
|
||||
*
|
||||
* @param image The image to test
|
||||
* @param rotationInDegrees The amount of rotation to apply
|
||||
* @return true if nothing found, false if a non-existent barcode was detected
|
||||
*/
|
||||
private boolean checkForFalsePositives(BufferedImage image, float rotationInDegrees) {
|
||||
BufferedImage rotatedImage = rotateImage(image, rotationInDegrees);
|
||||
LuminanceSource source = new BufferedImageLuminanceSource(rotatedImage);
|
||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||
Result result;
|
||||
try {
|
||||
result = getReader().decode(bitmap);
|
||||
log.info(String.format("Found false positive: '%s' with format '%s' (rotation: %d)",
|
||||
result.getText(), result.getBarcodeFormat(), (int) rotationInDegrees));
|
||||
return false;
|
||||
} catch (ReaderException re) {
|
||||
// continue
|
||||
}
|
||||
|
||||
// Try "try harder" getMode
|
||||
Map<DecodeHintType,Object> hints = new EnumMap<>(DecodeHintType.class);
|
||||
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
|
||||
try {
|
||||
result = getReader().decode(bitmap, hints);
|
||||
log.info(String.format("Try harder found false positive: '%s' with format '%s' (rotation: %d)",
|
||||
result.getText(), result.getBarcodeFormat(), (int) rotationInDegrees));
|
||||
return false;
|
||||
} catch (ReaderException re) {
|
||||
// continue
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
258
java_test/java/com/google/zxing/common/BitArrayTestCase.java
Normal file
258
java_test/java/com/google/zxing/common/BitArrayTestCase.java
Normal file
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
* Copyright 2007 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.common;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class BitArrayTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testGetSet() {
|
||||
BitArray array = new BitArray(33);
|
||||
for (int i = 0; i < 33; i++) {
|
||||
assertFalse(array.get(i));
|
||||
array.set(i);
|
||||
assertTrue(array.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNextSet1() {
|
||||
BitArray array = new BitArray(32);
|
||||
for (int i = 0; i < array.getSize(); i++) {
|
||||
assertEquals(String.valueOf(i), 32, array.getNextSet(i));
|
||||
}
|
||||
array = new BitArray(33);
|
||||
for (int i = 0; i < array.getSize(); i++) {
|
||||
assertEquals(String.valueOf(i), 33, array.getNextSet(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNextSet2() {
|
||||
BitArray array = new BitArray(33);
|
||||
array.set(31);
|
||||
for (int i = 0; i < array.getSize(); i++) {
|
||||
assertEquals(String.valueOf(i), i <= 31 ? 31 : 33, array.getNextSet(i));
|
||||
}
|
||||
array = new BitArray(33);
|
||||
array.set(32);
|
||||
for (int i = 0; i < array.getSize(); i++) {
|
||||
assertEquals(String.valueOf(i), 32, array.getNextSet(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNextSet3() {
|
||||
BitArray array = new BitArray(63);
|
||||
array.set(31);
|
||||
array.set(32);
|
||||
for (int i = 0; i < array.getSize(); i++) {
|
||||
int expected;
|
||||
if (i <= 31) {
|
||||
expected = 31;
|
||||
} else if (i == 32) {
|
||||
expected = 32;
|
||||
} else {
|
||||
expected = 63;
|
||||
}
|
||||
assertEquals(String.valueOf(i), expected, array.getNextSet(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNextSet4() {
|
||||
BitArray array = new BitArray(63);
|
||||
array.set(33);
|
||||
array.set(40);
|
||||
for (int i = 0; i < array.getSize(); i++) {
|
||||
int expected;
|
||||
if (i <= 33) {
|
||||
expected = 33;
|
||||
} else if (i <= 40) {
|
||||
expected = 40;
|
||||
} else {
|
||||
expected = 63;
|
||||
}
|
||||
assertEquals(String.valueOf(i), expected, array.getNextSet(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNextSet5() {
|
||||
Random r = new Random(0xDEADBEEF);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
BitArray array = new BitArray(1 + r.nextInt(100));
|
||||
int numSet = r.nextInt(20);
|
||||
for (int j = 0; j < numSet; j++) {
|
||||
array.set(r.nextInt(array.getSize()));
|
||||
}
|
||||
int numQueries = r.nextInt(20);
|
||||
for (int j = 0; j < numQueries; j++) {
|
||||
int query = r.nextInt(array.getSize());
|
||||
int expected = query;
|
||||
while (expected < array.getSize() && !array.get(expected)) {
|
||||
expected++;
|
||||
}
|
||||
int actual = array.getNextSet(query);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetBulk() {
|
||||
BitArray array = new BitArray(64);
|
||||
array.setBulk(32, 0xFFFF0000);
|
||||
for (int i = 0; i < 48; i++) {
|
||||
assertFalse(array.get(i));
|
||||
}
|
||||
for (int i = 48; i < 64; i++) {
|
||||
assertTrue(array.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetRange() {
|
||||
BitArray array = new BitArray(64);
|
||||
array.setRange(28, 36);
|
||||
assertFalse(array.get(27));
|
||||
for (int i = 28; i < 36; i++) {
|
||||
assertTrue(array.get(i));
|
||||
}
|
||||
assertFalse(array.get(36));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear() {
|
||||
BitArray array = new BitArray(32);
|
||||
for (int i = 0; i < 32; i++) {
|
||||
array.set(i);
|
||||
}
|
||||
array.clear();
|
||||
for (int i = 0; i < 32; i++) {
|
||||
assertFalse(array.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlip() {
|
||||
BitArray array = new BitArray(32);
|
||||
assertFalse(array.get(5));
|
||||
array.flip(5);
|
||||
assertTrue(array.get(5));
|
||||
array.flip(5);
|
||||
assertFalse(array.get(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArray() {
|
||||
BitArray array = new BitArray(64);
|
||||
array.set(0);
|
||||
array.set(63);
|
||||
int[] ints = array.getBitArray();
|
||||
assertEquals(1, ints[0]);
|
||||
assertEquals(Integer.MIN_VALUE, ints[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRange() {
|
||||
BitArray array = new BitArray(64);
|
||||
assertTrue(array.isRange(0, 64, false));
|
||||
assertFalse(array.isRange(0, 64, true));
|
||||
array.set(32);
|
||||
assertTrue(array.isRange(32, 33, true));
|
||||
array.set(31);
|
||||
assertTrue(array.isRange(31, 33, true));
|
||||
array.set(34);
|
||||
assertFalse(array.isRange(31, 35, true));
|
||||
for (int i = 0; i < 31; i++) {
|
||||
array.set(i);
|
||||
}
|
||||
assertTrue(array.isRange(0, 33, true));
|
||||
for (int i = 33; i < 64; i++) {
|
||||
array.set(i);
|
||||
}
|
||||
assertTrue(array.isRange(0, 64, true));
|
||||
assertFalse(array.isRange(0, 64, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reverseAlgorithmTest() {
|
||||
int[] oldBits = {128, 256, 512, 6453324, 50934953};
|
||||
for (int size = 1; size < 160; size++) {
|
||||
int[] newBitsOriginal = reverseOriginal(oldBits.clone(), size);
|
||||
BitArray newBitArray = new BitArray(oldBits.clone(), size);
|
||||
newBitArray.reverse();
|
||||
int[] newBitsNew = newBitArray.getBitArray();
|
||||
assertTrue(arraysAreEqual(newBitsOriginal, newBitsNew, size / 32 + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClone() {
|
||||
BitArray array = new BitArray(32);
|
||||
array.clone().set(0);
|
||||
assertFalse(array.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
BitArray a = new BitArray(32);
|
||||
BitArray b = new BitArray(32);
|
||||
assertEquals(a, b);
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
assertNotEquals(a, new BitArray(31));
|
||||
a.set(16);
|
||||
assertNotEquals(a, b);
|
||||
assertNotEquals(a.hashCode(), b.hashCode());
|
||||
b.set(16);
|
||||
assertEquals(a, b);
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
}
|
||||
|
||||
private static int[] reverseOriginal(int[] oldBits, int size) {
|
||||
int[] newBits = new int[oldBits.length];
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (bitSet(oldBits, size - i - 1)) {
|
||||
newBits[i / 32] |= 1 << (i & 0x1F);
|
||||
}
|
||||
}
|
||||
return newBits;
|
||||
}
|
||||
|
||||
private static boolean bitSet(int[] bits, int i) {
|
||||
return (bits[i / 32] & (1 << (i & 0x1F))) != 0;
|
||||
}
|
||||
|
||||
private static boolean arraysAreEqual(int[] left, int[] right, int size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (left[i] != right[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
347
java_test/java/com/google/zxing/common/BitMatrixTestCase.java
Normal file
347
java_test/java/com/google/zxing/common/BitMatrixTestCase.java
Normal file
@@ -0,0 +1,347 @@
|
||||
/*
|
||||
* Copyright 2007 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.common;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class BitMatrixTestCase extends Assert {
|
||||
|
||||
private static final int[] BIT_MATRIX_POINTS = { 1, 2, 2, 0, 3, 1 };
|
||||
|
||||
@Test
|
||||
public void testGetSet() {
|
||||
BitMatrix matrix = new BitMatrix(33);
|
||||
assertEquals(33, matrix.getHeight());
|
||||
for (int y = 0; y < 33; y++) {
|
||||
for (int x = 0; x < 33; x++) {
|
||||
if (y * x % 3 == 0) {
|
||||
matrix.set(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int y = 0; y < 33; y++) {
|
||||
for (int x = 0; x < 33; x++) {
|
||||
assertEquals(y * x % 3 == 0, matrix.get(x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetRegion() {
|
||||
BitMatrix matrix = new BitMatrix(5);
|
||||
matrix.setRegion(1, 1, 3, 3);
|
||||
for (int y = 0; y < 5; y++) {
|
||||
for (int x = 0; x < 5; x++) {
|
||||
assertEquals(y >= 1 && y <= 3 && x >= 1 && x <= 3, matrix.get(x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnclosing() {
|
||||
BitMatrix matrix = new BitMatrix(5);
|
||||
assertNull(matrix.getEnclosingRectangle());
|
||||
matrix.setRegion(1, 1, 1, 1);
|
||||
assertArrayEquals(new int[] { 1, 1, 1, 1 }, matrix.getEnclosingRectangle());
|
||||
matrix.setRegion(1, 1, 3, 2);
|
||||
assertArrayEquals(new int[] { 1, 1, 3, 2 }, matrix.getEnclosingRectangle());
|
||||
matrix.setRegion(0, 0, 5, 5);
|
||||
assertArrayEquals(new int[] { 0, 0, 5, 5 }, matrix.getEnclosingRectangle());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnBit() {
|
||||
BitMatrix matrix = new BitMatrix(5);
|
||||
assertNull(matrix.getTopLeftOnBit());
|
||||
assertNull(matrix.getBottomRightOnBit());
|
||||
matrix.setRegion(1, 1, 1, 1);
|
||||
assertArrayEquals(new int[] { 1, 1 }, matrix.getTopLeftOnBit());
|
||||
assertArrayEquals(new int[] { 1, 1 }, matrix.getBottomRightOnBit());
|
||||
matrix.setRegion(1, 1, 3, 2);
|
||||
assertArrayEquals(new int[] { 1, 1 }, matrix.getTopLeftOnBit());
|
||||
assertArrayEquals(new int[] { 3, 2 }, matrix.getBottomRightOnBit());
|
||||
matrix.setRegion(0, 0, 5, 5);
|
||||
assertArrayEquals(new int[] { 0, 0 }, matrix.getTopLeftOnBit());
|
||||
assertArrayEquals(new int[] { 4, 4 }, matrix.getBottomRightOnBit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRectangularMatrix() {
|
||||
BitMatrix matrix = new BitMatrix(75, 20);
|
||||
assertEquals(75, matrix.getWidth());
|
||||
assertEquals(20, matrix.getHeight());
|
||||
matrix.set(10, 0);
|
||||
matrix.set(11, 1);
|
||||
matrix.set(50, 2);
|
||||
matrix.set(51, 3);
|
||||
matrix.flip(74, 4);
|
||||
matrix.flip(0, 5);
|
||||
|
||||
// Should all be on
|
||||
assertTrue(matrix.get(10, 0));
|
||||
assertTrue(matrix.get(11, 1));
|
||||
assertTrue(matrix.get(50, 2));
|
||||
assertTrue(matrix.get(51, 3));
|
||||
assertTrue(matrix.get(74, 4));
|
||||
assertTrue(matrix.get(0, 5));
|
||||
|
||||
// Flip a couple back off
|
||||
matrix.flip(50, 2);
|
||||
matrix.flip(51, 3);
|
||||
assertFalse(matrix.get(50, 2));
|
||||
assertFalse(matrix.get(51, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRectangularSetRegion() {
|
||||
BitMatrix matrix = new BitMatrix(320, 240);
|
||||
assertEquals(320, matrix.getWidth());
|
||||
assertEquals(240, matrix.getHeight());
|
||||
matrix.setRegion(105, 22, 80, 12);
|
||||
|
||||
// Only bits in the region should be on
|
||||
for (int y = 0; y < 240; y++) {
|
||||
for (int x = 0; x < 320; x++) {
|
||||
assertEquals(y >= 22 && y < 34 && x >= 105 && x < 185, matrix.get(x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRow() {
|
||||
BitMatrix matrix = new BitMatrix(102, 5);
|
||||
for (int x = 0; x < 102; x++) {
|
||||
if ((x & 0x03) == 0) {
|
||||
matrix.set(x, 2);
|
||||
}
|
||||
}
|
||||
|
||||
// Should allocate
|
||||
BitArray array = matrix.getRow(2, null);
|
||||
assertEquals(102, array.getSize());
|
||||
|
||||
// Should reallocate
|
||||
BitArray array2 = new BitArray(60);
|
||||
array2 = matrix.getRow(2, array2);
|
||||
assertEquals(102, array2.getSize());
|
||||
|
||||
// Should use provided object, with original BitArray size
|
||||
BitArray array3 = new BitArray(200);
|
||||
array3 = matrix.getRow(2, array3);
|
||||
assertEquals(200, array3.getSize());
|
||||
|
||||
for (int x = 0; x < 102; x++) {
|
||||
boolean on = (x & 0x03) == 0;
|
||||
assertEquals(on, array.get(x));
|
||||
assertEquals(on, array2.get(x));
|
||||
assertEquals(on, array3.get(x));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotate90Simple() {
|
||||
BitMatrix matrix = new BitMatrix(3, 3);
|
||||
matrix.set(0, 0);
|
||||
matrix.set(0, 1);
|
||||
matrix.set(1, 2);
|
||||
matrix.set(2, 1);
|
||||
|
||||
matrix.rotate90();
|
||||
|
||||
assertTrue(matrix.get(0, 2));
|
||||
assertTrue(matrix.get(1, 2));
|
||||
assertTrue(matrix.get(2, 1));
|
||||
assertTrue(matrix.get(1, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotate180Simple() {
|
||||
BitMatrix matrix = new BitMatrix(3, 3);
|
||||
matrix.set(0, 0);
|
||||
matrix.set(0, 1);
|
||||
matrix.set(1, 2);
|
||||
matrix.set(2, 1);
|
||||
|
||||
matrix.rotate180();
|
||||
|
||||
assertTrue(matrix.get(2, 2));
|
||||
assertTrue(matrix.get(2, 1));
|
||||
assertTrue(matrix.get(1, 0));
|
||||
assertTrue(matrix.get(0, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotate180() {
|
||||
testRotate180(7, 4);
|
||||
testRotate180(7, 5);
|
||||
testRotate180(8, 4);
|
||||
testRotate180(8, 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse() {
|
||||
BitMatrix emptyMatrix = new BitMatrix(3, 3);
|
||||
BitMatrix fullMatrix = new BitMatrix(3, 3);
|
||||
fullMatrix.setRegion(0, 0, 3, 3);
|
||||
BitMatrix centerMatrix = new BitMatrix(3, 3);
|
||||
centerMatrix.setRegion(1, 1, 1, 1);
|
||||
BitMatrix emptyMatrix24 = new BitMatrix(2, 4);
|
||||
|
||||
assertEquals(emptyMatrix, BitMatrix.parse(" \n \n \n", "x", " "));
|
||||
assertEquals(emptyMatrix, BitMatrix.parse(" \n \r\r\n \n\r", "x", " "));
|
||||
assertEquals(emptyMatrix, BitMatrix.parse(" \n \n ", "x", " "));
|
||||
|
||||
assertEquals(fullMatrix, BitMatrix.parse("xxx\nxxx\nxxx\n", "x", " "));
|
||||
|
||||
assertEquals(centerMatrix, BitMatrix.parse(" \n x \n \n", "x", " "));
|
||||
assertEquals(centerMatrix, BitMatrix.parse(" \n x \n \n", "x ", " "));
|
||||
try {
|
||||
assertEquals(centerMatrix, BitMatrix.parse(" \n xy\n \n", "x", " "));
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// good
|
||||
}
|
||||
|
||||
assertEquals(emptyMatrix24, BitMatrix.parse(" \n \n \n \n", "x", " "));
|
||||
|
||||
assertEquals(centerMatrix, BitMatrix.parse(centerMatrix.toString("x", "."), "x", "."));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseBoolean() {
|
||||
BitMatrix emptyMatrix = new BitMatrix(3, 3);
|
||||
BitMatrix fullMatrix = new BitMatrix(3, 3);
|
||||
fullMatrix.setRegion(0, 0, 3, 3);
|
||||
BitMatrix centerMatrix = new BitMatrix(3, 3);
|
||||
centerMatrix.setRegion(1, 1, 1, 1);
|
||||
BitMatrix emptyMatrix24 = new BitMatrix(2, 4);
|
||||
|
||||
boolean[][] matrix = new boolean[3][3];
|
||||
assertEquals(emptyMatrix, BitMatrix.parse(matrix));
|
||||
matrix[1][1] = true;
|
||||
assertEquals(centerMatrix, BitMatrix.parse(matrix));
|
||||
for (boolean[] arr : matrix) {
|
||||
Arrays.fill(arr, true);
|
||||
}
|
||||
assertEquals(fullMatrix, BitMatrix.parse(matrix));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnset() {
|
||||
BitMatrix emptyMatrix = new BitMatrix(3, 3);
|
||||
BitMatrix matrix = emptyMatrix.clone();
|
||||
matrix.set(1, 1);
|
||||
assertNotEquals(emptyMatrix, matrix);
|
||||
matrix.unset(1, 1);
|
||||
assertEquals(emptyMatrix, matrix);
|
||||
matrix.unset(1, 1);
|
||||
assertEquals(emptyMatrix, matrix);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXOR() {
|
||||
BitMatrix emptyMatrix = new BitMatrix(3, 3);
|
||||
BitMatrix fullMatrix = new BitMatrix(3, 3);
|
||||
fullMatrix.setRegion(0, 0, 3, 3);
|
||||
BitMatrix centerMatrix = new BitMatrix(3, 3);
|
||||
centerMatrix.setRegion(1, 1, 1, 1);
|
||||
BitMatrix invertedCenterMatrix = fullMatrix.clone();
|
||||
invertedCenterMatrix.unset(1, 1);
|
||||
BitMatrix badMatrix = new BitMatrix(4, 4);
|
||||
|
||||
testXOR(emptyMatrix, emptyMatrix, emptyMatrix);
|
||||
testXOR(emptyMatrix, centerMatrix, centerMatrix);
|
||||
testXOR(emptyMatrix, fullMatrix, fullMatrix);
|
||||
|
||||
testXOR(centerMatrix, emptyMatrix, centerMatrix);
|
||||
testXOR(centerMatrix, centerMatrix, emptyMatrix);
|
||||
testXOR(centerMatrix, fullMatrix, invertedCenterMatrix);
|
||||
|
||||
testXOR(invertedCenterMatrix, emptyMatrix, invertedCenterMatrix);
|
||||
testXOR(invertedCenterMatrix, centerMatrix, fullMatrix);
|
||||
testXOR(invertedCenterMatrix, fullMatrix, centerMatrix);
|
||||
|
||||
testXOR(fullMatrix, emptyMatrix, fullMatrix);
|
||||
testXOR(fullMatrix, centerMatrix, invertedCenterMatrix);
|
||||
testXOR(fullMatrix, fullMatrix, emptyMatrix);
|
||||
|
||||
try {
|
||||
emptyMatrix.clone().xor(badMatrix);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// good
|
||||
}
|
||||
|
||||
try {
|
||||
badMatrix.clone().xor(emptyMatrix);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// good
|
||||
}
|
||||
}
|
||||
|
||||
public static String matrixToString(BitMatrix result) {
|
||||
assertEquals(1, result.getHeight());
|
||||
StringBuilder builder = new StringBuilder(result.getWidth());
|
||||
for (int i = 0; i < result.getWidth(); i++) {
|
||||
builder.append(result.get(i, 0) ? '1' : '0');
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static void testXOR(BitMatrix dataMatrix, BitMatrix flipMatrix, BitMatrix expectedMatrix) {
|
||||
BitMatrix matrix = dataMatrix.clone();
|
||||
matrix.xor(flipMatrix);
|
||||
assertEquals(expectedMatrix, matrix);
|
||||
}
|
||||
|
||||
private static void testRotate180(int width, int height) {
|
||||
BitMatrix input = getInput(width, height);
|
||||
input.rotate180();
|
||||
BitMatrix expected = getExpected(width, height);
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
assertEquals("(" + x + ',' + y + ')', expected.get(x, y), input.get(x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static BitMatrix getExpected(int width, int height) {
|
||||
BitMatrix result = new BitMatrix(width, height);
|
||||
for (int i = 0; i < BIT_MATRIX_POINTS.length; i += 2) {
|
||||
result.set(width - 1 - BIT_MATRIX_POINTS[i], height - 1 - BIT_MATRIX_POINTS[i + 1]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static BitMatrix getInput(int width, int height) {
|
||||
BitMatrix result = new BitMatrix(width, height);
|
||||
for (int i = 0; i < BIT_MATRIX_POINTS.length; i += 2) {
|
||||
result.set(BIT_MATRIX_POINTS[i], BIT_MATRIX_POINTS[i + 1]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
65
java_test/java/com/google/zxing/common/BitSourceBuilder.java
Executable file
65
java_test/java/com/google/zxing/common/BitSourceBuilder.java
Executable file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.common;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
/**
|
||||
* Class that lets one easily build an array of bytes by appending bits at a time.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class BitSourceBuilder {
|
||||
|
||||
private final ByteArrayOutputStream output;
|
||||
private int nextByte;
|
||||
private int bitsLeftInNextByte;
|
||||
|
||||
public BitSourceBuilder() {
|
||||
output = new ByteArrayOutputStream();
|
||||
nextByte = 0;
|
||||
bitsLeftInNextByte = 8;
|
||||
}
|
||||
|
||||
public void write(int value, int numBits) {
|
||||
if (numBits <= bitsLeftInNextByte) {
|
||||
nextByte <<= numBits;
|
||||
nextByte |= value;
|
||||
bitsLeftInNextByte -= numBits;
|
||||
if (bitsLeftInNextByte == 0) {
|
||||
output.write(nextByte);
|
||||
nextByte = 0;
|
||||
bitsLeftInNextByte = 8;
|
||||
}
|
||||
} else {
|
||||
int bitsToWriteNow = bitsLeftInNextByte;
|
||||
int numRestOfBits = numBits - bitsToWriteNow;
|
||||
int mask = 0xFF >> (8 - bitsToWriteNow);
|
||||
int valueToWriteNow = (value >>> numRestOfBits) & mask;
|
||||
write(valueToWriteNow, bitsToWriteNow);
|
||||
write(value, numRestOfBits);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] toByteArray() {
|
||||
if (bitsLeftInNextByte < 8) {
|
||||
write(0, bitsLeftInNextByte);
|
||||
}
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2007 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.common;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class BitSourceTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testSource() {
|
||||
byte[] bytes = {(byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5};
|
||||
BitSource source = new BitSource(bytes);
|
||||
assertEquals(40, source.available());
|
||||
assertEquals(0, source.readBits(1));
|
||||
assertEquals(39, source.available());
|
||||
assertEquals(0, source.readBits(6));
|
||||
assertEquals(33, source.available());
|
||||
assertEquals(1, source.readBits(1));
|
||||
assertEquals(32, source.available());
|
||||
assertEquals(2, source.readBits(8));
|
||||
assertEquals(24, source.available());
|
||||
assertEquals(12, source.readBits(10));
|
||||
assertEquals(14, source.available());
|
||||
assertEquals(16, source.readBits(8));
|
||||
assertEquals(6, source.available());
|
||||
assertEquals(5, source.readBits(6));
|
||||
assertEquals(0, source.available());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2007 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.common;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class PerspectiveTransformTestCase extends Assert {
|
||||
|
||||
private static final float EPSILON = 1.0E-4f;
|
||||
|
||||
@Test
|
||||
public void testSquareToQuadrilateral() {
|
||||
PerspectiveTransform pt = PerspectiveTransform.squareToQuadrilateral(
|
||||
2.0f, 3.0f, 10.0f, 4.0f, 16.0f, 15.0f, 4.0f, 9.0f);
|
||||
assertPointEquals(2.0f, 3.0f, 0.0f, 0.0f, pt);
|
||||
assertPointEquals(10.0f, 4.0f, 1.0f, 0.0f, pt);
|
||||
assertPointEquals(4.0f, 9.0f, 0.0f, 1.0f, pt);
|
||||
assertPointEquals(16.0f, 15.0f, 1.0f, 1.0f, pt);
|
||||
assertPointEquals(6.535211f, 6.8873234f, 0.5f, 0.5f, pt);
|
||||
assertPointEquals(48.0f, 42.42857f, 1.5f, 1.5f, pt);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuadrilateralToQuadrilateral() {
|
||||
PerspectiveTransform pt = PerspectiveTransform.quadrilateralToQuadrilateral(
|
||||
2.0f, 3.0f, 10.0f, 4.0f, 16.0f, 15.0f, 4.0f, 9.0f,
|
||||
103.0f, 110.0f, 300.0f, 120.0f, 290.0f, 270.0f, 150.0f, 280.0f);
|
||||
assertPointEquals(103.0f, 110.0f, 2.0f, 3.0f, pt);
|
||||
assertPointEquals(300.0f, 120.0f, 10.0f, 4.0f, pt);
|
||||
assertPointEquals(290.0f, 270.0f, 16.0f, 15.0f, pt);
|
||||
assertPointEquals(150.0f, 280.0f, 4.0f, 9.0f, pt);
|
||||
assertPointEquals(7.1516876f, -64.60185f, 0.5f, 0.5f, pt);
|
||||
assertPointEquals(328.09116f, 334.16385f, 50.0f, 50.0f, pt);
|
||||
}
|
||||
|
||||
private static void assertPointEquals(float expectedX,
|
||||
float expectedY,
|
||||
float sourceX,
|
||||
float sourceY,
|
||||
PerspectiveTransform pt) {
|
||||
float[] points = {sourceX, sourceY};
|
||||
pt.transformPoints(points);
|
||||
assertEquals(expectedX, points[0], EPSILON);
|
||||
assertEquals(expectedY, points[1], EPSILON);
|
||||
}
|
||||
|
||||
}
|
||||
117
java_test/java/com/google/zxing/common/StringUtilsTestCase.java
Normal file
117
java_test/java/com/google/zxing/common/StringUtilsTestCase.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 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.
|
||||
*/
|
||||
|
||||
package com.google.zxing.common;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils}.
|
||||
*/
|
||||
public final class StringUtilsTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testRandom() {
|
||||
Random r = new Random(1234L);
|
||||
byte[] bytes = new byte[1000];
|
||||
r.nextBytes(bytes);
|
||||
assertEquals(Charset.defaultCharset(), StringUtils.guessCharset(bytes, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShortShiftJIS1() {
|
||||
// 金魚
|
||||
doTest(new byte[] { (byte) 0x8b, (byte) 0xe0, (byte) 0x8b, (byte) 0x9b, }, StringUtils.SHIFT_JIS_CHARSET, "SJIS");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShortISO885911() {
|
||||
// båd
|
||||
doTest(new byte[] { (byte) 0x62, (byte) 0xe5, (byte) 0x64, }, StandardCharsets.ISO_8859_1, "ISO8859_1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShortUTF81() {
|
||||
// Español
|
||||
doTest(new byte[] { (byte) 0x45, (byte) 0x73, (byte) 0x70, (byte) 0x61, (byte) 0xc3,
|
||||
(byte) 0xb1, (byte) 0x6f, (byte) 0x6c },
|
||||
StandardCharsets.UTF_8, "UTF8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedShiftJIS1() {
|
||||
// Hello 金!
|
||||
doTest(new byte[] { (byte) 0x48, (byte) 0x65, (byte) 0x6c, (byte) 0x6c, (byte) 0x6f,
|
||||
(byte) 0x20, (byte) 0x8b, (byte) 0xe0, (byte) 0x21, },
|
||||
StringUtils.SHIFT_JIS_CHARSET, "SJIS");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUTF16BE() {
|
||||
// 调压柜
|
||||
doTest(new byte[] { (byte) 0xFE, (byte) 0xFF, (byte) 0x8c, (byte) 0x03, (byte) 0x53, (byte) 0x8b,
|
||||
(byte) 0x67, (byte) 0xdc, },
|
||||
StandardCharsets.UTF_16,
|
||||
StandardCharsets.UTF_16.name());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUTF16LE() {
|
||||
// 调压柜
|
||||
doTest(new byte[] { (byte) 0xFF, (byte) 0xFE, (byte) 0x03, (byte) 0x8c, (byte) 0x8b, (byte) 0x53,
|
||||
(byte) 0xdc, (byte) 0x67, },
|
||||
StandardCharsets.UTF_16,
|
||||
StandardCharsets.UTF_16.name());
|
||||
}
|
||||
|
||||
private static void doTest(byte[] bytes, Charset charset, String encoding) {
|
||||
Charset guessedCharset = StringUtils.guessCharset(bytes, null);
|
||||
String guessedEncoding = StringUtils.guessEncoding(bytes, null);
|
||||
assertEquals(charset, guessedCharset);
|
||||
assertEquals(encoding, guessedEncoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility for printing out a string in given encoding as a Java statement, since it's better
|
||||
* to write that into the Java source file rather than risk character encoding issues in the
|
||||
* source file itself.
|
||||
*
|
||||
* @param args command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
String text = args[0];
|
||||
Charset charset = Charset.forName(args[1]);
|
||||
StringBuilder declaration = new StringBuilder();
|
||||
declaration.append("new byte[] { ");
|
||||
for (byte b : text.getBytes(charset)) {
|
||||
declaration.append("(byte) 0x");
|
||||
int value = b & 0xFF;
|
||||
if (value < 0x10) {
|
||||
declaration.append('0');
|
||||
}
|
||||
declaration.append(Integer.toHexString(value));
|
||||
declaration.append(", ");
|
||||
}
|
||||
declaration.append('}');
|
||||
System.out.println(declaration);
|
||||
}
|
||||
|
||||
}
|
||||
58
java_test/java/com/google/zxing/common/TestResult.java
Normal file
58
java_test/java/com/google/zxing/common/TestResult.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.common;
|
||||
|
||||
/**
|
||||
* Encapsulates the result of one test over a batch of black-box images.
|
||||
*/
|
||||
public final class TestResult {
|
||||
|
||||
private final int mustPassCount;
|
||||
private final int tryHarderCount;
|
||||
private final int maxMisreads;
|
||||
private final int maxTryHarderMisreads;
|
||||
private final float rotation;
|
||||
|
||||
public TestResult(int mustPassCount, int tryHarderCount, int maxMisreads, int maxTryHarderMisreads, float rotation) {
|
||||
this.mustPassCount = mustPassCount;
|
||||
this.tryHarderCount = tryHarderCount;
|
||||
this.maxMisreads = maxMisreads;
|
||||
this.maxTryHarderMisreads = maxTryHarderMisreads;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public int getMustPassCount() {
|
||||
return mustPassCount;
|
||||
}
|
||||
|
||||
public int getTryHarderCount() {
|
||||
return tryHarderCount;
|
||||
}
|
||||
|
||||
public int getMaxMisreads() {
|
||||
return maxMisreads;
|
||||
}
|
||||
|
||||
public int getMaxTryHarderMisreads() {
|
||||
return maxTryHarderMisreads;
|
||||
}
|
||||
|
||||
public float getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.common.detector;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link MathUtils}.
|
||||
*/
|
||||
public final class MathUtilsTestCase extends Assert {
|
||||
|
||||
private static final float EPSILON = 1.0E-8f;
|
||||
|
||||
@Test
|
||||
public void testRound() {
|
||||
assertEquals(-1, MathUtils.round(-1.0f));
|
||||
assertEquals(0, MathUtils.round(0.0f));
|
||||
assertEquals(1, MathUtils.round(1.0f));
|
||||
|
||||
assertEquals(2, MathUtils.round(1.9f));
|
||||
assertEquals(2, MathUtils.round(2.1f));
|
||||
|
||||
assertEquals(3, MathUtils.round(2.5f));
|
||||
|
||||
assertEquals(-2, MathUtils.round(-1.9f));
|
||||
assertEquals(-2, MathUtils.round(-2.1f));
|
||||
|
||||
assertEquals(-3, MathUtils.round(-2.5f)); // This differs from Math.round()
|
||||
|
||||
assertEquals(Integer.MAX_VALUE, MathUtils.round(Integer.MAX_VALUE));
|
||||
assertEquals(Integer.MIN_VALUE, MathUtils.round(Integer.MIN_VALUE));
|
||||
|
||||
assertEquals(Integer.MAX_VALUE, MathUtils.round(Float.POSITIVE_INFINITY));
|
||||
assertEquals(Integer.MIN_VALUE, MathUtils.round(Float.NEGATIVE_INFINITY));
|
||||
|
||||
assertEquals(0, MathUtils.round(Float.NaN));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDistance() {
|
||||
assertEquals((float) Math.sqrt(8.0), MathUtils.distance(1.0f, 2.0f, 3.0f, 4.0f), EPSILON);
|
||||
assertEquals(0.0f, MathUtils.distance(1.0f, 2.0f, 1.0f, 2.0f), EPSILON);
|
||||
|
||||
assertEquals((float) Math.sqrt(8.0), MathUtils.distance(1, 2, 3, 4), EPSILON);
|
||||
assertEquals(0.0f, MathUtils.distance(1, 2, 1, 2), EPSILON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSum() {
|
||||
assertEquals(0, MathUtils.sum(new int[] {}));
|
||||
assertEquals(1, MathUtils.sum(new int[] {1}));
|
||||
assertEquals(4, MathUtils.sum(new int[] {1, 3}));
|
||||
assertEquals(0, MathUtils.sum(new int[] {-1, 1}));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.common.reedsolomon;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link GenericGFPoly}.
|
||||
*/
|
||||
public final class GenericGFPolyTestCase extends Assert {
|
||||
|
||||
private static final GenericGF FIELD = GenericGF.QR_CODE_FIELD_256;
|
||||
|
||||
@Test
|
||||
public void testPolynomialString() {
|
||||
assertEquals("0", FIELD.getZero().toString());
|
||||
assertEquals("-1", FIELD.buildMonomial(0, -1).toString());
|
||||
GenericGFPoly p = new GenericGFPoly(FIELD, new int[] {3, 0, -2, 1, 1});
|
||||
assertEquals("a^25x^4 - ax^2 + x + 1", p.toString());
|
||||
p = new GenericGFPoly(FIELD, new int[] {3});
|
||||
assertEquals("a^25", p.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZero() {
|
||||
assertEquals(FIELD.getZero(),FIELD.buildMonomial(1, 0));
|
||||
assertEquals(FIELD.getZero(), FIELD.buildMonomial(1, 2).multiply(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluate() {
|
||||
assertEquals(3, FIELD.buildMonomial(0, 3).evaluateAt(0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,525 @@
|
||||
/*
|
||||
* Copyright 2013 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.common.reedsolomon;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author Rustam Abdullaev
|
||||
*/
|
||||
public final class ReedSolomonTestCase extends Assert {
|
||||
|
||||
private static final int DECODER_RANDOM_TEST_ITERATIONS = 3;
|
||||
private static final int DECODER_TEST_ITERATIONS = 10;
|
||||
|
||||
@Test
|
||||
public void testDataMatrix() {
|
||||
// real life test cases
|
||||
testEncodeDecode(GenericGF.DATA_MATRIX_FIELD_256,
|
||||
new int[] { 142, 164, 186 }, new int[] { 114, 25, 5, 88, 102 });
|
||||
testEncodeDecode(GenericGF.DATA_MATRIX_FIELD_256,
|
||||
new int[] {
|
||||
0x69, 0x75, 0x75, 0x71, 0x3B, 0x30, 0x30, 0x64,
|
||||
0x70, 0x65, 0x66, 0x2F, 0x68, 0x70, 0x70, 0x68,
|
||||
0x6D, 0x66, 0x2F, 0x64, 0x70, 0x6E, 0x30, 0x71,
|
||||
0x30, 0x7B, 0x79, 0x6A, 0x6F, 0x68, 0x30, 0x81,
|
||||
0xF0, 0x88, 0x1F, 0xB5
|
||||
},
|
||||
new int[] {
|
||||
0x1C, 0x64, 0xEE, 0xEB, 0xD0, 0x1D, 0x00, 0x03,
|
||||
0xF0, 0x1C, 0xF1, 0xD0, 0x6D, 0x00, 0x98, 0xDA,
|
||||
0x80, 0x88, 0xBE, 0xFF, 0xB7, 0xFA, 0xA9, 0x95
|
||||
});
|
||||
// synthetic test cases
|
||||
testEncodeDecodeRandom(GenericGF.DATA_MATRIX_FIELD_256, 10, 240);
|
||||
testEncodeDecodeRandom(GenericGF.DATA_MATRIX_FIELD_256, 128, 127);
|
||||
testEncodeDecodeRandom(GenericGF.DATA_MATRIX_FIELD_256, 220, 35);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQRCode() {
|
||||
// Test case from example given in ISO 18004, Annex I
|
||||
testEncodeDecode(GenericGF.QR_CODE_FIELD_256,
|
||||
new int[] {
|
||||
0x10, 0x20, 0x0C, 0x56, 0x61, 0x80, 0xEC, 0x11,
|
||||
0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11
|
||||
},
|
||||
new int[] {
|
||||
0xA5, 0x24, 0xD4, 0xC1, 0xED, 0x36, 0xC7, 0x87,
|
||||
0x2C, 0x55
|
||||
});
|
||||
testEncodeDecode(GenericGF.QR_CODE_FIELD_256,
|
||||
new int[] {
|
||||
0x72, 0x67, 0x2F, 0x77, 0x69, 0x6B, 0x69, 0x2F,
|
||||
0x4D, 0x61, 0x69, 0x6E, 0x5F, 0x50, 0x61, 0x67,
|
||||
0x65, 0x3B, 0x3B, 0x00, 0xEC, 0x11, 0xEC, 0x11,
|
||||
0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11
|
||||
},
|
||||
new int[] {
|
||||
0xD8, 0xB8, 0xEF, 0x14, 0xEC, 0xD0, 0xCC, 0x85,
|
||||
0x73, 0x40, 0x0B, 0xB5, 0x5A, 0xB8, 0x8B, 0x2E,
|
||||
0x08, 0x62
|
||||
});
|
||||
// real life test cases
|
||||
// synthetic test cases
|
||||
testEncodeDecodeRandom(GenericGF.QR_CODE_FIELD_256, 10, 240);
|
||||
testEncodeDecodeRandom(GenericGF.QR_CODE_FIELD_256, 128, 127);
|
||||
testEncodeDecodeRandom(GenericGF.QR_CODE_FIELD_256, 220, 35);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAztec() {
|
||||
// real life test cases
|
||||
testEncodeDecode(GenericGF.AZTEC_PARAM,
|
||||
new int[] { 0x5, 0x6 }, new int[] { 0x3, 0x2, 0xB, 0xB, 0x7 });
|
||||
testEncodeDecode(GenericGF.AZTEC_PARAM,
|
||||
new int[] { 0x0, 0x0, 0x0, 0x9 }, new int[] { 0xA, 0xD, 0x8, 0x6, 0x5, 0x6 });
|
||||
testEncodeDecode(GenericGF.AZTEC_PARAM,
|
||||
new int[] { 0x2, 0x8, 0x8, 0x7 }, new int[] { 0xE, 0xC, 0xA, 0x9, 0x6, 0x8 });
|
||||
testEncodeDecode(GenericGF.AZTEC_DATA_6, new int[] {
|
||||
0x9, 0x32, 0x1, 0x29, 0x2F, 0x2, 0x27, 0x25, 0x1, 0x1B },
|
||||
new int[] {
|
||||
0x2C, 0x2, 0xD, 0xD, 0xA, 0x16, 0x28, 0x9, 0x22, 0xA, 0x14
|
||||
});
|
||||
testEncodeDecode(GenericGF.AZTEC_DATA_8,
|
||||
new int[] {
|
||||
0xE0, 0x86, 0x42, 0x98, 0xE8, 0x4A, 0x96, 0xC6,
|
||||
0xB9, 0xF0, 0x8C, 0xA7, 0x4A, 0xDA, 0xF8, 0xCE,
|
||||
0xB7, 0xDE, 0x88, 0x64, 0x29, 0x8E, 0x84, 0xA9,
|
||||
0x6C, 0x6B, 0x9F, 0x08, 0xCA, 0x74, 0xAD, 0xAF,
|
||||
0x8C, 0xEB, 0x7C, 0x10, 0xC8, 0x53, 0x1D, 0x09,
|
||||
0x52, 0xD8, 0xD7, 0x3E, 0x11, 0x94, 0xE9, 0x5B,
|
||||
0x5F, 0x19, 0xD6, 0xFB, 0xD1, 0x0C, 0x85, 0x31,
|
||||
0xD0, 0x95, 0x2D, 0x8D, 0x73, 0xE1, 0x19, 0x4E,
|
||||
0x95, 0xB5, 0xF1, 0x9D, 0x6F
|
||||
},
|
||||
new int[] {
|
||||
0x31, 0xD7, 0x04, 0x46, 0xB2, 0xC1, 0x06, 0x94,
|
||||
0x17, 0xE5, 0x0C, 0x2B, 0xA3, 0x99, 0x15, 0x7F,
|
||||
0x16, 0x3C, 0x66, 0xBA, 0x33, 0xD9, 0xE8, 0x87,
|
||||
0x86, 0xBB, 0x4B, 0x15, 0x4E, 0x4A, 0xDE, 0xD4,
|
||||
0xED, 0xA1, 0xF8, 0x47, 0x2A, 0x50, 0xA6, 0xBC,
|
||||
0x53, 0x7D, 0x29, 0xFE, 0x06, 0x49, 0xF3, 0x73,
|
||||
0x9F, 0xC1, 0x75
|
||||
});
|
||||
testEncodeDecode(GenericGF.AZTEC_DATA_10,
|
||||
new int[] {
|
||||
0x15C, 0x1E1, 0x2D5, 0x02E, 0x048, 0x1E2, 0x037, 0x0CD,
|
||||
0x02E, 0x056, 0x26A, 0x281, 0x1C2, 0x1A6, 0x296, 0x045,
|
||||
0x041, 0x0AA, 0x095, 0x2CE, 0x003, 0x38F, 0x2CD, 0x1A2,
|
||||
0x036, 0x1AD, 0x04E, 0x090, 0x271, 0x0D3, 0x02E, 0x0D5,
|
||||
0x2D4, 0x032, 0x2CA, 0x281, 0x0AA, 0x04E, 0x024, 0x2D3,
|
||||
0x296, 0x281, 0x0E2, 0x08A, 0x1AA, 0x28A, 0x280, 0x07C,
|
||||
0x286, 0x0A1, 0x1D0, 0x1AD, 0x154, 0x032, 0x2C2, 0x1C1,
|
||||
0x145, 0x02B, 0x2D4, 0x2B0, 0x033, 0x2D5, 0x276, 0x1C1,
|
||||
0x282, 0x10A, 0x2B5, 0x154, 0x003, 0x385, 0x20F, 0x0C4,
|
||||
0x02D, 0x050, 0x266, 0x0D5, 0x033, 0x2D5, 0x276, 0x1C1,
|
||||
0x0D4, 0x2A0, 0x08F, 0x0C4, 0x024, 0x20F, 0x2E2, 0x1AD,
|
||||
0x154, 0x02E, 0x056, 0x26A, 0x281, 0x090, 0x1E5, 0x14E,
|
||||
0x0CF, 0x2B6, 0x1C1, 0x28A, 0x2A1, 0x04E, 0x0D5, 0x003,
|
||||
0x391, 0x122, 0x286, 0x1AD, 0x2D4, 0x028, 0x262, 0x2EA,
|
||||
0x0A2, 0x004, 0x176, 0x295, 0x201, 0x0D5, 0x024, 0x20F,
|
||||
0x116, 0x0C1, 0x056, 0x095, 0x213, 0x004, 0x1EA, 0x28A,
|
||||
0x02A, 0x234, 0x2CE, 0x037, 0x157, 0x0D3, 0x262, 0x026,
|
||||
0x262, 0x2A0, 0x086, 0x106, 0x2A1, 0x126, 0x1E5, 0x266,
|
||||
0x26A, 0x2A1, 0x0E6, 0x1AA, 0x281, 0x2B6, 0x271, 0x154,
|
||||
0x02F, 0x0C4, 0x02D, 0x213, 0x0CE, 0x003, 0x38F, 0x2CD,
|
||||
0x1A2, 0x036, 0x1B5, 0x26A, 0x086, 0x280, 0x086, 0x1AA,
|
||||
0x2A1, 0x226, 0x1AD, 0x0CF, 0x2A6, 0x292, 0x2C6, 0x022,
|
||||
0x1AA, 0x256, 0x0D5, 0x02D, 0x050, 0x266, 0x0D5, 0x004,
|
||||
0x176, 0x295, 0x201, 0x0D3, 0x055, 0x031, 0x2CD, 0x2EA,
|
||||
0x1E2, 0x261, 0x1EA, 0x28A, 0x004, 0x145, 0x026, 0x1A6,
|
||||
0x1C6, 0x1F5, 0x2CE, 0x034, 0x051, 0x146, 0x1E1, 0x0B0,
|
||||
0x1B0, 0x261, 0x0D5, 0x025, 0x142, 0x1C0, 0x07C, 0x0B0,
|
||||
0x1E6, 0x081, 0x044, 0x02F, 0x2CF, 0x081, 0x290, 0x0A2,
|
||||
0x1A6, 0x281, 0x0CD, 0x155, 0x031, 0x1A2, 0x086, 0x262,
|
||||
0x2A1, 0x0CD, 0x0CA, 0x0E6, 0x1E5, 0x003, 0x394, 0x0C5,
|
||||
0x030, 0x26F, 0x053, 0x0C1, 0x1B6, 0x095, 0x2D4, 0x030,
|
||||
0x26F, 0x053, 0x0C0, 0x07C, 0x2E6, 0x295, 0x143, 0x2CD,
|
||||
0x2CE, 0x037, 0x0C9, 0x144, 0x2CD, 0x040, 0x08E, 0x054,
|
||||
0x282, 0x022, 0x2A1, 0x229, 0x053, 0x0D5, 0x262, 0x027,
|
||||
0x26A, 0x1E8, 0x14D, 0x1A2, 0x004, 0x26A, 0x296, 0x281,
|
||||
0x176, 0x295, 0x201, 0x0E2, 0x2C4, 0x143, 0x2D4, 0x026,
|
||||
0x262, 0x2A0, 0x08F, 0x0C4, 0x031, 0x213, 0x2B5, 0x155,
|
||||
0x213, 0x02F, 0x143, 0x121, 0x2A6, 0x1AD, 0x2D4, 0x034,
|
||||
0x0C5, 0x026, 0x295, 0x003, 0x396, 0x2A1, 0x176, 0x295,
|
||||
0x201, 0x0AA, 0x04E, 0x004, 0x1B0, 0x070, 0x275, 0x154,
|
||||
0x026, 0x2C1, 0x2B3, 0x154, 0x2AA, 0x256, 0x0C1, 0x044,
|
||||
0x004, 0x23F
|
||||
},
|
||||
new int[] {
|
||||
0x379, 0x099, 0x348, 0x010, 0x090, 0x196, 0x09C, 0x1FF,
|
||||
0x1B0, 0x32D, 0x244, 0x0DE, 0x201, 0x386, 0x163, 0x11F,
|
||||
0x39B, 0x344, 0x3FE, 0x02F, 0x188, 0x113, 0x3D9, 0x102,
|
||||
0x04A, 0x2E1, 0x1D1, 0x18E, 0x077, 0x262, 0x241, 0x20D,
|
||||
0x1B8, 0x11D, 0x0D0, 0x0A5, 0x29C, 0x24D, 0x3E7, 0x006,
|
||||
0x2D0, 0x1B7, 0x337, 0x178, 0x0F1, 0x1E0, 0x00B, 0x01E,
|
||||
0x0DA, 0x1C6, 0x2D9, 0x00D, 0x28B, 0x34A, 0x252, 0x27A,
|
||||
0x057, 0x0CA, 0x2C2, 0x2E4, 0x3A6, 0x0E3, 0x22B, 0x307,
|
||||
0x174, 0x292, 0x10C, 0x1ED, 0x2FD, 0x2D4, 0x0A7, 0x051,
|
||||
0x34F, 0x07A, 0x1D5, 0x01D, 0x22E, 0x2C2, 0x1DF, 0x08F,
|
||||
0x105, 0x3FE, 0x286, 0x2A2, 0x3B1, 0x131, 0x285, 0x362,
|
||||
0x315, 0x13C, 0x0F9, 0x1A2, 0x28D, 0x246, 0x1B3, 0x12C,
|
||||
0x2AD, 0x0F8, 0x222, 0x0EC, 0x39F, 0x358, 0x014, 0x229,
|
||||
0x0C8, 0x360, 0x1C2, 0x031, 0x098, 0x041, 0x3E4, 0x046,
|
||||
0x332, 0x318, 0x2E3, 0x24E, 0x3E2, 0x1E1, 0x0BE, 0x239,
|
||||
0x306, 0x3A5, 0x352, 0x351, 0x275, 0x0ED, 0x045, 0x229,
|
||||
0x0BF, 0x05D, 0x253, 0x1BE, 0x02E, 0x35A, 0x0E4, 0x2E9,
|
||||
0x17A, 0x166, 0x03C, 0x007
|
||||
});
|
||||
testEncodeDecode(GenericGF.AZTEC_DATA_12,
|
||||
new int[] {
|
||||
0x571, 0xE1B, 0x542, 0xE12, 0x1E2, 0x0DC, 0xCD0, 0xB85,
|
||||
0x69A, 0xA81, 0x709, 0xA6A, 0x584, 0x510, 0x4AA, 0x256,
|
||||
0xCE0, 0x0F8, 0xFB3, 0x5A2, 0x0D9, 0xAD1, 0x389, 0x09C,
|
||||
0x4D3, 0x0B8, 0xD5B, 0x503, 0x2B2, 0xA81, 0x2A8, 0x4E0,
|
||||
0x92D, 0x3A5, 0xA81, 0x388, 0x8A6, 0xAA8, 0xAA0, 0x07C,
|
||||
0xA18, 0xA17, 0x41A, 0xD55, 0x032, 0xB09, 0xC15, 0x142,
|
||||
0xBB5, 0x2B0, 0x0CE, 0xD59, 0xD9C, 0x1A0, 0x90A, 0xAD5,
|
||||
0x540, 0x0F8, 0x583, 0xCC4, 0x0B4, 0x509, 0x98D, 0x50C,
|
||||
0xED5, 0x9D9, 0xC13, 0x52A, 0x023, 0xCC4, 0x092, 0x0FB,
|
||||
0x89A, 0xD55, 0x02E, 0x15A, 0x6AA, 0x049, 0x079, 0x54E,
|
||||
0x33E, 0xB67, 0x068, 0xAA8, 0x44E, 0x354, 0x03E, 0x452,
|
||||
0x2A1, 0x9AD, 0xB50, 0x289, 0x8AE, 0xA28, 0x804, 0x5DA,
|
||||
0x958, 0x04D, 0x509, 0x20F, 0x458, 0xC11, 0x589, 0x584,
|
||||
0xC04, 0x7AA, 0x8A0, 0xAA3, 0x4B3, 0x837, 0x55C, 0xD39,
|
||||
0x882, 0x698, 0xAA0, 0x219, 0x06A, 0x852, 0x679, 0x666,
|
||||
0x9AA, 0xA13, 0x99A, 0xAA0, 0x6B6, 0x9C5, 0x540, 0xBCC,
|
||||
0x40B, 0x613, 0x338, 0x03E, 0x3EC, 0xD68, 0x836, 0x6D6,
|
||||
0x6A2, 0x1A8, 0x021, 0x9AA, 0xA86, 0x266, 0xB4C, 0xFA9,
|
||||
0xA92, 0xB18, 0x226, 0xAA5, 0x635, 0x42D, 0x142, 0x663,
|
||||
0x540, 0x45D, 0xA95, 0x804, 0xD31, 0x543, 0x1B3, 0x6EA,
|
||||
0x78A, 0x617, 0xAA8, 0xA01, 0x145, 0x099, 0xA67, 0x19F,
|
||||
0x5B3, 0x834, 0x145, 0x467, 0x84B, 0x06C, 0x261, 0x354,
|
||||
0x255, 0x09C, 0x01F, 0x0B0, 0x798, 0x811, 0x102, 0xFB3,
|
||||
0xC81, 0xA40, 0xA26, 0x9A8, 0x133, 0x555, 0x0C5, 0xA22,
|
||||
0x1A6, 0x2A8, 0x4CD, 0x328, 0xE67, 0x940, 0x3E5, 0x0C5,
|
||||
0x0C2, 0x6F1, 0x4CC, 0x16D, 0x895, 0xB50, 0x309, 0xBC5,
|
||||
0x330, 0x07C, 0xB9A, 0x955, 0x0EC, 0xDB3, 0x837, 0x325,
|
||||
0x44B, 0x344, 0x023, 0x854, 0xA08, 0x22A, 0x862, 0x914,
|
||||
0xCD5, 0x988, 0x279, 0xA9E, 0x853, 0x5A2, 0x012, 0x6AA,
|
||||
0x5A8, 0x15D, 0xA95, 0x804, 0xE2B, 0x114, 0x3B5, 0x026,
|
||||
0x98A, 0xA02, 0x3CC, 0x40C, 0x613, 0xAD5, 0x558, 0x4C2,
|
||||
0xF50, 0xD21, 0xA99, 0xADB, 0x503, 0x431, 0x426, 0xA54,
|
||||
0x03E, 0x5AA, 0x15D, 0xA95, 0x804, 0xAA1, 0x380, 0x46C,
|
||||
0x070, 0x9D5, 0x540, 0x9AC, 0x1AC, 0xD54, 0xAAA, 0x563,
|
||||
0x044, 0x401, 0x220, 0x9F1, 0x4F0, 0xDAA, 0x170, 0x90F,
|
||||
0x106, 0xE66, 0x85C, 0x2B4, 0xD54, 0x0B8, 0x4D3, 0x52C,
|
||||
0x228, 0x825, 0x512, 0xB67, 0x007, 0xC7D, 0x9AD, 0x106,
|
||||
0xCD6, 0x89C, 0x484, 0xE26, 0x985, 0xC6A, 0xDA8, 0x195,
|
||||
0x954, 0x095, 0x427, 0x049, 0x69D, 0x2D4, 0x09C, 0x445,
|
||||
0x355, 0x455, 0x003, 0xE50, 0xC50, 0xBA0, 0xD6A, 0xA81,
|
||||
0x958, 0x4E0, 0xA8A, 0x15D, 0xA95, 0x806, 0x76A, 0xCEC,
|
||||
0xE0D, 0x048, 0x556, 0xAAA, 0x007, 0xC2C, 0x1E6, 0x205,
|
||||
0xA28, 0x4CC, 0x6A8, 0x676, 0xACE, 0xCE0, 0x9A9, 0x501,
|
||||
0x1E6, 0x204, 0x907, 0xDC4, 0xD6A, 0xA81, 0x70A, 0xD35,
|
||||
0x502, 0x483, 0xCAA, 0x719, 0xF5B, 0x383, 0x455, 0x422,
|
||||
0x71A, 0xA01, 0xF22, 0x915, 0x0CD, 0x6DA, 0x814, 0x4C5,
|
||||
0x751, 0x440, 0x22E, 0xD4A, 0xC02, 0x6A8, 0x490, 0x7A2,
|
||||
0xC60, 0x8AC, 0x4AC, 0x260, 0x23D, 0x545, 0x055, 0x1A5,
|
||||
0x9C1, 0xBAA, 0xE69, 0xCC4, 0x134, 0xC55, 0x010, 0xC83,
|
||||
0x542, 0x933, 0xCB3, 0x34D, 0x550, 0x9CC, 0xD55, 0x035,
|
||||
0xB4E, 0x2AA, 0x05E, 0x620, 0x5B0, 0x999, 0xC01, 0xF1F,
|
||||
0x66B, 0x441, 0xB36, 0xB35, 0x10D, 0x401, 0x0CD, 0x554,
|
||||
0x313, 0x35A, 0x67D, 0x4D4, 0x958, 0xC11, 0x355, 0x2B1,
|
||||
0xAA1, 0x68A, 0x133, 0x1AA, 0x022, 0xED4, 0xAC0, 0x269,
|
||||
0x8AA, 0x18D, 0x9B7, 0x53C, 0x530, 0xBD5, 0x450, 0x08A,
|
||||
0x284, 0xCD3, 0x38C, 0xFAD, 0x9C1, 0xA0A, 0x2A3, 0x3C2,
|
||||
0x583, 0x613, 0x09A, 0xA12, 0xA84, 0xE00, 0xF85, 0x83C,
|
||||
0xC40, 0x888, 0x17D, 0x9E4, 0x0D2, 0x051, 0x34D, 0x409,
|
||||
0x9AA, 0xA86, 0x2D1, 0x10D, 0x315, 0x426, 0x699, 0x473,
|
||||
0x3CA, 0x01F, 0x286, 0x286, 0x137, 0x8A6, 0x60B, 0x6C4,
|
||||
0xADA, 0x818, 0x4DE, 0x299, 0x803, 0xE5C, 0xD4A, 0xA87,
|
||||
0x66D, 0x9C1, 0xB99, 0x2A2, 0x59A, 0x201, 0x1C2, 0xA50,
|
||||
0x411, 0x543, 0x148, 0xA66, 0xACC, 0x413, 0xCD4, 0xF42,
|
||||
0x9AD, 0x100, 0x935, 0x52D, 0x40A, 0xED4, 0xAC0, 0x271,
|
||||
0x588, 0xA1D, 0xA81, 0x34C, 0x550, 0x11E, 0x620, 0x630,
|
||||
0x9D6, 0xAAA, 0xC26, 0x17A, 0x869, 0x0D4, 0xCD6, 0xDA8,
|
||||
0x1A1, 0x8A1, 0x352, 0xA01, 0xF2D, 0x50A, 0xED4, 0xAC0,
|
||||
0x255, 0x09C, 0x023, 0x603, 0x84E, 0xAAA, 0x04D, 0x60D,
|
||||
0x66A, 0xA55, 0x52B, 0x182, 0x220, 0x091, 0x00F, 0x8A7,
|
||||
0x86D, 0x50B, 0x848, 0x788, 0x373, 0x342, 0xE15, 0xA6A,
|
||||
0xA05, 0xC26, 0x9A9, 0x611, 0x441, 0x2A8, 0x95B, 0x380,
|
||||
0x3E3, 0xECD, 0x688, 0x366, 0xB44, 0xE24, 0x271, 0x34C,
|
||||
0x2E3, 0x56D, 0x40C, 0xACA, 0xA04, 0xAA1, 0x382, 0x4B4,
|
||||
0xE96, 0xA04, 0xE22, 0x29A, 0xAA2, 0xA80, 0x1F2, 0x862,
|
||||
0x85D, 0x06B, 0x554, 0x0CA, 0xC27, 0x054, 0x50A, 0xED4,
|
||||
0xAC0, 0x33B, 0x567, 0x670, 0x682, 0x42A, 0xB55, 0x500,
|
||||
0x3E1, 0x60F, 0x310, 0x2D1, 0x426, 0x635, 0x433, 0xB56,
|
||||
0x767, 0x04D, 0x4A8, 0x08F, 0x310, 0x248, 0x3EE, 0x26B,
|
||||
0x554, 0x0B8, 0x569, 0xAA8, 0x124, 0x1E5, 0x538, 0xCFA,
|
||||
0xD9C, 0x1A2, 0xAA1, 0x138, 0xD50, 0x0F9, 0x148, 0xA86,
|
||||
0x6B6, 0xD40, 0xA26, 0x2BA, 0x8A2, 0x011, 0x76A, 0x560,
|
||||
0x135, 0x424, 0x83D, 0x163, 0x045, 0x625, 0x613, 0x011,
|
||||
0xEAA, 0x282, 0xA8D, 0x2CE, 0x0DD, 0x573, 0x4E6, 0x209,
|
||||
0xA62, 0xA80, 0x864, 0x1AA, 0x149, 0x9E5, 0x99A, 0x6AA,
|
||||
0x84E, 0x66A, 0xA81, 0xADA, 0x715, 0x502, 0xF31, 0x02D,
|
||||
0x84C, 0xCE0, 0x0F8, 0xFB3, 0x5A2, 0x0D9, 0xB59, 0xA88,
|
||||
0x6A0, 0x086, 0x6AA, 0xA18, 0x99A, 0xD33, 0xEA6, 0xA4A,
|
||||
0xC60, 0x89A, 0xA95, 0x8D5, 0x0B4, 0x509, 0x98D, 0x501,
|
||||
0x176, 0xA56, 0x013, 0x4C5, 0x50C, 0x6CD, 0xBA9, 0xE29,
|
||||
0x85E, 0xAA2, 0x804, 0x514, 0x266, 0x99C, 0x67D, 0x6CE,
|
||||
0x0D0, 0x515, 0x19E, 0x12C, 0x1B0, 0x984, 0xD50, 0x954,
|
||||
0x270, 0x07C, 0x2C1, 0xE62, 0x044, 0x40B, 0xECF, 0x206,
|
||||
0x902, 0x89A, 0x6A0, 0x4CD, 0x554, 0x316, 0x888, 0x698,
|
||||
0xAA1, 0x334, 0xCA3, 0x99E, 0x500, 0xF94, 0x314, 0x309,
|
||||
0xBC5, 0x330, 0x5B6, 0x256, 0xD40, 0xC26, 0xF14, 0xCC0,
|
||||
0x1F2, 0xE6A, 0x554, 0x3B3, 0x6CE, 0x0DC, 0xC95, 0x12C,
|
||||
0xD10, 0x08E, 0x152, 0x820, 0x8AA, 0x18A, 0x453, 0x356,
|
||||
0x620, 0x9E6, 0xA7A, 0x14D, 0x688, 0x049, 0xAA9, 0x6A0,
|
||||
0x576, 0xA56, 0x013, 0x8AC, 0x450, 0xED4, 0x09A, 0x62A,
|
||||
0x808, 0xF31, 0x031, 0x84E, 0xB55, 0x561, 0x30B, 0xD43,
|
||||
0x486, 0xA66, 0xB6D, 0x40D, 0x0C5, 0x09A, 0x950, 0x0F9,
|
||||
0x6A8, 0x576, 0xA56, 0x012, 0xA84, 0xE01, 0x1B0, 0x1C2,
|
||||
0x755, 0x502, 0x6B0, 0x6B3, 0x552, 0xAA9, 0x58C, 0x111,
|
||||
0x004, 0x882, 0x7C5, 0x3C3, 0x6A8, 0x5C2, 0x43C, 0x41B,
|
||||
0x99A, 0x170, 0xAD3, 0x550, 0x2E1, 0x34D, 0x4B0, 0x8A2,
|
||||
0x095, 0x44A, 0xD9C, 0x01F, 0x1F6, 0x6B4, 0x41B, 0x35A,
|
||||
0x271, 0x213, 0x89A, 0x617, 0x1AB, 0x6A0, 0x656, 0x550,
|
||||
0x255, 0x09C, 0x125, 0xA74, 0xB50, 0x271, 0x114, 0xD55,
|
||||
0x154, 0x00F, 0x943, 0x142, 0xE83, 0x5AA, 0xA06, 0x561,
|
||||
0x382, 0xA28, 0x576, 0xA56, 0x019, 0xDAB, 0x3B3, 0x834,
|
||||
0x121, 0x55A, 0xAA8, 0x01F, 0x0B0, 0x798, 0x816, 0x8A1,
|
||||
0x331, 0xAA1, 0x9DA, 0xB3B, 0x382, 0x6A5, 0x404, 0x798,
|
||||
0x812, 0x41F, 0x713, 0x5AA, 0xA05, 0xC2B, 0x4D5, 0x409,
|
||||
0x20F, 0x2A9, 0xC67, 0xD6C, 0xE0D, 0x155, 0x089, 0xC6A,
|
||||
0x807, 0xC8A, 0x454, 0x335, 0xB6A, 0x051, 0x315, 0xD45,
|
||||
0x100, 0x8BB, 0x52B, 0x009, 0xAA1, 0x241, 0xE8B, 0x182,
|
||||
0x2B1, 0x2B0, 0x980, 0x8F5, 0x514, 0x154, 0x696, 0x706,
|
||||
0xEAB, 0x9A7, 0x310, 0x4D3, 0x154, 0x043, 0x20D, 0x50A,
|
||||
0x4CF, 0x2CC, 0xD35, 0x542, 0x733, 0x554, 0x0D6, 0xD38,
|
||||
0xAA8, 0x179, 0x881, 0x6C2, 0x667, 0x007, 0xC7D, 0x9AD,
|
||||
0x106, 0xCDA, 0xCD4, 0x435, 0x004, 0x335, 0x550, 0xC4C,
|
||||
0xD69, 0x9F5, 0x352, 0x563, 0x044, 0xD54, 0xAC6, 0xA85,
|
||||
0xA28, 0x4CC, 0x6A8, 0x08B, 0xB52, 0xB00, 0x9A6, 0x2A8,
|
||||
0x636, 0x6DD, 0x4F1, 0x4C2, 0xF55, 0x140, 0x228, 0xA13,
|
||||
0x34C, 0xE33, 0xEB6, 0x706, 0x828, 0xA8C, 0xF09, 0x60D,
|
||||
0x84C, 0x26A, 0x84A, 0xA13, 0x803, 0xE16, 0x0F3, 0x102,
|
||||
0x220, 0x5F6, 0x790, 0x348, 0x144, 0xD35, 0x026, 0x6AA,
|
||||
0xA18, 0xB44, 0x434, 0xC55, 0x099, 0xA65, 0x1CC, 0xF28,
|
||||
0x07C, 0xA18, 0xA18, 0x4DE, 0x299, 0x82D, 0xB12, 0xB6A,
|
||||
0x061, 0x378, 0xA66, 0x00F, 0x973, 0x52A, 0xA1D, 0x9B6,
|
||||
0x706, 0xE64, 0xA89, 0x668, 0x804, 0x70A, 0x941, 0x045,
|
||||
0x50C, 0x522, 0x99A, 0xB31, 0x04F, 0x353, 0xD0A, 0x6B4,
|
||||
0x402, 0x4D5, 0x4B5, 0x02B, 0xB52, 0xB00, 0x9C5, 0x622,
|
||||
0x876, 0xA04, 0xD31, 0x540, 0x479, 0x881, 0x8C2, 0x75A,
|
||||
0xAAB, 0x098, 0x5EA, 0x1A4, 0x353, 0x35B, 0x6A0, 0x686,
|
||||
0x284, 0xD4A, 0x807, 0xCB5, 0x42B, 0xB52, 0xB00, 0x954,
|
||||
0x270, 0x08D, 0x80E, 0x13A, 0xAA8, 0x135, 0x835, 0x9AA,
|
||||
0x801, 0xF14, 0xF0D, 0xAA1, 0x709, 0x0F1, 0x06E, 0x668,
|
||||
0x5C2, 0xB4D, 0x540, 0xB84, 0xD35, 0x2C2, 0x288, 0x255,
|
||||
0x12B, 0x670, 0x07C, 0x7D9, 0xAD1, 0x06C, 0xD68, 0x9C4,
|
||||
0x84E, 0x269, 0x85C, 0x6AD, 0xA81, 0x959, 0x540, 0x954,
|
||||
0x270, 0x496, 0x9D2, 0xD40, 0x9C4, 0x453, 0x554, 0x550,
|
||||
0x03E, 0x50C, 0x50B, 0xA0D, 0x6AA, 0x819, 0x584, 0xE0A,
|
||||
0x8A1, 0x5DA, 0x958, 0x067, 0x6AC, 0xECE, 0x0D0, 0x485,
|
||||
0x56A, 0xAA0, 0x07C, 0x2C1, 0xE62, 0x05A, 0x284, 0xCC6,
|
||||
0xA86, 0x76A, 0xCEC, 0xE09, 0xA95, 0x011, 0xE62, 0x049,
|
||||
0x07D, 0xC4D, 0x6AA, 0x817, 0x0AD, 0x355, 0x024, 0x83C,
|
||||
0xAA7, 0x19F, 0x5B3, 0x834, 0x554, 0x227, 0x1AA, 0x01F,
|
||||
0x229, 0x150, 0xCD6, 0xDA8, 0x144, 0xC57, 0x514, 0x402,
|
||||
0x2ED, 0x4AC, 0x026, 0xA84, 0x907, 0xA2C, 0x608, 0xAC4,
|
||||
0xAC2, 0x602, 0x3D5, 0x450, 0x551, 0xA59, 0xC1B, 0xAAE,
|
||||
0x69C, 0xC41, 0x34C, 0x550, 0x10C, 0x835, 0x429, 0x33C,
|
||||
0xB33, 0x4D5, 0x509, 0xCCD, 0x550, 0x35B, 0x4E2, 0xAA0,
|
||||
0x5E6, 0x205, 0xB09, 0x99C, 0x09F
|
||||
},
|
||||
new int[] {
|
||||
0xD54, 0x221, 0x154, 0x7CD, 0xBF3, 0x112, 0x89B, 0xC5E,
|
||||
0x9CD, 0x07E, 0xFB6, 0x78F, 0x7FA, 0x16F, 0x377, 0x4B4,
|
||||
0x62D, 0x475, 0xBC2, 0x861, 0xB72, 0x9D0, 0x76A, 0x5A1,
|
||||
0x22A, 0xF74, 0xDBA, 0x8B1, 0x139, 0xDCD, 0x012, 0x293,
|
||||
0x705, 0xA34, 0xDD5, 0x3D2, 0x7F8, 0x0A6, 0x89A, 0x346,
|
||||
0xCE0, 0x690, 0x40E, 0xFF3, 0xC4D, 0x97F, 0x9C9, 0x016,
|
||||
0x73A, 0x923, 0xBCE, 0xFA9, 0xE6A, 0xB92, 0x02A, 0x07C,
|
||||
0x04B, 0x8D5, 0x753, 0x42E, 0x67E, 0x87C, 0xEE6, 0xD7D,
|
||||
0x2BF, 0xFB2, 0xFF8, 0x42F, 0x4CB, 0x214, 0x779, 0x02D,
|
||||
0x606, 0xA02, 0x08A, 0xD4F, 0xB87, 0xDDF, 0xC49, 0xB51,
|
||||
0x0E9, 0xF89, 0xAEF, 0xC92, 0x383, 0x98D, 0x367, 0xBD3,
|
||||
0xA55, 0x148, 0x9DB, 0x913, 0xC79, 0x6FF, 0x387, 0x6EA,
|
||||
0x7FA, 0xC1B, 0x12D, 0x303, 0xBCA, 0x503, 0x0FB, 0xB14,
|
||||
0x0D4, 0xAD1, 0xAFC, 0x9DD, 0x404, 0x145, 0x6E5, 0x8ED,
|
||||
0xF94, 0xD72, 0x645, 0xA21, 0x1A8, 0xABF, 0xC03, 0x91E,
|
||||
0xD53, 0x48C, 0x471, 0x4E4, 0x408, 0x33C, 0x5DF, 0x73D,
|
||||
0xA2A, 0x454, 0xD77, 0xC48, 0x2F5, 0x96A, 0x9CF, 0x047,
|
||||
0x611, 0xE92, 0xC2F, 0xA98, 0x56D, 0x919, 0x615, 0x535,
|
||||
0x67A, 0x8C1, 0x2E2, 0xBC4, 0xBE8, 0x328, 0x04F, 0x257,
|
||||
0x3F9, 0xFA5, 0x477, 0x12E, 0x94B, 0x116, 0xEF7, 0x65F,
|
||||
0x6B3, 0x915, 0xC64, 0x9AF, 0xB6C, 0x6A2, 0x50D, 0xEA3,
|
||||
0x26E, 0xC23, 0x817, 0xA42, 0x71A, 0x9DD, 0xDA8, 0x84D,
|
||||
0x3F3, 0x85B, 0xB00, 0x1FC, 0xB0A, 0xC2F, 0x00C, 0x095,
|
||||
0xC58, 0x0E3, 0x807, 0x962, 0xC4B, 0x29A, 0x6FC, 0x958,
|
||||
0xD29, 0x59E, 0xB14, 0x95A, 0xEDE, 0xF3D, 0xFB8, 0x0E5,
|
||||
0x348, 0x2E7, 0x38E, 0x56A, 0x410, 0x3B1, 0x4B0, 0x793,
|
||||
0xAB7, 0x0BC, 0x648, 0x719, 0xE3E, 0xFB4, 0x3B4, 0xE5C,
|
||||
0x950, 0xD2A, 0x50B, 0x76F, 0x8D2, 0x3C7, 0xECC, 0x87C,
|
||||
0x53A, 0xBA7, 0x4C3, 0x148, 0x437, 0x820, 0xECD, 0x660,
|
||||
0x095, 0x2F4, 0x661, 0x6A4, 0xB74, 0x5F3, 0x1D2, 0x7EC,
|
||||
0x8E2, 0xA40, 0xA6F, 0xFC3, 0x3BE, 0x1E9, 0x52C, 0x233,
|
||||
0x173, 0x4EF, 0xA7C, 0x40B, 0x14C, 0x88D, 0xF30, 0x8D9,
|
||||
0xBDB, 0x0A6, 0x940, 0xD46, 0xB2B, 0x03E, 0x46A, 0x641,
|
||||
0xF08, 0xAFF, 0x496, 0x68A, 0x7A4, 0x0BA, 0xD43, 0x515,
|
||||
0xB26, 0xD8F, 0x05C, 0xD6E, 0xA2C, 0xF25, 0x628, 0x4E5,
|
||||
0x81D, 0xA2A, 0x1FF, 0x302, 0xFBD, 0x6D9, 0x711, 0xD8B,
|
||||
0xE5C, 0x5CF, 0x42E, 0x008, 0x863, 0xB6F, 0x1E1, 0x3DA,
|
||||
0xACE, 0x82B, 0x2DB, 0x7EB, 0xC15, 0x79F, 0xA79, 0xDAF,
|
||||
0x00D, 0x2F6, 0x0CE, 0x370, 0x7E8, 0x9E6, 0x89F, 0xAE9,
|
||||
0x175, 0xA95, 0x06B, 0x9DF, 0xAFF, 0x45B, 0x823, 0xAA4,
|
||||
0xC79, 0x773, 0x886, 0x854, 0x0A5, 0x6D1, 0xE55, 0xEBB,
|
||||
0x518, 0xE50, 0xF8F, 0x8CC, 0x834, 0x388, 0xCD2, 0xFC1,
|
||||
0xA55, 0x1F8, 0xD1F, 0xE08, 0xF93, 0x362, 0xA22, 0x9FA,
|
||||
0xCE5, 0x3C3, 0xDD4, 0xC53, 0xB94, 0xAD0, 0x6EB, 0x68D,
|
||||
0x660, 0x8FC, 0xBCD, 0x914, 0x16F, 0x4C0, 0x134, 0xE1A,
|
||||
0x76F, 0x9CB, 0x660, 0xEA0, 0x320, 0x15A, 0xCE3, 0x7E8,
|
||||
0x03E, 0xB9A, 0xC90, 0xA14, 0x256, 0x1A8, 0x639, 0x7C6,
|
||||
0xA59, 0xA65, 0x956, 0x9E4, 0x592, 0x6A9, 0xCFF, 0x4DC,
|
||||
0xAA3, 0xD2A, 0xFDE, 0xA87, 0xBF5, 0x9F0, 0xC32, 0x94F,
|
||||
0x675, 0x9A6, 0x369, 0x648, 0x289, 0x823, 0x498, 0x574,
|
||||
0x8D1, 0xA13, 0xD1A, 0xBB5, 0xA19, 0x7F7, 0x775, 0x138,
|
||||
0x949, 0xA4C, 0xE36, 0x126, 0xC85, 0xE05, 0xFEE, 0x962,
|
||||
0x36D, 0x08D, 0xC76, 0x1E1, 0x1EC, 0x8D7, 0x231, 0xB68,
|
||||
0x03C, 0x1DE, 0x7DF, 0x2B1, 0x09D, 0xC81, 0xDA4, 0x8F7,
|
||||
0x6B9, 0x947, 0x9B0
|
||||
});
|
||||
// synthetic test cases
|
||||
testEncodeDecodeRandom(GenericGF.AZTEC_PARAM, 2, 5); // compact mode message
|
||||
testEncodeDecodeRandom(GenericGF.AZTEC_PARAM, 4, 6); // full mode message
|
||||
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_6, 10, 7);
|
||||
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_6, 20, 12);
|
||||
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_8, 20, 11);
|
||||
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_8, 128, 127);
|
||||
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_10, 128, 128);
|
||||
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_10, 768, 255);
|
||||
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_12, 3072, 1023);
|
||||
}
|
||||
|
||||
public static void corrupt(int[] received, int howMany, Random random, int max) {
|
||||
BitSet corrupted = new BitSet(received.length);
|
||||
for (int j = 0; j < howMany; j++) {
|
||||
int location = random.nextInt(received.length);
|
||||
int value = random.nextInt(max);
|
||||
if (corrupted.get(location) || received[location] == value) {
|
||||
j--;
|
||||
} else {
|
||||
corrupted.set(location);
|
||||
received[location] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void testEncodeDecodeRandom(GenericGF field, int dataSize, int ecSize) {
|
||||
assertTrue("Invalid data size for " + field, dataSize > 0 && dataSize <= field.getSize() - 3);
|
||||
assertTrue("Invalid ECC size for " + field, ecSize > 0 && ecSize + dataSize <= field.getSize());
|
||||
ReedSolomonEncoder encoder = new ReedSolomonEncoder(field);
|
||||
int[] message = new int[dataSize + ecSize];
|
||||
int[] dataWords = new int[dataSize];
|
||||
int[] ecWords = new int[ecSize];
|
||||
Random random = getPseudoRandom();
|
||||
int iterations = field.getSize() > 256 ? 1 : DECODER_RANDOM_TEST_ITERATIONS;
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
// generate random data
|
||||
for (int k = 0; k < dataSize; k++) {
|
||||
dataWords[k] = random.nextInt(field.getSize());
|
||||
}
|
||||
// generate ECC words
|
||||
System.arraycopy(dataWords, 0, message, 0, dataWords.length);
|
||||
encoder.encode(message, ecWords.length);
|
||||
System.arraycopy(message, dataSize, ecWords, 0, ecSize);
|
||||
// check to see if Decoder can fix up to ecWords/2 random errors
|
||||
testDecoder(field, dataWords, ecWords);
|
||||
}
|
||||
}
|
||||
|
||||
private static void testEncodeDecode(GenericGF field, int[] dataWords, int[] ecWords) {
|
||||
testEncoder(field, dataWords, ecWords);
|
||||
testDecoder(field, dataWords, ecWords);
|
||||
}
|
||||
|
||||
private static void testEncoder(GenericGF field, int[] dataWords, int[] ecWords) {
|
||||
ReedSolomonEncoder encoder = new ReedSolomonEncoder(field);
|
||||
int[] messageExpected = new int[dataWords.length + ecWords.length];
|
||||
int[] message = new int[dataWords.length + ecWords.length];
|
||||
System.arraycopy(dataWords, 0, messageExpected, 0, dataWords.length);
|
||||
System.arraycopy(ecWords, 0, messageExpected, dataWords.length, ecWords.length);
|
||||
System.arraycopy(dataWords, 0, message, 0, dataWords.length);
|
||||
encoder.encode(message, ecWords.length);
|
||||
assertDataEquals("Encode in " + field + " (" + dataWords.length + ',' + ecWords.length + ") failed",
|
||||
messageExpected, message);
|
||||
}
|
||||
|
||||
private static void testDecoder(GenericGF field, int[] dataWords, int[] ecWords) {
|
||||
ReedSolomonDecoder decoder = new ReedSolomonDecoder(field);
|
||||
int[] message = new int[dataWords.length + ecWords.length];
|
||||
int maxErrors = ecWords.length / 2;
|
||||
Random random = getPseudoRandom();
|
||||
int iterations = field.getSize() > 256 ? 1 : DECODER_TEST_ITERATIONS;
|
||||
for (int j = 0; j < iterations; j++) {
|
||||
for (int i = 0; i < ecWords.length; i++) {
|
||||
if (i > 10 && i < ecWords.length / 2 - 10) {
|
||||
// performance improvement - skip intermediate cases in long-running tests
|
||||
i += ecWords.length / 10;
|
||||
}
|
||||
System.arraycopy(dataWords, 0, message, 0, dataWords.length);
|
||||
System.arraycopy(ecWords, 0, message, dataWords.length, ecWords.length);
|
||||
corrupt(message, i, random, field.getSize());
|
||||
try {
|
||||
decoder.decode(message, ecWords.length);
|
||||
} catch (ReedSolomonException e) {
|
||||
// fail only if maxErrors exceeded
|
||||
assertTrue("Decode in " + field + " (" + dataWords.length + ',' + ecWords.length + ") failed at " +
|
||||
i + " errors: " + e,
|
||||
i > maxErrors);
|
||||
// else stop
|
||||
break;
|
||||
}
|
||||
if (i < maxErrors) {
|
||||
assertDataEquals("Decode in " + field + " (" + dataWords.length + ',' + ecWords.length + ") failed at " +
|
||||
i + " errors",
|
||||
dataWords,
|
||||
message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertDataEquals(String message, int[] expected, int[] received) {
|
||||
for (int i = 0; i < expected.length; i++) {
|
||||
if (expected[i] != received[i]) {
|
||||
fail(message + ". Mismatch at " + i + ". Expected " + arrayToString(expected) + ", got " +
|
||||
arrayToString(Arrays.copyOf(received, expected.length)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String arrayToString(int[] data) {
|
||||
StringBuilder sb = new StringBuilder("{");
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
sb.append(String.format(i > 0 ? ",%X" : "%X", data[i]));
|
||||
}
|
||||
return sb.append('}').toString();
|
||||
}
|
||||
|
||||
private static Random getPseudoRandom() {
|
||||
return new Random(0xDEADBEEF);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.datamatrix;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author bbrown@google.com (Brian Brown)
|
||||
*/
|
||||
public final class DataMatrixBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public DataMatrixBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/datamatrix-1", new MultiFormatReader(), BarcodeFormat.DATA_MATRIX);
|
||||
addTest(21, 21, 0.0f);
|
||||
addTest(21, 21, 90.0f);
|
||||
addTest(21, 21, 180.0f);
|
||||
addTest(21, 21, 270.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.datamatrix;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class DataMatrixBlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public DataMatrixBlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/datamatrix-2", new MultiFormatReader(), BarcodeFormat.DATA_MATRIX);
|
||||
addTest(13, 13, 0, 1, 0.0f);
|
||||
addTest(15, 15, 0, 1, 90.0f);
|
||||
addTest(17, 16, 0, 1, 180.0f);
|
||||
addTest(15, 15, 0, 1, 270.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.datamatrix;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author gitlost
|
||||
*/
|
||||
public final class DataMatrixBlackBox3TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public DataMatrixBlackBox3TestCase() {
|
||||
super("src/test/resources/blackbox/datamatrix-3", new MultiFormatReader(), BarcodeFormat.DATA_MATRIX);
|
||||
addTest(18, 18, 0.0f);
|
||||
addTest(17, 17, 90.0f);
|
||||
addTest(18, 18, 180.0f);
|
||||
addTest(18, 18, 270.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.datamatrix;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.datamatrix.encoder.SymbolShapeHint;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author satorux@google.com (Satoru Takabayashi) - creator
|
||||
* @author dswitkin@google.com (Daniel Switkin) - ported and expanded from C++
|
||||
*/
|
||||
public final class DataMatrixWriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testDataMatrixImageWriter() {
|
||||
|
||||
Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.DATA_MATRIX_SHAPE, SymbolShapeHint.FORCE_SQUARE);
|
||||
|
||||
int bigEnough = 64;
|
||||
DataMatrixWriter writer = new DataMatrixWriter();
|
||||
BitMatrix matrix = writer.encode("Hello Google", BarcodeFormat.DATA_MATRIX, bigEnough, bigEnough, hints);
|
||||
assertNotNull(matrix);
|
||||
assertTrue(bigEnough >= matrix.getWidth());
|
||||
assertTrue(bigEnough >= matrix.getHeight());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataMatrixWriter() {
|
||||
|
||||
Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.DATA_MATRIX_SHAPE, SymbolShapeHint.FORCE_SQUARE);
|
||||
|
||||
int bigEnough = 14;
|
||||
DataMatrixWriter writer = new DataMatrixWriter();
|
||||
BitMatrix matrix = writer.encode("Hello Me", BarcodeFormat.DATA_MATRIX, bigEnough, bigEnough, hints);
|
||||
assertNotNull(matrix);
|
||||
assertEquals(bigEnough, matrix.getWidth());
|
||||
assertEquals(bigEnough, matrix.getHeight());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataMatrixTooSmall() {
|
||||
// The DataMatrix will not fit in this size, so the matrix should come back bigger
|
||||
int tooSmall = 8;
|
||||
DataMatrixWriter writer = new DataMatrixWriter();
|
||||
BitMatrix matrix = writer.encode("http://www.google.com/", BarcodeFormat.DATA_MATRIX, tooSmall, tooSmall, null);
|
||||
assertNotNull(matrix);
|
||||
assertTrue(tooSmall < matrix.getWidth());
|
||||
assertTrue(tooSmall < matrix.getHeight());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.datamatrix.decoder;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author bbrown@google.com (Brian Brown)
|
||||
*/
|
||||
public final class DecodedBitStreamParserTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testAsciiStandardDecode() throws Exception {
|
||||
// ASCII characters 0-127 are encoded as the value + 1
|
||||
byte[] bytes = {(byte) ('a' + 1), (byte) ('b' + 1), (byte) ('c' + 1),
|
||||
(byte) ('A' + 1), (byte) ('B' + 1), (byte) ('C' + 1)};
|
||||
String decodedString = DecodedBitStreamParser.decode(bytes).getText();
|
||||
assertEquals("abcABC", decodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsciiDoubleDigitDecode() throws Exception {
|
||||
// ASCII double digit (00 - 99) Numeric Value + 130
|
||||
byte[] bytes = {(byte) 130 , (byte) (1 + 130),
|
||||
(byte) (98 + 130), (byte) (99 + 130)};
|
||||
String decodedString = DecodedBitStreamParser.decode(bytes).getText();
|
||||
assertEquals("00019899", decodedString);
|
||||
}
|
||||
|
||||
// TODO(bbrown): Add test cases for each encoding type
|
||||
// TODO(bbrown): Add test cases for switching encoding types
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2006 Jeremias Maerki
|
||||
*
|
||||
* 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.datamatrix.encoder;
|
||||
|
||||
final class DebugPlacement extends DefaultPlacement {
|
||||
|
||||
DebugPlacement(String codewords, int numcols, int numrows) {
|
||||
super(codewords, numcols, numrows);
|
||||
}
|
||||
|
||||
String[] toBitFieldStringArray() {
|
||||
byte[] bits = getBits();
|
||||
int numrows = getNumrows();
|
||||
int numcols = getNumcols();
|
||||
String[] array = new String[numrows];
|
||||
int startpos = 0;
|
||||
for (int row = 0; row < numrows; row++) {
|
||||
StringBuilder sb = new StringBuilder(bits.length);
|
||||
for (int i = 0; i < numcols; i++) {
|
||||
sb.append(bits[startpos + i] == 1 ? '1' : '0');
|
||||
}
|
||||
array[row] = sb.toString();
|
||||
startpos += numcols;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2006 Jeremias Maerki.
|
||||
*
|
||||
* 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.datamatrix.encoder;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for the ECC200 error correction.
|
||||
*/
|
||||
public final class ErrorCorrectionTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testRS() {
|
||||
//Sample from Annexe R in ISO/IEC 16022:2000(E)
|
||||
char[] cw = {142, 164, 186};
|
||||
SymbolInfo symbolInfo = SymbolInfo.lookup(3);
|
||||
CharSequence s = ErrorCorrection.encodeECC200(String.valueOf(cw), symbolInfo);
|
||||
assertEquals("142 164 186 114 25 5 88 102", HighLevelEncodeTestCase.visualize(s));
|
||||
|
||||
//"A" encoded (ASCII encoding + 2 padding characters)
|
||||
cw = new char[]{66, 129, 70};
|
||||
s = ErrorCorrection.encodeECC200(String.valueOf(cw), symbolInfo);
|
||||
assertEquals("66 129 70 138 234 82 82 95", HighLevelEncodeTestCase.visualize(s));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,563 @@
|
||||
/*
|
||||
* Copyright 2006 Jeremias Maerki.
|
||||
*
|
||||
* 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.datamatrix.encoder;
|
||||
|
||||
import junit.framework.ComparisonFailure;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Tests for {@link HighLevelEncoder} and {@link MinimalEncoder}
|
||||
*/
|
||||
public final class HighLevelEncodeTestCase extends Assert {
|
||||
|
||||
private static final SymbolInfo[] TEST_SYMBOLS = {
|
||||
new SymbolInfo(false, 3, 5, 8, 8, 1),
|
||||
new SymbolInfo(false, 5, 7, 10, 10, 1),
|
||||
/*rect*/new SymbolInfo(true, 5, 7, 16, 6, 1),
|
||||
new SymbolInfo(false, 8, 10, 12, 12, 1),
|
||||
/*rect*/new SymbolInfo(true, 10, 11, 14, 6, 2),
|
||||
new SymbolInfo(false, 13, 0, 0, 0, 1),
|
||||
new SymbolInfo(false, 77, 0, 0, 0, 1)
|
||||
//The last entries are fake entries to test special conditions with C40 encoding
|
||||
};
|
||||
|
||||
private static void useTestSymbols() {
|
||||
SymbolInfo.overrideSymbolSet(TEST_SYMBOLS);
|
||||
}
|
||||
|
||||
private static void resetSymbols() {
|
||||
SymbolInfo.overrideSymbolSet(SymbolInfo.PROD_SYMBOLS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testASCIIEncodation() {
|
||||
|
||||
String visualized = encodeHighLevel("123456");
|
||||
assertEquals("142 164 186", visualized);
|
||||
|
||||
visualized = encodeHighLevel("123456£");
|
||||
assertEquals("142 164 186 235 36", visualized);
|
||||
|
||||
visualized = encodeHighLevel("30Q324343430794<OQQ");
|
||||
assertEquals("160 82 162 173 173 173 137 224 61 80 82 82", visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testC40EncodationBasic1() {
|
||||
|
||||
String visualized = encodeHighLevel("AIMAIMAIM");
|
||||
assertEquals("230 91 11 91 11 91 11 254", visualized);
|
||||
//230 shifts to C40 encodation, 254 unlatches, "else" case
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testC40EncodationBasic2() {
|
||||
|
||||
String visualized = encodeHighLevel("AIMAIAB");
|
||||
assertEquals("230 91 11 90 255 254 67 129", visualized);
|
||||
//"B" is normally encoded as "15" (one C40 value)
|
||||
//"else" case: "B" is encoded as ASCII
|
||||
|
||||
visualized = encodeHighLevel("AIMAIAb");
|
||||
assertEquals("66 74 78 66 74 66 99 129", visualized); //Encoded as ASCII
|
||||
//Alternative solution:
|
||||
//assertEquals("230 91 11 90 255 254 99 129", visualized);
|
||||
//"b" is normally encoded as "Shift 3, 2" (two C40 values)
|
||||
//"else" case: "b" is encoded as ASCII
|
||||
|
||||
visualized = encodeHighLevel("AIMAIMAIMË");
|
||||
assertEquals("230 91 11 91 11 91 11 254 235 76", visualized);
|
||||
//Alternative solution:
|
||||
//assertEquals("230 91 11 91 11 91 11 11 9 254", visualized);
|
||||
//Expl: 230 = shift to C40, "91 11" = "AIM",
|
||||
//"11 9" = "<22>" = "Shift 2, UpperShift, <char>
|
||||
//"else" case
|
||||
|
||||
visualized = encodeHighLevel("AIMAIMAIMë");
|
||||
assertEquals("230 91 11 91 11 91 11 254 235 108", visualized); //Activate when additional rectangulars are available
|
||||
//Expl: 230 = shift to C40, "91 11" = "AIM",
|
||||
//"<22>" in C40 encodes to: 1 30 2 11 which doesn't fit into a triplet
|
||||
//"10 243" =
|
||||
//254 = unlatch, 235 = Upper Shift, 108 = <20> = 0xEB/235 - 128 + 1
|
||||
//"else" case
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testC40EncodationSpecExample() {
|
||||
//Example in Figure 1 in the spec
|
||||
String visualized = encodeHighLevel("A1B2C3D4E5F6G7H8I9J0K1L2");
|
||||
assertEquals("230 88 88 40 8 107 147 59 67 126 206 78 126 144 121 35 47 254", visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testC40EncodationSpecialCases1() {
|
||||
|
||||
//Special tests avoiding ultra-long test strings because these tests are only used
|
||||
//with the 16x48 symbol (47 data codewords)
|
||||
useTestSymbols();
|
||||
|
||||
String visualized = encodeHighLevel("AIMAIMAIMAIMAIMAIM", false);
|
||||
assertEquals("230 91 11 91 11 91 11 91 11 91 11 91 11", visualized);
|
||||
//case "a": Unlatch is not required
|
||||
|
||||
visualized = encodeHighLevel("AIMAIMAIMAIMAIMAI", false);
|
||||
assertEquals("230 91 11 91 11 91 11 91 11 91 11 90 241", visualized);
|
||||
//case "b": Add trailing shift 0 and Unlatch is not required
|
||||
|
||||
visualized = encodeHighLevel("AIMAIMAIMAIMAIMA");
|
||||
assertEquals("230 91 11 91 11 91 11 91 11 91 11 254 66", visualized);
|
||||
//case "c": Unlatch and write last character in ASCII
|
||||
|
||||
resetSymbols();
|
||||
|
||||
visualized = encodeHighLevel("AIMAIMAIMAIMAIMAI");
|
||||
assertEquals("230 91 11 91 11 91 11 91 11 91 11 254 66 74 129 237", visualized);
|
||||
|
||||
visualized = encodeHighLevel("AIMAIMAIMA");
|
||||
assertEquals("230 91 11 91 11 91 11 66", visualized);
|
||||
//case "d": Skip Unlatch and write last character in ASCII
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testC40EncodationSpecialCases2() {
|
||||
|
||||
String visualized = encodeHighLevel("AIMAIMAIMAIMAIMAIMAI");
|
||||
assertEquals("230 91 11 91 11 91 11 91 11 91 11 91 11 254 66 74", visualized);
|
||||
//available > 2, rest = 2 --> unlatch and encode as ASCII
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextEncodation() {
|
||||
|
||||
String visualized = encodeHighLevel("aimaimaim");
|
||||
assertEquals("239 91 11 91 11 91 11 254", visualized);
|
||||
//239 shifts to Text encodation, 254 unlatches
|
||||
|
||||
visualized = encodeHighLevel("aimaimaim'");
|
||||
assertEquals("239 91 11 91 11 91 11 254 40 129", visualized);
|
||||
//assertEquals("239 91 11 91 11 91 11 7 49 254", visualized);
|
||||
//This is an alternative, but doesn't strictly follow the rules in the spec.
|
||||
|
||||
visualized = encodeHighLevel("aimaimaIm");
|
||||
assertEquals("239 91 11 91 11 87 218 110", visualized);
|
||||
|
||||
visualized = encodeHighLevel("aimaimaimB");
|
||||
assertEquals("239 91 11 91 11 91 11 254 67 129", visualized);
|
||||
|
||||
visualized = encodeHighLevel("aimaimaim{txt}\u0004");
|
||||
assertEquals("239 91 11 91 11 91 11 254 124 117 121 117 126 5 129 237", visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testX12Encodation() {
|
||||
|
||||
//238 shifts to X12 encodation, 254 unlatches
|
||||
|
||||
String visualized = encodeHighLevel("ABC>ABC123>AB");
|
||||
assertEquals("238 89 233 14 192 100 207 44 31 67", visualized);
|
||||
|
||||
visualized = encodeHighLevel("ABC>ABC123>ABC");
|
||||
assertEquals("238 89 233 14 192 100 207 44 31 254 67 68", visualized);
|
||||
|
||||
visualized = encodeHighLevel("ABC>ABC123>ABCD");
|
||||
assertEquals("238 89 233 14 192 100 207 44 31 96 82 254", visualized);
|
||||
|
||||
visualized = encodeHighLevel("ABC>ABC123>ABCDE");
|
||||
assertEquals("238 89 233 14 192 100 207 44 31 96 82 70", visualized);
|
||||
|
||||
visualized = encodeHighLevel("ABC>ABC123>ABCDEF");
|
||||
assertEquals("238 89 233 14 192 100 207 44 31 96 82 254 70 71 129 237", visualized);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEDIFACTEncodation() {
|
||||
|
||||
//240 shifts to EDIFACT encodation
|
||||
|
||||
String visualized = encodeHighLevel(".A.C1.3.DATA.123DATA.123DATA");
|
||||
assertEquals("240 184 27 131 198 236 238 16 21 1 187 28 179 16 21 1 187 28 179 16 21 1",
|
||||
visualized);
|
||||
|
||||
visualized = encodeHighLevel(".A.C1.3.X.X2..");
|
||||
assertEquals("240 184 27 131 198 236 238 98 230 50 47 47", visualized);
|
||||
|
||||
visualized = encodeHighLevel(".A.C1.3.X.X2.");
|
||||
assertEquals("240 184 27 131 198 236 238 98 230 50 47 129", visualized);
|
||||
|
||||
visualized = encodeHighLevel(".A.C1.3.X.X2");
|
||||
assertEquals("240 184 27 131 198 236 238 98 230 50", visualized);
|
||||
|
||||
visualized = encodeHighLevel(".A.C1.3.X.X");
|
||||
assertEquals("240 184 27 131 198 236 238 98 230 31", visualized);
|
||||
|
||||
visualized = encodeHighLevel(".A.C1.3.X.");
|
||||
assertEquals("240 184 27 131 198 236 238 98 231 192", visualized);
|
||||
|
||||
visualized = encodeHighLevel(".A.C1.3.X");
|
||||
assertEquals("240 184 27 131 198 236 238 89", visualized);
|
||||
|
||||
//Checking temporary unlatch from EDIFACT
|
||||
visualized = encodeHighLevel(".XXX.XXX.XXX.XXX.XXX.XXX.üXX.XXX.XXX.XXX.XXX.XXX.XXX");
|
||||
assertEquals("240 185 134 24 185 134 24 185 134 24 185 134 24 185 134 24 185 134 24"
|
||||
+ " 124 47 235 125 240" //<-- this is the temporary unlatch
|
||||
+ " 97 139 152 97 139 152 97 139 152 97 139 152 97 139 152 97 139 152 89 89",
|
||||
visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBase256Encodation() {
|
||||
|
||||
//231 shifts to Base256 encodation
|
||||
|
||||
String visualized = encodeHighLevel("\u00ABäöüé\u00BB");
|
||||
assertEquals("231 44 108 59 226 126 1 104", visualized);
|
||||
visualized = encodeHighLevel("\u00ABäöüéà\u00BB");
|
||||
assertEquals("231 51 108 59 226 126 1 141 254 129", visualized);
|
||||
visualized = encodeHighLevel("\u00ABäöüéàá\u00BB");
|
||||
assertEquals("231 44 108 59 226 126 1 141 36 147", visualized);
|
||||
|
||||
visualized = encodeHighLevel(" 23£"); //ASCII only (for reference)
|
||||
assertEquals("33 153 235 36 129", visualized);
|
||||
|
||||
visualized = encodeHighLevel("\u00ABäöüé\u00BB 234"); //Mixed Base256 + ASCII
|
||||
assertEquals("231 50 108 59 226 126 1 104 33 153 53 129", visualized);
|
||||
|
||||
visualized = encodeHighLevel("\u00ABäöüé\u00BB 23£ 1234567890123456789");
|
||||
assertEquals("231 54 108 59 226 126 1 104 99 10 161 167 33 142 164 186 208"
|
||||
+ " 220 142 164 186 208 58 129 59 209 104 254 150 45", visualized);
|
||||
|
||||
visualized = encodeHighLevel(createBinaryMessage(20));
|
||||
assertEquals("231 44 108 59 226 126 1 141 36 5 37 187 80 230 123 17 166 60 210 103 253 150",
|
||||
visualized);
|
||||
visualized = encodeHighLevel(createBinaryMessage(19)); //padding necessary at the end
|
||||
assertEquals("231 63 108 59 226 126 1 141 36 5 37 187 80 230 123 17 166 60 210 103 1 129",
|
||||
visualized);
|
||||
|
||||
visualized = encodeHighLevel(createBinaryMessage(276));
|
||||
assertStartsWith("231 38 219 2 208 120 20 150 35", visualized);
|
||||
assertEndsWith("146 40 194 129", visualized);
|
||||
|
||||
visualized = encodeHighLevel(createBinaryMessage(277));
|
||||
assertStartsWith("231 38 220 2 208 120 20 150 35", visualized);
|
||||
assertEndsWith("146 40 190 87", visualized);
|
||||
}
|
||||
|
||||
private static String createBinaryMessage(int len) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("\u00ABäöüéàá-");
|
||||
for (int i = 0; i < len - 9; i++) {
|
||||
sb.append('\u00B7');
|
||||
}
|
||||
sb.append('\u00BB');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void assertStartsWith(String expected, String actual) {
|
||||
if (!actual.startsWith(expected)) {
|
||||
throw new ComparisonFailure(null, expected, actual.substring(0, expected.length()));
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertEndsWith(String expected, String actual) {
|
||||
if (!actual.endsWith(expected)) {
|
||||
throw new ComparisonFailure(null, expected, actual.substring(actual.length() - expected.length()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnlatchingFromC40() {
|
||||
|
||||
String visualized = encodeHighLevel("AIMAIMAIMAIMaimaimaim");
|
||||
assertEquals("230 91 11 91 11 91 11 254 66 74 78 239 91 11 91 11 91 11", visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnlatchingFromText() {
|
||||
|
||||
String visualized = encodeHighLevel("aimaimaimaim12345678");
|
||||
assertEquals("239 91 11 91 11 91 11 91 11 254 142 164 186 208 129 237", visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHelloWorld() {
|
||||
|
||||
String visualized = encodeHighLevel("Hello World!");
|
||||
assertEquals("73 239 116 130 175 123 148 64 158 233 254 34", visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug1664266() {
|
||||
//There was an exception and the encoder did not handle the unlatching from
|
||||
//EDIFACT encoding correctly
|
||||
|
||||
String visualized = encodeHighLevel("CREX-TAN:h");
|
||||
assertEquals("68 83 70 89 46 85 66 79 59 105", visualized);
|
||||
|
||||
visualized = encodeHighLevel("CREX-TAN:hh");
|
||||
assertEquals("68 83 70 89 46 85 66 79 59 105 105 129", visualized);
|
||||
|
||||
visualized = encodeHighLevel("CREX-TAN:hhh");
|
||||
assertEquals("68 83 70 89 46 85 66 79 59 105 105 105", visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testX12Unlatch() {
|
||||
String visualized = encodeHighLevel("*DTCP01");
|
||||
assertEquals("43 69 85 68 81 131 129 56", visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testX12Unlatch2() {
|
||||
String visualized = encodeHighLevel("*DTCP0");
|
||||
assertEquals("238 9 10 104 141", visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug3048549() {
|
||||
//There was an IllegalArgumentException for an illegal character here because
|
||||
//of an encoding problem of the character 0x0060 in Java source code.
|
||||
|
||||
String visualized = encodeHighLevel("fiykmj*Rh2`,e6");
|
||||
assertEquals("103 106 122 108 110 107 43 83 105 51 97 45 102 55 129 237", visualized);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMacroCharacters() {
|
||||
|
||||
String visualized = encodeHighLevel("[)>\u001E05\u001D5555\u001C6666\u001E\u0004");
|
||||
//assertEquals("92 42 63 31 135 30 185 185 29 196 196 31 5 129 87 237", visualized);
|
||||
assertEquals("236 185 185 29 196 196 129 56", visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodingWithStartAsX12AndLatchToEDIFACTInTheMiddle() {
|
||||
|
||||
String visualized = encodeHighLevel("*MEMANT-1F-MESTECH");
|
||||
assertEquals("240 168 209 77 4 229 45 196 107 77 21 53 5 12 135 192", visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testX12AndEDIFACTSpecErrors() {
|
||||
//X12 encoding error with spec conform float point comparisons in lookAheadTest()
|
||||
String visualized = encodeHighLevel("AAAAAAAAAAA**\u00FCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
|
||||
assertEquals("230 89 191 89 191 89 191 89 178 56 114 10 243 177 63 89 191 89 191 89 191 89 191 89 191 89 191 89 " +
|
||||
"191 89 191 89 191 254 66 129", visualized);
|
||||
//X12 encoding error with integer comparisons in lookAheadTest()
|
||||
visualized = encodeHighLevel("AAAAAAAAAAAA0+****AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
|
||||
assertEquals("238 89 191 89 191 89 191 89 191 254 240 194 186 170 170 160 65 4 16 65 4 16 65 4 16 65 4 16 65 4 " +
|
||||
"16 65 4 16 65 4 16 65 124 129 167 62 212 107", visualized);
|
||||
//EDIFACT encoding error with spec conform float point comparisons in lookAheadTest()
|
||||
visualized = encodeHighLevel("AAAAAAAAAAA++++\u00FCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
|
||||
assertEquals("230 89 191 89 191 89 191 254 66 66 44 44 44 44 235 125 230 89 191 89 191 89 191 89 191 89 191 89 " +
|
||||
"191 89 191 89 191 89 191 89 191 254 129 17 167 62 212 107", visualized);
|
||||
//EDIFACT encoding error with integer comparisons in lookAheadTest()
|
||||
visualized = encodeHighLevel("++++++++++AAa0 0++++++++++++++++++++++++++++++");
|
||||
assertEquals("240 174 186 235 174 186 235 174 176 65 124 98 240 194 12 43 174 186 235 174 186 235 174 186 235 " +
|
||||
"174 186 235 174 186 235 174 186 235 174 186 235 173 240 129 167 62 212 107", visualized);
|
||||
visualized = encodeHighLevel("AAAAAAAAAAAA*+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
|
||||
assertEquals("230 89 191 89 191 89 191 89 191 7 170 64 191 89 191 89 191 89 191 89 191 89 191 89 191 89 191 89 " +
|
||||
"191 89 191 66", visualized);
|
||||
visualized = encodeHighLevel("AAAAAAAAAAA*0a0 *AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
|
||||
assertEquals("230 89 191 89 191 89 191 89 178 56 227 6 228 7 183 89 191 89 191 89 191 89 191 89 191 89 191 89 " +
|
||||
"191 89 191 89 191 254 66 66", visualized);
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testSizes() {
|
||||
int[] sizes = new int[2];
|
||||
encodeHighLevel("A", sizes);
|
||||
assertEquals(3, sizes[0]);
|
||||
assertEquals(3, sizes[1]);
|
||||
|
||||
encodeHighLevel("AB", sizes);
|
||||
assertEquals(3, sizes[0]);
|
||||
assertEquals(3, sizes[1]);
|
||||
|
||||
encodeHighLevel("ABC", sizes);
|
||||
assertEquals(3, sizes[0]);
|
||||
assertEquals(3, sizes[1]);
|
||||
|
||||
encodeHighLevel("ABCD", sizes);
|
||||
assertEquals(5, sizes[0]);
|
||||
assertEquals(5, sizes[1]);
|
||||
|
||||
encodeHighLevel("ABCDE", sizes);
|
||||
assertEquals(5, sizes[0]);
|
||||
assertEquals(5, sizes[1]);
|
||||
|
||||
encodeHighLevel("ABCDEF", sizes);
|
||||
assertEquals(5, sizes[0]);
|
||||
assertEquals(5, sizes[1]);
|
||||
|
||||
encodeHighLevel("ABCDEFG", sizes);
|
||||
assertEquals(8, sizes[0]);
|
||||
assertEquals(8, sizes[1]);
|
||||
|
||||
encodeHighLevel("ABCDEFGH", sizes);
|
||||
assertEquals(8, sizes[0]);
|
||||
assertEquals(8, sizes[1]);
|
||||
|
||||
encodeHighLevel("ABCDEFGHI", sizes);
|
||||
assertEquals(8, sizes[0]);
|
||||
assertEquals(8, sizes[1]);
|
||||
|
||||
encodeHighLevel("ABCDEFGHIJ", sizes);
|
||||
assertEquals(8, sizes[0]);
|
||||
assertEquals(8, sizes[1]);
|
||||
|
||||
encodeHighLevel("a", sizes);
|
||||
assertEquals(3, sizes[0]);
|
||||
assertEquals(3, sizes[1]);
|
||||
|
||||
encodeHighLevel("ab", sizes);
|
||||
assertEquals(3, sizes[0]);
|
||||
assertEquals(3, sizes[1]);
|
||||
|
||||
encodeHighLevel("abc", sizes);
|
||||
assertEquals(3, sizes[0]);
|
||||
assertEquals(3, sizes[1]);
|
||||
|
||||
encodeHighLevel("abcd", sizes);
|
||||
assertEquals(5, sizes[0]);
|
||||
assertEquals(5, sizes[1]);
|
||||
|
||||
encodeHighLevel("abcdef", sizes);
|
||||
assertEquals(5, sizes[0]);
|
||||
assertEquals(5, sizes[1]);
|
||||
|
||||
encodeHighLevel("abcdefg", sizes);
|
||||
assertEquals(8, sizes[0]);
|
||||
assertEquals(8, sizes[1]);
|
||||
|
||||
encodeHighLevel("abcdefgh", sizes);
|
||||
assertEquals(8, sizes[0]);
|
||||
assertEquals(8, sizes[1]);
|
||||
|
||||
encodeHighLevel("+", sizes);
|
||||
assertEquals(3, sizes[0]);
|
||||
assertEquals(3, sizes[1]);
|
||||
|
||||
encodeHighLevel("++", sizes);
|
||||
assertEquals(3, sizes[0]);
|
||||
assertEquals(3, sizes[1]);
|
||||
|
||||
encodeHighLevel("+++", sizes);
|
||||
assertEquals(3, sizes[0]);
|
||||
assertEquals(3, sizes[1]);
|
||||
|
||||
encodeHighLevel("++++", sizes);
|
||||
assertEquals(5, sizes[0]);
|
||||
assertEquals(5, sizes[1]);
|
||||
|
||||
encodeHighLevel("+++++", sizes);
|
||||
assertEquals(5, sizes[0]);
|
||||
assertEquals(5, sizes[1]);
|
||||
|
||||
encodeHighLevel("++++++", sizes);
|
||||
assertEquals(8, sizes[0]);
|
||||
assertEquals(8, sizes[1]);
|
||||
|
||||
encodeHighLevel("+++++++", sizes);
|
||||
assertEquals(8, sizes[0]);
|
||||
assertEquals(8, sizes[1]);
|
||||
|
||||
encodeHighLevel("++++++++", sizes);
|
||||
assertEquals(8, sizes[0]);
|
||||
assertEquals(8, sizes[1]);
|
||||
|
||||
encodeHighLevel("+++++++++", sizes);
|
||||
assertEquals(8, sizes[0]);
|
||||
assertEquals(8, sizes[1]);
|
||||
|
||||
encodeHighLevel("\u00F0\u00F0" +
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF", sizes);
|
||||
assertEquals(114, sizes[0]);
|
||||
assertEquals(62, sizes[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testECIs() {
|
||||
|
||||
String visualized = visualize(MinimalEncoder.encodeHighLevel("that particularly stands out to me is \u0625\u0650" +
|
||||
"\u062C\u064E\u0651\u0627\u0635 (\u02BE\u0101\u1E63) \"pear\", suggested to have originated from Hebrew " +
|
||||
"\u05D0\u05B7\u05D2\u05B8\u05BC\u05E1 (ag\u00E1s)"));
|
||||
assertEquals("239 209 151 206 214 92 122 140 35 158 144 162 52 205 55 171 137 23 67 206 218 175 147 113 15 254" +
|
||||
" 116 33 241 25 231 186 14 212 64 253 151 252 159 33 41 241 27 231 83 171 53 209 35 25 134 6 42 33 35 239 184" +
|
||||
" 31 193 234 7 252 205 101 127 241 209 34 24 5 22 23 221 148 179 239 128 140 92 187 106 204 198 59 19 25 114" +
|
||||
" 248 118 36 254 231 106 196 19 239 101 27 107 69 189 112 236 156 252 16 174 125 24 10 125 116 42 129",
|
||||
visualized);
|
||||
|
||||
visualized = visualize(MinimalEncoder.encodeHighLevel("that particularly stands out to me is \u0625\u0650" +
|
||||
"\u062C\u064E\u0651\u0627\u0635 (\u02BE\u0101\u1E63) \"pear\", suggested to have originated from Hebrew " +
|
||||
"\u05D0\u05B7\u05D2\u05B8\u05BC\u05E1 (ag\u00E1s)", StandardCharsets.UTF_8, -1 , SymbolShapeHint.FORCE_NONE));
|
||||
assertEquals("241 27 239 209 151 206 214 92 122 140 35 158 144 162 52 205 55 171 137 23 67 206 218 175 147 113" +
|
||||
" 15 254 116 33 231 202 33 131 77 154 119 225 163 238 206 28 249 93 36 150 151 53 108 246 145 228 217 71" +
|
||||
" 199 42 33 35 239 184 31 193 234 7 252 205 101 127 241 209 34 24 5 22 23 221 148 179 239 128 140 92 187 106" +
|
||||
" 204 198 59 19 25 114 248 118 36 254 231 43 133 212 175 38 220 44 6 125 49 172 93 189 209 111 61 217 203 62" +
|
||||
" 116 42 129 1 151 46 196 91 241 137 32 182 77 227 122 18 168 63 213 108 4 154 49 199 94 244 140 35 185 80",
|
||||
visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPadding() {
|
||||
int[] sizes = new int[2];
|
||||
encodeHighLevel("IS010000000000000000000000S1118058599124123S21.2.250.1.213.1.4.8 S3FIRST NAMETEST S5MS618-06" +
|
||||
"-1985S713201S4LASTNAMETEST", sizes);
|
||||
assertEquals(86, sizes[0]);
|
||||
assertEquals(86, sizes[1]);
|
||||
}
|
||||
|
||||
|
||||
private static void encodeHighLevel(String msg, int[] sizes) {
|
||||
sizes[0] = HighLevelEncoder.encodeHighLevel(msg).length();
|
||||
sizes[1] = MinimalEncoder.encodeHighLevel(msg).length();
|
||||
}
|
||||
|
||||
private static String encodeHighLevel(String msg) {
|
||||
return encodeHighLevel(msg, true);
|
||||
}
|
||||
|
||||
private static String encodeHighLevel(String msg, boolean compareSizeToMinimalEncoder) {
|
||||
CharSequence encoded = HighLevelEncoder.encodeHighLevel(msg);
|
||||
CharSequence encoded2 = MinimalEncoder.encodeHighLevel(msg);
|
||||
assertTrue(!compareSizeToMinimalEncoder || encoded2.length() <= encoded.length());
|
||||
return visualize(encoded);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string of char codewords into a different string which lists each character
|
||||
* using its decimal value.
|
||||
*
|
||||
* @param codewords the codewords
|
||||
* @return the visualized codewords
|
||||
*/
|
||||
static String visualize(CharSequence codewords) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < codewords.length(); i++) {
|
||||
if (i > 0) {
|
||||
sb.append(' ');
|
||||
}
|
||||
sb.append((int) codewords.charAt(i));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2006 Jeremias Maerki
|
||||
*
|
||||
* 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.datamatrix.encoder;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Tests the DataMatrix placement algorithm.
|
||||
*/
|
||||
public final class PlacementTestCase extends Assert {
|
||||
|
||||
private static final Pattern SPACE = Pattern.compile(" ");
|
||||
|
||||
@Test
|
||||
public void testPlacement() {
|
||||
String codewords = unvisualize("66 74 78 66 74 78 129 56 35 102 192 96 226 100 156 1 107 221"); //"AIMAIM" encoded
|
||||
DebugPlacement placement = new DebugPlacement(codewords, 12, 12);
|
||||
placement.place();
|
||||
String[] expected = {
|
||||
"011100001111",
|
||||
"001010101000",
|
||||
"010001010100",
|
||||
"001010100010",
|
||||
"000111000100",
|
||||
"011000010100",
|
||||
"000100001101",
|
||||
"011000010000",
|
||||
"001100001101",
|
||||
"100010010111",
|
||||
"011101011010",
|
||||
"001011001010"};
|
||||
String[] actual = placement.toBitFieldStringArray();
|
||||
for (int i = 0; i < actual.length; i++) {
|
||||
assertEquals("Row " + i, expected[i], actual[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static String unvisualize(CharSequence visualized) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String token : SPACE.split(visualized)) {
|
||||
sb.append((char) Integer.parseInt(token));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2006 Jeremias Maerki
|
||||
*
|
||||
* 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.datamatrix.encoder;
|
||||
|
||||
import com.google.zxing.Dimension;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests the SymbolInfo class.
|
||||
*/
|
||||
public final class SymbolInfoTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testSymbolInfo() {
|
||||
SymbolInfo info = SymbolInfo.lookup(3);
|
||||
assertEquals(5, info.getErrorCodewords());
|
||||
assertEquals(8, info.matrixWidth);
|
||||
assertEquals(8, info.matrixHeight);
|
||||
assertEquals(10, info.getSymbolWidth());
|
||||
assertEquals(10, info.getSymbolHeight());
|
||||
|
||||
info = SymbolInfo.lookup(3, SymbolShapeHint.FORCE_RECTANGLE);
|
||||
assertEquals(7, info.getErrorCodewords());
|
||||
assertEquals(16, info.matrixWidth);
|
||||
assertEquals(6, info.matrixHeight);
|
||||
assertEquals(18, info.getSymbolWidth());
|
||||
assertEquals(8, info.getSymbolHeight());
|
||||
|
||||
info = SymbolInfo.lookup(9);
|
||||
assertEquals(11, info.getErrorCodewords());
|
||||
assertEquals(14, info.matrixWidth);
|
||||
assertEquals(6, info.matrixHeight);
|
||||
assertEquals(32, info.getSymbolWidth());
|
||||
assertEquals(8, info.getSymbolHeight());
|
||||
|
||||
info = SymbolInfo.lookup(9, SymbolShapeHint.FORCE_SQUARE);
|
||||
assertEquals(12, info.getErrorCodewords());
|
||||
assertEquals(14, info.matrixWidth);
|
||||
assertEquals(14, info.matrixHeight);
|
||||
assertEquals(16, info.getSymbolWidth());
|
||||
assertEquals(16, info.getSymbolHeight());
|
||||
|
||||
try {
|
||||
SymbolInfo.lookup(1559);
|
||||
fail("There's no rectangular symbol for more than 1558 data codewords");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
//expected
|
||||
}
|
||||
try {
|
||||
SymbolInfo.lookup(50, SymbolShapeHint.FORCE_RECTANGLE);
|
||||
fail("There's no rectangular symbol for 50 data codewords");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
//expected
|
||||
}
|
||||
|
||||
info = SymbolInfo.lookup(35);
|
||||
assertEquals(24, info.getSymbolWidth());
|
||||
assertEquals(24, info.getSymbolHeight());
|
||||
|
||||
Dimension fixedSize = new Dimension(26, 26);
|
||||
info = SymbolInfo.lookup(35,
|
||||
SymbolShapeHint.FORCE_NONE, fixedSize, fixedSize, false);
|
||||
assertNotNull(info);
|
||||
assertEquals(26, info.getSymbolWidth());
|
||||
assertEquals(26, info.getSymbolHeight());
|
||||
|
||||
info = SymbolInfo.lookup(45,
|
||||
SymbolShapeHint.FORCE_NONE, fixedSize, fixedSize, false);
|
||||
assertNull(info);
|
||||
|
||||
Dimension minSize = fixedSize;
|
||||
Dimension maxSize = new Dimension(32, 32);
|
||||
|
||||
info = SymbolInfo.lookup(35,
|
||||
SymbolShapeHint.FORCE_NONE, minSize, maxSize, false);
|
||||
assertNotNull(info);
|
||||
assertEquals(26, info.getSymbolWidth());
|
||||
assertEquals(26, info.getSymbolHeight());
|
||||
|
||||
info = SymbolInfo.lookup(40,
|
||||
SymbolShapeHint.FORCE_NONE, minSize, maxSize, false);
|
||||
assertNotNull(info);
|
||||
assertEquals(26, info.getSymbolWidth());
|
||||
assertEquals(26, info.getSymbolHeight());
|
||||
|
||||
info = SymbolInfo.lookup(45,
|
||||
SymbolShapeHint.FORCE_NONE, minSize, maxSize, false);
|
||||
assertNotNull(info);
|
||||
assertEquals(32, info.getSymbolWidth());
|
||||
assertEquals(32, info.getSymbolHeight());
|
||||
|
||||
info = SymbolInfo.lookup(63,
|
||||
SymbolShapeHint.FORCE_NONE, minSize, maxSize, false);
|
||||
assertNull(info);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.inverted;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* Inverted barcodes
|
||||
*/
|
||||
public final class InvertedDataMatrixBlackBoxTestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public InvertedDataMatrixBlackBoxTestCase() {
|
||||
super("src/test/resources/blackbox/inverted", new MultiFormatReader(), BarcodeFormat.DATA_MATRIX);
|
||||
addHint(DecodeHintType.ALSO_INVERTED);
|
||||
addTest(1, 1, 0.0f);
|
||||
addTest(1, 1, 90.0f);
|
||||
addTest(1, 1, 180.0f);
|
||||
addTest(1, 1, 270.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.inverted;
|
||||
|
||||
import com.google.zxing.common.AbstractNegativeBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* Without hint inverted barcodes should not be found.
|
||||
*/
|
||||
public final class NoHintInvertedDataMatrixBlackBoxTestCase extends AbstractNegativeBlackBoxTestCase {
|
||||
|
||||
public NoHintInvertedDataMatrixBlackBoxTestCase() {
|
||||
super("src/test/resources/blackbox/inverted");
|
||||
addTest(0, 0.0f);
|
||||
addTest(0, 90.0f);
|
||||
addTest(0, 180.0f);
|
||||
addTest(0, 270.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2022 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.maxicode;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* Tests all characters in Set A.
|
||||
*
|
||||
* @author Daniel Gredler
|
||||
* @see <a href="https://github.com/zxing/zxing/issues/1543">Defect 1543</a>
|
||||
*/
|
||||
public final class MaxiCodeBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public MaxiCodeBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/maxicode-1", new MultiFormatReader(), BarcodeFormat.MAXICODE);
|
||||
addHint(DecodeHintType.PURE_BARCODE);
|
||||
addTest(1, 1, 0.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.maxicode;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* Tests {@link MaxiCodeReader} against a fixed set of test images.
|
||||
*/
|
||||
public final class Maxicode1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Maxicode1TestCase() {
|
||||
super("src/test/resources/blackbox/maxicode-1", new MultiFormatReader(), BarcodeFormat.MAXICODE);
|
||||
addTest(6, 6, 0.0f);
|
||||
}
|
||||
|
||||
}
|
||||
61
java_test/java/com/google/zxing/multi/MultiTestCase.java
Normal file
61
java_test/java/com/google/zxing/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.Result;
|
||||
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());
|
||||
Result[] 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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.Result;
|
||||
import com.google.zxing.ResultMetadataType;
|
||||
import com.google.zxing.ResultPoint;
|
||||
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();
|
||||
Result[] results = reader.decodeMultiple(bitmap);
|
||||
assertNotNull(results);
|
||||
assertEquals(4, results.length);
|
||||
|
||||
Collection<String> barcodeContents = new HashSet<>();
|
||||
for (Result result : results) {
|
||||
barcodeContents.add(result.getText());
|
||||
assertEquals(BarcodeFormat.QR_CODE, result.getBarcodeFormat());
|
||||
assertNotNull(result.getResultMetadata());
|
||||
}
|
||||
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() {
|
||||
Result sa1 = new Result("SA1", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
Result sa2 = new Result("SA2", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
Result sa3 = new Result("SA3", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
sa1.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, 2);
|
||||
sa1.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
sa2.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (1 << 4) + 2);
|
||||
sa2.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
sa3.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (2 << 4) + 2);
|
||||
sa3.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
|
||||
Result nsa = new Result("NotSA", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
nsa.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
|
||||
List<Result> inputs = Arrays.asList(sa3, sa1, nsa, sa2);
|
||||
|
||||
List<Result> results = QRCodeMultiReader.processStructuredAppend(inputs);
|
||||
assertNotNull(results);
|
||||
assertEquals(2, results.size());
|
||||
|
||||
Collection<String> barcodeContents = new HashSet<>();
|
||||
for (Result result : results) {
|
||||
barcodeContents.add(result.getText());
|
||||
}
|
||||
Collection<String> expectedContents = new HashSet<>();
|
||||
expectedContents.add("SA1SA2SA3");
|
||||
expectedContents.add("NotSA");
|
||||
assertEquals(expectedContents, barcodeContents);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.negative;
|
||||
|
||||
import com.google.zxing.common.AbstractNegativeBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* Additional random images with high contrast patterns which should not find any barcodes.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class FalsePositives2BlackBoxTestCase extends AbstractNegativeBlackBoxTestCase {
|
||||
|
||||
public FalsePositives2BlackBoxTestCase() {
|
||||
super("src/test/resources/blackbox/falsepositives-2");
|
||||
addTest(4, 0.0f);
|
||||
addTest(4, 90.0f);
|
||||
addTest(4, 180.0f);
|
||||
addTest(4, 270.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.negative;
|
||||
|
||||
import com.google.zxing.common.AbstractNegativeBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* This test ensures that random images with high contrast patterns do not decode as barcodes.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class FalsePositivesBlackBoxTestCase extends AbstractNegativeBlackBoxTestCase {
|
||||
|
||||
public FalsePositivesBlackBoxTestCase() {
|
||||
super("src/test/resources/blackbox/falsepositives");
|
||||
addTest(2, 0.0f);
|
||||
addTest(2, 90.0f);
|
||||
addTest(2, 180.0f);
|
||||
addTest(2, 270.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.negative;
|
||||
|
||||
import com.google.zxing.common.AbstractNegativeBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* This test ensures that partial barcodes do not decode.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class PartialBlackBoxTestCase extends AbstractNegativeBlackBoxTestCase {
|
||||
|
||||
public PartialBlackBoxTestCase() {
|
||||
super("src/test/resources/blackbox/partial");
|
||||
addTest(1, 0.0f);
|
||||
addTest(1, 90.0f);
|
||||
addTest(1, 180.0f);
|
||||
addTest(1, 270.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.negative;
|
||||
|
||||
import com.google.zxing.common.AbstractNegativeBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* This test ensures that unsupported barcodes do not decode.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UnsupportedBlackBoxTestCase extends AbstractNegativeBlackBoxTestCase {
|
||||
|
||||
public UnsupportedBlackBoxTestCase() {
|
||||
super("src/test/resources/blackbox/unsupported");
|
||||
addTest(0, 0.0f);
|
||||
addTest(0, 90.0f);
|
||||
addTest(0, 180.0f);
|
||||
addTest(0, 270.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2011 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author dsbnatut@gmail.com (Kazuki Nishiura)
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class CodaBarWriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
doTest("B515-3/B",
|
||||
"00000" +
|
||||
"1001001011" + "0110101001" + "0101011001" + "0110101001" + "0101001101" +
|
||||
"0110010101" + "01101101011" + "01001001011" +
|
||||
"00000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode2() {
|
||||
doTest("T123T",
|
||||
"00000" +
|
||||
"1011001001" + "0101011001" + "0101001011" + "0110010101" + "01011001001" +
|
||||
"00000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAltStartEnd() {
|
||||
assertEquals(encode("T123456789-$T"), encode("A123456789-$A"));
|
||||
}
|
||||
|
||||
private static void doTest(String input, CharSequence expected) {
|
||||
BitMatrix result = encode(input);
|
||||
assertEquals(expected, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
private static BitMatrix encode(String input) {
|
||||
return new CodaBarWriter().encode(input, BarcodeFormat.CODABAR, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class CodabarBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public CodabarBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/codabar-1", new MultiFormatReader(), BarcodeFormat.CODABAR);
|
||||
addTest(11, 11, 0.0f);
|
||||
addTest(11, 11, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class Code128BlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code128BlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/code128-1", new MultiFormatReader(), BarcodeFormat.CODE_128);
|
||||
addTest(6, 6, 0.0f);
|
||||
addTest(6, 6, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class Code128BlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code128BlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/code128-2", new MultiFormatReader(), BarcodeFormat.CODE_128);
|
||||
addTest(36, 39, 0.0f);
|
||||
addTest(36, 39, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class Code128BlackBox3TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code128BlackBox3TestCase() {
|
||||
super("src/test/resources/blackbox/code128-3", new MultiFormatReader(), BarcodeFormat.CODE_128);
|
||||
addTest(2, 2, 0.0f);
|
||||
addTest(2, 2, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
359
java_test/java/com/google/zxing/oned/Code128WriterTestCase.java
Normal file
359
java_test/java/com/google/zxing/oned/Code128WriterTestCase.java
Normal file
@@ -0,0 +1,359 @@
|
||||
/*
|
||||
* Copyright 2014 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.Writer;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.EnumMap;
|
||||
|
||||
/**
|
||||
* Tests {@link Code128Writer}.
|
||||
*/
|
||||
public class Code128WriterTestCase extends Assert {
|
||||
|
||||
private static final String FNC1 = "11110101110";
|
||||
private static final String FNC2 = "11110101000";
|
||||
private static final String FNC3 = "10111100010";
|
||||
private static final String FNC4A = "11101011110";
|
||||
private static final String FNC4B = "10111101110";
|
||||
private static final String START_CODE_A = "11010000100";
|
||||
private static final String START_CODE_B = "11010010000";
|
||||
private static final String START_CODE_C = "11010011100";
|
||||
private static final String SWITCH_CODE_A = "11101011110";
|
||||
private static final String SWITCH_CODE_B = "10111101110";
|
||||
private static final String QUIET_SPACE = "00000";
|
||||
private static final String STOP = "1100011101011";
|
||||
private static final String LF = "10000110010";
|
||||
|
||||
private Writer writer;
|
||||
private Code128Reader reader;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
writer = new Code128Writer();
|
||||
reader = new Code128Reader();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithFunc3() throws Exception {
|
||||
String toEncode = "\u00f3" + "123";
|
||||
String expected = QUIET_SPACE + START_CODE_B + FNC3 +
|
||||
// "1" "2" "3" check digit 51
|
||||
"10011100110" + "11001110010" + "11001011100" + "11101000110" + STOP + QUIET_SPACE;
|
||||
|
||||
BitMatrix result = encode(toEncode, false, "123");
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(expected, actual);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, "123");
|
||||
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithFunc2() throws Exception {
|
||||
String toEncode = "\u00f2" + "123";
|
||||
String expected = QUIET_SPACE + START_CODE_B + FNC2 +
|
||||
// "1" "2" "3" check digit 56
|
||||
"10011100110" + "11001110010" + "11001011100" + "11100010110" + STOP + QUIET_SPACE;
|
||||
|
||||
BitMatrix result = encode(toEncode, false, "123");
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(expected, actual);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, "123");
|
||||
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithFunc1() throws Exception {
|
||||
String toEncode = "\u00f1" + "123";
|
||||
String expected = QUIET_SPACE + START_CODE_C + FNC1 +
|
||||
// "12" "3" check digit 92
|
||||
"10110011100" + SWITCH_CODE_B + "11001011100" + "10101111000" + STOP + QUIET_SPACE;
|
||||
|
||||
BitMatrix result = encode(toEncode, false, "123");
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(expected, actual);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, "123");
|
||||
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoundtrip() throws Exception {
|
||||
String toEncode = "\u00f1" + "10958" + "\u00f1" + "17160526";
|
||||
String expected = "1095817160526";
|
||||
|
||||
BitMatrix encResult = encode(toEncode, false, expected);
|
||||
|
||||
int width = encResult.getWidth();
|
||||
encResult = encode(toEncode, true, expected);
|
||||
//Compact encoding has one latch less and encodes as STARTA,FNC1,1,CODEC,09,58,FNC1,17,16,05,26
|
||||
assertEquals(width, encResult.getWidth() + 11);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongCompact() throws Exception {
|
||||
//test longest possible input
|
||||
String toEncode = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
|
||||
encode(toEncode, true, toEncode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShift() throws Exception {
|
||||
//compare fast to compact
|
||||
String toEncode = "a\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\n";
|
||||
BitMatrix result = encode(toEncode, false, toEncode);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, toEncode);
|
||||
|
||||
//big difference since the fast algoritm doesn't make use of SHIFT
|
||||
assertEquals(width, result.getWidth() + 253);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDigitMixCompaction() throws Exception {
|
||||
//compare fast to compact
|
||||
String toEncode = "A1A12A123A1234A12345AA1AA12AA123AA1234AA1235";
|
||||
BitMatrix result = encode(toEncode, false, toEncode);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, toEncode);
|
||||
|
||||
//very good, no difference
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompaction1() throws Exception {
|
||||
//compare fast to compact
|
||||
String toEncode = "AAAAAAAAAAA12AAAAAAAAA";
|
||||
BitMatrix result = encode(toEncode, false, toEncode);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, toEncode);
|
||||
|
||||
//very good, no difference
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompaction2() throws Exception {
|
||||
//compare fast to compact
|
||||
String toEncode = "AAAAAAAAAAA1212aaaaaaaaa";
|
||||
BitMatrix result = encode(toEncode, false, toEncode);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, toEncode);
|
||||
|
||||
//very good, no difference
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithFunc4() throws Exception {
|
||||
String toEncode = "\u00f4" + "123";
|
||||
String expected = QUIET_SPACE + START_CODE_B + FNC4B +
|
||||
// "1" "2" "3" check digit 59
|
||||
"10011100110" + "11001110010" + "11001011100" + "11100011010" + STOP + QUIET_SPACE;
|
||||
|
||||
BitMatrix result = encode(toEncode, false, null);
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(expected, actual);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, null);
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithFncsAndNumberInCodesetA() throws Exception {
|
||||
String toEncode = "\n" + "\u00f1" + "\u00f4" + "1" + "\n";
|
||||
|
||||
String expected = QUIET_SPACE + START_CODE_A + LF + FNC1 + FNC4A +
|
||||
"10011100110" + LF + "10101111000" + STOP + QUIET_SPACE;
|
||||
|
||||
BitMatrix result = encode(toEncode, false, null);
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, null);
|
||||
assertEquals(width, result.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeSwitchBetweenCodesetsAAndB() throws Exception {
|
||||
// start with A switch to B and back to A
|
||||
testEncode("\0ABab\u0010", QUIET_SPACE + START_CODE_A +
|
||||
// "\0" "A" "B" Switch to B "a" "b"
|
||||
"10100001100" + "10100011000" + "10001011000" + SWITCH_CODE_B + "10010110000" + "10010000110" +
|
||||
// Switch to A "\u0010" check digit
|
||||
SWITCH_CODE_A + "10100111100" + "11001110100" + STOP + QUIET_SPACE);
|
||||
|
||||
// start with B switch to A and back to B
|
||||
// the compact encoder encodes this shorter as STARTB,a,b,SHIFT,NUL,a,b
|
||||
testEncode("ab\0ab", QUIET_SPACE + START_CODE_B +
|
||||
// "a" "b" Switch to A "\0" Switch to B
|
||||
"10010110000" + "10010000110" + SWITCH_CODE_A + "10100001100" + SWITCH_CODE_B +
|
||||
// "a" "b" check digit
|
||||
"10010110000" + "10010000110" + "11010001110" + STOP + QUIET_SPACE);
|
||||
}
|
||||
|
||||
private void testEncode(String toEncode, String expected) throws Exception {
|
||||
BitMatrix result = encode(toEncode, false, toEncode);
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(toEncode, expected, actual);
|
||||
|
||||
|
||||
int width = result.getWidth();
|
||||
result = encode(toEncode, true, toEncode);
|
||||
assertTrue(result.getWidth() <= width);
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetABadCharacter() throws Exception {
|
||||
// Lower case characters should not be accepted when the code set is forced to A.
|
||||
String toEncode = "ASDFx0123";
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "A");
|
||||
writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetBBadCharacter() throws Exception {
|
||||
String toEncode = "ASdf\00123"; // \0 (ascii value 0)
|
||||
// Characters with ASCII value below 32 should not be accepted when the code set is forced to B.
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "B");
|
||||
writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetCBadCharactersNonNum() throws Exception {
|
||||
String toEncode = "123a5678";
|
||||
// Non-digit characters should not be accepted when the code set is forced to C.
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "C");
|
||||
writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetCBadCharactersFncCode() throws Exception {
|
||||
String toEncode = "123\u00f2a678";
|
||||
// Function codes other than 1 should not be accepted when the code set is forced to C.
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "C");
|
||||
writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetCWrongAmountOfDigits() throws Exception {
|
||||
String toEncode = "123456789";
|
||||
// An uneven amount of digits should not be accepted when the code set is forced to C.
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "C");
|
||||
writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetA() throws Exception {
|
||||
String toEncode = "AB123";
|
||||
// would default to B "A" "B" "1"
|
||||
String expected = QUIET_SPACE + START_CODE_A + "10100011000" + "10001011000" + "10011100110" +
|
||||
// "2" "3" check digit 10
|
||||
"11001110010" + "11001011100" + "11001000100" + STOP + QUIET_SPACE;
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "A");
|
||||
BitMatrix result = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeWithForcedCodeSetFailureCodeSetB() throws Exception {
|
||||
String toEncode = "1234";
|
||||
// would default to C "1" "2" "3"
|
||||
String expected = QUIET_SPACE + START_CODE_B + "10011100110" + "11001110010" + "11001011100" +
|
||||
// "4" check digit 88
|
||||
"11001001110" + "11110010010" + STOP + QUIET_SPACE;
|
||||
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.FORCE_CODE_SET, "B");
|
||||
BitMatrix result = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
|
||||
String actual = BitMatrixTestCase.matrixToString(result);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
private BitMatrix encode(String toEncode, boolean compact, String expectedLoopback) throws Exception {
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
if (compact) {
|
||||
hints.put(EncodeHintType.CODE128_COMPACT, Boolean.TRUE);
|
||||
}
|
||||
BitMatrix encResult = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
if (expectedLoopback != null) {
|
||||
BitArray row = encResult.getRow(0, null);
|
||||
Result rtResult = reader.decodeRow(0, row, null);
|
||||
String actual = rtResult.getText();
|
||||
assertEquals(expectedLoopback, actual);
|
||||
}
|
||||
if (compact) {
|
||||
//check that what is encoded compactly yields the same on loopback as what was encoded fast.
|
||||
BitArray row = encResult.getRow(0, null);
|
||||
Result rtResult = reader.decodeRow(0, row, null);
|
||||
String actual = rtResult.getText();
|
||||
BitMatrix encResultFast = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0);
|
||||
row = encResultFast.getRow(0, null);
|
||||
rtResult = reader.decodeRow(0, row, null);
|
||||
assertEquals(rtResult.getText(), actual);
|
||||
}
|
||||
return encResult;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class Code39BlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code39BlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/code39-1", new MultiFormatReader(), BarcodeFormat.CODE_39);
|
||||
addTest(4, 4, 0.0f);
|
||||
addTest(4, 4, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class Code39BlackBox3TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code39BlackBox3TestCase() {
|
||||
super("src/test/resources/blackbox/code39-3", new MultiFormatReader(), BarcodeFormat.CODE_39);
|
||||
addTest(17, 17, 0.0f);
|
||||
addTest(17, 17, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class Code39ExtendedBlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code39ExtendedBlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/code39-2", new Code39Reader(false, true), BarcodeFormat.CODE_39);
|
||||
addTest(2, 2, 0.0f);
|
||||
addTest(2, 2, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2017 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.ChecksumException;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* @author Michael Jahn
|
||||
*/
|
||||
public final class Code39ExtendedModeTestCase extends Assert {
|
||||
|
||||
@SuppressWarnings("checkstyle:lineLength")
|
||||
@Test
|
||||
public void testDecodeExtendedMode() throws FormatException, ChecksumException, NotFoundException {
|
||||
doTest("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f",
|
||||
"000001001011011010101001001001011001010101101001001001010110101001011010010010010101011010010110100100100101011011010010101001001001010101011001011010010010010101101011001010100100100101010110110010101001001001010101010011011010010010010101101010011010100100100101010110100110101001001001010101011001101010010010010101101010100110100100100101010110101001101001001001010110110101001010010010010101010110100110100100100101011010110100101001001001010101101101001010010010010101010101100110100100100101011010101100101001001001010101101011001010010010010101010110110010100100100101011001010101101001001001010100110101011010010010010101100110101010100100100101010010110101101001001001010110010110101010010010010101001101101010101001001001011010100101101010010010010101101001011010100100100101101101001010101001001001010101100101101010010010010110101100101010010110110100000");
|
||||
doTest(" !\"#$%&'()*+,-./0123456789:;<=>?",
|
||||
"00000100101101101010011010110101001001010010110101001011010010010100101011010010110100100101001011011010010101001001010010101011001011010010010100101101011001010100100101001010110110010101001001010010101010011011010010010100101101010011010100100101001010110100110101001001010010101011001101010010010100101101010100110100100101001010110101001101001010110110110010101101010010010100101101011010010101001101101011010010101101011001010110110110010101010100110101101101001101010101100110101010100101101101101001011010101100101101010010010100101001101101010101001001001010110110010101010010010010101010011011010100100100101101010011010101001001001010110100110101010010010010101011001101010010110110100000");
|
||||
doTest("@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_",
|
||||
"000010010110110101010010010010100110101011011010100101101011010010110110110100101010101100101101101011001010101101100101010101001101101101010011010101101001101010101100110101101010100110101101010011011011010100101010110100110110101101001010110110100101010101100110110101011001010110101100101010110110010110010101011010011010101101100110101010100101101011011001011010101001101101010101001001001011010101001101010010010010101101010011010100100100101101101010010101001001001010101101001101010010010010110101101001010010110110100000");
|
||||
doTest("`abcdefghijklmnopqrstuvwxyz{|}~",
|
||||
"000001001011011010101001001001011001101010101001010010010110101001011010010100100101011010010110100101001001011011010010101001010010010101011001011010010100100101101011001010100101001001010110110010101001010010010101010011011010010100100101101010011010100101001001010110100110101001010010010101011001101010010100100101101010100110100101001001010110101001101001010010010110110101001010010100100101010110100110100101001001011010110100101001010010010101101101001010010100100101010101100110100101001001011010101100101001010010010101101011001010010100100101010110110010100101001001011001010101101001010010010100110101011010010100100101100110101010100101001001010010110101101001010010010110010110101010010100100101001101101010101001001001010110110100101010010010010101010110011010100100100101101010110010101001001001010110101100101010010010010101011011001010010110110100000");
|
||||
}
|
||||
|
||||
private static void doTest(String expectedResult, String encodedResult)
|
||||
throws FormatException, ChecksumException, NotFoundException {
|
||||
Code39Reader sut = new Code39Reader(false, true);
|
||||
BitMatrix matrix = BitMatrix.parse(encodedResult, "1", "0");
|
||||
BitArray row = new BitArray(matrix.getWidth());
|
||||
matrix.getRow(0, row);
|
||||
Result result = sut.decodeRow(0, row, null);
|
||||
assertEquals(expectedResult, result.getText());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2016 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link Code39Writer}.
|
||||
*/
|
||||
public final class Code39WriterTestCase extends Assert {
|
||||
|
||||
@SuppressWarnings("checkstyle:lineLength")
|
||||
@Test
|
||||
public void testEncode() {
|
||||
doTest("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
||||
"000001001011011010110101001011010110100101101101101001010101011001011011010110010101" +
|
||||
"011011001010101010011011011010100110101011010011010101011001101011010101001101011010" +
|
||||
"100110110110101001010101101001101101011010010101101101001010101011001101101010110010" +
|
||||
"101101011001010101101100101100101010110100110101011011001101010101001011010110110010" +
|
||||
"110101010011011010101010011011010110100101011010110010101101101100101010101001101011" +
|
||||
"01101001101010101100110101010100101101101101001011010101100101101010010110110100000");
|
||||
|
||||
// extended mode blocks
|
||||
doTest("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f",
|
||||
"000001001011011010101001001001011001010101101001001001010110101001011010010010010101" +
|
||||
"011010010110100100100101011011010010101001001001010101011001011010010010010101101011" +
|
||||
"001010100100100101010110110010101001001001010101010011011010010010010101101010011010" +
|
||||
"100100100101010110100110101001001001010101011001101010010010010101101010100110100100" +
|
||||
"100101010110101001101001001001010110110101001010010010010101010110100110100100100101" +
|
||||
"011010110100101001001001010101101101001010010010010101010101100110100100100101011010" +
|
||||
"101100101001001001010101101011001010010010010101010110110010100100100101011001010101" +
|
||||
"101001001001010100110101011010010010010101100110101010100100100101010010110101101001" +
|
||||
"001001010110010110101010010010010101001101101010101001001001011010100101101010010010" +
|
||||
"010101101001011010100100100101101101001010101001001001010101100101101010010010010110" +
|
||||
"101100101010010110110100000");
|
||||
|
||||
doTest(" !\"#$%&'()*+,-./0123456789:;<=>?",
|
||||
"000001001011011010100110101101010010010100101101010010110100100101001010110100101101" +
|
||||
"001001010010110110100101010010010100101010110010110100100101001011010110010101001001" +
|
||||
"010010101101100101010010010100101010100110110100100101001011010100110101001001010010" +
|
||||
"101101001101010010010100101010110011010100100101001011010101001101001001010010101101" +
|
||||
"010011010010101101101100101011010100100101001011010110100101010011011010110100101011" +
|
||||
"010110010101101101100101010101001101011011010011010101011001101010101001011011011010" +
|
||||
"010110101011001011010100100101001010011011010101010010010010101101100101010100100100" +
|
||||
"101010100110110101001001001011010100110101010010010010101101001101010100100100101010" +
|
||||
"11001101010010110110100000");
|
||||
|
||||
doTest("@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_",
|
||||
"0000010010110110101010010010010100110101011011010100101101011010010110110110100101010" +
|
||||
"101100101101101011001010101101100101010101001101101101010011010101101001101010101100" +
|
||||
"110101101010100110101101010011011011010100101010110100110110101101001010110110100101" +
|
||||
"010101100110110101011001010110101100101010110110010110010101011010011010101101100110" +
|
||||
"101010100101101011011001011010101001101101010101001001001011010101001101010010010010" +
|
||||
"101101010011010100100100101101101010010101001001001010101101001101010010010010110101" +
|
||||
"101001010010110110100000");
|
||||
|
||||
doTest("`abcdefghijklmnopqrstuvwxyz{|}~",
|
||||
"000001001011011010101001001001011001101010101001010010010110101001011010010100100101" +
|
||||
"011010010110100101001001011011010010101001010010010101011001011010010100100101101011" +
|
||||
"001010100101001001010110110010101001010010010101010011011010010100100101101010011010" +
|
||||
"100101001001010110100110101001010010010101011001101010010100100101101010100110100101" +
|
||||
"001001010110101001101001010010010110110101001010010100100101010110100110100101001001" +
|
||||
"011010110100101001010010010101101101001010010100100101010101100110100101001001011010" +
|
||||
"101100101001010010010101101011001010010100100101010110110010100101001001011001010101" +
|
||||
"101001010010010100110101011010010100100101100110101010100101001001010010110101101001" +
|
||||
"010010010110010110101010010100100101001101101010101001001001010110110100101010010010" +
|
||||
"010101010110011010100100100101101010110010101001001001010110101100101010010010010101" +
|
||||
"011011001010010110110100000");
|
||||
}
|
||||
|
||||
private static void doTest(String input, CharSequence expected) {
|
||||
BitMatrix result = new Code39Writer().encode(input, BarcodeFormat.CODE_39, 0, 0);
|
||||
assertEquals(input, expected, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class Code93BlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public Code93BlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/code93-1", new MultiFormatReader(), BarcodeFormat.CODE_93);
|
||||
addTest(3, 3, 0.0f);
|
||||
addTest(3, 3, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2018 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.ChecksumException;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* @author Daisuke Makiuchi
|
||||
*/
|
||||
public final class Code93ReaderTestCase extends Assert {
|
||||
|
||||
@SuppressWarnings("checkstyle:lineLength")
|
||||
@Test
|
||||
public void testDecode() throws FormatException, ChecksumException, NotFoundException {
|
||||
doTest("Code93!\n$%/+ :\u001b;[{\u007f\u0000@`\u007f\u007f\u007f",
|
||||
"0000001010111101101000101001100101001011001001100101100101001001100101100100101000010101010000101110101101101010001001001101001101001110010101101011101011011101011101101110100101110101101001110101110110101101010001110110101100010101110110101000110101110110101000101101110110101101001101110110101100101101110110101100110101110110101011011001110110101011001101110110101001101101110110101001110101001100101101010001010111101111");
|
||||
}
|
||||
|
||||
private static void doTest(String expectedResult, String encodedResult)
|
||||
throws FormatException, ChecksumException, NotFoundException {
|
||||
Code93Reader sut = new Code93Reader();
|
||||
BitMatrix matrix = BitMatrix.parse(encodedResult, "1", "0");
|
||||
BitArray row = new BitArray(matrix.getWidth());
|
||||
matrix.getRow(0, row);
|
||||
Result result = sut.decodeRow(0, row, null);
|
||||
assertEquals(expectedResult, result.getText());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2016 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link Code93Writer}.
|
||||
*/
|
||||
public final class Code93WriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
doTest("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
||||
"000001010111101101010001101001001101000101100101001100100101100010101011010001011001" +
|
||||
"001011000101001101001000110101010110001010011001010001101001011001000101101101101001" +
|
||||
"101100101101011001101001101100101101100110101011011001011001101001101101001110101000" +
|
||||
"101001010010001010001001010000101001010001001001001001000101010100001000100101000010" +
|
||||
"10100111010101000010101011110100000");
|
||||
|
||||
doTest("\u0000\u0001\u001a\u001b\u001f $%+!,09:;@AZ[_`az{\u007f",
|
||||
"00000" + "101011110" +
|
||||
"111011010" + "110010110" + "100100110" + "110101000" + // bU aA
|
||||
"100100110" + "100111010" + "111011010" + "110101000" + // aZ bA
|
||||
"111011010" + "110010010" + "111010010" + "111001010" + // bE space $
|
||||
"110101110" + "101110110" + "111010110" + "110101000" + // % + cA
|
||||
"111010110" + "101011000" + "100010100" + "100001010" + // cL 0 9
|
||||
"111010110" + "100111010" + "111011010" + "110001010" + // cZ bF
|
||||
"111011010" + "110011010" + "110101000" + "100111010" + // bV A Z
|
||||
"111011010" + "100011010" + "111011010" + "100101100" + // bK bO
|
||||
"111011010" + "101101100" + "100110010" + "110101000" + // bW dA
|
||||
"100110010" + "100111010" + "111011010" + "100010110" + // dZ bP
|
||||
"111011010" + "110100110" + // bT
|
||||
"110100010" + "110101100" + // checksum: 12 28
|
||||
"101011110" + "100000");
|
||||
}
|
||||
|
||||
private static void doTest(String input, CharSequence expected) {
|
||||
BitMatrix result = new Code93Writer().encode(input, BarcodeFormat.CODE_93, 0, 0);
|
||||
assertEquals(expected, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertToExtended() {
|
||||
// non-extended chars are not changed.
|
||||
String src = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
|
||||
String dst = Code93Writer.convertToExtended(src);
|
||||
assertEquals(src, dst);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class EAN13BlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public EAN13BlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/ean13-1", new MultiFormatReader(), BarcodeFormat.EAN_13);
|
||||
addTest(30, 32, 0.0f);
|
||||
addTest(27, 32, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* This is a set of mobile image taken at 480x360 with difficult lighting.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class EAN13BlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public EAN13BlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/ean13-2", new MultiFormatReader(), BarcodeFormat.EAN_13);
|
||||
addTest(12, 17, 0, 1, 0.0f);
|
||||
addTest(11, 17, 0, 1, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class EAN13BlackBox3TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public EAN13BlackBox3TestCase() {
|
||||
super("src/test/resources/blackbox/ean13-3", new MultiFormatReader(), BarcodeFormat.EAN_13);
|
||||
addTest(53, 55, 0.0f);
|
||||
addTest(55, 55, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2009 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A very difficult set of images taken with extreme shadows and highlights.
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class EAN13BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public EAN13BlackBox4TestCase() {
|
||||
super("src/test/resources/blackbox/ean13-4", new MultiFormatReader(), BarcodeFormat.EAN_13);
|
||||
addTest(6, 13, 1, 1, 0.0f);
|
||||
addTest(7, 13, 1, 1, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2011 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A set of blurry images taken with a fixed-focus device.
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class EAN13BlackBox5BlurryTestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public EAN13BlackBox5BlurryTestCase() {
|
||||
super("src/test/resources/blackbox/ean13-5", new MultiFormatReader(), BarcodeFormat.EAN_13);
|
||||
addTest(0, 0, 0.0f);
|
||||
addTest(0, 0, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2009 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Ari Pollak
|
||||
*/
|
||||
public final class EAN13WriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
String testStr =
|
||||
"00001010001011010011101100110010011011110100111010101011001101101100100001010111001001110100010010100000";
|
||||
BitMatrix result = new EAN13Writer().encode("5901234123457", BarcodeFormat.EAN_13, testStr.length(), 0);
|
||||
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddChecksumAndEncode() {
|
||||
String testStr =
|
||||
"00001010001011010011101100110010011011110100111010101011001101101100100001010111001001110100010010100000";
|
||||
BitMatrix result = new EAN13Writer().encode("590123412345", BarcodeFormat.EAN_13, testStr.length(), 0);
|
||||
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeIllegalCharacters() {
|
||||
new EAN13Writer().encode("5901234123abc", BarcodeFormat.EAN_13, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class EAN8BlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public EAN8BlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/ean8-1", new MultiFormatReader(), BarcodeFormat.EAN_8);
|
||||
addTest(8, 8, 0.0f);
|
||||
addTest(8, 8, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
48
java_test/java/com/google/zxing/oned/EAN8WriterTestCase.java
Normal file
48
java_test/java/com/google/zxing/oned/EAN8WriterTestCase.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2009 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Ari Pollak
|
||||
*/
|
||||
public final class EAN8WriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
String testStr = "0000001010001011010111101111010110111010101001110111001010001001011100101000000";
|
||||
BitMatrix result = new EAN8Writer().encode("96385074", BarcodeFormat.EAN_8, testStr.length(), 0);
|
||||
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddChecksumAndEncode() {
|
||||
String testStr = "0000001010001011010111101111010110111010101001110111001010001001011100101000000";
|
||||
BitMatrix result = new EAN8Writer().encode("9638507", BarcodeFormat.EAN_8, testStr.length(), 0);
|
||||
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeIllegalCharacters() {
|
||||
new EAN8Writer().encode("96385abc", BarcodeFormat.EAN_8, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2010 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link EANManufacturerOrgSupport}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class EANManufacturerOrgSupportTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void testLookup() {
|
||||
EANManufacturerOrgSupport support = new EANManufacturerOrgSupport();
|
||||
assertNull(support.lookupCountryIdentifier("472000"));
|
||||
assertEquals("US/CA", support.lookupCountryIdentifier("000000"));
|
||||
assertEquals("MO", support.lookupCountryIdentifier("958000"));
|
||||
assertEquals("GB", support.lookupCountryIdentifier("500000"));
|
||||
assertEquals("GB", support.lookupCountryIdentifier("509000"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author kevin.osullivan@sita.aero
|
||||
*/
|
||||
public final class ITFBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public ITFBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/itf-1", new MultiFormatReader(), BarcodeFormat.ITF);
|
||||
addTest(14, 14, 0.0f);
|
||||
addTest(14, 14, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class ITFBlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public ITFBlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/itf-2", new MultiFormatReader(), BarcodeFormat.ITF);
|
||||
addTest(13, 13, 0.0f);
|
||||
addTest(13, 13, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
47
java_test/java/com/google/zxing/oned/ITFWriterTestCase.java
Normal file
47
java_test/java/com/google/zxing/oned/ITFWriterTestCase.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2017 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link ITFWriter}.
|
||||
*/
|
||||
public final class ITFWriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
doTest("00123456789012",
|
||||
"0000010101010111000111000101110100010101110001110111010001010001110100011" +
|
||||
"100010101000101011100011101011101000111000101110100010101110001110100000");
|
||||
}
|
||||
|
||||
private static void doTest(String input, CharSequence expected) {
|
||||
BitMatrix result = new ITFWriter().encode(input, BarcodeFormat.ITF, 0, 0);
|
||||
assertEquals(expected, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeIllegalCharacters() {
|
||||
new ITFWriter().encode("00123456789abc", BarcodeFormat.ITF, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class UPCABlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCABlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/upca-1", new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||
addTest(14, 18, 0, 1, 0.0f);
|
||||
addTest(16, 18, 0, 1, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCABlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCABlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/upca-2", new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||
addTest(28, 36, 0, 2, 0.0f);
|
||||
addTest(29, 36, 0, 2, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCABlackBox3ReflectiveTestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCABlackBox3ReflectiveTestCase() {
|
||||
super("src/test/resources/blackbox/upca-3", new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||
addTest(7, 9, 0, 2, 0.0f);
|
||||
addTest(8, 9, 0, 2, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCABlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCABlackBox4TestCase() {
|
||||
super("src/test/resources/blackbox/upca-4", new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||
addTest(9, 11, 0, 1, 0.0f);
|
||||
addTest(9, 11, 0, 1, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCABlackBox5TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCABlackBox5TestCase() {
|
||||
super("src/test/resources/blackbox/upca-5", new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||
addTest(20, 23, 0, 0, 0.0f);
|
||||
addTest(22, 23, 0, 0, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A set of blurry images taken with a fixed-focus device.
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCABlackBox6BlurryTestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCABlackBox6BlurryTestCase() {
|
||||
super("src/test/resources/blackbox/upca-6", new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||
addTest(0, 0, 0.0f);
|
||||
addTest(0, 0, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
47
java_test/java/com/google/zxing/oned/UPCAWriterTestCase.java
Normal file
47
java_test/java/com/google/zxing/oned/UPCAWriterTestCase.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author qwandor@google.com (Andrew Walbran)
|
||||
*/
|
||||
public final class UPCAWriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
String testStr =
|
||||
"00001010100011011011101100010001011010111101111010101011100101110100100111011001101101100101110010100000";
|
||||
BitMatrix result = new UPCAWriter().encode("485963095124", BarcodeFormat.UPC_A, testStr.length(), 0);
|
||||
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddChecksumAndEncode() {
|
||||
String testStr =
|
||||
"00001010011001001001101111010100011011000101011110101010001001001000111010011100101100110110110010100000";
|
||||
BitMatrix result = new UPCAWriter().encode("12345678901", BarcodeFormat.UPC_A, testStr.length(), 0);
|
||||
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class UPCEANExtensionBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCEANExtensionBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/upcean-extension-1", new MultiFormatReader(), BarcodeFormat.EAN_13);
|
||||
addTest(2, 2, 0.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class UPCEBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCEBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/upce-1", new MultiFormatReader(), BarcodeFormat.UPC_E);
|
||||
addTest(3, 3, 0.0f);
|
||||
addTest(3, 3, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCEBlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCEBlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/upce-2", new MultiFormatReader(), BarcodeFormat.UPC_E);
|
||||
addTest(31, 35, 0, 1, 0.0f);
|
||||
addTest(31, 35, 1, 1, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class UPCEBlackBox3ReflectiveTestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public UPCEBlackBox3ReflectiveTestCase() {
|
||||
super("src/test/resources/blackbox/upce-3", new MultiFormatReader(), BarcodeFormat.UPC_E);
|
||||
addTest(6, 8, 0.0f);
|
||||
addTest(6, 8, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
57
java_test/java/com/google/zxing/oned/UPCEWriterTestCase.java
Normal file
57
java_test/java/com/google/zxing/oned/UPCEWriterTestCase.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2016 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.BitMatrixTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link UPCEWriter}.
|
||||
*/
|
||||
public final class UPCEWriterTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEncode() {
|
||||
doTest("05096893",
|
||||
"0000000000010101110010100111000101101011110110111001011101010100000000000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeSystem1() {
|
||||
doTest("12345670",
|
||||
"0000000000010100100110111101010001101110010000101001000101010100000000000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddChecksumAndEncode() {
|
||||
doTest("0509689",
|
||||
"0000000000010101110010100111000101101011110110111001011101010100000000000");
|
||||
}
|
||||
|
||||
private static void doTest(String content, String encoding) {
|
||||
BitMatrix result = new UPCEWriter().encode(content, BarcodeFormat.UPC_E, encoding.length(), 0);
|
||||
assertEquals(encoding, BitMatrixTestCase.matrixToString(result));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEncodeIllegalCharacters() {
|
||||
new UPCEWriter().encode("05096abc", BarcodeFormat.UPC_E, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class RSS14BlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public RSS14BlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/rss14-1", new MultiFormatReader(), BarcodeFormat.RSS_14);
|
||||
addTest(6, 6, 0.0f);
|
||||
addTest(6, 6, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class RSS14BlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public RSS14BlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/rss14-2", new MultiFormatReader(), BarcodeFormat.RSS_14);
|
||||
addTest(4, 8, 1, 1, 0.0f);
|
||||
addTest(3, 8, 0, 1, 180.0f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2010 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded;
|
||||
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
public final class BinaryUtil {
|
||||
|
||||
private static final Pattern ONE = Pattern.compile("1");
|
||||
private static final Pattern ZERO = Pattern.compile("0");
|
||||
private static final Pattern SPACE = Pattern.compile(" ");
|
||||
|
||||
private BinaryUtil() {
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructs a BitArray from a String like the one returned from BitArray.toString()
|
||||
*/
|
||||
public static BitArray buildBitArrayFromString(CharSequence data) {
|
||||
CharSequence dotsAndXs = ZERO.matcher(ONE.matcher(data).replaceAll("X")).replaceAll(".");
|
||||
BitArray binary = new BitArray(SPACE.matcher(dotsAndXs).replaceAll("").length());
|
||||
int counter = 0;
|
||||
|
||||
for (int i = 0; i < dotsAndXs.length(); ++i) {
|
||||
if (i % 9 == 0) { // spaces
|
||||
if (dotsAndXs.charAt(i) != ' ') {
|
||||
throw new IllegalStateException("space expected");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
char currentChar = dotsAndXs.charAt(i);
|
||||
if (currentChar == 'X' || currentChar == 'x') {
|
||||
binary.set(counter);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
return binary;
|
||||
}
|
||||
|
||||
public static BitArray buildBitArrayFromStringWithoutSpaces(CharSequence data) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
CharSequence dotsAndXs = ZERO.matcher(ONE.matcher(data).replaceAll("X")).replaceAll(".");
|
||||
int current = 0;
|
||||
while (current < dotsAndXs.length()) {
|
||||
sb.append(' ');
|
||||
for (int i = 0; i < 8 && current < dotsAndXs.length(); ++i) {
|
||||
sb.append(dotsAndXs.charAt(current));
|
||||
current++;
|
||||
}
|
||||
}
|
||||
return buildBitArrayFromString(sb.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2010 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded;
|
||||
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
public final class BinaryUtilTest extends Assert {
|
||||
|
||||
private static final Pattern SPACE = Pattern.compile(" ");
|
||||
|
||||
@Test
|
||||
public void testBuildBitArrayFromString() {
|
||||
|
||||
CharSequence data = " ..X..X.. ..XXX... XXXXXXXX ........";
|
||||
check(data);
|
||||
|
||||
data = " XXX..X..";
|
||||
check(data);
|
||||
|
||||
data = " XX";
|
||||
check(data);
|
||||
|
||||
data = " ....XX.. ..XX";
|
||||
check(data);
|
||||
|
||||
data = " ....XX.. ..XX..XX ....X.X. ........";
|
||||
check(data);
|
||||
}
|
||||
|
||||
private static void check(CharSequence data) {
|
||||
BitArray binary = BinaryUtil.buildBitArrayFromString(data);
|
||||
assertEquals(data, binary.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildBitArrayFromStringWithoutSpaces() {
|
||||
CharSequence data = " ..X..X.. ..XXX... XXXXXXXX ........";
|
||||
checkWithoutSpaces(data);
|
||||
|
||||
data = " XXX..X..";
|
||||
checkWithoutSpaces(data);
|
||||
|
||||
data = " XX";
|
||||
checkWithoutSpaces(data);
|
||||
|
||||
data = " ....XX.. ..XX";
|
||||
checkWithoutSpaces(data);
|
||||
|
||||
data = " ....XX.. ..XX..XX ....X.X. ........";
|
||||
checkWithoutSpaces(data);
|
||||
}
|
||||
|
||||
private static void checkWithoutSpaces(CharSequence data) {
|
||||
CharSequence dataWithoutSpaces = SPACE.matcher(data).replaceAll("");
|
||||
BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(dataWithoutSpaces);
|
||||
assertEquals(data, binary.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2010 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded;
|
||||
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.oned.rss.DataCharacter;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
public final class BitArrayBuilderTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void testBuildBitArray1() {
|
||||
int[][] pairValues = {{19}, {673, 16}};
|
||||
|
||||
String expected = " .......X ..XX..X. X.X....X .......X ....";
|
||||
|
||||
checkBinary(pairValues, expected);
|
||||
}
|
||||
|
||||
private static void checkBinary(int[][] pairValues, String expected) {
|
||||
BitArray binary = buildBitArray(pairValues);
|
||||
assertEquals(expected, binary.toString());
|
||||
}
|
||||
|
||||
private static BitArray buildBitArray(int[][] pairValues) {
|
||||
List<ExpandedPair> pairs = new ArrayList<>();
|
||||
for (int i = 0; i < pairValues.length; ++i) {
|
||||
int [] pair = pairValues[i];
|
||||
|
||||
DataCharacter leftChar;
|
||||
if (i == 0) {
|
||||
leftChar = null;
|
||||
} else {
|
||||
leftChar = new DataCharacter(pair[0], 0);
|
||||
}
|
||||
|
||||
DataCharacter rightChar;
|
||||
if (i == 0) {
|
||||
rightChar = new DataCharacter(pair[0], 0);
|
||||
} else if (pair.length == 2) {
|
||||
rightChar = new DataCharacter(pair[1], 0);
|
||||
} else {
|
||||
rightChar = null;
|
||||
}
|
||||
|
||||
ExpandedPair expandedPair = new ExpandedPair(leftChar, rightChar, null);
|
||||
pairs.add(expandedPair);
|
||||
}
|
||||
|
||||
return BitArrayBuilder.buildBitArray(pairs);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2010 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded;
|
||||
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.oned.rss.expanded.decoders.AbstractExpandedDecoder;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
public final class ExpandedInformationDecoderTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void testNoAi() throws Exception {
|
||||
BitArray information = BinaryUtil.buildBitArrayFromString(" .......X ..XX..X. X.X....X .......X ....");
|
||||
|
||||
AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(information);
|
||||
String decoded = decoder.parseInformation();
|
||||
assertEquals("(10)12A", decoded);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2010 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A test of {@link RSSExpandedReader} against a fixed test set of images.
|
||||
*/
|
||||
public final class RSSExpandedBlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public RSSExpandedBlackBox1TestCase() {
|
||||
super("src/test/resources/blackbox/rssexpanded-1", new MultiFormatReader(), BarcodeFormat.RSS_EXPANDED);
|
||||
addTest(32, 32, 0.0f);
|
||||
addTest(32, 32, 180.0f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2010 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These authors would like to acknowledge the Spanish Ministry of Industry,
|
||||
* Tourism and Trade, for the support in the project TSI020301-2008-2
|
||||
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
|
||||
* Mobile Dynamic Environments", led by Treelogic
|
||||
* ( http://www.treelogic.com/ ):
|
||||
*
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
package com.google.zxing.oned.rss.expanded;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
|
||||
/**
|
||||
* A test of {@link RSSExpandedReader} against a fixed test set of images.
|
||||
*/
|
||||
public final class RSSExpandedBlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
public RSSExpandedBlackBox2TestCase() {
|
||||
super("src/test/resources/blackbox/rssexpanded-2", new MultiFormatReader(), BarcodeFormat.RSS_EXPANDED);
|
||||
addTest(21, 23, 0.0f);
|
||||
addTest(21, 23, 180.0f);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user