/******************************************************************************
 * 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:
 *   Szabo, Bence Janos
 *
 ******************************************************************************/
module ExclusiveRangeTemplate {

type component EmptyCT {}


testcase tc_integer() runs on EmptyCT {

  template integer positive_templ:= (!1 .. !10);
  var integer f := 10;
  if (match(f, positive_templ)) {
    setverdict(fail, match(f, positive_templ));
  }
  f := 1;
  if (match(f, positive_templ)) {
    setverdict(fail, match(f, positive_templ));
  }
  f := 0;
  if (match(f, positive_templ)) {
    setverdict(fail, match(f, positive_templ));
  }
  f := 2;
  if (match(f, positive_templ) == false) {
    setverdict(fail, match(f, positive_templ));
  }
  f := 9;
  if (match(f, positive_templ) == false) {
    setverdict(fail, match(f, positive_templ));
  }

  if ("(!1 .. !10)" != log2str(positive_templ)) {
    setverdict(fail, match("(!1 .. !10)", log2str(positive_templ)));
  }
  template integer copy_positive_templ := positive_templ;
  if (log2str(positive_templ) != log2str(copy_positive_templ)) {
    setverdict(fail, match(log2str(positive_templ), log2str(copy_positive_templ)));
  }

  var template integer tmp;
  string2ttcn(ttcn2string(positive_templ), tmp);
  if (log2str(positive_templ) != log2str(tmp)) {
    setverdict(fail, "Expected: ", positive_templ, " Got: ", tmp);
  }

  template integer negative_templ:= (!-10 .. !-1);
  f := -10;
  if (match(f, negative_templ)) {
    setverdict(fail, match(f, negative_templ));
  }
  f := -1;
  if (match(f, negative_templ)) {
    setverdict(fail, match(f, negative_templ));
  }
  f := 0;
  if (match(f, negative_templ)) {
    setverdict(fail, match(f, negative_templ));
  }
  f := -1;
  if (match(f, negative_templ)) {
    setverdict(fail, match(f, negative_templ));
  }
  f := -2;
  if (match(f, negative_templ) == false) {
    setverdict(fail, match(f, negative_templ));
  }
  f := -9;
  if (match(f, negative_templ) == false) {
    setverdict(fail, match(f, negative_templ));
  }

  if ("(!-10 .. !-1)" != log2str(negative_templ)) {
    setverdict(fail, match("(!-10 .. !-1)", log2str(negative_templ)));
  }
  template integer copy_negative_templ := negative_templ;
  if (log2str(negative_templ) != log2str(copy_negative_templ)) {
    setverdict(fail, match(log2str(negative_templ), log2str(copy_negative_templ)));
  }

  setverdict(pass);
}

testcase tc_float() runs on EmptyCT {

  template float positive_templ:= (!1.0 .. !10.0);
  var float f := 10.0;
  if (match(f, positive_templ)) {
    setverdict(fail, match(f, positive_templ));
  }
  f := 1.0;
  if (match(f, positive_templ)) {
    setverdict(fail, match(f, positive_templ));
  }
  f := 0.0;
  if (match(f, positive_templ)) {
    setverdict(fail, match(f, positive_templ));
  }
  f := 1.0;
  if (match(f, 11.0)) {
    setverdict(fail, match(f, positive_templ));
  }
  f := 2.0;
  if (match(f, positive_templ) == false) {
    setverdict(fail, match(f, positive_templ));
  }
  f := 9.0;
  if (match(f, positive_templ) == false) {
    setverdict(fail, match(f, positive_templ));
  }

  if ("(!1.000000 .. !10.000000)" != log2str(positive_templ)) {
    setverdict(fail, match("(!1.000000 .. !10.000000)", log2str(positive_templ)));
  }
  template float copy_positive_templ := positive_templ;
  if (log2str(positive_templ) != log2str(copy_positive_templ)) {
    setverdict(fail, match(log2str(positive_templ), log2str(copy_positive_templ)));
  }

  var template float tmp;
  string2ttcn(ttcn2string(positive_templ), tmp);
  if (log2str(positive_templ) != log2str(tmp)) {
    setverdict(fail, "Expected: ", positive_templ, " Got: ", tmp);
  }

  template float negative_templ := (!-10.0 .. !-1.0);
  f := -10.0;
  if (match(f, negative_templ)) {
    setverdict(fail, match(f, negative_templ));
  }
  f := -1.0;
  if (match(f, negative_templ)) {
    setverdict(fail, match(f, negative_templ));
  }
  f := -0.0;
  if (match(f, negative_templ)) {
    setverdict(fail, match(f, negative_templ));
  }
  f := -11.0;
  if (match(f, negative_templ)) {
    setverdict(fail, match(f, negative_templ));
  }
  f := -2.0;
  if (match(f, negative_templ) == false) {
    setverdict(fail, match(f, negative_templ));
  }
  f := -9.0;
  if (match(f, negative_templ) == false) {
    setverdict(fail, match(f, negative_templ));
  }
  f := -5.0;
  if (match(f, negative_templ) == false) {
    setverdict(fail, match(f, negative_templ));
  }

  if ("(!-10.000000 .. !-1.000000)" != log2str(negative_templ)) {
    setverdict(fail, match("(!-10.000000 .. !-1.000000)", log2str(negative_templ)));
  }
  template float copy_negative_templ := negative_templ;
  if (log2str(negative_templ) != log2str(copy_negative_templ)) {
    setverdict(fail, match(log2str(negative_templ), log2str(copy_negative_templ)));
  }

  string2ttcn(ttcn2string(negative_templ), tmp);
  if (log2str(negative_templ) != log2str(tmp)) {
    setverdict(fail, "Expected: ", negative_templ, " Got: ", tmp);
  }

  template float infinity_templ := (!-infinity .. !infinity);
  if (match(f, infinity_templ) == false) {
    setverdict(fail, match(f, infinity_templ));
  }
  f := -infinity;
  if (match(f, infinity_templ)) {
    setverdict(fail, match(f, infinity_templ));
  }
  f := infinity;
  if (match(f, infinity_templ)) {
    setverdict(fail, match(f, infinity_templ));
  }

  if ("(!-infinity .. !infinity)" != log2str(infinity_templ)) {
    setverdict(fail, match("(!-infinity .. !infinity)", log2str(infinity_templ)));
  }
  template float copy_infinity_templ := infinity_templ;
  if (log2str(infinity_templ) != log2str(copy_infinity_templ)) {
    setverdict(fail, match(log2str(infinity_templ), log2str(copy_infinity_templ)));
  }

  setverdict(pass);
}

testcase tc_charstring() runs on EmptyCT {

  template charstring templ:= (!"d" .. !"g");
  var charstring f := "d";
  if (match(f, templ)) {
    setverdict(fail, match(f, templ));
  }
  f := "g";
  if (match(f, templ)) {
    setverdict(fail, match(f, templ));
  }
  f := "f";
  if (match(f, templ) == false) {
    setverdict(fail, match(f, templ));
  }
  f := "j";
  if (match(f, templ)) {
    setverdict(fail, match(f, templ));
  }
  f := "eeefff";
  if (match(f, templ) == false) {
    setverdict(fail, match(f, templ));
  }

  f := "dddeeefff";
  if (match(f, templ)) {
    setverdict(fail, match(f, templ));
  }
  f := "eeefffggg";
  if (match(f, templ)) {
    setverdict(fail, match(f, templ));
  }

  if ("(!\"d\" .. !\"g\")" != log2str(templ)) {
    setverdict(fail, match("(!\"d\" .. !\"g\")", log2str(templ)));
  }
  template charstring copy_templ := templ;
  if (log2str(templ) != log2str(copy_templ)) {
    setverdict(fail, match(log2str(templ), log2str(copy_templ)));
  }

  var template charstring tmp;
  string2ttcn(ttcn2string(templ), tmp);
  if (log2str(templ) != log2str(tmp)) {
    setverdict(fail, "Expected: ", templ, " Got: ", tmp);
  }

  setverdict(pass);
}


testcase tc_universal_charstring() runs on EmptyCT {

  template universal charstring charstr_templ:= (!"d" .. !"g");
  var universal charstring f := "d";
  if (match(f, charstr_templ)) {
    setverdict(fail, match(f, charstr_templ));
  }
  f := "g";
  if (match(f, charstr_templ)) {
    setverdict(fail, match(f, charstr_templ));
  }
  f := "f";
  if (match(f, charstr_templ) == false) {
    setverdict(fail, match(f, charstr_templ));
  }
  f := "j";
  if (match(f, charstr_templ)) {
    setverdict(fail, match(f, charstr_templ));
  }
  f := "eeefff";
  if (match(f, charstr_templ) == false) {
    setverdict(fail, match(f, charstr_templ));
  }

  f := "dddeeefff";
  if (match(f, charstr_templ)) {
    setverdict(fail, match(f, charstr_templ));
  }
  f := "eeefffggg";
  if (match(f, charstr_templ)) {
    setverdict(fail, match(f, charstr_templ));
  }

  if ("(!\"d\" .. !\"g\")" != log2str(charstr_templ)) {
    setverdict(fail, match("(!\"d\" .. !\"g\")", log2str(charstr_templ)));
  }
  template universal charstring copy_charstr_templ := charstr_templ;
  if (log2str(charstr_templ) != log2str(copy_charstr_templ)) {
    setverdict(fail, match(log2str(charstr_templ), log2str(copy_charstr_templ)));
  }

  var template universal charstring tmp;
  string2ttcn(ttcn2string(charstr_templ), tmp);
  if (log2str(charstr_templ) != log2str(tmp)) {
    setverdict(fail, "Expected: ", charstr_templ, " Got: ", tmp);
  }

  template universal charstring unicharstr_templ:= (!char(1,2,3,4) .. !char(1,2,4,5));
  f := char(1,2,3,4);
  if (match(f, unicharstr_templ)) {
    setverdict(fail, match(f, unicharstr_templ));
  }
  f := char(1,2,4,5);
  if (match(f, unicharstr_templ)) {
    setverdict(fail, match(f, unicharstr_templ));
  }
  f := char(1,2,3,5);
  if (match(f, unicharstr_templ) == false) {
    setverdict(fail, match(f, unicharstr_templ));
  }
  f := char(1,2,4,4);
  if (match(f, unicharstr_templ) == false) {
    setverdict(fail, match(f, unicharstr_templ));
  }

  if ("(!char(1, 2, 3, 4) .. !char(1, 2, 4, 5))" != log2str(unicharstr_templ)) {
    setverdict(fail, match("(!char(1, 2, 3, 4) .. !char(1, 2, 4, 5))", log2str(unicharstr_templ)));
  }
  template universal charstring copy_unicharstr_templ := unicharstr_templ;
  if (log2str(unicharstr_templ) != log2str(copy_unicharstr_templ)) {
    setverdict(fail, match(log2str(unicharstr_templ), log2str(copy_unicharstr_templ)));
  }

  string2ttcn(ttcn2string(unicharstr_templ), tmp);
  if (log2str(unicharstr_templ) != log2str(tmp)) {
    setverdict(fail, "Expected: ", unicharstr_templ, " Got: ", tmp);
  }

  setverdict(pass);
}


template integer positive_templ_glob:= (!1 .. !10);
// Test that is works with global const template
testcase tc_global_template_integer() runs on EmptyCT {
  var integer f := 10;
    if (match(f, positive_templ_glob)) {
    setverdict(fail, match(f, positive_templ_glob));
  }
  f := 1;
  if (match(f, positive_templ_glob)) {
    setverdict(fail, match(f, positive_templ_glob));
  }
  f := 0;
  if (match(f, positive_templ_glob)) {
    setverdict(fail, match(f, positive_templ_glob));
  }
  f := 2;
  if (match(f, positive_templ_glob) == false) {
    setverdict(fail, match(f, positive_templ_glob));
  }
  f := 9;
  if (match(f, positive_templ_glob) == false) {
    setverdict(fail, match(f, positive_templ_glob));
  }

  if ("(!1 .. !10)" != log2str(positive_templ_glob)) {
    setverdict(fail, match("(!1 .. !10)", log2str(positive_templ_glob)));
  }
  template integer copy_positive_templ := positive_templ_glob;
  if (log2str(positive_templ_glob) != log2str(copy_positive_templ)) {
    setverdict(fail, match(log2str(positive_templ_glob), log2str(copy_positive_templ)));
  }

  setverdict(pass);
}

// Test that it works with testcase local var template
testcase tc_testcase_var_template_integer() runs on EmptyCT {
  var template integer positive_templ:= (!1 .. !10);
  var integer f := 10;
    if (match(f, positive_templ)) {
    setverdict(fail, match(f, positive_templ));
  }
  f := 1;
  if (match(f, positive_templ)) {
    setverdict(fail, match(f, positive_templ));
  }
  f := 0;
  if (match(f, positive_templ)) {
    setverdict(fail, match(f, positive_templ));
  }
  f := 2;
  if (match(f, positive_templ) == false) {
    setverdict(fail, match(f, positive_templ));
  }
  f := 9;
  if (match(f, positive_templ) == false) {
    setverdict(fail, match(f, positive_templ));
  }

  if ("(!1 .. !10)" != log2str(positive_templ)) {
    setverdict(fail, match("(!1 .. !10)", log2str(positive_templ)));
  }
  template integer copy_positive_templ := positive_templ;
  if (log2str(positive_templ) != log2str(copy_positive_templ)) {
    setverdict(fail, match(log2str(positive_templ), log2str(copy_positive_templ)));
  }

  setverdict(pass);
}

control {
  execute(tc_integer());
  execute(tc_float());
  execute(tc_charstring());
  execute(tc_universal_charstring());
  execute(tc_global_template_integer());
  execute(tc_testcase_var_template_integer());
}

}