File: Common.ttcn

package info (click to toggle)
eclipse-titan 8.2.0-1
  • links: PTS
  • area: main
  • in suites: bookworm, sid
  • size: 103,544 kB
  • sloc: cpp: 271,008; ansic: 33,683; yacc: 23,419; makefile: 15,483; lex: 9,204; java: 4,848; perl: 4,555; sh: 2,242; xml: 1,378; javascript: 85; awk: 48; php: 32; python: 13
file content (250 lines) | stat: -rw-r--r-- 7,237 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/******************************************************************************
 * 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:
 *   Balasko, Jeno
 *   Baranyi, Botond
 *
 ******************************************************************************/
// This module contain the common constants, types and functions for testing the following functions:
// oct2unichar
// unichar2oct
// get_stringencoding
module Common {

const octetstring c_BOM_UTF8    :='EFBBBF'O; 
const octetstring c_BOM_UTF16BE :='FEFF'O
const octetstring c_BOM_UTF16LE :='FFFE'O
const octetstring c_BOM_UTF32BE :='0000FEFF'O;
const octetstring c_BOM_UTF32LE :='FFFE0000'O;
const universal charstring c_arvizturo := char(0,0,0,193)&"rv"&char(0,0,0,237)&"zt"&char(0,0,1,113)&"r"&char(0,0,1,81) & " t" & char(0,0,0,252)&"k"&char(0,0,0,246)&"rf"&char(0,0,0,250)&"r"&char(0,0,0,243)&"g"&char(0,0,0,233)&"p";

type component MTC {}

type record of universal charstring RoUCS;
type record of octetstring RoOS;

function f_check_string_encoding( in octetstring os, in charstring  expectedEncoding) {
  var charstring c := get_stringencoding(os);
  log(c);
  if( c == expectedEncoding ) {
    setverdict(pass,"encoding type ok");
  } else {
    setverdict(fail,"encoding type nok, expected: " & expectedEncoding & " got: " & c );
  }  
}


function f_oct2unichar_positivetest(
  in octetstring inputOs,
  in charstring encType,
  in universal charstring expectedUCS,
  in charstring expectedEncType,
  in octetstring expectedOs :=''O
) {
  var universal charstring u;
  @try{
    u := oct2unichar( inputOs, encType );
    log("Unicode result:",u);
    if(match(u,expectedUCS)) {
      setverdict(pass,"oct2unichar() conversion is the expected");
    } else {
      setverdict(fail,"unmatched :", match(u,expectedUCS)); 
    }
  }
  @catch(err_str) {    
    //setverdict(fail,"oct2unichar(",inputOs , ", ", encType ," ) unexpectedly failed:" , err_str );
    setverdict(fail,err_str);
  }

  //f_check_string_encoding(inputOs,expectedEncType);

  if(expectedOs == ''O)
  {
    expectedOs:=inputOs;
  }
  if( unichar2oct( u, encType ) == expectedOs){
    setverdict(pass, "converting back to octetstring is ok")
  }  else {
    setverdict(fail,"converting back to octetstring is nok, expected:", expectedOs, " got: ",  unichar2oct( u, encType ) );
  }  

}

function f_oct2unichar_negativetest(
  in octetstring inputOs,
  in charstring encType,
  in charstring expectedErrorMsg
) {
  var universal charstring u;
  @try{
    u := oct2unichar( inputOs, encType );
    setverdict(fail,"Error was expected")
  }
  @catch(err_str) {
    var template charstring expectedErrorTempl := pattern "*{expectedErrorMsg}";
    log("oct2unichar(",inputOs,", """,encType," "") failed as expected:", err_str);    
    if( match(err_str, expectedErrorTempl) ) {
      setverdict(pass, "error message is the expected: >>" & err_str & "<<")
    } else {
      setverdict(fail,"error message is not the expected. Expected: >>"& expectedErrorMsg & "<< got: >>" & err_str &"<<");
    }
  } 

}




//changes the content of elements i,i+1
//for utf16
function f_changeOrder(inout octetstring o) return boolean {
  var integer len := lengthof(o);
  log("Octetstring to be changed:",o);
  var octetstring temp;
  if((len mod 2)!=0 ) {
    return false;
  }

  for(var integer i:=0; i<len; i:=i+2) {
    temp:=o[i];
    o[i]:=o[i+1];
    o[i+1]:=temp;
  }
  log("Changed octetstring:", o);
  return true;
}

function f_changeOrderUTF32(inout octetstring o) return boolean {
  var integer len := lengthof(o);
  log( "Octetstring to be changed:", o);
  var octetstring temp1, temp2, temp3, temp4;
  if((len mod 4)!=0 ) {
    return false;
  }
  for(var integer i:=0; i<len; i:=i+4) {
    temp1:=o[i];
    temp2:=o[i+1]
    temp3:=o[i+2]
    temp4:=o[i+3]
    o[i]:=temp4;
    o[i+1]:=temp3;
    o[i+2]:=temp2;
    o[i+3]:=temp1;
  }
  log("Changed octetstring:", o);
  return true;
}


//*****************************************************

function f_unichar2octAndReverse(
  in universal charstring u,
  in charstring encodingType) {

  log("unichar2oct( ", u,", ",encodingType,"):")
  var octetstring o := unichar2oct( u, encodingType );
  log(u);
  var universal charstring u2 := oct2unichar(o,encodingType);
  if( u== u2) {
    setverdict(pass, "successful conversion");
  } else {
    setverdict(fail, "unsuccessful concersion, the original UCS was:", u, " the encoding and decoding result was: ", u2);
  }

}

//*****************************************************
// unichar2oct checking functions 
//*****************************************************

//works if <
function f_charstring2utf16BE(in charstring cs) return octetstring {
  var octetstring os := c_BOM_UTF16BE;
  var integer len := lengthof(cs)
  for(var integer i :=0;i< len;i:=i+1){
    os := os & '00'O & char2oct(cs[i]);
  } 
  return os;
}

//works if <256*256
function f_ucharstring2utf16BE(in universal charstring cs) return octetstring {
  var octetstring os := c_BOM_UTF16BE;
  var integer len := lengthof(cs)
  for(var integer i :=0;i< len;i:=i+1){
    //os := os & '00'O & char2oct(cs[i]);
    os := os & int2oct(unichar2int(cs[i]),2);
  } 
  return os;
}


function f_charstring2utf32BE(in charstring cs) return octetstring {
  var octetstring os := c_BOM_UTF32BE;
  var integer len := lengthof(cs)
  for(var integer i :=0;i< len;i:=i+1){
    os := os & '000000'O & char2oct(cs[i]);
  } 
  return os;
}

function f_ucharstring2utf32BE(in universal charstring cs) return octetstring {
  var octetstring os := c_BOM_UTF32BE;
  var integer len := lengthof(cs)
  for(var integer i :=0;i< len;i:=i+1){
    //os := os & '000000'O & char2oct(cs[i]);
    os := os & int2oct(unichar2int(cs[i]),4);
  } 
  return os;
}

function f_unichar2oct_positivetest(
  in universal charstring u,
  in charstring encodingType,
  in octetstring expectedResult) { 
  log("unichar2oct( ", u,", ",encodingType,"):")
  @try {
    var octetstring o := unichar2oct( u, encodingType );
    if(o==expectedResult){
      setverdict(pass)
    } else {
      setverdict(fail, "expected result:", expectedResult, " received result:", o)
    }
  }
  @catch(err_str) { 
    setverdict(fail, "unichar2oct failed unexpectedly");
  }
}

function f_unichar2oct_negativetest(
  in universal charstring u,
  in charstring encodingType,
  in charstring expectedError) { 
  log("unichar2oct( ", u,", ",encodingType,"):")
  @try {
    var octetstring o := unichar2oct( u, encodingType );
  }
  @catch(err_str) {
    if(expectedError == "") 
    {
      setverdict(pass, "expected error, error message not checked:",err_str)
    } else {
      var template charstring expectedErrorTempl := pattern "*{expectedError}";
      if(match(err_str, expectedErrorTempl)) {
        setverdict(pass, "unichar2oct() failed as expected with msg: ", err_str)
      } else {
        setverdict(fail,"unichar2oct() failed as expected but with wrong msg: ", err_str)
      }
    }
  }

}


}