/******************************************************************************
 * 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:
 *   Baranyi, Botond
 *
 ******************************************************************************/
 
// This module contains further tests for PER encodings and encodings for ASN.1 types
// (in features only available in the Function Test Runtime).
module AsnAndPerRT2 {

import from Types all;
import from Custom1 all;

// Test 20 (RT2 only).
// The redirected value is decoded into a value of ASN.1 type Seq.
// Same input value as in test 8.
testcase tc_asn_value_redirect() runs on CT
{
  connect(self:pt_msg, self:pt_msg);
  var Seq val := { num := 10, str := "abc" };
  var Msg msg := { data := bit2oct(encvalue(val)), list := { } };
  var Seq res;
  pt_msg.send(msg);
  timer tmr := 1.0;
  tmr.start;
  alt {
    [] pt_msg.receive(msg) -> value (res := @decoded data) {
      if (res != val) {
        setverdict(fail, "Invalid decoded value. Expected: ", val, ", got: ", res);
      }
      else {
        setverdict(pass);
      }
    }
    [] pt_msg.receive(?) {
      setverdict(fail, "Invalid message received.");
    }
    [] tmr.timeout {
      setverdict(fail, "Timed out.");
    }
  }
}

// Test 21 (RT2 only).
// The redirected value is decoded using the PER coder.
// Same input value as in test 11.
testcase tc_per_value_redirect() runs on CT
{
  connect(self:pt_msg, self:pt_msg);
  var SeqOf val := { 1, 2, 3 };
  var Msg msg := { data := bit2oct(encvalue(val)), list := { } };
  var SeqOf res;
  pt_msg.send(msg);
  timer tmr := 1.0;
  tmr.start;
  alt {
    [] pt_msg.receive(msg) -> value (res := @decoded data) {
      if (res != val) {
        setverdict(fail, "Invalid decoded value. Expected: ", val, ", got: ", res);
      }
      else {
        setverdict(pass);
      }
    }
    [] pt_msg.receive(?) {
      setverdict(fail, "Invalid message received.");
    }
    [] tmr.timeout {
      setverdict(fail, "Timed out.");
    }
  }
}

control {
  execute(tc_asn_value_redirect());
  execute(tc_per_value_redirect());
}

}
