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
fed14ef6
Commit
fed14ef6
authored
Jul 17, 2016
by
Maxime Perrotin
Browse files
Complexify test of ROOT choice
parent
a2e39cf5
Changes
3
Hide whitespace changes
Inline
Side-by-side
asn1_value_editor/asn1_value_editor.py
View file @
fed14ef6
...
...
@@ -310,10 +310,11 @@ class asn1Editor(QTreeView):
rowIndex
=
root
.
child
(
i
).
index
()
self
.
choiceDisplay
(
rowIndex
,
len
(
choices
),
j
)
def
parseModel
(
self
,
root
,
nbRows
=-
1
,
dest
=
None
):
def
parseModel
(
self
,
root
,
nbRows
=-
1
,
dest
=
None
,
choice
=-
1
):
''' Parse the model to get all field values recursively
root type is QStandardItem
dest is a ctypes instance of the type to fill
choice >= 0 to specify a specific row to parse for a CHOICE
'''
if
dest
is
None
:
self
.
log
.
error
(
'parseModel: destination ASN.1 variable not set'
)
...
...
@@ -323,7 +324,7 @@ class asn1Editor(QTreeView):
if
not
seqOf
:
nbRows
=
root
.
rowCount
()
def
parseRow
(
root
,
i
,
dest
,
choice
=
False
,
seqOf
=
False
):
def
parseRow
(
root
,
i
,
dest
,
seqOf
=
False
):
name
=
root
.
child
(
i
,
0
).
text
().
replace
(
'-'
,
'_'
)
asnType
=
root
.
child
(
i
,
1
).
text
()
value
=
root
.
child
(
i
,
3
).
text
()
...
...
@@ -349,7 +350,7 @@ class asn1Editor(QTreeView):
break
else
:
raise
TypeError
(
'CHOICE row not found'
)
parseRow
(
chrow
,
rownb
,
dest
=
ptr
,
choice
=
True
)
parseRow
(
chrow
,
rownb
,
dest
=
ptr
)
ptr
.
Reset
(
state
)
intMappings
=
root
.
child
(
i
,
3
).
data
(
INTMAP
)
for
enumerant
,
num
in
intMappings
.
viewitems
():
...
...
@@ -359,10 +360,12 @@ class asn1Editor(QTreeView):
else
:
raise
TypeError
(
'CHOICE determinant not found'
)
elif
asnType
==
'INTEGER'
:
print
'SET INTEGER'
ptr
.
Set
(
int
(
value
))
elif
asnType
==
'REAL'
:
ptr
.
Set
(
float
(
value
))
elif
asnType
==
'BOOLEAN'
:
print
'SET BOOLEAN'
boolValue
=
value
==
'True'
ptr
.
Set
(
boolValue
)
elif
asnType
==
'ENUMERATED'
:
...
...
@@ -375,10 +378,17 @@ class asn1Editor(QTreeView):
raise
TypeError
(
'ENUMERATED value not found'
)
else
:
# Strings
ptr
.
SetFromPyString
(
value
)
for
i
in
xrange
(
nbRows
):
# for each child row
if
choice
!=
-
1
:
# Read only the row of the choice selection
stateBefore
=
dest
.
GetState
()
parseRow
(
root
,
i
,
dest
,
seqOf
=
seqOf
)
parseRow
(
root
,
choice
,
dest
,
seqOf
=
False
)
dest
.
Reset
(
stateBefore
)
else
:
for
i
in
xrange
(
nbRows
):
# for each child row
stateBefore
=
dest
.
GetState
()
parseRow
(
root
,
i
,
dest
,
seqOf
=
seqOf
)
dest
.
Reset
(
stateBefore
)
else
:
# single elements (all but SeqOf, Choice, Sequence)
row
=
root
.
row
()
try
:
...
...
@@ -428,7 +438,15 @@ class asn1Editor(QTreeView):
dest
.
SetLength
(
nbRows
)
elif
asnType
==
'CHOICE'
:
value
=
self
.
model
.
item
(
row
,
3
).
text
()
self
.
parseModel
(
root
,
dest
=
dest
)
# We must parse only one row, containing the choice (value)
for
rownb
in
xrange
(
root
.
rowCount
()):
curr
=
root
.
child
(
rownb
,
0
).
text
()
if
curr
==
value
:
break
else
:
raise
TypeError
(
'CHOICE ROW not found'
)
print
'coucou'
,
value
,
rownb
self
.
parseModel
(
root
,
dest
=
dest
,
choice
=
rownb
)
intMappings
=
self
.
model
.
item
(
row
,
3
).
data
(
INTMAP
)
for
enumerant
,
num
in
intMappings
.
viewitems
():
if
enumerant
==
value
:
...
...
test/pytest/data/dv1.asn
View file @
fed14ef6
...
...
@@ -15,7 +15,8 @@ Type-SingleString ::= OCTET STRING (SIZE(0..20))
Type-SingleChoice ::= CHOICE {
choice-A Type-SingleInt,
choice-B Type-SingleBool
choice-B Type-SingleBool,
choice-C ENUMERATED {enum-ONE, enum-TWO, enum-THREE}
}
Type-SimpleSeq ::= SEQUENCE {
...
...
test/pytest/test_standalone.py
View file @
fed14ef6
...
...
@@ -75,7 +75,7 @@ def test_simpleseq(qtbot):
assert
format_gser
(
result
)
==
format_gser
(
defValue
)
def
test_simplechoice
(
qtbot
):
''' Test CHOICE '''
''' Test CHOICE
.
'''
typeName
=
"Type-SingleChoice"
defValue
=
'choice-B: TRUE'
result
=
common
(
typeName
,
defValue
)
...
...
@@ -83,6 +83,9 @@ def test_simplechoice(qtbot):
defValue
=
'choice-A: 99'
result
=
common
(
typeName
,
defValue
)
assert
format_gser
(
result
)
==
format_gser
(
defValue
)
defValue
=
'choice-C: enum-THREE'
result
=
common
(
typeName
,
defValue
)
assert
format_gser
(
result
)
==
format_gser
(
defValue
)
def
test_simpleseqof
(
qtbot
):
''' Test SEQOF '''
...
...
Write
Preview
Markdown
is supported
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