Commit 05e05533 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Fix support for strings in vn.py, augment test cases

parent 6d7758bf
...@@ -171,10 +171,11 @@ class SingleValueEditor(QObject): ...@@ -171,10 +171,11 @@ class SingleValueEditor(QObject):
try: try:
logger.info(asnFile) logger.info(asnFile)
dataView = asn1scc.parse_asn1([asnFile], self.dataView = asn1scc.parse_asn1([asnFile],
ast_version=asn1scc.ASN1.UniqueEnumeratedNames, rename_policy=asn1scc.ASN1.RenameOnlyConflicting,
flags=[asn1scc.ASN1.AstOnly]) ast_version=asn1scc.ASN1.UniqueEnumeratedNames,
self.ASN1_AST = dataView.types flags=[asn1scc.ASN1.AstOnly])
self.ASN1_AST = self.dataView.types
except (ImportError, NameError, TypeError) as err: except (ImportError, NameError, TypeError) as err:
logger.error('Error loading ASN.1 model') logger.error('Error loading ASN.1 model')
logger.debug(str(err)) logger.debug(str(err))
...@@ -182,8 +183,9 @@ class SingleValueEditor(QObject): ...@@ -182,8 +183,9 @@ class SingleValueEditor(QObject):
raise raise
# convert dataView types to a list of tc as needed by asn1-value-editor # convert dataView types to a list of tc as needed by asn1-value-editor
for t, v in dataView.types.items(): for t, v in self.ASN1_AST.viewitems():
self.tc[t] = asn1sccToasn1ValueEditorTypes(dataView.types, t, v.type) self.tc[t] = asn1sccToasn1ValueEditorTypes(self.ASN1_AST,
t, v.type)
logger.debug("Types found in '%s' asn file: \n\t%s", logger.debug("Types found in '%s' asn file: \n\t%s",
asnFile, self.tc.keys()) asnFile, self.tc.keys())
...@@ -265,8 +267,6 @@ class SingleValueEditor(QObject): ...@@ -265,8 +267,6 @@ class SingleValueEditor(QObject):
instance = getattr(self.asn1ctypes, asnType.replace('-', '_'))() instance = getattr(self.asn1ctypes, asnType.replace('-', '_'))()
widget['editor'].asn1Instance = instance widget['editor'].asn1Instance = instance
logger.info('Created instance of ' + asnType) logger.info('Created instance of ' + asnType)
x = instance.Get()
if defValue: if defValue:
valueNotationToCTypes(gser=defValue, valueNotationToCTypes(gser=defValue,
dest=instance, dest=instance,
......
...@@ -252,8 +252,8 @@ def valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None): ...@@ -252,8 +252,8 @@ def valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None):
for each in path: for each in path:
reach(each, outp) reach(each, outp)
# Follow the ASN.1 type in the AST from ASN1SCC # Follow the ASN.1 type in the AST from ASN1SCC
rec(inp[i], outp[i], sort.type.type) rec(inp[i], outp[i], sort.type)
if sort.type.Min != sort.type.Max: if sort.Min != sort.Max:
outp.Reset() outp.Reset()
for each in path: for each in path:
reach(each, outp) reach(each, outp)
...@@ -261,16 +261,19 @@ def valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None): ...@@ -261,16 +261,19 @@ def valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None):
outp.SetLength(len(inp)) outp.SetLength(len(inp))
elif isinstance(inp, (int, float, bool)): elif isinstance(inp, (int, float, bool)):
outp.Set(inp) outp.Set(inp)
elif isinstance(inp, str):
outp.SetFromPyString(inp)
elif isinstance(inp, dict): elif isinstance(inp, dict):
if 'Enum' in inp: if 'Enum' in inp:
# Get proper enum id from the ASN1SCC AST # Get proper enum id from the ASN1SCC AST
enum_id = sort.type.EnumValues[ enum_id = sort.EnumValues[inp['Enum'].replace('_', '-')].EnumID
inp['Enum'].replace('_', '-')].EnumID print ASN1Mod.DV.__file__
val = getattr(ASN1Mod.DV, enum_id) val = getattr(ASN1Mod.DV, enum_id)
outp.Set(val) outp.Set(val)
elif 'Choice' in inp: elif 'Choice' in inp:
child_name = inp['Choice'] 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) enum_val = getattr(ASN1Mod.DV, ch_ty.EnumID)
state = outp.GetState() state = outp.GetState()
outp.kind.Set(enum_val) outp.kind.Set(enum_val)
...@@ -290,7 +293,7 @@ def valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None): ...@@ -290,7 +293,7 @@ def valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None):
reach(each, outp) reach(each, outp)
# Then get the field itself # Then get the field itself
reach(field.replace('-', '_'), outp) reach(field.replace('-', '_'), outp)
field_ty = sort.type.Children[field.replace('_', '-')] field_ty = sort.Children[field.replace('_', '-')]
rec(data, outp, field_ty.type) rec(data, outp, field_ty.type)
# move back to original path # move back to original path
outp.Reset() outp.Reset()
...@@ -298,7 +301,7 @@ def valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None): ...@@ -298,7 +301,7 @@ def valueNotationToCTypes(gser, dest, sort, ASN1Mod, ASN1_AST, var=None):
reach(path[0], outp) reach(path[0], outp)
else: else:
# Unsupported type # Unsupported type
pass raise NotImplementedError('vn - type conversion error')
rec(var, dest, sort) rec(var, dest, sort)
......
...@@ -37,6 +37,31 @@ def test_int(qtbot): ...@@ -37,6 +37,31 @@ def test_int(qtbot):
result = common(typeName, defValue) result = common(typeName, defValue)
assert result == 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__': if __name__ == '__main__':
print('You must run py.test-2.7 to execute this test script') 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)') print('Make sure you have pytest-qt (pip install --user pytest-qt)')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment