use of com.google.zxing.common.BitArray in project zxing by zxing.
the class EncoderTestCase method testAppendLengthInfo.
@Test
public void testAppendLengthInfo() throws WriterException {
BitArray bits = new BitArray();
// 1 letter (1/1).
Encoder.appendLengthInfo(// 1 letter (1/1).
1, Version.getVersionForNumber(1), Mode.NUMERIC, bits);
// 10 bits.
assertEquals(" ........ .X", bits.toString());
bits = new BitArray();
// 2 letters (2/1).
Encoder.appendLengthInfo(// 2 letters (2/1).
2, Version.getVersionForNumber(10), Mode.ALPHANUMERIC, bits);
// 11 bits.
assertEquals(" ........ .X.", bits.toString());
bits = new BitArray();
// 255 letter (255/1).
Encoder.appendLengthInfo(// 255 letter (255/1).
255, Version.getVersionForNumber(27), Mode.BYTE, bits);
// 16 bits.
assertEquals(" ........ XXXXXXXX", bits.toString());
bits = new BitArray();
// 512 letters (1024/2).
Encoder.appendLengthInfo(// 512 letters (1024/2).
512, Version.getVersionForNumber(40), Mode.KANJI, bits);
// 12 bits.
assertEquals(" ..X..... ....", bits.toString());
}
use of com.google.zxing.common.BitArray in project zxing by zxing.
the class MatrixUtilTestCase method testBuildMatrix.
@Test
public void testBuildMatrix() throws WriterException {
// From http://www.swetake.com/qr/qr7.html
char[] bytes = { 32, 65, 205, 69, 41, 220, 46, 128, 236, 42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61 };
BitArray bits = new BitArray();
for (char c : bytes) {
bits.appendBits(c, 8);
}
ByteMatrix matrix = new ByteMatrix(21, 21);
MatrixUtil.buildMatrix(bits, ErrorCorrectionLevel.H, // Version 1
Version.getVersionForNumber(1), // Mask pattern 3
3, matrix);
String expected = " 1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1\n" + " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" + " 1 0 1 1 1 0 1 0 0 0 0 1 0 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 1 1 1 0 1 0 1 1 0 0 1 0 1 0 1 1 1 0 1\n" + " 1 0 0 0 0 0 1 0 0 0 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" + " 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0\n" + " 0 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 0 0 0 0\n" + " 1 0 1 0 1 0 0 0 0 0 1 1 1 0 0 1 0 1 1 1 0\n" + " 1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 1 1 0 1 0\n" + " 1 0 1 0 1 1 0 1 1 1 0 0 1 1 1 0 0 1 0 1 0\n" + " 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 1 1 1 1\n" + " 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 1 1\n" + " 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 0 1 0 1 1 0\n" + " 1 0 0 0 0 0 1 0 0 0 0 1 0 1 1 1 0 0 0 0 0\n" + " 1 0 1 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1\n" + " 1 0 1 1 1 0 1 0 1 1 0 1 0 0 0 0 0 1 1 1 0\n" + " 1 0 1 1 1 0 1 0 1 1 1 1 0 0 0 0 1 1 1 0 0\n" + " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0\n" + " 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 1 0\n";
assertEquals(expected, matrix.toString());
}
use of com.google.zxing.common.BitArray in project zxing by zxing.
the class MatrixUtilTestCase method testEmbedDataBits.
@Test
public void testEmbedDataBits() throws WriterException {
// Cells other than basic patterns should be filled with zero.
ByteMatrix matrix = new ByteMatrix(21, 21);
MatrixUtil.clearMatrix(matrix);
MatrixUtil.embedBasicPatterns(Version.getVersionForNumber(1), matrix);
BitArray bits = new BitArray();
MatrixU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.toString());
}
use of com.google.zxing.common.BitArray in project zxing by zxing.
the class MatrixUtilTestCase method testMakeVersionInfoBits.
// We don't test a lot of cases in this function since we've already
// tested them in TEST(calculateBCHCode).
@Test
public void testMakeVersionInfoBits() throws WriterException {
// From Appendix D in JISX0510:2004 (p 68)
BitArray bits = new BitArray();
MatrixUtil.makeVersionInfoBits(Version.getVersionForNumber(7), bits);
assertEquals(" ...XXXXX ..X..X.X ..", bits.toString());
}
use of com.google.zxing.common.BitArray in project zxing by zxing.
the class EncoderTest method toBitArray.
private static BitArray toBitArray(CharSequence bits) {
BitArray in = new BitArray();
char[] str = DOTX.matcher(bits).replaceAll("").toCharArray();
for (char aStr : str) {
in.appendBit(aStr == 'X');
}
return in;
}
Aggregations