/******************************************************************************
 * 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
 *   Szabados, Kristof
 *   Szabo, Janos Zoltan – initial implementation
 *
 ******************************************************************************/
module TtemplateBool {
type component templateBool_mycomp {};
type record templateBool_rec {
 boolean x1,
 boolean x2,
 boolean x3 optional };
template templateBool_rec templateBool_tSpec :={ //specific values
 x1:=true,
 x2:=false,
 x3:=false };
template templateBool_rec templateBool_tList :={ //specific value and value list
 x1:=true,
 x2:=(false),
 x3:=false };
template templateBool_rec templateBool_tComp :={ //specific value and compl. list
 x1:=true,
 x2:=complement (true),
 x3:=false };
template templateBool_rec templateBool_tOmit :={ //omitting values
 x1:=true,
 x2:=false,
 x3:=omit } ;
template templateBool_rec templateBool_tAny :={ //specific and any value
 x1:=true,
 x2:=false,
 x3:=? } ;
template templateBool_rec templateBool_tAnyorNone :={ //specific and AnyorNone value
 x1:=true,
 x2:=false,
 x3:=* };
template templateBool_rec templateBool_tIfpresent :={ //specific value and ifpresent
 x1:=true,
 x2:=false,
 x3:=false ifpresent };

testcase templateBoolSpec() runs on templateBool_mycomp {
var templateBool_rec x1,x2;		//specific value
x1:={ x1:=true,  x2:=false,  x3:=false };
x2:={ x1:=true,  x2:=true,  x3:=false };
//match
if (match(x1,templateBool_tSpec)) {setverdict(pass);}
 else {setverdict(fail);}
//no match
if (not(match(x2,templateBool_tSpec))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBoolList() runs on templateBool_mycomp {
var templateBool_rec x1,x2,x3;		//value list
x1:={ x1:=true,  x2:=false,  x3:=false };
x2:={ x1:=true,  x2:=true,  x3:=false };
x3:={ x1:=false,  x2:=false,  x3:=false };
//match
if (match(x1,templateBool_tList)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: out of list
if (not(match(x2,templateBool_tList))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateBool_tList))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBoolComp() runs on templateBool_mycomp {
var templateBool_rec x1,x2,x3;		//complemented list
x1:={ x1:=true,  x2:=false,  x3:=false };
x2:={ x1:=true,  x2:=true,  x3:=false };
x3:={ x1:=false,  x2:=false,  x3:=false };
//match
if (match(x1,templateBool_tComp)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: in the list
if (not(match(x2,templateBool_tComp))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateBool_tComp))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBoolOmit() runs on templateBool_mycomp {
var templateBool_rec x1,x2,x3;		//omitting value
x1:={ x1:=true,  x2:=false,  x3:=omit };
x2:={ x1:=true,  x2:=false,  x3:=true };
x3:={ x1:=false,  x2:=false,  x3:=omit };
//match
if (match(x1,templateBool_tOmit)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: not omitted
if (not(match(x2,templateBool_tOmit))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateBool_tOmit))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBoolAny() runs on templateBool_mycomp {
var templateBool_rec x1,x2,x3;		//any value
x1:={ x1:=true,  x2:=false,  x3:=false };
x2:={ x1:=true,  x2:=false,  x3:=omit };
x3:={ x1:=false,  x2:=false,  x3:=false };
//match
if (match(x1,templateBool_tAny)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: field omitted
if (not(match(x2,templateBool_tAny))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateBool_tAny))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBoolAnyorNone() runs on templateBool_mycomp {
var templateBool_rec x1,x2,x3;		//AnyorNone value
x1:={ x1:=true,  x2:=false,  x3:=omit };
x2:={ x1:=true,  x2:=false,  x3:=true };
x3:={ x1:=false,  x2:=false,  x3:=omit };
//match: omitted
if (match(x1,templateBool_tAnyorNone)) {setverdict(pass);}
 else {setverdict(fail);}
//match: value
if (match(x2,templateBool_tAnyorNone)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateBool_tAnyorNone))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBoolIfpresent() runs on templateBool_mycomp {
var templateBool_rec x1,x2,x3,x4;		//ifpresent
x1:={ x1:=true,  x2:=false,  x3:=false };
x2:={ x1:=true,  x2:=false,  x3:=omit };
x3:={ x1:=true,  x2:=false,  x3:=true };
x4:={ x1:=false,  x2:=false,  x3:=omit };
//match: present and match
if (match(x1,templateBool_tIfpresent)) {setverdict(pass);}
 else {setverdict(fail);}
//match: not present
if (match(x2,templateBool_tIfpresent)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: present and not match
if (not(match(x3,templateBool_tIfpresent))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x4,templateBool_tIfpresent))) {setverdict(pass);}
 else {setverdict(fail);}
}

function f_opposite(boolean p_par) return boolean {
  return not p_par;
}

template boolean t_conjunction := conjunct(false, @dynamic f_opposite);

template boolean t_implication := true implies @dynamic f_opposite;

template boolean t_dynamic(boolean p_par) := @dynamic {
  return value and p_par;
}

testcase templateBoolConjunction() runs on templateBool_mycomp {
  var boolean v1 := true, v2 := false;
  if (match(v1, t_conjunction)) {
    setverdict(fail, match(v1, t_conjunction));
  }
  if (not match(v2, t_conjunction)) {
    setverdict(fail, match(v2, t_conjunction));
  }
  setverdict(pass);
}

testcase templateBoolImplication() runs on templateBool_mycomp {
  var boolean v1 := true, v2 := false;
  if (match(v1, t_implication)) {
    setverdict(fail, match(v1, t_implication));
  }
  if (not match(v2, t_implication)) {
    setverdict(fail, match(v2, t_implication));
  }
  setverdict(pass);
}

testcase templateBoolDynamic() runs on templateBool_mycomp {
  var boolean v1 := true, v2 := false;
  if (not match(v1, t_dynamic(true))) {
    setverdict(fail, match(v1, t_dynamic(true)));
  }
  if (match(v2, t_dynamic(true))) {
    setverdict(fail, match(v2, t_dynamic(true)));
  }
  setverdict(pass);
}

control {
 execute(templateBoolSpec());
 execute(templateBoolList());
 execute(templateBoolComp());
 execute(templateBoolOmit());
 execute(templateBoolAny());
 execute(templateBoolAnyorNone());
 execute(templateBoolIfpresent());
 execute(templateBoolConjunction());
 execute(templateBoolImplication());
 execute(templateBoolDynamic());
}
}
