Last sync 2016.04.01
[deliverable/titan.core.git] / regression_test / XML / XER / Txerasntypes.ttcnpp
1 /******************************************************************************
2 * Copyright (c) 2000-2016 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 * Contributors:
9 * Balasko, Jeno
10 * Baranyi, Botond
11 * Raduly, Csaba
12 * Szabados, Kristof
13 *
14 ******************************************************************************/
15 module Txerasntypes {
16
17 modulepar boolean Txerasntypes_verbose := false;
18 #define verbose Txerasntypes_verbose
19
20 #include "../macros.ttcnin"
21
22 import from Asntypes all;
23 import from AsnValues all;
24 import from UTF8 all;
25
26 type component ASN1 {}
27
28 //external function flatten(inout charstring par) ;
29 external function flatten(inout universal charstring par) ;
30
31 /**************************** BIT STRING ****************************/
32 DECLARE_XER_ENCODERS(Asn_bs,bs)
33 DECLARE_EXER_ENCODERS(Asn_bs,bs)
34
35 const charstring xer_fifteen := "<Asn-bs>00001111</Asn-bs>";
36 const charstring xer_pi1 := "<Asn-bs>0010010000111111011010101000100010000101101000110000100011010011"&
37 "0001001100011001100010100010111000000011011100000111001101000100"&
38 "1010010000001001001110000010001000101001100111110011000111010000"&
39 "0000100000101110111110101001100011101100010011100110110010001001</Asn-bs>";
40 const charstring xer_pi2 := "<Asn-bs>010001010010100000100001111001100011100011010000" &
41 "000100110111011110111110010101000110011011001111001101001110100100001100"&
42 "011011001100000010101100001010011011011111001001011111000101000011011101"&
43 "0011111110000100110101011011010110110101010001110000100100010111</Asn-bs>";
44 const charstring xer_bs_empty := "<Asn-bs/>";
45
46 testcase encode_bs() runs on ASN1 // BIT STRING
47 {
48 var Asn_bs bsval := '00001111'B;
49 var universal charstring expected := xer_fifteen;
50
51 CHECK_METHOD(cxer_enc_bs, bsval, expected);
52 CHECK_METHOD(bxer_enc_bs, bsval, expected & lf);
53 CHECK_METHOD(exer_enc_bs, bsval, expected & lf);
54
55 bsval := ''B;
56 expected := xer_bs_empty;
57 CHECK_METHOD(cxer_enc_bs, bsval, expected);
58 CHECK_METHOD(bxer_enc_bs, bsval, expected & lf);
59 CHECK_METHOD(exer_enc_bs, bsval, expected & lf);
60
61 expected := xer_bs_empty; // FIXME: Asn-bs ?
62 CHECK_METHOD(cxer_enc_bs, AsnValues.bstr0, expected);
63 CHECK_METHOD(bxer_enc_bs, AsnValues.bstr0, expected & lf);
64
65 expected := "<Asn-bs>10100100</Asn-bs>";
66 CHECK_METHOD(cxer_enc_bs, AsnValues.bstr, expected);
67 CHECK_METHOD(bxer_enc_bs, AsnValues.bstr, expected & lf);
68
69 expected := xer_pi2;
70 CHECK_METHOD(cxer_enc_bs, AsnValues.binpi2, expected);
71 CHECK_METHOD(bxer_enc_bs, AsnValues.binpi2, expected & lf);
72
73 expected := xer_pi1;
74 CHECK_METHOD(cxer_enc_bs, AsnValues.binpi, expected);
75 CHECK_METHOD(bxer_enc_bs, AsnValues.binpi, expected & lf);
76 }
77
78 testcase decode_bs() runs on ASN1
79 {
80 var Asn_bs expected;
81
82 expected := ''B;
83 CHECK_DECODE(cxer_dec_bs, xer_bs_empty, Asn_bs, expected);
84 CHECK_DECODE(bxer_dec_bs, xer_bs_empty, Asn_bs, expected);
85 CHECK_DECODE(exer_dec_bs, xer_bs_empty, Asn_bs, expected);
86
87 expected := '00001111'B;
88 CHECK_DECODE(cxer_dec_bs, xer_fifteen, Asn_bs, expected);
89 CHECK_DECODE(bxer_dec_bs, xer_fifteen, Asn_bs, expected);
90 CHECK_DECODE(exer_dec_bs, xer_fifteen, Asn_bs, expected);
91
92 expected := '0100010100101000001000011110011000111000110100000001001101110111101111100101010001100110110011110011010011101001000011000110110011000000101011000010100110110111110010010111110001010000110111010011111110000100110101011011010110110101010001110000100100010111'B;
93 CHECK_DECODE(cxer_dec_bs, xer_pi2, Asn_bs, expected);
94 CHECK_DECODE(bxer_dec_bs, xer_pi2, Asn_bs, expected);
95 CHECK_DECODE(exer_dec_bs, xer_pi2, Asn_bs, expected);
96 CHECK_DECODE(cxer_dec_bs, xer_pi2, Asn_bs, AsnValues.binpi2);
97 CHECK_DECODE(bxer_dec_bs, xer_pi2, Asn_bs, AsnValues.binpi2);
98 CHECK_DECODE(exer_dec_bs, xer_pi2, Asn_bs, AsnValues.binpi2);
99
100 expected := '0010010000111111011010101000100010000101101000110000100011010011000100110001100110001010001011100000001101110000011100110100010010100100000010010011100000100010001010011001111100110001110100000000100000101110111110101001100011101100010011100110110010001001'B;
101 CHECK_DECODE(cxer_dec_bs, xer_pi1, Asn_bs, AsnValues.binpi);
102 CHECK_DECODE(bxer_dec_bs, xer_pi1, Asn_bs, AsnValues.binpi);
103 CHECK_DECODE(exer_dec_bs, xer_pi1, Asn_bs, AsnValues.binpi);
104 }
105
106 /**************************** BOOLEAN ****************************/
107 DECLARE_XER_ENCODERS(Asn_bool, bool);
108 DECLARE_EXER_ENCODERS(Asn_bool,bool)
109 DECLARE_XER_ENCODERS(A_rboolean, arbool);
110 DECLARE_EXER_ENCODERS(A_rboolean,arbool)
111
112 testcase encode_abool() runs on ASN1
113 {
114 var Asn_bool boolval := true;
115 var universal charstring expected := "<Asn-bool><true/></Asn-bool>";
116 CHECK_METHOD(cxer_enc_bool, boolval, expected);
117 CHECK_METHOD(bxer_enc_bool, boolval, expected & lf);
118 expected := "<Asn-bool>true</Asn-bool>"; // EXER uses TextBoolean
119 CHECK_METHOD(exer_enc_bool, boolval, expected & lf);
120
121 expected := "<Asn-bool><true/></Asn-bool>";
122 CHECK_METHOD(cxer_enc_bool, AsnValues.boo, expected);
123 CHECK_METHOD(bxer_enc_bool, AsnValues.boo, expected & lf);
124
125 CHECK_METHOD(cxer_enc_bool, AsnValues.so_true, expected);
126 CHECK_METHOD(bxer_enc_bool, AsnValues.so_true, expected & lf);
127
128 expected := "<Asn-bool>true</Asn-bool>"; // EXER uses TextBoolean
129 CHECK_METHOD(exer_enc_bool, AsnValues.boo, expected & lf);
130 CHECK_METHOD(exer_enc_bool, AsnValues.so_true, expected & lf);
131
132 boolval := false;
133 expected := "<Asn-bool><false/></Asn-bool>";
134 CHECK_METHOD(cxer_enc_bool, boolval, expected);
135 CHECK_METHOD(bxer_enc_bool, boolval, expected & lf);
136 expected := "<Asn-bool>false</Asn-bool>"; // EXER uses TextBoolean
137 CHECK_METHOD(exer_enc_bool, boolval, expected & lf);
138
139 expected := "<Asn-bool><false/></Asn-bool>";
140 CHECK_METHOD(cxer_enc_bool, AsnValues.noo, expected);
141 CHECK_METHOD(bxer_enc_bool, AsnValues.noo, expected & lf);
142 expected := "<Asn-bool>false</Asn-bool>"; // EXER uses TextBoolean
143 CHECK_METHOD(exer_enc_bool, AsnValues.noo, expected & lf);
144
145 expected := "<A-rboolean/>\n\n";
146 CHECK_METHOD(bxer_enc_arbool, AsnValues.arbomit, expected);
147 CHECK_METHOD(exer_enc_arbool, AsnValues.arbomit, expected);
148 flatten(expected);
149 CHECK_METHOD(cxer_enc_arbool, AsnValues.arbomit, expected & lf);
150
151 expected :=
152 "<A-rboolean>\n" &
153 "\t<bb><true/></bb>\n" &
154 "</A-rboolean>\n\n";
155 CHECK_METHOD(bxer_enc_arbool, AsnValues.arbtrue, expected);
156 flatten(expected);
157 CHECK_METHOD(cxer_enc_arbool, AsnValues.arbtrue, expected & lf);
158 expected :=
159 "<A-rboolean>\n" &
160 "\t<bb>true</bb>\n" & // EXER uses TextBoolean
161 "</A-rboolean>\n\n";
162 CHECK_METHOD(exer_enc_arbool, AsnValues.arbtrue, expected);
163
164 expected :=
165 "<A-rboolean>\n" &
166 "\t<bb><false/></bb>\n" &
167 "</A-rboolean>\n\n";
168 CHECK_METHOD(bxer_enc_arbool, AsnValues.arbfalse, expected);
169 flatten(expected);
170 CHECK_METHOD(cxer_enc_arbool, AsnValues.arbfalse, expected & lf);
171 expected :=
172 "<A-rboolean>\n" &
173 "\t<bb>false</bb>\n" &
174 "</A-rboolean>\n\n";
175 CHECK_METHOD(exer_enc_arbool, AsnValues.arbfalse, expected);
176 }
177
178 testcase decode_abool() runs on ASN1
179 {
180 {
181 var Asn_bool expected;
182
183 const charstring verite := "<Asn-bool><true/></Asn-bool>";
184 expected := true;
185 CHECK_DECODE2(bool, verite, Asn_bool, expected);
186
187 const charstring faux := "<Asn-bool><false/></Asn-bool>"
188 expected := false;
189 CHECK_DECODE2(bool, faux, Asn_bool, expected);
190 }
191
192 {
193 var A_rboolean expected := { omit };
194 const charstring omitted := "<A-rboolean/>\n\n";
195 CHECK_DECODE2(arbool, omitted, A_rboolean, expected);
196 }
197
198 {
199 var A_rboolean expected := { true };
200 const charstring one_true :=
201 "<A-rboolean>\n" &
202 "\t<bb><true/></bb>\n" &
203 "</A-rboolean>\n\n";
204 CHECK_DECODE2(arbool, one_true, A_rboolean, expected);
205 }
206
207 {
208 var A_rboolean expected := { false };
209 const charstring one_true :=
210 "<A-rboolean>\n" &
211 "\t<bb><false/></bb>\n" &
212 "</A-rboolean>\n\n";
213 CHECK_DECODE2(arbool, one_true, A_rboolean, expected);
214 }
215 }
216
217 /**************************** EMBEDDED PDV ****************************/
218 DECLARE_XER_ENCODERS(Asn_pdv, pdv);
219 DECLARE_EXER_ENCODERS(Asn_pdv,pdv)
220
221 const charstring pdvstr_syntax :=
222 "<Asn-pdv>\n" &
223 "\t<identification>\n" &
224 "\t\t<syntax>0.4.0.0.1.2</syntax>\n" &
225 "\t</identification>\n" &
226 "\t<data-value>BABEFACE</data-value>\n" &
227 "</Asn-pdv>\n";
228
229 const charstring pdvstr_pci := // pci = initials of presentation-context-id
230 "<Asn-pdv>\n" &
231 "\t<identification>\n" &
232 "\t\t<presentation-context-id>1</presentation-context-id>\n" &
233 "\t</identification>\n" &
234 "\t<data-value>BABEFACE</data-value>\n" &
235 "</Asn-pdv>\n";
236
237 const charstring pdvstr_syntaxes :=
238 "<Asn-pdv>\n" &
239 "\t<identification>\n" &
240 "\t\t<syntaxes>\n" &
241 "\t\t\t<abstract>1.0.9.8.7.6.5</abstract>\n" &
242 "\t\t\t<transfer>1.0.5.6.7.8.9</transfer>\n" &
243 "\t\t</syntaxes>\n" &
244 "\t</identification>\n" &
245 //"\t<data-value-descriptor>Food given to cattle</data-value-descriptor>\n" &
246 "\t<data-value>BEEFFEED</data-value>\n" &
247 "</Asn-pdv>\n"
248
249 const charstring pdvstr_syntax2 :=
250 "<Asn-pdv>\n" &
251 "\t<identification>\n" &
252 "\t\t<syntax>0.4.0.1.3.5</syntax>\n" &
253 "\t</identification>\n" &
254 //"\t<data-value-descriptor>We need real coffee</data-value-descriptor>\n" &
255 "\t<data-value>DECAFBAD</data-value>\n" &
256 "</Asn-pdv>\n"
257
258 const charstring pdvstr_context_neg :=
259 "<Asn-pdv>\n" &
260 "\t<identification>\n" &
261 "\t\t<context-negotiation>\n" &
262 "\t\t\t<presentation-context-id>69</presentation-context-id>\n" &
263 "\t\t\t<transfer-syntax>2.7.18.28.18.28.45.90.45</transfer-syntax>\n" &
264 "\t\t</context-negotiation>\n" &
265 "\t</identification>\n" &
266 "\t<data-value>C1AFB1</data-value>\n" &
267 "</Asn-pdv>\n"
268
269 const charstring pdvstr_xfer :=
270 "<Asn-pdv>\n" &
271 "\t<identification>\n" &
272 "\t\t<transfer-syntax>0.4.0.0.1.2</transfer-syntax>\n" &
273 "\t</identification>\n" &
274 "\t<data-value>C0FFEE</data-value>\n" &
275 "</Asn-pdv>\n";
276
277 const charstring pdvstr_fixed :=
278 "<Asn-pdv>\n" &
279 "\t<identification>\n" &
280 "\t\t<fixed/>\n" &
281 "\t</identification>\n" &
282 "\t<data-value>F1</data-value>\n" &
283 "</Asn-pdv>\n";
284
285 const Asn_pdv tpdv := {
286 { syntax := objid { etsi 0 1 2 } },
287 omit, // data-value-descriptor not allowed for EMBEDDED PDV
288 'BABEFACE'O };
289
290 testcase encode_pdv() runs on ASN1
291 {
292 var universal charstring expected;
293
294 expected := pdvstr_syntax;
295 CHECK_METHOD(bxer_enc_pdv, tpdv, expected);
296 CHECK_METHOD(exer_enc_pdv, tpdv, expected);
297 flatten(expected);
298 CHECK_METHOD(cxer_enc_pdv, tpdv, expected);
299
300 expected := pdvstr_pci;
301 CHECK_METHOD(bxer_enc_pdv, AsnValues.pdv_pci, expected);
302 CHECK_METHOD(bxer_enc_pdv, AsnValues.epdv_pci, expected);
303 flatten(expected);
304 CHECK_METHOD(cxer_enc_pdv, AsnValues.pdv_pci, expected);
305 CHECK_METHOD(cxer_enc_pdv, AsnValues.epdv_pci, expected);
306
307 expected := pdvstr_syntaxes;
308 CHECK_METHOD(bxer_enc_pdv, AsnValues.pdv_sxs, expected);
309 CHECK_METHOD(bxer_enc_pdv, AsnValues.epdv_sxs, expected);
310 flatten(expected);
311 CHECK_METHOD(cxer_enc_pdv, AsnValues.pdv_sxs, expected);
312 CHECK_METHOD(cxer_enc_pdv, AsnValues.epdv_sxs, expected);
313
314 expected := pdvstr_syntax2;
315 CHECK_METHOD(bxer_enc_pdv, AsnValues.pdv_sx, expected);
316 CHECK_METHOD(bxer_enc_pdv, AsnValues.epdv_sx, expected);
317 flatten(expected);
318 CHECK_METHOD(cxer_enc_pdv, AsnValues.pdv_sx, expected);
319 CHECK_METHOD(cxer_enc_pdv, AsnValues.epdv_sx, expected);
320
321 expected := pdvstr_context_neg;
322 CHECK_METHOD(bxer_enc_pdv, AsnValues.pdv_cneg, expected);
323 CHECK_METHOD(bxer_enc_pdv, AsnValues.epdv_cneg, expected);
324 flatten(expected);
325 CHECK_METHOD(cxer_enc_pdv, AsnValues.pdv_cneg, expected);
326 CHECK_METHOD(cxer_enc_pdv, AsnValues.epdv_cneg, expected);
327
328 expected := pdvstr_xfer;
329 CHECK_METHOD(bxer_enc_pdv, AsnValues.pdv_xsx, expected);
330 CHECK_METHOD(bxer_enc_pdv, AsnValues.epdv_xsx, expected);
331 flatten(expected);
332 CHECK_METHOD(cxer_enc_pdv, AsnValues.pdv_xsx, expected);
333 CHECK_METHOD(cxer_enc_pdv, AsnValues.epdv_xsx, expected);
334
335 expected := pdvstr_fixed;
336 CHECK_METHOD(bxer_enc_pdv, AsnValues.pdv_fix, expected);
337 CHECK_METHOD(bxer_enc_pdv, AsnValues.epdv_fix, expected);
338 flatten(expected);
339 CHECK_METHOD(cxer_enc_pdv, AsnValues.pdv_fix, expected);
340 CHECK_METHOD(cxer_enc_pdv, AsnValues.epdv_fix, expected);
341 }
342
343 testcase decode_pdv() runs on ASN1
344 {
345 var Asn_pdv expected;
346
347 expected := AsnValues.pdv_sxs;
348 CHECK_DECODE2(pdv, pdvstr_syntaxes, Asn_pdv, expected);
349
350 expected := AsnValues.pdv_sx;
351 CHECK_DECODE2(pdv, pdvstr_syntax2, Asn_pdv, expected);
352
353 expected := AsnValues.pdv_pci;
354 CHECK_DECODE2(pdv, pdvstr_pci, Asn_pdv, expected);
355
356 expected := AsnValues.pdv_cneg;
357 CHECK_DECODE2(pdv, pdvstr_context_neg, Asn_pdv, expected);
358
359 expected := AsnValues.pdv_xsx;
360 CHECK_DECODE2(pdv, pdvstr_xfer, Asn_pdv, expected);
361
362 expected := AsnValues.pdv_fix;
363 CHECK_DECODE2(pdv, pdvstr_fixed, Asn_pdv, expected);
364 }
365
366
367
368
369 /**************************** EXTERNAL ****************************/
370 DECLARE_XER_ENCODERS(Asn_ext, ext);
371 DECLARE_EXER_ENCODERS(Asn_ext,ext)
372
373 type record extwrap {
374 Asn_ext SEQUENCE
375 }
376
377 DECLARE_XER_ENCODERS(extwrap, extw);
378 DECLARE_EXER_ENCODERS(extwrap,extw)
379
380 const charstring ext_octet_aligned :=
381 "<Asn-ext>\n" &
382 "\t<indirect-reference>66</indirect-reference>\n" &
383 "\t<encoding>\n" &
384 "\t\t<octet-aligned>DECAFBAD</octet-aligned>\n" &
385 "\t</encoding>\n" &
386 "</Asn-ext>\n";
387
388 const charstring ext_octet_aligned2 :=
389 "<Asn-ext>\n" &
390 "\t<indirect-reference>2</indirect-reference>\n" &
391 "\t<encoding>\n" &
392 "\t\t<octet-aligned>BABEFACE</octet-aligned>\n" &
393 "\t</encoding>\n" &
394 "</Asn-ext>\n";
395
396 const charstring ext_syntax_direct :=
397 "<Asn-ext>\n" &
398 "\t<direct-reference>2.7.18.28.18.28.45.90.45</direct-reference>\n" &
399 "\t<data-value-descriptor>using syntax, direct only</data-value-descriptor>\n" &
400 "\t<encoding>\n" &
401 "\t\t<octet-aligned>BAADF00D</octet-aligned>\n" &
402 "\t</encoding>\n" &
403 "</Asn-ext>\n";
404
405 const charstring ext_context_both :=
406 "<Asn-ext>\n" &
407 "\t<direct-reference>2.1.1</direct-reference>\n" &
408 "\t<indirect-reference>111</indirect-reference>\n" &
409 "\t<data-value-descriptor>using context negotiation, both</data-value-descriptor>\n" &
410 "\t<encoding>\n" &
411 "\t\t<octet-aligned>1337D00D</octet-aligned>\n" &
412 "\t</encoding>\n" &
413 "</Asn-ext>\n";
414
415
416 const charstring ext_octet_aligned_wrap :=
417 "<extwrap>\n" &
418 "\t<SEQUENCE>\n" &
419 "\t\t<indirect-reference>66</indirect-reference>\n" &
420 "\t\t<encoding>\n" &
421 "\t\t\t<octet-aligned>DECAFBAD</octet-aligned>\n" &
422 "\t\t</encoding>\n" &
423 "\t</SEQUENCE>\n" &
424 "</extwrap>\n\n";
425
426 const charstring ext_syntax_direct_wrap :=
427 "<extwrap>\n" &
428 "\t<SEQUENCE>\n" &
429 "\t\t<direct-reference>2.7.18.28.18.28.45.90.45</direct-reference>\n" &
430 "\t\t<data-value-descriptor>using syntax, direct only</data-value-descriptor>\n" &
431 "\t\t<encoding>\n" &
432 "\t\t\t<octet-aligned>BAADF00D</octet-aligned>\n" &
433 "\t\t</encoding>\n" &
434 "\t</SEQUENCE>\n" &
435 "</extwrap>\n\n";
436
437 const Asn_ext extval := {
438 { presentation_context_id := 66 },
439 omit,
440 'DECAFBAD'O
441 };
442
443 testcase encode_ext() runs on ASN1
444 {
445 var universal charstring expected := ext_octet_aligned;
446 CHECK_METHOD(bxer_enc_ext, extval, expected);
447 CHECK_METHOD(exer_enc_ext, extval, expected);
448 flatten(expected);
449 CHECK_METHOD(cxer_enc_ext, extval, expected);
450
451 expected := ext_octet_aligned2;
452 CHECK_METHOD(bxer_enc_ext, AsnValues.ext, expected);
453 flatten(expected);
454 CHECK_METHOD(cxer_enc_ext, AsnValues.ext, expected);
455
456 expected := ext_syntax_direct;
457 CHECK_METHOD(bxer_enc_ext, AsnValues.ext_sx, expected);
458 flatten(expected);
459 CHECK_METHOD(cxer_enc_ext, AsnValues.ext_sx, expected);
460
461 expected := ext_context_both;
462 CHECK_METHOD(bxer_enc_ext, AsnValues.ext_cn, expected);
463 flatten(expected);
464 CHECK_METHOD(cxer_enc_ext, AsnValues.ext_cn, expected);
465
466 var extwrap xw := { SEQUENCE := extval }
467 expected := ext_octet_aligned_wrap;
468
469 CHECK_METHOD(bxer_enc_extw, xw, expected);
470 CHECK_METHOD(exer_enc_extw, xw, expected);
471 flatten(expected);
472 CHECK_METHOD(cxer_enc_extw, xw, expected & lf);
473 }
474
475 testcase decode_ext() runs on ASN1
476 {
477 var Asn_ext expected := extval;
478
479 CHECK_DECODE2(ext, ext_octet_aligned, Asn_ext, expected);
480
481 CHECK_DECODE2(ext, ext_octet_aligned2, Asn_ext, AsnValues.ext);
482
483 CHECK_DECODE2(ext, ext_syntax_direct, Asn_ext, AsnValues.ext_sx);
484
485 CHECK_DECODE2(ext, ext_context_both, Asn_ext, AsnValues.ext_cn);
486
487 var extwrap expectedw := { SEQUENCE := extval };
488 var universal charstring xwrap := ext_octet_aligned_wrap;
489 CHECK_DECODE2(extw, xwrap, extwrap, expectedw);
490
491 expectedw := { SEQUENCE := AsnValues.ext_sx };
492 xwrap := ext_syntax_direct_wrap;
493 CHECK_DECODE2(extw, xwrap, extwrap, expectedw);
494 }
495
496 /**************************** INTEGER ****************************/
497 DECLARE_XER_ENCODERS(Asn_int, aint);
498 DECLARE_EXER_ENCODERS(Asn_int,aint)
499
500 testcase encode_aint() runs on ASN1
501 {
502 var Asn_int intval := -137;
503 var universal charstring expected := "<Asn-int>-137</Asn-int>";
504 // "<Asn-int/>";
505 // It can never do that. Unbound should cause an error.
506 CHECK_METHOD(cxer_enc_aint, intval, expected);
507 CHECK_METHOD(bxer_enc_aint, intval, expected & lf);
508 CHECK_METHOD(exer_enc_aint, intval, expected & lf);
509
510 expected := "<Asn-int>42</Asn-int>";
511 CHECK_METHOD(cxer_enc_aint, AsnValues.fourty_two, expected);
512 CHECK_METHOD(bxer_enc_aint, AsnValues.fourty_two, expected & lf);
513
514 expected := "<Asn-int>0</Asn-int>";
515 CHECK_METHOD(cxer_enc_aint, AsnValues.zarro, expected);
516 CHECK_METHOD(bxer_enc_aint, AsnValues.zarro, expected & lf);
517
518 intval := 0;
519 CHECK_METHOD(cxer_enc_aint, intval, expected);
520 CHECK_METHOD(bxer_enc_aint, intval, expected & lf);
521 CHECK_METHOD(exer_enc_aint, intval, expected & lf);
522
523 expected := "<Asn-int>602214179000000000000000</Asn-int>";
524 CHECK_METHOD(cxer_enc_aint, AsnValues.avogadro, expected);
525 CHECK_METHOD(bxer_enc_aint, AsnValues.avogadro, expected & lf);
526
527 // This is somewhat redundant because [bc]xer_enc_int doesn't encode
528 // a TTCN3 integer (see Txerint.ttcnpp for that), but an Asn_int.
529 intval := 602214179000000000000000;
530 CHECK_METHOD(cxer_enc_aint, intval, expected);
531 CHECK_METHOD(bxer_enc_aint, intval, expected & lf);
532 CHECK_METHOD(exer_enc_aint, intval, expected & lf);
533 }
534
535 testcase decode_aint() runs on ASN1
536 {
537 var integer expected;
538 const charstring one_three_seven := "<Asn-int>137</Asn-int>";
539 expected := 137;
540 CHECK_DECODE2(aint, one_three_seven, integer, expected);
541
542 const charstring minus_nine := "<Asn-int>-9</Asn-int>";
543 expected := -9;
544 CHECK_DECODE2(aint, minus_nine, integer, expected);
545
546 const charstring fourtytwo := "<Asn-int>42</Asn-int>";
547 CHECK_DECODE2(aint, fourtytwo, integer, AsnValues.fourty_two);
548
549 const charstring nix := "<Asn-int>0</Asn-int>";
550 CHECK_DECODE2(aint, nix, integer, AsnValues.zarro);
551 const charstring minix := "<Asn-int>-0</Asn-int>";
552 CHECK_DECODE2(aint, minix, integer, AsnValues.zarro);
553
554 const charstring avo := "<Asn-int>602214179000000000000000</Asn-int>";
555 expected := 602214179000000000000000;
556 CHECK_DECODE2(aint, avo, Asn_int, expected);
557
558 const charstring empty_int := "<Asn-int/>";
559 var octetstring bytes;
560 var integer rv := u2o("UTF-8", empty_int, bytes);
561 MUST_UNBOUND(bxer_dec_aint(bytes)); // can't check with ==
562 }
563
564 /**************************** NULL ****************************/
565 DECLARE_XER_ENCODERS(Asn_nul, nul);
566 DECLARE_EXER_ENCODERS(Asn_nul,nul)
567
568 testcase encode_nul() runs on ASN1
569 {
570 var Asn_nul nulval := NULL;
571 var universal charstring expected := "<Asn-nul/>";
572 CHECK_METHOD(cxer_enc_nul, nulval, expected);
573 CHECK_METHOD(bxer_enc_nul, nulval, expected & lf);
574 CHECK_METHOD(exer_enc_nul, nulval, expected & lf);
575 }
576
577 testcase decode_nul() runs on ASN1
578 {
579 const charstring nullstr := "<Asn-nul/>";
580 var Asn_nul expected := NULL;
581 CHECK_DECODE2(nul, nullstr, Asn_nul, expected);
582 }
583
584 /**************************** OBJECT IDENTIFIER ****************************/
585 DECLARE_XER_ENCODERS(Asn_oid, oid);
586 DECLARE_EXER_ENCODERS(Asn_oid,oid)
587
588 const charstring oidstr_empty := "<Asn-oid/>";
589 const charstring oidstr_etsiMobNet := "<Asn-oid>0.4.0.0.1</Asn-oid>";
590 const charstring oidstr_pi := "<Asn-oid>1.3.14.15.9.2.6.5.3.5.8.9.7.9.3.2.3.8.4.6.2.6.4.3.3</Asn-oid>";
591 const charstring oidstr_e := "<Asn-oid>2.7.18.28.18.28.45.90.45</Asn-oid>";
592 const charstring oidstr_ericsson_testing := "<Asn-oid>0.4.0.127.0.5.0</Asn-oid>";
593 const charstring oidstr_etsi_solo := "<Asn-oid>0.4.0</Asn-oid>";
594 const charstring oidstr_ber := "<Asn-oid>2.1.1</Asn-oid>";
595 const charstring oidstr_cer := "<Asn-oid>2.6.6.1.2.4.4</Asn-oid>";
596
597 const Asn_oid etsiMobNet := objid{ itu_t identified_organization etsi(0) mobile_domain(0) umts_Network(1) }
598
599 testcase encode_oid() runs on ASN1
600 {
601 var Asn_oid noid;
602 var universal charstring expected := oidstr_empty;
603
604 // unbound! CHECK_METHOD(cxer_enc_oid, noid, expected);
605 // unbound! CHECK_METHOD(bxer_enc_oid, noid, expected & lf);
606
607 expected := oidstr_etsiMobNet;
608
609 expected := oidstr_pi
610 CHECK_METHOD(cxer_enc_oid, pi_oid, expected);
611 CHECK_METHOD(bxer_enc_oid, pi_oid, expected & lf);
612 CHECK_METHOD(exer_enc_oid, pi_oid, expected & lf);
613
614 expected := oidstr_e;
615 CHECK_METHOD(cxer_enc_oid, e_oid, expected);
616 CHECK_METHOD(bxer_enc_oid, e_oid, expected & lf);
617 CHECK_METHOD(exer_enc_oid, e_oid, expected & lf);
618
619 // { itu-t identified-organization etsi(0) reserved(127) etsi-identified-organization(0) ericsson(5) testing(0) }
620 expected := oidstr_ericsson_testing;
621 CHECK_METHOD(cxer_enc_oid, ericsson_testing, expected);
622 CHECK_METHOD(bxer_enc_oid, ericsson_testing, expected & lf);
623 CHECK_METHOD(exer_enc_oid, ericsson_testing, expected & lf);
624
625 expected := oidstr_etsi_solo;
626 CHECK_METHOD(cxer_enc_oid, etsi_solo, expected);
627 CHECK_METHOD(bxer_enc_oid, etsi_solo, expected & lf);
628 CHECK_METHOD(exer_enc_oid, etsi_solo, expected & lf);
629
630 expected := oidstr_ber;
631 CHECK_METHOD(cxer_enc_oid, ber_oid, expected);
632 CHECK_METHOD(bxer_enc_oid, ber_oid, expected & lf);
633 CHECK_METHOD(exer_enc_oid, ber_oid, expected & lf);
634
635 expected := oidstr_cer;
636 CHECK_METHOD(cxer_enc_oid, cer_oid, expected);
637 CHECK_METHOD(bxer_enc_oid, cer_oid, expected & lf);
638 CHECK_METHOD(exer_enc_oid, cer_oid, expected & lf);
639 }
640
641 testcase decode_oid() runs on ASN1
642 {
643 var Asn_oid expected;
644 //compiler error, must have at least two components := objid { 1 };
645 //CHECK_DECODE2(oid, oidstr_empty, Asn_oid, expected);
646
647 expected := etsiMobNet;
648 CHECK_DECODE2(oid, oidstr_etsiMobNet, Asn_oid, expected);
649
650 expected := pi_oid;
651 CHECK_DECODE2(oid, oidstr_pi, Asn_oid, expected);
652
653 expected := e_oid;
654 CHECK_DECODE2(oid, oidstr_e, Asn_oid, expected);
655
656 expected := ericsson_testing;
657 CHECK_DECODE2(oid, oidstr_ericsson_testing, Asn_oid, expected);
658
659 expected := etsi_solo;
660 CHECK_DECODE2(oid, oidstr_etsi_solo, Asn_oid, expected);
661
662 expected := ber_oid;
663 CHECK_DECODE2(oid, oidstr_ber, Asn_oid, expected);
664
665 expected := cer_oid;
666 CHECK_DECODE2(oid, oidstr_cer, Asn_oid, expected);
667 }
668
669 /**************************** RELATIVE OBJECT IDENTIFIER ****************************/
670 DECLARE_XER_ENCODERS(Asn_roid, roid);
671 DECLARE_EXER_ENCODERS(Asn_roid,roid)
672
673 testcase encode_roid() runs on ASN1
674 {
675 var Asn_oid roidval;
676 var universal charstring expected := "<Asn-roid/>";
677 // unbound! CHECK_METHOD(cxer_enc_roid, roidval, expected);
678 // unbound! CHECK_METHOD(bxer_enc_roid, roidval, expected & lf);
679
680 roidval := objid {iso(1) member_body(2) bsi(826) disc(0) ericsson(1249)};
681 expected := "<Asn-roid>1.2.826.0.1249</Asn-roid>";
682 CHECK_METHOD(cxer_enc_roid, roidval, expected);
683 CHECK_METHOD(bxer_enc_roid, roidval, expected & lf);
684 CHECK_METHOD(exer_enc_roid, roidval, expected & lf);
685
686 CHECK_METHOD(cxer_enc_roid, AsnValues.zoid, expected);
687 CHECK_METHOD(bxer_enc_roid, AsnValues.zoid, expected & lf);
688 }
689
690 testcase decode_roid() runs on ASN1
691 {
692 var Asn_oid expected;
693 expected := objid {iso(1) member_body(2) bsi(826) disc(0) ericsson(1249)};
694 CHECK_DECODE2(roid, "<Asn-roid>1.2.826.0.1249</Asn-roid>", Asn_oid, expected);
695 }
696
697 /**************************** OCTET STRING ****************************/
698 DECLARE_XER_ENCODERS(Asn_os,os)
699 DECLARE_EXER_ENCODERS(Asn_os,os)
700
701 const charstring ostr_1111 := "<Asn-os>00001111</Asn-os>";
702 const charstring ostr_empty := "<Asn-os/>";
703 const charstring ostr_0123 := "<Asn-os>00112233</Asn-os>";
704
705 testcase encode_os() runs on ASN1 // OCTET STRING
706 {
707 var Asn_os osval := '00001111'O;
708 var universal charstring expected := ostr_1111;
709 //var charstring encoded := bxer_enc_bs(bsval);
710 CHECK_METHOD(cxer_enc_os, osval, expected);
711 CHECK_METHOD(bxer_enc_os, osval, expected & lf);
712 CHECK_METHOD(exer_enc_os, osval, expected & lf);
713
714 osval := ''O;
715 expected := ostr_empty;
716 CHECK_METHOD(cxer_enc_os, osval, expected);
717 CHECK_METHOD(bxer_enc_os, osval, expected & lf);
718 CHECK_METHOD(exer_enc_os, osval, expected & lf);
719 // still empty expected
720 CHECK_METHOD(cxer_enc_os, AsnValues.os0, expected);
721 CHECK_METHOD(bxer_enc_os, AsnValues.os0, expected & lf);
722
723 expected := ostr_0123;
724 CHECK_METHOD(cxer_enc_os, AsnValues.os, expected);
725 CHECK_METHOD(bxer_enc_os, AsnValues.os, expected & lf);
726 }
727
728 testcase decode_os() runs on ASN1 // OCTET STRING
729 {
730 var Asn_os expected;
731
732 expected := '00001111'O;
733 CHECK_DECODE2(os, ostr_1111, Asn_os, expected);
734
735 expected := ''O;
736 CHECK_DECODE2(os, ostr_empty, Asn_os, expected);
737
738 expected := AsnValues.os
739 CHECK_DECODE2(os, ostr_0123, Asn_os, expected);
740 }
741
742 /**************************** REAL ****************************/
743 DECLARE_XER_ENCODERS(Asn_real, real);
744 DECLARE_EXER_ENCODERS(Asn_real,real)
745
746 const charstring floatstr_pi := "<Asn-real>3.141593</Asn-real>";
747 const charstring floatstr_longpi := "<Asn-real>3.14159265358979</Asn-real>";
748
749 testcase encode_real() runs on ASN1
750 {
751 var Asn_real rval := 3.1415926;
752 var universal charstring expected := floatstr_pi;
753 // "<Asn-real/>";
754 // It can never do that. Unbound should cause an error.
755 CHECK_METHOD(cxer_enc_real, rval, expected);
756 CHECK_METHOD(bxer_enc_real, rval, expected & lf);
757 CHECK_METHOD(exer_enc_real, rval, expected & lf);
758 // TODO
759 CHECK_METHOD(cxer_enc_real, AsnValues.pi, expected);
760 CHECK_METHOD(bxer_enc_real, AsnValues.pi, expected & lf);
761 }
762
763 testcase decode_real() runs on ASN1
764 {
765 var float expected := 3.141593;
766
767 CHECK_DECODE2(real, floatstr_pi, float, expected);
768
769 CHECK_DECODE2(real, floatstr_longpi, float, AsnValues.pi);
770 }
771
772 /**************************** Strings ****************************/
773 DECLARE_XER_ENCODERS(Asn_ia5, ia5s);
774 DECLARE_EXER_ENCODERS(Asn_ia5,ia5s)
775
776 const charstring ia5_yay := "<Asn-ia5>Yay!</Asn-ia5>\n";
777 const charstring ia5_cthulhu := "<Asn-ia5>Ia5! Ia5! Cthulhu fhtagn!</Asn-ia5>\n";
778 const charstring ia5_empty := "<Asn-ia5/>\n";
779 const charstring ia5_bonafide := "<Asn-ia5>A bona fide IA5String</Asn-ia5>\n";
780
781 testcase encode_ia5str() runs on ASN1
782 {
783 var Asn_ia5 rval := "Yay!";
784 var universal charstring expected := ia5_yay;
785 CHECK_METHOD(cxer_enc_ia5s, rval, expected);
786 CHECK_METHOD(bxer_enc_ia5s, rval, expected & lf);
787 CHECK_METHOD(exer_enc_ia5s, rval, expected & lf);
788
789 expected := ia5_cthulhu;
790 CHECK_METHOD(cxer_enc_ia5s, AsnValues.ia5val, expected);
791 CHECK_METHOD(bxer_enc_ia5s, AsnValues.ia5val, expected & lf);
792
793 expected := ia5_empty;
794 CHECK_METHOD(cxer_enc_ia5s, AsnValues.ia6val, expected);
795 CHECK_METHOD(bxer_enc_ia5s, AsnValues.ia6val, expected & lf);
796
797 expected := ia5_bonafide;
798 CHECK_METHOD(cxer_enc_ia5s, AsnValues.ia7val, expected);
799 CHECK_METHOD(bxer_enc_ia5s, AsnValues.ia7val, expected & lf);
800
801 expected := ia5_empty;
802 CHECK_METHOD(cxer_enc_ia5s, AsnValues.ia8val, expected);
803 CHECK_METHOD(bxer_enc_ia5s, AsnValues.ia8val, expected & lf);
804 }
805
806 testcase decode_ia5str() runs on ASN1
807 {
808 var charstring expected;
809
810 expected := "Yay!";
811 CHECK_DECODE2(ia5s, ia5_yay, Asn_ia5, expected);
812
813 expected := AsnValues.ia5val;
814 CHECK_DECODE2(ia5s, ia5_cthulhu, Asn_ia5, expected);
815
816 expected := AsnValues.ia6val;
817 CHECK_DECODE2(ia5s, ia5_empty, Asn_ia5, expected);
818
819 expected := AsnValues.ia7val;
820 CHECK_DECODE2(ia5s, ia5_bonafide, Asn_ia5, expected);
821 }
822
823 /**************************** UTF8String ****************************/
824 DECLARE_XER_ENCODERS(Asn_utf, utf);
825 DECLARE_EXER_ENCODERS(Asn_utf,utf)
826
827 // XER encoding of "UTF8 A'RVI'ZTU"RO"" TU:KO:RFU'RO'GE'P"
828 const universal charstring utf_arviz_turo :=
829 "<Asn-utf>UTF8 " & Aacute & "RV" & Iacute & "ZT" & Udouble & "R" & Odouble &
830 " T" & Uuml & "K" & Ouml & "RF" & Uacute & "R" & Oacute & "G" & Eacute & "P</Asn-utf>\n";
831
832 // XER encoding of an empty string
833 const charstring utf_empty := "<Asn-utf/>\n";
834
835 // XER encoding which needs to do a lot of escaping
836 const universal charstring utf_esc_oss :=
837 "<Asn-utf>UTF8 escapology\n<soh/><stx/><etx/><eot/><enq/><ack/><bel/><bs/>\t\n<vt/><ff/>\r<so/><si/><dle/><dc1/><dc2/><dc3/><dc4/><nak/><syn/><etb/><can/><em/><sub/><esc/><is4/><is3/><is2/><is1/>" &
838 //these would be the UTF8 bytes: "\xc2\x84\xC5\x82\xE4\x89\x82\xF0\x94\x89\x82\xF4\x84\x89\x82</Asn-utf>\n";
839 //but universal charstring uses UCS4
840 char(0,0,0,132) & char(0,0,1,66) & char(0,0,66,66) & char(0,1,66,66) & char(0,16,66,66) & "</Asn-utf>\n";
841
842 // An alternative representation which should decode into the same value
843 const universal charstring utf_esc_oss_alt :=
844 "<Asn-utf>UTF8 escapology\n<soh/><stx/><etx/><eot/><enq/><ack/><bel/><bs/>\t\n<vt/><ff/>\r<so/><si/><dle/><dc1/><dc2/><dc3/><dc4/><nak/><syn/><etb/><can/><em/><sub/><esc/><is4/><is3/><is2/><is1/>" &
845 // libxml2 handles &#n; and &#xn; for us. But it won't accept control characters.
846 "&#x84;&#x0142;&#x4242;&#x00014242;&#x00104242;" & "</Asn-utf>\n";
847
848 const universal charstring utf_bogus :=
849 "<Asn-utf>UTF8 escapology\n<doh/><stx/><etx/><eot/><enq/><ack/><bel/><bs/>\t\n<vt/><ff/>\r<so/><si/><dle/><dc1/><dc2/><dc3/><dc4/><nak/><syn/><etb/><can/><em/><sub/><esc/><is4/><is3/><is2/><is1/>" &
850 //--------------------------^^^
851 char(0,0,0,132) & char(0,0,1,66) & char(0,0,66,66) & char(0,1,66,66) & char(0,16,66,66) & "</Asn-utf>\n";
852
853 // XER encoding which needs to do a lot of escaping:
854 // "UTF8 " followed by "\x01\x02...\x1F" then \x84\x0142\x4242\x00014242\x00104242
855 //const charstring utf_esc :=
856 //"<Asn-utf>UTF8\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" &
857 //"\xc2\x84\xC5\x82\xE4\x89\x82\xF0\x94\x89\x82\xF4\x84\x89\x82</Asn-utf>\n";
858
859 // XER encoding of an HTML fragment
860 const charstring utf_html :=
861 "<Asn-utf>&lt;html&gt;&lt;body onload=&apos;javascript.alert(&quot;UTF8&quot;)&apos;&gt;&amp;nbsp;&lt;/body&gt;&lt;/html&gt;</Asn-utf>\n";
862
863 testcase encode_utf() runs on ASN1
864 {
865 // Encode "UTF8 A'RVI'ZTU"RO"" TU:KO:RFU'RO'GE'P"
866 var universal charstring expected := utf_arviz_turo;
867 CHECK_METHOD(cxer_enc_utf, AsnValues.val_utf, expected);
868 CHECK_METHOD(bxer_enc_utf, AsnValues.val_utf, expected & lf);
869
870 // Encode an empty string
871 expected := utf_empty;
872 CHECK_METHOD(cxer_enc_utf, AsnValues.blank_utf, expected);
873 CHECK_METHOD(bxer_enc_utf, AsnValues.blank_utf, expected & lf);
874
875 // Encode a string with lots of characters that need to be escaped:
876 expected := utf_esc_oss;
877 CHECK_METHOD(cxer_enc_utf, AsnValues.esc_utf, expected);
878 CHECK_METHOD(bxer_enc_utf, AsnValues.esc_utf, expected & lf);
879
880 expected := utf_html;
881 CHECK_METHOD(cxer_enc_utf, AsnValues.html_utf, expected);
882 CHECK_METHOD(bxer_enc_utf, AsnValues.html_utf, expected & lf);
883 }
884
885 testcase decode_utf() runs on ASN1
886 {
887 var Asn_utf expected;
888
889 expected := AsnValues.val_utf;
890 CHECK_DECODE2(utf, utf_arviz_turo, Asn_utf, expected);
891
892 expected := AsnValues.blank_utf;
893 CHECK_DECODE2(utf, utf_empty, Asn_utf, expected);
894
895 expected := AsnValues.esc_utf_dec;
896 CHECK_DECODE2(utf, utf_esc_oss, Asn_utf, expected);
897 CHECK_DECODE2(utf, utf_esc_oss_alt, Asn_utf, expected);
898 // Dynamic testcase error, as expected:
899 //CHECK_DECODE2(utf, utf_bogus, Asn_utf, expected);
900
901 expected := AsnValues.html_utf;
902 CHECK_DECODE2(utf, utf_html, Asn_utf, expected);
903 }
904
905
906 /**************** Other restricted character string types ****************/
907 DECLARE_XER_ENCODERS(Asn_bmp, bmp);
908 DECLARE_EXER_ENCODERS(Asn_bmp,bmp)
909 DECLARE_XER_ENCODERS(Asn_gen, gen);
910 DECLARE_EXER_ENCODERS(Asn_gen,gen)
911 DECLARE_XER_ENCODERS(Asn_gra, gra);
912 DECLARE_EXER_ENCODERS(Asn_gra,gra)
913 DECLARE_XER_ENCODERS(Asn_num, num);
914 DECLARE_EXER_ENCODERS(Asn_num,num)
915 DECLARE_XER_ENCODERS(Asn_prn, prn);
916 DECLARE_EXER_ENCODERS(Asn_prn,prn)
917 DECLARE_XER_ENCODERS(Asn_ttx, ttx);
918 DECLARE_EXER_ENCODERS(Asn_ttx,ttx)
919 DECLARE_XER_ENCODERS(Asn_uni, uni);
920 DECLARE_EXER_ENCODERS(Asn_uni,uni)
921 DECLARE_XER_ENCODERS(Asn_vtx, vtx);
922 DECLARE_EXER_ENCODERS(Asn_vtx,vtx)
923 DECLARE_XER_ENCODERS(Asn_vis, vis);
924 DECLARE_EXER_ENCODERS(Asn_vis,vis)
925
926 DECLARE_XER_ENCODERS(universal charstring, ustr);
927
928 const charstring str_bmp := "<Asn-bmp>Ich wei&#xDF; es! Basic Multilingual Plane.</Asn-bmp>\n";
929 const charstring str_bmp0 := "<Asn-bmp/>\n";
930 const charstring str_bmp_esc :=
931 "<Asn-bmp>BMP\n<nul/><soh/><stx/><etx/><eot/><enq/><ack/><bel/><bs/>\t\n<vt/><ff/>\r<so/><si/><dle/><dc1/><dc2/><dc3/><dc4/><nak/><syn/><etb/><can/><em/><sub/><esc/><is4/><is3/><is2/><is1/>&#x84;&#x0142;&#x4242;</Asn-bmp>\n";
932 const charstring str_bmp_html :=
933 "<Asn-bmp>&lt;html&gt;&lt;body onload=&apos;javascript.alert(&quot;BMP&quot;)&apos;&gt;&amp;nbsp;&lt;/body&gt;&lt;/html&gt;</Asn-bmp>\n";
934
935 const charstring str_gen0 := "<Asn-gen/>\n";
936 const charstring str_gen := "<Asn-gen>Who is General Failure and why is he reading my disk ?</Asn-gen>\n";
937
938 const charstring str_gra0 := "<Asn-gra/>\n";
939 const charstring str_gra := "<Asn-gra>Graphic</Asn-gra>\n";
940
941 const charstring str_num0 := "<Asn-num/>\n";
942 const charstring str_num := "<Asn-num>150130937545296572356771972164254457814047970568738777235893533016064</Asn-num>\n";
943
944 const charstring str_prn0 := "<Asn-prn/>\n";
945 const charstring str_prn := "<Asn-prn>Printable</Asn-prn>\n";
946
947 const charstring str_ttx0 := "<Asn-ttx/>\n";
948 const charstring str_ttx := "<Asn-ttx>Teletex</Asn-ttx>\n";
949
950 const charstring str_uni0 := "<Asn-uni/>\n";
951 const charstring str_uni := "<Asn-uni>Universal &#x7070;&#x7FBD;&#xE1;rv&#xED;zt&#x0171;r&#x0151; t&#xFC;k&#xF6;rf&#xFA;r&#xF3;g&#xE9;p</Asn-uni>\n";
952 const charstring str_uni_esc := "<Asn-uni>Universal escapology\n<nul/><soh/><stx/><etx/><eot/><enq/><ack/><bel/><bs/>\t\n<vt/><ff/>\r<so/><si/><dle/><dc1/><dc2/><dc3/><dc4/><nak/><syn/><etb/><can/><em/><sub/><esc/><is4/><is3/><is2/><is1/>&#x84;&#x0142;&#x4242;&#x014242;&#x104242;</Asn-uni>\n";
953 //&#x00;&#x84;&#x0142;&#x4242;
954 const charstring str_uni_html:= "<Asn-uni>&lt;html&gt;&lt;body onload=&apos;javascript.alert(&quot;Universal&quot;)&apos;&gt;&amp;nbsp;&lt;/body&gt;&lt;/html&gt;</Asn-uni>\n";
955
956 const charstring str_vtx0 := "<Asn-vtx/>\n";
957 const charstring str_vtx := "<Asn-vtx>Videotex</Asn-vtx>\n";
958
959 const charstring str_vis0 := "<Asn-vis/>\n";
960 const charstring str_vis := "<Asn-vis>Visible (ISO646)</Asn-vis>\n";
961
962
963
964 testcase encode_restricted_strings() runs on ASN1
965 {
966 var universal charstring expected;
967
968 expected := str_bmp;
969 CHECK_METHOD(cxer_enc_bmp, AsnValues.b1val, expected);
970 CHECK_METHOD(bxer_enc_bmp, AsnValues.b1val, expected & lf);
971
972 expected := str_bmp0;
973 CHECK_METHOD(cxer_enc_bmp, AsnValues.b0val, expected);
974 CHECK_METHOD(bxer_enc_bmp, AsnValues.b0val, expected & lf);
975
976 expected := str_bmp_esc;
977 CHECK_METHOD(cxer_enc_bmp, AsnValues.esc_bmp, expected);
978 CHECK_METHOD(bxer_enc_bmp, AsnValues.esc_bmp, expected & lf);
979
980 expected := str_bmp_html;
981 CHECK_METHOD(cxer_enc_bmp, AsnValues.html_bmp, expected);
982 CHECK_METHOD(bxer_enc_bmp, AsnValues.html_bmp, expected & lf);
983
984 //----------------------------------------------------
985 expected := str_gen0;
986 CHECK_METHOD(cxer_enc_gen, AsnValues.g0val, expected);
987 CHECK_METHOD(bxer_enc_gen, AsnValues.g0val, expected & lf);
988
989 expected := str_gen;
990 CHECK_METHOD(cxer_enc_gen, AsnValues.g1val, expected);
991 CHECK_METHOD(bxer_enc_gen, AsnValues.g1val, expected & lf);
992
993 //----------------------------------------------------
994 expected := str_gra0;
995 CHECK_METHOD(cxer_enc_gra, AsnValues.gr0val, expected);
996 CHECK_METHOD(bxer_enc_gra, AsnValues.gr0val, expected & lf);
997
998 expected := str_gra;
999 CHECK_METHOD(cxer_enc_gra, AsnValues.gr1val, expected);
1000 CHECK_METHOD(bxer_enc_gra, AsnValues.gr1val, expected & lf);
1001
1002 //----------------------------------------------------
1003 expected := str_num0;
1004 CHECK_METHOD(cxer_enc_num, AsnValues.blank_num, expected);
1005 CHECK_METHOD(bxer_enc_num, AsnValues.blank_num, expected & lf);
1006
1007 expected := str_num;
1008 CHECK_METHOD(cxer_enc_num, AsnValues.val_num, expected);
1009 CHECK_METHOD(bxer_enc_num, AsnValues.val_num, expected & lf);
1010
1011 //----------------------------------------------------
1012 expected := str_prn0;
1013 CHECK_METHOD(cxer_enc_prn, AsnValues.blank_prn, expected);
1014 CHECK_METHOD(bxer_enc_prn, AsnValues.blank_prn, expected & lf);
1015
1016 expected := str_prn;
1017 CHECK_METHOD(cxer_enc_prn, AsnValues.val_prn, expected);
1018 CHECK_METHOD(bxer_enc_prn, AsnValues.val_prn, expected & lf);
1019
1020 //----------------------------------------------------
1021 expected := str_ttx0;
1022 CHECK_METHOD(cxer_enc_ttx, AsnValues.blank_ttx, expected);
1023 CHECK_METHOD(bxer_enc_ttx, AsnValues.blank_ttx, expected & lf);
1024
1025 expected := str_ttx;
1026 CHECK_METHOD(cxer_enc_ttx, AsnValues.val_ttx, expected);
1027 CHECK_METHOD(bxer_enc_ttx, AsnValues.val_ttx, expected & lf);
1028
1029 //----------------------------------------------------
1030 expected := str_uni0;
1031 CHECK_METHOD(cxer_enc_uni, AsnValues.blank_uni, expected);
1032 CHECK_METHOD(bxer_enc_uni, AsnValues.blank_uni, expected & lf);
1033
1034 expected := str_uni_esc;
1035 CHECK_METHOD(cxer_enc_uni, AsnValues.esc_uni, expected);
1036 CHECK_METHOD(bxer_enc_uni, AsnValues.esc_uni, expected & lf);
1037
1038 expected := str_uni;
1039 CHECK_METHOD(cxer_enc_uni, AsnValues.val_uni, expected);
1040 CHECK_METHOD(bxer_enc_uni, AsnValues.val_uni, expected & lf);
1041
1042 expected := str_uni_html;
1043 CHECK_METHOD(cxer_enc_uni, AsnValues.html_uni, expected);
1044 CHECK_METHOD(bxer_enc_uni, AsnValues.html_uni, expected & lf);
1045
1046 //----------------------------------------------------
1047 expected := str_vtx0;
1048 CHECK_METHOD(cxer_enc_vtx, AsnValues.blank_vtx, expected);
1049 CHECK_METHOD(bxer_enc_vtx, AsnValues.blank_vtx, expected & lf);
1050
1051 expected := str_vtx;
1052 CHECK_METHOD(cxer_enc_vtx, AsnValues.val_vtx, expected);
1053 CHECK_METHOD(bxer_enc_vtx, AsnValues.val_vtx, expected & lf);
1054
1055 //----------------------------------------------------
1056 expected := str_vis0;
1057 CHECK_METHOD(cxer_enc_vis, AsnValues.blank_vis, expected);
1058 CHECK_METHOD(bxer_enc_vis, AsnValues.blank_vis, expected & lf);
1059
1060 expected := str_vis;
1061 CHECK_METHOD(cxer_enc_vis, AsnValues.val_vis, expected);
1062 CHECK_METHOD(bxer_enc_vis, AsnValues.val_vis, expected & lf);
1063 }
1064
1065 testcase decode_restricted_strings() runs on ASN1
1066 {
1067 {
1068 var Asn_bmp expected;
1069
1070 expected := AsnValues.b1val;
1071 CHECK_DECODE(cxer_dec_bmp, str_bmp, universal charstring, expected/*AsnValues.b1val*/);
1072 CHECK_DECODE(bxer_dec_bmp, str_bmp, universal charstring, expected /*& lf*/);
1073
1074 expected := AsnValues.b0val;
1075 CHECK_DECODE(cxer_dec_bmp, str_bmp0, universal charstring, expected);
1076 CHECK_DECODE(bxer_dec_bmp, str_bmp0, universal charstring, expected /*& lf*/);
1077
1078 expected := AsnValues.esc_bmp_dec;
1079 CHECK_DECODE(cxer_dec_bmp, str_bmp_esc, universal charstring, expected);
1080 CHECK_DECODE(bxer_dec_bmp, str_bmp_esc, universal charstring, expected /*& lf*/);
1081
1082 expected := AsnValues.html_bmp;
1083 CHECK_DECODE(cxer_dec_bmp, str_bmp_html, universal charstring, expected);
1084 CHECK_DECODE(bxer_dec_bmp, str_bmp_html, universal charstring, expected /*& lf*/);
1085 }
1086 //----------------------------------------------------
1087 {
1088 var Asn_gen expected := AsnValues.g0val;
1089 CHECK_DECODE(cxer_dec_gen, str_gen0, Asn_gen, expected);
1090 CHECK_DECODE(bxer_dec_gen, str_gen0, Asn_gen, expected);
1091
1092 expected := AsnValues.g1val;
1093 CHECK_DECODE(cxer_dec_gen, str_gen, Asn_gen, expected);
1094 CHECK_DECODE(bxer_dec_gen, str_gen, Asn_gen, expected);
1095 }
1096
1097 //----------------------------------------------------
1098 {
1099 var Asn_gra expected := AsnValues.gr0val;
1100 CHECK_DECODE(cxer_dec_gra, str_gra0, Asn_gra, expected);
1101 CHECK_DECODE(bxer_dec_gra, str_gra0, Asn_gra, expected);
1102
1103 expected := AsnValues.gr1val;
1104 CHECK_DECODE(cxer_dec_gra, str_gra, Asn_gra, expected);
1105 CHECK_DECODE(bxer_dec_gra, str_gra, Asn_gra, expected);
1106 }
1107
1108 //----------------------------------------------------
1109 {
1110 var Asn_num expected := AsnValues.blank_num;
1111 CHECK_DECODE3(num, str_num0, expected); // checks both BXER and CXER
1112
1113 expected := AsnValues.val_num;
1114 CHECK_DECODE3(num, str_num, expected);
1115 }
1116
1117 //----------------------------------------------------
1118 {
1119 var Asn_prn expected := AsnValues.blank_prn;
1120 CHECK_DECODE3(prn, str_prn0, expected);
1121
1122 expected := AsnValues.val_prn;
1123 CHECK_DECODE3(prn, str_prn, expected);
1124 }
1125
1126 //----------------------------------------------------
1127 {
1128 var Asn_ttx expected := AsnValues.blank_ttx;
1129 CHECK_DECODE3(ttx, str_ttx0, expected);
1130
1131 expected := AsnValues.val_ttx;
1132 CHECK_DECODE3(ttx, str_ttx, expected);
1133 }
1134
1135 //----------------------------------------------------
1136 {
1137 var Asn_uni expected := AsnValues.blank_uni;
1138 CHECK_DECODE3(uni, str_uni0, expected);
1139
1140 expected := AsnValues.esc_uni_dec;
1141 CHECK_DECODE3(uni, str_uni_esc, expected);
1142
1143 expected := AsnValues.val_uni;
1144 CHECK_DECODE3(uni, str_uni, expected);
1145
1146 expected := AsnValues.html_uni;
1147 CHECK_DECODE3(uni, str_uni_html, expected);
1148 }
1149
1150 //----------------------------------------------------
1151 {
1152 var Asn_vtx expected := AsnValues.blank_vtx;
1153 CHECK_DECODE3(vtx, str_vtx0, expected);
1154
1155 expected := AsnValues.val_vtx;
1156 CHECK_DECODE3(vtx, str_vtx, expected);
1157 }
1158
1159 //----------------------------------------------------
1160 {
1161 var Asn_vis expected := AsnValues.blank_vis;
1162 CHECK_DECODE3(vis, str_vis0, expected);
1163
1164 expected := AsnValues.val_vis;
1165 CHECK_DECODE3(vis, str_vis, expected);
1166 }
1167 }
1168
1169 /************ The big, scary, unrestricted CHARACTER STRING ************/
1170 DECLARE_XER_ENCODERS(Asn_unr, unr);
1171 DECLARE_EXER_ENCODERS(Asn_unr,unr)
1172
1173 const charstring str_unr_sxs :=
1174 "<Asn-unr>\n" &
1175 "\t<identification>\n" &
1176 "\t\t<syntaxes>\n" &
1177 "\t\t\t<abstract>1.3.14.15.9.2.6.5.3.5.8.9.7.9.3.2.3.8.4.6.2.6.4.3.3</abstract>\n" &
1178 "\t\t\t<transfer>2.7.18.28.18.28.45.90.45</transfer>\n" &
1179 "\t\t</syntaxes>\n" &
1180 "\t</identification>\n" &
1181 "\t<string-value>C3A17276C3AD7A74C5B172C5912074C3</string-value>\n" &
1182 "</Asn-unr>\n\n";
1183
1184 const charstring str_unr_sx :=
1185 "<Asn-unr>\n" &
1186 "\t<identification>\n" &
1187 "\t\t<syntax>1.3.14.15.9.2.6.5.3.5.8.9.7.9.3.2.3.8.4.6.2.6.4.3.3</syntax>\n" &
1188 "\t</identification>\n" &
1189 "\t<string-value>BC6BC3B67266C3BA72C3B367C3A970</string-value>\n" &
1190 "</Asn-unr>\n\n";
1191
1192 const charstring str_unr_pci :=
1193 "<Asn-unr>\n" &
1194 "\t<identification>\n" &
1195 "\t\t<presentation-context-id>42</presentation-context-id>\n" &
1196 "\t</identification>\n" &
1197 "\t<string-value>C3815256C38D5A54C5B052C5902054C3</string-value>\n" &
1198 "</Asn-unr>\n\n";
1199
1200 const charstring str_unr_cneg :=
1201 "<Asn-unr>\n" &
1202 "\t<identification>\n" &
1203 "\t\t<context-negotiation>\n" &
1204 "\t\t\t<presentation-context-id>17</presentation-context-id>\n" &
1205 "\t\t\t<transfer-syntax>2.1.1</transfer-syntax>\n" &
1206 "\t\t</context-negotiation>\n" &
1207 "\t</identification>\n" &
1208 "\t<string-value>9C4BC3965246C39A52C39347C38950</string-value>\n" &
1209 "</Asn-unr>\n\n";
1210
1211 const charstring str_unr_tsx :=
1212 "<Asn-unr>\n" &
1213 "\t<identification>\n" &
1214 "\t\t<transfer-syntax>2.1.1</transfer-syntax>\n" &
1215 "\t</identification>\n" &
1216 "\t<string-value>BEEE</string-value>\n" &
1217 "</Asn-unr>\n\n";
1218
1219 const charstring str_unr_fix :=
1220 "<Asn-unr>\n" &
1221 "\t<identification>\n" &
1222 "\t\t<fixed/>\n" &
1223 "\t</identification>\n" &
1224 "\t<string-value>" &
1225 "C3815256C38D5A54C5B052C5902054C39C4BC3965246C39A52C39347C38950" &
1226 "</string-value>\n" &
1227 "</Asn-unr>\n\n" ;
1228
1229 testcase encode_unr() runs on ASN1
1230 {
1231 var universal charstring expected;
1232
1233 expected := str_unr_sxs; // syntaxes
1234 CHECK_METHOD(bxer_enc_unr, val_unr_sxs, expected);
1235 CHECK_METHOD(exer_enc_unr, val_unr_sxs, expected);
1236 flatten(expected);
1237 CHECK_METHOD(cxer_enc_unr, val_unr_sxs, expected & lf);
1238
1239 expected := str_unr_sx; // syntax
1240 CHECK_METHOD(bxer_enc_unr, val_unr_sx, expected);
1241 CHECK_METHOD(exer_enc_unr, val_unr_sx, expected);
1242 flatten(expected);
1243 CHECK_METHOD(cxer_enc_unr, val_unr_sx, expected & lf);
1244
1245 expected := str_unr_pci; // presentation-context-id
1246 CHECK_METHOD(bxer_enc_unr, val_unr_pci, expected);
1247 CHECK_METHOD(exer_enc_unr, val_unr_pci, expected);
1248 flatten(expected);
1249 CHECK_METHOD(cxer_enc_unr, val_unr_pci, expected & lf);
1250
1251 expected := str_unr_cneg; // context-negotiation
1252 CHECK_METHOD(bxer_enc_unr, val_unr_cneg, expected);
1253 CHECK_METHOD(exer_enc_unr, val_unr_cneg, expected);
1254 flatten(expected);
1255 CHECK_METHOD(cxer_enc_unr, val_unr_cneg, expected & lf);
1256
1257 expected := str_unr_tsx; // transfer-syntax
1258 CHECK_METHOD(bxer_enc_unr, val_unr_tsx, expected);
1259 CHECK_METHOD(exer_enc_unr, val_unr_tsx, expected);
1260 flatten(expected);
1261 CHECK_METHOD(cxer_enc_unr, val_unr_tsx, expected & lf);
1262
1263
1264 expected := str_unr_fix; // fixed
1265 CHECK_METHOD(bxer_enc_unr, val_unr_fix, expected);
1266 CHECK_METHOD(exer_enc_unr, val_unr_fix, expected);
1267 flatten(expected);
1268 CHECK_METHOD(cxer_enc_unr, val_unr_fix, expected & lf);
1269 }
1270
1271 testcase decode_unr() runs on ASN1
1272 {
1273 var Asn_unr expected;
1274
1275 expected := val_unr_sxs;
1276 CHECK_DECODE2(unr, str_unr_sxs, Asn_unr, expected);
1277
1278 expected := val_unr_sx;
1279 CHECK_DECODE2(unr, str_unr_sx, Asn_unr, expected);
1280
1281 expected := val_unr_pci;
1282 CHECK_DECODE2(unr, str_unr_pci, Asn_unr, expected);
1283
1284 expected := val_unr_cneg;
1285 CHECK_DECODE2(unr, str_unr_cneg, Asn_unr, expected);
1286
1287 expected := val_unr_tsx;
1288 CHECK_DECODE2(unr, str_unr_tsx, Asn_unr, expected);
1289
1290 expected := val_unr_fix;
1291 CHECK_DECODE2(unr, str_unr_fix, Asn_unr, expected);
1292 }
1293
1294
1295
1296 /**************************** XXXX ****************************/
1297 DECLARE_XER_ENCODERS(LotsaText, softext);
1298 DECLARE_EXER_ENCODERS(LotsaText,softext)
1299
1300 testcase limerick() runs on ASN1
1301 {
1302 var LotsaText rval := AsnValues.limerick;
1303 var universal charstring expected :=
1304 "<LotsaText>\n" &
1305 "\t<VisibleString>There was a young fellow named Fisk</VisibleString>\n" &
1306 "\t<VisibleString>A swordsman, exceedingly brisk</VisibleString>\n" &
1307 "\t<VisibleString>So fast was his action</VisibleString>\n" &
1308 "\t<VisibleString>The Lorentz contraction</VisibleString>\n" &
1309 "\t<VisibleString>Reduced his rapier to a disc</VisibleString>\n" &
1310 "</LotsaText>\n\n";
1311 CHECK_METHOD(bxer_enc_softext, rval, expected);
1312 CHECK_METHOD(exer_enc_softext, rval, expected);
1313 flatten(expected);
1314 CHECK_METHOD(cxer_enc_softext, rval, expected & lf);
1315 // TODO
1316 }
1317
1318
1319
1320
1321 /**************************** XXXX ****************************
1322 DECLARE_XER_ENCODERS(Asn_xxxx, xxxx);
1323 DECLARE_EXER_ENCODERS(Asn_xxxx,xxxx)
1324
1325 testcase xxxx() runs on ASN1
1326 {
1327 var Asn_xxxx rval := xXxX;
1328 var yyyy expected := "<XXXX>3.141593</XXXX>";
1329 CHECK_METHOD(cxer_enc_xxxx, rval, expected);
1330 CHECK_METHOD(bxer_enc_xxxx, rval, expected & lf);
1331 CHECK_METHOD(exer_enc_xxxx, rval, expected & lf);
1332 // TODO
1333 }
1334
1335 --------------- >8 --------------- cut here
1336
1337 */
1338
1339 // An empty SEQUENCE
1340 DECLARE_XER_ENCODERS(NothingToSeeHere, nix);
1341 DECLARE_EXER_ENCODERS(NothingToSeeHere,nix)
1342
1343 const universal charstring emptyelement := "<NothingToSeeHere/>\n";
1344
1345 testcase encode_emptyrec() runs on ASN1
1346 {
1347
1348 CHECK_METHOD(cxer_enc_nix, AsnValues.move_along, emptyelement);
1349 CHECK_METHOD(bxer_enc_nix, AsnValues.move_along, emptyelement & lf);
1350 }
1351
1352 const universal charstring nonempty_element := "<NothingToSeeHere></NothingToSeeHere>\n";
1353 testcase decode_emptyrec() runs on ASN1
1354 {
1355 CHECK_DECODE2(nix, emptyelement, NothingToSeeHere, AsnValues.move_along);
1356 // Use of the empty-element form is required for Canonical XER.
1357 // Basic XER should accept it.
1358 CHECK_DECODE(bxer_dec_nix, nonempty_element, NothingToSeeHere, AsnValues.move_along);
1359 }
1360
1361 /**************************** choice ****************************/
1362 DECLARE_XER_ENCODERS(Something, smth);
1363 DECLARE_EXER_ENCODERS(Something,smth)
1364
1365 const charstring smth_bitstr :=
1366 "<Something>\n" &
1367 "\t<bitstr>01001000100001</bitstr>\n" &
1368 "</Something>\n\n";
1369
1370 const charstring smth_bool :=
1371 "<Something>\n" &
1372 "\t<booool><true/></booool>\n" &
1373 "</Something>\n\n";
1374
1375 const charstring smth_ebool :=
1376 "<Something>\n" &
1377 "\t<booool>true</booool>\n" &
1378 "</Something>\n\n";
1379
1380 const charstring smth_float :=
1381 "<Something>\n" &
1382 "\t<floating>3.141593</floating>\n" &
1383 "</Something>\n\n";
1384
1385 const charstring smth_barney :=
1386 "<Something>\n" &
1387 "\t<cartoon><barney/></cartoon>\n" &
1388 "</Something>\n\n";
1389
1390 const charstring smth_ebarney :=
1391 "<Something>\n" &
1392 "\t<cartoon>barney</cartoon>\n" &
1393 "</Something>\n\n";
1394
1395 const charstring smth_int :=
1396 "<Something>\n" &
1397 "\t<wholenum>42</wholenum>\n" &
1398 "</Something>\n\n";
1399
1400
1401 testcase encode_something() runs on ASN1
1402 {
1403 var universal charstring expected;
1404 {
1405 var Something eval := { bitstr := '01001000100001'B }
1406 expected := smth_bitstr;
1407 CHECK_METHOD(bxer_enc_smth, eval, expected);
1408 CHECK_METHOD(exer_enc_smth, eval, expected);
1409 CHECK_METHOD(exer_enc_smth, eval, expected);
1410 flatten(expected);
1411 CHECK_METHOD(cxer_enc_smth, eval, expected & lf);
1412 }
1413
1414 {
1415 var Something eval := { booool := true }
1416 expected := smth_ebool;
1417 CHECK_METHOD(exer_enc_smth, eval, expected);
1418 expected := smth_bool;
1419 CHECK_METHOD(bxer_enc_smth, eval, expected);
1420 flatten(expected);
1421 CHECK_METHOD(cxer_enc_smth, eval, expected & lf);
1422 }
1423
1424 {
1425 var Something eval := { floating := 3.141593 };
1426 expected := smth_float;
1427 CHECK_METHOD(bxer_enc_smth, eval, expected);
1428 CHECK_METHOD(exer_enc_smth, eval, expected);
1429 CHECK_METHOD(exer_enc_smth, eval, expected);
1430 flatten(expected);
1431 CHECK_METHOD(cxer_enc_smth, eval, expected & lf);
1432 }
1433
1434 {
1435 var Something neval := { wholenum := 42 };
1436 expected := smth_int;
1437 CHECK_METHOD(bxer_enc_smth, neval, expected);
1438 CHECK_METHOD(exer_enc_smth, neval, expected);
1439 CHECK_METHOD(exer_enc_smth, neval, expected);
1440 flatten(expected);
1441 CHECK_METHOD(cxer_enc_smth, neval, expected & lf);
1442 }
1443
1444 {
1445 var Something feval := { cartoon := barney };
1446 expected := smth_ebarney;
1447 CHECK_METHOD(exer_enc_smth, feval, expected);
1448 expected := smth_barney;
1449 CHECK_METHOD(bxer_enc_smth, feval, expected);
1450 flatten(expected);
1451 CHECK_METHOD(cxer_enc_smth, feval, expected & lf);
1452 }
1453 }
1454
1455 testcase decode_something() runs on ASN1
1456 {
1457 var Something expected;
1458
1459 expected := { bitstr := '01001000100001'B };
1460 CHECK_DECODE2(smth, smth_bitstr, Something, expected);
1461
1462 expected := { booool := true };
1463 CHECK_DECODE2(smth, smth_bool, Something, expected);
1464
1465 expected := { floating := 3.141593 };
1466 CHECK_DECODE2(smth, smth_float, Something, expected);
1467
1468 expected := { wholenum := 42 };
1469 CHECK_DECODE2(smth, smth_int, Something, expected);
1470
1471 expected := { cartoon := barney };
1472 CHECK_DECODE2(smth, smth_barney, Something, expected);
1473 }
1474
1475 /**************************** record ****************************/
1476
1477 DECLARE_XER_ENCODERS(Everything, ev);
1478 DECLARE_EXER_ENCODERS(Everything,ev)
1479 DECLARE_XER_ENCODERS(MaybeEverything, mev);
1480 DECLARE_EXER_ENCODERS(MaybeEverything,mev)
1481
1482 const charstring xer_everything :=
1483 "<Everything>\n" &
1484 "\t<bitstr>01011010</bitstr>\n" &
1485 "\t<booool><true/></booool>\n" &
1486
1487 "\t<pdv>\n" &
1488 "\t\t<identification>\n" &
1489 "\t\t\t<context-negotiation>\n" &
1490 "\t\t\t\t<presentation-context-id>69</presentation-context-id>\n" &
1491 "\t\t\t\t<transfer-syntax>2.7.18.28.18.28.45.90.45</transfer-syntax>\n" &
1492 "\t\t\t</context-negotiation>\n" &
1493 "\t\t</identification>\n" &
1494 "\t\t<data-value>C1AFB1</data-value>\n" &
1495 "\t</pdv>\n" &
1496
1497 "\t<cartoon><wilma/></cartoon>\n" &
1498
1499 "\t<outsider>\n" &
1500 "\t\t<direct-reference>2.1.1</direct-reference>\n" &
1501 "\t\t<indirect-reference>111</indirect-reference>\n" &
1502 "\t\t<data-value-descriptor>using context negotiation, both</data-value-descriptor>\n" &
1503 "\t\t<encoding>\n" &
1504 "\t\t\t<octet-aligned>1337D00D</octet-aligned>\n" &
1505 "\t\t</encoding>\n" &
1506 "\t</outsider>\n" &
1507
1508 "\t<wholenum>1252</wholenum>\n" &
1509 "\t<nix/>\n" &
1510 "\t<emptyrec/>\n" &
1511 "\t<objection>2.1.1</objection>\n" &
1512 "\t<octets>BAADF00D</octets>\n" &
1513 "\t<printer>evth</printer>\n" &
1514 "\t<floating>3.141593</floating>\n" &
1515 //"\t<></>\n" &
1516
1517 "\t<rroid>1.2.826.0.1249</rroid>\n" &
1518
1519 "</Everything>\n\n";
1520
1521 const charstring exer_everything :=
1522 "<Everything>\n" &
1523 "\t<bitstr>01011010</bitstr>\n" &
1524 "\t<booool>true</booool>\n" & // EXER uses TextBoolean
1525
1526 "\t<pdv>\n" &
1527 "\t\t<identification>\n" &
1528 "\t\t\t<context-negotiation>\n" &
1529 "\t\t\t\t<presentation-context-id>69</presentation-context-id>\n" &
1530 "\t\t\t\t<transfer-syntax>2.7.18.28.18.28.45.90.45</transfer-syntax>\n" &
1531 "\t\t\t</context-negotiation>\n" &
1532 "\t\t</identification>\n" &
1533 "\t\t<data-value>C1AFB1</data-value>\n" &
1534 "\t</pdv>\n" &
1535
1536 "\t<cartoon>wilma</cartoon>\n" & // EXER
1537
1538 "\t<outsider>\n" &
1539 "\t\t<direct-reference>2.1.1</direct-reference>\n" &
1540 "\t\t<indirect-reference>111</indirect-reference>\n" &
1541 "\t\t<data-value-descriptor>using context negotiation, both</data-value-descriptor>\n" &
1542 "\t\t<encoding>\n" &
1543 "\t\t\t<octet-aligned>1337D00D</octet-aligned>\n" &
1544 "\t\t</encoding>\n" &
1545 "\t</outsider>\n" &
1546
1547 "\t<wholenum>1252</wholenum>\n" &
1548 "\t<nix/>\n" &
1549 "\t<emptyrec/>\n" &
1550 "\t<objection>2.1.1</objection>\n" &
1551 "\t<octets>BAADF00D</octets>\n" &
1552 "\t<printer>evth</printer>\n" &
1553 "\t<floating>3.141593</floating>\n" &
1554 //"\t<></>\n" &
1555
1556 "\t<rroid>1.2.826.0.1249</rroid>\n" &
1557
1558 "</Everything>\n\n";
1559
1560 const Everything evth := {
1561 bitstr := '01011010'B,
1562 booool := true,
1563 pdv := AsnValues.pdv_cneg,
1564 cartoon := wilma,
1565 outsider := AsnValues.ext_cn,
1566 wholenum := 1252,
1567 nix := NULL,
1568 emptyrec := {},
1569 objection:= AsnValues.ber_oid,
1570 octets := 'BAADF00D'O,
1571 printer := "evth",
1572 floating := 3.141593,
1573 rroid := AsnValues.zoid
1574 }
1575
1576
1577 testcase encode_everything() runs on ASN1
1578 {
1579 var universal charstring expected;
1580 {
1581 var Everything eval := evth;
1582 expected := xer_everything;
1583 CHECK_METHOD(bxer_enc_ev, eval, expected);
1584 flatten(expected);
1585 CHECK_METHOD(cxer_enc_ev, eval, expected & lf);
1586 expected := exer_everything;
1587 CHECK_METHOD(exer_enc_ev, eval, expected);
1588 }
1589
1590 {
1591 var Everything eval := AsnValues.a_evth;
1592 }
1593
1594 }
1595
1596 testcase decode_everything() runs on ASN1
1597 {
1598 var Everything expected;
1599 expected := evth;
1600 CHECK_DECODE2(ev, xer_everything, Everything, expected);
1601 }
1602
1603 /*********************** record with optional fields ***********************/
1604
1605 const charstring mevstr_all :=
1606 "<MaybeEverything>\n" &
1607 "\t<bitstr>01011010</bitstr>\n" &
1608 "\t<booool><true/></booool>\n" &
1609
1610 "\t<pdv>\n" &
1611 "\t\t<identification>\n" &
1612 "\t\t\t<context-negotiation>\n" &
1613 "\t\t\t\t<presentation-context-id>69</presentation-context-id>\n" &
1614 "\t\t\t\t<transfer-syntax>2.7.18.28.18.28.45.90.45</transfer-syntax>\n" &
1615 "\t\t\t</context-negotiation>\n" &
1616 "\t\t</identification>\n" &
1617 "\t\t<data-value>C1AFB1</data-value>\n" &
1618 "\t</pdv>\n" &
1619
1620 "\t<cartoon><betty/></cartoon>\n" &
1621
1622 "\t<outsider>\n" &
1623 "\t\t<direct-reference>2.1.1</direct-reference>\n" &
1624 "\t\t<indirect-reference>111</indirect-reference>\n" &
1625 "\t\t<data-value-descriptor>using context negotiation, both</data-value-descriptor>\n" &
1626 "\t\t<encoding>\n" &
1627 "\t\t\t<octet-aligned>1337D00D</octet-aligned>\n" &
1628 "\t\t</encoding>\n" &
1629 "\t</outsider>\n" &
1630
1631 "\t<wholenum>1252</wholenum>\n" &
1632 "\t<nix/>\n" &
1633 "\t<anyad>DECAFF</anyad>\n" &
1634 "\t<emptyrec/>\n" &
1635 "\t<objection>2.1.1</objection>\n" &
1636 "\t<octets>BAADF00D</octets>\n" &
1637 "\t<printer>mev-all</printer>\n" &
1638 "\t<floating>3.141593</floating>\n" &
1639 "\t<rroid>1.2.826.0.1249</rroid>\n" &
1640
1641 "</MaybeEverything>\n\n";
1642
1643 const charstring mevstr_all_exer :=
1644 "<MaybeEverything>\n" &
1645 "\t<bitstr>01011010</bitstr>\n" &
1646 "\t<booool>true</booool>\n" & // EXER uses TextBooleean
1647
1648 "\t<pdv>\n" &
1649 "\t\t<identification>\n" &
1650 "\t\t\t<context-negotiation>\n" &
1651 "\t\t\t\t<presentation-context-id>69</presentation-context-id>\n" &
1652 "\t\t\t\t<transfer-syntax>2.7.18.28.18.28.45.90.45</transfer-syntax>\n" &
1653 "\t\t\t</context-negotiation>\n" &
1654 "\t\t</identification>\n" &
1655 "\t\t<data-value>C1AFB1</data-value>\n" &
1656 "\t</pdv>\n" &
1657
1658 "\t<cartoon>betty</cartoon>\n" & // EXER uses TextEnumerated
1659
1660 "\t<outsider>\n" &
1661 "\t\t<direct-reference>2.1.1</direct-reference>\n" &
1662 "\t\t<indirect-reference>111</indirect-reference>\n" &
1663 "\t\t<data-value-descriptor>using context negotiation, both</data-value-descriptor>\n" &
1664 "\t\t<encoding>\n" &
1665 "\t\t\t<octet-aligned>1337D00D</octet-aligned>\n" &
1666 "\t\t</encoding>\n" &
1667 "\t</outsider>\n" &
1668
1669 "\t<wholenum>1252</wholenum>\n" &
1670 "\t<nix/>\n" &
1671 "\t<anyad>DECAFF</anyad>\n" &
1672 "\t<emptyrec/>\n" &
1673 "\t<objection>2.1.1</objection>\n" &
1674 "\t<octets>BAADF00D</octets>\n" &
1675 "\t<printer>mev-all</printer>\n" &
1676 "\t<floating>3.141593</floating>\n" &
1677 "\t<rroid>1.2.826.0.1249</rroid>\n" &
1678
1679 "</MaybeEverything>\n\n";
1680
1681 const MaybeEverything mev_all := {
1682 bitstr := '01011010'B,
1683 booool := true,
1684 pdv := AsnValues.pdv_cneg,
1685 cartoon := betty,
1686 outsider := AsnValues.ext_cn,
1687 wholenum := 1252,
1688 nix := NULL,
1689 anyad := 'DECAFF'O,
1690 emptyrec := {},
1691 objection:= AsnValues.ber_oid,
1692 octets := 'BAADF00D'O,
1693 printer := "mev-all",
1694 floating := 3.141593,
1695 rroid := AsnValues.zoid
1696 };
1697
1698 const charstring mevstr_none := "<MaybeEverything/>\n\n";
1699 const MaybeEverything mev_none := {
1700 bitstr := omit,
1701 booool := omit,
1702 pdv := omit,
1703 cartoon := omit,
1704 outsider := omit,
1705 wholenum := omit,
1706 nix := omit,
1707 anyad := omit,
1708 emptyrec := omit,
1709 objection:= omit,
1710 octets := omit,
1711 printer := omit,
1712 floating := omit,
1713 rroid := omit
1714 };
1715
1716 const charstring mevstr_bits :=
1717 "<MaybeEverything>\n" &
1718 "\t<bitstr>1010101001010101</bitstr>\n" &
1719 "</MaybeEverything>\n\n";
1720
1721 const MaybeEverything mev_bits := {
1722 bitstr := '1010101001010101'B,
1723 booool := omit,
1724 pdv := omit,
1725 cartoon := omit,
1726 outsider := omit,
1727 wholenum := omit,
1728 nix := omit,
1729 anyad := omit,
1730 emptyrec := omit,
1731 objection:= omit,
1732 octets := omit,
1733 printer := omit,
1734 floating := omit,
1735 rroid := omit
1736 };
1737
1738 const charstring mevstr_bitsbool :=
1739 "<MaybeEverything>\n" &
1740 "\t<bitstr>1010101001010101</bitstr>\n" &
1741 "\t<booool><false/></booool>\n" &
1742 "</MaybeEverything>\n\n";
1743
1744 const charstring mevstr_bitsbool_exer :=
1745 "<MaybeEverything>\n" &
1746 "\t<bitstr>1010101001010101</bitstr>\n" &
1747 "\t<booool>false</booool>\n" & // EXER
1748 "</MaybeEverything>\n\n";
1749
1750 const MaybeEverything mev_bitsbool := {
1751 bitstr := '1010101001010101'B,
1752 booool := false,
1753 pdv := omit,
1754 cartoon := omit,
1755 outsider := omit,
1756 wholenum := omit,
1757 nix := omit,
1758 anyad := omit,
1759 emptyrec := omit,
1760 objection:= omit,
1761 octets := omit,
1762 printer := omit,
1763 floating := omit,
1764 rroid := omit
1765 };
1766
1767 const charstring mevstr_3 :=
1768 "<MaybeEverything>\n" &
1769 "\t<bitstr>1010101001010101</bitstr>\n" &
1770 "\t<booool><false/></booool>\n" &
1771 "\t<cartoon><fred/></cartoon>\n" &
1772 "</MaybeEverything>\n\n";
1773
1774 const charstring mevstr_3_exer :=
1775 "<MaybeEverything>\n" &
1776 "\t<bitstr>1010101001010101</bitstr>\n" &
1777 "\t<booool>false</booool>\n" & // EXER
1778 "\t<cartoon>fred</cartoon>\n" & // EXER
1779 "</MaybeEverything>\n\n";
1780
1781 const MaybeEverything mev_3 := {
1782 bitstr := '1010101001010101'B,
1783 booool := false,
1784 pdv := omit,
1785 cartoon := fred,
1786 outsider := omit,
1787 wholenum := omit,
1788 nix := omit,
1789 anyad := omit,
1790 emptyrec := omit,
1791 objection:= omit,
1792 octets := omit,
1793 printer := omit,
1794 floating := omit,
1795 rroid := omit
1796 };
1797
1798
1799 testcase encode_everything_opt() runs on ASN1
1800 {
1801 var universal charstring expected;
1802 expected := mevstr_all;
1803 CHECK_METHOD(bxer_enc_mev, mev_all, expected);
1804 flatten(expected);
1805 CHECK_METHOD(cxer_enc_mev, mev_all, expected & lf);
1806 expected := mevstr_all_exer;
1807 CHECK_METHOD(exer_enc_mev, mev_all, expected);
1808
1809 expected := mevstr_none;
1810 CHECK_METHOD(bxer_enc_mev, mev_none, expected);
1811 CHECK_METHOD(exer_enc_mev, mev_none, expected);
1812 flatten(expected);
1813 CHECK_METHOD(cxer_enc_mev, mev_none, expected & lf);
1814
1815 expected := mevstr_bits;
1816 CHECK_METHOD(bxer_enc_mev, mev_bits, expected);
1817 CHECK_METHOD(exer_enc_mev, mev_bits, expected);
1818 flatten(expected);
1819 CHECK_METHOD(cxer_enc_mev, mev_bits, expected & lf);
1820
1821 expected := mevstr_bitsbool;
1822 CHECK_METHOD(bxer_enc_mev, mev_bitsbool, expected);
1823 flatten(expected);
1824 CHECK_METHOD(cxer_enc_mev, mev_bitsbool, expected & lf);
1825 expected := mevstr_bitsbool_exer;
1826 CHECK_METHOD(exer_enc_mev, mev_bitsbool, expected);
1827
1828 expected := mevstr_3;
1829 CHECK_METHOD(bxer_enc_mev, mev_3, expected);
1830 flatten(expected);
1831 CHECK_METHOD(cxer_enc_mev, mev_3, expected & lf);
1832 expected := mevstr_3_exer;
1833 CHECK_METHOD(exer_enc_mev, mev_3, expected);
1834 }
1835
1836 testcase decode_everything_opt() runs on ASN1
1837 {
1838 CHECK_DECODE2(mev, mevstr_all, MaybeEverything, mev_all);
1839 CHECK_DECODE2(mev, mevstr_none, MaybeEverything, mev_none);
1840 CHECK_DECODE2(mev, mevstr_bits, MaybeEverything, mev_bits);
1841 CHECK_DECODE2(mev, mevstr_bitsbool, MaybeEverything, mev_bitsbool);
1842 CHECK_DECODE2(mev, mevstr_3, MaybeEverything, mev_3);
1843 }
1844
1845 /**************************** enumerated ****************************/
1846
1847 DECLARE_XER_ENCODERS(Flintstones, flin);
1848 DECLARE_EXER_ENCODERS(Flintstones,flin)
1849
1850 const universal charstring fredstr_exer := "fred";
1851 const universal charstring barneystr_exer:= "barney";
1852 const universal charstring wilmastr_exer := "wilma";
1853 const universal charstring bettystr_exer := "betty";
1854
1855 const universal charstring fredstr := "<" & fredstr_exer & "/>";
1856 const universal charstring barneystr:= "<" & barneystr_exer & "/>";
1857 const universal charstring wilmastr := "<" & wilmastr_exer & "/>";
1858 const universal charstring bettystr := "<" & bettystr_exer & "/>";
1859
1860 const universal charstring fred_nested_exer := "<Flintstones>" & fredstr_exer & "</Flintstones>\n\n";
1861 const universal charstring barney_nested_exer:= "<Flintstones>" & barneystr_exer & "</Flintstones>\n\n";
1862 const universal charstring wilma_nested_exer := "<Flintstones>" & wilmastr_exer & "</Flintstones>\n\n";
1863 const universal charstring betty_nested_exer := "<Flintstones>" & bettystr_exer & "</Flintstones>\n\n";
1864
1865 const universal charstring fred_nested := "<Flintstones>" & fredstr & "</Flintstones>\n";
1866 const universal charstring barney_nested:= "<Flintstones>" & barneystr & "</Flintstones>\n";
1867 const universal charstring wilma_nested := "<Flintstones>" & wilmastr & "</Flintstones>\n";
1868 const universal charstring betty_nested := "<Flintstones>" & bettystr & "</Flintstones>\n";
1869
1870 testcase encode_flintstones() runs on ASN1
1871 {
1872 CHECK_METHOD(bxer_enc_flin, fred, fred_nested & lf);
1873 CHECK_METHOD(exer_enc_flin, fred, fred_nested_exer);
1874 CHECK_METHOD(cxer_enc_flin, fred, fred_nested);
1875
1876 CHECK_METHOD(bxer_enc_flin, barney, barney_nested & lf);
1877 CHECK_METHOD(exer_enc_flin, barney, barney_nested_exer);
1878 CHECK_METHOD(cxer_enc_flin, barney, barney_nested);
1879
1880 CHECK_METHOD(bxer_enc_flin, wilma, wilma_nested & lf);
1881 CHECK_METHOD(exer_enc_flin, wilma, wilma_nested_exer);
1882 CHECK_METHOD(cxer_enc_flin, wilma, wilma_nested);
1883
1884 CHECK_METHOD(bxer_enc_flin, betty, betty_nested & lf);
1885 CHECK_METHOD(exer_enc_flin, betty, betty_nested_exer);
1886 CHECK_METHOD(cxer_enc_flin, betty, betty_nested);
1887
1888 }
1889
1890 testcase decode_flintstones() runs on ASN1
1891 {
1892 var Flintstones expected;
1893
1894 expected := fred;
1895 CHECK_DECODE2(flin, fred_nested, Flintstones, expected);
1896
1897 expected := barney;
1898 CHECK_DECODE2(flin, barney_nested, Flintstones, expected);
1899
1900 expected := wilma;
1901 CHECK_DECODE2(flin, wilma_nested, Flintstones, expected);
1902
1903 expected := betty;
1904 CHECK_DECODE2(flin, betty_nested, Flintstones, expected);
1905 }
1906
1907 /**************************** set of enumerated ****************************/
1908
1909 DECLARE_XER_ENCODERS(Family, fam);
1910 DECLARE_EXER_ENCODERS(Family,fam)
1911
1912 const universal charstring rubblestr :=
1913 "<Family>\n\t" & barneystr & bettystr & "\n</Family>\n\n";
1914
1915 const universal charstring nobodystr :=
1916 "<Family/>\n\n";
1917
1918 const universal charstring allstr :=
1919 "<Family>\n\t" & fredstr & wilmastr & bettystr & barneystr & "\n</Family>\n\n";
1920
1921 const universal charstring allstr_exer :=
1922 "<Family>\n" &
1923 "\t<Flintstones>" & fredstr_exer & "</Flintstones>\n" &
1924 "\t<Flintstones>" & wilmastr_exer & "</Flintstones>\n" &
1925 "\t<Flintstones>" & bettystr_exer & "</Flintstones>\n" &
1926 "\t<Flintstones>" & barneystr_exer & "</Flintstones>\n" &
1927 "</Family>\n\n";
1928
1929 const Family nobody := {}
1930 const Family alll := { fred, wilma, betty, barney }
1931
1932 testcase encode_family() runs on ASN1
1933 {
1934 //family rubble := { barney, betty }
1935 var universal charstring expected;
1936
1937 expected := rubblestr;
1938 CHECK_METHOD(bxer_enc_fam, AsnValues.rubble, expected);
1939 flatten(expected);
1940 CHECK_METHOD(cxer_enc_fam, AsnValues.rubble, expected & lf);
1941
1942 expected := nobodystr;
1943 CHECK_METHOD(bxer_enc_fam, nobody, expected);
1944 CHECK_METHOD(exer_enc_fam, nobody, expected);
1945 flatten(expected);
1946 CHECK_METHOD(cxer_enc_fam, nobody, expected & lf);
1947
1948 expected := allstr;
1949 CHECK_METHOD(bxer_enc_fam, alll, expected);
1950 flatten(expected);
1951 CHECK_METHOD(cxer_enc_fam, alll, expected & lf);
1952 expected := allstr_exer;
1953 CHECK_METHOD(exer_enc_fam, alll, expected);
1954 }
1955
1956 testcase decode_family() runs on ASN1
1957 {
1958 // suffix, input , type , expected
1959 CHECK_DECODE2(fam, rubblestr, Family, AsnValues.rubble);
1960 CHECK_DECODE2(fam, nobodystr, Family, nobody);
1961 CHECK_DECODE2(fam, allstr , Family, alll);
1962 }
1963
1964 const universal charstring nagy_arvizturo :=
1965 char(0,0,0,193) & "RV" & char(0,0,0,205) & "ZT" & char(0,0,1,112) & "R" &
1966 char(0,0,1,80) & " T" & char(0,0,0,220) & "K" & char(0,0,0,214) & "RF" &
1967 char(0,0,0,218) & "R" & char(0,0,0,211) & "G" & char(0,0,0,201) & "P";
1968 const universal charstring kis_arvizturo :=
1969 char(0,0,0,225) & "rv" & char(0,0,0,237) & "zt" & char(0,0,1,113) & "r" &
1970 char(0,0,1,81) & " t" & char(0,0,0,252) & "k" & char(0,0,0,246) & "rf" &
1971 char(0,0,0,250) & "r" & char(0,0,0,243) & "g" & char(0,0,0,233) & "p";
1972
1973
1974 //////////////////////////////////////////////////////////////////////////
1975 //
1976 // Control part
1977 //
1978 //////////////////////////////////////////////////////////////////////////
1979
1980 control {
1981 execute(encode_bs());
1982 execute(encode_abool());
1983 execute(encode_pdv());
1984 execute(encode_ext());
1985 execute(encode_aint());
1986 execute(encode_nul());
1987 execute(encode_oid());
1988 execute(encode_roid());
1989 execute(encode_os());
1990 execute(encode_real());
1991
1992 execute(encode_ia5str());
1993 execute(encode_utf());
1994 execute(encode_restricted_strings());
1995
1996 execute(encode_unr());
1997
1998 execute(encode_emptyrec());
1999 execute(encode_something());
2000 execute(encode_everything());
2001 execute(encode_everything_opt());
2002
2003 execute(encode_flintstones());
2004 execute(encode_family());
2005
2006 execute(limerick());
2007
2008 execute(decode_bs());
2009 execute(decode_abool());
2010 execute(decode_pdv());
2011 execute(decode_ext());
2012 execute(decode_aint());
2013 execute(decode_nul());
2014 execute(decode_oid());
2015 execute(decode_roid());
2016 execute(decode_os());
2017 execute(decode_real());
2018
2019 execute(decode_ia5str());
2020 execute(decode_utf());
2021 execute(decode_restricted_strings());
2022
2023 execute(decode_unr());
2024
2025 execute(decode_emptyrec());
2026 execute(decode_something());
2027 execute(decode_everything());
2028 execute(decode_everything_opt());
2029
2030 execute(decode_flintstones());
2031 execute(decode_family());
2032 }
2033
2034
2035 }
2036 with {
2037 encode "XML";
2038 extension "version R8A";
2039 }
This page took 0.075448 seconds and 5 git commands to generate.