/******************************************************************************
 * 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:21.1.2, Ensure that disconnect operation with all ports of a component works correctly
 ** @verdict  pass accept, ttcn3verdict:pass
 ***************************************************/

// The following requirements are tested:
// To ease disconnect ... operations related to all connections ... of a component ..., 
// it is allowed to use disconnect ... operations with one argument only. This one argument
// specifies one side of the connections to be disconnected... The all port keyword can be 
// used to denote all ports of a component.

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

    type component GeneralComp
    {
        port P p1, p2;
    }
    
	function checkAllDisconnected() runs on GeneralComp
	{
		timer t := 1.0;
		t.start;
		if(not p1.checkstate("Connected") and not p2.checkstate("Connected")) {
			setverdict(pass);			
		} else {
			setverdict(fail);
		}
		t.timeout; // keep alive for 1 second
	}
	
	function checkSecondConnected() runs on GeneralComp
	{
		if(not p1.checkstate("Connected") and p2.checkstate("Connected")) {
			setverdict(pass);			
		} else {
			setverdict(fail);
		}
	}
	
    testcase TC_Sem_210102_disconnect_and_unmap_operations_003() runs on GeneralComp system GeneralComp {
        // components are created alive so that their connections are not destroyed when behaviour stops
		var GeneralComp v_ptc1 := GeneralComp.create alive, 
			v_ptc2 := GeneralComp.create alive,
			v_ptc3 := GeneralComp.create alive;

		connect(v_ptc1:p1, v_ptc2:p1);
		connect(v_ptc1:p2, v_ptc3:p1);		
		connect(v_ptc2:p2, v_ptc3:p2);

		disconnect(v_ptc1:all port);

		// verity that ports are really disconnected
		v_ptc1.start(checkAllDisconnected());
        v_ptc2.start(checkSecondConnected());
        v_ptc3.start(checkSecondConnected());
		all component.done;
    }
    control{
        execute(TC_Sem_210102_disconnect_and_unmap_operations_003());
    }
}

