Test case R0101
Full test suiteDevice test case
Function/FB calls : persistence
This test case it part of the test suite proposed for new devices.
Test case ID: R0101
Language: ST
tests2/t0101.st
// should run 2 times
FUNCTION F1_R0101 : INT (* returns X+Y+2 *)
VAR_INPUT
X : INT ;
Y : INT ;
END_VAR
F1_R0101 := X + Y +2;
END_FUNCTION
FUNCTION_BLOCK FB1_R0101
VAR_INPUT
X : INT ;
Y : INT := 30 ;
END_VAR
VAR_TEMP
T1 : INT; T2 : INT := 3; (* these are kept fixed at 1,4 *)
END_VAR
VAR
V1 : INT; V2 : INT := 5; (* these increment by one in each call, from (0,5) *)
END_VAR
VAR_OUTPUT
O1,O2,O3,O4 : INT;
END_VAR
(* increment all vars *)
T1 := T1 + 1;
T2 := T2 + 1;
V1 := V1 + 1;
V2 := V2 + 1;
O4 := O1; // value of O1 in previous call
O1 := X + Y + 2; // sum of inputs (+2)
O2 := T1 + T2 ; // always 5
O3 := V1 + V2 ; // 7 , 9 , 11
END_FUNCTION_BLOCK
PROGRAM R0101
VAR
I1,I2,I3,I4 : INT;
f1 : FB1_R0101;
END_VAR
VAR_EXTERNAL
_T_PARAMS : TEST_PARAMS;
END_VAR
I2 := F1_R0101(X := 100, Y:= 50); // 152
I4 := F1_R0101(100, 70); // 172
f1( X := 1000 , Y := 300);
// should Y persists its value ? norm is not clear ; we do persist it
f1( X := 5000);
(*
after one run we should have :
Test.f1.O1 : 5302
Test.f1.O2 : 5
Test.f1.O3 : 9
Test.f1.O4 : 1302
*)
IF _T_PARAMS.cycle = _T_PARAMS.timestorun THEN // last iteration
_GEB_ASSERT_(I2 = 152);
//_GEB_ASSERT_(I3 = 62);
_GEB_ASSERT_(I4 = 172);
_GEB_ASSERT_(f1.O1=5302);
_GEB_MSG_(INT_TO_STRING(f1.O1));
_GEB_ASSERT_(f1.O2=5);
_GEB_ASSERT_(f1.O3=13);
_GEB_ASSERT_(f1.O4=1302);
_GEB_ASSERT_(f1.X=5000);
_GEB_ASSERT_(f1.Y=300);
END_IF;
END_PROGRAM


