winIDEA SDK
Loading...
Searching...
No Matches
test_case_controller_example.py
# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
#
# (c) TASKING Germany GmbH, 2023
import isystem.connect as ic
winidea_id = ''
def init_target() -> ic.ConnectionMgr:
cmgr = ic.ConnectionMgr()
cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
debugCtrl = ic.CDebugFacade(cmgr)
debugCtrl.reset()
debugCtrl.runUntilFunction('main')
debugCtrl.waitUntilStopped()
return cmgr
def run_test(cmgr: ic.ConnectionMgr):
# Specify the function to be called and the parameters
testCaseCtrl = ic.CTestCaseController(cmgr, 'sum', 'retVal')
testCaseCtrl.createParameter(0, 'param1')
testCaseCtrl.createParameter(1, 'param2')
testCaseCtrl.createParameter(2, 'param3')
# Add the new variable to be used just for this test case
testCaseCtrl.createVariable('newVariable', 'int[10]')
# Initialize the test case
testCaseCtrl.init()
# Initialize the array and reset the first element after that
testCaseCtrl.modifyAsString('newVariable', "{0, 1, 2, -6, 4, 5, 6, 7, 8, 9}")
testCaseCtrl.modify('newVariable[0]', '10')
# Use two static values and our variable as call parameters
# This will return 5 + 10 + (-6) == 9
testCaseCtrl.modify('param1', '5')
testCaseCtrl.modify('param2', 'newVariable[0]')
testCaseCtrl.modify('param3', 'newVariable[3]')
print('Running test...')
testCaseCtrl.run()
testCaseCtrl.waitUntilStopped()
print('Finished.')
state = testCaseCtrl.getStatus()
if state == ic.IConnectTest.stateEnded:
print('Test finished normally.')
else:
print('Test ended in unexpected state: ', state)
# Gets function return value. Format specifier 'd' is used to always get
# decimal value, regardless of winIDEA settings.
rv = testCaseCtrl.evaluate('retVal,d')
print('return value: ', rv)
if rv != '9':
print('Test failed! retVal =', rv)
testCaseCtrl.destroy()
def main():
cmgr = init_target()
print('initialized')
run_test(cmgr)
if __name__ == '__main__':
main()