1 /******************************************************************************
2 * Copyright (c) 2000-2015 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 ******************************************************************************/
9 modulepar boolean UseNil_verbose := false;
10 #define verbose UseNil_verbose
11 #include "../macros.ttcnin"
15 type enumerated ProductColor0 { red(0), green(1), blue(2) }
17 // useNil on the type (record)
19 integer sizeval optional
21 with { variant "useNil" }
23 type record NilProduct {
29 DECLARE_XER_ENCODERS(NilProduct, nilp);
30 DECLARE_EXER_ENCODERS(NilProduct, nilp);
32 DECLARE_XER_ENCODERS(Size, sz);
33 DECLARE_EXER_ENCODERS(Size, sz);
35 const NilProduct absent := {
41 const NilProduct present_ := {
48 const universal charstring str_absent_e_correct :=
49 "<NilProduct xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\'>\n" &
50 "\t<name>no shirt</name>\n" &
51 "\t<color>red</color>\n" &
52 "\t<size xsi:nil=\'true\'/>\n" &
56 const universal charstring str_absent_e :=
57 "<NilProduct xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\'>\n" &
58 "\t<name>no shirt</name>\n" &
59 "\t<color>red</color>\n" &
60 "\t<size xsi:nil=\'true\'/>\n" &
64 const universal charstring str_absent_b :=
66 "\t<name>no shirt</name>\n" &
67 "\t<color><red/></color>\n" &
72 const universal charstring str_present_e_correct :=
73 "<NilProduct xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\'>\n" &
74 "\t<name>shirt</name>\n" &
75 "\t<color>red</color>\n" &
76 "\t<size xsi:nil='false'>10</size>\n" &
80 const universal charstring str_present_e :=
82 "\t<name>shirt</name>\n" &
83 "\t<color>red</color>\n" &
84 "\t<size>10</size>\n" & // HO37920: no \t after 10
88 const universal charstring str_present_b :=
90 "\t<name>shirt</name>\n" &
91 "\t<color><red/></color>\n" &
93 "\t\t<sizeval>10</sizeval>\n" &
98 testcase encode_nil_absent() runs on Nil
100 CHECK_METHOD(bxer_enc_nilp, absent, str_absent_b);
101 CHECK_METHOD(exer_enc_nilp, absent, str_absent_e);
104 testcase encode_nil_present() runs on Nil
106 CHECK_METHOD(bxer_enc_nilp, present_, str_present_b);
107 CHECK_METHOD(exer_enc_nilp, present_, str_present_e);
110 testcase decode_nil_absent() runs on Nil
112 CHECK_DECODE(bxer_dec_nilp, str_absent_b, NilProduct, absent);
113 CHECK_DECODE(exer_dec_nilp, str_absent_e, NilProduct, absent);
116 testcase decode_nil_present() runs on Nil
118 CHECK_DECODE(bxer_dec_nilp, str_present_b, NilProduct, present_);
119 CHECK_DECODE(exer_dec_nilp, str_present_e, NilProduct, present_);
122 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
124 const universal charstring str_sz_absent_e :=
125 "<Size xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xsi:nil=\'true\'/>\n\n";
127 const universal charstring str_sz_absent_b :=
130 const universal charstring str_sz_present_e :=
131 "<Size>10</Size>\n\n";
133 const universal charstring str_sz_present_b :=
135 "\t<sizeval>10</sizeval>\n" &
138 testcase encode_size_absent() runs on Nil
140 CHECK_METHOD(bxer_enc_sz, absent.size, str_sz_absent_b);
141 CHECK_METHOD(exer_enc_sz, absent.size, str_sz_absent_e);
144 testcase encode_size_present() runs on Nil
146 CHECK_METHOD(bxer_enc_sz, present_.size, str_sz_present_b);
147 CHECK_METHOD(exer_enc_sz, present_.size, str_sz_present_e);
150 testcase decode_size_absent() runs on Nil
152 CHECK_DECODE(bxer_dec_sz, str_sz_absent_b, Size, absent.size);
153 CHECK_DECODE(exer_dec_sz, str_sz_absent_e, Size, absent.size);
156 testcase decode_size_present() runs on Nil
158 CHECK_DECODE(bxer_dec_sz, str_sz_present_b, Size, present_.size);
159 CHECK_DECODE(exer_dec_sz, str_sz_present_e, Size, present_.size);
162 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
165 integer sizeval optional
168 type record NilProduct2 {
171 Size2 size // useNil on the field (record)
173 with { variant (size) "useNil" }
175 DECLARE_XER_ENCODERS(NilProduct2, np2);
176 DECLARE_EXER_ENCODERS(NilProduct2, np2);
178 const NilProduct2 absent2 := {
184 const NilProduct2 present2 := {
190 const universal charstring str_absent2_b :=
192 "\t<name>no shirt</name>\n" &
193 "\t<color><red/></color>\n" &
198 const universal charstring str_absent2_e :=
199 "<NilProduct2 xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\'>\n" &
200 "\t<name>no shirt</name>\n" &
201 "\t<color>red</color>\n" &
202 "\t<size xsi:nil=\'true\'/>\n" &
207 const universal charstring str_present2_b :=
209 "\t<name>shirt</name>\n" &
210 "\t<color><red/></color>\n" &
212 "\t\t<sizeval>10</sizeval>\n" &
217 const universal charstring str_present2_e :=
219 "\t<name>shirt</name>\n" &
220 "\t<color>red</color>\n" &
221 "\t<size>10</size>\n" & // HO37920: no \t after 10
226 testcase encode_np2_absent() runs on Nil
228 CHECK_METHOD(bxer_enc_np2, absent2, str_absent2_b);
229 CHECK_METHOD(exer_enc_np2, absent2, str_absent2_e);
232 testcase encode_np2_present() runs on Nil
234 CHECK_METHOD(bxer_enc_np2, present2, str_present2_b);
235 CHECK_METHOD(exer_enc_np2, present2, str_present2_e);
238 testcase decode_np2_absent() runs on Nil
240 CHECK_DECODE(bxer_dec_np2, str_absent2_b, NilProduct2, absent2);
241 CHECK_DECODE(exer_dec_np2, str_absent2_e, NilProduct2, absent2);
244 testcase decode_np2_present() runs on Nil
246 CHECK_DECODE(bxer_dec_np2, str_present2_b, NilProduct2, present2);
247 CHECK_DECODE(exer_dec_np2, str_present2_e, NilProduct2, present2);
250 /* * * * * * * Complex type as the optional member * * * * * * */
252 type record NilProduct3 {
262 variant (container) "useNil";
263 variant (container.name) "attribute";
267 DECLARE_XER_ENCODERS(NilProduct3, np3);
268 DECLARE_EXER_ENCODERS(NilProduct3, np3);
270 const NilProduct3 absent3 := {{
275 const NilProduct3 present3 := {{
277 size := { 10, "inches" }
280 const universal charstring str_absent3_b :=
283 "\t\t<name>no shirt</name>\n" &
288 const universal charstring str_absent3_e :=
289 "<NilProduct3 xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\'>\n" &
290 "\t<container name='no shirt' xsi:nil='true'/>\n" &
291 "</NilProduct3>\n\n";
294 const universal charstring str_present3_b :=
297 "\t\t<name>shirt</name>\n" &
299 "\t\t\t<sizeval>10</sizeval>\n" &
300 "\t\t\t<unit>inches</unit>\n" &
306 const universal charstring str_present3_e :=
308 "\t<container name='shirt'>\n" &
310 "\t\t<sizeval>10</sizeval>\n" &
311 "\t\t<unit>inches</unit>\n" &
313 "\t</container>\n" & // HO37920: a single tab is needed
318 testcase encode_np3_absent() runs on Nil
320 CHECK_METHOD(bxer_enc_np3, absent3, str_absent3_b);
321 CHECK_METHOD(exer_enc_np3, absent3, str_absent3_e);
324 testcase encode_np3_present() runs on Nil
326 CHECK_METHOD(bxer_enc_np3, present3, str_present3_b);
327 CHECK_METHOD(exer_enc_np3, present3, str_present3_e);
330 testcase decode_np3_absent() runs on Nil
332 CHECK_DECODE(bxer_dec_np3, str_absent3_b, NilProduct3, absent3);
333 CHECK_DECODE(exer_dec_np3, str_absent3_e, NilProduct3, absent3);
336 testcase decode_np3_present() runs on Nil
338 CHECK_DECODE(bxer_dec_np3, str_present3_b, NilProduct3, present3);
339 CHECK_DECODE(exer_dec_np3, str_present3_e, NilProduct3, present3);
342 /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
343 Regression test for HO85831.
346 type enumerated szunet {
356 type record of integer intlist;
358 type union ximsa_ssp_isp_content {
366 charstring s optional
369 universal charstring s optional
374 // float is always written with six decimal places, hence min. 8 characters
375 // bitstring and hexstring can not be character-encodable
376 // octetstring can be character-encodable (with base64), but it must have
377 // an even number of hex digits
380 variant (integer_list[-]) "useNil";
381 variant (charstring_list[-]) "useNil";
382 variant (ustring_list[-]) "useNil";
383 variant (bool_list[-]) "useNil";
384 variant (bool_list[-].b) "text"; // needed for boolean to produce one-character encoding: "1" or "0"
385 variant (enum_list[-]) "useNil";
388 const ximsa_ssp_isp_content imsar := {
395 const universal charstring str_imsar_e :=
396 "<ximsa_ssp_isp_content>\n" &
397 "\t<integer_list>\n" &
399 "\t\t<SEQUENCE>2</SEQUENCE>\n" &
400 //bad: "\t\t<SEQUENCE/>\n" &
402 "\t\t<SEQUENCE>42</SEQUENCE>\n" &
403 "\t</integer_list>\n" &
404 "</ximsa_ssp_isp_content>\n\n" ;
406 const ximsa_ssp_isp_content imsastr := {
413 const universal charstring str_imsastr_e :=
414 "<ximsa_ssp_isp_content>\n" &
415 "\t<charstring_list>\n" &
416 "\t\t<SEQUENCE>two</SEQUENCE>\n" &
418 "\t\t<SEQUENCE>!</SEQUENCE>\n" &
419 //bad: "\t\t<SEQUENCE/>\n" &
421 "\t</charstring_list>\n" &
422 "</ximsa_ssp_isp_content>\n\n" ;
424 const ximsa_ssp_isp_content imsaustr := {
431 const universal charstring str_imsaustr_e :=
432 "<ximsa_ssp_isp_content>\n" &
433 "\t<ustring_list>\n" &
434 "\t\t<SEQUENCE>|_|</SEQUENCE>\n" &
436 "\t\t<SEQUENCE>u</SEQUENCE>\n" &
437 //bad: "\t\t<SEQUENCE/>\n" &
439 "\t</ustring_list>\n" &
440 "</ximsa_ssp_isp_content>\n\n" ;
443 const boolean file_not_found := false;
444 const ximsa_ssp_isp_content bimsar := {
452 const universal charstring str_bimsar_e :=
453 "<ximsa_ssp_isp_content>\n" &
455 "\t\t<SEQUENCE>1</SEQUENCE>\n" &
456 "\t\t<SEQUENCE>0</SEQUENCE>\n" &
457 "\t\t<SEQUENCE>0</SEQUENCE>\n" &
459 "</ximsa_ssp_isp_content>\n\n" ;
461 const ximsa_ssp_isp_content eimsar := {
468 const universal charstring str_eimsar_e :=
469 "<ximsa_ssp_isp_content>\n" &
471 "\t\t<SEQUENCE>O</SEQUENCE>\n" &
472 "\t\t<SEQUENCE>ACIO</SEQUENCE>\n" &
474 "</ximsa_ssp_isp_content>\n\n" ;
477 DECLARE_EXER_ENCODERS(ximsa_ssp_isp_content, x);
479 testcase encode_usenil_recof() runs on Nil
481 CHECK_METHOD(exer_enc_x, imsar, str_imsar_e);
482 CHECK_METHOD(exer_enc_x, imsastr, str_imsastr_e);
483 CHECK_METHOD(exer_enc_x, imsaustr,str_imsaustr_e);
484 CHECK_METHOD(exer_enc_x, bimsar, str_bimsar_e);
485 CHECK_METHOD(exer_enc_x, eimsar, str_eimsar_e);
489 /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */
491 // Encoding nillable multi-level structures (if present, these will contain child elements)
493 type record MultiNil {
499 charstring str optional
503 variant(available) "attribute";
504 variant(val.inner.activated) "attribute";
507 const MultiNil c_absent := { false, omit };
509 const universal charstring str_absent :=
510 "<MultiNil xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' available='false' xsi:nil='true'/>\n\n";
512 const MultiNil c_present := { true, { { true }, omit } };
514 const universal charstring str_present :=
515 "<MultiNil available='true'>\n" &
516 "\t<inner activated='true'/>\n" &
519 const universal charstring str_present2 :=
520 "<MultiNil xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' available='true' xsi:nil='false'>\n" &
521 "\t<inner activated='true'/>\n" &
524 DECLARE_EXER_ENCODERS(MultiNil, multi);
526 testcase encode_multi_nil() runs on Nil {
527 CHECK_METHOD(exer_enc_multi, c_absent, str_absent);
528 CHECK_METHOD(exer_enc_multi, c_present, str_present);
531 testcase decode_multi_nil() runs on Nil {
532 CHECK_DECODE(exer_dec_multi, str_absent, MultiNil, c_absent);
533 CHECK_DECODE(exer_dec_multi, str_present, MultiNil, c_present);
534 CHECK_DECODE(exer_dec_multi, str_present2, MultiNil, c_present);
537 /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */
540 execute(encode_nil_absent());
541 execute(encode_nil_present());
542 execute(decode_nil_absent());
543 execute(decode_nil_present());
545 execute(encode_size_absent());
546 execute(encode_size_present());
547 execute(decode_size_absent());
548 execute(decode_size_present());
550 execute(encode_np2_absent());
551 execute(encode_np2_present());
552 execute(decode_np2_absent());
553 execute(decode_np2_present());
555 execute(encode_np3_absent());
556 execute(encode_np3_present());
557 execute(decode_np3_absent());
558 execute(decode_np3_present());
560 execute(encode_usenil_recof());
562 execute(encode_multi_nil());
563 execute(decode_multi_nil());
569 variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'"
570 variant "elementFormQualified";
571 variant "attributeFormQualified";