Sync with 5.2.0
[deliverable/titan.core.git] / regression_test / XML / XER / Txernested.ttcnpp
CommitLineData
970ed795
EL
1/******************************************************************************
2 * Copyright (c) 2000-2014 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 ******************************************************************************/
8module Txernested
9{
10modulepar boolean Txernested_verbose := false;
11#define verbose Txernested_verbose
12#include "../macros.ttcnin"
13
14external function flatten(inout universal charstring par) ;
15
16import from Asntypes all;
17import from AsnValues all;
18
19type set of record {
20 set {
21 integer ts1,
22 boolean ts2
23 } f1 optional,
24 deep f2
25} nestor; // TTCNv3 equivalent of Nestor
26
27// SEQ OF SET OF SEQ OF SET OF SEQUENCE {
28type record of set of record of set of record {
29 // your CHOICE { only REAL } OPTIONAL
30 union { float only } your optional
31} deep
32
33/*
34 type record nested_inner {
35 set {
36 integer ts1,
37 boolean ts2
38 } f1 optional,
39 deep f2
40 } ;
41
42 const nested_inner ni := {
43 f1 := omit,
44 f2 := {{{{}}}}
45 }
46
47 const nested_inner eki_eki :=
48 {
49
50 { ts1 := 17, ts2 := true }
51 , {}
52 }
53 */
54const nestor n3 :=
55{
56 { omit, {} },
57 { omit, {{}} },
58 { omit, {{{}}} }
59}
60
61type component Tnested {}
62
63 DECLARE_XER_ENCODERS(nestor, nst);
64DECLARE_EXER_ENCODERS(nestor, nst)
65 DECLARE_XER_ENCODERS(Nestor, Nst);
66DECLARE_EXER_ENCODERS(Nestor, Nst)
67 DECLARE_XER_ENCODERS(NestorEx, Nstx);
68DECLARE_EXER_ENCODERS(NestorEx, Nstx)
69
70//const charstring oftype := "oftype";
71
72const deep d_empty := {{{{}}}}
73const Deep D_empty := {{{{}}}}
74const nestor n_empty := {
75}
76const nestor n2 := {
77 { omit, {} }
78}
79const charstring s_empty := "<nestor/>\n\n";
80
81const charstring s_2 :=
82"<nestor>\n" &
83"\t<SEQUENCE>\n" &
84"\t\t<f2/>\n" &
85"\t</SEQUENCE>\n" &
86"</nestor>\n\n";
87
88const charstring s_3 :=
89"<nestor>\n" &
90
91"\t<SEQUENCE>\n" &
92"\t\t<f2/>\n" &
93"\t</SEQUENCE>\n" &
94
95"\t<SEQUENCE>\n" &
96"\t\t<f2>\n" &
97"\t\t\t<SET_OF/>\n" &
98"\t\t</f2>\n" &
99"\t</SEQUENCE>\n" &
100
101"\t<SEQUENCE>\n" &
102"\t\t<f2>\n" &
103"\t\t\t<SET_OF>\n" &
104"\t\t\t\t<SEQUENCE_OF/>\n" &
105"\t\t\t</SET_OF>\n" &
106"\t\t</f2>\n" &
107"\t</SEQUENCE>\n" &
108
109"</nestor>\n\n";
110
111/////////////////////////////////////////////////////////////////////
112testcase encode_nest() runs on Tnested {
113 var universal charstring expected := s_empty;
114 CHECK_METHOD(bxer_enc_nst, n_empty, expected);
115 CHECK_METHOD(exer_enc_nst, n_empty, expected);
116 flatten(expected);
117 CHECK_METHOD(cxer_enc_nst, n_empty, expected & lf);
118
119 expected := s_2;
120 CHECK_METHOD(bxer_enc_nst, n2, expected);
121 CHECK_METHOD(exer_enc_nst, n2, expected);
122 flatten(expected);
123 CHECK_METHOD(cxer_enc_nst, n2, expected & lf);
124
125 expected := s_3;
126 CHECK_METHOD(bxer_enc_nst, n3, expected);
127 CHECK_METHOD(exer_enc_nst, n3, expected);
128 flatten(expected);
129 CHECK_METHOD(cxer_enc_nst, n3, expected & lf);
130}
131
132testcase decode_nest() runs on Tnested {
133 var nestor expected;
134
135 expected := n_empty;
136 CHECK_DECODE2(nst, s_empty, nestor, expected);
137
138 expected := n2;
139 CHECK_DECODE2(nst, s_2, nestor, expected);
140
141 expected := n3;
142 CHECK_DECODE2(nst, s_3, nestor, expected);
143}
144
145/////////////////////////////////////////////////////////////////////
146
147const charstring nstr_nixtor :=
148"<Nestor>\n" &
149"\t<SEQUENCE>\n" &
150"\t\t<name>nixtor</name>\n" &
151"\t\t<f2/>\n" &
152"\t</SEQUENCE>\n" &
153"</Nestor>\n\n";
154
155const charstring nstr_nixtor2 :=
156"<Nestor>\n" &
157"\t<SEQUENCE>\n" &
158"\t\t<name>nixtor2</name>\n" &
159"\t\t<f2>\n" &
160"\t\t\t<SET_OF/>\n" &
161"\t\t</f2>\n" &
162"\t</SEQUENCE>\n" &
163"</Nestor>\n\n";
164
165const charstring nstr_nixtor3 :=
166"<Nestor>\n" &
167"\t<SEQUENCE>\n" &
168"\t\t<name>nixtor3</name>\n" &
169"\t\t<f2>\n" &
170"\t\t\t<SET_OF>\n" &
171"\t\t\t\t<SEQUENCE_OF/>\n" &
172"\t\t\t</SET_OF>\n" &
173"\t\t</f2>\n" &
174"\t</SEQUENCE>\n" &
175"</Nestor>\n\n";
176
177const charstring nstr_nixtor4 :=
178"<Nestor>\n" &
179"\t<SEQUENCE>\n" &
180"\t\t<name>nixtor4</name>\n" &
181"\t\t<f2>\n" &
182"\t\t\t<SET_OF>\n" &
183"\t\t\t\t<SEQUENCE_OF/>\n" &
184"\t\t\t</SET_OF>\n" &
185"\t\t</f2>\n" &
186"\t</SEQUENCE>\n" &
187"</Nestor>\n\n";
188
189const charstring nstr_an3 :=
190"<Nestor>\n" &
191"\t<SEQUENCE>\n" &
192"\t\t<name>an3[0]</name>\n" &
193"\t\t<f2/>\n" &
194"\t</SEQUENCE>\n" &
195"\t<SEQUENCE>\n" &
196"\t\t<name>an3[1]</name>\n" &
197"\t\t<f2>\n" &
198"\t\t\t<SET_OF/>\n" &
199"\t\t</f2>\n" &
200"\t</SEQUENCE>\n" &
201"\t<SEQUENCE>\n" &
202"\t\t<name>an3[2]</name>\n" &
203"\t\t<f2>\n" &
204"\t\t\t<SET_OF>\n" &
205"\t\t\t\t<SEQUENCE_OF/>\n" &
206"\t\t\t</SET_OF>\n" &
207"\t\t</f2>\n" &
208"\t</SEQUENCE>\n" &
209"</Nestor>\n\n";
210
211const charstring nstr_nn :=
212"<Nestor>\n" &
213"\t<SEQUENCE>\n" &
214"\t\t<name>nn</name>\n" &
215"\t\t<f1>\n" &
216"\t\t\t<ts1>10</ts1>\n" &
217"\t\t\t<ts2><true/></ts2>\n" &
218"\t\t</f1>\n" &
219"\t\t<f2>\n" &
220"\t\t\t<SET_OF>\n" &
221"\t\t\t\t<SEQUENCE_OF>\n" &
222"\t\t\t\t\t<SET_OF>\n" &
223"\t\t\t\t\t\t<SEQUENCE>\n" &
224"\t\t\t\t\t\t\t<your>\n" &
225"\t\t\t\t\t\t\t\t<only>5.000000</only>\n" &
226"\t\t\t\t\t\t\t</your>\n" &
227"\t\t\t\t\t\t</SEQUENCE>\n" &
228"\t\t\t\t\t</SET_OF>\n" &
229"\t\t\t\t</SEQUENCE_OF>\n" &
230"\t\t\t</SET_OF>\n" &
231"\t\t</f2>\n" &
232"\t</SEQUENCE>\n" &
233"</Nestor>\n\n";
234
235const charstring nstrx_nixtorex :=
236"<NestorEx>\n" &
237"\t<NestorSeq>\n" &
238"\t\t<name>nixtorex</name>\n" &
239"\t\t<f2/>\n" &
240"\t</NestorSeq>\n" &
241"</NestorEx>\n\n";
242
243const charstring nstrx_nixtor2ex :=
244"<NestorEx>\n" &
245"\t<NestorSeq>\n" &
246"\t\t<name>nixtor2ex</name>\n" &
247"\t\t<f2>\n" &
248"\t\t\t<Deep4o/>\n" &
249"\t\t</f2>\n" &
250"\t</NestorSeq>\n" &
251"</NestorEx>\n\n";
252
253const charstring nstrx_nixtor3ex :=
254"<NestorEx>\n" &
255"\t<NestorSeq>\n" &
256"\t\t<name>nixtor3ex</name>\n" &
257"\t\t<f2>\n" &
258"\t\t\t<Deep4o>\n" &
259"\t\t\t\t<Deep3o/>\n" &
260"\t\t\t</Deep4o>\n" &
261"\t\t</f2>\n" &
262"\t</NestorSeq>\n" &
263"</NestorEx>\n\n";
264
265const charstring nstrx_nixtor4ex :=
266"<NestorEx>\n" &
267"\t<NestorSeq>\n" &
268"\t\t<name>nixtor4ex</name>\n" &
269"\t\t<f2>\n" &
270"\t\t\t<Deep4o>\n" &
271"\t\t\t\t<Deep3o/>\n" &
272"\t\t\t</Deep4o>\n" &
273"\t\t</f2>\n" &
274"\t</NestorSeq>\n" &
275"</NestorEx>\n\n";
276
277const charstring nstrx_an3ex :=
278"<NestorEx>\n" &
279"\t<NestorSeq>\n" &
280"\t\t<name>an3ex[0]</name>\n" &
281"\t\t<f2/>\n" &
282"\t</NestorSeq>\n" &
283"\t<NestorSeq>\n" &
284"\t\t<name>an3ex[1]</name>\n" &
285"\t\t<f2>\n" &
286"\t\t\t<Deep4o/>\n" &
287"\t\t</f2>\n" &
288"\t</NestorSeq>\n" &
289"\t<NestorSeq>\n" &
290"\t\t<name>an3ex[2]</name>\n" &
291"\t\t<f2>\n" &
292"\t\t\t<Deep4o>\n" &
293"\t\t\t\t<Deep3o/>\n" &
294"\t\t\t</Deep4o>\n" &
295"\t\t</f2>\n" &
296"\t</NestorSeq>\n" &
297"</NestorEx>\n\n";
298
299const charstring nstrx_nnx :=
300"<NestorEx>\n" &
301"\t<NestorSeq>\n" &
302"\t\t<name>nnx</name>\n" &
303"\t\t<f1>\n" &
304"\t\t\t<ts1>10</ts1>\n" &
305"\t\t\t<ts2><true/></ts2>\n" &
306"\t\t</f1>\n" &
307"\t\t<f2>\n" &
308"\t\t\t<Deep4o>\n" &
309"\t\t\t\t<Deep3o>\n" &
310"\t\t\t\t\t<Deep2o>\n" &
311"\t\t\t\t\t\t<Deep1s>\n" &
312"\t\t\t\t\t\t\t<your>\n" &
313"\t\t\t\t\t\t\t\t<only>5.000000</only>\n" &
314"\t\t\t\t\t\t\t</your>\n" &
315"\t\t\t\t\t\t</Deep1s>\n" &
316"\t\t\t\t\t</Deep2o>\n" &
317"\t\t\t\t</Deep3o>\n" &
318"\t\t\t</Deep4o>\n" &
319"\t\t</f2>\n" &
320"\t</NestorSeq>\n" &
321"</NestorEx>\n\n";
322
323testcase encode_nest_asn() runs on Tnested
324{
325 var universal charstring expected;
326
327 expected := nstr_nixtor;
328 CHECK_METHOD(bxer_enc_Nst, AsnValues.nixtor, expected);
329 flatten(expected);
330 CHECK_METHOD(cxer_enc_Nst, AsnValues.nixtor, expected & lf);
331
332 expected := nstr_nixtor2;
333 CHECK_METHOD(bxer_enc_Nst, AsnValues.nixtor2, expected);
334 flatten(expected);
335 CHECK_METHOD(cxer_enc_Nst, AsnValues.nixtor2, expected & lf);
336
337 expected := nstr_nixtor3;
338 CHECK_METHOD(bxer_enc_Nst, AsnValues.nixtor3, expected);
339 flatten(expected);
340 CHECK_METHOD(cxer_enc_Nst, AsnValues.nixtor3, expected & lf);
341
342 expected := nstr_nixtor4;
343 CHECK_METHOD(bxer_enc_Nst, AsnValues.nixtor4, expected);
344 flatten(expected);
345 CHECK_METHOD(cxer_enc_Nst, AsnValues.nixtor4, expected & lf);
346
347 expected := nstr_an3;
348 CHECK_METHOD(bxer_enc_Nst, AsnValues.an3, expected);
349 flatten(expected);
350 CHECK_METHOD(cxer_enc_Nst, AsnValues.an3, expected & lf);
351
352 expected := nstr_nn;
353 CHECK_METHOD(bxer_enc_Nst, AsnValues.nn, expected);
354 flatten(expected);
355 CHECK_METHOD(cxer_enc_Nst, AsnValues.nn, expected & lf);
356
357 expected := nstr_an3;
358 CHECK_METHOD(bxer_enc_Nst, AsnValues.an3, expected);
359 flatten(expected);
360 CHECK_METHOD(cxer_enc_Nst, AsnValues.an3, expected & lf);
361
362 /*******************************************************************/
363
364 expected := nstrx_nixtorex;
365 CHECK_METHOD(bxer_enc_Nstx, AsnValues.nixtorex, expected);
366 flatten(expected);
367 CHECK_METHOD(cxer_enc_Nstx, AsnValues.nixtorex, expected & lf);
368
369 expected := nstrx_nixtor2ex;
370 CHECK_METHOD(bxer_enc_Nstx, AsnValues.nixtor2ex, expected);
371 flatten(expected);
372 CHECK_METHOD(cxer_enc_Nstx, AsnValues.nixtor2ex, expected & lf);
373
374 expected := nstrx_nixtor3ex;
375 CHECK_METHOD(bxer_enc_Nstx, AsnValues.nixtor3ex, expected);
376 flatten(expected);
377 CHECK_METHOD(cxer_enc_Nstx, AsnValues.nixtor3ex, expected & lf);
378
379 expected := nstrx_nixtor4ex;
380 CHECK_METHOD(bxer_enc_Nstx, AsnValues.nixtor4ex, expected);
381 flatten(expected);
382 CHECK_METHOD(cxer_enc_Nstx, AsnValues.nixtor4ex, expected & lf);
383
384 expected := nstrx_an3ex;
385 CHECK_METHOD(bxer_enc_Nstx, AsnValues.an3ex, expected);
386 flatten(expected);
387 CHECK_METHOD(cxer_enc_Nstx, AsnValues.an3ex, expected & lf);
388
389 expected := nstrx_nnx;
390 CHECK_METHOD(bxer_enc_Nstx, AsnValues.nnx, expected);
391 flatten(expected);
392 CHECK_METHOD(cxer_enc_Nstx, AsnValues.nnx, expected & lf);
393
394}
395
396/********* infinite recursion in record-of is OK *********/
397type record of Inf Inf;
398DECLARE_XER_ENCODERS(Inf, inf);
399DECLARE_EXER_ENCODERS(Inf, inf);
400
401const Inf empty := {}
402const Inf level3 := {{{}}}
403
404const universal charstring str_empty := "<Inf/>\n\n";
405const universal charstring str3 :=
406"<Inf>\n" &
407"\t<Inf>\n" &
408"\t\t<Inf>\n" &
409"\t\t</Inf>\n" &
410"\t</Inf>\n" &
411"</Inf>\n\n";
412const universal charstring str3empty :=
413"<Inf>\n" &
414"\t<Inf>\n" &
415"\t\t<Inf/>\n" &
416"\t</Inf>\n" &
417"</Inf>\n\n";
418
419
420testcase encode_inf() runs on Tnested
421{
422 var universal charstring expected;
423
424 expected := str_empty;
425 CHECK_METHOD(bxer_enc_inf, empty, expected);
426 CHECK_METHOD(exer_enc_inf, empty, expected);
427 flatten(expected);
428 CHECK_METHOD(cxer_enc_inf, empty, expected & lf);
429
430 expected := str3empty;
431 CHECK_METHOD(bxer_enc_inf, level3, expected);
432 CHECK_METHOD(exer_enc_inf, level3, expected);
433 flatten(expected);
434 CHECK_METHOD(cxer_enc_inf, level3, expected & lf);
435}
436
437testcase decode_inf() runs on Tnested
438{
439 CHECK_DECODE2( inf, str_empty, Inf, empty);
440 CHECK_DECODE(exer_dec_inf, str_empty, Inf, empty);
441
442 CHECK_DECODE2( inf, str3empty, Inf, level3);
443 CHECK_DECODE(exer_dec_inf, str3empty, Inf, level3);
444
445 // also check that non-empty element can be decoded
446 CHECK_DECODE2( inf, str3 , Inf, level3);
447 CHECK_DECODE(exer_dec_inf, str3 , Inf, level3);
448}
449
450control {
451 execute(encode_nest());
452 execute(encode_nest_asn());
453 execute(decode_nest());
454
455 execute(encode_inf());
456 execute(decode_inf());
457}
458
459} // module
460with {
461 encode "XML";
462 extension "version R8N";
463}
This page took 0.039939 seconds and 5 git commands to generate.