/*****************************************************************
 ** @author   STF 584
 ** @version  0.0.1
 ** @purpose  1:7.2, Ensure that the IUT correctly handles field reference decoding
 ** @verdict  pass reject
 *****************************************************************/

/* The following requirement is tested:
In case the string operand is of the universalcharstring type and
the extended syntax with parentheses is used, the type operand can be followed by an optional parameter defining the encoding format. The parameter shall be of the charstring type and it shall contain one of the strings allowed for the decvalue_unichar function (specified in clause C.5.4). Any other value shall cause an error. In case the string operand is not a universalcharstring, the optional parameter shall not be present.
*/

module NegSem_0703_decoded_field_reference_002 {

type component GeneralComp {
}

type charstring PduHeader;
type integer OuterPayloadHeader;

type record PDU {
		PduHeader header,
		universal charstring outerPayload        // universal charstring
}

type record OuterPayload {
	 charstring innerPayload
}

type universal charstring InnerPayload;

testcase TC_NegSem_0703_decoded_field_reference_002() runs on GeneralComp {
    // outerPayload content is "test text"
    var charstring v_testText := "test text";
    var universal charstring v_test := encvalue_unichar(v_testText);

    // convert universal charstring (UTF-8)
	var PDU v_packet := {header:= "header", outerPayload := v_test};

	var InnerPayload v_payload := v_packet.outerPayload => (OuterPayload.innerPayload, "incorrect encoding format"); // error: incorrect encoding format

	if ( match(v_payload,"test text")) {
		setverdict(pass);
	} else {
		setverdict(fail);
	}
}

control{
    execute(TC_NegSem_0703_decoded_field_reference_002());
}

}