def test_write_padding_bits_iso_i2(): # See ISO/IEC 18004:2006(E) -- I.2 Encoding a QR Code symbol (page 94) data = bits('0001 0000001000 0000001100 0101011001 1000011 0000') buff = Buffer(data) version = 1 encoder.write_padding_bits(buff, version, len(buff)) assert bits('00010000 00100000 00001100 01010110 01100001 10000000') == buff.getbits()
def test_write_padding_bits_iso_i3(): # See ISO/IEC 18004:2006(E) -- I.3 Encoding a Micro QR Code symbol (page 96) data = bits('0 1000 0000001100 0101011001 1000011 00000') buff = Buffer(data) version = consts.VERSION_M2 encoder.write_padding_bits(buff, version, len(buff)) assert bits('01000000 00011000 10101100 11000011 00000000') == buff.getbits()
def test_write_segment_alphanumeric_standard_value_example(eci): # See ISO/IEC 18004:2006(E) -- 6.4.3 Numeric mode - EXAMPLE (page 26) s = b'AC-42' seg = encoder.make_segment(s, consts.MODE_ALPHANUMERIC) buff = Buffer() v, vrange = None, consts.VERSION_RANGE_01_09 encoder.write_segment(buff, seg, v, vrange, eci=eci) assert bits('00100000001010011100111011100111001000010') == buff.getbits()
def test_write_segment_numeric_standard_value_i3(eci): # See ISO/IEC 18004:2006(E) -- I.3 Encoding a Micro QR Code symbol (page 96) s = b'01234567' seg = encoder.make_segment(s, consts.MODE_NUMERIC) buff = Buffer() v, vrange = consts.VERSION_M2, consts.VERSION_M2 encoder.write_segment(buff, seg, v, vrange, eci=eci) assert bits('01000000000110001010110011000011') == buff.getbits()
def test_write_segment_numeric_standard_value_example2(eci): # See ISO/IEC 18004:2006(E) -- 6.4.3 Numeric mode - EXAMPLE 2 (page 25) s = b'0123456789012345' seg = encoder.make_segment(s, consts.MODE_NUMERIC) buff = Buffer() v, vrange = consts.VERSION_M3, consts.VERSION_M3 encoder.write_segment(buff, seg, v, vrange, eci=eci) assert bits('0010000000000110001010110011010100110111000010100111010100101') == buff.getbits()
def test_write_terminator_standard_value_i3(): # See ISO/IEC 18004:2006(E) -- I.3 Encoding a Micro QR Code symbol (page 96) data = bits('01000000000110001010110011000011') buff = Buffer(data) version = consts.VERSION_M2 capacity = consts.SYMBOL_CAPACITY[version][consts.ERROR_LEVEL_L] encoder.write_terminator(buff, capacity, version, len(data)) assert data + bits('00000') == buff.getbits()
def test_write_pad_codewords_standard_value_i3(): # See ISO/IEC 18004:2006(E) -- I.3 Encoding a Micro QR Code symbol (page 96) data = bits('0100000000011000101011001100001100000000') buff = Buffer(data) version = consts.VERSION_M2 error = consts.ERROR_LEVEL_L capacity = consts.SYMBOL_CAPACITY[version][error] encoder.write_pad_codewords(buff, version, capacity, len(buff)) assert data == buff.getbits()
def test_write_terminator_standard_value_i2(): # See ISO/IEC 18004:2006(E) -- I.2 Encoding a QR Code symbol (page 94) data = bits('000100000010000000001100010101100110000110000') buff = Buffer(data) version = 1 v = None capacity = consts.SYMBOL_CAPACITY[version][consts.ERROR_LEVEL_M] encoder.write_terminator(buff, capacity, v, len(data)) assert data + bits('0000') == buff.getbits()
def test_write_terminator_thonky(): # <http://www.thonky.com/qr-code-tutorial/data-encoding/#add-a-terminator-of-0s-if-necessary> data = bits('00100000010110110000101101111000110100010111001011011100010011010100001101') buff = Buffer(data) version = 1 v = None capacity = consts.SYMBOL_CAPACITY[version][consts.ERROR_LEVEL_Q] encoder.write_terminator(buff, capacity, v, len(data)) assert data + bits('0000') == buff.getbits()
def test_write_padding_bits_thonky(): # <http://www.thonky.com/qr-code-tutorial/data-encoding> data = bits('00100000 01011011 00001011 01111000 11010001 01110010 11011100 ' '01001101 01000011 010000') buff = Buffer(data) version = 1 encoder.write_padding_bits(buff, version, len(buff)) assert bits('00100000 01011011 00001011 01111000 11010001 01110010 11011100 ' '01001101 01000011 01000000') == buff.getbits()
def test_write_pad_codewords_standard_value_i2(): # See ISO/IEC 18004:2006(E) -- I.2 Encoding a QR Code symbol (page 94) data = bits('00010000 00100000 00001100 01010110 01100001 10000000') buff = Buffer(data) version = 1 error = consts.ERROR_LEVEL_M capacity = consts.SYMBOL_CAPACITY[version][error] encoder.write_pad_codewords(buff, version, capacity, len(buff)) assert data + bits('1110110000010001111011000001000111101100000100011110110' '0000100011110110000010001') == buff.getbits()
def test_write_segment_alphanumeric_thonky(eci): # <http://www.thonky.com/qr-code-tutorial/data-encoding/#step-3-encode-using-the-selected-mode> s = b'HELLO WORLD' seg = encoder.make_segment(s, consts.MODE_ALPHANUMERIC, None) buff = Buffer() v, vrange = None, consts.VERSION_RANGE_01_09 encoder.write_segment(buff, seg, v, vrange, eci) assert bits( '00100000010110110000101101111000110100010111001011011100010011010100001101' ) == buff.getbits()
def test_write_segment_eci_standard_value(): # See ISO/IEC 18004:2006(E) -- 6.4.2.1 ECI Designator - EXAMPLE (page 24) encoding = 'ISO-8859-7' #TODO: ? # NOTE: ISO/IEC 18004:2006(E) uses "ΑΒΓΔΕ" but text says: # (character values A1HEX, A2HEX, A3HEX, A4HEX, A5HEX) and result seems # to use the A...HEX values as well s = '\u2018\u2019\u00A3\u20AC\u20AF'.encode(encoding) seg = encoder.make_segment(s, consts.MODE_BYTE, encoding) buff = Buffer() v, vrange = None, consts.VERSION_RANGE_01_09 encoder.write_segment(buff, seg, v, vrange, True) expected = bits('0111 00001001 0100 00000101 10100001 10100010 10100011 10100100 10100101') result = buff.getbits() assert len(expected) == len(result) assert expected == result
def test_write_segment_bytes_thonky(eci): # <http://www.thonky.com/qr-code-tutorial/byte-mode-encoding/> s = b'Hello, world!' seg = encoder.make_segment(s, consts.MODE_BYTE, consts.DEFAULT_BYTE_ENCODING) buff = Buffer() v, vrange = None, consts.VERSION_RANGE_01_09 encoder.write_segment(buff, seg, v, vrange, eci=eci) assert bits('010000001101' '01001000' '01100101' '01101100' '01101100' '01101111' '00101100' '00100000' '01110111' '01101111' '01110010' '01101100' '01100100' '00100001') == buff.getbits()
def test_write_padding_bits_thonky(): # <http://www.thonky.com/qr-code-tutorial/data-encoding> data = bits('00100000 01011011 00001011 01111000 11010001 01110010 11011100 01001101 01000011 010000') buff = Buffer(data) version = 1 encoder.write_padding_bits(buff, version, len(buff)) assert bits('00100000 01011011 00001011 01111000 11010001 01110010 11011100 01001101 01000011 01000000') == buff.getbits()
def test_write_segment_alphanumeric_thonky(eci): # <http://www.thonky.com/qr-code-tutorial/data-encoding/#step-3-encode-using-the-selected-mode> s = b'HELLO WORLD' seg = encoder.make_segment(s, consts.MODE_ALPHANUMERIC, None) buff = Buffer() v, vrange = None, consts.VERSION_RANGE_01_09 encoder.write_segment(buff, seg, v, vrange, eci) assert bits('00100000010110110000101101111000110100010111001011011100010011010100001101') == buff.getbits()
def test_write_pad_codewords_standard_value_i2(): # See ISO/IEC 18004:2006(E) -- I.2 Encoding a QR Code symbol (page 94) data = bits('00010000 00100000 00001100 01010110 01100001 10000000') buff = Buffer(data) version = 1 error = consts.ERROR_LEVEL_M capacity = consts.SYMBOL_CAPACITY[version][error] encoder.write_pad_codewords(buff, version, capacity, len(buff)) assert data + bits('11101100000100011110110000010001111011000001000111101100000100011110110000010001') == buff.getbits()