/*****************************************************************
 ** @author   STF 470
 ** @version  0.0.1
 ** @purpose  1:22.3.4, Verify any from getreply index redirection to lazy variable
 ** @verdict  pass accept, ttcn3verdict:pass
 *****************************************************************/
// The following requirements are tested:
// Restriction i
// 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 getreply operation. Later
// evaluation of the lazy or fuzzy variable does not lead to repeated invocation of the
// getreply operation.
module Sem_220304_getreply_operation_007 {

    signature S();

	type port P procedure {
		inout S;
	}

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

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