Structures: manipulation and passing as arguments

This test case it part of the test suite proposed for new devices.

Test case ID: R0015
Language: ST

Code:
tests2/t0015.st
(* checks structs/arrays passing-returning to functions  - and assignment *) 

TYPE 
    POINT: STRUCT
            X: INT; 
            Y : INT;
    END_STRUCT;
         
    RECT: STRUCT
            P1: POINT;
            P2: POINT;
    END_STRUCT;
    
END_TYPE 

PROGRAM T0015

VAR
    pp1,pp2,pp3,pp4: POINT;
    r1,r2: RECT;
END_VAR
    r1.P1.X := 42;                 // r1 : [42,0][0,0] (not final)
    r2 := r1; // this should make a copy  // r2 : [42,0][0,0] (not final)
    r1.P1.X := 15;               // r1 : [15,0][0,0]  (not final)   
    pp1.X := 10;                  
    pp1.Y := 13;                  // pp1: [10,13] (not final)
    r2.P2 := pp1;                 // r2 : [42,0][10,13] (final)
    pp1.Y := 11;                  // pp1: [10,11] (not final)
    
    _GEB_ASSERT_(pp1.X = 10 AND pp1.Y = 11 );
    pp2 := PTRANSPOSE_T0015(pp1,pp4); // ; pp2: [16,10]  pp4 : [1,2]
    _GEB_ASSERT_(pp1.X = 10 AND pp1.Y = 11 ); // the above should not have altered p1
     
    pp1.X := pp1.X * 2;              // pp1: [20,11]
    pp3 := PTRANSPOSE_T0015( pin := pp1, pxx => r1.P2 ); // p3 : [16,20]  r1: [15,0][1,2]

    _GEB_ASSERT_(pp1.X = 20 AND pp1.Y = 11 );
    _GEB_ASSERT_(pp2.X = 16 AND pp2.Y = 10 );
    _GEB_ASSERT_(pp3.X = 16 AND pp3.Y = 20 );
    _GEB_ASSERT_(pp4.X =1 AND pp4.Y= 2 );
    
    _GEB_ASSERT_(r1.P1.X=15 AND r1.P1.Y=0);
    _GEB_ASSERT_(r1.P2.X=1 AND r1.P2.Y=2 );

    _GEB_ASSERT_(r2.P1.X=42 AND r2.P1.Y=0);
    _GEB_ASSERT_(r2.P2.X=10 AND r2.P2.Y=13 );


END_PROGRAM

(* transpose point coordinates and adds 5 to coordinate X *)
FUNCTION PTRANSPOSE_T0015: POINT
 VAR_INPUT 
    pin: POINT;
 END_VAR
 VAR_OUTPUT 
    pxx: POINT; // this is always returned  as [1,2]
 END_VAR
 
 VAR
     xx: INT;
 END_VAR
     xx := pin.X;
     PTRANSPOSE_T0015 := pin;
     PTRANSPOSE_T0015.X := PTRANSPOSE_T0015.Y +5;
     PTRANSPOSE_T0015.Y := xx ; 
     pxx.X := 1;
     pxx.Y := 2;
     
 END_FUNCTION