Titan Core Initial Contribution
[deliverable/titan.core.git] / regression_test / predefFunction / int_to_SW.ttcn
1 /******************************************************************************
2 * Copyright (c) 2000-2014 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 ******************************************************************************/
8 module int_to_SW { //^In TTCN-3 module `int_to_SW'://
9
10 type component PDTestComponent {};
11
12
13 /*--- INT2BIT --------------------------------------------------*/
14
15 const bitstring i2bcon := '0000011111000001111100001111'B
16 const bitstring i2bcon1 := int2bit(0,10);
17 const bitstring i2bcon2 := int2bit(0,0);
18 const bitstring i2bcon3 := int2bit(1,1)
19 const bitstring i2bcon4 := int2bit(255,8)
20 const bitstring i2bcon5 := int2bit(bit2int(i2bcon),lengthof(i2bcon))
21 const bitstring i2bcon6 := not4b int2bit(bit2int(not4b i2bcon),lengthof(i2bcon))
22 const bitstring i2bcon7 := int2bit(bit2int(substr(i2bcon,0,lengthof(i2bcon)/2)),lengthof(i2bcon)/2)
23 const bitstring i2bcon8 := int2bit(bit2int(substr(i2bcon,lengthof(i2bcon)/2,lengthof(i2bcon)/2)),lengthof(i2bcon)/2)
24 const integer i1 := 12345678910111213141516
25 const bitstring bs1 := '00000000000000000010100111010100001010110110010101101000100100110010100010111011111000001100'B
26
27 testcase int_to_bit() runs on PDTestComponent{ //In testcase definition//
28 if ((i2bcon1 == '0000000000'B)
29 and (i2bcon1 == int2bit(0,10)))
30 {setverdict(pass);}
31 else {setverdict(fail, __LINE__);} //^In else statement// \
32 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
33 if ((i2bcon2 == ''B)and (i2bcon2 == int2bit(0,0)))
34 {setverdict(pass);}
35 else {setverdict(fail, __LINE__);} //^In else statement// \
36 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
37 if ((i2bcon3 == '1'B)and (i2bcon3 == int2bit(1,1)))
38 {setverdict(pass);}
39 else {setverdict(fail, __LINE__);} //^In else statement// \
40 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
41 if ((i2bcon4 == '11111111'B)and (i2bcon4 == int2bit(255,8)))
42 {setverdict(pass);}
43 else {setverdict(fail, __LINE__);} //^In else statement// \
44 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
45 if ((i2bcon5 == i2bcon)and (i2bcon5 == int2bit(bit2int(i2bcon),lengthof(i2bcon))))
46 {setverdict(pass);}
47 else {setverdict(fail, __LINE__);} //^In else statement// \
48 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
49 if ((i2bcon6 == i2bcon)and (i2bcon5 == not4b int2bit(bit2int(not4b i2bcon),lengthof(i2bcon))))
50 {setverdict(pass);}
51 else {setverdict(fail, __LINE__);} //^In else statement// \
52 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
53 if (i2bcon == (i2bcon7 & i2bcon8))
54 {setverdict(pass);}
55 else {setverdict(fail, __LINE__);} //^In else statement// \
56 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
57 if (int2bit(i1, 92) == bs1)
58 {setverdict(pass);}
59 else {setverdict(fail, __LINE__);} //^In else statement// \
60 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
61 if (int2bit(12345678910111213141516, 92) == '00000000000000000010100111010100001010110110010101101000100100110010100010111011111000001100'B)
62 {setverdict(pass);}
63 else {setverdict(fail, __LINE__);} //^In else statement// \
64 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
65 if (int2bit(12345678910111213141516, 92) == bs1)
66 {setverdict(pass);}
67 else {setverdict(fail, __LINE__);} //^In else statement// \
68 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
69 if (int2bit(12345678910111213141516, 75) == '010100111010100001010110110010101101000100100110010100010111011111000001100'B)
70 {setverdict(pass);}
71 else {setverdict(fail, __LINE__);} //^In else statement// \
72 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
73 }
74
75 /*--- INT2CHAR --------------------------------------------------*/
76
77 const integer i2cconi[3] := {0,1,2}
78
79 type record of integer i2crtype
80 const i2crtype i2cconii := {0,1,2}
81
82 const char i2ccon1 := int2char(8 mod 6) //^warning: Obsolete type `char' was substituted with `charstring'//
83 const char i2ccon2 := int2char(i2cconi[2]) //^warning: Obsolete type `char' was substituted with `charstring'//
84 const char i2ccon3 := int2char(sizeof(i2cconi)-1) //^warning: Obsolete type `char' was substituted with `charstring'//
85 const char i2ccon4 := int2char(sizeof(i2cconii)-1) //^warning: Obsolete type `char' was substituted with `charstring'//
86
87 testcase int_to_char() runs on PDTestComponent{ //In testcase definition//
88
89 if ((i2ccon1 == int2char(8 mod 6))
90 and (i2ccon1 == "\ 2"))
91 {setverdict(pass);}
92 else {setverdict(fail, __LINE__);} //^In else statement// \
93 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
94 if ((i2ccon2 == int2char(i2cconi[2]))
95 and (i2ccon2 == "\ 2"))
96 {setverdict(pass);}
97 else {setverdict(fail, __LINE__);} //^In else statement// \
98 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
99 if ((i2ccon3 == int2char(sizeof(i2cconi)-1))
100 and (i2ccon3 == "\ 2"))
101 {setverdict(pass);}
102 else {setverdict(fail, __LINE__);} //^In else statement// \
103 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
104 if ((i2ccon4 == int2char(sizeof(i2cconii)-1))
105 and (i2ccon4 == "\ 2"))
106 {setverdict(pass);}
107 else {setverdict(fail, __LINE__);} //^In else statement// \
108 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
109 }
110
111 /*--- INT2UNICHAR --------------------------------------------------*/
112
113
114
115 const universal char i2uccon1 := int2unichar(1) //^warning: Obsolete type `universal char' was substituted with `universal charstring'//
116 const universal char i2uccon2 := int2unichar(256) //^warning: Obsolete type `universal char' was substituted with `universal charstring'//
117 const universal char i2uccon3 := int2unichar(65536) //^warning: Obsolete type `universal char' was substituted with `universal charstring'//
118 const universal char i2uccon4 := int2unichar(16777216) //^warning: Obsolete type `universal char' was substituted with `universal charstring'//
119 const universal char i2uccon5 := int2unichar(2147483647) //^warning: Obsolete type `universal char' was substituted with `universal charstring'//
120
121
122 testcase int_to_unichar() runs on PDTestComponent{ //In testcase definition//
123
124 //log (i2uccon1)
125 //log (i2uccon2)
126 //log (i2uccon3)
127 //log (i2uccon4)
128 //log (i2uccon5)
129
130 if ((i2uccon1 == int2unichar(1))
131 and (i2uccon1 == char(0, 0, 0, 1)))
132 {setverdict(pass);}
133 else {setverdict(fail, __LINE__);} //^In else statement// \
134 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
135 if ((i2uccon2 == int2unichar(256))
136 and (i2uccon2 == char(0, 0, 1, 0)))
137 {setverdict(pass);}
138 else {setverdict(fail, __LINE__);} //^In else statement// \
139 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
140 if ((i2uccon3 == int2unichar(65536))
141 and (i2uccon3 == char(0, 1, 0, 0)))
142 {setverdict(pass);}
143 else {setverdict(fail, __LINE__);} //^In else statement// \
144 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
145 if ((i2uccon4 == int2unichar(16777216))
146 and (i2uccon4 == char(1, 0, 0, 0)))
147 {setverdict(pass);}
148 else {setverdict(fail, __LINE__);} //^In else statement// \
149 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
150 if ((i2uccon5 == int2unichar(2147483647))
151 and (i2uccon5 == char(127, 255, 255, 255)))
152 {setverdict(pass);}
153 else {setverdict(fail, __LINE__);} //^In else statement// \
154 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
155
156 }
157
158
159 /*--- INT2FLOAT --------------------------------------------------*/
160
161
162 const integer i2fconi[3] := {0,1,2}
163
164 type record of integer i2frtype;
165 const i2frtype i2fconii := {0}
166
167 type float i2fflo (-1.0 .. 6.0)
168
169 const float i2fcon1 := int2float(3/2)
170 const float i2fcon2 := int2float(-3)
171 const float i2fcon3 := int2float(lengthof(""))
172 const float i2fcon4 := int2float(i2fconi[0])
173 const float i2fcon5 := int2float(i2fconii[0])
174 const float i2fcon8 := int2float(2147483648)
175 const float i2fcon9 := int2float(214748364800)
176 const float i2fcon10 := int2float(4294967296)
177
178 const i2fflo i2fcon6 := int2float(20/3)
179 const i2fflo i2fcon7 := int2float(8 mod 6)
180
181 testcase int_to_float() runs on PDTestComponent{ //In testcase definition//
182
183 if ((i2fcon1 == 1.0)
184 and (i2fcon1 == int2float(3/2)))
185 {setverdict(pass);}
186 else {setverdict(fail, __LINE__);} //^In else statement// \
187 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
188 if ((i2fcon2 == -3.0)
189 and (i2fcon2 == -3E0))
190 {setverdict(pass);}
191 else {setverdict(fail, __LINE__);} //^In else statement// \
192 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
193 if ((i2fcon3 == 0.0)
194 and (i2fcon3 == int2float(lengthof(""))))
195 {setverdict(pass);}
196 else {setverdict(fail, __LINE__);} //^In else statement// \
197 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
198 if ((i2fcon4 == 0.0)
199 and (i2fcon4 == int2float(i2fconi[0])))
200 {setverdict(pass);}
201 else {setverdict(fail, __LINE__);} //^In else statement// \
202 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
203 if ((i2fcon5 == 0.0)
204 and (i2fcon5 == int2float(i2fconii[0])))
205 {setverdict(pass);}
206 else {setverdict(fail, __LINE__);} //^In else statement// \
207 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
208 if ((i2fcon6 == 6.0)
209 and (i2fcon6 == int2float(20/3)))
210 {setverdict(pass);}
211 else {setverdict(fail, __LINE__);} //^In else statement// \
212 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
213 if ((i2fcon7 == 2.0)
214 and (i2fcon7 == int2float(8 mod 6)))
215 {setverdict(pass);}
216 else {setverdict(fail, __LINE__);} //^In else statement// \
217 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
218 if ((i2fcon8 == 2147483648.0)
219 and (i2fcon8 == int2float(2147483648)))
220 {setverdict(pass);}
221 else {setverdict(fail, __LINE__);} //^In else statement// \
222 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
223 if ((i2fcon9 == 214748364800.0)
224 and (i2fcon9 == int2float(214748364800)))
225 {setverdict(pass);}
226 else {setverdict(fail, __LINE__);} //^In else statement// \
227 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
228 if ((i2fcon10 == 4294967296.0)
229 and (i2fcon10 == int2float(4294967296)))
230 {setverdict(pass);}
231 else {setverdict(fail, __LINE__);} //^In else statement// \
232 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
233 }
234
235 /*--- INT2HEX --------------------------------------------------*/
236
237 const hexstring i2hcon := '0123456'H
238 const hexstring i2hcon1 := int2hex(0,10)
239 const hexstring i2hcon2 := int2hex(0,0)
240 const hexstring i2hcon3 := int2hex(15,1)
241 const hexstring i2hcon4 := int2hex(hex2int(i2hcon),lengthof(i2hcon))
242 const integer i2hconi := hex2int(i2hcon)
243 const hexstring hs1 := '000000000000029D42B65689328BBE0C'H
244
245 testcase int_to_hex() runs on PDTestComponent{ //In testcase definition//
246
247 if ((i2hcon1 == '0000000000'H)
248 and (i2hcon1 == int2hex(0,10)))
249 {setverdict(pass);}
250 else {setverdict(fail, __LINE__);} //^In else statement// \
251 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
252 if ((i2hcon2 == ''H)
253 and (i2hcon2 == int2hex(0,0)))
254 {setverdict(pass);}
255 else {setverdict(fail, __LINE__);} //^In else statement// \
256 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
257 if ((i2hcon3 == 'F'H)
258 and (i2hcon3 == int2hex(15,1)))
259 {setverdict(pass);}
260 else {setverdict(fail, __LINE__);} //^In else statement// \
261 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
262 if ((i2hcon4 == i2hcon)
263 and (i2hcon4 == int2hex(hex2int(i2hcon),lengthof(i2hcon))))
264 {setverdict(pass);}
265 else {setverdict(fail, __LINE__);} //^In else statement// \
266 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
267 if (int2hex(i1, 32) == hs1)
268 { setverdict(pass) }
269 else { setverdict(fail, __LINE__) } //^In else statement// \
270 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
271 if (int2hex(12345678910111213141516, 32) == '000000000000029D42B65689328BBE0C'H)
272 { setverdict(pass) }
273 else { setverdict(fail, __LINE__) } //^In else statement// \
274 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
275 if (int2hex(12345678910111213141516, 32) == hs1)
276 { setverdict(pass) }
277 else { setverdict(fail, __LINE__) } //^In else statement// \
278 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
279 if (int2hex(12345678910111213141516, 20) == '029D42B65689328BBE0C'H)
280 { setverdict(pass) }
281 else { setverdict(fail, __LINE__) } //^In else statement// \
282 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
283 }
284
285 /*--- INT2OCT --------------------------------------------------*/
286
287 const octetstring i2ocon := '12345678'O
288 const octetstring i2ocon1 := int2oct(0,10)
289 const octetstring i2ocon2 := int2oct(0,0)
290 const octetstring i2ocon3 := int2oct(15,1)
291 const octetstring i2ocon4 := int2oct(oct2int(i2ocon),lengthof(i2ocon))
292 const octetstring i2ocon5 := int2oct(33,8);
293 const integer i2oconi := oct2int(i2ocon)
294 const octetstring os1 := '00000000000000000000000000000000000000000000029D42B65689328BBE0C'O
295
296 testcase int_to_oct() runs on PDTestComponent{ //In testcase definition//
297 if ((i2ocon1 == '00000000000000000000'O)
298 and (i2ocon1 == int2oct(0,10)))
299 {setverdict(pass);}
300 else {setverdict(fail, __LINE__);} //^In else statement// \
301 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
302 if ((i2ocon2 == ''O)and (i2ocon2 == int2oct(0,0)))
303 {setverdict(pass);}
304 else {setverdict(fail, __LINE__);} //^In else statement// \
305 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
306 if ((i2ocon3 == '0F'O)
307 and (i2ocon3 == int2oct(15,1)))
308 {setverdict(pass);}
309 else {setverdict(fail, __LINE__);} //^In else statement// \
310 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
311 if (i2ocon5 == '0000000000000021'O)
312 {setverdict(pass);}
313 else {setverdict(fail, __LINE__);} //^In else statement// \
314 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
315 if ((i2ocon4 == i2ocon)
316 and (i2ocon4 == int2oct(oct2int(i2ocon),lengthof(i2ocon))))
317 {setverdict(pass);}
318 else {setverdict(fail, __LINE__);} //^In else statement// \
319 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
320 if (int2oct(i1, 32) == os1)
321 { setverdict(pass) }
322 else { setverdict(fail, __LINE__) } //^In else statement// \
323 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
324 if (int2oct(12345678910111213141516, 32) == '00000000000000000000000000000000000000000000029D42B65689328BBE0C'O)
325 { setverdict(pass) }
326 else { setverdict(fail, __LINE__) } //^In else statement// \
327 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
328 if (int2oct(12345678910111213141516, 32) == os1)
329 { setverdict(pass) }
330 else { setverdict(fail, __LINE__) } //^In else statement// \
331 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
332 if (int2oct(12345678910111213141516, 10) == '029D42B65689328BBE0C'O)
333 { setverdict(pass) }
334 else { setverdict(fail, __LINE__) } //^In else statement// \
335 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
336 }
337
338 /*--- INT2STR --------------------------------------------------*/
339
340 const charstring i2scon := "1234567890"
341 const charstring i2scon1 := int2str(0)
342 const charstring i2scon2 := int2str(-1)
343 const charstring i2scon3 := int2str(16 mod 3)
344 const charstring i2scon4 := int2str(16 rem 3)
345 const charstring i2scon5 := int2str(lengthof(i2scon))
346
347 const integer i2sconi := str2int(i2scon)
348
349 const charstring i2scon6 := int2str(i2sconi)
350 const charstring i2scon7 := "1234567891011121314151617181920"
351 const charstring i2scon8 := "-1234567891011121314151617181920" // Negative values.
352 const integer i2sconi1 := str2int(i2scon7)
353 const integer i2sconi2 := str2int(i2scon8)
354
355 testcase int_to_str() runs on PDTestComponent{ //In testcase definition//
356
357 if ((i2scon1 == "0")
358 and (i2scon1 == int2str(0)))
359 {setverdict(pass);}
360 else {setverdict(fail, __LINE__);} //^In else statement// \
361 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
362 if ((i2scon2 == "-1")
363 and (i2scon2 == int2str(-1)))
364 {setverdict(pass);}
365 else {setverdict(fail, __LINE__);} //^In else statement// \
366 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
367 if ((i2scon3 == "1")
368 and (i2scon3 == int2str(16 mod 3)))
369 {setverdict(pass);}
370 else {setverdict(fail, __LINE__);} //^In else statement// \
371 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
372 if ((i2scon4 == "1")
373 and (i2scon4 == int2str(16 rem 3)))
374 {setverdict(pass);}
375 else {setverdict(fail, __LINE__);} //^In else statement// \
376 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
377 if ((i2scon5 == "10")
378 and (i2scon5 == int2str(lengthof(i2scon))))
379 {setverdict(pass);}
380 else {setverdict(fail, __LINE__);} //^In else statement// \
381 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
382 if ((i2scon6 == i2scon)
383 and (i2scon6 == int2str(i2sconi)))
384 {setverdict(pass);}
385 else {setverdict(fail, __LINE__);} //^In else statement// \
386 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
387 // Compile time evaluation. (Positive/negative.)
388 if ((i2scon7 == int2str(1234567891011121314151617181920)
389 and (int2str(1234567891011121314151617181920) == i2scon7)))
390 {setverdict(pass);}
391 else {setverdict(fail, __LINE__);} //^In else statement// \
392 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
393 if ((int2str(1234567891011121314151617181930 - 10) == i2scon7)
394 and (i2scon7 == int2str(1234567891011121314151617181930 - 10)))
395 {setverdict(pass);}
396 else {setverdict(fail, __LINE__);} //^In else statement// \
397 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
398 if ((i2scon7 == int2str(i2sconi1)
399 and (int2str(i2sconi1) == i2scon7)))
400 {setverdict(pass);}
401 else {setverdict(fail, __LINE__);} //^In else statement// \
402 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
403 if ((int2str(i2sconi1 + 10 - 10) == i2scon7)
404 and (i2scon7 == int2str(i2sconi1 + 10 - 10)))
405 {setverdict(pass);}
406 else {setverdict(fail, __LINE__);} //^In else statement// \
407 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
408 if ((i2scon8 == int2str(-1234567891011121314151617181920)
409 and (int2str(1234567891011121314151617181920) == i2scon7)))
410 {setverdict(pass);}
411 else {setverdict(fail, __LINE__);} //^In else statement// \
412 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
413 if ((int2str(-1234567891011121314151617181930 + 10) == i2scon8)
414 and (i2scon8 == int2str(-1234567891011121314151617181930 + 10)))
415 {setverdict(pass);}
416 else {setverdict(fail, __LINE__);} //^In else statement// \
417 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
418 if ((i2scon8 == int2str(i2sconi2)
419 and (int2str(i2sconi2) == i2scon8)))
420 {setverdict(pass);}
421 else {setverdict(fail, __LINE__);} //^In else statement// \
422 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
423 if ((int2str(i2sconi2 + 10 - 10) == i2scon8)
424 and (i2scon8 == int2str(i2sconi2 + 10 - 10)))
425 {setverdict(pass);}
426 else {setverdict(fail, __LINE__);} //^In else statement// \
427 //^warning\: Control never reaches this code because of previous effective condition\(s\)//
428 }
429
430
431
432
433 control {
434 execute (int_to_bit());
435 execute (int_to_char());
436 execute (int_to_unichar());
437
438 execute (int_to_float());
439 execute (int_to_hex());
440 execute (int_to_oct());
441 execute (int_to_str());
442 }
443
444 }
This page took 0.042502 seconds and 5 git commands to generate.