diff options
| author | Taneli Huuskonen <tanelihuuskonen@users.noreply.github.com> | 2016-05-08 17:01:41 +0300 |
|---|---|---|
| committer | Sean Owen <srowen@gmail.com> | 2016-05-08 17:01:41 +0300 |
| commit | f0dfcdfed5c97adb5a80d1d74eca46a9014e2c95 (patch) | |
| tree | b4694d05a07fa4744e2d41a7dc9582686571d572 /core/src/test/java/com | |
| parent | a064c719e6dc6e112fe13ba42946adb3e4691466 (diff) | |
| download | zxing-f0dfcdfed5c97adb5a80d1d74eca46a9014e2c95.tar.xz | |
Fix for bug #593
* Fixed bug #593
Bug #593 was misleadingly reported as pertaining to another project, but
testing revealed it affected this project as well. The Code128 encoding
algorithm failed when an odd number of digits were followed by FNC1 and
other digits. The code selection algorithm was rewritten. A test case
showing the bug was added, and an old test case was updated to expect
the result of the new algorithm - another valid encoding of the same
length as the old one.
* Fixed bug #593
Bug #593 was misleadingly reported as pertaining to another project, but
testing revealed it affected this project as well. The Code128 encoding
algorithm failed when an odd number of digits were followed by FNC1 and
other digits. The code selection algorithm was rewritten. A test case
showing the bug was added, and an old test case was updated to expect
the result of the new algorithm - another valid encoding of the same
length as the old one.
* Cleaning up
Added a private enum and changed some names to improve readability.
Also some trivial cosmetic changes.
* Further cleanup of Code128 writer test
Removed a private one-liner method used exactly once, alphabetized
imports.
Diffstat (limited to 'core/src/test/java/com')
| -rw-r--r-- | core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java b/core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java index 1d26507d4..ad403fb2a 100644 --- a/core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java +++ b/core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java @@ -21,8 +21,11 @@ import org.junit.Before; import org.junit.Test; import com.google.zxing.BarcodeFormat; +import com.google.zxing.ReaderException; +import com.google.zxing.Result; import com.google.zxing.Writer; import com.google.zxing.WriterException; +import com.google.zxing.common.BitArray; import com.google.zxing.common.BitMatrix; public class Code128WriterTestCase extends Assert { @@ -32,14 +35,18 @@ public class Code128WriterTestCase extends Assert { private static final String FNC3 = "10111100010"; private static final String FNC4 = "10111101110"; private static final String START_CODE_B = "11010010000"; + private static final String START_CODE_C = "11010011100"; + private static final String SWITCH_CODE_B = "10111101110"; private static final String QUIET_SPACE = "00000"; private static final String STOP = "1100011101011"; private Writer writer; + private Code128Reader reader; @Before public void setup() { writer = new Code128Writer(); + reader = new Code128Reader(); } @Test @@ -69,8 +76,8 @@ public class Code128WriterTestCase extends Assert { @Test public void testEncodeWithFunc1() throws WriterException { String toEncode = "\u00f1" + "123"; - // "1" "2" "3" check digit 61 - String expected = QUIET_SPACE + START_CODE_B + FNC1 + "10011100110" + "11001110010" + "11001011100" + "11001000010" + STOP + QUIET_SPACE; + // "12" "3" check digit 92 + String expected = QUIET_SPACE + START_CODE_C + FNC1 + "10110011100" + SWITCH_CODE_B + "11001011100" + "10101111000" + STOP + QUIET_SPACE; BitMatrix result = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0); @@ -79,6 +86,18 @@ public class Code128WriterTestCase extends Assert { } @Test + public void testRoundtrip() throws WriterException, ReaderException { + String toEncode = "\u00f1" + "10958" + "\u00f1" + "17160526"; + String expected = "1095817160526"; + + BitMatrix encResult = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0); + BitArray row = encResult.getRow(0, null); + Result rtResult = reader.decodeRow(0, row, null); + String actual = rtResult.getText(); + assertEquals(expected, actual); + } + + @Test public void testEncodeWithFunc4() throws WriterException { String toEncode = "\u00f4" + "123"; // "1" "2" "3" check digit 59 |
