Sync with 5.4.2
[deliverable/titan.core.git] / regression_test / XML / EXER-whitepaper / Order.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 Order {
9
10// USE-ORDER tests straight out of the whitepaper
11
12modulepar boolean Order_verbose := false;
13#define verbose Order_verbose
14#include "../macros.ttcnin"
15
16type component Ord {}
17
18// Example 1: "Plain" USE-ORDER
19type record UOProductO {
20 record of enumerated { id, name, price, color } order,
21 charstring available, // this is not in the whitepaper
22 integer id,
23 charstring name,
24 float price,
25 charstring color
26}
27with {
28 variant "element";
29 variant "useOrder";
30 variant "namespace as 'http://www.example.com' prefix 'exm'";
31 variant (available) "attribute";
32}
33
34DECLARE_XER_ENCODERS(UOProductO, prodO);
35DECLARE_EXER_ENCODERS(UOProductO, prodO);
36
37const UOProductO uoprod := {
38 order := { id, color, price, name },
39 available := "<true/>",
40 id := 100,
41 name := "shirt",
42 price := 12.23,
43 color := "red"
44}
45
46const universal charstring str_prod_e :=
47"<exm:UOProductO xmlns:exm=\'http://www.example.com\' available=\'&lt;true/&gt;\'>\n" &
48"\t<id>100</id>\n" &
49"\t<color>red</color>\n" &
50"\t<price>12.230000</price>\n" &
51"\t<name>shirt</name>\n" &
52"</exm:UOProductO>\n" &
53"\n";
54
55const universal charstring str_prod_b :=
56"<UOProductO>\n" &
57"\t<order>\n" &
58"\t\t<id/><color/><price/><name/>\n" &
59"\t</order>\n" &
60"\t<available>&lt;true/&gt;</available>\n" &
61"\t<id>100</id>\n" &
62"\t<name>shirt</name>\n" &
63"\t<price>12.230000</price>\n" &
64"\t<color>red</color>\n" &
65"</UOProductO>\n" &
66"\n";
67
68testcase enc_uo() runs on Ord
69{
70 CHECK_METHOD(bxer_enc_prodO, uoprod, str_prod_b);
71 CHECK_METHOD(exer_enc_prodO, uoprod, str_prod_e);
72}
73
74testcase dec_uo() runs on Ord
75{
76 CHECK_DECODE(bxer_dec_prodO, str_prod_b, UOProductO, uoprod);
77 CHECK_DECODE(exer_dec_prodO, str_prod_e, UOProductO, uoprod);
78}
79
80// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
81
82// Example 2: USE-ORDER and EMBED-VALUES
83type record UOProductEmb {
84 record length(5) of universal charstring embed,
85 record of enumerated { id, name, price, color } order,
86 integer id,
87 charstring name,
88 float price,
89 charstring color
90}
91with {
92 variant "element";
93 variant "useOrder";
94 variant "embedValues";
95 variant "namespace as 'http://www.example.com' prefix 'exm'";
96}
97
98DECLARE_XER_ENCODERS(UOProductEmb, prod5);
99DECLARE_EXER_ENCODERS(UOProductEmb, prod5);
100
101const UOProductEmb prod5 := {
102 embed := {"Order Id ", "", "", "US Dollars", "" },
103 order := { id, color, price, name },
104 id := 100,
105 name := "shirt",
106 price := 12.23,
107 color := "red"
108}
109
110const universal charstring str_prod5_e :=
111"<exm:UOProductEmb xmlns:exm=\'http://www.example.com\'>Order Id " &
112"<id>100</id><color>red</color><price>12.230000</price>US Dollars<name>shirt</name></exm:UOProductEmb>" &
113"\n";
114
115const universal charstring str_prod5_b :=
116"<UOProductEmb>\n" &
117"\t<embed>\n" &
118"\t\t<UNIVERSAL_CHARSTRING>Order Id </UNIVERSAL_CHARSTRING>\n" &
119"\t\t<UNIVERSAL_CHARSTRING/>\n" &
120"\t\t<UNIVERSAL_CHARSTRING/>\n" &
121"\t\t<UNIVERSAL_CHARSTRING>US Dollars</UNIVERSAL_CHARSTRING>\n" &
122"\t\t<UNIVERSAL_CHARSTRING/>\n" &
123"\t</embed>\n" &
124"\t<order>\n" &
125"\t\t<id/><color/><price/><name/>\n" &
126"\t</order>\n" &
127"\t<id>100</id>\n" &
128"\t<name>shirt</name>\n" &
129"\t<price>12.230000</price>\n" &
130"\t<color>red</color>\n" &
131"</UOProductEmb>\n" &
132"\n";
133
134testcase enc_uo_emb() runs on Ord
135{
136 CHECK_METHOD(bxer_enc_prod5, prod5, str_prod5_b);
137 CHECK_METHOD(exer_enc_prod5, prod5, str_prod5_e);
138}
139
140testcase dec_uo_emb() runs on Ord
141{
142 var UOProductEmb expected := prod5;
143 CHECK_DECODE(bxer_dec_prod5, str_prod5_b, UOProductEmb, expected);
144 CHECK_DECODE(exer_dec_prod5, str_prod5_e, UOProductEmb, expected);
145}
146
147// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
148
149// Example 3: USE-ORDER and USE-NIL
150type record UOProductNil {
151 record of enumerated { id, name, price, color } order,
152 boolean available, // not in the whitepaper
153 UOProductInfo info optional
154}
155with {
156 variant "element";
157 variant "useOrder";
158 variant "useNil";
159 variant (available) "attribute";
160 variant "namespace as 'http://www.example.com' prefix 'exm'";
161}
162
163type record UOProductInfo {
164 integer id,
165 charstring name,
166 float price,
167 charstring color
168}
169
170DECLARE_XER_ENCODERS(UOProductNil, prod0);
171DECLARE_EXER_ENCODERS(UOProductNil, prod0);
172
173// ... ... present ... ...
174
175const UOProductNil prod0 := {
176 order := { id, color, price, name },
177 available := true,
178 info := {
179 id := 100,
180 name := "shirt",
181 price := 12.23,
182 color := "red"
183 }
184}
185
186const universal charstring str_prod0_e :=
187"<exm:UOProductNil xmlns:exm=\'http://www.example.com\' available=\'true\'>\n" &
188"\t<id>100</id>\n" &
189"\t<color>red</color>\n" &
190"\t<price>12.230000</price>\n" &
191"\t<name>shirt</name>\n" &
192"</exm:UOProductNil>\n" &
193"\n";
194
195// 'nil' attribute present but says 'no'
196const universal charstring str_prod0nonil_e :=
197"<exm:UOProductNil available=\'true\' xmlns:exm=\'http://www.example.com\' " &
198"xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xsi:nil=\'nyet\'>\n" &
199"\t<id>100</id>\n" &
200"\t<color>red</color>\n" &
201"\t<price>12.230000</price>\n" &
202"\t<name>shirt</name>\n" &
203"</exm:UOProductNil>\n" &
204"\n";
205
206const universal charstring str_prod0_b :=
207"<UOProductNil>\n" &
208"\t<order>\n" &
209"\t\t<id/><color/><price/><name/>\n" &
210"\t</order>\n" &
211"\t<available><true/></available>\n" &
212"\t<info>\n" &
213"\t\t<id>100</id>\n" &
214"\t\t<name>shirt</name>\n" &
215"\t\t<price>12.230000</price>\n" &
216"\t\t<color>red</color>\n" &
217"\t</info>\n" &
218"</UOProductNil>\n" &
219"\n";
220
221testcase enc_uo_nil_present() runs on Ord
222{
223 CHECK_METHOD(bxer_enc_prod0, prod0, str_prod0_b);
224 CHECK_METHOD(exer_enc_prod0, prod0, str_prod0_e);
225}
226
227testcase dec_uo_nil_present() runs on Ord
228{
229 CHECK_DECODE(bxer_dec_prod0, str_prod0_b, UOProductNil, prod0);
230 CHECK_DECODE(exer_dec_prod0, str_prod0_e, UOProductNil, prod0);
231 CHECK_DECODE(exer_dec_prod0, str_prod0nonil_e, UOProductNil, prod0);
232}
233
234// Example 4: ... ... absent ... ...
235
236const UOProductNil prod0nil := {
237 order := { },
238 available := false,
239 info := omit
240}
241
242const universal charstring str_prod0nil_e :=
243"<exm:UOProductNil xmlns:exm=\'http://www.example.com\' " &
244"xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' " &
245"available=\'false\' xsi:nil=\'true\'/>\n" &
246"\n";
247
248const universal charstring str_prod0nil_b :=
249"<UOProductNil>\n" &
250"\t<order/>\n" &
251"\t<available><false/></available>\n" &
252"</UOProductNil>\n" &
253"\n";
254
255testcase enc_uo_nil_absent() runs on Ord
256{
257 CHECK_METHOD(bxer_enc_prod0, prod0nil, str_prod0nil_b);
258 CHECK_METHOD(exer_enc_prod0, prod0nil, str_prod0nil_e);
259}
260
261testcase dec_uo_nil_absent() runs on Ord
262{
263 CHECK_DECODE(bxer_dec_prod0, str_prod0nil_b, UOProductNil, prod0nil);
264 CHECK_DECODE(exer_dec_prod0, str_prod0nil_e, UOProductNil, prod0nil);
265}
266
267// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
268
269// Example 5: USE-ORDER and ANY-ELEMENT
270
271type record UORecordAny {
272 record of enumerated { id, anyElem, bytes, anyElem2 } order,
273 integer id,
274 universal charstring anyElem,
275 octetstring bytes,
276 universal charstring anyElem2
277} with {
278 variant "useOrder";
279 variant (anyElem) "anyElement";
280 variant (anyElem2) "anyElement";
281}
282
283DECLARE_EXER_ENCODERS(UORecordAny, uo_any);
284
285const UORecordAny any0 := {
286 order := { bytes, anyElem, anyElem2, id },
287 id := 2,
288 anyElem := "<something/>",
289 bytes := 'A1'O,
290 anyElem2 := "<field>123</field>"
291};
292
293const universal charstring str_any0 :=
294 "<UORecordAny>\n" &
295 "\t<bytes>A1</bytes>\n" &
296 "\t<something/>\n" &
297 "\t<field>123</field>\n" &
298 "\t<id>2</id>\n" &
299 "</UORecordAny>\n\n";
300
301testcase enc_uo_any() runs on Ord
302{
303 CHECK_METHOD(exer_enc_uo_any, any0, str_any0);
304}
305
306testcase dec_uo_any() runs on Ord
307{
308 CHECK_DECODE(exer_dec_uo_any, str_any0, UORecordAny, any0);
309}
310
311// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
312
3f84031e 313// Example 6: USE-ORDER with only one element that is optional
314
315type record UORecordOneOpt {
316 record of enumerated { id } order,
317 integer id optional
318} with {
319 variant "useOrder";
320}
321
322DECLARE_EXER_ENCODERS(UORecordOneOpt, uo_one_opt);
323
324const UORecordOneOpt one_opt := {
325 order := { id },
326 id := 2
327};
328
329const universal charstring str_one_opt_e :=
330 "<UORecordOneOpt>\n" &
331 "\t<id>2</id>\n" &
332 "</UORecordOneOpt>\n\n";
333
334testcase enc_uo_one_opt() runs on Ord
335{
336 CHECK_METHOD(exer_enc_uo_one_opt, one_opt, str_one_opt_e);
337}
338
339testcase dec_uo_one_opt() runs on Ord
340{
341 CHECK_DECODE(exer_dec_uo_one_opt, str_one_opt_e, UORecordOneOpt, one_opt);
342}
343
344// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
345
346// Example 7: USE-ORDER with only one record element that is optional
347
348type record UORecordOneOpt2 {
349 record of enumerated { id } order,
350 RecordOneOpt id optional
351} with {
352 variant "useOrder";
353}
354
355type record RecordOneOpt {
356 integer identity
357}
358
359DECLARE_EXER_ENCODERS(UORecordOneOpt2, uo_one_opt2);
360
361const UORecordOneOpt2 one_opt2 := {
362 order := { id },
363 id := { identity := 2 }
364};
365
366const universal charstring str_one_opt2_e :=
367 "<UORecordOneOpt2>\n" &
368 "\t<id>\n" &
369 "\t\t<identity>2</identity>\n" &
370 "\t</id>\n" &
371 "</UORecordOneOpt2>\n\n";
372
373testcase enc_uo_one_opt2() runs on Ord
374{
375 CHECK_METHOD(exer_enc_uo_one_opt2, one_opt2, str_one_opt2_e);
376}
377
378testcase dec_uo_one_opt2() runs on Ord
379{
380 CHECK_DECODE(exer_dec_uo_one_opt2, str_one_opt2_e, UORecordOneOpt2, one_opt2);
381}
382
383// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
384
970ed795
EL
385control {
386 execute(enc_uo());
387 execute(dec_uo());
388
389 execute(enc_uo_emb());
390 execute(dec_uo_emb());
391
392 execute(enc_uo_nil_present());
393 execute(enc_uo_nil_absent());
394 execute(dec_uo_nil_present());
395 execute(dec_uo_nil_absent());
396
397 execute(enc_uo_any());
398 execute(dec_uo_any());
3f84031e 399
400 execute(enc_uo_one_opt());
401 execute(dec_uo_one_opt());
402
403 execute(enc_uo_one_opt2());
404 execute(dec_uo_one_opt2());
970ed795
EL
405}
406
407}
408with {
409encode "XML"
410variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'"
411/*
412A "namespace" attribute here would have the equivalent effect of
413
414NAMESPACE ALL AS ...
415
416rather than
417
418NAMESPACE ALL, ALL IN ALL AS ...
419
420because (at least for a record or set type) unqualified attributes stop there
421and are not propagated to the component.
422*/
3f84031e 423
970ed795 424}
This page took 0.040184 seconds and 5 git commands to generate.