示例#1
0
def test_make_final_message_iso_i2():
    # ISO/IEC 18004:2015(E) - I.2 Encoding a QR Code symbol  -- page 94
    # Input: 01234567
    # Symbol: 1-M
    s = '00010000 00100000 00001100 01010110 01100001 10000000 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001'
    codewords = Buffer(bits(s)).toints()
    expected_s = '00010000 00100000 00001100 01010110 01100001 10000000 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 10100101 00100100 11010100 11000001 11101101 00110110 11000111 10000111 00101100 01010101'
    expected = bits(expected_s)
    assert expected == encoder.make_final_message(1, consts.ERROR_LEVEL_M, codewords).getbits()
示例#2
0
def test_make_final_message_iso_i3():
    # ISO/IEC 18004:2015(E) - I.3 Encoding a Micro QR Code symbol  -- page 96
    # Input: 01234567
    # Symbol: M2-L
    s = '01000000 00011000 10101100 11000011 00000000'
    codewords = Buffer(bits(s)).toints()
    expected_s = '01000000 00011000 10101100 11000011 00000000 10000110 00001101 00100010 10101110 00110000'
    expected = bits(expected_s)
    assert expected == encoder.make_final_message(consts.VERSION_M2, consts.ERROR_LEVEL_L, codewords).getbits()
示例#3
0
def test_make_final_message_iso_i3():
    # ISO/IEC 18004:2015(E) - I.3 Encoding a Micro QR Code symbol  -- page 96
    # Input: 01234567
    # Symbol: M2-L
    s = '01000000 00011000 10101100 11000011 00000000'
    codewords = Buffer(bits(s)).toints()
    expected_s = '01000000 00011000 10101100 11000011 00000000 10000110 00001101 00100010 10101110 00110000'
    expected = bits(expected_s)
    assert expected == encoder.make_final_message(consts.VERSION_M2, consts.ERROR_LEVEL_L, codewords).getbits()
示例#4
0
def test_make_final_message_iso_i2():
    # ISO/IEC 18004:2015(E) - I.2 Encoding a QR Code symbol  -- page 94
    # Input: 01234567
    # Symbol: 1-M
    s = '00010000 00100000 00001100 01010110 01100001 10000000 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001'
    codewords = Buffer(bits(s)).toints()
    expected_s = '00010000 00100000 00001100 01010110 01100001 10000000 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001 10100101 00100100 11010100 11000001 11101101 00110110 11000111 10000111 00101100 01010101'
    expected = bits(expected_s)
    assert expected == encoder.make_final_message(1, consts.ERROR_LEVEL_M, codewords).getbits()
示例#5
0
def test_make_final_message_thonky():
    # <http://www.thonky.com/qr-code-tutorial/structure-final-message>
    # 5-Q
    codewords = [67,85,70,134,87,38,85,194,119,50,6,18,6,103,38,
                 246,246,66,7,118,134,242,7,38,86,22,198,199,146,6,
                 182,230,247,119,50,7,118,134,87,38,82,6,134,151,50,7,
                 70,247,118,86,194,6,151,50,16,236,17,236,17,236,17,236]
    s = '01000011111101101011011001000110010101011111011011100110111101110100011001000010111101110111011010000110000001110111011101010110010101110111011000110010110000100010011010000110000001110000011001010101111100100111011010010111110000100000011110000110001100100111011100100110010101110001000000110010010101100010011011101100000001100001011001010010000100010001001011000110000001101110110000000110110001111000011000010001011001111001001010010111111011000010011000000110001100100001000100000111111011001101010101010111100101001110101111000111110011000111010010011111000010110110000010110001000001010010110100111100110101001010110101110011110010100100110000011000111101111011011010000101100100111111000101111100010010110011101111011111100111011111001000100001111001011100100011101110011010101111100010000110010011000010100010011010000110111100001111111111011101011000000111100110101011001001101011010001101111010101001001101111000100010000101000000010010101101010001101101100100000111010000110100011111100000010000001101111011110001100000010110010001001111000010110001101111011000000000'
    expected = bits(s)
    res = encoder.make_final_message(5, consts.ERROR_LEVEL_Q, codewords)
    assert len(expected) == len(res)
    assert expected == res.getbits()
示例#6
0
def test_make_final_message_thonky():
    # <http://www.thonky.com/qr-code-tutorial/structure-final-message>
    # 5-Q
    codewords = [67,85,70,134,87,38,85,194,119,50,6,18,6,103,38,
                 246,246,66,7,118,134,242,7,38,86,22,198,199,146,6,
                 182,230,247,119,50,7,118,134,87,38,82,6,134,151,50,7,
                 70,247,118,86,194,6,151,50,16,236,17,236,17,236,17,236]
    s = '01000011111101101011011001000110010101011111011011100110111101110100011001000010111101110111011010000110000001110111011101010110010101110111011000110010110000100010011010000110000001110000011001010101111100100111011010010111110000100000011110000110001100100111011100100110010101110001000000110010010101100010011011101100000001100001011001010010000100010001001011000110000001101110110000000110110001111000011000010001011001111001001010010111111011000010011000000110001100100001000100000111111011001101010101010111100101001110101111000111110011000111010010011111000010110110000010110001000001010010110100111100110101001010110101110011110010100100110000011000111101111011011010000101100100111111000101111100010010110011101111011111100111011111001000100001111001011100100011101110011010101111100010000110010011000010100010011010000110111100001111111111011101011000000111100110101011001001101011010001101111010101001001101111000100010000101000000010010101101010001101101100100000111010000110100011111100000010000001101111011110001100000010110010001001111000010110001101111011000000000'
    expected = bits(s)
    res = encoder.make_final_message(5, consts.ERROR_LEVEL_Q, codewords)
    assert len(expected) == len(res)
    assert expected == res.getbits()
示例#7
0
def test_codeword_placement_iso_i3():
    # ISO/IEC 18004:2015(E) - page 96
    # 01234567 as M2-L symbol
    s = '01000000 00011000 10101100 11000011 00000000'
    codewords = Buffer(bits(s)).toints()
    version = consts.VERSION_M2
    buff = encoder.make_final_message(version, consts.ERROR_LEVEL_L, codewords)
    expected_s = '01000000 00011000 10101100 11000011 00000000 10000110 00001101 00100010 10101110 00110000'
    expected = bits(expected_s)
    assert expected == buff.getbits()
    matrix = encoder.make_matrix(version)
    encoder.add_finder_patterns(matrix, is_micro=version < 1)
    encoder.add_codewords(matrix, buff, version=version)
    ref_matrix = read_matrix('iso-i3_code_placement')
    assert ref_matrix == matrix
示例#8
0
def test_codeword_placement_iso_i3():
    # ISO/IEC 18004:2015(E) - page 96
    # 01234567 as M2-L symbol
    s = '01000000 00011000 10101100 11000011 00000000'
    codewords = Buffer(bits(s)).toints()
    version = consts.VERSION_M2
    buff = encoder.make_final_message(version, consts.ERROR_LEVEL_L, codewords)
    expected_s = '01000000 00011000 10101100 11000011 00000000 10000110 00001101 00100010 10101110 00110000'
    expected = bits(expected_s)
    assert expected == buff.getbits()
    matrix = encoder.make_matrix(version)
    encoder.add_finder_patterns(matrix, is_micro=version < 1)
    encoder.add_codewords(matrix, buff, version=version)
    ref_matrix = read_matrix('iso-i3_code_placement')
    assert ref_matrix == matrix
示例#9
0
def test_codeword_placement_iso_i2():
    # ISO/IEC 18004:2015(E) - page 94
    # 01234567 as 1-M symbol
    s = '00010000 00100000 00001100 01010110 01100001 10000000 11101100 00010001 ' \
        '11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001'
    codewords = Buffer(bits(s))
    version = 1
    buff = encoder.make_final_message(version, consts.ERROR_LEVEL_M, codewords)
    expected_s = '00010000 00100000 00001100 01010110 01100001 10000000 11101100 ' \
                 '00010001 11101100 00010001 11101100 00010001 11101100 00010001 ' \
                 '11101100 00010001 10100101 00100100 11010100 11000001 11101101 ' \
                 '00110110 11000111 10000111 00101100 01010101'
    expected = bits(expected_s)
    assert expected == buff.getbits()
    matrix = encoder.make_matrix(version)
    encoder.add_finder_patterns(matrix, is_micro=version < 1)
    encoder.add_codewords(matrix, buff, version=version)
    ref_matrix = read_matrix('iso-i2_code_placement')
    assert ref_matrix == matrix