/***************************************************
 ** @author   STF 521
 ** @version  0.0.1
 ** @purpose  1:16.1.4, verify that a non-deterministic external function call cannot be used in a function called during receiving operation (in templates)
 ** @verdict  pass reject
 ** @configuration  external_functions
 ***************************************************/

// 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:
// e) Calling non-deterministic external functions, i.e. external functions where the resulting values for actual
// inout or out parameters or the return value may differ for different invocations with the same actual in and
// inout parameters (see notes 4 and 6).

module NegSem_160104_invoking_functions_from_specific_places_038 {
    type port P message {
        inout integer;
    }

    type component GeneralComp {
        port P p;
	}

	/**
	 * @return always true
	 */
    external function xf_NegSem_160104_invoking_functions_from_specific_places_001() return boolean;

	function f_test() runs on GeneralComp return template integer {
		if (xf_NegSem_160104_invoking_functions_from_specific_places_001()) { return ?; }
		else { return 1; }
	}

    testcase TC_NegSem_160104_invoking_functions_from_specific_places_038() 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_038());
	}
}
