"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "core/src/test/java/com/google/zxing/qrcode/encoder/EncoderTestCase.java" between
zxing-zxing-3.4.1.tar.gz and zxing-zxing-3.5.0.tar.gz

About: ZXing ("zebra crossing") is a multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages. Info: Project is in maintenance mode (no active development).

EncoderTestCase.java  (zxing-zxing-3.4.1):EncoderTestCase.java  (zxing-zxing-3.5.0)
skipping to change at line 22 skipping to change at line 22
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.zxing.qrcode.encoder; package com.google.zxing.qrcode.encoder;
import com.google.zxing.EncodeHintType; import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException; import com.google.zxing.WriterException;
import com.google.zxing.common.BitArray; import com.google.zxing.common.BitArray;
import com.google.zxing.common.StringUtils;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.google.zxing.qrcode.decoder.Mode; import com.google.zxing.qrcode.decoder.Mode;
import com.google.zxing.qrcode.decoder.Version; import com.google.zxing.qrcode.decoder.Version;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.io.UnsupportedEncodingException;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import java.nio.charset.Charset;
/** /**
* @author satorux@google.com (Satoru Takabayashi) - creator * @author satorux@google.com (Satoru Takabayashi) - creator
* @author mysen@google.com (Chris Mysen) - ported from C++ * @author mysen@google.com (Chris Mysen) - ported from C++
*/ */
public final class EncoderTestCase extends Assert { public final class EncoderTestCase extends Assert {
@Test @Test
public void testGetAlphanumericCode() { public void testGetAlphanumericCode() {
// The first ten code points are numbers. // The first ten code points are numbers.
skipping to change at line 69 skipping to change at line 70
assertEquals(43, Encoder.getAlphanumericCode('/')); assertEquals(43, Encoder.getAlphanumericCode('/'));
assertEquals(44, Encoder.getAlphanumericCode(':')); assertEquals(44, Encoder.getAlphanumericCode(':'));
// Should return -1 for other letters; // Should return -1 for other letters;
assertEquals(-1, Encoder.getAlphanumericCode('a')); assertEquals(-1, Encoder.getAlphanumericCode('a'));
assertEquals(-1, Encoder.getAlphanumericCode('#')); assertEquals(-1, Encoder.getAlphanumericCode('#'));
assertEquals(-1, Encoder.getAlphanumericCode('\0')); assertEquals(-1, Encoder.getAlphanumericCode('\0'));
} }
@Test @Test
public void testChooseMode() throws WriterException { public void testChooseMode() {
// Numeric mode. // Numeric mode.
assertSame(Mode.NUMERIC, Encoder.chooseMode("0")); assertSame(Mode.NUMERIC, Encoder.chooseMode("0"));
assertSame(Mode.NUMERIC, Encoder.chooseMode("0123456789")); assertSame(Mode.NUMERIC, Encoder.chooseMode("0123456789"));
// Alphanumeric mode. // Alphanumeric mode.
assertSame(Mode.ALPHANUMERIC, Encoder.chooseMode("A")); assertSame(Mode.ALPHANUMERIC, Encoder.chooseMode("A"));
assertSame(Mode.ALPHANUMERIC, assertSame(Mode.ALPHANUMERIC,
Encoder.chooseMode("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./: ")); Encoder.chooseMode("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./: "));
// 8-bit byte mode. // 8-bit byte mode.
assertSame(Mode.BYTE, Encoder.chooseMode("a")); assertSame(Mode.BYTE, Encoder.chooseMode("a"));
assertSame(Mode.BYTE, Encoder.chooseMode("#")); assertSame(Mode.BYTE, Encoder.chooseMode("#"));
skipping to change at line 99 skipping to change at line 100
// Nihon in Kanji in Shift_JIS. // Nihon in Kanji in Shift_JIS.
assertSame(Mode.BYTE, Encoder.chooseMode(shiftJISString(bytes(0x9, 0xf, 0x9, 0x7b)))); assertSame(Mode.BYTE, Encoder.chooseMode(shiftJISString(bytes(0x9, 0xf, 0x9, 0x7b))));
// Sou-Utsu-Byou in Kanji in Shift_JIS. // Sou-Utsu-Byou in Kanji in Shift_JIS.
assertSame(Mode.BYTE, Encoder.chooseMode(shiftJISString(bytes(0xe, 0x4, 0x9, 0x5, 0x9, 0x61)))); assertSame(Mode.BYTE, Encoder.chooseMode(shiftJISString(bytes(0xe, 0x4, 0x9, 0x5, 0x9, 0x61))));
} }
@Test @Test
public void testEncode() throws WriterException { public void testEncode() throws WriterException {
QRCode qrCode = Encoder.encode("ABCDEF", ErrorCorrectionLevel.H); QRCode qrCode = Encoder.encode("ABCDEF", ErrorCorrectionLevel.H);
String expected = String expected = "<<\n" +
"<<\n" + " mode: ALPHANUMERIC\n" +
" mode: ALPHANUMERIC\n" + " ecLevel: H\n" +
" ecLevel: H\n" + " version: 1\n" +
" version: 1\n" + " maskPattern: 0\n" +
" maskPattern: 4\n" + " matrix:\n" +
" matrix:\n" + " 1 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 1 1 1 1\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 0 1 1 1 0 0 1 0 0 0 0 0 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 1 0 1 1 0 1 0 1 1 1 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 1 1 1 0 1 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 1 1 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 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 1\n" +
" 1 0 0 0 0 0 1 0 1 0 0 1 1 0 1 0 0 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 0 1 0 0 1 0 0 0 1 1 0 0 1 1\n" + " 1 0 1 1 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 1 0\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 1 0 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 0 1 1 0 0 0 0\n" + " 1 0 0 0 0 0 1 0 0 1 1 0 1 1 0 1 0 0 0 1 1\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 0 0 0 0 0 0 1 0 1 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";
">>\n";
assertEquals(expected, qrCode.toString()); assertEquals(expected, qrCode.toString());
} }
@Test @Test
public void testEncodeWithVersion() throws WriterException { public void testEncodeWithVersion() throws WriterException {
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class); Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.QR_VERSION, 7); hints.put(EncodeHintType.QR_VERSION, 7);
QRCode qrCode = Encoder.encode("ABCDEF", ErrorCorrectionLevel.H, hints); QRCode qrCode = Encoder.encode("ABCDEF", ErrorCorrectionLevel.H, hints);
assertTrue(qrCode.toString().contains(" version: 7\n")); assertTrue(qrCode.toString().contains(" version: 7\n"));
} }
skipping to change at line 151 skipping to change at line 151
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class); Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.QR_VERSION, 3); hints.put(EncodeHintType.QR_VERSION, 3);
Encoder.encode("THISMESSAGEISTOOLONGFORAQRCODEVERSION3", ErrorCorrectionLeve l.H, hints); Encoder.encode("THISMESSAGEISTOOLONGFORAQRCODEVERSION3", ErrorCorrectionLeve l.H, hints);
} }
@Test @Test
public void testSimpleUTF8ECI() throws WriterException { public void testSimpleUTF8ECI() throws WriterException {
Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class); Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, "UTF8"); hints.put(EncodeHintType.CHARACTER_SET, "UTF8");
QRCode qrCode = Encoder.encode("hello", ErrorCorrectionLevel.H, hints); QRCode qrCode = Encoder.encode("hello", ErrorCorrectionLevel.H, hints);
String expected = String expected = "<<\n" +
"<<\n" + " mode: BYTE\n" +
" mode: BYTE\n" + " ecLevel: H\n" +
" ecLevel: H\n" + " version: 1\n" +
" version: 1\n" + " maskPattern: 3\n" +
" maskPattern: 6\n" + " matrix:\n" +
" matrix:\n" + " 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1\n" +
" 1 1 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 1 1 1 1\n" + " 1 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 1\n" +
" 1 0 0 0 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 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 0 1 1 0 1 0 1 1 1 0 1\n" + " 1 0 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 1\n" +
" 1 0 1 1 1 0 1 0 1 0 0 0 1 0 1 0 1 1 1 0 1\n" + " 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1\n" +
" 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1\n" + " 1 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1\n" +
" 1 0 0 0 0 0 1 0 0 0 0 1 0 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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0 1 0 0 0 1 1 0 0 0\n" +
" 1 0 1 1 1 0 1 0 1 1 1 1 0 1 0 0 1 0 1 1 0\n" + " 1 0 1 1 1 0 1 0 1 1 0 0 0 1 0 0 1 0 0 0 0\n" +
" 1 0 1 1 1 0 1 0 0 1 1 1 0 0 1 0 0 1 0 1 1\n" + " 1 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 1 1 0\n" +
" 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 0 0\n" + " 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 1 1 0 0 0 0\n" +
" 1 1 1 1 1 1 1 0 0 0 0 1 0 1 0 0 1 0 1 0 0\n" + ">>\n";
">>\n";
assertEquals(expected, qrCode.toString()); assertEquals(expected, qrCode.toString());
} }
@Test @Test
public void testEncodeKanjiMode() throws WriterException { public void testEncodeKanjiMode() throws WriterException {
Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class); Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, "Shift_JIS"); hints.put(EncodeHintType.CHARACTER_SET, "Shift_JIS");
// Nihon in Kanji // Nihon in Kanji
QRCode qrCode = Encoder.encode("\u65e5\u672c", ErrorCorrectionLevel.M, hints ); QRCode qrCode = Encoder.encode("\u65e5\u672c", ErrorCorrectionLevel.M, hints );
String expected = String expected = "<<\n" +
"<<\n" + " mode: KANJI\n" +
" mode: KANJI\n" + " ecLevel: M\n" +
" ecLevel: M\n" + " version: 1\n" +
" version: 1\n" + " maskPattern: 4\n" +
" maskPattern: 0\n" + " matrix:\n" +
" matrix:\n" + " 1 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 1 1 1 1\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 0 0 0 1 1 0 1 0 0 0 0 0 1\n" +
" 1 0 0 0 0 0 1 0 1 1 0 0 0 0 1 0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1 1 0 1 1 0 1 0 1 1 1 0 1 0 0 1\n" + " 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 0 1 0 0 0\n" +
" 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 1 0 1\n" + " 1 1 1 1 1 1 1 0 1 1 0 1 0 0 1 1 1 1 1 1 0\n" +
" 1 1 1 1 1 1 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1\n" + " 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1\n" +
" 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 1 1\n" + " 1 0 1 1 1 0 1 0 1 0 1 0 1 1 1 0 0 0 1 1 1\n" +
" 1 0 1 1 1 0 1 0 1 0 0 0 1 0 1 0 1 0 1 0 1\n" + " 1 0 1 1 1 0 1 0 0 1 0 0 1 1 1 0 0 0 1 1 1\n" +
" 1 0 1 1 1 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0\n" + " 1 0 1 1 1 0 1 0 0 1 1 0 1 1 0 0 0 1 0 0 0\n" +
" 1 0 1 1 1 0 1 0 1 0 1 1 0 1 1 1 0 0 1 0 1\n" + " 1 0 0 0 0 0 1 0 0 0 1 1 1 0 0 1 0 1 0 0 0\n" +
" 1 0 0 0 0 0 1 0 0 0 0 1 1 1 0 1 1 1 0 1 0\n" + " 1 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 0 1 1 0\n" +
" 1 1 1 1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 0 0\n" + ">>\n";
">>\n";
assertEquals(expected, qrCode.toString()); assertEquals(expected, qrCode.toString());
} }
@Test @Test
public void testEncodeShiftjisNumeric() throws WriterException { public void testEncodeShiftjisNumeric() throws WriterException {
Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class); Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, "Shift_JIS"); hints.put(EncodeHintType.CHARACTER_SET, "Shift_JIS");
QRCode qrCode = Encoder.encode("0123", ErrorCorrectionLevel.M, hints); QRCode qrCode = Encoder.encode("0123", ErrorCorrectionLevel.M, hints);
String expected = String expected = "<<\n" +
"<<\n" + " mode: NUMERIC\n" +
" mode: NUMERIC\n" + " ecLevel: M\n" +
" ecLevel: M\n" + " version: 1\n" +
" version: 1\n" + " maskPattern: 0\n" +
" maskPattern: 2\n" + " matrix:\n" +
" matrix:\n" + " 1 1 1 1 1 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 1\n" +
" 1 1 1 1 1 1 1 0 0 1 1 0 1 0 1 1 1 1 1 1 1\n" + " 1 0 0 0 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 0 1\n" +
" 1 0 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 1\n" + " 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1\n" +
" 1 0 1 1 1 0 1 0 1 0 0 0 0 0 1 0 1 1 1 0 1\n" + " 1 0 1 1 1 0 1 0 0 0 1 0 0 0 1 0 1 1 1 0 1\n" +
" 1 0 1 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1\n" + " 1 0 1 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1\n" +
" 1 0 1 1 1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 0 1\n" + " 1 0 0 0 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0 1\n" +
" 1 0 0 0 0 0 1 0 1 1 0 0 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" +
" 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 0 1 1 0 0 0 0 0 0 0 0 0 0\n" +
" 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0\n" + " 1 0 1 0 1 0 1 0 0 0 0 0 1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0 0 0 0 1 0 0 0 1 1 1 1 0 1 1 1 0 0 0\n" +
" 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 1 1 0\n" + " 1 1 1 1 1 1 1 0 1 0 1 1 0 1 1 1 0 1 1 0 1\n" +
" 1 1 1 1 1 1 1 0 1 1 0 1 0 1 0 0 1 1 1 0 0\n" + ">>\n";
">>\n";
assertEquals(expected, qrCode.toString()); assertEquals(expected, qrCode.toString());
} }
@Test @Test
public void testEncodeGS1WithStringTypeHint() throws WriterException { public void testEncodeGS1WithStringTypeHint() throws WriterException {
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class); Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.GS1_FORMAT, "true"); hints.put(EncodeHintType.GS1_FORMAT, "true");
QRCode qrCode = Encoder.encode("100001%11171218", ErrorCorrectionLevel.H, hi nts); QRCode qrCode = Encoder.encode("100001%11171218", ErrorCorrectionLevel.H, hi nts);
verifyGS1EncodedData(qrCode); verifyGS1EncodedData(qrCode);
} }
skipping to change at line 296 skipping to change at line 293
QRCode qrCode = Encoder.encode("ABCDEF", ErrorCorrectionLevel.H, hints); QRCode qrCode = Encoder.encode("ABCDEF", ErrorCorrectionLevel.H, hints);
verifyNotGS1EncodedData(qrCode); verifyNotGS1EncodedData(qrCode);
} }
@Test @Test
public void testGS1ModeHeaderWithECI() throws WriterException { public void testGS1ModeHeaderWithECI() throws WriterException {
Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class); Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, "UTF8"); hints.put(EncodeHintType.CHARACTER_SET, "UTF8");
hints.put(EncodeHintType.GS1_FORMAT, true); hints.put(EncodeHintType.GS1_FORMAT, true);
QRCode qrCode = Encoder.encode("hello", ErrorCorrectionLevel.H, hints); QRCode qrCode = Encoder.encode("hello", ErrorCorrectionLevel.H, hints);
String expected = String expected = "<<\n" +
"<<\n" + " mode: BYTE\n" +
" mode: BYTE\n" + " ecLevel: H\n" +
" ecLevel: H\n" + " version: 1\n" +
" version: 1\n" + " maskPattern: 6\n" +
" maskPattern: 5\n" + " matrix:\n" +
" matrix:\n" + " 1 1 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 1 1 1 1\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 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 0 0 0 0 1 0 1 1 1 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 1 1 0 1 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 0 0 1 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 0 0 1 0 1 0 0 0 0 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" +
" 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 0 0 1 1 1 0 0 0 0 0 0 0 0\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 1 1 0 1 1 0 1 0 0 0 0 0 0 0 1 1 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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0 0 1 0 1 0 0 1 0 0 0 0 0 0\n" +
" 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 1 0 0 1 0\n" + ">>\n";
">>\n";
assertEquals(expected, qrCode.toString()); assertEquals(expected, qrCode.toString());
} }
@Test @Test
public void testAppendModeInfo() { public void testAppendModeInfo() {
BitArray bits = new BitArray(); BitArray bits = new BitArray();
Encoder.appendModeInfo(Mode.NUMERIC, bits); Encoder.appendModeInfo(Mode.NUMERIC, bits);
assertEquals(" ...X", bits.toString()); assertEquals(" ...X", bits.toString());
} }
skipping to change at line 583 skipping to change at line 579
assertEquals("" , bits.toString()); assertEquals("" , bits.toString());
// Invalid data. // Invalid data.
try { try {
Encoder.appendAlphanumericBytes("abc", new BitArray()); Encoder.appendAlphanumericBytes("abc", new BitArray());
} catch (WriterException we) { } catch (WriterException we) {
// good // good
} }
} }
@Test @Test
public void testAppend8BitBytes() throws WriterException { public void testAppend8BitBytes() {
// 0x61, 0x62, 0x63 // 0x61, 0x62, 0x63
BitArray bits = new BitArray(); BitArray bits = new BitArray();
Encoder.append8BitBytes("abc", bits, Encoder.DEFAULT_BYTE_MODE_ENCODING); Encoder.append8BitBytes("abc", bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
assertEquals(" .XX....X .XX...X. .XX...XX", bits.toString()); assertEquals(" .XX....X .XX...X. .XX...XX", bits.toString());
// Empty. // Empty.
bits = new BitArray(); bits = new BitArray();
Encoder.append8BitBytes("", bits, Encoder.DEFAULT_BYTE_MODE_ENCODING); Encoder.append8BitBytes("", bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
assertEquals("", bits.toString()); assertEquals("", bits.toString());
} }
// Numbers are from page 21 of JISX0510:2004 // Numbers are from page 21 of JISX0510:2004
@Test @Test
public void testAppendKanjiBytes() throws WriterException { public void testAppendKanjiBytes() throws WriterException {
BitArray bits = new BitArray(); BitArray bits = new BitArray();
Encoder.appendKanjiBytes(shiftJISString(bytes(0x93, 0x5f)), bits); Encoder.appendKanjiBytes(shiftJISString(bytes(0x93, 0x5f)), bits);
assertEquals(" .XX.XX.. XXXXX", bits.toString()); assertEquals(" .XX.XX.. XXXXX", bits.toString());
Encoder.appendKanjiBytes(shiftJISString(bytes(0xe4, 0xaa)), bits); Encoder.appendKanjiBytes(shiftJISString(bytes(0xe4, 0xaa)), bits);
assertEquals(" .XX.XX.. XXXXXXX. X.X.X.X. X.", bits.toString()); assertEquals(" .XX.XX.. XXXXXXX. X.X.X.X. X.", bits.toString());
} }
// Numbers are from http://www.swetake.com/qr/qr3.html and // Numbers are from http://www.swetake.com/qr/qr3.html and
// http://www.swetake.com/qr/qr9.html // http://www.swetake.com/qr/qr9.html
@Test @Test
public void testGenerateECBytes() { public void testGenerateECBytes() {
byte[] dataBytes = bytes(32, 65, 205, 69, 41, 220, 46, 128, 236); byte[] dataBytes = bytes(32, 65, 205, 69, 41, 220, 46, 128, 236);
byte[] ecBytes = Encoder.generateECBytes(dataBytes, 17); byte[] ecBytes = Encoder.generateECBytes(dataBytes, 17);
int[] expected = { int[] expected = {
42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219 , 61 42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219 , 61
skipping to change at line 675 skipping to change at line 671
// - To be precise, it needs 11727 + 4 (getMode info) + 14 (length info) = // - To be precise, it needs 11727 + 4 (getMode info) + 14 (length info) =
// 11745 bits = 1468.125 bytes are needed (i.e. cannot fit in 1468 // 11745 bits = 1468.125 bytes are needed (i.e. cannot fit in 1468
// bytes). // bytes).
StringBuilder builder = new StringBuilder(3518); StringBuilder builder = new StringBuilder(3518);
for (int x = 0; x < 3518; x++) { for (int x = 0; x < 3518; x++) {
builder.append('0'); builder.append('0');
} }
Encoder.encode(builder.toString(), ErrorCorrectionLevel.L); Encoder.encode(builder.toString(), ErrorCorrectionLevel.L);
} }
@Test
public void testMinimalEncoder1() throws Exception {
verifyMinimalEncoding("A", "ALPHANUMERIC(A)", null, false);
}
@Test
public void testMinimalEncoder2() throws Exception {
verifyMinimalEncoding("AB", "ALPHANUMERIC(AB)", null, false);
}
@Test
public void testMinimalEncoder3() throws Exception {
verifyMinimalEncoding("ABC", "ALPHANUMERIC(ABC)", null, false);
}
@Test
public void testMinimalEncoder4() throws Exception {
verifyMinimalEncoding("ABCD", "ALPHANUMERIC(ABCD)", null, false);
}
@Test
public void testMinimalEncoder5() throws Exception {
verifyMinimalEncoding("ABCDE", "ALPHANUMERIC(ABCDE)", null, false);
}
@Test
public void testMinimalEncoder6() throws Exception {
verifyMinimalEncoding("ABCDEF", "ALPHANUMERIC(ABCDEF)", null, false);
}
@Test
public void testMinimalEncoder7() throws Exception {
verifyMinimalEncoding("ABCDEFG", "ALPHANUMERIC(ABCDEFG)", null, false);
}
@Test
public void testMinimalEncoder8() throws Exception {
verifyMinimalEncoding("1", "NUMERIC(1)", null, false);
}
@Test
public void testMinimalEncoder9() throws Exception {
verifyMinimalEncoding("12", "NUMERIC(12)", null, false);
}
@Test
public void testMinimalEncoder10() throws Exception {
verifyMinimalEncoding("123", "NUMERIC(123)", null, false);
}
@Test
public void testMinimalEncoder11() throws Exception {
verifyMinimalEncoding("1234", "NUMERIC(1234)", null, false);
}
@Test
public void testMinimalEncoder12() throws Exception {
verifyMinimalEncoding("12345", "NUMERIC(12345)", null, false);
}
@Test
public void testMinimalEncoder13() throws Exception {
verifyMinimalEncoding("123456", "NUMERIC(123456)", null, false);
}
@Test
public void testMinimalEncoder14() throws Exception {
verifyMinimalEncoding("123A", "ALPHANUMERIC(123A)", null, false);
}
@Test
public void testMinimalEncoder15() throws Exception {
verifyMinimalEncoding("A1", "ALPHANUMERIC(A1)", null, false);
}
@Test
public void testMinimalEncoder16() throws Exception {
verifyMinimalEncoding("A12", "ALPHANUMERIC(A12)", null, false);
}
@Test
public void testMinimalEncoder17() throws Exception {
verifyMinimalEncoding("A123", "ALPHANUMERIC(A123)", null, false);
}
@Test
public void testMinimalEncoder18() throws Exception {
verifyMinimalEncoding("A1234", "ALPHANUMERIC(A1234)", null, false);
}
@Test
public void testMinimalEncoder19() throws Exception {
verifyMinimalEncoding("A12345", "ALPHANUMERIC(A12345)", null, false);
}
@Test
public void testMinimalEncoder20() throws Exception {
verifyMinimalEncoding("A123456", "ALPHANUMERIC(A123456)", null, false);
}
@Test
public void testMinimalEncoder21() throws Exception {
verifyMinimalEncoding("A1234567", "ALPHANUMERIC(A1234567)", null, false);
}
@Test
public void testMinimalEncoder22() throws Exception {
verifyMinimalEncoding("A12345678", "BYTE(A),NUMERIC(12345678)", null, false)
;
}
@Test
public void testMinimalEncoder23() throws Exception {
verifyMinimalEncoding("A123456789", "BYTE(A),NUMERIC(123456789)", null, fals
e);
}
@Test
public void testMinimalEncoder24() throws Exception {
verifyMinimalEncoding("A1234567890", "ALPHANUMERIC(A1),NUMERIC(234567890)",
null, false);
}
@Test
public void testMinimalEncoder25() throws Exception {
verifyMinimalEncoding("AB1", "ALPHANUMERIC(AB1)", null, false);
}
@Test
public void testMinimalEncoder26() throws Exception {
verifyMinimalEncoding("AB12", "ALPHANUMERIC(AB12)", null, false);
}
@Test
public void testMinimalEncoder27() throws Exception {
verifyMinimalEncoding("AB123", "ALPHANUMERIC(AB123)", null, false);
}
@Test
public void testMinimalEncoder28() throws Exception {
verifyMinimalEncoding("AB1234", "ALPHANUMERIC(AB1234)", null, false);
}
@Test
public void testMinimalEncoder29() throws Exception {
verifyMinimalEncoding("ABC1", "ALPHANUMERIC(ABC1)", null, false);
}
@Test
public void testMinimalEncoder30() throws Exception {
verifyMinimalEncoding("ABC12", "ALPHANUMERIC(ABC12)", null, false);
}
@Test
public void testMinimalEncoder31() throws Exception {
verifyMinimalEncoding("ABC1234", "ALPHANUMERIC(ABC1234)", null, false);
}
@Test
public void testMinimalEncoder32() throws Exception {
verifyMinimalEncoding("http://foo.com", "BYTE(http://foo.com)" +
"", null, false);
}
@Test
public void testMinimalEncoder33() throws Exception {
verifyMinimalEncoding("HTTP://FOO.COM", "ALPHANUMERIC(HTTP://FOO.COM" +
")", null, false);
}
@Test
public void testMinimalEncoder34() throws Exception {
verifyMinimalEncoding("1001114670010%01201220%107211220%140045003267781",
"NUMERIC(1001114670010),ALPHANUMERIC(%01201220%107211220%),NUMERIC(14004
5003267781)", null, false);
}
@Test
public void testMinimalEncoder35() throws Exception {
verifyMinimalEncoding("\u0150", "ECI(ISO-8859-2),BYTE(.)", null, false);
}
@Test
public void testMinimalEncoder36() throws Exception {
verifyMinimalEncoding("\u015C", "ECI(ISO-8859-3),BYTE(.)", null, false);
}
@Test
public void testMinimalEncoder37() throws Exception {
verifyMinimalEncoding("\u0150\u015C", "ECI(UTF-8),BYTE(..)", null, false);
}
@Test
public void testMinimalEncoder38() throws Exception {
verifyMinimalEncoding("\u0150\u0150\u015C\u015C", "ECI(ISO-8859-2),BYTE(." +
".),ECI(ISO-8859-3),BYTE(..)", null, false);
}
@Test
public void testMinimalEncoder39() throws Exception {
verifyMinimalEncoding("abcdef\u0150ghij", "ECI(ISO-8859-2),BYTE(abcde" +
"f.ghij)", null, false);
}
@Test
public void testMinimalEncoder40() throws Exception {
verifyMinimalEncoding("2938928329832983\u01502938928329832983\u015C293892832
9832983",
"NUMERIC(2938928329832983),ECI(ISO-8859-2),BYTE(.),NUMERIC(2938928329832
983),ECI(ISO-8" +
"859-3),BYTE(.),NUMERIC(2938928329832983)", null, false);
}
@Test
public void testMinimalEncoder41() throws Exception {
verifyMinimalEncoding("1001114670010%01201220%107211220%140045003267781", "F
NC1_FIRST_POSITION(),NUMERIC(100111" +
"4670010),ALPHANUMERIC(%01201220%107211220%),NUMERIC(140045003267781)",
null,
true);
}
@Test
public void testMinimalEncoder42() throws Exception {
// test halfwidth Katakana character (they are single byte encoded in Shift_
JIS)
verifyMinimalEncoding("Katakana:\uFF66\uFF66\uFF66\uFF66\uFF66\uFF66", "ECI(
Shift_JIS),BYTE(Katakana:......)", null
, false);
}
@Test
public void testMinimalEncoder43() throws Exception {
// The character \u30A2 encodes as double byte in Shift_JIS so KANJI is more
compact in this case
verifyMinimalEncoding("Katakana:\u30A2\u30A2\u30A2\u30A2\u30A2\u30A2", "BYTE
(Katakana:),KANJI(......)", null,
false);
}
@Test
public void testMinimalEncoder44() throws Exception {
// The character \u30A2 encodes as double byte in Shift_JIS but KANJI is not
more compact in this case because
// KANJI is only more compact when it encodes pairs of characters. In the ca
se of mixed text it can however be
// that Shift_JIS encoding is more compact as in this example
verifyMinimalEncoding("Katakana:\u30A2a\u30A2a\u30A2a\u30A2a\u30A2a\u30A2",
"ECI(Shift_JIS),BYTE(Katakana:.a.a.a" +
".a.a.)", null, false);
}
static void verifyMinimalEncoding(String input, String expectedResult, Charset
priorityCharset, boolean isGS1)
throws Exception {
MinimalEncoder.ResultList result = MinimalEncoder.encode(input, null, priori
tyCharset, isGS1,
ErrorCorrectionLevel.L);
assertEquals(result.toString(), expectedResult);
}
private static void verifyGS1EncodedData(QRCode qrCode) { private static void verifyGS1EncodedData(QRCode qrCode) {
String expected = String expected = "<<\n" +
"<<\n" + " mode: ALPHANUMERIC\n" +
" mode: ALPHANUMERIC\n" + " ecLevel: H\n" +
" ecLevel: H\n" + " version: 2\n" +
" version: 2\n" + " maskPattern: 2\n" +
" maskPattern: 4\n" + " matrix:\n" +
" matrix:\n" + " 1 1 1 1 1 1 1 0 1 0 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1\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 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 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 1 0 1 0 1 0 1 1 0 1 1 0 0 0 1 0 1 1 1 0 1\n" +
" 1 0 1 1 1 0 1 0 0 0 0 0 1 1 1 0 1 0 1 0 1 1 1 0 1\n" + " 1 0 1 1 1 0 1 0 0 1 1 0 1 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0 0 0 1 1 1 0 0 1 1 0 1 0 0 0\n" + " 1 0 1 1 1 0 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 0 1\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 0 1 0 1 1 1 0 1 0 0 1 1 1 1 1\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 1 1 0 0 1 1 0 1 0 0 0 0 1 0 1 1\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";
">>\n";
assertEquals(expected, qrCode.toString()); assertEquals(expected, qrCode.toString());
} }
private static void verifyNotGS1EncodedData(QRCode qrCode) { private static void verifyNotGS1EncodedData(QRCode qrCode) {
String expected = String expected = "<<\n" +
"<<\n" + " mode: ALPHANUMERIC\n" +
" mode: ALPHANUMERIC\n" + " ecLevel: H\n" +
" ecLevel: H\n" + " version: 1\n" +
" version: 1\n" + " maskPattern: 0\n" +
" maskPattern: 4\n" + " matrix:\n" +
" matrix:\n" + " 1 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 1 1 1 1\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 0 1 1 1 0 0 1 0 0 0 0 0 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 1 0 1 1 0 1 0 1 1 1 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 1 1 1 0 1 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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" 1 0 0 0 0 0 1 0 1 1 1 1 0 1 0 1 1 1 1 0 1\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 1 1 0 1 0 1 0 0 0 0 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 1 1 0 1 1 1 1 0 1 0 1 0\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 1 0 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 0 1 1 0 0 0 0\n" + " 1 0 0 0 0 0 1 0 0 1 1 0 1 1 0 1 0 0 0 1 1\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 0 0 0 0 0 0 1 0 1 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";
">>\n";
assertEquals(expected, qrCode.toString()); assertEquals(expected, qrCode.toString());
} }
private static String shiftJISString(byte[] bytes) throws WriterException { private static String shiftJISString(byte[] bytes) {
try { return new String(bytes, StringUtils.SHIFT_JIS_CHARSET);
return new String(bytes, "Shift_JIS");
} catch (UnsupportedEncodingException uee) {
throw new WriterException(uee.toString());
}
} }
} }
 End of changes. 15 change blocks. 
220 lines changed or deleted 471 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)