Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / XML / EXER-whitepaper / AnyElementOptional2.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 AnyElementOptional2 {
9
10 // More complex tests for optional anyElement coding instructions
11 // Testing if omitted anyElement fields (in a record) interpret the next field or
12 // the next record as the anyElement.
13
14 modulepar boolean AnyElement_verbose := false;
15
16 #define verbose AnyElement_verbose
17 #include "../macros.ttcnin"
18
19 // Types
20
21 type component AE {}
22
23 type record any_elem_outer1 {
24 record of union {
25 any_elem_inner1 inner,
26 float ft
27 } elem_list
28 } with {
29 variant(elem_list[-]) "name as 'elem'";
30 }
31
32 type record any_elem_inner1 {
33 integer id,
34 universal charstring any_elem optional,
35 integer ival
36 } with {
37 variant (id) "attribute";
38 variant (any_elem) "anyElement except 'http://www.somewhere.com'";
39 }
40
41
42 type record any_elem_outer2 {
43 record of union {
44 any_elem_inner2 inner,
45 float ft
46 } elem_list
47 } with {
48 variant(elem_list[-]) "name as 'elem'";
49 }
50
51 type record any_elem_inner2 {
52 integer id,
53 universal charstring any_elem optional,
54 integer ival
55 } with {
56 variant (any_elem) "anyElement except 'http://www.somewhere.com'";
57 }
58
59
60 type record any_elem_outer3 {
61 record of union {
62 any_elem_inner3 inner,
63 float ft
64 } elem_list
65 } with {
66 variant(elem_list[-]) "name as 'elem'";
67 }
68
69 type record any_elem_inner3 {
70 integer id,
71 universal charstring any_elem optional
72 } with {
73 variant (id) "attribute";
74 variant (any_elem) "anyElement except 'http://www.somewhere.com'";
75 }
76
77
78 type record any_elem_outer4 {
79 record of union {
80 any_elem_inner4 inner,
81 float ft
82 } elem_list
83 } with {
84 variant(elem_list[-]) "name as 'elem'";
85 }
86
87
88 type record any_elem_inner4 {
89 integer id,
90 universal charstring any_elem optional
91 } with {
92 variant (any_elem) "anyElement except 'http://www.somewhere.com'";
93 }
94
95
96
97 // Constants
98
99 const any_elem_outer1 c_outer1 := { {
100 { inner := { 11, "<something/>", 7 } },
101 { inner := { 2, omit, 19 } },
102 { ft := 6.1 }
103 } };
104
105 const universal charstring c_outer1_enc :=
106 "<psw:any_elem_outer1 xmlns:psw='http://www.somewhere.com'>\n" &
107 "\t<psw:elem_list>\n" &
108 "\t\t<psw:elem>\n" &
109 "\t\t\t<psw:inner id='11'>\n" &
110 "\t\t\t\t<something/>\n" &
111 "\t\t\t\t<psw:ival>7</psw:ival>\n" &
112 "\t\t\t</psw:inner>\n" &
113 "\t\t</psw:elem>\n" &
114 "\t\t<psw:elem>\n" &
115 "\t\t\t<psw:inner id='2'>\n" &
116 "\t\t\t\t<psw:ival>19</psw:ival>\n" &
117 "\t\t\t</psw:inner>\n" &
118 "\t\t</psw:elem>\n" &
119 "\t\t<psw:elem>\n" &
120 "\t\t\t<psw:ft>6.100000</psw:ft>\n" &
121 "\t\t</psw:elem>\n" &
122 "\t</psw:elem_list>\n" &
123 "</psw:any_elem_outer1>\n\n";
124
125
126 const any_elem_outer2 c_outer2 := { {
127 { inner := { 11, "<something/>", 7 } },
128 { inner := { 2, omit, 19 } },
129 { ft := 6.1 }
130 } };
131
132 const universal charstring c_outer2_enc :=
133 "<psw:any_elem_outer2 xmlns:psw='http://www.somewhere.com'>\n" &
134 "\t<psw:elem_list>\n" &
135 "\t\t<psw:elem>\n" &
136 "\t\t\t<psw:inner>\n" &
137 "\t\t\t\t<psw:id>11</psw:id>\n" &
138 "\t\t\t\t<something/>\n" &
139 "\t\t\t\t<psw:ival>7</psw:ival>\n" &
140 "\t\t\t</psw:inner>\n" &
141 "\t\t</psw:elem>\n" &
142 "\t\t<psw:elem>\n" &
143 "\t\t\t<psw:inner>\n" &
144 "\t\t\t\t<psw:id>2</psw:id>\n" &
145 "\t\t\t\t<psw:ival>19</psw:ival>\n" &
146 "\t\t\t</psw:inner>\n" &
147 "\t\t</psw:elem>\n" &
148 "\t\t<psw:elem>\n" &
149 "\t\t\t<psw:ft>6.100000</psw:ft>\n" &
150 "\t\t</psw:elem>\n" &
151 "\t</psw:elem_list>\n" &
152 "</psw:any_elem_outer2>\n\n";
153
154
155 const any_elem_outer3 c_outer3 := { {
156 { inner := { 11, "<something/>" } },
157 { inner := { 2, omit } },
158 { ft := 6.1 }
159 } };
160
161 const universal charstring c_outer3_enc :=
162 "<psw:any_elem_outer3 xmlns:psw='http://www.somewhere.com'>\n" &
163 "\t<psw:elem_list>\n" &
164 "\t\t<psw:elem>\n" &
165 "\t\t\t<psw:inner id='11'>\n" &
166 "\t\t\t\t<something/>\n" &
167 "\t\t\t</psw:inner>\n" &
168 "\t\t</psw:elem>\n" &
169 "\t\t<psw:elem>\n" &
170 "\t\t\t<psw:inner id='2'/>\n" &
171 "\t\t</psw:elem>\n" &
172 "\t\t<psw:elem>\n" &
173 "\t\t\t<psw:ft>6.100000</psw:ft>\n" &
174 "\t\t</psw:elem>\n" &
175 "\t</psw:elem_list>\n" &
176 "</psw:any_elem_outer3>\n\n";
177
178
179 const any_elem_outer4 c_outer4 := { {
180 { inner := { 11, "<something/>" } },
181 { inner := { 2, omit } },
182 { ft := 6.1 }
183 } };
184
185 const universal charstring c_outer4_enc :=
186 "<psw:any_elem_outer4 xmlns:psw='http://www.somewhere.com'>\n" &
187 "\t<psw:elem_list>\n" &
188 "\t\t<psw:elem>\n" &
189 "\t\t\t<psw:inner>\n" &
190 "\t\t\t\t<psw:id>11</psw:id>\n" &
191 "\t\t\t\t<something/>\n" &
192 "\t\t\t</psw:inner>\n" &
193 "\t\t</psw:elem>\n" &
194 "\t\t<psw:elem>\n" &
195 "\t\t\t<psw:inner>\n" &
196 "\t\t\t\t<psw:id>2</psw:id>\n" &
197 "\t\t\t</psw:inner>\n" &
198 "\t\t</psw:elem>\n" &
199 "\t\t<psw:elem>\n" &
200 "\t\t\t<psw:ft>6.100000</psw:ft>\n" &
201 "\t\t</psw:elem>\n" &
202 "\t</psw:elem_list>\n" &
203 "</psw:any_elem_outer4>\n\n";
204
205
206
207 // Encoding & decoding functions
208
209 DECLARE_EXER_ENCODERS(any_elem_outer1, outer1);
210 DECLARE_EXER_ENCODERS(any_elem_outer2, outer2);
211 DECLARE_EXER_ENCODERS(any_elem_outer3, outer3);
212 DECLARE_EXER_ENCODERS(any_elem_outer4, outer4);
213
214 // Test cases
215
216 testcase encode_any_opt_complex1() runs on AE {
217 CHECK_METHOD(exer_enc_outer1, c_outer1, c_outer1_enc);
218 }
219
220 testcase decode_any_opt_complex1() runs on AE {
221 CHECK_DECODE(exer_dec_outer1, c_outer1_enc, any_elem_outer1, c_outer1);
222 }
223
224 testcase encode_any_opt_complex2() runs on AE {
225 CHECK_METHOD(exer_enc_outer2, c_outer2, c_outer2_enc);
226 }
227
228 testcase decode_any_opt_complex2() runs on AE {
229 CHECK_DECODE(exer_dec_outer2, c_outer2_enc, any_elem_outer2, c_outer2);
230 }
231
232 testcase encode_any_opt_complex3() runs on AE {
233 CHECK_METHOD(exer_enc_outer3, c_outer3, c_outer3_enc);
234 }
235
236 testcase decode_any_opt_complex3() runs on AE {
237 CHECK_DECODE(exer_dec_outer3, c_outer3_enc, any_elem_outer3, c_outer3);
238 }
239
240 testcase encode_any_opt_complex4() runs on AE {
241 CHECK_METHOD(exer_enc_outer4, c_outer4, c_outer4_enc);
242 }
243
244 testcase decode_any_opt_complex4() runs on AE {
245 CHECK_DECODE(exer_dec_outer4, c_outer4_enc, any_elem_outer4, c_outer4);
246 }
247
248
249
250 control {
251 execute(encode_any_opt_complex1());
252 execute(decode_any_opt_complex1());
253 execute(encode_any_opt_complex2());
254 execute(decode_any_opt_complex2());
255 execute(encode_any_opt_complex3());
256 execute(decode_any_opt_complex3());
257 execute(encode_any_opt_complex4());
258 execute(decode_any_opt_complex4());
259 }
260
261 } with {
262 encode "XML";
263 variant "namespace as 'http://www.somewhere.com' prefix 'psw'";
264 variant "elementFormQualified";
265 }
This page took 0.04114 seconds and 5 git commands to generate.