/******************************************************************************
 * 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:
 *   Szabados, Kristof *
 ******************************************************************************/
module XER_EncDec_3 {

type component Test_CT{};


type float MyFloat
with {
  encode "XML";
  variant "XSD:decimal";
};

type record MyRec {
  MyFloat myfloat
} 
with {
  encode "XML";
  variant (myfloat) "fractionDigits 2";
  variant (myfloat) "attribute";
};

external function ef_xer_dec(in octetstring par) return MyRec
  with { extension "prototype(convert) decode (XER:XER_EXTENDED) errorbehavior(ALL:ERROR)" }

testcase tc_dec_fractiondigits_attr() runs on Test_CT {
  var universal charstring xml := "<MyRec myfloat='1234567890.111'></MyRec>\n";
@try {
  ef_xer_dec(unichar2oct(xml));
} @catch (msg) {
  var template charstring msg_exp := pattern "*Dynamic test case error: While XER-decoding type '@XER_EncDec_3.MyRec': Component 'myfloat': The float value \(1234567890.111\) contains too many fractionDigits. Expected 2 or less*";
  if (not match(msg, msg_exp)) {
    setverdict(fail, "Invalid error message: ", msg);
  } else {
    setverdict(pass);
  }
}
  setverdict(pass);
}

control {
  execute(tc_dec_fractiondigits_attr());
}

}
