Commit fed14ef6 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Complexify test of ROOT choice

parent a2e39cf5
......@@ -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:
......
......@@ -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 {
......
......@@ -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 '''
......
Markdown is supported
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