/******************************************************************************
 * Copyright (c) 2000-2021 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
 *
 * Contributors:
 *   Balasko, Jeno
 *   Raduly, Csaba
 *   Szabados, Kristof
 *
 ******************************************************************************/
module xmlTest_encDec
{

//=========================================================================
// Import Part
//=========================================================================
//import from XSD all;
// import from PIPEasp_Types all;
// import from PIPEasp_PortType all;
// import from PIPEasp_Templates all;
// import from xmlTest_Shell all;
import from www_XmlTest_org_complex1_e all;

external function f_enc_InternationalPrice(in InternationalPrice pdu, out octetstring stream)
with { extension "prototype(fast) encode(XER:XER_EXTENDED)" }
//0: OK
//1: NOK

external function f_dec_InternationalPrice(in octetstring stream, out InternationalPrice pdu) return integer
with { extension "prototype(backtrack) decode(XER:XER_EXTENDED)" }

//Encoding decoding test:
function f_encDecTest_InternationalPrice() {
  var InternationalPrice vl_pdu:= {
    currency:="US",
    base:=54321.9
  },vl_decodedPdu;
  var octetstring vl_expectedEncodedPdu:=char2oct("<ns:InternationalPrice ns:currency='US' xmlns:ns='www.XmlTest.org/complex1_e'>54321.900000</ns:InternationalPrice>\n\n")
  ;
  var octetstring vl_stream:=''O;

  f_enc_InternationalPrice(vl_pdu,vl_stream);
  if( not match(vl_stream,vl_expectedEncodedPdu)) {
    log("Actual encoded value:   ", vl_stream);
    setverdict(fail);
  }

  //Check value decoded from the encoded vs original value:
  //log("Decoding comes");
  var integer vl_retval:=f_dec_InternationalPrice(vl_stream, vl_decodedPdu);
  //log("retval:",vl_retval);
  if(f_dec_InternationalPrice(vl_stream, vl_decodedPdu)==0) {
    //log("The decoded pdu: ", vl_decodedPdu);
    if(match(vl_pdu,vl_decodedPdu)) {
      setverdict(pass);
    } else {
      log("Pdu could not decoded");
      log(match(vl_pdu,vl_decodedPdu));
    }
  }

  //Check value decoded from the expected value vs original value:
  if( f_dec_InternationalPrice(vl_expectedEncodedPdu, vl_decodedPdu)==0) {
    //log("The decoded pdu: ", vl_decodedPdu);
    if(match(vl_pdu,vl_decodedPdu)) {
      setverdict(pass);
    } else {
      log("Pdu could not decoded from the expected value");
      log(match(vl_pdu,vl_decodedPdu));
    }
  }
  
}


}//module
