/******************************************************************************
 * 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:20.5.1, verify break command behaviour in invoked default
 ** @verdict  pass accept, ttcn3verdict:pass
 ***************************************************/

// The following requirement is tested:
// If the execution of the selected top alternative of the default ends with a break statement 
// the control flow of the test component will continue immediately after the alt statement.

module Sem_200501_the_default_mechanism_007 { 

	type port P message {
		inout integer;
	} with {extension "internal"}
	
	type component GeneralComp {
		var integer vc_messageCounter := 0;
		port P p;
	}
	
	altstep a() runs on GeneralComp {
		[] p.receive(integer:?) {
			vc_messageCounter := vc_messageCounter + 1;
			if (vc_messageCounter == 2) {
				setverdict(pass, "Message count full, terminating alt");
				break;
			}
			setverdict(pass, "Default value -> repeating alt");
			repeat;
		}
	}
	
	testcase TC_Sem_200501_the_default_mechanism_007() runs on GeneralComp {
		activate(a());

		connect(self:p, self:p);

		p.send(integer:5);
		p.send(integer:0);
		p.send(integer:1);

		alt {
			[] p.receive(integer:1) { // not expected: break should occur first
				vc_messageCounter := vc_messageCounter + 1;
				setverdict(fail);
			}
		}
		if (vc_messageCounter != 2) { 
			setverdict(fail, "Different number of received messages (", vc_messageCounter, ") than expected (2)");
		}
	}

	control{
		execute(TC_Sem_200501_the_default_mechanism_007());
	}
}
