summaryrefslogtreecommitdiff
path: root/core/src/test/java/com
diff options
context:
space:
mode:
authorDamian Peckett <damian@pecke.tt>2017-12-18 18:13:53 +0300
committerSean Owen <srowen@gmail.com>2017-12-18 18:13:53 +0300
commite54e0c781bda75c13155fd434a1d61cbc43602ef (patch)
treec7d71f2dd9602173f90a1628bbd100d04c5e997f /core/src/test/java/com
parent561f09b32ea8b5898f02486993b358e22440aee0 (diff)
downloadzxing-e54e0c781bda75c13155fd434a1d61cbc43602ef.tar.xz
Add support for encoding GS1 formatted QR (#927)
* Add support for encoding GS1 formatted QR * Place FNC1 mode header after ECI header
Diffstat (limited to 'core/src/test/java/com')
-rw-r--r--core/src/test/java/com/google/zxing/qrcode/encoder/EncoderTestCase.java140
1 files changed, 140 insertions, 0 deletions
diff --git a/core/src/test/java/com/google/zxing/qrcode/encoder/EncoderTestCase.java b/core/src/test/java/com/google/zxing/qrcode/encoder/EncoderTestCase.java
index 96c785e60..d5bc6de59 100644
--- a/core/src/test/java/com/google/zxing/qrcode/encoder/EncoderTestCase.java
+++ b/core/src/test/java/com/google/zxing/qrcode/encoder/EncoderTestCase.java
@@ -256,6 +256,76 @@ public final class EncoderTestCase extends Assert {
}
@Test
+ public void testEncodeGS1WithStringTypeHint() throws WriterException {
+ Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
+ hints.put(EncodeHintType.GS1_FORMAT, "true");
+ QRCode qrCode = Encoder.encode("100001%11171218", ErrorCorrectionLevel.H, hints);
+ verifyGS1EncodedData(qrCode);
+ }
+
+ @Test
+ public void testEncodeGS1WithBooleanTypeHint() throws WriterException {
+ Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
+ hints.put(EncodeHintType.GS1_FORMAT, true);
+ QRCode qrCode = Encoder.encode("100001%11171218", ErrorCorrectionLevel.H, hints);
+ verifyGS1EncodedData(qrCode);
+ }
+
+ @Test
+ public void testDoesNotEncodeGS1WhenBooleanTypeHintExplicitlyFalse() throws WriterException {
+ Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
+ hints.put(EncodeHintType.GS1_FORMAT, false);
+ QRCode qrCode = Encoder.encode("ABCDEF", ErrorCorrectionLevel.H, hints);
+ verifyNotGS1EncodedData(qrCode);
+ }
+
+ @Test
+ public void testDoesNotEncodeGS1WhenStringTypeHintExplicitlyFalse() throws WriterException {
+ Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
+ hints.put(EncodeHintType.GS1_FORMAT, "false");
+ QRCode qrCode = Encoder.encode("ABCDEF", ErrorCorrectionLevel.H, hints);
+ verifyNotGS1EncodedData(qrCode);
+ }
+
+ @Test
+ public void testGS1ModeHeaderWithECI() throws WriterException {
+ Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class);
+ hints.put(EncodeHintType.CHARACTER_SET, "UTF8");
+ hints.put(EncodeHintType.GS1_FORMAT, true);
+ QRCode qrCode = Encoder.encode("hello", ErrorCorrectionLevel.H, hints);
+ String expected =
+ "<<\n" +
+ " mode: BYTE\n" +
+ " ecLevel: H\n" +
+ " version: 1\n" +
+ " maskPattern: 5\n" +
+ " matrix:\n" +
+ " 1 1 1 1 1 1 1 0 1 0 1 1 0 0 1 1 1 1 1 1 1\n" +
+ " 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 0 0 1\n" +
+ " 1 0 1 1 1 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 1\n" +
+ " 1 0 1 1 1 0 1 0 0 1 0 1 0 0 1 0 1 1 1 0 1\n" +
+ " 1 0 1 1 1 0 1 0 1 0 1 0 0 0 1 0 1 1 1 0 1\n" +
+ " 1 0 0 0 0 0 1 0 0 1 1 1 1 0 1 0 0 0 0 0 1\n" +
+ " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" +
+ " 0 0 0 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 0 0 0\n" +
+ " 0 0 0 0 0 1 1 0 0 1 1 0 0 0 1 0 1 0 1 0 1\n" +
+ " 0 1 0 1 1 0 0 1 0 1 1 1 1 1 1 0 1 1 1 0 1\n" +
+ " 0 1 0 1 1 1 1 0 1 1 0 0 0 1 0 1 0 1 1 0 0\n" +
+ " 1 1 1 1 0 1 0 1 0 0 1 0 1 0 0 1 1 1 1 0 0\n" +
+ " 1 0 0 1 0 0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 1\n" +
+ " 0 0 0 0 0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 1 0\n" +
+ " 1 1 1 1 1 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0\n" +
+ " 1 0 0 0 0 0 1 0 1 1 0 0 0 0 1 0 1 1 1 0 0\n" +
+ " 1 0 1 1 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 0 1\n" +
+ " 1 0 1 1 1 0 1 0 0 0 0 0 1 1 1 0 1 1 1 1 0\n" +
+ " 1 0 1 1 1 0 1 0 0 0 1 0 0 1 0 0 1 0 1 1 1\n" +
+ " 1 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 0 1 1 1 1\n" +
+ " 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 1 0 0 1 0\n" +
+ ">>\n";
+ assertEquals(expected, qrCode.toString());
+ }
+
+ @Test
public void testAppendModeInfo() {
BitArray bits = new BitArray();
Encoder.appendModeInfo(Mode.NUMERIC, bits);
@@ -594,6 +664,76 @@ public final class EncoderTestCase extends Assert {
Encoder.encode(builder.toString(), ErrorCorrectionLevel.L);
}
+ private void verifyGS1EncodedData(QRCode qrCode) {
+ String expected =
+ "<<\n" +
+ " mode: ALPHANUMERIC\n" +
+ " ecLevel: H\n" +
+ " version: 2\n" +
+ " maskPattern: 4\n" +
+ " matrix:\n" +
+ " 1 1 1 1 1 1 1 0 0 1 1 1 1 0 1 0 1 0 1 1 1 1 1 1 1\n" +
+ " 1 0 0 0 0 0 1 0 1 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 1\n" +
+ " 1 0 1 1 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1 0\n" +
+ " 1 0 1 1 1 0 1 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 0 0 1\n" +
+ " 1 0 1 1 1 0 1 0 0 0 0 0 0 1 1 1 0 0 1 1 0 1 0 0 0\n" +
+ " 1 0 1 1 1 0 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 0 0 1 0\n" +
+ " 1 0 0 0 0 0 1 0 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 0\n" +
+ " 1 1 1 1 1 1 1 0 0 0 1 0 0 0 0 1 1 0 0 1 1 0 0 1 1\n" +
+ ">>\n";
+ assertEquals(expected, qrCode.toString());
+ }
+
+ private void verifyNotGS1EncodedData(QRCode qrCode) {
+ String expected =
+ "<<\n" +
+ " mode: ALPHANUMERIC\n" +
+ " ecLevel: H\n" +
+ " version: 1\n" +
+ " maskPattern: 4\n" +
+ " matrix:\n" +
+ " 1 1 1 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 1 1 1\n" +
+ " 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1\n" +
+ " 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\n" +
+ " 1 0 1 1 1 0 1 0 0 1 0 0 1 0 1 0 1 1 1 0 1\n" +
+ " 1 0 1 1 1 0 1 0 0 1 0 1 0 0 1 0 1 1 1 0 1\n" +
+ " 1 0 0 0 0 0 1 0 1 0 0 1 1 0 1 0 0 0 0 0 1\n" +
+ " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" +
+ " 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0\n" +
+ " 0 0 0 0 1 1 1 1 0 1 1 0 1 0 1 1 0 0 0 1 0\n" +
+ " 0 0 0 0 1 1 0 1 1 1 0 0 1 1 1 1 0 1 1 0 1\n" +
+ " 1 0 0 0 0 1 1 0 0 1 0 1 0 0 0 1 1 1 0 1 1\n" +
+ " 1 0 0 1 1 1 0 0 1 1 1 1 0 0 0 0 1 0 0 0 0\n" +
+ " 0 1 1 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 1 0 0\n" +
+ " 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 0 0 1 0 1\n" +
+ " 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 0 0 1 1 0 0\n" +
+ " 1 0 0 0 0 0 1 0 1 1 0 1 0 0 0 1 0 1 1 1 1\n" +
+ " 1 0 1 1 1 0 1 0 1 0 0 1 0 0 0 1 1 0 0 1 1\n" +
+ " 1 0 1 1 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 1 1\n" +
+ " 1 0 1 1 1 0 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0\n" +
+ " 1 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 1 0 0 0 1\n" +
+ " 1 1 1 1 1 1 1 0 0 0 1 0 0 1 0 0 0 0 1 1 1\n" +
+ ">>\n";
+ assertEquals(expected, qrCode.toString());
+ }
+
private static String shiftJISString(byte[] bytes) throws WriterException {
try {
return new String(bytes, "Shift_JIS");