/*****************************************************************
 ** @author   STF 470
 ** @version  0.0.1
 ** @purpose  1:22.3.2, Verify any from getcall index redirection to lazy variable
 ** @verdict  pass accept, ttcn3verdict:pass
 *****************************************************************/
// The following requirements are tested:
// Restriction k
// If a variable referenced in the @index clause is a lazy or fuzzy variable, the expression
// assigned to this variable is equal to the result produced by the getcall operation. Later
// evaluation of the lazy or fuzzy variable does not lead to repeated invocation of the
// getcall operation.
module Sem_220302_getcall_operation_012 {

    signature S(integer p_par);

	type port P procedure {
		inout S;
	}

	const integer c_portCount := 4;
    type component GeneralComp
	{
		port P p[c_portCount];
	}
	function f() runs on GeneralComp
	{
		var @lazy integer v_index;
        alt
		{
        	[] any from p.getcall -> @index value v_index {
				if(v_index == 1){ // no getcall call during evaluation, v_index remains equal to 1
		            setverdict(pass);
		        } else {
		            setverdict(fail, "Index incorrectly assigned");
		        }
			}
			[else] { setverdict(fail, "The any from getcall didn't match for some reason"); }
		}
	}
    testcase TC_Sem_220302_getcall_operation_012() runs on GeneralComp system GeneralComp {
		var GeneralComp v_ptc := GeneralComp.create;
		for(var integer i := 0; i < c_portCount; i := i + 1) {
			connect(self:p[i], v_ptc:p[i]);
			if (i mod 2 > 0) { p[i].call(S:{ p_par := i + 100 }, nowait); }
		}
		v_ptc.start(f());
		v_ptc.done;
    }

    control {
        execute(TC_Sem_220302_getcall_operation_012(), 5.0);
    }
}