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 str_to_OK { //^In TTCN-3 module `str_to_OK'://
10 type component PDTestComponent {};
13 /*--- STR2BIT --------------------------------------------------*/
15 const bitstring s2bcon := str2bit("")
16 modulepar bitstring s2bpar := s2bcon
17 modulepar bitstring s2bpar1 := str2bit("000000" & "" & "111111")
18 const bitstring s2bcon2 := str2bit(substr("000000111111",0,6) & "" & substr("000000111111",6,6))
19 modulepar bitstring s2bpar2 := str2bit(substr("000000111111",0,6) & "" & substr("000000111111",6,6))
20 modulepar bitstring s2bpar3 := str2bit(("000000" <@ lengthof(s2bcon2)/2) & "" & ("111111" @> lengthof(s2bcon2)/2))
22 testcase str_to_bit() runs on PDTestComponent{
25 if ((s2bpar == str2bit(""))
28 else {setverdict(fail, __LINE__);}
30 if ((s2bpar1 == str2bit("000000" & "" & "111111"))
31 and (s2bpar1 == '000000111111'B))
33 else {setverdict(fail, __LINE__);}
35 if ((s2bpar2 == str2bit(substr("000000111111",0,6) & "" & substr("000000111111",6,6)))
36 and (s2bpar2 == '000000111111'B))
38 else {setverdict(fail, __LINE__);}
40 if ((s2bpar3 == str2bit(("000000" <@ lengthof(s2bpar2)/2) & "" & ("111111" @> lengthof(s2bpar2)/2)))
41 and (s2bpar3 == '000000111111'B))
43 else {setverdict(fail, __LINE__);}
47 var charstring cc := ""
48 var bitstring bb := ''B
50 for (j:=0; j<64; j:=j+1) {
51 cc := cc & bit2str(int2bit(j,j))
52 bb := bb & int2bit(j,j)
53 if (bb == str2bit(cc))
55 else {setverdict(fail, __LINE__);}
60 /*--- STR2FLOAT --------------------------------------------------*/
62 //const float s2fcon := str2float("")
63 const float s2fcon := str2float("0.0")
64 modulepar float s2fpar := str2float("0.0")
65 modulepar float s2fpar1 := str2float("12345678901.0")
66 modulepar float s2fpar2 := str2float("000000000000" & "12345678901.0") //In module parameter definition// \
67 //In default value// //In the operand of operation `str2float\(\)'// \
68 //warning: Leading zero digit was detected and ignored in the mantissa of the operand of operation `str2float\(\)'//
69 modulepar float s2fpar3 := str2float("-12" & "345678901.0")
70 modulepar float s2fpar4 := str2float("1.234E3")
71 //modulepar float s2fpar5 := str2float("1.234-3")
72 modulepar float s2fpar5 := str2float("1.234")
73 //modulepar float s2fpar6 := str2float("1,234E3")
74 modulepar float s2fpar6 := str2float("1.0")
75 //modulepar float s2fpar7 := str2float("--234")
78 modulepar float s2fpar7 := str2float("1");
79 modulepar float s2fpar7m:= str2float("-1");
80 modulepar float s2fpar8m:= str2float("-1.");
81 modulepar float s2fpar8 := str2float("1.");
82 modulepar float s2fpar9 := str2float("+001"); //In module parameter definition// \
83 //In default value// //In the operand of operation `str2float\(\)'// \
84 //warning: Leading zero digit was detected and ignored in the mantissa of the operand of operation `str2float\(\)'//
85 modulepar float s2fpar10:= str2float("+001."); //In module parameter definition// \
86 //In default value// //In the operand of operation `str2float\(\)'// \
87 //warning: Leading zero digit was detected and ignored in the mantissa of the operand of operation `str2float\(\)'//
88 modulepar float s2fpar11:= str2float("-0");
89 modulepar float s2fpar12:= str2float("-0.");
90 modulepar float s2fpar13:= str2float("-0.0");
94 // modulepar prevents constant folding
95 modulepar charstring s2fmp_str := "0.0"
96 modulepar charstring s2fmp1_str := "12345678901.0"
97 modulepar charstring s2fmp2_str := "000000000000" & "12345678901.0"
98 modulepar charstring s2fmp3_str := "-12" & "345678901.0"
99 modulepar charstring s2fmp4_str := "1.234E3"
100 //modulepar charstring s2fmp5_str := "1.234-3"
101 modulepar charstring s2fmp5_str := "1.234"
102 //modulepar charstring s2fmp6_str := "1,234E3"
103 modulepar charstring s2fmp6_str := "1.0"
104 //modulepar charstring s2fmp7_str := "--234"
107 modulepar charstring s2fmp7_str := "1";
108 modulepar charstring s2fmp7m_str:= "-1";
109 modulepar charstring s2fmp8m_str:= "-1.";
110 modulepar charstring s2fmp8_str := "1.";
111 modulepar charstring s2fmp9_str := "+001";
112 modulepar charstring s2fmp10_str:= "+001.";
113 modulepar charstring s2fmp11_str:= "-0";
114 modulepar charstring s2fmp12_str:= "-0.";
115 modulepar charstring s2fmp13_str:= "-0.0";
118 //modulepar float s2fmp := str2float("")
119 modulepar float s2fmp := str2float("0.0")
120 modulepar float s2fmp1 := str2float("12345678901.0")
121 modulepar float s2fmp2 := str2float("000000000000" & "12345678901.0") //In module parameter definition// \
122 //In default value// //In the operand of operation `str2float\(\)'// \
123 //warning: Leading zero digit was detected and ignored in the mantissa of the operand of operation `str2float\(\)'//
124 modulepar float s2fmp3 := str2float("-12" & "345678901.0")
125 modulepar float s2fmp4 := str2float("1.234E3")
126 //modulepar float s2fmp5 := str2float("1.234-3")
127 modulepar float s2fmp5 := str2float("1.234")
128 //modulepar float s2fmp6 := str2float("1,234E3")
129 modulepar float s2fmp6 := str2float("1.0")
130 //modulepar float s2fmp7 := str2float("--234")
133 modulepar float s2fmp7 := str2float("1");
134 modulepar float s2fmp7m:= str2float("-1");
135 modulepar float s2fmp8m:= str2float("-1.");
136 modulepar float s2fmp8 := str2float("1.");
137 modulepar float s2fmp9 := str2float("+001"); //In module parameter definition// \
138 //In default value// //In the operand of operation `str2float\(\)'// \
139 //warning: Leading zero digit was detected and ignored in the mantissa of the operand of operation `str2float\(\)'//
140 modulepar float s2fmp10:= str2float("+001."); //In module parameter definition// \
141 //In default value// //In the operand of operation `str2float\(\)'// \
142 //warning: Leading zero digit was detected and ignored in the mantissa of the operand of operation `str2float\(\)'//
143 modulepar float s2fmp11:= str2float("-0");
144 modulepar float s2fmp12:= str2float("-0.");
145 modulepar float s2fmp13:= str2float("-0.0");
149 testcase str_to_float() runs on PDTestComponent{ //In testcase definition//
152 if ((s2fpar == str2float("0.0"))
155 else {setverdict(fail, __LINE__);}
157 if ((s2fpar1 == str2float("12345678901.0"))
158 and (s2fpar1 == 12345678901.0))
160 else {setverdict(fail, __LINE__);}
162 if ((s2fpar2 == str2float("000000000000" & "12345678901.0")) //In if statement// \
163 //In the left operand of operation `and'// \
164 //In the right operand of operation `=='// \
165 //In the operand of operation `str2float\(\)'// \
166 //warning: Leading zero digit was detected and ignored in the mantissa of the operand of operation `str2float\(\)'//
167 and (s2fpar2 == 12345678901.0))
169 else {setverdict(fail, __LINE__);}
171 if ((s2fpar3 == str2float("-12" & "345678901.0"))
172 and (s2fpar3 == -12345678901.0))
174 else {setverdict(fail, __LINE__);}
176 if ((s2fpar4 == str2float("1.234E3"))
177 and (s2fpar4 == 1234.0))
179 else {setverdict(fail, __LINE__);}
181 if ((s2fpar5 == str2float("1.234"))
182 and (s2fpar5 == 1.234))
184 else {setverdict(fail, __LINE__);}
186 if ((s2fpar6 == str2float("1.0"))
187 and (s2fpar6 == 1.0))
189 else {setverdict(fail, __LINE__);}
191 if ((s2fpar7 == str2float("1" ))
192 and (s2fpar7 == 1.0))
194 else {setverdict(fail, __LINE__);}
196 if ((s2fpar7m== str2float("-1" ))
197 and (s2fpar7m==-1.0))
199 else {setverdict(fail, __LINE__);}
201 if ((s2fpar8m== str2float("-1." ))
202 and (s2fpar8m==-1.0))
204 else {setverdict(fail, __LINE__);}
206 if ((s2fpar8 == str2float("1." ))
207 and (s2fpar8 == 1.0))
209 else {setverdict(fail, __LINE__);}
211 if ((s2fpar9 == str2float("+001" )) //In if statement// \
212 //In the left operand of operation `and'// \
213 //In the right operand of operation `=='// \
214 //In the operand of operation `str2float\(\)'// \
215 //warning: Leading zero digit was detected and ignored in the mantissa of the operand of operation `str2float\(\)'//
216 and (s2fpar9 == 1.0))
218 else {setverdict(fail, __LINE__);}
220 if ((s2fpar10== str2float("+001.")) //In if statement// \
221 //In the left operand of operation `and'// \
222 //In the right operand of operation `=='// \
223 //In the operand of operation `str2float\(\)'// \
224 //warning: Leading zero digit was detected and ignored in the mantissa of the operand of operation `str2float\(\)'//
225 and (s2fpar10== 1.0))
227 else {setverdict(fail, __LINE__);}
229 if ((s2fpar11== str2float("-0" ))
230 and (s2fpar11==-0.0))
232 else {setverdict(fail, __LINE__);}
234 if ((s2fpar12== str2float("-0." ))
235 and (s2fpar12== -0.0))
237 else {setverdict(fail, __LINE__);}
239 if ((s2fpar13== str2float("-0.0" ))
240 and (s2fpar13== -0.0))
242 else {setverdict(fail, __LINE__);}
244 if ((s2fmp == str2float(s2fmp_str))
247 else {setverdict(fail, __LINE__);}
249 if ((s2fmp1 == str2float(s2fmp1_str))
250 and (s2fmp1 == 12345678901.0))
252 else {setverdict(fail, __LINE__);}
254 if ((s2fmp2 == str2float("000000000000" & "12345678901.0")) //In if statement// \
255 //In the left operand of operation `and'// \
256 //In the right operand of operation `=='// \
257 //In the operand of operation `str2float\(\)'// \
258 //warning: Leading zero digit was detected and ignored in the mantissa of the operand of operation `str2float\(\)'//
259 and (s2fmp2 == 12345678901.0))
261 else {setverdict(fail, __LINE__);}
263 if ((s2fmp3 == str2float("-12" & "345678901.0"))
264 and (s2fmp3 == -12345678901.0))
266 else {setverdict(fail, __LINE__);}
268 if ((s2fmp4 == str2float(s2fmp4_str))
269 and (s2fmp4 == 1234.0))
271 else {setverdict(fail, __LINE__);}
273 if ((s2fmp5 == str2float(s2fmp5_str))
274 and (s2fmp5 == 1.234))
276 else {setverdict(fail, __LINE__);}
278 if ((s2fmp6 == str2float(s2fmp6_str))
281 else {setverdict(fail, __LINE__);}
283 if ((s2fmp7 == str2float(s2fmp7_str))
286 else {setverdict(fail, __LINE__);}
288 if ((s2fmp7m == str2float(s2fmp7m_str))
289 and (s2fmp7m ==-1.0))
291 else {setverdict(fail, __LINE__);}
293 if ((s2fmp8m == str2float(s2fmp8m_str))
294 and (s2fmp8m ==-1.0))
296 else {setverdict(fail, __LINE__);}
298 if ((s2fmp8 == str2float(s2fmp8_str))
301 else {setverdict(fail, __LINE__);}
303 if ((s2fmp9 == str2float(s2fmp9_str))
306 else {setverdict(fail, __LINE__);}
308 if ((s2fmp10 == str2float(s2fmp10_str))
309 and (s2fmp10 == 1.0))
311 else {setverdict(fail, __LINE__);}
313 if ((s2fmp11 == str2float(s2fmp11_str))
314 and (s2fmp11 ==-0.0))
316 else {setverdict(fail, __LINE__);}
318 if ((s2fmp12 == str2float(s2fmp12_str))
319 and (s2fmp12 == -0.0))
321 else {setverdict(fail, __LINE__);}
323 if ((s2fmp13 == str2float(s2fmp13_str))
324 and (s2fmp13 == -0.0))
326 else {setverdict(fail, __LINE__);}
330 /*--- STR2HEX --------------------------------------------------*/
332 const hexstring s2hcon := str2hex("")
333 modulepar hexstring s2hpar := s2hcon
334 modulepar hexstring s2hpar1 := str2hex("000000" & "" & "111111")
335 const hexstring s2hcon2 := str2hex(substr("000000111111",0,6) & "" & substr("000000111111",6,6))
336 modulepar hexstring s2hpar2 := s2hcon2
337 modulepar hexstring s2hpar3 := str2hex(("000000" <@ lengthof(s2hcon2)/2) & "" & ("111111" @> lengthof(s2hcon2)/2))
339 testcase str_to_hex() runs on PDTestComponent{
342 if ((s2hpar == str2hex(""))
345 else {setverdict(fail, __LINE__);}
347 if ((s2hpar1 == str2hex("000000" & "" & "111111"))
348 and (s2hpar1 == '000000111111'H))
350 else {setverdict(fail, __LINE__);}
352 if ((s2hpar2 == str2hex(substr("000000111111",0,6) & "" & substr("000000111111",6,6)))
353 and (s2hpar2 == '000000111111'H))
355 else {setverdict(fail, __LINE__);}
357 if ((s2hpar3 == str2hex(("000000" <@ lengthof(s2hpar2)/2) & "" & ("111111" @> lengthof(s2hpar2)/2)))
358 and (s2hpar3 == '000000111111'H))
360 else {setverdict(fail, __LINE__);}
364 var charstring cc := ""
365 var hexstring hh := ''H
367 for (j:=0; j<32; j:=j+1) {
368 cc := cc & hex2str(int2hex(j,j))
369 hh := hh & int2hex(j,j)
370 if (hh == str2hex(cc))
372 else {setverdict(fail, __LINE__);}
377 /*--- STR2INT --------------------------------------------------*/
379 const integer s2icon := str2int("0")
380 modulepar integer s2ipar := s2icon
381 modulepar integer s2ipar1 := str2int("" & "1234567890")
382 modulepar integer s2ipar2 := str2int("12" & "34567890")
383 modulepar integer s2ipar3 := str2int("0000000000000000000000" & "1234567890") //In module parameter definition// \
384 //In default value// //In the operand of operation `str2int\(\)'// \
385 //warning: Leading zero digit was detected and ignored in the operand of operation `str2int\(\)'//
386 modulepar integer s2ipar4 := str2int("-12" & "34567890")
387 //modulepar integer s2ipar5 := str2int("12ap")
388 modulepar integer s2ipar5 := str2int("12")
389 //modulepar integer s2ipar6 := str2int("ap")
390 modulepar integer s2ipar6 := str2int("1234567891011121314151617181920")
391 modulepar integer s2ipar7 := str2int("-1234567891011121314151617181920")
392 modulepar integer s2ipar8 := str2int("+1");
393 modulepar integer s2ipar9 := str2int("01"); //In module parameter definition// \
394 //In default value// //In the operand of operation `str2int\(\)'// \
395 //warning: Leading zero digit was detected and ignored in the operand of operation `str2int\(\)'//
396 modulepar integer s2ipar10 := str2int("+01"); //In module parameter definition// \
397 //In default value// //In the operand of operation `str2int\(\)'// \
398 //warning: Leading zero digit was detected and ignored in the operand of operation `str2int\(\)'//
399 modulepar integer s2ipar11 := str2int("-01"); //In module parameter definition// \
400 //In default value// //In the operand of operation `str2int\(\)'// \
401 //warning: Leading zero digit was detected and ignored in the operand of operation `str2int\(\)'//
403 testcase str_to_int() runs on PDTestComponent{ //In testcase definition//
404 var charstring vv := "1234567891011121314151617181920"
405 var charstring vv1 := "-1234567891011121314151617181920"
406 var integer ii := str2int("1234567891011121314151617181920")
407 var integer ii1 := str2int("-1234567891011121314151617181920")
409 if ((s2ipar == str2int("0"))
412 else {setverdict(fail, __LINE__);}
413 if ((s2ipar8 == str2int("+1"))
416 else {setverdict(fail, __LINE__);}
417 if ((s2ipar9 == str2int("01")) //In if statement// \
418 //In the left operand of operation `and'// \
419 //In the right operand of operation `=='// \
420 //In the operand of operation `str2int\(\)'// \
421 //warning: Leading zero digit was detected and ignored in the operand of operation `str2int\(\)'//
424 else {setverdict(fail, __LINE__);}
425 if ((s2ipar10 == str2int("+01")) //In if statement// \
426 //In the left operand of operation `and'// \
427 //In the right operand of operation `=='// \
428 //In the operand of operation `str2int\(\)'// \
429 //warning: Leading zero digit was detected and ignored in the operand of operation `str2int\(\)'//
432 else {setverdict(fail, __LINE__);}
433 if ((s2ipar11 == str2int("-01")) //In if statement// \
434 //In the left operand of operation `and'// \
435 //In the right operand of operation `=='// \
436 //In the operand of operation `str2int\(\)'// \
437 //warning: Leading zero digit was detected and ignored in the operand of operation `str2int\(\)'//
438 and (s2ipar11 == -1))
440 else {setverdict(fail, __LINE__);}
441 if ((s2ipar1 == str2int("" & "1234567890"))
442 and (s2ipar1 == 1234567890))
444 else {setverdict(fail, __LINE__);}
445 if ((s2ipar2 == str2int("12" & "34567890"))
446 and (s2ipar2 == 1234567890))
448 else {setverdict(fail, __LINE__);}
449 if ((s2ipar3 == str2int("00000000000000000000000" & "1234567890")) //In if statement// \
450 //In the left operand of operation `and'// \
451 //In the right operand of operation `=='// \
452 //In the operand of operation `str2int\(\)'// \
453 //warning: Leading zero digit was detected and ignored in the operand of operation `str2int\(\)'//
454 and (s2ipar3 == 1234567890))
456 else {setverdict(fail, __LINE__);}
457 if ((s2ipar4 == str2int("-12" & "34567890"))
458 and (s2ipar4 == -1234567890))
460 else {setverdict(fail, __LINE__);}
461 if ((s2ipar5 == str2int("12"))
464 else {setverdict(fail, __LINE__);}
466 if ((s2ipar6 == str2int("ap"))
469 else {setverdict(fail, __LINE__);}
471 // Compile time evaluation. (Positive/negative.)
472 if ((str2int("1234567891011121314151617181920") == s2ipar6)
473 and (s2ipar6 == str2int("1234567891011121314151617181920")))
475 else {setverdict(fail, __LINE__);}
476 if ((str2int("-1234567891011121314151617181920") == s2ipar7)
477 and (s2ipar7 == str2int("-1234567891011121314151617181920")))
479 else {setverdict(fail, __LINE__);}
481 if ((int2str(str2int("1234567891011121314151617181920")) == "1234567891011121314151617181920")
482 and ("1234567891011121314151617181920" == int2str(str2int("1234567891011121314151617181920"))))
484 else {setverdict(fail, __LINE__);}
485 if ((int2str(str2int("-1234567891011121314151617181920")) == "-1234567891011121314151617181920")
486 and ("-1234567891011121314151617181920" == int2str(str2int("-1234567891011121314151617181920"))))
488 else {setverdict(fail, __LINE__);}
490 if ((str2int("1234567891011121314151617181920") - 10 == s2ipar6 - 10)
491 and (s2ipar6 + 10 == str2int("1234567891011121314151617181920") + 10))
493 else {setverdict(fail, __LINE__);}
494 if ((str2int("-1234567891011121314151617181920") + 10 == s2ipar7 + 10)
495 and (s2ipar7 - 10 == str2int("-1234567891011121314151617181920") - 10))
497 else {setverdict(fail, __LINE__);}
498 // Run-time evaluation. (Positive/negative.)
499 if ((str2int(vv) == ii)
500 and (ii == str2int("1234567891011121314151617181920")))
502 else {setverdict(fail, __LINE__);}
503 if ((str2int("-1234567891011121314151617181920") == ii1)
504 and (ii1 == str2int(vv1)))
506 else {setverdict(fail, __LINE__);}
507 if ((int2str(str2int(vv)) == "1234567891011121314151617181920")
508 and ("1234567891011121314151617181920" == int2str(str2int(vv))))
510 else {setverdict(fail, __LINE__);}
511 if ((int2str(str2int(vv1)) == "-1234567891011121314151617181920")
512 and ("-1234567891011121314151617181920" == int2str(str2int(vv1))))
514 else {setverdict(fail, __LINE__);}
515 if ((str2int(vv) - 10 == ii - 10)
516 and (ii + 10 == str2int("1234567891011121314151617181920") + 10))
518 else {setverdict(fail, __LINE__);}
519 if ((str2int("-1234567891011121314151617181920") + 10 == ii1 + 10)
520 and (ii1 - 10 == str2int(vv1) - 10))
522 else {setverdict(fail, __LINE__);}
523 if ((str2int(vv) == -str2int(vv1))
524 and (str2int(vv1) == -str2int(vv)))
526 else {setverdict(fail, __LINE__);}
529 for (j:=1; j<10; j:=j+1) {
530 if (str2int(substr("0123456789",0,j+1)) == (str2int(substr("0123456789",0,j))*10 + j))
532 else {setverdict(fail, __LINE__);}
537 /*--- STR2OCT --------------------------------------------------*/
539 const octetstring s2ocon := str2oct("")
540 modulepar octetstring s2opar := s2ocon
541 modulepar octetstring s2opar1 := str2oct("000000" & "" & "111111")
542 const octetstring s2ocon2 := str2oct(substr("000000111111",0,6) & "" & substr("000000111111",6,6))
543 modulepar octetstring s2opar2 := s2ocon2
544 modulepar octetstring s2opar3 := str2oct(("000000" <@ lengthof(s2ocon2)/2) & "" & ("111111" @> lengthof(s2ocon2)/2))
546 testcase str_to_oct() runs on PDTestComponent{
549 if ((s2opar == str2oct(""))
552 else {setverdict(fail, __LINE__);}
554 if ((s2opar1 == str2oct("000000" & "" & "111111"))
555 and (s2opar1 == '000000111111'O))
557 else {setverdict(fail, __LINE__);}
559 if ((s2opar2 == str2oct(substr("000000111111",0,6) & "" & substr("000000111111",6,6)))
560 and (s2opar2 == '000000111111'O))
562 else {setverdict(fail, __LINE__);}
564 if ((s2opar3 == str2oct(("000000" <@ lengthof(s2opar2)/2) & "" & ("111111" @> lengthof(s2opar2)/2)))
565 and (s2opar3 == '000000111111'O))
567 else {setverdict(fail, __LINE__);}
571 var charstring cc := ""
572 var octetstring oo := ''O
574 for (j:=0; j<64; j:=j+1) {
575 cc := cc & oct2str(int2oct(j,j))
576 oo := oo & int2oct(j,j)
577 if (oo == str2oct(cc))
579 else {setverdict(fail, __LINE__);}
586 execute (str_to_bit());
587 execute (str_to_float());
588 execute (str_to_hex());
589 execute (str_to_int());
590 execute (str_to_oct());