Sync with 5.4.1
[deliverable/titan.core.git] / regression_test / XML / EXER-whitepaper / Untagged.ttcnpp
CommitLineData
970ed795 1/******************************************************************************
3abe9331 2 * Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
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 ******************************************************************************/
8module Untagged {
9modulepar boolean Untagged_verbose := false;
10#define verbose Untagged_verbose
11#include "../macros.ttcnin"
12
13/* * * * * * * * * * * Untagged applied to a field * * * * * * * * * * */
14
15type enumerated ProductColor { red(0), green(1), blue(2) }
16
17type record ProductInfo {
18 charstring name,
19 ProductColor color
20}
21
22type record AdditionalInfo {
23 integer size,
24 boolean available
25}
26
27type record ProductU {
28 record of ProductColor color,
29 ProductInfo info,
30 AdditionalInfo addInfo,
31 union {
32 integer usd,
33 integer euro
34 } priceInfo
35}
36with {
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";
44}
45
46const ProductU val := {
47 color := { red, green, blue },
48 info := {
49 name := "shirt",
50 color:= red
51 },
52 addInfo := {
53 size := 44,
54 available := false
55 },
56 priceInfo := { usd := 25 }
57}
58
59const universal charstring str_prodU_e :=
60"<ProductU>\n" &
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" &
68"\t<USD>25</USD>\n" &
69"</ProductU>\n" &
70"\n";
71
72const universal charstring str_prodU_b :=
73"<ProductU>\n" &
74"\t<color>\n" &
75"\t\t<red/><green/><blue/>\n" &
76"\t</color>\n" &
77"\t<info>\n" &
78"\t\t<name>shirt</name>\n" &
79"\t\t<color><red/></color>\n" &
80"\t</info>\n" &
81"\t<addInfo>\n" &
82"\t\t<size>44</size>\n" &
83"\t\t<available><false/></available>\n" &
84"\t</addInfo>\n" &
85"\t<priceInfo>\n" &
86"\t\t<usd>25</usd>\n" &
87"\t</priceInfo>\n" &
88"</ProductU>\n" &
89"\n";
90
91DECLARE_XER_ENCODERS(ProductU, prodU);
92DECLARE_EXER_ENCODERS(ProductU, prodU);
93
94type component UTA {}
95
96testcase encode_ut() runs on UTA
97{
98 CHECK_METHOD(bxer_enc_prodU, val, str_prodU_b);
99 CHECK_METHOD(exer_enc_prodU, val, str_prodU_e);
100}
101
102testcase decode_ut() runs on UTA
103{
104 CHECK_DECODE(bxer_dec_prodU, str_prodU_b, ProductU, val);
105 CHECK_DECODE(exer_dec_prodU, str_prodU_e, ProductU, val);
106}
107
108/* * * * * * * * * * * Untagged applied to a type * * * * * * * * * * */
109
110type record ProductInfo2 {
111 charstring name,
112 ProductColor color
113}
114with {
115 variant "untagged";
116 variant "name as 'ProductInfo'";
117}
118
119type record AdditionalInfo2 {
120 integer size,
121 boolean available
122}
123with {
124 variant "untagged";
125 variant "name as 'AdditionalInfo'";
126}
127
128type record Product2 {
129 record of ProductColor color,
130 ProductInfo2 info,
131 AdditionalInfo2 addInfo,
132 union {
133 integer usd,
134 integer euro
135 } priceInfo
136}
137with {
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";
145}
146
147DECLARE_XER_ENCODERS(Product2, prod2);
148DECLARE_EXER_ENCODERS(Product2, prod2); // EXER only
149
150const Product2 val2 := {
151 color := { red, green, blue },
152 info := {
153 name := "shirt",
154 color:= red
155 },
156 addInfo := {
157 size := 44,
158 available := false
159 },
160 priceInfo := { usd := 25 }
161}
162
163const universal charstring str_prod_b2 :=
164"<Product2>\n" &
165"\t<color>\n" &
166"\t\t<red/><green/><blue/>\n" &
167"\t</color>\n" &
168"\t<info>\n" &
169"\t\t<name>shirt</name>\n" &
170"\t\t<color><red/></color>\n" &
171"\t</info>\n" &
172"\t<addInfo>\n" &
173"\t\t<size>44</size>\n" &
174"\t\t<available><false/></available>\n" &
175"\t</addInfo>\n" &
176"\t<priceInfo>\n" &
177"\t\t<usd>25</usd>\n" &
178"\t</priceInfo>\n" &
179"</Product2>\n" &
180"\n";
181
182testcase encode_ut2() runs on UTA
183{
184 CHECK_METHOD(bxer_enc_prod2, val2, str_prod_b2);
185 CHECK_METHOD(exer_enc_prod2, val2, str_prodU_e);
186}
187
188testcase decode_ut2() runs on UTA
189{
190 CHECK_DECODE(bxer_dec_prod2, str_prod_b2, Product2, val2);
191 CHECK_DECODE(exer_dec_prod2, str_prodU_e, Product2, val2);
192}
193
194/* * * * * * * * * * * Nested untagged * * * * * * * * * * */
195
196type record level0 {
197 level1 f1
198}
199with {
200 variant (f1) "untagged";
201 variant "untagged"
202}
203
204type record level1 {
205 level2 f2
206}
207with { variant (f2) "untagged" }
208
209type record level2 {
210 level3 f3
211}
212with { variant (f3) "untagged" }
213
214type union level3 {
215 integer i,
216 float f
217}
218
219DECLARE_XER_ENCODERS(level0, l0);
220DECLARE_EXER_ENCODERS(level0, l0);
221
222const level0 cl0 := {
223 f1 := { // a level1
224 f2 := { // a level2
225 f3 := { i := 13 }
226 }
227 }
228}
229
230const universal charstring bstr_cl0 :=
231"<level0>\n" &
232"\t<f1>\n" &
233"\t\t<f2>\n" &
234"\t\t\t<f3>\n" &
235"\t\t\t\t<i>13</i>\n" &
236"\t\t\t</f3>\n" &
237"\t\t</f2>\n" &
238"\t</f1>\n" &
239"</level0>\n\n";
240
241const universal charstring estr_cl0 :=
242// This is the "right thing" because UNTAGGED is ignored for top-level types
243"<level0>\n" &
244"\t<i>13</i>\n" &
245"</level0>\n\n";
246
247testcase encode_deep() runs on UTA
248{
249 CHECK_METHOD(bxer_enc_l0, cl0, bstr_cl0);
250 CHECK_METHOD(exer_enc_l0, cl0, estr_cl0);
251}
252
253testcase decode_deep() runs on UTA
254{
255 CHECK_DECODE(bxer_dec_l0, bstr_cl0, level0, cl0);
256 CHECK_DECODE(exer_dec_l0, estr_cl0, level0, cl0);
257}
258
259/* * * * * * * * * * * Deeper * * * * * * * * * * */
260
261type union ch0 {
262 level0 l0,
263 record of integer numbers
264}
265with {
266 variant (numbers) "untagged"
267}
268
269type record wrapper {
270 ch0 c0
271}
272with {
273 variant (c0) "untagged"
274}
275
276DECLARE_XER_ENCODERS(wrapper, w);
277DECLARE_EXER_ENCODERS(wrapper, w);
278
279const wrapper cw0 := {
280 c0 := {
281 l0 := cl0
282 }
283}
284
285const wrapper cw1 := {
286 c0 := {
287 numbers := { 3, 14, 15, 92, 6 }
288 }
289}
290
291const universal charstring bstr_cw0 :=
292"<wrapper>\n" &
293"\t<c0>\n" &
294"\t\t<l0>\n" &
295"\t\t\t<f1>\n" &
296"\t\t\t\t<f2>\n" &
297"\t\t\t\t\t<f3>\n" &
298"\t\t\t\t\t\t<i>13</i>\n" &
299"\t\t\t\t\t</f3>\n" &
300"\t\t\t\t</f2>\n" &
301"\t\t\t</f1>\n" &
302"\t\t</l0>\n" &
303"\t</c0>\n" &
304"</wrapper>\n\n";
305
306const universal charstring estr_cw0 :=
307"<wrapper>\n" &
308"\t<i>13</i>\n" &
309"</wrapper>\n\n";
310
311const universal charstring bstr_cw1 :=
312"<wrapper>\n" &
313"\t<c0>\n" &
314"\t\t<numbers>\n" &
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" &
320"\t\t</numbers>\n" &
321"\t</c0>\n" &
322"</wrapper>\n\n";
323
324const universal charstring estr_cw1 :=
325"<wrapper>\n" &
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" &
331"</wrapper>\n\n";
332
333testcase encode_wrap() runs on UTA
334{
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);
339}
340
341testcase decode_wrap() runs on UTA
342{
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);
347}
348
349/* * * * * * * * HK76145 * * * * * * * * * */
350
351type record dir {
352 record of record {
353 record {
354 charstring name,
355 integer size
356 } folder
357 } lista
358}
359with {
360 variant (lista) "untagged"
361 variant (lista[-]) "untagged"
362}
363
364DECLARE_XER_ENCODERS(dir, dir);
365DECLARE_EXER_ENCODERS(dir, dir);
366
367const dir durr := {
368 lista := {{
369 folder := {
370 name := "foo",
371 size := 13
372 }
373 }}
374}
375
376const universal charstring bstr_durr :=
377"<dir>\n" &
378"\t<lista>\n" &
379"\t\t<SEQUENCE>\n" &
380"\t\t\t<folder>\n" &
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" &
385"\t</lista>\n" &
386"</dir>\n\n";
387
388const universal charstring estr_durr :=
389"<dir>\n" &
390"\t<folder>\n" &
391"\t\t<name>foo</name>\n" &
392"\t\t<size>13</size>\n" &
393"\t</folder>\n" &
394"</dir>\n\n";
395
396
397
398testcase encode_dir() runs on UTA
399{
400 CHECK_METHOD(bxer_enc_dir, durr, bstr_durr);
401 CHECK_METHOD(exer_enc_dir, durr, estr_durr);
402}
403
404testcase decode_dir() runs on UTA
405{
406 CHECK_DECODE(bxer_dec_dir, bstr_durr, dir, durr);
407 CHECK_DECODE(exer_dec_dir, estr_durr, dir, durr);
408}
409
410/* * * * * * * * Empty record in an untagged record-of * * * * * * * */
411
412type record Envelope {
413 //record of Header header optional,
414 Body body
415}
416
417type union Body {
418 record {} fault,
419 record of Content content_list
420}
421with {
422 variant (content_list) "untagged";
423 variant (content_list[-]) "untagged";
424}
425
426type union Content {
427 Logout logout,
428 LogoutResponse logoutResponse
429}
430with {
431 variant (logout ) "name as capitalized"
432 variant (logoutResponse) "name as capitalized"
433}
434
435type record Logout {};
436type record LogoutResponse {};
437
438DECLARE_XER_ENCODERS(Envelope, env);
439DECLARE_EXER_ENCODERS(Envelope, env);
440
441const Envelope resp := {
442 body := {
443 content_list := {{ logoutResponse := {} }}
444 }
445}
446
447const universal charstring str_resp :=
448"<Envelope>\n" &
449"\t<body>\n" &
450"\t\t<LogoutResponse/>\n" &
451"\t</body>" &
452"\n</Envelope>\n\n";
453
454const universal charstring str_resp_non_canon :=
455"<Envelope>\n" &
456"\t<body>\n" &
457"\t\t<LogoutResponse>\n" &
458"\t\t</LogoutResponse>\n" &
459"\t</body>" &
460"\n</Envelope>\n\n";
461
462
463testcase encode_env() runs on UTA
464{
465 CHECK_METHOD(exer_enc_env, resp, str_resp);
466}
467
468testcase decode_env() runs on UTA
469{
470 CHECK_DECODE(exer_dec_env, str_resp, Envelope, resp);
471 CHECK_DECODE(exer_dec_env, str_resp_non_canon, Envelope, resp);
472}
473
474
475/* * * * * Untagged simple types as fields * * * * */
476/* * * * * * * * * Tests for HL75936 * * * * * * * */
477// bitstring is exempt : not character-encodable
478
479// ~~~~~~~~~~~~ boolean
480type record r_b {
481 boolean field
482}
483with {
484 variant (field) "untagged";
485}
486DECLARE_EXER_ENCODERS(r_b, b);
487
488const r_b c_b := { field := true }
489const universal charstring s_b :=
490"<r_b>true</r_b>\n\n";
491
492testcase encode_ut_bool() runs on UTA
493{
494 CHECK_METHOD(exer_enc_b, c_b, s_b);
495}
496
497testcase decode_ut_bool() runs on UTA
498{
499 CHECK_DECODE(exer_dec_b, s_b, r_b, c_b);
500}
501
502// ~~~~~~~~~~~~~~~ charstring
503type record r_cs {
504 charstring field
505}
506with {
507 variant (field) "untagged"
508}
509DECLARE_EXER_ENCODERS(r_cs, cs);
510
511const r_cs c_cs := { field := "Hello, world!" }
512const universal charstring s_cs :=
513"<r_cs>Hello, world!</r_cs>\n\n";
514
515testcase encode_ut_cs() runs on UTA
516{
517 CHECK_METHOD(exer_enc_cs, c_cs, s_cs);
518}
519
520testcase decode_ut_cs() runs on UTA
521{
522 CHECK_DECODE(exer_dec_cs, s_cs, r_cs, c_cs);
523}
524
525// ~~~~~~~~~~~~~~~ float
526type record r_f {
527 float field
528}
529with {
530 variant (field) "untagged"
531}
532DECLARE_EXER_ENCODERS(r_f, f);
533
534const r_f c_f := { field := 42.42 }
535const universal charstring s_f :=
536"<r_f>42.420000</r_f>\n\n";
537
538testcase encode_ut_f() runs on UTA
539{
540 CHECK_METHOD(exer_enc_f, c_f, s_f);
541}
542
543testcase decode_ut_f() runs on UTA
544{
545 CHECK_DECODE(exer_dec_f, s_f, r_f, c_f);
546}
547
548// ~~~~~~~~~~~~~~~ integer
549type record r_i {
550 integer field
551}
552with {
553 variant (field) "untagged"
554}
555DECLARE_EXER_ENCODERS(r_i, i);
556
557const r_i c_i := { field := 42 }
558const universal charstring s_i :=
559"<r_i>42</r_i>\n\n";
560
561testcase encode_ut_i() runs on UTA
562{
563 CHECK_METHOD(exer_enc_i, c_i, s_i);
564}
565
566testcase decode_ut_i() runs on UTA
567{
568 CHECK_DECODE(exer_dec_i, s_i, r_i, c_i);
569}
570
571// ~~~~ octetstring (needs hexBinary or base64Binary to be character-encodable)
572type record r_ostr {
573 octetstring field
574}
575with {
576 variant (field) "untagged"
577 variant (field) "XSD:hexBinary"
578}
579DECLARE_EXER_ENCODERS(r_ostr, ostr);
580
581const r_ostr c_ostr := { field := 'DEADBEEF'O }
582const universal charstring s_ostr :=
583"<r_ostr>DEADBEEF</r_ostr>\n\n";
584
585testcase encode_ut_ostr() runs on UTA
586{
587 CHECK_METHOD(exer_enc_ostr, c_ostr, s_ostr);
588}
589
590testcase decode_ut_ostr() runs on UTA
591{
592 CHECK_DECODE(exer_dec_ostr, s_ostr, r_ostr, c_ostr);
593}
594
595type record r_ostr64 {
596 octetstring field
597}
598with {
599 variant (field) "untagged"
600 variant (field) "XSD:base64Binary"
601}
602DECLARE_EXER_ENCODERS(r_ostr64, ostr64);
603
604const r_ostr64 c_ostr64 := { field := 'DEADBEEF'O }
605const universal charstring s_ostr64 :=
606"<r_ostr64>3q2+7w==</r_ostr64>\n\n";
607
608testcase encode_ut_ostr64() runs on UTA
609{
610 CHECK_METHOD(exer_enc_ostr64, c_ostr64, s_ostr64);
611}
612
613testcase decode_ut_ostr64() runs on UTA
614{
615 CHECK_DECODE(exer_dec_ostr64, s_ostr64, r_ostr64, c_ostr64);
616}
617
618
619
620// ~~~~~~~~~~~~~~~ universal charstring
621type record r_ustr {
622 charstring missing optional,
623 universal charstring field
624}
625with {
626 variant (missing) "attribute";
627 variant (field) "untagged";
628}
629DECLARE_EXER_ENCODERS(r_ustr, ustr);
630
631const r_ustr c_ustr := {
632 missing := omit,
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"
636}
637const universal charstring s_ustr :=
638"<r_ustr>" & c_ustr.field & "</r_ustr>\n\n";
639
640const r_ustr c_ustr0 := {
641 missing := omit,
642 field := ""
643}
644const universal charstring s_ustr0 :=
645"<r_ustr/>\n\n";
646
647testcase encode_ut_ustr() runs on UTA
648{
649 CHECK_METHOD(exer_enc_ustr, c_ustr, s_ustr);
650 CHECK_METHOD(exer_enc_ustr, c_ustr0,s_ustr0);
651}
652
653testcase decode_ut_ustr() runs on UTA
654{
655 CHECK_DECODE(exer_dec_ustr, s_ustr, r_ustr, c_ustr);
656 CHECK_DECODE(exer_dec_ustr, s_ustr0,r_ustr, c_ustr0);
657}
658
659
660
51fa56b9 661// ------- optional record of
662type record length (1 .. infinity) of charstring RoCS
663with {
664 variant ([-]) "name as 'str'";
665}
666
667type record r_recof {
668 record length (1 .. infinity) of integer num_list optional,
669 RoCS str_list optional
670}
671with {
672 variant(num_list) "untagged";
673 variant(num_list[-]) "name as 'num'";
674 variant(str_list) "untagged";
675}
676
677DECLARE_EXER_ENCODERS(r_recof, recof);
678
679const r_recof c_recof := { num_list := omit, str_list := omit };
680
681const universal charstring s_recof := "<r_recof/>\n\n";
682
683testcase encode_ut_recof() runs on UTA
684{
685 CHECK_METHOD(exer_enc_recof, c_recof, s_recof);
686}
687
688testcase decode_ut_recof() runs on UTA
689{
690 CHECK_DECODE(exer_dec_recof, s_recof, r_recof, c_recof);
691}
692
693
694
970ed795
EL
695/* * * * * * * * * * * Run it! * * * * * * * * * * */
696
697control {
698 execute(encode_ut());
699 execute(decode_ut());
700 execute(encode_ut2());
701 execute(decode_ut2());
702 execute(encode_deep());
703 execute(decode_deep());
704 execute(encode_wrap());
705 execute(decode_wrap());
706 execute(encode_dir());
707 execute(decode_dir());
708 execute(encode_env());
709 execute(decode_env());
710 // // // //
711 execute(encode_ut_bool());
712 execute(decode_ut_bool());
713
714 execute(encode_ut_cs());
715 execute(decode_ut_cs());
716
717 execute(encode_ut_f());
718 execute(decode_ut_f());
719
720 execute(encode_ut_i());
721 execute(decode_ut_i());
722
723 execute(encode_ut_ostr());
724 execute(decode_ut_ostr());
725 execute(encode_ut_ostr64());
726 execute(decode_ut_ostr64());
727
728 execute(encode_ut_ustr());
729 execute(decode_ut_ustr());
730
51fa56b9 731 execute(encode_ut_recof());
732 execute(decode_ut_recof());
970ed795
EL
733}
734
735}
736with {
737encode "XML";
738}
This page took 0.049967 seconds and 5 git commands to generate.