/***************************************************
 ** @author   STF 470
 ** @version  0.0.1
 ** @purpose  1:16.1.2, Ensure that predefined decvalue function works properly in case of decoding failure
 ** @verdict  pass accept, ttcn3verdict:pass
 ***************************************************/

// The following requirements are tested:
// (C.5.2)
// The decvalue function decodes a bitstring into a value. The test system shall suppose that
// the bitstring encoded_value represents an encoded instance of the actual type of decoded_value.
// If the decoding was unsuccessful, the actual parameters for encoded_value and decoded_value are
// not changed. The function shall return an integer value to indicate success or failure of the
// decoding below:
// • The return value 1 indicates an unspecified cause of decoding failure.

module Sem_160102_predefined_functions_019 {
    type enumerated E { one(1), two(2), three(3) } with { variant "32 bit"};

    type component GeneralComp {
    }

    testcase TC_Sem_160102_predefined_functions_019 () runs on GeneralComp {
        var bitstring v_test := int2bit(0, 32);
		var E v_decoded;
		var integer v_res := decvalue(v_test, v_decoded);
		// expected result:
		// v_res: 1 (failure, unspecified) -> no named value corresponding to ordinal number 0
		// v_decoded: uninitialized
		// v_test: original 32-bit value
		if (match(v_res, 1) and not isbound(v_decoded) and match(lengthof(v_test), 32)) {
			setverdict(pass);
		} else {
			setverdict(fail, "Unexpected decoding result");
		}
    }

    control{
        execute(TC_Sem_160102_predefined_functions_019());
    }
}