/******************************************************************************
 * 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_002 { 

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

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

    type port loopbackPort message {
      	inout MessageType
    } with {extension "internal"}

    const universal charstring c_Ref:="constant reference";
	

	type component GeneralComp {	    	    
      	port loopbackPort messagePort
	}	

	testcase TC_Sem_B010505_pattern_compatibility_002(universal charstring p_Ref) runs on GeneralComp {

    	var MessageType v_testMessage;
    	var universal charstring v_Ref:="variable reference";
    	template universal charstring m_Ref:= pattern "{c_Ref}";
    	template universal charstring m_RefExp_p1 := pattern "{m_";  
    	template universal charstring m_RefExp_p2 := pattern "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_002("parameter reference"));
	}

}
 
