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 ******************************************************************************/
10 type component PDTestComponent {};
13 /*--- INT2BIT --------------------------------------------------*/
15 const bitstring i2bcon := '0000011111000001111100001111'B
17 modulepar bitstring i2bpar := '0000011111000001111100001111'B
18 modulepar bitstring i2bpar1 := int2bit(0,10);
19 modulepar bitstring i2bpar2 := int2bit(0,0);
20 modulepar bitstring i2bpar3 := int2bit(1,1)
21 modulepar bitstring i2bpar4 := int2bit(255,8)
22 modulepar bitstring i2bpar5 := int2bit(bit2int(i2bcon),lengthof(i2bcon))
23 modulepar bitstring i2bpar6 := not4b int2bit(bit2int(not4b i2bcon),lengthof(i2bcon))
24 modulepar bitstring i2bpar7 := int2bit(bit2int(substr(i2bcon,0,lengthof(i2bcon)/2)),lengthof(i2bcon)/2)
25 modulepar bitstring i2bpar8 := int2bit(bit2int(substr(i2bcon, lengthof(i2bcon)/2, lengthof(i2bcon)/2)),lengthof(i2bcon)/2)
27 testcase int_to_bit() runs on PDTestComponent{
28 var integer i1 := 12345678910111213141516
29 var bitstring bs1 := '00000000000000000010100111010100001010110110010101101000100100110010100010111011111000001100'B
30 var bitstring bs2 := '010100111010100001010110110010101101000100100110010100010111011111000001100'B
31 if ((i2bpar1 == '0000000000'B)
32 and (i2bpar1 == int2bit(0,10)))
34 else {setverdict(fail, __LINE__);}
35 if ((i2bpar2 == ''B)and (i2bpar2 == int2bit(0,0)))
37 else {setverdict(fail, __LINE__);}
38 if ((i2bpar3 == '1'B)and (i2bpar3 == int2bit(1,1)))
40 else {setverdict(fail, __LINE__);}
41 if ((i2bpar4 == '11111111'B)and (i2bpar4 == int2bit(255,8)))
43 else {setverdict(fail, __LINE__);}
44 if ((i2bpar5 == i2bpar)and (i2bpar5 == int2bit(bit2int(i2bpar),lengthof(i2bpar))))
46 else {setverdict(fail, __LINE__);}
47 if ((i2bpar6 == i2bpar)and (i2bpar5 == not4b int2bit(bit2int(not4b i2bpar),lengthof(i2bpar))))
49 else {setverdict(fail, __LINE__);}
50 if (i2bpar == (i2bpar7 & i2bpar8))
52 else {setverdict(fail, __LINE__);}
53 if (int2bit(i1, 92) == bs1)
55 else {setverdict(fail, __LINE__);}
57 if (int2bit(12345678910111213141516, 92) == '00000000000000000010100111010100001010110110010101101000100100110010100010111011111000001100'B)
59 else {setverdict(fail, __LINE__);}
61 if (int2bit(12345678910111213141516, 92) == bs1)
63 else {setverdict(fail, __LINE__);}
64 if (int2bit(12345678910111213141516, 75) == bs2)
66 else {setverdict(fail, __LINE__);}
69 /*--- INT2CHAR --------------------------------------------------*/
71 const integer i2cpari[3] := {0,1,2}
73 type record of integer i2crtype
74 const i2crtype i2cparii := {0,1,2}
76 modulepar charstring i2cpar1 := int2char(8 mod 6)
77 modulepar charstring i2cpar2 := int2char(i2cpari[2])
78 modulepar charstring i2cpar3 := int2char(sizeof(i2cpari)-1)
79 modulepar charstring i2cpar4 := int2char(sizeof(i2cparii)-1)
81 testcase int_to_char() runs on PDTestComponent{
83 if ((i2cpar1 == int2char(8 mod 6))
84 and (i2cpar1 == "
\ 2"))
86 else {setverdict(fail, __LINE__);}
87 if ((i2cpar2 == int2char(i2cpari[2]))
88 and (i2cpar2 == "
\ 2"))
90 else {setverdict(fail, __LINE__);}
91 if ((i2cpar3 == int2char(sizeof(i2cpari)-1))
92 and (i2cpar3 == "
\ 2"))
94 else {setverdict(fail, __LINE__);}
95 if ((i2cpar4 == int2char(sizeof(i2cparii)-1))
96 and (i2cpar4 == "
\ 2"))
98 else {setverdict(fail, __LINE__);}
103 for (j:=0; j<128; j:=j+1) {
104 if (char2int(int2char(j)) == j)
106 else {setverdict(fail, __LINE__);}
111 /*--- INT2UNICHAR --------------------------------------------------*/
115 modulepar universal charstring i2uccon1 := int2unichar(1)
116 modulepar universal charstring i2uccon2 := int2unichar(256)
117 modulepar universal charstring i2uccon3 := int2unichar(65536)
118 modulepar universal charstring i2uccon4 := int2unichar(16777216)
119 modulepar universal charstring i2uccon5 := int2unichar(2147483647)
122 testcase int_to_unichar() runs on PDTestComponent{
130 if ((i2uccon1 == int2unichar(1))
131 and (i2uccon1 == char(0, 0, 0, 1)))
133 else {setverdict(fail, __LINE__);}
134 if ((i2uccon2 == int2unichar(256))
135 and (i2uccon2 == char(0, 0, 1, 0)))
137 else {setverdict(fail, __LINE__);}
138 if ((i2uccon3 == int2unichar(65536))
139 and (i2uccon3 == char(0, 1, 0, 0)))
141 else {setverdict(fail, __LINE__);}
142 if ((i2uccon4 == int2unichar(16777216))
143 and (i2uccon4 == char(1, 0, 0, 0)))
145 else {setverdict(fail, __LINE__);}
146 if ((i2uccon5 == int2unichar(2147483647))
147 and (i2uccon5 == char(127, 255, 255, 255)))
149 else {setverdict(fail, __LINE__);}
154 /*--- INT2FLOAT --------------------------------------------------*/
157 const integer i2fpari[3] := {0,1,2}
159 type record of integer i2frtype;
160 const i2frtype i2fparii := {0}
162 type float i2fflo (-1.0 .. 6.0)
164 modulepar float i2fpar1 := int2float(3/2)
165 modulepar float i2fpar2 := int2float(-3)
166 modulepar float i2fpar3 := int2float(lengthof(""))
167 modulepar float i2fpar4 := int2float(i2fpari[0])
168 modulepar float i2fpar5 := int2float(i2fparii[0])
169 modulepar float i2fpar8 := int2float(2147483648)
170 modulepar float i2fpar9 := int2float(214748364800)
171 modulepar float i2fpar10 := int2float(4294967296)
173 modulepar i2fflo i2fpar6 := int2float(20/3)
174 modulepar i2fflo i2fpar7 := int2float(8 mod 6)
176 testcase int_to_float() runs on PDTestComponent{
179 and (i2fpar1 == int2float(3/2)))
181 else {setverdict(fail, __LINE__);}
182 if ((i2fpar2 == -3.0)
183 and (i2fpar2 == -3E0))
185 else {setverdict(fail, __LINE__);}
187 and (i2fpar3 == int2float(lengthof(""))))
189 else {setverdict(fail, __LINE__);}
191 and (i2fpar4 == int2float(i2fpari[0])))
193 else {setverdict(fail, __LINE__);}
195 and (i2fpar5 == int2float(i2fparii[0])))
197 else {setverdict(fail, __LINE__);}
199 and (i2fpar6 == int2float(20/3)))
201 else {setverdict(fail, __LINE__);}
203 and (i2fpar7 == int2float(8 mod 6)))
205 else {setverdict(fail, __LINE__);}
206 if ((i2fpar8 == 2147483648.0)
207 and (i2fpar8 == int2float(2147483648)))
209 else {setverdict(fail, __LINE__);}
210 if ((i2fpar9 == 214748364800.0)
211 and (i2fpar9 == int2float(214748364800)))
213 else {setverdict(fail, __LINE__);}
214 if ((i2fpar10 == 4294967296.0)
215 and (i2fpar10 == int2float(4294967296)))
217 else {setverdict(fail, __LINE__);}
218 var float i2fvar1 := 2147483648.0
219 var float i2fvar2 := 214748364800.0
220 var float i2fvar3 := 4294967296.0
221 if ((i2fvar1 == 2147483648.0)
222 and (i2fvar1 == int2float(2147483648)))
224 else {setverdict(fail, __LINE__);}
225 if ((i2fvar2 == 214748364800.0)
226 and (i2fvar2 == int2float(214748364800)))
228 else {setverdict(fail, __LINE__);}
229 if ((i2fvar3 == 4294967296.0)
230 and (i2fvar3 == int2float(4294967296)))
232 else {setverdict(fail, __LINE__);}
236 /*--- INT2HEX --------------------------------------------------*/
238 const hexstring i2hcon := '0123456'H
239 modulepar hexstring i2hpar := '0123456'H
240 modulepar hexstring i2hpar1 := int2hex(0,10)
241 modulepar hexstring i2hpar2 := int2hex(0,0)
242 modulepar hexstring i2hpar3 := int2hex(15,1)
243 modulepar hexstring i2hpar4 := int2hex(hex2int(i2hcon),lengthof(i2hcon))
244 modulepar integer i2hpari := hex2int(i2hcon)
246 testcase int_to_hex() runs on PDTestComponent{
247 var integer i1 := 12345678910111213141516
248 var hexstring hs1 := '000000000000029D42B65689328BBE0C'H
249 var hexstring hs2 := '029D42B65689328BBE0C'H
250 if ((i2hpar1 == '0000000000'H)
251 and (i2hpar1 == int2hex(0,10)))
253 else {setverdict(fail, __LINE__);}
254 if ((i2hpar2 == ''H) and (i2hpar2 == int2hex(0,0)))
256 else {setverdict(fail, __LINE__);}
257 if ((i2hpar3 == 'F'H)
258 and (i2hpar3 == int2hex(15,1)))
260 else {setverdict(fail, __LINE__);}
261 if ((i2hpar4 == i2hpar)
262 and (i2hpar4 == int2hex(hex2int(i2hpar),lengthof(i2hpar))))
264 else {setverdict(fail, __LINE__);}
265 if (int2hex(i1, 32) == hs1) { setverdict(pass) } else { setverdict(fail, __LINE__) }
266 //compile-time: if (int2hex(12345678910111213141516, 32) == '000000000000029D42B65689328BBE0C'H) { setverdict(pass) } else { setverdict(fail, __LINE__) }
267 if (int2hex(12345678910111213141516, 32) == hs1) { setverdict(pass) } else { setverdict(fail, __LINE__) }
268 if (int2hex(12345678910111213141516, 20) == hs2) { setverdict(pass) } else { setverdict(fail, __LINE__) }
271 /*--- INT2OCT --------------------------------------------------*/
273 const octetstring i2ocon := '12345678'O
274 modulepar octetstring i2opar := '12345678'O
275 modulepar octetstring i2opar1 := int2oct(0,10)
276 modulepar octetstring i2opar2 := int2oct(0,0)
277 modulepar octetstring i2opar3 := int2oct(15,1)
278 modulepar octetstring i2opar4 := int2oct(oct2int(i2ocon),lengthof(i2ocon))
279 modulepar octetstring i2opar5 := int2oct(33,8);
280 modulepar integer i2opari := oct2int(i2ocon)
282 testcase int_to_oct() runs on PDTestComponent{
283 var integer i1 := 881883119815076896174081;
284 var octetstring os1 := '00000000000000000000000000000000000000000000BABEFACEDECAFBADF001'O
285 var octetstring os2 := 'BABEFACEDECAFBADF001'O
286 if ((i2opar1 == '00000000000000000000'O)
287 and (i2opar1 == int2oct(0,10)))
289 else {setverdict(fail, __LINE__);}
290 if ((i2opar2 == ''O)and (i2opar2 == int2oct(0,0)))
292 else {setverdict(fail, __LINE__);}
293 if ((i2opar3 == '0F'O)
294 and (i2opar3 == int2oct(15,1)))
296 else {setverdict(fail, __LINE__);}
297 if (i2opar5 == '0000000000000021'O)
299 else {setverdict(fail, __LINE__);}
300 if ((i2opar4 == i2opar)
301 and (i2opar4 == int2oct(oct2int(i2opar),lengthof(i2opar))))
303 else {setverdict(fail, __LINE__);}
305 log(int2oct(i1, 32));
307 if (int2oct(i1, 32) == os1) { setverdict(pass) } else { setverdict(fail, __LINE__, match(int2oct(i1, 32) , os1)) }
308 //compile-time: if (int2oct(12345678910111213141516, 32) == '00000000000000000000000000000000000000000000029D42B65689328BBE0C'O) { setverdict(pass) } else { setverdict(fail, __LINE__) }
309 if (int2oct(881883119815076896174081, 32) == os1) { setverdict(pass) } else { setverdict(fail, __LINE__) }
310 if (int2oct(881883119815076896174081, 10) == os2) { setverdict(pass) } else { setverdict(fail, __LINE__) }
313 /*--- INT2STR --------------------------------------------------*/
315 const charstring i2scon := "1234567890"
316 modulepar charstring i2spar := "1234567890"
317 modulepar charstring i2spar1 := int2str(0)
318 modulepar charstring i2spar2 := int2str(-1)
319 modulepar charstring i2spar3 := int2str(16 mod 3)
320 modulepar charstring i2spar4 := int2str(16 rem 3)
321 modulepar charstring i2spar5 := int2str(lengthof(i2scon))
323 const integer i2sconi := str2int(i2scon)
325 modulepar charstring i2spar6 := int2str(i2sconi)
326 const charstring i2scon7 := "1234567891011121314151617181920"
327 modulepar charstring i2spar7 := "1234567891011121314151617181920"
328 const charstring i2scon8 := "-1234567891011121314151617181920" // Negative values.
329 modulepar charstring i2spar8 := "-1234567891011121314151617181920" // Negative values.
330 modulepar integer i2spari1 := str2int(i2scon7)
331 modulepar integer i2spari2 := str2int(i2scon8)
333 testcase int_to_str() runs on PDTestComponent{
335 var charstring cc := int2str(i2sconi)
336 var charstring vv := "1234567891011121314151617181920"
337 var charstring vv1 := "-1234567891011121314151617181920"
338 var integer ii := str2int(vv)
339 var integer ii1 := str2int(vv1)
342 and (i2spar1 == int2str(0)))
344 else {setverdict(fail, __LINE__);}
345 if ((i2spar2 == "-1")
346 and (i2spar2 == int2str(-1)))
348 else {setverdict(fail, __LINE__);}
350 and (i2spar3 == int2str(16 mod 3)))
352 else {setverdict(fail, __LINE__);}
354 and (i2spar4 == int2str(16 rem 3)))
356 else {setverdict(fail, __LINE__);}
357 if ((i2spar5 == "10")
358 and (i2spar5 == int2str(lengthof(i2spar))))
360 else {setverdict(fail, __LINE__);}
361 if ((i2spar6 == i2spar)
362 and (i2spar6 == int2str(i2sconi)))
364 else {setverdict(fail, __LINE__);}
365 // Compile time evaluation. (Positive/negative.)
366 if ((i2spar7 == int2str(1234567891011121314151617181920)
367 and (int2str(1234567891011121314151617181920) == i2spar7)))
369 else {setverdict(fail, __LINE__);}
370 if ((int2str(1234567891011121314151617181930 - 10) == i2spar7)
371 and (i2spar7 == int2str(1234567891011121314151617181930 - 10)))
373 else {setverdict(fail, __LINE__);}
374 if ((i2spar7 == int2str(i2spari1)
375 and (int2str(i2spari1) == i2spar7)))
377 else {setverdict(fail, __LINE__);}
378 if ((int2str(i2spari1 + 10 - 10) == i2spar7)
379 and (i2spar7 == int2str(i2spari1 + 10 - 10)))
381 else {setverdict(fail, __LINE__);}
382 if ((i2spar8 == int2str(-1234567891011121314151617181920)
383 and (int2str(1234567891011121314151617181920) == i2spar7)))
385 else {setverdict(fail, __LINE__);}
386 if ((int2str(-1234567891011121314151617181930 + 10) == i2spar8)
387 and (i2spar8 == int2str(-1234567891011121314151617181930 + 10)))
389 else {setverdict(fail, __LINE__);}
390 if ((i2spar8 == int2str(i2spari2)
391 and (int2str(i2spari2) == i2spar8)))
393 else {setverdict(fail, __LINE__);}
394 if ((int2str(i2spari2 + 10 - 10) == i2spar8)
395 and (i2spar8 == int2str(i2spari2 + 10 - 10)))
397 else {setverdict(fail, __LINE__);}
398 // Run-time evaluation. (Positive/negative.)
399 if ((vv == int2str(1234567891011121314151617181920)
400 and (int2str(1234567891011121314151617181920) == vv)))
402 else {setverdict(fail, __LINE__);}
403 if ((int2str(1234567891011121314151617181910 + 10) == vv)
404 and (vv == int2str(1234567891011121314151617181910 + 10)))
406 else {setverdict(fail, __LINE__);}
407 if ((vv == int2str(ii)
408 and (int2str(1234567891011121314151617181920) == vv)))
410 else {setverdict(fail, __LINE__);}
411 if ((int2str(ii + 10 - 10) == vv)
412 and (vv == int2str(ii + 10 - 10)))
414 else {setverdict(fail, __LINE__);}
416 and (ii == i2spari1))
418 else {setverdict(fail, __LINE__);}
419 if ((int2str(i2spari1) == int2str(ii))
420 and (int2str(ii) == int2str(i2spari1)))
422 else {setverdict(fail, __LINE__);}
423 if ((vv1 == int2str(-1234567891011121314151617181920)
424 and (int2str(-1234567891011121314151617181920) == vv1)))
426 else {setverdict(fail, __LINE__);}
427 if ((int2str(-1234567891011121314151617181910 - 10) == vv1)
428 and (vv1 == int2str(-1234567891011121314151617181910 - 10)))
430 else {setverdict(fail, __LINE__);}
431 if ((vv1 == int2str(ii1)
432 and (int2str(-1234567891011121314151617181920) == vv1)))
434 else {setverdict(fail, __LINE__);}
435 if ((int2str(ii1 + 10 - 10) == vv1)
436 and (vv1 == int2str(ii1 + 10 - 10)))
438 else {setverdict(fail, __LINE__);}
439 if ((i2spari2 == ii1)
440 and (ii1 == i2spari2))
442 else {setverdict(fail, __LINE__);}
443 if ((int2str(i2spari2) == int2str(ii1))
444 and (int2str(ii1) == int2str(i2spari2)))
446 else {setverdict(fail, __LINE__);}
453 execute (int_to_bit());
454 execute (int_to_char());
455 execute (int_to_unichar());
457 execute (int_to_float());
458 execute (int_to_hex());
459 execute (int_to_oct());
460 execute (int_to_str());