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 ******************************************************************************/
10 // USE-ORDER tests straight out of the whitepaper
12 modulepar boolean Order_verbose := false;
13 #define verbose Order_verbose
14 #include "../macros.ttcnin"
18 // Example 1: "Plain" USE-ORDER
19 type record UOProductO {
20 record of enumerated { id, name, price, color } order,
21 charstring available, // this is not in the whitepaper
30 variant "namespace as 'http://www.example.com' prefix 'exm'";
31 variant (available) "attribute";
34 DECLARE_XER_ENCODERS(UOProductO, prodO);
35 DECLARE_EXER_ENCODERS(UOProductO, prodO);
37 const UOProductO uoprod := {
38 order := { id, color, price, name },
39 available := "<true/>",
46 const universal charstring str_prod_e :=
47 "<exm:UOProductO xmlns:exm=\'http://www.example.com\' available=\'<true/>\'>\n" &
49 "\t<color>red</color>\n" &
50 "\t<price>12.230000</price>\n" &
51 "\t<name>shirt</name>\n" &
52 "</exm:UOProductO>\n" &
55 const universal charstring str_prod_b :=
58 "\t\t<id/><color/><price/><name/>\n" &
60 "\t<available><true/></available>\n" &
62 "\t<name>shirt</name>\n" &
63 "\t<price>12.230000</price>\n" &
64 "\t<color>red</color>\n" &
68 testcase enc_uo() runs on Ord
70 CHECK_METHOD(bxer_enc_prodO, uoprod, str_prod_b);
71 CHECK_METHOD(exer_enc_prodO, uoprod, str_prod_e);
74 testcase dec_uo() runs on Ord
76 CHECK_DECODE(bxer_dec_prodO, str_prod_b, UOProductO, uoprod);
77 CHECK_DECODE(exer_dec_prodO, str_prod_e, UOProductO, uoprod);
80 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
82 // Example 2: USE-ORDER and EMBED-VALUES
83 type record UOProductEmb {
84 record length(5) of universal charstring embed,
85 record of enumerated { id, name, price, color } order,
94 variant "embedValues";
95 variant "namespace as 'http://www.example.com' prefix 'exm'";
98 DECLARE_XER_ENCODERS(UOProductEmb, prod5);
99 DECLARE_EXER_ENCODERS(UOProductEmb, prod5);
101 const UOProductEmb prod5 := {
102 embed := {"Order Id ", "", "", "US Dollars", "" },
103 order := { id, color, price, name },
110 const 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>" &
115 const universal charstring str_prod5_b :=
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" &
125 "\t\t<id/><color/><price/><name/>\n" &
128 "\t<name>shirt</name>\n" &
129 "\t<price>12.230000</price>\n" &
130 "\t<color>red</color>\n" &
131 "</UOProductEmb>\n" &
134 testcase enc_uo_emb() runs on Ord
136 CHECK_METHOD(bxer_enc_prod5, prod5, str_prod5_b);
137 CHECK_METHOD(exer_enc_prod5, prod5, str_prod5_e);
140 testcase dec_uo_emb() runs on Ord
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);
147 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
149 // Example 3: USE-ORDER and USE-NIL
150 type record UOProductNil {
151 record of enumerated { id, name, price, color } order,
152 boolean available, // not in the whitepaper
153 UOProductInfo info optional
159 variant (available) "attribute";
160 variant "namespace as 'http://www.example.com' prefix 'exm'";
163 type record UOProductInfo {
170 DECLARE_XER_ENCODERS(UOProductNil, prod0);
171 DECLARE_EXER_ENCODERS(UOProductNil, prod0);
173 // ... ... present ... ...
175 const UOProductNil prod0 := {
176 order := { id, color, price, name },
186 const universal charstring str_prod0_e :=
187 "<exm:UOProductNil xmlns:exm=\'http://www.example.com\' available=\'true\'>\n" &
189 "\t<color>red</color>\n" &
190 "\t<price>12.230000</price>\n" &
191 "\t<name>shirt</name>\n" &
192 "</exm:UOProductNil>\n" &
195 // 'nil' attribute present but says 'no'
196 const 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" &
200 "\t<color>red</color>\n" &
201 "\t<price>12.230000</price>\n" &
202 "\t<name>shirt</name>\n" &
203 "</exm:UOProductNil>\n" &
206 const universal charstring str_prod0_b :=
209 "\t\t<id/><color/><price/><name/>\n" &
211 "\t<available><true/></available>\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" &
218 "</UOProductNil>\n" &
221 testcase enc_uo_nil_present() runs on Ord
223 CHECK_METHOD(bxer_enc_prod0, prod0, str_prod0_b);
224 CHECK_METHOD(exer_enc_prod0, prod0, str_prod0_e);
227 testcase dec_uo_nil_present() runs on Ord
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);
234 // Example 4: ... ... absent ... ...
236 const UOProductNil prod0nil := {
242 const 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" &
248 const universal charstring str_prod0nil_b :=
251 "\t<available><false/></available>\n" &
252 "</UOProductNil>\n" &
255 testcase enc_uo_nil_absent() runs on Ord
257 CHECK_METHOD(bxer_enc_prod0, prod0nil, str_prod0nil_b);
258 CHECK_METHOD(exer_enc_prod0, prod0nil, str_prod0nil_e);
261 testcase dec_uo_nil_absent() runs on Ord
263 CHECK_DECODE(bxer_dec_prod0, str_prod0nil_b, UOProductNil, prod0nil);
264 CHECK_DECODE(exer_dec_prod0, str_prod0nil_e, UOProductNil, prod0nil);
267 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
269 // Example 5: USE-ORDER and ANY-ELEMENT
271 type record UORecordAny {
272 record of enumerated { id, anyElem, bytes, anyElem2 } order,
274 universal charstring anyElem,
276 universal charstring anyElem2
279 variant (anyElem) "anyElement";
280 variant (anyElem2) "anyElement";
283 DECLARE_EXER_ENCODERS(UORecordAny, uo_any);
285 const UORecordAny any0 := {
286 order := { bytes, anyElem, anyElem2, id },
288 anyElem := "<something/>",
290 anyElem2 := "<field>123</field>"
293 const universal charstring str_any0 :=
295 "\t<bytes>A1</bytes>\n" &
297 "\t<field>123</field>\n" &
299 "</UORecordAny>\n\n";
301 testcase enc_uo_any() runs on Ord
303 CHECK_METHOD(exer_enc_uo_any, any0, str_any0);
306 testcase dec_uo_any() runs on Ord
308 CHECK_DECODE(exer_dec_uo_any, str_any0, UORecordAny, any0);
311 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
317 execute(enc_uo_emb());
318 execute(dec_uo_emb());
320 execute(enc_uo_nil_present());
321 execute(enc_uo_nil_absent());
322 execute(dec_uo_nil_present());
323 execute(dec_uo_nil_absent());
325 execute(enc_uo_any());
326 execute(dec_uo_any());
332 variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'"
334 A "namespace" attribute here would have the equivalent effect of
340 NAMESPACE ALL, ALL IN ALL AS ...
342 because (at least for a record or set type) unqualified attributes stop there
343 and are not propagated to the component.