/******************************************************************************
 * 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 – initial implementation
 *
 ******************************************************************************/
module Tools {

import from Types all;

type component CT {}

const integer c_16K := 16384;

function f_DFE(in integer p_octets, in boolean p_negative) return octetstring {
  // 0DFFFF...FE or CDFFFF...FE
  var octetstring x;
  if (p_negative) {
    x := 'CD'O;
  }
  else {
    x := '0D'O;
  }
  for (var integer i := 1; i < p_octets - 1; i := i + 1) {
    x[i] := 'FF'O;
  }
  x[p_octets - 1] := 'FE'O;
  return x;
}

function f_seqof() return SeqOf5 {
  // create a SeqOf5 of 18000 elements
  var SeqOf5 x;
  var SeqOf5 n := { 17, 12, 10, 15, 18, 13, 19, 11, 16, 14 };
  for (var integer i := 0; i < 1800; i := i + 1) {
    for (var integer j := 0; j < 10; j := j + 1) {
      x[i * 10 + j] := n[j];
    }
  }
  return x;
}

function f_setof() return SetOf5 {
  // create a SetOf5 of 18000 elements
  var SetOf5 x;
  var SetOf5 n := { 17, 12, 10, 15, 18, 13, 19, 11, 16, 14 };
  for (var integer i := 0; i < 1800; i := i + 1) {
    for (var integer j := 0; j < 10; j := j + 1) {
      x[i * 10 + j] := n[j];
    }
  }
  return x;
}

function f_seqof_setof_enc(in boolean p_sorted) return bitstring {
  var bitstring x := '11000001'B;
  if (p_sorted) {
    var integer pos := 0;
    var bitstring b[10] := { '0000'B, '0001'B, '0010'B, '0011'B, '0100'B, '0101'B, '0110'B, '0111'B, '1000'B, '1001'B };
    for (var integer j := 0; j < 10; j := j + 1) {
      for (var integer i := 0; i < 1800; i := i + 1) {
        if (j * 1800 + i == c_16K) {
          x := x & '1000011001010000'B;
        }
        x := x & b[j];
      }
      pos := pos + 1800;
    }
  }
  else {
    var bitstring b[10] := { '0111'B, '0010'B, '0000'B, '0101'B, '1000'B, '0011'B, '1001'B, '0001'B, '0110'B, '0100'B };
    for (var integer i := 0; i < 1800; i := i + 1) {
      for (var integer j := 0; j < 10; j := j + 1) {
        if (i * 10 + j == c_16K) {
          x := x & '1000011001010000'B;
        }
        x := x & b[j];
      }
    }
  }
  return x;
}

function f_vis_str(out VisStr1 p_str, out bitstring p_enc) {
  // creates a VisStr1 of 36000 characters and its encoding
  p_str := "";
  p_enc := '11000010'B;
  for (var integer i := 0; i < 9000; i := i + 1) {
    p_str := p_str & "abcd";
    if (i * 2 == c_16K) {
      p_enc := p_enc & '1000110010100000'B;
    }
    p_enc := p_enc & '00011011'B;
  }
}

function f_gen_str(out GenStr p_str, out bitstring p_enc) {
  // creates a GenStr of 35168 characters and its encoding
  p_str := "";
  p_enc := '11000010'B;
  for (var integer i := 0; i < 8792; i := i + 1) {
    p_str := p_str & "John";
    if (i * 2 == c_16K) {
      p_enc := p_enc & '1000100101100000'B;
    }
    p_enc := p_enc & '01001010011011110110100001101110'B;
  }
}

}
