diff options
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 |
