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 ******************************************************************************/
9 modulepar boolean UseOrder_verbose := false;
10 #define verbose UseOrder_verbose
11 #include "../macros.ttcnin"
16 type record UOProduct {
17 record of enumerated { id, name, price, color } order,
27 variant "namespace as 'http://www.example.com' prefix 'exm'";
31 DECLARE_XER_ENCODERS(UOProduct, uo);
32 DECLARE_EXER_ENCODERS(UOProduct, uo);
34 const UOProduct uopval := {
35 order := { id, color, price, name },
43 const universal charstring str_uo_e :=
44 "<exm:UOProduct xmlns:exm=\'http://www.example.com\'>\n" &
46 "\t<color>red</color>\n" &
47 "\t<price>12.230000</price>\n" &
48 "\t<name>shirt</name>\n" &
49 "</exm:UOProduct>\n" &
52 const universal charstring str_uo_b :=
55 "\t\t<id/><color/><price/><name/>\n" &
59 "\t<name>shirt</name>\n" &
60 "\t<price>12.230000</price>\n" &
61 "\t<color>red</color>\n" &
65 testcase encode_uo() runs on UO
67 CHECK_METHOD(bxer_enc_uo, uopval, str_uo_b);
68 CHECK_METHOD(exer_enc_uo, uopval, str_uo_e);
71 testcase decode_uo() runs on UO
73 CHECK_DECODE(bxer_dec_uo, str_uo_b, UOProduct, uopval);
74 CHECK_DECODE(exer_dec_uo, str_uo_e, UOProduct, uopval);
78 external function exer_enc_uo_w(in UOProduct par) return octetstring
79 with { extension "prototype(convert) encode (XER:XER_EXTENDED) errorbehavior(ALL:WARNING)" }
81 external function exer_enc_uo2(in UOProduct par, out octetstring o)
82 with { extension "prototype(fast) encode (XER:XER_EXTENDED) errorbehavior(ALL:WARNING)" }
84 external function exer_dec_uo2(in octetstring par, out UOProduct o) return integer
85 with { extension "prototype(backtrack) decode (XER:XER_EXTENDED) errorbehavior(ALL:WARNING)" };
87 testcase encdec_uo() runs on UO
89 // This is what the encoder returns on error (no fields encoded).
90 const universal charstring panic := "<exm:UOProduct xmlns:exm='http://www.example.com'/>\n\n";
92 const UOProduct c_uo := {
93 /* There is no way to test incorrect values like { id, id, id, id } or
94 { id, name }, without a dynamic testcase error */
95 order := { id, name, color, price },
102 var octetstring encoded;
103 exer_enc_uo2(c_uo, encoded);
107 rez := exer_dec_uo2(encoded, v_uo);
112 const UOProduct unidentified :=
114 order := { name, color, price },
120 CHECK_METHOD(exer_enc_uo_w, unidentified, panic);
123 { // the right number, but some (!) duplication
124 const UOProduct deja_vu :=
126 order := { name, name, name, name },
132 CHECK_METHOD(exer_enc_uo_w, deja_vu, panic);
135 // We can test errors during decoding with prototype(backtrack)
137 const universal charstring priceless := "<exm:UOProduct xmlns:exm='http://www.example.com'>\n\t<id>100</id>\n\t<name>shirt</name>\n\t<color>red</color>\n</exm:UOProduct>\n\n";
139 rez := u2o("UTF-8", priceless, encoded);
140 if (rez!=0) { setverdict(fail, "Conversion failed: ", rez) }
143 rez := exer_dec_uo2(encoded, v_uo);
144 COMPARE(rez, 1); // 1 means error
148 const universal charstring id2 := "<exm:UOProduct xmlns:exm='http://www.example.com'>\n\t<id>100</id>\n\t<id>234</id>\n\t<name>shirt</name>\n\t<color>red</color>\n</exm:UOProduct>\n\n";
149 // Still no price but 4 child elements
150 rez := u2o("UTF-8", id2, encoded);
151 if (rez!=0) { setverdict(fail, "Conversion failed: ", rez) }
154 rez := exer_dec_uo2(encoded, v_uo);
155 COMPARE(rez, 1); // 1 means error
159 const universal charstring toomuch := "<exm:UOProduct xmlns:exm='http://www.example.com'>\n\t<price>12.230000</price>\n\t<id>100</id>\n\t<id>234</id>\n\t<name>shirt</name>\n\t<color>red</color>\n</exm:UOProduct>\n\n";
160 // too many child elements
161 rez := u2o("UTF-8", toomuch, encoded);
162 if (rez!=0) { setverdict(fail, "Conversion failed: ", rez) }
165 rez := exer_dec_uo2(encoded, v_uo);
166 COMPARE(rez, 1); // 1 means error
170 /* *** *** * *** * * *** * *** *** *** * *** *** * * *** *
171 *** *** *** * *** * * * * *** *** *** *** *** * *** * * * *
172 * * *** * *** *** * *** * *** * *** *** *** *** *** * *** *** *
173 * *** * * * *** * * *** * * *** * *** *** *** * * * * * * *** *
174 * * *** * * * *** * * *** * ***/
176 // USE-ORDER with optional fields (regression test for HL22039)
178 record of enumerated { goalie, defender, midfield, forward } order,
179 universal charstring goalie optional,
180 universal charstring defender optional,
181 universal charstring midfield optional,
182 universal charstring forward optional
188 DECLARE_XER_ENCODERS(Team, tm);
189 DECLARE_EXER_ENCODERS(Team, tm);
191 const Team arany := {
192 { goalie, defender, midfield, forward },
194 "Buzanski Lorant Lantos",
196 "Czibor Kocsis Hidegkuti Puskas Budai"
199 const Team ezust := {
200 { defender, midfield, forward },
202 "Buzanski Lorant Lantos",
204 "Czibor Kocsis Hidegkuti Puskas Budai"
207 const Team attack := {
208 order := { forward, goalie },
212 forward := "Garrincha Didi Vav" & char(0,0,0,225) & " Pel" & char(0,0,0,233) & " Zagalo"
215 const Team senki := {
217 omit, omit, omit, omit
220 const universal charstring str_arany_e :=
222 "\t<goalie>Grosics</goalie>\n" &
223 "\t<defender>Buzanski Lorant Lantos</defender>\n" &
224 "\t<midfield>Bozsik Zakarias</midfield>\n" &
225 "\t<forward>Czibor Kocsis Hidegkuti Puskas Budai</forward>\n" &
228 const universal charstring str_arany_b :=
231 "\t\t<goalie/><defender/><midfield/><forward/>\n" &
233 "\t<goalie>Grosics</goalie>\n" &
234 "\t<defender>Buzanski Lorant Lantos</defender>\n" &
235 "\t<midfield>Bozsik Zakarias</midfield>\n" &
236 "\t<forward>Czibor Kocsis Hidegkuti Puskas Budai</forward>\n" &
239 const universal charstring str_ezust_e :=
241 "\t<defender>Buzanski Lorant Lantos</defender>\n" &
242 "\t<midfield>Bozsik Zakarias</midfield>\n" &
243 "\t<forward>Czibor Kocsis Hidegkuti Puskas Budai</forward>\n" &
246 const universal charstring str_ezust_b :=
249 "\t\t<defender/><midfield/><forward/>\n" &
251 "\t<defender>Buzanski Lorant Lantos</defender>\n" &
252 "\t<midfield>Bozsik Zakarias</midfield>\n" &
253 "\t<forward>Czibor Kocsis Hidegkuti Puskas Budai</forward>\n" &
256 const universal charstring str_attack_e :=
258 "\t<forward>Garrincha Didi Vavá Pelé Zagalo</forward>\n" &
259 "\t<goalie>Gilmar</goalie>\n" &
262 const universal charstring str_attack_b :=
265 "\t\t<forward/><goalie/>\n" &
267 "\t<goalie>Gilmar</goalie>\n" &
268 "\t<forward>Garrincha Didi Vavá Pelé Zagalo</forward>\n" &
272 const universal charstring str_senki_e := "<Team/>\n\n";
273 const universal charstring str_senki_e2 := "<Team></Team>\n\n";
274 //const universal charstring str_senki_e2 := "<Team/>\n\n";
276 const universal charstring str_senki_b :=
283 testcase encode_uo_team() runs on UO
285 CHECK_METHOD(bxer_enc_tm, arany, str_arany_b);
286 CHECK_METHOD(exer_enc_tm, arany, str_arany_e);
288 CHECK_METHOD(bxer_enc_tm, ezust, str_ezust_b);
289 CHECK_METHOD(exer_enc_tm, ezust, str_ezust_e);
291 CHECK_METHOD(bxer_enc_tm, attack, str_attack_b);
292 CHECK_METHOD(exer_enc_tm, attack, str_attack_e);
294 CHECK_METHOD(bxer_enc_tm, senki, str_senki_b);
295 CHECK_METHOD(exer_enc_tm, senki, str_senki_e);
298 testcase decode_uo_team() runs on UO
300 CHECK_DECODE(bxer_dec_tm, str_arany_b, Team, arany);
301 CHECK_DECODE(exer_dec_tm, str_arany_e, Team, arany);
303 CHECK_DECODE(bxer_dec_tm, str_ezust_b, Team, ezust);
304 CHECK_DECODE(exer_dec_tm, str_ezust_e, Team, ezust);
306 CHECK_DECODE(bxer_dec_tm, str_attack_b, Team, attack);
307 CHECK_DECODE(exer_dec_tm, str_attack_e, Team, attack);
309 CHECK_DECODE(bxer_dec_tm, str_senki_b, Team, senki);
310 CHECK_DECODE(exer_dec_tm, str_senki_e, Team, senki);
311 CHECK_DECODE(exer_dec_tm, str_senki_e2,Team, senki);
314 // -- -- -- -- run it -- -- -- --
317 execute(encode_uo());
318 execute(decode_uo());
319 execute(encdec_uo());
321 execute(encode_uo_team());
322 execute(decode_uo_team());