5import isystem.connect
as ic
6import isystem.itest
as it
12def init_target() -> ic.ConnectionMgr:
13 cmgr = ic.ConnectionMgr()
14 cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
16 debug_ctrl = ic.CDebugFacade(cmgr)
18 debug_ctrl.runUntilFunction(
'main')
19 debug_ctrl.waitUntilStopped()
23def run_test_with_param_in_host_var(test_case: it.PTestCase):
25 This function uses host variables to specify test parameters.
27 host_vars = ic.CTestHostVars()
28 test_spec = 'func: [sum, ["${param1}", 4, 2], retVal]\n' + \
30 '- retVal == ${param1} + 6'
31 test_spec_obj = ic.CTestSpecification.parseTestSpec(test_spec)
33 for param_a
in range(0, 5, 2):
34 host_vars.setValue(
'${param1}', str(param_a))
36 test_case.itest(test_spec_obj,
None,
False, host_vars)
38 print(
'\nsum test result:', end=
' ')
39 results = test_case.getTestResultsContainer()
40 result = results.nextTestResult()
42 print(result.toString())
44 print(f
"OK a = {param_a}")
47def run_test_with_param_in_string(test_case: it.PTestCase):
49 Builds the test specification using Python's string formatting.
52 for param_a
in range(0, 5, 2):
53 test_spec = (f
'func: [sum, [{param_a}, 2, 1], retVal]\n'
55 f
'- retVal == 3 + {param_a}')
56 test_spec_obj = ic.CTestSpecification.parseTestSpec(test_spec)
58 test_case.itest(test_spec_obj,
None)
60 print(
'\nsum test result:', end=
' ')
61 results = test_case.getTestResultsContainer()
62 result = results.nextTestResult()
64 print(result.toString())
66 print(f
"OK a = {param_a}")
69def run_test_with_param_as_local_var(test_case: it.PTestCase):
71 Modifies local variable, which is used
as function parameter.
73 for param_a
in range(0, 5, 2):
79 func: [sum, [a, 2, 1], retVal]
83 test_case.itest(test_spec, None)
85 print(
'\nsum test result:', end=
' ')
86 results = test_case.getTestResultsContainer()
87 result = results.nextTestResult()
89 print(result.toString())
91 print(f
"OK a = {param_a}")
94def run_test_with_test_spec_as_object(test_case: it.PTestCase):
96 This example uses test specification as a starting point,
97 and sets parameters later by using API.
'testSpec' is no longer a string,
98 but an object
with methods.
101 test_spec = ic.CTestSpecification()
102 func_under_test = test_spec.getFunctionUnderTest(False)
103 func_under_test.setName(
"sum")
104 func_under_test.setRetValueName(
"retVal")
106 for param_a
in range(0, 5, 2):
108 params = ic.StrVector()
109 params.append(str(param_a))
110 params.append(str(2))
111 params.append(str(3))
112 test_spec.getFunctionUnderTest(
False).setPositionParameters(params)
114 exprs = ic.StrVector()
115 exprs.append(
'retVal == 5 + ' + str(param_a))
116 test_spec.setExpectedResults(exprs)
118 print(test_spec.toString())
120 test_case.itest(test_spec,
None)
122 print(
'\nsum test result:', end=
' ')
123 results = test_case.getTestResultsContainer()
124 result = results.nextTestResult()
126 print(result.toString())
128 print(f
"OK a = {param_a}")
133 test_case = it.PTestCase(cmgr)
134 print(
"Tests with host variable")
135 run_test_with_param_in_host_var(test_case)
136 print(
"Tests with parameter in YAML test specification string.")
137 run_test_with_param_in_string(test_case)
138 print(
"Test with parameter as local variable")
139 run_test_with_param_as_local_var(test_case)
140 print(
"Use test specification as object.")
141 run_test_with_test_spec_as_object(test_case)
144if __name__ ==
'__main__':