Commit 0cb468d7 authored by Maxime Perrotin's avatar Maxime Perrotin

Generate proper, tested ctypes instances with ValueGenerator

parent 038ec9c2
......@@ -127,8 +127,8 @@ def compute_string_combinations(asn1_ty, dest):
state = dest.GetState()
for n in xrange(int(asn1_ty.Min), int(asn1_ty.Max) + 1):
dest.SetFromPyString('X' * n)
yield '"' + 'X' * n + '"'
dest.Reset(state)
yield '"' + 'X' * n + '"'
def compute_integer_combinations(asn1_ty, dest, max_iter=0):
''' Generator returning all integer values, with optional limit '''
......@@ -139,34 +139,35 @@ def compute_integer_combinations(asn1_ty, dest, max_iter=0):
for each in itertools.count(long(asn1_ty.Min)):
if each > max_iter:
break
dest.Set(each)
yield str(each)
# ctypes "Set" can only take an int, not a long
dest.Set(int(each))
dest.Reset(state)
yield str(each)
def compute_real_combinations(asn1_ty, dest):
''' Generator returning three real values only (set is infinite) '''
state = dest.GetState()
dest.Set(float(asn1_ty.Min))
yield asn1_ty.Min
dest.Reset(state)
yield asn1_ty.Min
dest.Set((float(asn1_ty.Max) + float(asn1_ty.Min)) / 2.0)
yield str((float(asn1_ty.Max) + float(asn1_ty.Min)) / 2.0)
dest.Reset(state)
yield str((float(asn1_ty.Max) + float(asn1_ty.Min)) / 2.0)
dest.Set(float(asn1_ty.Max))
yield asn1_ty.Max
dest.Reset(state)
yield asn1_ty.Max
def compute_boolean_combinations(asn1_ty, dest):
''' Generator returning all combinations of boolean '''
state = dest.GetState()
dest.Set(True)
yield 'TRUE'
dest.Reset(state)
yield 'TRUE'
dest.Set(False)
yield 'FALSE'
dest.Reset(state)
yield 'FALSE'
def compute_enumerated_combinations(asn1_ty, dest):
......@@ -185,12 +186,12 @@ def compute_choice_combinations(asn1_ty, pool, dest):
state = dest.GetState()
DV = sys.modules[dest.__module__].DV
for discr, value_ty in asn1_ty.Children.viewitems():
dest.Reset(state)
enum_id = asn1_ty.Children[discr].EnumID
dest.kind.Set(getattr(DV, enum_id.replace('-', '_')))
dest = getattr(dest, discr.replace('-', '_'))
for each in compute_combinations(value_ty, pool, dest):
yield '{}: {}'.format(discr, each)
dest.Reset(state)
def myproduct(*iterables):
......
......@@ -602,10 +602,15 @@ class sdlHandler(QObject):
docks.append(dock)
return docks
def click_tc(self, name, arg=None):
def direct_tc(self, name, arg_ctypes_ptr):
''' Send a TC by calling directly the function in the dll '''
getattr(self.dll, '{}_{}'.format(self.proc.processName,
name))(arg_ctypes_ptr)
def click_tc(self, name, arg_gser=None):
''' Send a TC by clicking on the Send button automatically
Inputs: name of Input,
arg: parameter in GSER format (ASN.1 Value Notation)
arg_gser: parameter in GSER format (ASN.1 Value Notation)
Doing so enables Undo/Redo, MSC Trace, etc. '''
if name not in self.active_tc:
return
......@@ -619,7 +624,7 @@ class sdlHandler(QObject):
asn1Instance = vals['editor'].asn1Instance
ASN1_AST=self.proc.dataview
sort=ASN1_AST[vals['editor'].item['nodeTypename']].type
vn.valueNotationToCTypes(gser=arg,
vn.valueNotationToCTypes(gser=arg_gser,
dest=asn1Instance,
sort=sort,
ASN1Mod=ASN1,
......@@ -674,12 +679,14 @@ class sdlHandler(QObject):
the PI, save the resulting state, undo, and yield the state '''
if asn1_ty:
print 'Exhausting', name
ptr = asn1_inst._ptr
for arg_gser in compute_combinations(asn1_ty,
self.proc.dataview,
asn1_inst):
self.click_tc(name, arg_gser)
self.direct_tc(name, ptr)
#self.click_tc(name, arg_gser)
new_hash = self.current_hash
self.undo()
#self.undo()
yield new_hash, (name, arg_gser)
else:
self.click_tc(name)
......
......@@ -8,6 +8,7 @@ from asn1_value_editor.ValueGenerator import (compute_random_value,
compute_combinations)
from asn1_value_editor.vn import fromValueNotationToPySide as parse_gser
from asn1_value_editor.vn import format_gser
from opengeode import Asn1scc as asn1scc
asn1scc.LOG.setLevel(asn1scc.logging.DEBUG)
......@@ -186,6 +187,21 @@ def test_random_mydata():
assert type(each) is int and 0 <= each <= 255
assert item['b']['Enum'] in ('enum-one', 'enum-two')
def test_exhaustive_mydata():
''' MyData - complex sequence '''
typeName = "MyData"
inst = Inst(typeName)
state = inst.GetState()
result = compute_combinations(pool[typeName], pool, inst)
count = 0
for each in xrange(5000):
res = result.next()
st1 = inst.GetState()
inst.Reset(state)
assert format_gser(inst.GSER()) == format_gser(res)
inst.Reset(st1)
def test_random_seq2():
''' Test more complex sequence '''
typeName = "Type-Seq"
......@@ -198,6 +214,4 @@ def test_random_seq2():
assert value['item-b']['Choice'] in ('choice-A', 'choice-B', 'choice-C')
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)')
sys.exit(1)
test_exhaustive_mydata()
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