/*****************************************************************
 ** @author   STF 521
 ** @version  0.0.1
 ** @purpose  1:22.3.1, blocking multicast call with response and exception handling part and subsequent alt
 ** @verdict  pass accept, ttcn3verdict:pass
 *****************************************************************/

// The following requirements are tested:
// In case of a multicast or broadcast call operation of a blocking procedure, two options exist. Either,
// only one response or exception is handled in the response and exception handling part of the call
// operation. Then, further responses and exceptions can be handled in subsequent alt or interleave
// statements.

module Sem_220301_CallOperation_012 {

	signature S();

	type port P procedure {
		inout S;
	}

    type component GeneralComp {
		port P p;
	}

	function f_called() runs on GeneralComp {
		p.getcall(S:?);
		p.reply(S:{});
	}

    testcase TC_Sem_220301_CallOperation_012() runs on GeneralComp system GeneralComp {
        var GeneralComp v_ptc1 := GeneralComp.create,
			v_ptc2 := GeneralComp.create,
			v_ptc3 := GeneralComp.create,
			v_comp;
		connect(self:p, v_ptc1:p);
		connect(self:p, v_ptc2:p);
		connect(self:p, v_ptc3:p);
		v_ptc1.start(f_called());
		v_ptc2.start(f_called());
		v_ptc3.start(f_called());
		p.call(S:{}) to (v_ptc1, v_ptc3) {
			[] p.getreply(S:?) -> sender v_comp {
				if (v_comp == v_ptc1 or v_comp == v_ptc3) {
					setverdict(pass, "First reply received");
				} else {
					setverdict(fail, "Wrong component");
				}
			}
		}
		alt {
			[] p.getreply(S:?) -> sender v_comp {
				if (v_comp == v_ptc1 or v_comp == v_ptc3) {
					setverdict(pass, "Second reply received");
				} else {
					setverdict(fail, "Wrong component");
				}
			}
		}
    }

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