Beispiel #1
0
def test_byte():
    oa = OutputArchive()
    for b in range(256):
        oa.write_byte(b, 'tag_' + str(b))
    ia = InputArchive(str(oa.buffer))
    for b in range(256):
        r = ia.read_byte('tag_' + str(b))
        assert b == r
Beispiel #2
0
def test_int():
    oa = OutputArchive()
    for b in range(256):
        oa.write_int(b, 'tag_' + str(b))
    ia = InputArchive(str(oa.buffer))
    for b in range(256):
        r = ia.read_int('tag_' + str(b))
        assert type(r) == int
        assert b == r
Beispiel #3
0
def test_bool():
    oa = OutputArchive()
    oa.write_bool(True, 'tag')
    ia = InputArchive(str(oa.buffer))
    assert ia.read_bool('tag')

    oa = OutputArchive()
    oa.write_bool(False, 'tag')
    ia = InputArchive(str(oa.buffer))
    assert not ia.read_bool('tag')
Beispiel #4
0
def test_long():
    oa = OutputArchive()
    oa.write_long(9141385893744296737, 'tag')
    ia = InputArchive(str(oa.buffer))
    r = ia.read_long('tag')
    assert type(r) == long
    assert 9141385893744296737 == r

    oa = OutputArchive()
    oa.write_long(1, 'tag')
    ia = InputArchive(str(oa.buffer))
    r = ia.read_long('tag')
    assert type(r) == long
    assert 1 == r
Beispiel #5
0
def test_vector():
    oa = OutputArchive()
    v = [1, 2, 3, 4, 5]
    oa.start_vector(v, 'tag')
    for i in range(len(v)):
        oa.write_int(v[i], 'tag_' + str(i))
    oa.end_vector(v, 'tag')

    ia = InputArchive(str(oa.buffer))
    l = ia.start_vector('tag')
    vv = []
    for i in range(l):
        vv.append(ia.read_int('tag_' + str(i)))
    ia.end_vector('tag')
    assert v == vv