/******************************************************************************
 * Copyright (c) ETSI 2017.
 *
 * This file is subject to copyrights owned by ETSI. Non-exclusive permission
 * is hereby granted, free of charge, to copy, reproduce and amend this file
 * under the following conditions: It is provided "as is", without warranty of any
 * kind, expressed or implied.
 * 
 * ETSI shall never be liable for any claim, damages, or other liability arising
 * from its use or inability of use.This permission does not apply to any documentation
 * associated with this file for which ETSI keeps all rights reserved. The present
 * copyright notice shall be included in all copies of whole or part of this
 * file and shall not imply any sub-license right.
 *
 * Modified by: Adrien Kirjak
 *
 ** @version  0.0.1
 ** @purpose  1:16.1.4, verify a function called during receiving operation cannot contain a component variable used as an actual out parameter (in templates)
 ** @verdict  pass reject
 ***************************************************/

// The following requirement is tested:
// If value returning functions are called in receiving communication operations (in templates, template fields, 
// in-line templates, or as actual parameters), in guards or events of alt statements or altsteps (see clause 20.2), 
// or in initializations of altstep local definitions (see clause 16.2), the following operations shall not be 
// used in functions called in the cases specified above, in order to avoid side effects that cause changing the 
// state of the component or the actual snapshot and to prevent different results of subsequent evaluations 
// on an unchanged snapshot:
// g) Changing of component variables, i.e. using component variables on the left-hand side of assignments, 
// and in the instantiation of out and inout parameters (see notes 4 and 6).

module NegSem_160104_invoking_functions_from_specific_places_041 { 
    type port P message {
        inout integer;
    } with {extension "internal"}

    type component GeneralComp {
        port P p;
		var integer vc_int;
	}
	
	function f_out (out integer p_out) {
		p_out := 1;
	}
    
	function f_test() runs on GeneralComp return template integer {
		f_out(vc_int);
		return ?;
	}

    testcase TC_NegSem_160104_invoking_functions_from_specific_places_041() runs on GeneralComp system GeneralComp {        
        template @fuzzy integer mw_test := f_test();
        connect(mtc:p, mtc:p);
        p.send(1);
		p.receive(mw_test);
		setverdict(pass);
	}

	control {
		execute(TC_NegSem_160104_invoking_functions_from_specific_places_041());
	}
}
