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


/* The following requirement is tested:
Decoded field reference is a specific notation that can be applied to expressions of bitstring, hexstring,
octetstring, charstring or universal charstring types. It is used for accessing content of implicitly decoded payload fields.
*/

module Sem_0703_decoded_field_reference_002 {

type component GeneralComp {
}

type hexstring PduHeader;
type integer OuterPayloadHeader;

type record PDU {
		PduHeader header,
		hexstring outerPayload        // hexstring
}

type record OuterPayload {
	 charstring innerPayload
}

type charstring InnerPayload;

testcase TC_Sem_0703_decoded_field_reference_002() runs on GeneralComp {
    // outerPayload content is "test text"
    var OuterPayload v_outerPayload := { innerPayload := "test text" };

    // convert universal charstring to octetstring
    var bitstring v_test := encvalue(v_outerPayload);

    // convert bitstring to hexstring
	var PDU v_packet := {header:= 'FF'H, outerPayload := bit2hex(v_test)};    // PDU contains hexadecimal values

	var InnerPayload v_payload := v_packet.outerPayload => OuterPayload.innerPayload;    // decode "innerPayload"

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

control{
    execute(TC_Sem_0703_decoded_field_reference_002());
}

}