/******************************************************************************
 * Copyright (c) 2000-2025 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 Regressions {
modulepar boolean Regressions_verbose := false;
#define verbose Regressions_verbose
#include "../macros.ttcnin"

//import from EmbedValues { const LF };
//import from Flattener { function flatten }

type union choose1 {
  integer f1,
  record of boolean f2_list
}
with {
  variant (f2_list) "untagged";
  variant (f2_list[-]) "name as 'f2' ";
  variant "element";
}

DECLARE_EXER_ENCODERS(choose1, cx);

const choose1 alt1 := { f1 := 42 };
const choose1 alt20:= { f2_list := {} };
const choose1 alt2 := { f2_list := { true,true,false } };

const universal charstring str_alt1 :=
"<choose1>\n" &
"\t<f1>42</f1>\n" &
"</choose1>\n\n";

const universal charstring str_alt2 :=
"<choose1>\n" &
"\t<f2>true</f2>\n" &
"\t<f2>true</f2>\n" &
"\t<f2>false</f2>\n" &
"</choose1>\n\n";

const universal charstring str_alt20 :=
"<choose1>\n" &
"</choose1>\n\n";

const universal charstring str_alt21 :=
"<choose1/>\n\n";


type component C {}

testcase tc_enc_choice() runs on C
{
  CHECK_METHOD(exer_enc_cx, alt1, str_alt1);
  CHECK_METHOD(exer_enc_cx, alt2, str_alt2);
  CHECK_METHOD(exer_enc_cx, alt20,str_alt20);
}

testcase tc_dec_choice() runs on C
{
  CHECK_DECODE(exer_dec_cx, str_alt1,  choose1, alt1);
  CHECK_DECODE(exer_dec_cx, str_alt2,  choose1, alt2);
  CHECK_DECODE(exer_dec_cx, str_alt20, choose1, alt20);
  CHECK_DECODE(exer_dec_cx, str_alt21, choose1, alt20);
}

control {
  execute(tc_enc_choice());
  execute(tc_dec_choice());
}

}
with {
  encode "XML";
}
