Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / XML / TTCNandXML / Marx.ttcnpp
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 ******************************************************************************/
8 module Marx {
9 modulepar boolean Marx_verbose := false;
10 #define verbose Marx_verbose
11 #include "../macros.ttcnin"
12
13
14 type record Silent {}
15
16
17 //type enumerated Marxes { chico, groucho, harpo };
18
19 type record Brothers {
20 record of enumerated { chico,groucho,harpo } order,
21 integer chico,
22 charstring groucho,
23 Silent harpo
24 }
25 with {
26 variant "useOrder";
27 }
28
29 DECLARE_XER_ENCODERS(Brothers, marx);
30 DECLARE_EXER_ENCODERS(Brothers, marx);
31
32 type component MGM {}
33 type component Paramount {}
34
35 const universal charstring str_grimm_b :=
36 "<Brothers>\n" &
37 "\t<order>\n" &
38 "\t\t<chico/><groucho/><harpo/>\n" &
39 "\t</order>\n" &
40 "\t<chico>17</chico>\n" &
41 "\t<groucho>Je suis Marxiste, tendance Groucho</groucho>\n" &
42 "\t<harpo/>\n" &
43 "</Brothers>\n" &
44 "\n";
45
46 const universal charstring str_grimm_e :=
47 "<Brothers>\n" &
48 "\t<chico>17</chico>\n" &
49 "\t<groucho>Je suis Marxiste, tendance Groucho</groucho>\n" &
50 "\t<harpo/>\n" &
51 "</Brothers>\n" &
52 "\n";
53
54 const universal charstring str_grimm_b2 :=
55 "<Brothers>\n" &
56 "\t<order>\n" &
57 "\t\t<groucho/><harpo/><chico/>\n" &
58 "\t</order>\n" &
59 "\t<chico>17</chico>\n" &
60 "\t<groucho>Je suis Marxiste, tendance Groucho</groucho>\n" &
61 "\t<harpo/>\n" &
62 "</Brothers>\n" &
63 "\n";
64
65 const universal charstring str_grimm_e2 :=
66 "<Brothers>\n" &
67 "\t<groucho>Je suis Marxiste, tendance Groucho</groucho>\n" &
68 "\t<harpo/>\n" &
69 "\t<chico>17</chico>\n" &
70 "</Brothers>\n" &
71 "\n";
72
73 testcase duck_soup () runs on Paramount
74 {
75 var Brothers grimm := {
76 { chico, groucho, harpo },
77 17, "Je suis Marxiste, tendance Groucho", {}
78 }
79 CHECK_METHOD(bxer_enc_marx, grimm, str_grimm_b);
80 CHECK_METHOD(exer_enc_marx, grimm, str_grimm_e);
81
82 grimm.order := { groucho, harpo, chico };
83
84 CHECK_METHOD(bxer_enc_marx, grimm, str_grimm_b2);
85 CHECK_METHOD(exer_enc_marx, grimm, str_grimm_e2);
86 }
87
88 testcase a_night_at_the_opera () runs on MGM
89 {
90 var Brothers grimm := {
91 { chico, groucho, harpo },
92 17, "Je suis Marxiste, tendance Groucho", {}
93 }
94 CHECK_DECODE(bxer_dec_marx, str_grimm_b, Brothers, grimm);
95 CHECK_DECODE(exer_dec_marx, str_grimm_e, Brothers, grimm);
96 }
97
98 /* * * * * * * * * * * * * * */
99
100 type record Stooges {
101 record of universal charstring emb,
102 record of enumerated { curly, larry, moe } ord,
103 integer curly,
104 float larry,
105 boolean moe
106 }
107 with {
108 variant "useOrder";
109 variant "embedValues";
110 }
111
112 DECLARE_XER_ENCODERS (Stooges, st3);
113 DECLARE_EXER_ENCODERS(Stooges, st3);
114
115 const universal charstring str_stg_b :=
116 "<Stooges>\n" &
117
118 "\t<emb>\n" &
119 "\t\t<UNIVERSAL_CHARSTRING/>\n" &
120 "\t\t<UNIVERSAL_CHARSTRING>. is curly</UNIVERSAL_CHARSTRING>\n" &
121 "\t\t<UNIVERSAL_CHARSTRING>.. is bald</UNIVERSAL_CHARSTRING>\n" &
122 "\t\t<UNIVERSAL_CHARSTRING>...is tall</UNIVERSAL_CHARSTRING>\n" &
123 "\t</emb>\n" &
124
125 "\t<ord>\n" &
126 "\t\t<larry/><curly/><moe/>\n" &
127 "\t</ord>\n" &
128 "\t<curly>13</curly>\n" &
129 "\t<larry>1.414213</larry>\n" &
130 "\t<moe><true/></moe>\n" &
131 "</Stooges>\n" &
132 "\n";
133
134 const universal charstring str_stg_e :=
135 "<Stooges>" &
136 "" & // the first embedded string (empty in this case)
137 "<larry>1.414213</larry>" &
138 ". is curly" & // the embedded strings are not affected by USE-ORDER
139 "<curly>13</curly>" &
140 ".. is bald" &
141 "<moe>true</moe>" &
142 "...is tall" &
143 "</Stooges>" &
144 "\n";
145
146
147 const Stooges s3 := {
148 emb := {"",". is curly",".. is bald","...is tall"},
149 ord := { larry, curly, moe },
150 curly := 13,
151 larry := 1.414213,
152 moe := true
153 }
154
155 testcase beer_and_pretzels() runs on MGM
156 {
157 CHECK_METHOD(bxer_enc_st3, s3, str_stg_b);
158 CHECK_METHOD(exer_enc_st3, s3, str_stg_e);
159 }
160
161 testcase plane_nuts() runs on MGM
162 {
163 var Stooges expected := s3;
164 CHECK_DECODE(bxer_dec_st3, str_stg_b, Stooges, expected);
165 CHECK_DECODE(exer_dec_st3, str_stg_e, Stooges, expected);
166 }
167
168 control {
169 execute(duck_soup()); // encoding use-order
170 execute(a_night_at_the_opera()); // decode ===//===
171 execute(beer_and_pretzels()); // encoding use-order + embed-values
172 execute(plane_nuts()); // decode ===//=== ===//===
173 }
174
175 }
176 with {
177 encode "XML"
178 }
This page took 0.059529 seconds and 5 git commands to generate.