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 Untagged_verbose := false;
10 #define verbose Untagged_verbose
11 #include "../macros.ttcnin"
13 /* * * * * * * * * * * Untagged applied to a field * * * * * * * * * * */
15 type enumerated ProductColor { red(0), green(1), blue(2) }
17 type record ProductInfo {
22 type record AdditionalInfo {
27 type record ProductU {
28 record of ProductColor color,
30 AdditionalInfo addInfo,
37 variant (color) "untagged";
38 variant (info) "untagged";
39 variant (addInfo) "untagged";
40 variant (priceInfo) "untagged";
41 // It's getting a bit monotonous...
42 variant (priceInfo.usd) "name as uppercased";
43 variant (priceInfo.euro) "name as uppercased";
46 const ProductU val := {
47 color := { red, green, blue },
56 priceInfo := { usd := 25 }
59 const universal charstring str_prodU_e :=
61 "\t<ProductColor>red</ProductColor>\n" &
62 "\t<ProductColor>green</ProductColor>\n" &
63 "\t<ProductColor>blue</ProductColor>\n" &
64 "\t<name>shirt</name>\n" &
65 "\t<color>red</color>\n" &
66 "\t<size>44</size>\n" &
67 "\t<available>false</available>\n" &
72 const universal charstring str_prodU_b :=
75 "\t\t<red/><green/><blue/>\n" &
78 "\t\t<name>shirt</name>\n" &
79 "\t\t<color><red/></color>\n" &
82 "\t\t<size>44</size>\n" &
83 "\t\t<available><false/></available>\n" &
86 "\t\t<usd>25</usd>\n" &
91 DECLARE_XER_ENCODERS(ProductU, prodU);
92 DECLARE_EXER_ENCODERS(ProductU, prodU);
96 testcase encode_ut() runs on UTA
98 CHECK_METHOD(bxer_enc_prodU, val, str_prodU_b);
99 CHECK_METHOD(exer_enc_prodU, val, str_prodU_e);
102 testcase decode_ut() runs on UTA
104 CHECK_DECODE(bxer_dec_prodU, str_prodU_b, ProductU, val);
105 CHECK_DECODE(exer_dec_prodU, str_prodU_e, ProductU, val);
108 /* * * * * * * * * * * Untagged applied to a type * * * * * * * * * * */
110 type record ProductInfo2 {
116 variant "name as 'ProductInfo'";
119 type record AdditionalInfo2 {
125 variant "name as 'AdditionalInfo'";
128 type record Product2 {
129 record of ProductColor color,
131 AdditionalInfo2 addInfo,
138 variant "name as 'ProductU'"
139 variant (color) "untagged";
140 variant (info) "untagged";
141 variant (priceInfo) "untagged";
142 // It's getting a bit monotonous...
143 variant (priceInfo.usd) "name as uppercased";
144 variant (priceInfo.euro) "name as uppercased";
147 DECLARE_XER_ENCODERS(Product2, prod2);
148 DECLARE_EXER_ENCODERS(Product2, prod2); // EXER only
150 const Product2 val2 := {
151 color := { red, green, blue },
160 priceInfo := { usd := 25 }
163 const universal charstring str_prod_b2 :=
166 "\t\t<red/><green/><blue/>\n" &
169 "\t\t<name>shirt</name>\n" &
170 "\t\t<color><red/></color>\n" &
173 "\t\t<size>44</size>\n" &
174 "\t\t<available><false/></available>\n" &
177 "\t\t<usd>25</usd>\n" &
182 testcase encode_ut2() runs on UTA
184 CHECK_METHOD(bxer_enc_prod2, val2, str_prod_b2);
185 CHECK_METHOD(exer_enc_prod2, val2, str_prodU_e);
188 testcase decode_ut2() runs on UTA
190 CHECK_DECODE(bxer_dec_prod2, str_prod_b2, Product2, val2);
191 CHECK_DECODE(exer_dec_prod2, str_prodU_e, Product2, val2);
194 /* * * * * * * * * * * Nested untagged * * * * * * * * * * */
200 variant (f1) "untagged";
207 with { variant (f2) "untagged" }
212 with { variant (f3) "untagged" }
219 DECLARE_XER_ENCODERS(level0, l0);
220 DECLARE_EXER_ENCODERS(level0, l0);
222 const level0 cl0 := {
230 const universal charstring bstr_cl0 :=
235 "\t\t\t\t<i>13</i>\n" &
241 const universal charstring estr_cl0 :=
242 // This is the "right thing" because UNTAGGED is ignored for top-level types
247 testcase encode_deep() runs on UTA
249 CHECK_METHOD(bxer_enc_l0, cl0, bstr_cl0);
250 CHECK_METHOD(exer_enc_l0, cl0, estr_cl0);
253 testcase decode_deep() runs on UTA
255 CHECK_DECODE(bxer_dec_l0, bstr_cl0, level0, cl0);
256 CHECK_DECODE(exer_dec_l0, estr_cl0, level0, cl0);
259 /* * * * * * * * * * * Deeper * * * * * * * * * * */
263 record of integer numbers
266 variant (numbers) "untagged"
269 type record wrapper {
273 variant (c0) "untagged"
276 DECLARE_XER_ENCODERS(wrapper, w);
277 DECLARE_EXER_ENCODERS(wrapper, w);
279 const wrapper cw0 := {
285 const wrapper cw1 := {
287 numbers := { 3, 14, 15, 92, 6 }
291 const universal charstring bstr_cw0 :=
298 "\t\t\t\t\t\t<i>13</i>\n" &
299 "\t\t\t\t\t</f3>\n" &
306 const universal charstring estr_cw0 :=
311 const universal charstring bstr_cw1 :=
315 "\t\t\t<INTEGER>3</INTEGER>\n" &
316 "\t\t\t<INTEGER>14</INTEGER>\n" &
317 "\t\t\t<INTEGER>15</INTEGER>\n" &
318 "\t\t\t<INTEGER>92</INTEGER>\n" &
319 "\t\t\t<INTEGER>6</INTEGER>\n" &
324 const universal charstring estr_cw1 :=
326 "\t<INTEGER>3</INTEGER>\n" &
327 "\t<INTEGER>14</INTEGER>\n" &
328 "\t<INTEGER>15</INTEGER>\n" &
329 "\t<INTEGER>92</INTEGER>\n" &
330 "\t<INTEGER>6</INTEGER>\n" &
333 testcase encode_wrap() runs on UTA
335 CHECK_METHOD(bxer_enc_w, cw0, bstr_cw0);
336 CHECK_METHOD(exer_enc_w, cw0, estr_cw0);
337 CHECK_METHOD(bxer_enc_w, cw1, bstr_cw1);
338 CHECK_METHOD(exer_enc_w, cw1, estr_cw1);
341 testcase decode_wrap() runs on UTA
343 CHECK_DECODE(bxer_dec_w, bstr_cw1, wrapper, cw1);
344 CHECK_DECODE(exer_dec_w, estr_cw1, wrapper, cw1);
345 CHECK_DECODE(bxer_dec_w, bstr_cw0, wrapper, cw0);
346 CHECK_DECODE(exer_dec_w, estr_cw0, wrapper, cw0);
349 /* * * * * * * * HK76145 * * * * * * * * * */
360 variant (lista) "untagged"
361 variant (lista[-]) "untagged"
364 DECLARE_XER_ENCODERS(dir, dir);
365 DECLARE_EXER_ENCODERS(dir, dir);
376 const universal charstring bstr_durr :=
381 "\t\t\t\t<name>foo</name>\n" &
382 "\t\t\t\t<size>13</size>\n" &
383 "\t\t\t</folder>\n" &
384 "\t\t</SEQUENCE>\n" &
388 const universal charstring estr_durr :=
391 "\t\t<name>foo</name>\n" &
392 "\t\t<size>13</size>\n" &
398 testcase encode_dir() runs on UTA
400 CHECK_METHOD(bxer_enc_dir, durr, bstr_durr);
401 CHECK_METHOD(exer_enc_dir, durr, estr_durr);
404 testcase decode_dir() runs on UTA
406 CHECK_DECODE(bxer_dec_dir, bstr_durr, dir, durr);
407 CHECK_DECODE(exer_dec_dir, estr_durr, dir, durr);
410 /* * * * * * * * Empty record in an untagged record-of * * * * * * * */
412 type record Envelope {
413 //record of Header header optional,
419 record of Content content_list
422 variant (content_list) "untagged";
423 variant (content_list[-]) "untagged";
428 LogoutResponse logoutResponse
431 variant (logout ) "name as capitalized"
432 variant (logoutResponse) "name as capitalized"
435 type record Logout {};
436 type record LogoutResponse {};
438 DECLARE_XER_ENCODERS(Envelope, env);
439 DECLARE_EXER_ENCODERS(Envelope, env);
441 const Envelope resp := {
443 content_list := {{ logoutResponse := {} }}
447 const universal charstring str_resp :=
450 "\t\t<LogoutResponse/>\n" &
454 const universal charstring str_resp_non_canon :=
457 "\t\t<LogoutResponse>\n" &
458 "\t\t</LogoutResponse>\n" &
463 testcase encode_env() runs on UTA
465 CHECK_METHOD(exer_enc_env, resp, str_resp);
468 testcase decode_env() runs on UTA
470 CHECK_DECODE(exer_dec_env, str_resp, Envelope, resp);
471 CHECK_DECODE(exer_dec_env, str_resp_non_canon, Envelope, resp);
475 /* * * * * Untagged simple types as fields * * * * */
476 /* * * * * * * * * Tests for HL75936 * * * * * * * */
477 // bitstring is exempt : not character-encodable
479 // ~~~~~~~~~~~~ boolean
484 variant (field) "untagged";
486 DECLARE_EXER_ENCODERS(r_b, b);
488 const r_b c_b := { field := true }
489 const universal charstring s_b :=
490 "<r_b>true</r_b>\n\n";
492 testcase encode_ut_bool() runs on UTA
494 CHECK_METHOD(exer_enc_b, c_b, s_b);
497 testcase decode_ut_bool() runs on UTA
499 CHECK_DECODE(exer_dec_b, s_b, r_b, c_b);
502 // ~~~~~~~~~~~~~~~ charstring
507 variant (field) "untagged"
509 DECLARE_EXER_ENCODERS(r_cs, cs);
511 const r_cs c_cs := { field := "Hello, world!" }
512 const universal charstring s_cs :=
513 "<r_cs>Hello, world!</r_cs>\n\n";
515 testcase encode_ut_cs() runs on UTA
517 CHECK_METHOD(exer_enc_cs, c_cs, s_cs);
520 testcase decode_ut_cs() runs on UTA
522 CHECK_DECODE(exer_dec_cs, s_cs, r_cs, c_cs);
525 // ~~~~~~~~~~~~~~~ float
530 variant (field) "untagged"
532 DECLARE_EXER_ENCODERS(r_f, f);
534 const r_f c_f := { field := 42.42 }
535 const universal charstring s_f :=
536 "<r_f>42.420000</r_f>\n\n";
538 testcase encode_ut_f() runs on UTA
540 CHECK_METHOD(exer_enc_f, c_f, s_f);
543 testcase decode_ut_f() runs on UTA
545 CHECK_DECODE(exer_dec_f, s_f, r_f, c_f);
548 // ~~~~~~~~~~~~~~~ integer
553 variant (field) "untagged"
555 DECLARE_EXER_ENCODERS(r_i, i);
557 const r_i c_i := { field := 42 }
558 const universal charstring s_i :=
561 testcase encode_ut_i() runs on UTA
563 CHECK_METHOD(exer_enc_i, c_i, s_i);
566 testcase decode_ut_i() runs on UTA
568 CHECK_DECODE(exer_dec_i, s_i, r_i, c_i);
571 // ~~~~ octetstring (needs hexBinary or base64Binary to be character-encodable)
576 variant (field) "untagged"
577 variant (field) "XSD:hexBinary"
579 DECLARE_EXER_ENCODERS(r_ostr, ostr);
581 const r_ostr c_ostr := { field := 'DEADBEEF'O }
582 const universal charstring s_ostr :=
583 "<r_ostr>DEADBEEF</r_ostr>\n\n";
585 testcase encode_ut_ostr() runs on UTA
587 CHECK_METHOD(exer_enc_ostr, c_ostr, s_ostr);
590 testcase decode_ut_ostr() runs on UTA
592 CHECK_DECODE(exer_dec_ostr, s_ostr, r_ostr, c_ostr);
595 type record r_ostr64 {
599 variant (field) "untagged"
600 variant (field) "XSD:base64Binary"
602 DECLARE_EXER_ENCODERS(r_ostr64, ostr64);
604 const r_ostr64 c_ostr64 := { field := 'DEADBEEF'O }
605 const universal charstring s_ostr64 :=
606 "<r_ostr64>3q2+7w==</r_ostr64>\n\n";
608 testcase encode_ut_ostr64() runs on UTA
610 CHECK_METHOD(exer_enc_ostr64, c_ostr64, s_ostr64);
613 testcase decode_ut_ostr64() runs on UTA
615 CHECK_DECODE(exer_dec_ostr64, s_ostr64, r_ostr64, c_ostr64);
620 // ~~~~~~~~~~~~~~~ universal charstring
622 charstring missing optional,
623 universal charstring field
626 variant (missing) "attribute";
627 variant (field) "untagged";
629 DECLARE_EXER_ENCODERS(r_ustr, ustr);
631 const r_ustr c_ustr := {
633 // LATIN CAPITAL LETTER A WITH RING ABOVE
634 // | LATIN SMALL LETTER O WITH DIAERESIS
635 field := char(0,0,0,197) & "ngstr" & char(0,0,0,246) & "m"
637 const universal charstring s_ustr :=
638 "<r_ustr>" & c_ustr.field & "</r_ustr>\n\n";
640 const r_ustr c_ustr0 := {
644 const universal charstring s_ustr0 :=
647 testcase encode_ut_ustr() runs on UTA
649 CHECK_METHOD(exer_enc_ustr, c_ustr, s_ustr);
650 CHECK_METHOD(exer_enc_ustr, c_ustr0,s_ustr0);
653 testcase decode_ut_ustr() runs on UTA
655 CHECK_DECODE(exer_dec_ustr, s_ustr, r_ustr, c_ustr);
656 CHECK_DECODE(exer_dec_ustr, s_ustr0,r_ustr, c_ustr0);
661 /* * * * * * * * * * * Run it! * * * * * * * * * * */
664 execute(encode_ut());
665 execute(decode_ut());
666 execute(encode_ut2());
667 execute(decode_ut2());
668 execute(encode_deep());
669 execute(decode_deep());
670 execute(encode_wrap());
671 execute(decode_wrap());
672 execute(encode_dir());
673 execute(decode_dir());
674 execute(encode_env());
675 execute(decode_env());
677 execute(encode_ut_bool());
678 execute(decode_ut_bool());
680 execute(encode_ut_cs());
681 execute(decode_ut_cs());
683 execute(encode_ut_f());
684 execute(decode_ut_f());
686 execute(encode_ut_i());
687 execute(decode_ut_i());
689 execute(encode_ut_ostr());
690 execute(decode_ut_ostr());
691 execute(encode_ut_ostr64());
692 execute(decode_ut_ostr64());
694 execute(encode_ut_ustr());
695 execute(decode_ut_ustr());