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
d194fdf3
Commit
d194fdf3
authored
Jul 16, 2016
by
Maxime Perrotin
Browse files
Fix and test
parent
63ea9a53
Changes
3
Hide whitespace changes
Inline
Side-by-side
asn1_value_editor/asn1_value_editor.py
View file @
d194fdf3
...
...
@@ -332,32 +332,32 @@ class asn1Editor(QTreeView):
ptr
=
ptr
[
i
]
if
asnType
in
(
'SEQUENCE'
,
'SET'
):
#state = ptr.GetState()
#if not seqOf:
# ptr = getattr(ptr, name)
self
.
parseModel
(
root
.
child
(
i
),
dest
=
ptr
)
#ptr.Reset(state)
elif
asnType
==
'SEQOF'
:
#state = ptr.GetState()
# XXX missing SetLength
state
=
ptr
.
GetState
()
self
.
parseModel
(
root
.
child
(
i
),
nbRows
=
int
(
value
),
dest
=
ptr
)
#ptr.Reset(state)
ptr
.
SetLength
(
int
(
value
))
ptr
.
Reset
(
state
)
elif
asnType
==
'CHOICE'
:
state
=
ptr
.
GetState
()
# We must parse only one row, containing the choice (value)
chrow
=
root
.
child
(
i
)
for
rownb
in
xrange
(
chrow
.
rowCount
()):
curr
=
chrow
.
child
(
rownb
,
0
).
text
()
.
replace
(
'-'
,
'_'
)
if
curr
==
value
.
replace
(
'-'
,
'_'
)
:
curr
=
chrow
.
child
(
rownb
,
0
).
text
()
if
curr
==
value
:
# set rownb to the row of the current choice
break
else
:
print
(
'ERROR - choice
not found'
)
raise
TypeError
(
'CHOICE row
not found'
)
parseRow
(
chrow
,
rownb
,
dest
=
ptr
,
choice
=
True
)
ptr
.
Reset
(
state
)
# not correct: _PRESENT is not sufficient, full prefix needed
ptr
.
kind
.
Set
(
getattr
(
self
.
backend
.
DV
,
value
.
replace
(
'-'
,
'_'
)
+
'_PRESENT'
))
intMappings
=
root
.
child
(
i
,
3
).
data
(
INTMAP
)
for
enumerant
,
num
in
intMappings
.
viewitems
():
if
enumerant
==
value
:
ptr
.
kind
.
Set
(
num
)
break
else
:
raise
TypeError
(
'CHOICE determinant not found'
)
elif
asnType
==
'INTEGER'
:
ptr
.
Set
(
int
(
value
))
elif
asnType
==
'REAL'
:
...
...
@@ -373,10 +373,6 @@ class asn1Editor(QTreeView):
break
else
:
raise
TypeError
(
'ENUMERATED value not found'
)
#valNb = getattr(self.backend.DV, value.replace('-', '_'))
# XXX not correct, get the value from the data field
# (there could be prefixes)
#ptr.Set(valNb)
else
:
# Strings
ptr
.
SetFromPyString
(
value
)
for
i
in
xrange
(
nbRows
):
# for each child row
...
...
@@ -406,7 +402,6 @@ class asn1Editor(QTreeView):
intMappings
=
self
.
model
.
item
(
row
,
3
).
data
(
INTMAP
)
for
enumerant
,
num
in
intMappings
.
viewitems
():
if
enumerant
==
value
:
print
'Value:'
,
num
dest
.
Set
(
num
)
break
else
:
...
...
@@ -453,7 +448,6 @@ class asn1Editor(QTreeView):
ptr
=
getattr
(
dest
,
name
)
if
not
seqOf
else
dest
if
seqOf
:
ptr
=
ptr
[
i
]
if
asnType
in
(
'INTEGER'
,
'REAL'
,
'SEQOF'
):
# XXX plotter: TODO
plotters
=
child
.
data
(
PLOTTERS
)
...
...
@@ -462,8 +456,10 @@ class asn1Editor(QTreeView):
for
plotter
in
plotters
:
self
.
plotterBackend
.
updatePlot
(
plotter
,
value
)
self
.
log
.
debug
(
"updateModel - updatePlot end"
)
if
asnType
in
(
'INTEGER'
,
'REAL'
,
'BOOLEAN'
):
if
asnType
in
(
'INTEGER'
,
'REAL'
):
child
.
setText
(
str
(
ptr
.
Get
()))
elif
asnType
==
'BOOLEAN'
:
child
.
setText
(
'True'
if
ptr
.
Get
()
else
'False'
)
elif
asnType
==
'STRING'
:
child
.
setText
(
ptr
.
GetPyString
())
elif
asnType
==
'ENUMERATED'
:
...
...
@@ -474,21 +470,29 @@ class asn1Editor(QTreeView):
child
.
setText
(
enumerant
)
break
else
:
print
(
"ERROR =
ENUMERATED value not found"
)
raise
TypeError
(
"
ENUMERATED value not found"
)
elif
asnType
in
(
'SEQUENCE'
,
'SET'
):
self
.
updateModel
(
root
.
child
(
i
),
ptr
)
elif
asnType
==
'CHOICE'
:
state
=
ptr
.
GetState
()
value
=
ptr
.
kind
.
Get
()
value
Num
=
ptr
.
kind
.
Get
()
ptr
.
Reset
(
state
)
intMappings
=
child
.
data
(
INTMAP
)
choiceList
=
child
.
data
(
CHOICE_LIST
)
for
enumerant
,
num
in
intMappings
.
viewitems
():
if
num
==
value
:
if
num
==
value
Num
:
child
.
setText
(
str
(
enumerant
))
# is num really the row of this choice ? XXX
fillRow
(
root
.
child
(
i
),
num
,
dest
=
ptr
,
choice
=
True
)
# Find the choice row number
for
rowNb
,
choiceName
in
enumerate
(
choiceList
):
if
choiceName
==
enumerant
:
fillRow
(
root
.
child
(
i
),
rowNb
,
dest
=
ptr
,
choice
=
True
)
break
else
:
raise
TypeError
(
'CHOICE ROW not found'
)
break
#ptr.Reset(state)
else
:
raise
TypeError
(
'fillRow: CHOICE determinant not found'
)
elif
asnType
==
'SEQOF'
:
state
=
ptr
.
GetState
()
size
=
ptr
.
GetLength
()
...
...
@@ -522,7 +526,6 @@ class asn1Editor(QTreeView):
self
.
updateModel
(
root
,
ptr
=
asn1Instance
,
nbRows
=
nbElem
)
elif
asnType
==
'CHOICE'
:
kind
=
asn1Instance
.
kind
.
Get
()
print
kind
,
self
.
model
.
item
(
row
,
3
).
data
(
INTMAP
)
# 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
():
...
...
@@ -530,11 +533,8 @@ class asn1Editor(QTreeView):
break
else
:
self
.
log
.
error
(
"CHOICE index not found in DV.py"
)
# how to translate this kind number into the choice string? XXX
self
.
model
.
item
(
row
,
3
).
setText
(
enumerant
)
# decode the actual value
print
'choice, enumerant='
,
enumerant
#ptr = getattr(asn1Instance, enumerant.replace('-', '_'))
self
.
updateModel
(
root
,
asn1Instance
)
elif
asnType
in
(
'INTEGER'
,
'REAL'
):
self
.
model
.
item
(
row
,
3
).
setText
(
str
(
asn1Instance
.
Get
()))
...
...
@@ -969,7 +969,7 @@ class asn1Editor(QTreeView):
elif
elem
[
"type"
]
==
'CHOICE'
:
data
=
self
.
addChoice
(
elem
,
field
)
else
:
print
'You are using a non-
supported type: '
+
elem
[
"type"
]
raise
TypeError
(
'Un
supported type: '
+
elem
[
"type"
]
)
sys
.
exit
(
-
1
)
return
{
"item"
:
field
,
"type"
:
asnType
,
"value"
:
data
[
"value"
],
"constraint"
:
data
[
"constraint"
]}
...
...
test/pytest/data/dv1.asn
View file @
d194fdf3
...
...
@@ -14,14 +14,14 @@ Type-SingleEnum ::= ENUMERATED { enum-one(4), enum-two(2) }
Type-SingleString ::= OCTET STRING (SIZE(0..20))
Type-SingleChoice ::= CHOICE {
choice-
a
Type-SingleInt,
choice-
b
Type-SingleBool
choice-
A
Type-SingleInt,
choice-
B
Type-SingleBool
}
Type-SimpleSeq ::= SEQUENCE {
item-a Type-SingleInt,
item-b Type-SingleBool,
item-
c
Type-SingleEnum,
item-
C
Type-SingleEnum,
item-d Type-SingleString
}
...
...
@@ -30,11 +30,10 @@ Type-SingleSeqOf ::= SEQUENCE (SIZE (0..5)) OF INTEGER (0..255)
Type-Seq ::= SEQUENCE {
item-a Type-SingleReal,
item-b Type-SingleChoice,
item-
c
MyData,
item-
C
MyData,
item-d Type-SingleString
}
END
TASTE-BasicTypes DEFINITIONS ::=
...
...
test/pytest/test_standalone.py
View file @
d194fdf3
...
...
@@ -70,14 +70,17 @@ def test_string(qtbot):
def
test_simpleseq
(
qtbot
):
''' Test SEQUENCE '''
typeName
=
"Type-SimpleSeq"
defValue
=
'{item-a 42, item-b TRUE, item-
c
enum-two, item-d "Hello world"}'
defValue
=
'{item-a 42, item-b TRUE, item-
C
enum-two, item-d "Hello world"}'
result
=
common
(
typeName
,
defValue
)
assert
format_gser
(
result
)
==
format_gser
(
defValue
)
def
test_simplechoice
(
qtbot
):
''' Test CHOICE '''
typeName
=
"Type-SingleChoice"
defValue
=
'choice-b: TRUE'
defValue
=
'choice-B: TRUE'
result
=
common
(
typeName
,
defValue
)
assert
format_gser
(
result
)
==
format_gser
(
defValue
)
defValue
=
'choice-A: 99'
result
=
common
(
typeName
,
defValue
)
assert
format_gser
(
result
)
==
format_gser
(
defValue
)
...
...
@@ -88,6 +91,23 @@ def test_simpleseqof(qtbot):
result
=
common
(
typeName
,
defValue
)
assert
format_gser
(
result
)
==
format_gser
(
defValue
)
def
test_mydata
(
qtbot
):
''' Test more complex sequence '''
typeName
=
"MyData"
defValue
=
'{{a {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, b enum-one}, {a {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, b enum-two}}'
result
=
common
(
typeName
,
defValue
)
assert
format_gser
(
result
)
==
format_gser
(
defValue
)
def
test_seq2
(
qtbot
):
''' Test more complex sequence '''
typeName
=
"Type-Seq"
defValue
=
'{item-a 42.0, item-b choice-B: TRUE, item-C {{a {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, b enum-one}, {a {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, b enum-two}}, item-d "Hello, world"}'
result
=
common
(
typeName
,
defValue
)
assert
format_gser
(
result
)
==
format_gser
(
defValue
)
defValue
=
'{item-a 42.0, item-b choice-A: 99, item-C {{a {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, b enum-one}}, item-d "Hi"}'
result
=
common
(
typeName
,
defValue
)
assert
format_gser
(
result
)
==
format_gser
(
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
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