/******************************************************************************
 * 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.2
 ** @purpose  1:21.1.2, Ensure that umnap operation of a component and system port works correctly
 ** @verdict  pass accept, ttcn3verdict:pass
 ***************************************************/

// The following requirements are tested:
// The ... unmap operations perform ... the unmapping of (previously mapped) ports of 
// test components and ports in the test system interface.

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

    type component GeneralComp
    {
        port P p;
    }
    
	function checkMapped(boolean p_stateActive) runs on GeneralComp
	{
		if(p.checkstate("Mapped") xor not p_stateActive) {
			setverdict(pass);			
		} else {
			setverdict(fail);
		}
	}
	
    testcase TC_Sem_210102_unmap_operation_001() runs on GeneralComp system GeneralComp {
        var GeneralComp v_ptc1 := GeneralComp.create;

		map(self:p, system:p);
		map(v_ptc1:p, system:p);

		unmap(v_ptc1:p, system:p);

		// verity that ports are really unmapped
        checkMapped(true); // still mapped to system:p
        v_ptc1.start(checkMapped(false)); // no active mapping
		v_ptc1.done;		
    }
	
    control{
        execute(TC_Sem_210102_unmap_operation_001());
    }
}

