mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
Fix qr compaction (#1449)
* - Added missing error handling in case of a failing assert - Fixed typo in the documentation * Fixed bug that the minimal encoder would fail with an internal error if the string to encode contained only characters from ISO-8859-1 and on or more character that is not defined in any of the ISO-8859 characters sets.
This commit is contained in:
parent
f984496a10
commit
3909ebe294
|
@ -223,40 +223,6 @@ final class MinimalEncoder {
|
|||
return Encoder.getAlphanumericCode(c) != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: to encode alphanumerically at least 2 characters are needed (5.5 bits per character). Similarily three
|
||||
* digits are needed to encode numerically (3+1/3 bits per digit)
|
||||
*/
|
||||
static int getEncodingGranularity(Mode mode) {
|
||||
switch (mode) {
|
||||
case KANJI:
|
||||
case BYTE:
|
||||
return 1;
|
||||
case ALPHANUMERIC:
|
||||
return 2;
|
||||
case NUMERIC:
|
||||
return 3;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: to encode alphanumerically 11 bits are used per 2 characters. Similarily 10 bits are used to encode 3
|
||||
* numeric digits.
|
||||
*/
|
||||
static int getBitsPerEncodingUnit(Mode mode) {
|
||||
switch (mode) {
|
||||
case KANJI: return 16;
|
||||
case ALPHANUMERIC: return 11;
|
||||
case NUMERIC: return 10;
|
||||
case BYTE: return 8;
|
||||
case ECI:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of encodeable characters in the given mode for the given version. Example: in
|
||||
* Version 1, 2^10 digits or 2^8 bytes can be encoded. In Version 3 it is 2^14 digits and 2^16 bytes
|
||||
|
@ -324,7 +290,7 @@ final class MinimalEncoder {
|
|||
}
|
||||
if (haveECI) {
|
||||
//prepend a default character set ECI
|
||||
result.addFirst(result.new ResultNode(Mode.ECI, 0, 0));
|
||||
result.addFirst(result.new ResultNode(Mode.ECI, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -332,15 +298,15 @@ final class MinimalEncoder {
|
|||
first = result.getFirst();
|
||||
if (first.mode != Mode.ECI) {
|
||||
//prepend a FNC1_FIRST_POSITION
|
||||
result.addFirst(result.new ResultNode(Mode.FNC1_FIRST_POSITION, 0, 0));
|
||||
result.addFirst(result.new ResultNode(Mode.FNC1_FIRST_POSITION, 0, 0, 0));
|
||||
} else {
|
||||
//insert a FNC1_FIRST_POSITION after the ECI
|
||||
result.add(1,result.new ResultNode(Mode.FNC1_FIRST_POSITION, 0, 0));
|
||||
result.add(1,result.new ResultNode(Mode.FNC1_FIRST_POSITION, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
//Add TERMINATOR according to "8.4.8 Terminator"
|
||||
//TODO: The terminiator can be omitted if there are less than 4 bit in the capacity of the symbol.
|
||||
result.add(result.new ResultNode(Mode.TERMINATOR, stringToEncode.length(), 0));
|
||||
result.add(result.new ResultNode(Mode.TERMINATOR, stringToEncode.length(), 0, 0));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -418,27 +384,35 @@ final class MinimalEncoder {
|
|||
void addEdges(Version version, ArrayList<ResultList>[][][] vertices, int from, ResultList previous) {
|
||||
for (int i = 0; i < encoders.length; i++) {
|
||||
if (encoders[i].canEncode(stringToEncode.charAt(from))) {
|
||||
ResultList edge = new ResultList(version, Mode.BYTE, from, i);
|
||||
ResultList edge = new ResultList(version, Mode.BYTE, from, i, 1);
|
||||
boolean needECI = (previous == null && i > 0) ||
|
||||
(previous != null && getEdgeCharsetEncoderIndex(previous) != i);
|
||||
if (needECI) {
|
||||
ResultList.ResultNode eci = edge.new ResultNode(Mode.ECI, from, i);
|
||||
ResultList.ResultNode eci = edge.new ResultNode(Mode.ECI, from, i, 0);
|
||||
edge.addFirst(eci);
|
||||
}
|
||||
addEdge(vertices, edge, previous);
|
||||
}
|
||||
}
|
||||
if (canEncode(Mode.KANJI, stringToEncode.charAt(from))) {
|
||||
addEdge(vertices, new ResultList(version, Mode.KANJI, from, 0), previous);
|
||||
addEdge(vertices, new ResultList(version, Mode.KANJI, from, 0, 1), previous);
|
||||
}
|
||||
int inputLength = stringToEncode.length();
|
||||
if (from + 1 < inputLength && canEncode(Mode.ALPHANUMERIC, stringToEncode.charAt(from)) &&
|
||||
canEncode(Mode.ALPHANUMERIC, stringToEncode.charAt(from + 1))) {
|
||||
addEdge(vertices, new ResultList(version, Mode.ALPHANUMERIC, from, 0), previous);
|
||||
if (canEncode(Mode.ALPHANUMERIC, stringToEncode.charAt(from))) {
|
||||
if (from + 1 >= inputLength || !canEncode(Mode.ALPHANUMERIC, stringToEncode.charAt(from + 1))) {
|
||||
addEdge(vertices, new ResultList(version, Mode.ALPHANUMERIC, from, 0, 1), previous);
|
||||
} else {
|
||||
addEdge(vertices, new ResultList(version, Mode.ALPHANUMERIC, from, 0, 2), previous);
|
||||
}
|
||||
}
|
||||
if (from + 2 < inputLength && canEncode(Mode.NUMERIC, stringToEncode.charAt(from)) && canEncode(Mode.NUMERIC,
|
||||
stringToEncode.charAt(from + 1)) && canEncode(Mode.NUMERIC, stringToEncode.charAt(from + 2))) {
|
||||
addEdge(vertices, new ResultList(version, Mode.NUMERIC, from, 0), previous);
|
||||
if (canEncode(Mode.NUMERIC, stringToEncode.charAt(from))) {
|
||||
if (from + 1 >= inputLength || !canEncode(Mode.NUMERIC, stringToEncode.charAt(from + 1))) {
|
||||
addEdge(vertices, new ResultList(version, Mode.NUMERIC, from, 0, 1), previous);
|
||||
} else if (from + 2 >= inputLength || !canEncode(Mode.NUMERIC, stringToEncode.charAt(from + 2))) {
|
||||
addEdge(vertices, new ResultList(version, Mode.NUMERIC, from, 0, 2), previous);
|
||||
} else {
|
||||
addEdge(vertices, new ResultList(version, Mode.NUMERIC, from, 0, 3), previous);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -468,7 +442,7 @@ final class MinimalEncoder {
|
|||
// ResultList.ResultNode previous = getEdgePrevious(edge);
|
||||
// String fromKey = previous == null ? "initial" : "" + fromPosition + "_" + previous.mode +
|
||||
// (willHaveECI ? "_" + encoders[previous.charsetEncoderIndex].charset().name() : "");
|
||||
// int toPosition = fromPosition + getEncodingGranularity(getEdgeMode(edge));
|
||||
// int toPosition = fromPosition + getEdgeLength(edge);
|
||||
// edgeStrings.add("(" + fromKey + ") -- " + getEdgeMode(edge) + (toPosition -
|
||||
// fromPosition > 0 ? "(" + stringToEncode.substring(fromPosition, toPosition) +
|
||||
// ")" : "") + " (" + edge.getSize() + ")" + " --> " + "(" + vertexKey + ")");
|
||||
|
@ -760,11 +734,11 @@ final class MinimalEncoder {
|
|||
}
|
||||
|
||||
/**
|
||||
* Short for rl=new ResultList(version); rl.add(rl.new ResultNode(modes, position, charsetEncoderIndex));
|
||||
* Short for rl=new ResultList(version); rl.add(rl.new ResultNode(modes, position, charsetEncoderIndex, length));
|
||||
*/
|
||||
private ResultList(Version version, Mode mode, int position, int charsetEncoderIndex) {
|
||||
private ResultList(Version version, Mode mode, int position, int charsetEncoderIndex, int length) {
|
||||
this(version);
|
||||
add(new ResultNode(mode, position, charsetEncoderIndex));
|
||||
add(new ResultNode(mode, position, charsetEncoderIndex, length));
|
||||
}
|
||||
|
||||
private void addFirst(ResultList resultList) {
|
||||
|
@ -836,8 +810,25 @@ final class MinimalEncoder {
|
|||
* appends the bits
|
||||
*/
|
||||
void getBits(BitArray bits) throws WriterException {
|
||||
for (Iterator<ResultNode> it = iterator(); it.hasNext();) {
|
||||
it.next().getBits(bits);
|
||||
int size = size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
ResultNode rni = get(i);
|
||||
if (rni.declaresMode) {
|
||||
// append mode
|
||||
bits.appendBits(rni.mode.getBits(), 4);
|
||||
if (rni.getCharacterLength() > 0) {
|
||||
int length = rni.getCharacterCountIndicator();
|
||||
for (int j = i + 1; j < size; j++) {
|
||||
ResultNode rnj = get(j);
|
||||
if (rnj.declaresMode) {
|
||||
break;
|
||||
}
|
||||
length += rnj.getCharacterCountIndicator();
|
||||
}
|
||||
bits.appendBits(length, rni.mode.getCharacterCountBits(version));
|
||||
}
|
||||
}
|
||||
rni.getBits(bits);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -899,13 +890,15 @@ final class MinimalEncoder {
|
|||
private boolean declaresMode = true;
|
||||
private final int position;
|
||||
private final int charsetEncoderIndex;
|
||||
private final int length;
|
||||
|
||||
ResultNode(Mode mode, int position, int charsetEncoderIndex) {
|
||||
ResultNode(Mode mode, int position, int charsetEncoderIndex, int length) {
|
||||
|
||||
assert mode != null;
|
||||
this.mode = mode;
|
||||
this.position = position;
|
||||
this.charsetEncoderIndex = charsetEncoderIndex;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -913,12 +906,21 @@ final class MinimalEncoder {
|
|||
*/
|
||||
private int getSize() {
|
||||
int size = declaresMode ? 4 + mode.getCharacterCountBits(version) : 0;
|
||||
if (mode == Mode.ECI) {
|
||||
size += 8; // the ECI assignment numbers for ISO-8859-x, UTF-8 and UTF-16 are all 8 bit long
|
||||
} else if (mode == Mode.BYTE) {
|
||||
size += 8 * getBytesOfCharacter(position, charsetEncoderIndex).length;
|
||||
} else {
|
||||
size += getBitsPerEncodingUnit(mode);
|
||||
switch (mode) {
|
||||
case KANJI:
|
||||
size += 13;
|
||||
break;
|
||||
case ALPHANUMERIC:
|
||||
size += length == 1 ? 6 : 11;
|
||||
break;
|
||||
case NUMERIC:
|
||||
size += length == 1 ? 4 : length == 2 ? 7 : 10;
|
||||
break;
|
||||
case BYTE:
|
||||
size += 8 * getBytesOfCharacter(position, charsetEncoderIndex).length;
|
||||
break;
|
||||
case ECI:
|
||||
size += 8; // the ECI assignment numbers for ISO-8859-x, UTF-8 and UTF-16 are all 8 bit long
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
@ -927,7 +929,7 @@ final class MinimalEncoder {
|
|||
* returns the length in characters
|
||||
*/
|
||||
private int getCharacterLength() {
|
||||
return (getBitsPerEncodingUnit(mode) == 0 ? 0 : 1) * getEncodingGranularity(mode);
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -942,20 +944,9 @@ final class MinimalEncoder {
|
|||
* appends the bits
|
||||
*/
|
||||
private void getBits(BitArray bits) throws WriterException {
|
||||
if (declaresMode) {
|
||||
// append mode
|
||||
bits.appendBits(mode.getBits(), 4);
|
||||
if (mode == Mode.ECI) {
|
||||
bits.appendBits(CharacterSetECI.getCharacterSetECI(encoders[charsetEncoderIndex].charset()).getValue(), 8);
|
||||
} else {
|
||||
int characterLength = getCharacterCountIndicator();
|
||||
if (characterLength > 0) {
|
||||
// append length
|
||||
bits.appendBits(characterLength, mode.getCharacterCountBits(version));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getCharacterLength() > 0) {
|
||||
if (mode == Mode.ECI) {
|
||||
bits.appendBits(CharacterSetECI.getCharacterSetECI(encoders[charsetEncoderIndex].charset()).getValue(), 8);
|
||||
} else if (getCharacterLength() > 0) {
|
||||
// append data
|
||||
Encoder.appendBytes(stringToEncode.substring(position, position + getCharacterLength()), mode, bits,
|
||||
encoders[charsetEncoderIndex].charset());
|
||||
|
@ -970,7 +961,7 @@ final class MinimalEncoder {
|
|||
if (mode == Mode.ECI) {
|
||||
result.append(encoders[charsetEncoderIndex].charset().displayName());
|
||||
} else {
|
||||
result.append(makePrintable(stringToEncode.substring(position, position + getEncodingGranularity(mode))));
|
||||
result.append(makePrintable(stringToEncode.substring(position, position + length)));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
|
|
@ -668,190 +668,224 @@ public final class EncoderTestCase extends Assert {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder1() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("A", null, false).toString(), "BYTE(A),TERMINATOR()");
|
||||
public void testMinimalEncoder1() throws Exception {
|
||||
verifyMinimalEncoding("A", "ALPHANUMERIC(A),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder2() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("AB", null, false).toString(), "ALPHANUMERIC(AB),TERMINATOR()");
|
||||
public void testMinimalEncoder2() throws Exception {
|
||||
verifyMinimalEncoding("AB", "ALPHANUMERIC(AB),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder3() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("ABC", null, false).toString(), "BYTE(A,B,C),TERMINATOR()");
|
||||
public void testMinimalEncoder3() throws Exception {
|
||||
verifyMinimalEncoding("ABC", "ALPHANUMERIC(AB,C),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder4() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("ABCD", null, false).toString(), "ALPHANUMERIC(AB,CD),TERMINATOR()");
|
||||
public void testMinimalEncoder4() throws Exception {
|
||||
verifyMinimalEncoding("ABCD", "ALPHANUMERIC(AB,CD),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder5() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("ABCDE", null, false).toString(), "BYTE(A,B,C,D,E),TERMINATOR()");
|
||||
public void testMinimalEncoder5() throws Exception {
|
||||
verifyMinimalEncoding("ABCDE", "ALPHANUMERIC(AB,CD,E),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder6() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("ABCDEF", null, false).toString(), "ALPHANUMERIC(AB,CD,EF),TERMINATOR()");
|
||||
public void testMinimalEncoder6() throws Exception {
|
||||
verifyMinimalEncoding("ABCDEF", "ALPHANUMERIC(AB,CD,EF),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder7() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("ABCDEFG", null, false).toString(), "BYTE(A),ALPHANUMERIC(BC,DE,FG),TERMINATO" +
|
||||
"R()");
|
||||
public void testMinimalEncoder7() throws Exception {
|
||||
verifyMinimalEncoding("ABCDEFG", "ALPHANUMERIC(AB,CD,EF,G),TERMINATO" +
|
||||
"R()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder8() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("1", null, false).toString(), "BYTE(1),TERMINATOR()");
|
||||
public void testMinimalEncoder8() throws Exception {
|
||||
verifyMinimalEncoding("1", "NUMERIC(1),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder9() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("12", null, false).toString(), "ALPHANUMERIC(12),TERMINATOR()");
|
||||
public void testMinimalEncoder9() throws Exception {
|
||||
verifyMinimalEncoding("12", "NUMERIC(12),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder10() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("123", null, false).toString(), "NUMERIC(123),TERMINATOR()");
|
||||
public void testMinimalEncoder10() throws Exception {
|
||||
verifyMinimalEncoding("123", "NUMERIC(123),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder11() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("1234", null, false).toString(), "ALPHANUMERIC(12,34),TERMINATOR()");
|
||||
public void testMinimalEncoder11() throws Exception {
|
||||
verifyMinimalEncoding("1234", "NUMERIC(123,4),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder12() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("12345", null, false).toString(), "NUMERIC(123),ALPHANUMERIC(45),TERMINATOR()");
|
||||
public void testMinimalEncoder12() throws Exception {
|
||||
verifyMinimalEncoding("12345", "NUMERIC(123,45),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder13() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("123456", null, false).toString(), "NUMERIC(123,456),TERMINATOR()");
|
||||
public void testMinimalEncoder13() throws Exception {
|
||||
verifyMinimalEncoding("123456", "NUMERIC(123,456),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder14() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("123A", null, false).toString(), "ALPHANUMERIC(12,3A),TERMINATOR()");
|
||||
public void testMinimalEncoder14() throws Exception {
|
||||
verifyMinimalEncoding("123A", "ALPHANUMERIC(12,3A),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder15() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("A1", null, false).toString(), "ALPHANUMERIC(A1),TERMINATOR()");
|
||||
public void testMinimalEncoder15() throws Exception {
|
||||
verifyMinimalEncoding("A1", "ALPHANUMERIC(A1),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder16() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("A12", null, false).toString(), "BYTE(A,1,2),TERMINATOR()");
|
||||
public void testMinimalEncoder16() throws Exception {
|
||||
verifyMinimalEncoding("A12", "ALPHANUMERIC(A1,2),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder17() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("A123", null, false).toString(), "ALPHANUMERIC(A1,23),TERMINATOR()");
|
||||
public void testMinimalEncoder17() throws Exception {
|
||||
verifyMinimalEncoding("A123", "ALPHANUMERIC(A1,23),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder18() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("A1234", null, false).toString(), "ALPHANUMERIC(A1),NUMERIC(234),TERMINATOR()");
|
||||
public void testMinimalEncoder18() throws Exception {
|
||||
verifyMinimalEncoding("A1234", "ALPHANUMERIC(A1,23,4),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder19() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("AB1", null, false).toString(), "BYTE(A,B,1),TERMINATOR()");
|
||||
public void testMinimalEncoder19() throws Exception {
|
||||
verifyMinimalEncoding("A12345", "ALPHANUMERIC(A1,23,45),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder20() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("AB12", null, false).toString(), "ALPHANUMERIC(AB,12),TERMINATOR()");
|
||||
public void testMinimalEncoder20() throws Exception {
|
||||
verifyMinimalEncoding("A123456", "ALPHANUMERIC(A1,23,45,6),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder21() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("AB123", null, false).toString(), "ALPHANUMERIC(AB),NUMERIC(123),TERMINATOR()");
|
||||
public void testMinimalEncoder21() throws Exception {
|
||||
verifyMinimalEncoding("A1234567", "ALPHANUMERIC(A1,23,45,67),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder22() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("AB1234", null, false).toString(), "ALPHANUMERIC(AB,12,34),TERMINATOR()");
|
||||
public void testMinimalEncoder22() throws Exception {
|
||||
verifyMinimalEncoding("A12345678", "BYTE(A),NUMERIC(123,456,78),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder23() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("ABC1", null, false).toString(), "ALPHANUMERIC(AB,C1),TERMINATOR()");
|
||||
public void testMinimalEncoder23() throws Exception {
|
||||
verifyMinimalEncoding("A123456789", "BYTE(A),NUMERIC(123,456,789),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder24() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("ABC12", null, false).toString(), "BYTE(A,B,C,1,2),TERMINATOR()");
|
||||
public void testMinimalEncoder24() throws Exception {
|
||||
verifyMinimalEncoding("A1234567890", "ALPHANUMERIC(A1),NUMERIC(234,567,890),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder25() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("ABC1234", null, false).toString(), "ALPHANUMERIC(AB,C1),NUMERIC(234),TERMINA" +
|
||||
"TOR()");
|
||||
public void testMinimalEncoder25() throws Exception {
|
||||
verifyMinimalEncoding("AB1", "ALPHANUMERIC(AB,1),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder26() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("http://foo.com", null, false).toString(), "BYTE(h,t,t,p,:,/,/,f,o,o,.,c,o,m)" +
|
||||
",TERMINATOR()");
|
||||
public void testMinimalEncoder26() throws Exception {
|
||||
verifyMinimalEncoding("AB12", "ALPHANUMERIC(AB,12),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder27() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("HTTP://FOO.COM", null, false).toString(), "ALPHANUMERIC(HT,TP,:/,/F,OO,.C,OM" +
|
||||
"),TERMINATOR()");
|
||||
public void testMinimalEncoder27() throws Exception {
|
||||
verifyMinimalEncoding("AB123", "ALPHANUMERIC(AB,12,3),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder28() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("1001114670010%01201220%107211220%140045003267781", null, false).toString(),
|
||||
"NUMERIC(100,111,467,001),ALPHANUMERIC(0%,01,20,12,20,%1,07,21,12,20,%1,40),NUMERIC(045,003,267,781),TERMINA" +
|
||||
"TOR()");
|
||||
public void testMinimalEncoder28() throws Exception {
|
||||
verifyMinimalEncoding("AB1234", "ALPHANUMERIC(AB,12,34),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder29() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("\u0150", null, false).toString(), "ECI(ISO-8859-2),BYTE(.),TERMINATOR()");
|
||||
public void testMinimalEncoder29() throws Exception {
|
||||
verifyMinimalEncoding("ABC1", "ALPHANUMERIC(AB,C1),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder30() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("\u015C", null, false).toString(), "ECI(ISO-8859-3),BYTE(.),TERMINATOR()");
|
||||
public void testMinimalEncoder30() throws Exception {
|
||||
verifyMinimalEncoding("ABC12", "ALPHANUMERIC(AB,C1,2),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder31() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("\u0150\u015C", null, false).toString(), "ECI(UTF-8),BYTE(.,.),TERMINATOR()");
|
||||
public void testMinimalEncoder31() throws Exception {
|
||||
verifyMinimalEncoding("ABC1234", "ALPHANUMERIC(AB,C1,23,4),TERMINA" +
|
||||
"TOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder32() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("\u0150\u0150\u015C\u015C", null, false).toString(), "ECI(ISO-8859-2),BYTE(.," +
|
||||
".),ECI(ISO-8859-3),BYTE(.,.),TERMINATOR()");
|
||||
public void testMinimalEncoder32() throws Exception {
|
||||
verifyMinimalEncoding("http://foo.com", "BYTE(h,t,t,p,:,/,/,f,o,o,.,c,o,m)" +
|
||||
",TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder33() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("abcdef\u0150ghij", null, false).toString(), "ECI(ISO-8859-2),BYTE(a,b,c,d,e," +
|
||||
"f,.,g,h,i,j),TERMINATOR()");
|
||||
public void testMinimalEncoder33() throws Exception {
|
||||
verifyMinimalEncoding("HTTP://FOO.COM", "ALPHANUMERIC(HT,TP,:/,/F,OO,.C,OM" +
|
||||
"),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder34() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("2938928329832983\u01502938928329832983\u015C2938928329832983", null, false)
|
||||
.toString(), "NUMERIC(293,892,832,983,298),ECI(ISO-8859-2),BYTE(3,.,2),NUMERIC(938,928,329,832,983),ECI(ISO-8" +
|
||||
"859-3),BYTE(.,2),NUMERIC(938,928,329,832,983),TERMINATOR()");
|
||||
public void testMinimalEncoder34() throws Exception {
|
||||
verifyMinimalEncoding("1001114670010%01201220%107211220%140045003267781",
|
||||
"NUMERIC(100,111,467,001,0),ALPHANUMERIC(%0,12,01,22,0%,10,72,11,22,0%),NUMERIC(140,045,003,267,781),TERMINA" +
|
||||
"TOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder35() throws WriterException {
|
||||
assertEquals(MinimalEncoder.encode("1001114670010%01201220%107211220%140045003267781", null, true).toString(),
|
||||
"FNC1_FIRST_POSITION(),NUMERIC(100,111,467,001),ALPHANUMERIC(0%,01,20,12,20,%1,07,21,12,20,%1,40),NUMERIC(04" +
|
||||
"5,003,267,781),TERMINATOR()");
|
||||
public void testMinimalEncoder35() throws Exception {
|
||||
verifyMinimalEncoding("\u0150", "ECI(ISO-8859-2),BYTE(.),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder36() throws Exception {
|
||||
verifyMinimalEncoding("\u015C", "ECI(ISO-8859-3),BYTE(.),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder37() throws Exception {
|
||||
verifyMinimalEncoding("\u0150\u015C", "ECI(UTF-8),BYTE(.,.),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder38() throws Exception {
|
||||
verifyMinimalEncoding("\u0150\u0150\u015C\u015C", "ECI(ISO-8859-2),BYTE(.," +
|
||||
".),ECI(ISO-8859-3),BYTE(.,.),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder39() throws Exception {
|
||||
verifyMinimalEncoding("abcdef\u0150ghij", "ECI(ISO-8859-2),BYTE(a,b,c,d,e," +
|
||||
"f,.,g,h,i,j),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder40() throws Exception {
|
||||
verifyMinimalEncoding("2938928329832983\u01502938928329832983\u015C2938928329832983",
|
||||
"NUMERIC(293,892,832,983,298,3),ECI(ISO-8859-2),BYTE(.),NUMERIC(293,892,832,983,298,3),ECI(ISO-8" +
|
||||
"859-3),BYTE(.),NUMERIC(293,892,832,983,298,3),TERMINATOR()", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalEncoder41() throws Exception {
|
||||
verifyMinimalEncoding("1001114670010%01201220%107211220%140045003267781", "FNC1_FIRST_POSITION(),NUMERIC(100,111" +
|
||||
",467,001,0),ALPHANUMERIC(%0,12,01,22,0%,10,72,11,22,0%),NUMERIC(140,045,003,267,781),TERMINATOR()", true);
|
||||
}
|
||||
|
||||
static void verifyMinimalEncoding(String input, String expectedResult, boolean isGS1) throws Exception {
|
||||
MinimalEncoder.ResultList result = MinimalEncoder.encode(input, null, isGS1);
|
||||
assertEquals(result.toString(), expectedResult);
|
||||
}
|
||||
|
||||
private static void verifyGS1EncodedData(QRCode qrCode) {
|
||||
|
|
Loading…
Reference in a new issue