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
2cc2dc0c
Commit
2cc2dc0c
authored
Jul 16, 2016
by
Maxime Perrotin
Browse files
Test and fix bugs
parent
07c44894
Changes
3
Show whitespace changes
Inline
Side-by-side
asn1_value_editor/asn1_value_editor.py
View file @
2cc2dc0c
...
...
@@ -428,14 +428,19 @@ class asn1Editor(QTreeView):
name
=
root
.
text
()
asnType
=
self
.
model
.
item
(
row
,
1
).
text
()
if
asnType
==
'SEQOF'
:
# Missing a SetLength
nbRows
=
int
(
self
.
model
.
item
(
row
,
3
).
text
())
self
.
parseModel
(
root
,
nbRows
=
nbRows
,
dest
=
dest
)
dest
.
SetLength
(
nbRows
)
elif
asnType
==
'CHOICE'
:
value
=
self
.
model
.
item
(
row
,
3
).
text
()
print
value
,
'THIS IS THE CHOICE VALUE, MAN'
self
.
parseModel
(
root
,
dest
=
dest
)
# XXX missing a kind.Set here !
intMappings
=
self
.
model
.
item
(
row
,
3
).
data
(
INTMAP
)
for
enumerant
,
num
in
intMappings
.
viewitems
():
if
enumerant
==
value
:
dest
.
kind
.
Set
(
num
)
break
else
:
raise
TypeError
(
'CHOICE discriminant not found'
)
else
:
self
.
parseModel
(
root
,
dest
=
dest
)
...
...
@@ -521,12 +526,6 @@ class asn1Editor(QTreeView):
# get the mapping to retrieve the choice name from the kind
intMappings
=
self
.
model
.
item
(
row
,
3
).
data
(
INTMAP
)
for
enumerant
,
num
in
intMappings
.
viewitems
():
try
:
# When using datamodel from standalone editor (OG simu)
import
DV
num
=
getattr
(
DV
,
num
)
except
(
ImportError
,
AttributeError
)
as
err
:
print
(
'XXX - discard when tested:'
+
str
(
err
))
if
num
==
kind
:
break
else
:
...
...
test/pytest/data/dv1.asn
View file @
2cc2dc0c
...
...
@@ -25,6 +25,8 @@ Type-SimpleSeq ::= SEQUENCE {
item-d Type-SingleString
}
Type-SingleSeqOf ::= SEQUENCE (SIZE (0..5)) OF INTEGER (0..255)
Type-Seq ::= SEQUENCE {
item-a Type-SingleReal,
item-b Type-SingleChoice,
...
...
test/pytest/test_standalone.py
View file @
2cc2dc0c
...
...
@@ -16,8 +16,12 @@ TEST = editor.SingleValueEditor('data/dv1.asn')
def
common
(
typeName
,
defValue
):
''' Set up test case: create asn1 editor and fill with default value '''
widget
=
TEST
.
setupEdit
(
typeName
,
defValue
=
defValue
)[
'editor'
]
widget
.
getVariable
(
dest
=
widget
.
asn1Instance
)
return
widget
.
asn1Instance
.
GSER
()
# Create a new type instance to put the result, so that we make sure
# that the result value is really taken from the ASN.1 editor
dest_instance
=
getattr
(
TEST
.
asn1ctypes
,
typeName
.
replace
(
'-'
,
'_'
))()
widget
.
getVariable
(
dest
=
dest_instance
)
assert
widget
.
asn1Instance
.
GSER
()
==
dest_instance
.
GSER
()
return
dest_instance
.
GSER
()
def
test_bool
(
qtbot
):
''' Test boolean values '''
...
...
@@ -62,13 +66,27 @@ def test_string(qtbot):
result
=
common
(
typeName
,
defValue
)
assert
result
==
defValue
def
test_seq
(
qtbot
):
def
test_
simple
seq
(
qtbot
):
''' Test SEQUENCE '''
typeName
=
"Type-SimpleSeq"
defValue
=
'{ item-a 42 , item-b TRUE , item-c enum-two , item-d "Hello world" }'
result
=
common
(
typeName
,
defValue
)
assert
result
==
defValue
def
test_simplechoice
(
qtbot
):
''' Test CHOICE '''
typeName
=
"Type-SingleChoice"
defValue
=
'choice-b: TRUE'
result
=
common
(
typeName
,
defValue
)
assert
result
==
defValue
def
test_simpleseqof
(
qtbot
):
''' Test SEQOF '''
typeName
=
"Type-SingleSeqOf"
defValue
=
'{ 1 , 2 , 3 , 4 , 5 }'
result
=
common
(
typeName
,
defValue
)
assert
result
==
defValue
if
__name__
==
'__main__'
:
print
(
'You must run py.test-2.7 to execute this test script'
)
print
(
'Make sure you have pytest-qt (pip install --user pytest-qt)'
)
...
...
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