Commit def89c60 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Add tons of tests and fix bug found by tests

parent 009190c5
......@@ -112,7 +112,7 @@ def compute_combinations(asn1_ty, pool):
elif basic.kind.endswith('StringType'):
# Strings
for n in xrange(int(basic.Min), int(basic.Max) + 1):
yield '"' + 'X' * X + '"'
yield '"' + 'X' * n + '"'
def compute_integer_combinations(asn1_ty, max_iter=0):
......
......@@ -27,6 +27,8 @@ Type-SimpleSeq ::= SEQUENCE {
}
Type-SingleSeqOf ::= SEQUENCE (SIZE (0..5)) OF INTEGER (0..255)
Type-TinySeqOf ::= SEQUENCE (SIZE (2)) OF BOOLEAN
Type-TinySeqOf2::= SEQUENCE (SIZE (0..2)) OF INTEGER (0..5)
Type-Seq ::= SEQUENCE {
item-a Type-SingleReal,
......
......@@ -24,7 +24,7 @@ dataview = asn1scc.parse_asn1(TEST,
pool = dataview.types
def test_random_bool(qtbot):
def test_random_bool():
''' Test boolean values '''
typeName = "Type-SingleBool"
results = []
......@@ -34,22 +34,40 @@ def test_random_bool(qtbot):
results.append(result)
assert 'TRUE' in results and 'FALSE' in results
def test_random_int(qtbot):
def test_exhaustive_bool():
''' Test boolean values '''
typeName = "Type-SingleBool"
result = list(compute_combinations(pool[typeName], pool))
assert result == ['TRUE', 'FALSE']
def test_random_int():
''' Test integer value '''
typeName = "Type-SingleInt"
for i in range(1000):
result = compute_random_value(pool[typeName], pool)
assert 0 <= int(result) <= 255
def test_exhaustive_int():
''' Test integer value '''
typeName = "Type-SingleInt"
result = list(compute_combinations(pool[typeName], pool))
assert result == [str(i) for i in range(256)]
def test_random_real(qtbot):
def test_random_real():
''' Test float value '''
typeName = "Type-SingleReal"
for i in range(1000):
result = compute_random_value(pool[typeName], pool)
assert -5.0 <= float(result) <= 5.0
def test_random_enum(qtbot):
def test_exhaustive_real():
''' Test float value '''
typeName = "Type-SingleReal"
result = list(compute_combinations(pool[typeName], pool))
asFloat = [float(i) for i in result]
assert asFloat == [-5.0, 0.0, 5.0]
def test_random_enum():
''' Test enumerated value '''
typeName = "Type-SingleEnum"
results = []
......@@ -59,14 +77,30 @@ def test_random_enum(qtbot):
results.append(result)
assert 'enum-one' in results and 'enum-two' in results
def test_random_string(qtbot):
def test_exhaustive_enum():
''' Test enumerated value '''
typeName = "Type-SingleEnum"
result = list(compute_combinations(pool[typeName], pool))
assert result == ['enum-one', 'enum-two']
def test_random_string():
''' Test octet string value '''
typeName = "Type-SingleString"
for i in range(1000):
result = compute_random_value(pool[typeName], pool)
assert re.sub('[X\"]', '', result) == '' and 2 <= len(result) <= 22
def test_random_simpleseq(qtbot):
def test_exhaustive_string():
''' Test octet string value '''
typeName = "Type-SingleString"
result = list(compute_combinations(pool[typeName], pool))
expected_len = [i+2 for i in range(21)]
assert result[0] == '""'
assert result[1] == '"X"'
for idx, each in enumerate(result):
assert len(each) == expected_len[idx]
def test_random_simpleseq():
''' Test SEQUENCE '''
typeName = "Type-SimpleSeq"
for i in range(1000):
......@@ -75,7 +109,7 @@ def test_random_simpleseq(qtbot):
'item-a' in result and 'item-b' in result and 'item-C' \
in result and 'item-d' in result
def test_random_simplechoice(qtbot):
def test_random_simplechoice():
''' Test CHOICE. '''
typeName = "Type-SingleChoice"
for i in range(100):
......@@ -90,7 +124,24 @@ def test_random_simplechoice(qtbot):
else:
assert False, 'No valid choice in result'
def test_random_simpleseqof(qtbot):
def test_exhaustive_simplechoice():
''' Test simple choice (only made of basic types, not sequences '''
typeName = "Type-SingleChoice"
result = compute_combinations(pool[typeName], pool)
choiceA = choiceB = choiceC = 0
expected = {'choice-A': range(256),
'choice-B': [True, False],
'choice-C': [{'Enum': 'enum-ONE'},
{'Enum': 'enum-TWO'},
{'Enum': 'enum-THREE'}]}
for each in result:
value = parse_gser('result', each)['result']
choiceDet = value['Choice']
assert value[choiceDet] in expected[choiceDet]
expected[choiceDet].remove(value[choiceDet])
assert not any(value for value in expected.viewvalues())
def test_random_simpleseqof():
''' Test SEQOF '''
typeName = "Type-SingleSeqOf"
for i in range(100):
......@@ -100,8 +151,18 @@ def test_random_simpleseqof(qtbot):
for each in value:
assert type(each) is int and 0 <= each <= 255
def test_random_mydata(qtbot):
def test_exhaustive_tinyseqof():
''' Test SEQOF '''
typeName = "Type-TinySeqOf" # Size-2 seq of boolean -> 00 01 10 11
result = compute_combinations(pool[typeName], pool)
expected = [[False, False], [False, True], [True, False], [True, True]]
for each in result:
value = parse_gser('result', each)['result']
assert value in expected
expected.remove(value)
assert not expected
def test_random_mydata():
''' Test more complex sequence '''
typeName = "MyData"
for i in range(10):
......@@ -115,7 +176,7 @@ def test_random_mydata(qtbot):
assert type(each) is int and 0 <= each <= 255
assert item['b']['Enum'] in ('enum-one', 'enum-two')
def test_random_seq2(qtbot):
def test_random_seq2():
''' Test more complex sequence '''
typeName = "Type-Seq"
for i in range(10):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment