Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
asn1-value-editor
Commits
def89c60
Commit
def89c60
authored
Aug 04, 2016
by
Maxime Perrotin
Browse files
Add tons of tests and fix bug found by tests
parent
009190c5
Changes
3
Show whitespace changes
Inline
Side-by-side
asn1_value_editor/ValueGenerator.py
View file @
def89c60
...
@@ -112,7 +112,7 @@ def compute_combinations(asn1_ty, pool):
...
@@ -112,7 +112,7 @@ def compute_combinations(asn1_ty, pool):
elif
basic
.
kind
.
endswith
(
'StringType'
):
elif
basic
.
kind
.
endswith
(
'StringType'
):
# Strings
# Strings
for
n
in
xrange
(
int
(
basic
.
Min
),
int
(
basic
.
Max
)
+
1
):
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
):
def
compute_integer_combinations
(
asn1_ty
,
max_iter
=
0
):
...
...
test/pytest/data/dv1.asn
View file @
def89c60
...
@@ -27,6 +27,8 @@ Type-SimpleSeq ::= SEQUENCE {
...
@@ -27,6 +27,8 @@ Type-SimpleSeq ::= SEQUENCE {
}
}
Type-SingleSeqOf ::= SEQUENCE (SIZE (0..5)) OF INTEGER (0..255)
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 {
Type-Seq ::= SEQUENCE {
item-a Type-SingleReal,
item-a Type-SingleReal,
...
...
test/pytest/test_valuegenerator.py
View file @
def89c60
...
@@ -24,7 +24,7 @@ dataview = asn1scc.parse_asn1(TEST,
...
@@ -24,7 +24,7 @@ dataview = asn1scc.parse_asn1(TEST,
pool
=
dataview
.
types
pool
=
dataview
.
types
def
test_random_bool
(
qtbot
):
def
test_random_bool
():
''' Test boolean values '''
''' Test boolean values '''
typeName
=
"Type-SingleBool"
typeName
=
"Type-SingleBool"
results
=
[]
results
=
[]
...
@@ -34,22 +34,40 @@ def test_random_bool(qtbot):
...
@@ -34,22 +34,40 @@ def test_random_bool(qtbot):
results
.
append
(
result
)
results
.
append
(
result
)
assert
'TRUE'
in
results
and
'FALSE'
in
results
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 '''
''' Test integer value '''
typeName
=
"Type-SingleInt"
typeName
=
"Type-SingleInt"
for
i
in
range
(
1000
):
for
i
in
range
(
1000
):
result
=
compute_random_value
(
pool
[
typeName
],
pool
)
result
=
compute_random_value
(
pool
[
typeName
],
pool
)
assert
0
<=
int
(
result
)
<=
255
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 '''
''' Test float value '''
typeName
=
"Type-SingleReal"
typeName
=
"Type-SingleReal"
for
i
in
range
(
1000
):
for
i
in
range
(
1000
):
result
=
compute_random_value
(
pool
[
typeName
],
pool
)
result
=
compute_random_value
(
pool
[
typeName
],
pool
)
assert
-
5.0
<=
float
(
result
)
<=
5.0
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 '''
''' Test enumerated value '''
typeName
=
"Type-SingleEnum"
typeName
=
"Type-SingleEnum"
results
=
[]
results
=
[]
...
@@ -59,14 +77,30 @@ def test_random_enum(qtbot):
...
@@ -59,14 +77,30 @@ def test_random_enum(qtbot):
results
.
append
(
result
)
results
.
append
(
result
)
assert
'enum-one'
in
results
and
'enum-two'
in
results
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 '''
''' Test octet string value '''
typeName
=
"Type-SingleString"
typeName
=
"Type-SingleString"
for
i
in
range
(
1000
):
for
i
in
range
(
1000
):
result
=
compute_random_value
(
pool
[
typeName
],
pool
)
result
=
compute_random_value
(
pool
[
typeName
],
pool
)
assert
re
.
sub
(
'[X
\"
]'
,
''
,
result
)
==
''
and
2
<=
len
(
result
)
<=
22
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 '''
''' Test SEQUENCE '''
typeName
=
"Type-SimpleSeq"
typeName
=
"Type-SimpleSeq"
for
i
in
range
(
1000
):
for
i
in
range
(
1000
):
...
@@ -75,7 +109,7 @@ def test_random_simpleseq(qtbot):
...
@@ -75,7 +109,7 @@ def test_random_simpleseq(qtbot):
'item-a'
in
result
and
'item-b'
in
result
and
'item-C'
\
'item-a'
in
result
and
'item-b'
in
result
and
'item-C'
\
in
result
and
'item-d'
in
result
in
result
and
'item-d'
in
result
def
test_random_simplechoice
(
qtbot
):
def
test_random_simplechoice
():
''' Test CHOICE. '''
''' Test CHOICE. '''
typeName
=
"Type-SingleChoice"
typeName
=
"Type-SingleChoice"
for
i
in
range
(
100
):
for
i
in
range
(
100
):
...
@@ -90,7 +124,24 @@ def test_random_simplechoice(qtbot):
...
@@ -90,7 +124,24 @@ def test_random_simplechoice(qtbot):
else
:
else
:
assert
False
,
'No valid choice in result'
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 '''
''' Test SEQOF '''
typeName
=
"Type-SingleSeqOf"
typeName
=
"Type-SingleSeqOf"
for
i
in
range
(
100
):
for
i
in
range
(
100
):
...
@@ -100,8 +151,18 @@ def test_random_simpleseqof(qtbot):
...
@@ -100,8 +151,18 @@ def test_random_simpleseqof(qtbot):
for
each
in
value
:
for
each
in
value
:
assert
type
(
each
)
is
int
and
0
<=
each
<=
255
assert
type
(
each
)
is
int
and
0
<=
each
<=
255
def
test_exhaustive_tinyseqof
():
def
test_random_mydata
(
qtbot
):
''' 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 '''
''' Test more complex sequence '''
typeName
=
"MyData"
typeName
=
"MyData"
for
i
in
range
(
10
):
for
i
in
range
(
10
):
...
@@ -115,7 +176,7 @@ def test_random_mydata(qtbot):
...
@@ -115,7 +176,7 @@ def test_random_mydata(qtbot):
assert
type
(
each
)
is
int
and
0
<=
each
<=
255
assert
type
(
each
)
is
int
and
0
<=
each
<=
255
assert
item
[
'b'
][
'Enum'
]
in
(
'enum-one'
,
'enum-two'
)
assert
item
[
'b'
][
'Enum'
]
in
(
'enum-one'
,
'enum-two'
)
def
test_random_seq2
(
qtbot
):
def
test_random_seq2
():
''' Test more complex sequence '''
''' Test more complex sequence '''
typeName
=
"Type-Seq"
typeName
=
"Type-Seq"
for
i
in
range
(
10
):
for
i
in
range
(
10
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment