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
05e05533
Commit
05e05533
authored
Jul 16, 2016
by
Maxime Perrotin
Browse files
Fix support for strings in vn.py, augment test cases
parent
6d7758bf
Changes
3
Show whitespace changes
Inline
Side-by-side
asn1_value_editor/standalone_editor.py
View file @
05e05533
...
...
@@ -171,10 +171,11 @@ class SingleValueEditor(QObject):
try
:
logger
.
info
(
asnFile
)
dataView
=
asn1scc
.
parse_asn1
([
asnFile
],
self
.
dataView
=
asn1scc
.
parse_asn1
([
asnFile
],
rename_policy
=
asn1scc
.
ASN1
.
RenameOnlyConflicting
,
ast_version
=
asn1scc
.
ASN1
.
UniqueEnumeratedNames
,
flags
=
[
asn1scc
.
ASN1
.
AstOnly
])
self
.
ASN1_AST
=
dataView
.
types
self
.
ASN1_AST
=
self
.
dataView
.
types
except
(
ImportError
,
NameError
,
TypeError
)
as
err
:
logger
.
error
(
'Error loading ASN.1 model'
)
logger
.
debug
(
str
(
err
))
...
...
@@ -182,8 +183,9 @@ class SingleValueEditor(QObject):
raise
# convert dataView types to a list of tc as needed by asn1-value-editor
for
t
,
v
in
dataView
.
types
.
items
():
self
.
tc
[
t
]
=
asn1sccToasn1ValueEditorTypes
(
dataView
.
types
,
t
,
v
.
type
)
for
t
,
v
in
self
.
ASN1_AST
.
viewitems
():
self
.
tc
[
t
]
=
asn1sccToasn1ValueEditorTypes
(
self
.
ASN1_AST
,
t
,
v
.
type
)
logger
.
debug
(
"Types found in '%s' asn file:
\n\t
%s"
,
asnFile
,
self
.
tc
.
keys
())
...
...
@@ -265,8 +267,6 @@ class SingleValueEditor(QObject):
instance
=
getattr
(
self
.
asn1ctypes
,
asnType
.
replace
(
'-'
,
'_'
))()
widget
[
'editor'
].
asn1Instance
=
instance
logger
.
info
(
'Created instance of '
+
asnType
)
x
=
instance
.
Get
()
if
defValue
:
valueNotationToCTypes
(
gser
=
defValue
,
dest
=
instance
,
...
...
asn1_value_editor/vn.py
View file @
05e05533
...
...
@@ -252,8 +252,8 @@ def valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None):
for
each
in
path
:
reach
(
each
,
outp
)
# Follow the ASN.1 type in the AST from ASN1SCC
rec
(
inp
[
i
],
outp
[
i
],
sort
.
type
.
type
)
if
sort
.
type
.
Min
!=
sort
.
type
.
Max
:
rec
(
inp
[
i
],
outp
[
i
],
sort
.
type
)
if
sort
.
Min
!=
sort
.
Max
:
outp
.
Reset
()
for
each
in
path
:
reach
(
each
,
outp
)
...
...
@@ -261,16 +261,19 @@ def valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None):
outp
.
SetLength
(
len
(
inp
))
elif
isinstance
(
inp
,
(
int
,
float
,
bool
)):
outp
.
Set
(
inp
)
elif
isinstance
(
inp
,
str
):
outp
.
SetFromPyString
(
inp
)
elif
isinstance
(
inp
,
dict
):
if
'Enum'
in
inp
:
# Get proper enum id from the ASN1SCC AST
enum_id
=
sort
.
type
.
EnumValues
[
inp
[
'Enum'
].
replace
(
'_'
,
'-'
)].
EnumID
enum_id
=
sort
.
EnumValues
[
inp
[
'Enum'
].
replace
(
'_'
,
'-'
)].
EnumID
print
ASN1Mod
.
DV
.
__file__
val
=
getattr
(
ASN1Mod
.
DV
,
enum_id
)
outp
.
Set
(
val
)
elif
'Choice'
in
inp
:
child_name
=
inp
[
'Choice'
]
ch_ty
=
sort
.
type
.
Children
[
child_name
.
replace
(
'_'
,
'-'
)]
ch_ty
=
sort
.
Children
[
child_name
.
replace
(
'_'
,
'-'
)]
enum_val
=
getattr
(
ASN1Mod
.
DV
,
ch_ty
.
EnumID
)
state
=
outp
.
GetState
()
outp
.
kind
.
Set
(
enum_val
)
...
...
@@ -290,7 +293,7 @@ def valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None):
reach
(
each
,
outp
)
# Then get the field itself
reach
(
field
.
replace
(
'-'
,
'_'
),
outp
)
field_ty
=
sort
.
type
.
Children
[
field
.
replace
(
'_'
,
'-'
)]
field_ty
=
sort
.
Children
[
field
.
replace
(
'_'
,
'-'
)]
rec
(
data
,
outp
,
field_ty
.
type
)
# move back to original path
outp
.
Reset
()
...
...
@@ -298,7 +301,7 @@ def valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None):
reach
(
path
[
0
],
outp
)
else
:
# Unsupported type
pass
raise
NotImplementedError
(
'vn - type conversion error'
)
rec
(
var
,
dest
,
sort
)
...
...
test/pytest/test_standalone.py
View file @
05e05533
...
...
@@ -37,6 +37,31 @@ def test_int(qtbot):
result
=
common
(
typeName
,
defValue
)
assert
result
==
defValue
def
test_real
(
qtbot
):
''' Test float value '''
typeName
=
"Type-SingleReal"
defValue
=
'1.25'
result
=
common
(
typeName
,
defValue
)
assert
result
==
defValue
def
test_enum
(
qtbot
):
''' Test enumerated value '''
typeName
=
"Type-SingleEnum"
defValue
=
'enum-one'
result
=
common
(
typeName
,
defValue
)
assert
result
==
defValue
defValue
=
'enum-two'
result
=
common
(
typeName
,
defValue
)
assert
result
==
defValue
def
test_string
(
qtbot
):
''' Test octet string value '''
typeName
=
"Type-SingleString"
defValue
=
'"Hello, world"'
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