/******************************************************************************
 * 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:B.1.5.5, Ensure that the IUT correctly handles character pattern compatibility rules of template matching
 ** @verdict  pass accept, ttcn3verdict:pass
 ***************************************************/

module Sem_B010505_pattern_compatibility_001 { 

    modulepar {
     	charstring MOD_REF:="modulepar reference";
    }

    type record MessageType {
     	universal charstring  		field1, 
     	universal charstring		field2,
     	universal charstring		field3,
     	universal charstring  		field4, 
     	universal charstring		field5,
     	universal charstring		field6,
     	universal charstring		field7
    }

    type port loopbackPort message {
      	inout MessageType
    } with {extension "internal"}
	
    const charstring c_Ref:="constant reference";
	

	type component GeneralComp {	    	    
      	port loopbackPort messagePort
	}	

	testcase TC_Sem_B010505_pattern_compatibility_001(charstring p_Ref) runs on GeneralComp {

    	var MessageType v_testMessage;
    	var charstring v_Ref:="variable reference";
    	template charstring m_Ref:= pattern "{c_Ref}";
    	template charstring m_RefExp_p1 := "{m_";  
    	template charstring m_RefExp_p2 := "Ref}!";
 
 		template MessageType mw_matchingTemplate:= {  	
		  	field1 := pattern "{v_Ref}",
		  	field2 := pattern "{c_Ref}", 
		  	field3 := pattern "{MOD_REF}",
		  	field4 := pattern "{p_Ref}",
		  	field5 := pattern "{m_Ref}",
		  	field6 := pattern "{m_"&"Ref}!",
		  	field7 := pattern "{m_RefExp_p1}{m_RefExp_p2}"
		} 

 		v_testMessage:=  {  
		  	field1 := "variable reference",
		  	field2 := "constant reference", 
		  	field3 := "modulepar reference",
		  	field4 := "parameter reference",
		  	field5 := "constant reference",
		  	field6 := "constant reference!",
		  	field7 := "{m_Ref}!"
 		} 
 
		connect(self:messagePort, self:messagePort);
 		messagePort.send(v_testMessage);

    	alt {
     		[] messagePort.receive(mw_matchingTemplate) {
        		setverdict(pass);
     		}
     		[] messagePort.receive {
        		setverdict(fail);
     		}
    	}
	}

	control{
		execute(TC_Sem_B010505_pattern_compatibility_001("parameter reference"));
	}

}
 
