/******************************************************************************
 * 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
 *
 ******************************************************************************/
module UseNumber {
modulepar boolean UseNumber_verbose := false;
#define verbose UseNumber_verbose
#include "../macros.ttcnin"

type component NR {}

type enumerated ProductColorUN { red(0), green(1), blue(2) }
with {
  variant "useNumber"
}

type record NrProduct {
  charstring name,
  ProductColorUN color,
  integer size
}

DECLARE_XER_ENCODERS(NrProduct, nr);
DECLARE_EXER_ENCODERS(NrProduct, nr);

const NrProduct nrval := {
  name  := "shirt",
  color := red,
  size  := 10
}

const universal charstring str_nr_e :=
"<NrProduct>\n" &
"\t<name>shirt</name>\n" &
"\t<color>0</color>\n" &
"\t<size>10</size>\n" &
"</NrProduct>\n" &
"\n";

const universal charstring str_nr_b :=
"<NrProduct>\n" &
"\t<name>shirt</name>\n" &
"\t<color><red/></color>\n" &
"\t<size>10</size>\n" &
"</NrProduct>\n" &
"\n";

testcase encode_nr() runs on NR
{
  CHECK_METHOD(bxer_enc_nr, nrval, str_nr_b);
  CHECK_METHOD(exer_enc_nr, nrval, str_nr_e);
}

testcase decode_nr() runs on NR
{
  CHECK_DECODE(bxer_dec_nr, str_nr_b, NrProduct, nrval);
  CHECK_DECODE(exer_dec_nr, str_nr_e, NrProduct, nrval);
}

control {
  execute(encode_nr());
  execute(decode_nr());
}

}
with {
  encode "XML"
}
