/******************************************************************************
 * 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  9:7.1.5, Verify that fixed value is automatically assigned to empty element by decoder
 ** @verdict  pass accept, ttcn3verdict:pass
***************************************************/
// The following requirements are tested:
// The fixed attribute applied to attribute or element elements shall be mapped 
// to a subtype definition with the single allowed value identical to the value 
// of the fixed attribute plus a "defaultForEmpty ÃÂ¢ÃÂÃÂ¦" encoding instruction 
// identifying the value of the fixed attribute as well.
// From B.3.7: This encoding instruction ... designates that the decoder shall 
// insert the value specified by freetext if the corresponding attribute is 
// omitted or when the corresponding element appears without any content in the 
// XML instance being decoded; it has no effect in other cases.
////////////////////////////////////////////////////////////////////////////////

module Pos_070105_default_and_fixed_004 {

   import from schema_Pos_070105_default_and_fixed_004 language "XSD" all;

   template MyType m_msg := {
       foo := "foo"
   };

	external function enc_MyType(in MyType pdu) return octetstring
  	 with { extension "prototype (convert) encode(XER:XER_EXTENDED)" }
  
  	external function dec_MyType(in octetstring stream) return MyType
  	 with { extension "prototype (convert) decode(XER:XER_EXTENDED)" }

    /**
     * @desc The timeout given in seconds after which the test case will be stopped.
     */
    modulepar float PX_TC_EXECUTION_TIMEOUT := 5.0;

    type universal charstring Raw;

    type port P message {
        inout Raw;
    } with {extension "internal"}

    type component C {
        port P p;
		port P p1;
    }

    testcase TC_Pos_070105_default_and_fixed_004() runs on C system C {
        var Raw v_rcv;

        connect(self:p, self:p1);

        v_rcv := "<ns123:MyType xmlns:ns123='schema:Pos_070105_default_and_fixed_004'>\n\t<foo/>\n</ns123:MyType>\n\n";

		if(match(dec_MyType(unichar2oct(v_rcv)),m_msg))	{
			setverdict(pass, "Decoded value matches encoded template and reference XML ");
		}
		else {	
			setverdict(fail, "XML decoding failure, reason:", dec_MyType(unichar2oct(v_rcv)));
		}

    }

    control {
        execute(TC_Pos_070105_default_and_fixed_004(), PX_TC_EXECUTION_TIMEOUT);
    }


}
