summaryrefslogtreecommitdiff
path: root/core/src/test/java/com
diff options
context:
space:
mode:
authorSean Owen <srowen@gmail.com>2016-10-01 01:41:40 +0300
committerSean Owen <srowen@gmail.com>2016-10-01 01:41:40 +0300
commit2d02cb05ea288d14f5691e25628d21349865c5db (patch)
tree0782997286f0152efad42d8e1f10ef3ef3176bd6 /core/src/test/java/com
parent75c51f93feb66a96b6604af4804053cbbfb8d2ea (diff)
downloadzxing-2d02cb05ea288d14f5691e25628d21349865c5db.tar.xz
Partial fix for #679: add check digit if absent in UPC-A/E EAN-13/8 encoding, and reject those with invalid check digit
Diffstat (limited to 'core/src/test/java/com')
-rw-r--r--core/src/test/java/com/google/zxing/oned/EAN13WriterTestCase.java7
-rw-r--r--core/src/test/java/com/google/zxing/oned/EAN8WriterTestCase.java7
-rw-r--r--core/src/test/java/com/google/zxing/oned/UPCEWriterTestCase.java42
3 files changed, 56 insertions, 0 deletions
diff --git a/core/src/test/java/com/google/zxing/oned/EAN13WriterTestCase.java b/core/src/test/java/com/google/zxing/oned/EAN13WriterTestCase.java
index bac2cd980..97a4603d9 100644
--- a/core/src/test/java/com/google/zxing/oned/EAN13WriterTestCase.java
+++ b/core/src/test/java/com/google/zxing/oned/EAN13WriterTestCase.java
@@ -35,4 +35,11 @@ public final class EAN13WriterTestCase extends Assert {
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
}
+ @Test
+ public void testAddChecksumAndEncode() throws WriterException {
+ String testStr = "00010100010110100111011001100100110111101001110101010110011011011001000010101110010011101000100101000";
+ BitMatrix result = new EAN13Writer().encode("590123412345", BarcodeFormat.EAN_13, testStr.length(), 0);
+ assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
+ }
+
}
diff --git a/core/src/test/java/com/google/zxing/oned/EAN8WriterTestCase.java b/core/src/test/java/com/google/zxing/oned/EAN8WriterTestCase.java
index a5ab2d198..3e73669c0 100644
--- a/core/src/test/java/com/google/zxing/oned/EAN8WriterTestCase.java
+++ b/core/src/test/java/com/google/zxing/oned/EAN8WriterTestCase.java
@@ -35,4 +35,11 @@ public final class EAN8WriterTestCase extends Assert {
assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
}
+ @Test
+ public void testAddChecksumAndEncode() throws WriterException {
+ String testStr = "0001010001011010111101111010110111010101001110111001010001001011100101000";
+ BitMatrix result = new EAN8Writer().encode("9638507", BarcodeFormat.EAN_8, testStr.length(), 0);
+ assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
+ }
+
}
diff --git a/core/src/test/java/com/google/zxing/oned/UPCEWriterTestCase.java b/core/src/test/java/com/google/zxing/oned/UPCEWriterTestCase.java
new file mode 100644
index 000000000..678624877
--- /dev/null
+++ b/core/src/test/java/com/google/zxing/oned/UPCEWriterTestCase.java
@@ -0,0 +1,42 @@
+/*
+ * 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.WriterException;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.common.BitMatrixTestCase;
+import org.junit.Assert;
+import org.junit.Test;
+
+public final class UPCEWriterTestCase extends Assert {
+
+ @Test
+ public void testEncode() throws WriterException {
+ String testStr = "0000000000010101110010100111000101101011110110111001011101010100000000000";
+ BitMatrix result = new UPCEWriter().encode("05096893", BarcodeFormat.UPC_E, testStr.length(), 0);
+ assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
+ }
+
+ @Test
+ public void testAddChecksumAndEncode() throws WriterException {
+ String testStr = "0000000000010101110010100111000101101011110110111001011101010100000000000";
+ BitMatrix result = new UPCEWriter().encode("0509689", BarcodeFormat.UPC_E, testStr.length(), 0);
+ assertEquals(testStr, BitMatrixTestCase.matrixToString(result));
+ }
+
+}