public void testAppendKanjiBytes() { BitArray bits = new BitArray(); Encoder.appendKanjiBytes(shiftJISString(new byte[] { (byte)0x93, 0x5f }), bits); Assert.AreEqual(" .XX.XX.. XXXXX", bits.ToString()); Encoder.appendKanjiBytes(shiftJISString(new byte[] { (byte)0xe4, (byte)0xaa }), bits); Assert.AreEqual(" .XX.XX.. XXXXXXX. X.X.X.X. X.", bits.ToString()); }
public void testAppendAlphanumericBytes() { // A = 10 = 0xa = 001010 in 6 bits var bits = new BitArray(); Encoder.appendAlphanumericBytes("A", bits); Assert.AreEqual(" ..X.X.", bits.ToString()); // AB = 10 * 45 + 11 = 461 = 0x1cd = 00111001101 in 11 bits bits = new BitArray(); Encoder.appendAlphanumericBytes("AB", bits); Assert.AreEqual(" ..XXX..X X.X", bits.ToString()); // ABC = "AB" + "C" = 00111001101 + 001100 bits = new BitArray(); Encoder.appendAlphanumericBytes("ABC", bits); Assert.AreEqual(" ..XXX..X X.X..XX. .", bits.ToString()); // Empty. bits = new BitArray(); Encoder.appendAlphanumericBytes("", bits); Assert.AreEqual("", bits.ToString()); // Invalid data. try { Encoder.appendAlphanumericBytes("abc", new BitArray()); } catch (WriterException) { // good } }
public void testAppend8BitBytes() { // 0x61, 0x62, 0x63 var bits = new BitArray(); Encoder.append8BitBytes("abc", bits, Encoder.DEFAULT_BYTE_MODE_ENCODING); Assert.AreEqual(" .XX....X .XX...X. .XX...XX", bits.ToString()); // Empty. bits = new BitArray(); Encoder.append8BitBytes("", bits, Encoder.DEFAULT_BYTE_MODE_ENCODING); Assert.AreEqual("", bits.ToString()); }
public void testTerminateBits() { var v = new BitArray(); Encoder.terminateBits(0, v); Assert.AreEqual("", v.ToString()); v = new BitArray(); Encoder.terminateBits(1, v); Assert.AreEqual(" ........", v.ToString()); v = new BitArray(); v.appendBits(0, 3); // Append 000 Encoder.terminateBits(1, v); Assert.AreEqual(" ........", v.ToString()); v = new BitArray(); v.appendBits(0, 5); // Append 00000 Encoder.terminateBits(1, v); Assert.AreEqual(" ........", v.ToString()); v = new BitArray(); v.appendBits(0, 8); // Append 00000000 Encoder.terminateBits(1, v); Assert.AreEqual(" ........", v.ToString()); v = new BitArray(); Encoder.terminateBits(2, v); Assert.AreEqual(" ........ XXX.XX..", v.ToString()); v = new BitArray(); v.appendBits(0, 1); // Append 0 Encoder.terminateBits(3, v); Assert.AreEqual(" ........ XXX.XX.. ...X...X", v.ToString()); }
public void testAppendNumericBytes() { // 1 = 01 = 0001 in 4 bits. var bits = new BitArray(); Encoder.appendNumericBytes("1", bits); Assert.AreEqual(" ...X", bits.ToString()); // 12 = 0xc = 0001100 in 7 bits. bits = new BitArray(); Encoder.appendNumericBytes("12", bits); Assert.AreEqual(" ...XX..", bits.ToString()); // 123 = 0x7b = 0001111011 in 10 bits. bits = new BitArray(); Encoder.appendNumericBytes("123", bits); Assert.AreEqual(" ...XXXX. XX", bits.ToString()); // 1234 = "123" + "4" = 0001111011 + 0100 bits = new BitArray(); Encoder.appendNumericBytes("1234", bits); Assert.AreEqual(" ...XXXX. XX.X..", bits.ToString()); // Empty. bits = new BitArray(); Encoder.appendNumericBytes("", bits); Assert.AreEqual("", bits.ToString()); }
public void testAppendLengthInfo() { var bits = new BitArray(); Encoder.appendLengthInfo(1, // 1 letter (1/1). Version.getVersionForNumber(1), Mode.NUMERIC, bits); Assert.AreEqual(" ........ .X", bits.ToString()); // 10 bits. bits = new BitArray(); Encoder.appendLengthInfo(2, // 2 letters (2/1). Version.getVersionForNumber(10), Mode.ALPHANUMERIC, bits); Assert.AreEqual(" ........ .X.", bits.ToString()); // 11 bits. bits = new BitArray(); Encoder.appendLengthInfo(255, // 255 letter (255/1). Version.getVersionForNumber(27), Mode.BYTE, bits); Assert.AreEqual(" ........ XXXXXXXX", bits.ToString()); // 16 bits. bits = new BitArray(); Encoder.appendLengthInfo(512, // 512 letters (1024/2). Version.getVersionForNumber(40), Mode.KANJI, bits); Assert.AreEqual(" ..X..... ....", bits.ToString()); // 12 bits. }
public void testAppendBytes() { // Should use appendNumericBytes. // 1 = 01 = 0001 in 4 bits. var bits = new BitArray(); Encoder.appendBytes("1", Mode.NUMERIC, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING); Assert.AreEqual(" ...X", bits.ToString()); // Should use appendAlphanumericBytes. // A = 10 = 0xa = 001010 in 6 bits bits = new BitArray(); Encoder.appendBytes("A", Mode.ALPHANUMERIC, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING); Assert.AreEqual(" ..X.X.", bits.ToString()); // Lower letters such as 'a' cannot be encoded in MODE_ALPHANUMERIC. try { Encoder.appendBytes("a", Mode.ALPHANUMERIC, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING); } catch (WriterException) { // good } // Should use append8BitBytes. // 0x61, 0x62, 0x63 bits = new BitArray(); Encoder.appendBytes("abc", Mode.BYTE, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING); Assert.AreEqual(" .XX....X .XX...X. .XX...XX", bits.ToString()); // Anything can be encoded in QRCode.MODE_8BIT_BYTE. Encoder.appendBytes("\0", Mode.BYTE, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING); // Should use appendKanjiBytes. // 0x93, 0x5f bits = new BitArray(); Encoder.appendBytes(shiftJISString(new byte[] {0x93, 0x5f}), Mode.KANJI, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING); Assert.AreEqual(" .XX.XX.. XXXXX", bits.ToString()); }
public void testAppendModeInfo() { BitArray bits = new BitArray(); Encoder.appendModeInfo(Mode.NUMERIC, bits); Assert.AreEqual(" ...X", bits.ToString()); }
public void testMakeTypeInfoInfoBits() { // From Appendix C in JISX0510:2004 (p 65) BitArray bits = new BitArray(); MatrixUtil.makeTypeInfoBits(ErrorCorrectionLevel.M, 5, bits); Assert.AreEqual(" X......X X..XXX.", bits.ToString()); }
public void testMakeVersionInfoBits() { // From Appendix D in JISX0510:2004 (p 68) BitArray bits = new BitArray(); MatrixUtil.makeVersionInfoBits(Version.getVersionForNumber(7), bits); Assert.AreEqual(" ...XXXXX ..X..X.X ..", bits.ToString()); }
public void testToString() { BitArray v = new BitArray(); v.appendBits(0xdead, 16); // 1101 1110 1010 1101 Assert.AreEqual(" XX.XXXX. X.X.XX.X", v.ToString()); }
public void testAppendBitVector() { BitArray v1 = new BitArray(); v1.appendBits(0xbe, 8); BitArray v2 = new BitArray(); v2.appendBits(0xef, 8); v1.appendBitArray(v2); // beef = 1011 1110 1110 1111 Assert.AreEqual(" X.XXXXX. XXX.XXXX", v1.ToString()); }