Commit | Line | Data |
---|---|---|
970ed795 EL |
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 hex_to_OK { | |
9 | ||
10 | type component PDTestComponent {}; | |
11 | ||
12 | /*--- HEX2BIT --------------------------------------------------*/ | |
13 | ||
14 | modulepar bitstring h2bpar := hex2bit(''H) | |
15 | modulepar bitstring h2bpar1 := hex2bit('000000'H & ''H & '111111'H) | |
16 | modulepar bitstring h2bpar2 := hex2bit(substr('000000111111'H,0,6) & ''H & substr('000000111111'H,6,6)) | |
17 | const bitstring h2bcon2 := hex2bit(substr('000000111111'H,0,6) & ''H & substr('000000111111'H,6,6)) | |
18 | modulepar bitstring h2bpar3 := hex2bit(('000000'H <@ lengthof(h2bcon2)/2) & ''H & ('111111'H @> lengthof(h2bcon2)/2)) | |
19 | modulepar bitstring h2bpar4 := hex2bit((not4b 'FFFFFF'H) & '111111'H) | |
20 | modulepar bitstring h2bpar5 := hex2bit('000000111111'H and4b '000000111111'H) | |
21 | modulepar bitstring h2bpar6 := hex2bit('000000000000'H or4b '000000111111'H) | |
22 | modulepar bitstring h2bpar7 := hex2bit('000000000000'H xor4b '000000111111'H) | |
23 | ||
24 | const bitstring h2bparb := '000000000000000000000000000100010001000100010001'B | |
25 | ||
26 | testcase hex_to_bit() runs on PDTestComponent{ | |
27 | ||
28 | if ((h2bpar == hex2bit(''H)) | |
29 | and (h2bpar == ''B)) | |
30 | {setverdict(pass);} | |
31 | else {setverdict(fail);} | |
32 | ||
33 | if ((h2bpar1 == hex2bit('000000'H & ''H & '111111'H)) | |
34 | and (h2bpar1 == h2bparb)) | |
35 | {setverdict(pass);} | |
36 | else {setverdict(fail);} | |
37 | ||
38 | if ((h2bpar2 == hex2bit(substr('000000111111'H,0,6) & ''H & substr('000000111111'H,6,6))) | |
39 | and (h2bpar2 == h2bparb)) | |
40 | {setverdict(pass);} | |
41 | else {setverdict(fail);} | |
42 | ||
43 | if ((h2bpar3 == hex2bit(('000000'H <@ lengthof(h2bpar2)/2) & ''H & ('111111'H @> lengthof(h2bpar2)/2))) | |
44 | and (h2bpar3 == h2bparb)) | |
45 | {setverdict(pass);} | |
46 | else {setverdict(fail);} | |
47 | ||
48 | if ((h2bpar4 == hex2bit((not4b 'FFFFFF'H) & '111111'H)) | |
49 | and (h2bpar4 == h2bparb)) | |
50 | {setverdict(pass);} | |
51 | else {setverdict(fail);} | |
52 | ||
53 | if ((h2bpar5 == hex2bit('000000111111'H and4b '000000111111'H)) | |
54 | and (h2bpar5 == h2bparb)) | |
55 | {setverdict(pass);} | |
56 | else {setverdict(fail);} | |
57 | ||
58 | if ((h2bpar6 == hex2bit('000000000000'H or4b '000000111111'H)) | |
59 | and (h2bpar6 == h2bparb)) | |
60 | {setverdict(pass);} | |
61 | else {setverdict(fail);} | |
62 | ||
63 | if ((h2bpar7 == hex2bit('000000000000'H xor4b '000000111111'H)) | |
64 | and (h2bpar7 == h2bparb)) | |
65 | {setverdict(pass);} | |
66 | else {setverdict(fail);} | |
67 | ||
68 | } | |
69 | /*--- HEX2INT --------------------------------------------------*/ | |
70 | ||
71 | modulepar integer h2ipar := hex2int(''H) | |
72 | modulepar integer h2ipar1 := hex2int('FFF'H & 'FFFF'H) | |
73 | modulepar integer h2ipar2 := hex2int((not4b 'FFF'H) & 'FFFF'H) | |
74 | modulepar integer h2ipar3 := hex2int(('FFF'H and4b '000'H) & 'FFFF'H) | |
75 | modulepar integer h2ipar4 := hex2int(('000'H or4b '000'H) & 'FFFF'H) | |
76 | modulepar integer h2ipar5 := hex2int(('0FF'H xor4b '0FF'H) & 'FFFF'H) | |
77 | modulepar integer h2i1_16 := 12345678910111213141516; | |
78 | ||
79 | testcase hex_to_int() runs on PDTestComponent{ | |
80 | var integer i1 := 12345678910111213141516 | |
81 | var hexstring hs1 := '000000000000029D42B65689328BBE0C'H | |
82 | var integer b; | |
83 | ||
84 | if ((h2ipar == hex2int(''H)) | |
85 | and (h2ipar == 0)) | |
86 | {setverdict(pass);} | |
87 | else {setverdict(fail);} | |
88 | ||
89 | if ((h2ipar1 == hex2int('FFF'H & 'FFFF'H)) | |
90 | and (h2ipar1 == 268435455)) | |
91 | {setverdict(pass);} | |
92 | else {setverdict(fail);} | |
93 | ||
94 | b := hex2int((not4b 'FFF'H) & 'FFFF'H) | |
95 | if ((h2ipar2 == b) | |
96 | and (h2ipar2 == 65535)) | |
97 | {setverdict(pass);} | |
98 | else {setverdict(fail);} | |
99 | ||
100 | b := hex2int(('FFF'H and4b '000'H) & 'FFFF'H) | |
101 | if ((h2ipar3 == b) | |
102 | and (h2ipar3 == 65535)) | |
103 | {setverdict(pass);} | |
104 | else {setverdict(fail);} | |
105 | ||
106 | b := hex2int(('000'H or4b '000'H) & 'FFFF'H) | |
107 | if ((h2ipar4 == b) | |
108 | and (h2ipar4 == 65535)) | |
109 | {setverdict(pass);} | |
110 | else {setverdict(fail);} | |
111 | ||
112 | b := hex2int(('0FF'H xor4b '0FF'H) & 'FFFF'H) | |
113 | if ((h2ipar5 == b) | |
114 | and (h2ipar5 == 65535)) | |
115 | {setverdict(pass);} | |
116 | else {setverdict(fail);} | |
117 | ||
118 | if (hex2int(hs1) == i1) | |
119 | {setverdict(pass);} | |
120 | else {setverdict(fail);} | |
121 | if (hex2int('000000000000029D42B65689328BBE0C'H) == h2i1_16) | |
122 | {setverdict(pass);} | |
123 | else {setverdict(fail);} | |
124 | if (hex2int(hs1) == 12345678910111213141516) | |
125 | {setverdict(pass);} | |
126 | else {setverdict(fail);} | |
127 | if (hex2int('029D42B65689328BBE0C'H) == h2i1_16) | |
128 | {setverdict(pass);} | |
129 | else {setverdict(fail);} | |
130 | ||
131 | var integer j | |
132 | for (j:=0; j<4096; j:=j+1) { | |
133 | if (hex2int(int2hex(j,3)) == j) | |
134 | {setverdict(pass);} | |
135 | else {setverdict(fail);} | |
136 | } | |
137 | } | |
138 | ||
139 | ||
140 | /*--- HEX2OCT --------------------------------------------------*/ | |
141 | ||
142 | modulepar octetstring h2opar := hex2oct(''H) | |
143 | modulepar octetstring h2opar1 := hex2oct('000000'H & ''H & '111111'H) | |
144 | modulepar octetstring h2opar2 := hex2oct(substr('000000111111'H,0,6) & ''H & substr('000000111111'H,6,6)) | |
145 | modulepar octetstring h2opar3 := hex2oct(('000000'H <@ 3) & ''H & ('111111'H @> 3)) | |
146 | modulepar octetstring h2opar4 := hex2oct((not4b 'FFFFFF'H) & '111111'H) | |
147 | modulepar octetstring h2opar5 := hex2oct('000000111111'H and4b '000000111111'H) | |
148 | modulepar octetstring h2opar6 := hex2oct('000000000000'H or4b '000000111111'H) | |
149 | modulepar octetstring h2opar7 := hex2oct('000000000000'H xor4b '000000111111'H) | |
150 | modulepar octetstring h2opar8 := hex2oct('00011'H) | |
151 | modulepar octetstring h2opar9 := hex2oct('1'H) | |
152 | ||
153 | modulepar octetstring h2oparo := '000000111111'O | |
154 | ||
155 | testcase hex_to_oct() runs on PDTestComponent{ | |
156 | ||
157 | if ((h2opar == hex2oct(''H)) | |
158 | and (h2opar == ''O)) | |
159 | {setverdict(pass);} | |
160 | else {setverdict(fail);} | |
161 | ||
162 | if ((h2opar1 == hex2oct('000000'H & ''H & '111111'H)) | |
163 | and (h2opar1 == h2oparo)) | |
164 | {setverdict(pass);} | |
165 | else {setverdict(fail);} | |
166 | ||
167 | if ((h2opar2 == hex2oct(substr('000000111111'H,0,6) & ''H & substr('000000111111'H,6,6))) | |
168 | and (h2opar2 == h2oparo)) | |
169 | {setverdict(pass);} | |
170 | else {setverdict(fail);} | |
171 | ||
172 | if ((h2opar3 == hex2oct(('000000'H <@ 3) & ''H & ('111111'H @> 3))) | |
173 | and (h2opar3 == h2oparo)) | |
174 | {setverdict(pass);} | |
175 | else {setverdict(fail);} | |
176 | ||
177 | if ((h2opar4 == hex2oct((not4b 'FFFFFF'H) & '111111'H)) | |
178 | and (h2opar4 == h2oparo)) | |
179 | {setverdict(pass);} | |
180 | else {setverdict(fail);} | |
181 | ||
182 | if ((h2opar5 == hex2oct('000000111111'H and4b '000000111111'H)) | |
183 | and (h2opar5 == h2oparo)) | |
184 | {setverdict(pass);} | |
185 | else {setverdict(fail);} | |
186 | ||
187 | if ((h2opar6 == hex2oct('000000000000'H or4b '000000111111'H)) | |
188 | and (h2opar6 == h2oparo)) | |
189 | {setverdict(pass);} | |
190 | else {setverdict(fail);} | |
191 | ||
192 | if ((h2opar7 == hex2oct('000000000000'H xor4b '000000111111'H)) | |
193 | and (h2opar7 == h2oparo)) | |
194 | {setverdict(pass);} | |
195 | else {setverdict(fail);} | |
196 | ||
197 | if ((h2opar8 == hex2oct('00011'H)) | |
198 | and (h2opar8 == '000011'O)) | |
199 | {setverdict(pass);} | |
200 | else {setverdict(fail);} | |
201 | ||
202 | if ((h2opar9 == hex2oct('1'H)) | |
203 | and (h2opar9 == '01'O)) | |
204 | {setverdict(pass);} | |
205 | else {setverdict(fail);} | |
206 | ||
207 | ||
208 | } | |
209 | ||
210 | /*--- HEX2STR --------------------------------------------------*/ | |
211 | ||
212 | modulepar charstring h2spar := hex2str(''H) | |
213 | modulepar charstring h2spar1 := hex2str('000000'H & ''H & '111111'H) | |
214 | modulepar charstring h2spar2 := hex2str(substr('000000111111'H,0,6) & ''H & substr('000000111111'H,6,6)) | |
215 | modulepar charstring h2spar3 := hex2str(('000000'H <@ 3) & ''H & ('111111'H @> 3)) | |
216 | modulepar charstring h2spar4 := hex2str((not4b 'FFFFFF'H) & '111111'H) | |
217 | modulepar charstring h2spar5 := hex2str('000000111111'H and4b '000000111111'H) | |
218 | modulepar charstring h2spar6 := hex2str('000000000000'H or4b '000000111111'H) | |
219 | modulepar charstring h2spar7 := hex2str('000000000000'H xor4b '000000111111'H) | |
220 | ||
221 | modulepar charstring h2spars := "000000111111" | |
222 | ||
223 | testcase hex_to_str() runs on PDTestComponent{ | |
224 | ||
225 | if ((h2spar == hex2str(''H)) | |
226 | and (h2spar == "")) | |
227 | {setverdict(pass);} | |
228 | else {setverdict(fail);} | |
229 | ||
230 | if ((h2spar1 == hex2str('000000'H & ''H & '111111'H)) | |
231 | and (h2spar1 == h2spars)) | |
232 | {setverdict(pass);} | |
233 | else {setverdict(fail);} | |
234 | ||
235 | if ((h2spar2 == hex2str(substr('000000111111'H,0,6) & ''H & substr('000000111111'H,6,6))) | |
236 | and (h2spar2 == h2spars)) | |
237 | {setverdict(pass);} | |
238 | else {setverdict(fail);} | |
239 | ||
240 | if ((h2spar3 == hex2str(('000000'H <@ 3) & ''H & ('111111'H @> 3))) | |
241 | and (h2spar3 == h2spars)) | |
242 | {setverdict(pass);} | |
243 | else {setverdict(fail);} | |
244 | ||
245 | if ((h2spar4 == hex2str((not4b 'FFFFFF'H) & '111111'H)) | |
246 | and (h2spar4 == h2spars)) | |
247 | {setverdict(pass);} | |
248 | else {setverdict(fail);} | |
249 | ||
250 | if ((h2spar5 == hex2str('000000111111'H and4b '000000111111'H)) | |
251 | and (h2spar5 == h2spars)) | |
252 | {setverdict(pass);} | |
253 | else {setverdict(fail);} | |
254 | ||
255 | if ((h2spar6 == hex2str('000000000000'H or4b '000000111111'H)) | |
256 | and (h2spar6 == h2spars)) | |
257 | {setverdict(pass);} | |
258 | else {setverdict(fail);} | |
259 | ||
260 | if ((h2spar7 == hex2str('000000000000'H xor4b '000000111111'H)) | |
261 | and (h2spar7 == h2spars)) | |
262 | {setverdict(pass);} | |
263 | else {setverdict(fail);} | |
264 | ||
265 | } | |
266 | ||
267 | control { | |
268 | execute (hex_to_bit()); | |
269 | execute (hex_to_int()); | |
270 | execute (hex_to_oct()); | |
271 | execute (hex_to_str()); | |
272 | } | |
273 | ||
274 | } |