Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
d44e3c4f | 2 | * Copyright (c) 2000-2016 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 | |
d44e3c4f | 7 | * |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Delic, Adam | |
11 | * Raduly, Csaba | |
12 | * | |
970ed795 EL |
13 | ******************************************************************************/ |
14 | module EmbedValues { | |
15 | modulepar boolean EmbedValues_verbose := false; | |
16 | #define verbose EmbedValues_verbose | |
17 | #include "../macros.ttcnin" | |
18 | ||
19 | const charstring LF := "\n"; | |
20 | ||
21 | type record Notification { | |
22 | record length(4) of universal charstring embed, | |
23 | integer account, | |
24 | integer amount_due, | |
25 | charstring payable_by | |
26 | } | |
27 | with { | |
28 | variant "embedValues" | |
29 | variant (payable_by) "name as 'payable-by'" | |
30 | variant (payable_by) "XSD:date" | |
31 | variant (amount_due) "name as 'amount-due'" | |
32 | } | |
33 | ||
34 | type record NotificationU { | |
35 | record length(4) of universal charstring embed, | |
36 | integer account, | |
37 | integer amount_due, | |
38 | charstring payable_by | |
39 | } | |
40 | with { | |
41 | variant "embedValues" | |
42 | variant (payable_by) "name as 'payable-by'" | |
43 | variant (payable_by) "XSD:date" | |
44 | variant (amount_due) "name as 'amount-due'" | |
45 | } | |
46 | ||
47 | type component Embedder {} | |
48 | ||
49 | DECLARE_XER_ENCODERS(Notification, notif); | |
50 | DECLARE_EXER_ENCODERS(Notification, notif); | |
51 | ||
52 | DECLARE_XER_ENCODERS(NotificationU, notifU); | |
53 | DECLARE_EXER_ENCODERS(NotificationU, notifU); | |
54 | ||
55 | const Notification inputS := { | |
56 | embed := { | |
57 | "Please note the following details:", | |
58 | "(your business account)", | |
59 | "This is in excess of your normal monthly allowance", | |
60 | "or earlier" | |
61 | }, | |
62 | account := 568903, | |
63 | amount_due := 536, | |
64 | payable_by := "27-08-2003" | |
65 | } | |
66 | ||
67 | const NotificationU inputU := { | |
68 | embed := { | |
69 | "Please note the following details:", | |
70 | "(your business account)", | |
71 | "This is in excess of your normal monthly allowance", | |
72 | "or earlier" | |
73 | }, | |
74 | account := 568903, | |
75 | amount_due := 536, | |
76 | payable_by := "27-08-2003" | |
77 | } | |
78 | ||
79 | const universal charstring notif_str := | |
80 | "<Notification>" & | |
81 | "Please note the following details:" & | |
82 | "<account>568903</account>" & | |
83 | "(your business account)" & | |
84 | "<amount-due>536</amount-due>" & | |
85 | "This is in excess of your normal monthly allowance" & | |
86 | "<payable-by>27-08-2003</payable-by>" & | |
87 | "or earlier" & | |
88 | "</Notification>" & | |
89 | LF; | |
90 | ||
91 | const universal charstring notifU_str := // almost, but not quite, the same as notif_str | |
92 | "<NotificationU>" & | |
93 | "Please note the following details:" & | |
94 | "<account>568903</account>" & | |
95 | "(your business account)" & | |
96 | "<amount-due>536</amount-due>" & | |
97 | "This is in excess of your normal monthly allowance" & | |
98 | "<payable-by>27-08-2003</payable-by>" & | |
99 | "or earlier" & | |
100 | "</NotificationU>" & | |
101 | LF; | |
102 | ||
103 | const universal charstring notif_str_b := | |
104 | "<Notification>\n" & | |
105 | "\t<embed>\n" & | |
106 | "\t\t<UNIVERSAL_CHARSTRING>Please note the following details:</UNIVERSAL_CHARSTRING>\n" & | |
107 | "\t\t<UNIVERSAL_CHARSTRING>(your business account)</UNIVERSAL_CHARSTRING>\n" & | |
108 | "\t\t<UNIVERSAL_CHARSTRING>This is in excess of your normal monthly allowance</UNIVERSAL_CHARSTRING>\n" & | |
109 | "\t\t<UNIVERSAL_CHARSTRING>or earlier</UNIVERSAL_CHARSTRING>\n" & | |
110 | "\t</embed>\n" & | |
111 | "\t<account>568903</account>\n" & | |
112 | "\t<amount_due>536</amount_due>\n" & | |
113 | "\t<payable_by>27-08-2003</payable_by>\n" & | |
114 | "</Notification>\n" & | |
115 | LF; | |
116 | ||
117 | const universal charstring notifU_str_b := | |
118 | "<NotificationU>\n" & | |
119 | "\t<embed>\n" & | |
120 | "\t\t<UNIVERSAL_CHARSTRING>Please note the following details:</UNIVERSAL_CHARSTRING>\n" & | |
121 | "\t\t<UNIVERSAL_CHARSTRING>(your business account)</UNIVERSAL_CHARSTRING>\n" & | |
122 | "\t\t<UNIVERSAL_CHARSTRING>This is in excess of your normal monthly allowance</UNIVERSAL_CHARSTRING>\n" & | |
123 | "\t\t<UNIVERSAL_CHARSTRING>or earlier</UNIVERSAL_CHARSTRING>\n" & | |
124 | "\t</embed>\n" & | |
125 | "\t<account>568903</account>\n" & | |
126 | "\t<amount_due>536</amount_due>\n" & | |
127 | "\t<payable_by>27-08-2003</payable_by>\n" & | |
128 | "</NotificationU>\n" & | |
129 | LF; | |
130 | ||
131 | testcase enc_embed() runs on Embedder | |
132 | { | |
133 | CHECK_METHOD(bxer_enc_notif, inputS, notif_str_b); | |
134 | CHECK_METHOD(exer_enc_notif, inputS, notif_str); | |
135 | ||
136 | CHECK_METHOD(bxer_enc_notifU, inputU, notifU_str_b); | |
137 | CHECK_METHOD(exer_enc_notifU, inputU, notifU_str); | |
138 | } | |
139 | ||
140 | testcase dec_embed() runs on Embedder | |
141 | { | |
142 | CHECK_DECODE(bxer_dec_notif, notif_str_b, Notification, inputS); | |
143 | CHECK_DECODE(exer_dec_notif, notif_str, Notification, inputS); | |
144 | ||
145 | CHECK_DECODE(bxer_dec_notifU, notifU_str_b, NotificationU, inputU); | |
146 | CHECK_DECODE(exer_dec_notifU, notifU_str, NotificationU, inputU); | |
147 | } | |
148 | ||
149 | /********************** EMEBD-VALUES and ATTRIBUTE **********************/ | |
150 | ||
151 | type record EandA { | |
152 | record of universal charstring embed, | |
153 | integer id, | |
154 | charstring color | |
155 | } | |
156 | with { | |
157 | variant "embedValues"; | |
158 | variant (id) "attribute"; | |
159 | } | |
160 | ||
161 | DECLARE_XER_ENCODERS(EandA, ea); | |
162 | DECLARE_EXER_ENCODERS(EandA, ea); | |
163 | ||
164 | const EandA c_ea := { | |
165 | embed := { "The shirt has", "" }, | |
166 | id := 13, | |
167 | color := "purple" | |
168 | } | |
169 | ||
170 | const universal charstring e_str_ea := | |
171 | "<EandA id='13'>" & | |
172 | "The shirt has" & | |
173 | "<color>purple</color>" & | |
174 | "</EandA>\n"; | |
175 | ||
176 | const universal charstring b_str_ea := | |
177 | "<EandA>\n" & | |
178 | "\t<embed>\n" & | |
179 | "\t\t<UNIVERSAL_CHARSTRING>The shirt has</UNIVERSAL_CHARSTRING>\n" & | |
180 | "\t\t<UNIVERSAL_CHARSTRING/>\n" & | |
181 | "\t</embed>\n" & | |
182 | "\t<id>13</id>\n" & | |
183 | "\t<color>purple</color>\n" & | |
184 | "</EandA>\n\n"; | |
185 | ||
186 | testcase enc_ea() runs on Embedder | |
187 | { | |
188 | CHECK_METHOD(bxer_enc_ea, c_ea, b_str_ea); | |
189 | CHECK_METHOD(exer_enc_ea, c_ea, e_str_ea); | |
190 | } | |
191 | ||
192 | testcase dec_ea() runs on Embedder | |
193 | { | |
194 | CHECK_DECODE(bxer_dec_ea, b_str_ea, EandA, c_ea); | |
195 | CHECK_DECODE(exer_dec_ea, e_str_ea, EandA, c_ea); | |
196 | } | |
197 | ||
198 | /********************** EMBED-VALUES and USE-NIL **********************/ | |
199 | ||
200 | type union j | |
201 | { | |
202 | integer just, | |
203 | boolean unjust | |
204 | }; | |
205 | ||
206 | type record ENil { | |
207 | record of universal charstring embeddings, | |
208 | //must not be character-encodable, hence sequence, set, choice, se*-of... | |
209 | //integer nile optional | |
210 | j nile optional | |
211 | } | |
212 | with { | |
213 | variant "embedValues"; | |
214 | variant "useNil"; | |
215 | } | |
216 | ||
217 | const ENil there := { | |
218 | embeddings := { "She was ", "!" }, | |
219 | nile := { just := 17 } | |
220 | } | |
221 | ||
222 | const universal charstring bstr_there := | |
223 | "<ENil>\n" & | |
224 | "\t<embeddings>\n" & | |
225 | "\t\t<UNIVERSAL_CHARSTRING>She was </UNIVERSAL_CHARSTRING>\n" & | |
226 | "\t\t<UNIVERSAL_CHARSTRING>!</UNIVERSAL_CHARSTRING>\n" & | |
227 | "\t</embeddings>\n" & | |
228 | "\t<nile>\n" & | |
229 | "\t\t<just>17</just>\n" & | |
230 | "\t</nile>\n" & | |
231 | "</ENil>\n\n" ; | |
232 | ||
233 | const universal charstring estr_there := | |
234 | "<ENil>She was <just>17</just>!</ENil>\n"; | |
235 | ||
236 | const ENil gone := { | |
237 | embeddings := {}, | |
238 | nile := omit | |
239 | } | |
240 | ||
241 | const universal charstring bstr_gone := | |
242 | "<ENil>\n" & | |
243 | "\t<embeddings/>\n" & | |
244 | "</ENil>\n\n" ; | |
245 | ||
246 | const universal charstring estr_gone := | |
247 | "<ENil xmlns:pix='foo' pix:nil='true'/>\n"; | |
248 | ||
249 | DECLARE_XER_ENCODERS(ENil, en); | |
250 | DECLARE_EXER_ENCODERS(ENil, en); | |
251 | ||
252 | testcase enc_enil() runs on Embedder | |
253 | { | |
254 | CHECK_METHOD(bxer_enc_en, there, bstr_there); | |
255 | CHECK_METHOD(exer_enc_en, there, estr_there); | |
256 | ||
257 | CHECK_METHOD(bxer_enc_en, gone, bstr_gone); | |
258 | CHECK_METHOD(exer_enc_en, gone, estr_gone); | |
259 | } | |
260 | ||
261 | testcase dec_enil() runs on Embedder | |
262 | { | |
263 | CHECK_DECODE(bxer_dec_en, bstr_there, ENil, there); | |
264 | CHECK_DECODE(exer_dec_en, estr_there, ENil, there); | |
265 | ||
266 | CHECK_DECODE(bxer_dec_en, bstr_gone, ENil, gone); | |
267 | CHECK_DECODE(exer_dec_en, estr_gone, ENil, gone); | |
268 | } | |
269 | ||
270 | /****************** EMBED-VALUES and optional fields ******************/ | |
271 | ||
272 | type record EmOpt { | |
273 | record of universal charstring embed, | |
274 | integer doi optional, | |
275 | integer doii optional, | |
276 | integer zece optional, | |
277 | integer sase optional | |
278 | } | |
279 | with { | |
280 | variant "embedValues" | |
281 | } | |
282 | ||
283 | DECLARE_XER_ENCODERS(EmOpt, eo); | |
284 | DECLARE_EXER_ENCODERS(EmOpt, eo); | |
285 | ||
286 | const EmOpt c_testing := { | |
287 | embed := { "Doi:", "doi:", "zece:", "sase:", "Se aude?" }, | |
288 | doi := 2, | |
289 | doii := 2, | |
290 | zece := 10, | |
291 | sase := 6 | |
292 | } | |
293 | ||
294 | const universal charstring bstr_test6 := | |
295 | "<EmOpt>\n" & | |
296 | "\t<embed>\n" & | |
297 | "\t\t<UNIVERSAL_CHARSTRING>Doi:</UNIVERSAL_CHARSTRING>\n" & | |
298 | "\t\t<UNIVERSAL_CHARSTRING>doi:</UNIVERSAL_CHARSTRING>\n" & | |
299 | "\t\t<UNIVERSAL_CHARSTRING>zece:</UNIVERSAL_CHARSTRING>\n" & | |
300 | "\t\t<UNIVERSAL_CHARSTRING>sase:</UNIVERSAL_CHARSTRING>\n" & | |
301 | "\t\t<UNIVERSAL_CHARSTRING>Se aude?</UNIVERSAL_CHARSTRING>\n" & | |
302 | "\t</embed>\n" & | |
303 | "\t<doi>2</doi>\n" & | |
304 | "\t<doii>2</doii>\n" & | |
305 | "\t<zece>10</zece>\n" & | |
306 | "\t<sase>6</sase>\n" & | |
307 | "</EmOpt>\n\n"; | |
308 | ||
309 | const universal charstring estr_test6 := | |
310 | "<EmOpt>" & | |
311 | "Doi:<doi>2</doi>" & | |
312 | "doi:<doii>2</doii>" & | |
313 | "zece:<zece>10</zece>" & | |
314 | "sase:<sase>6</sase>" & | |
315 | "Se aude?" & | |
316 | "</EmOpt>\n"; | |
317 | ||
318 | const universal charstring bstr_test10 := | |
319 | "<EmOpt>\n" & | |
320 | "\t<embed>\n" & | |
321 | "\t\t<UNIVERSAL_CHARSTRING>Doi:</UNIVERSAL_CHARSTRING>\n" & | |
322 | "\t\t<UNIVERSAL_CHARSTRING>doi:</UNIVERSAL_CHARSTRING>\n" & | |
323 | "\t\t<UNIVERSAL_CHARSTRING>zece:</UNIVERSAL_CHARSTRING>\n" & | |
324 | "\t\t<UNIVERSAL_CHARSTRING>Se aude?</UNIVERSAL_CHARSTRING>\n" & | |
325 | "\t</embed>\n" & | |
326 | "\t<doi>2</doi>\n" & | |
327 | "\t<doii>2</doii>\n" & | |
328 | "\t<zece>10</zece>\n" & | |
329 | "</EmOpt>\n\n"; | |
330 | ||
331 | const universal charstring estr_test10 := | |
332 | "<EmOpt>" & | |
333 | "Doi:<doi>2</doi>" & | |
334 | "doi:<doii>2</doii>" & | |
335 | "zece:<zece>10</zece>" & | |
336 | "Se aude?" & | |
337 | "</EmOpt>\n"; | |
338 | ||
339 | const universal charstring bstr_test2 := | |
340 | "<EmOpt>\n" & | |
341 | "\t<embed>\n" & | |
342 | "\t\t<UNIVERSAL_CHARSTRING>Doi:</UNIVERSAL_CHARSTRING>\n" & | |
343 | "\t\t<UNIVERSAL_CHARSTRING>Se aude?</UNIVERSAL_CHARSTRING>\n" & | |
344 | "\t</embed>\n" & | |
345 | "\t<doi>2</doi>\n" & | |
346 | "</EmOpt>\n\n"; | |
347 | ||
348 | const universal charstring estr_test2 := | |
349 | "<EmOpt>" & | |
350 | "Doi:<doi>2</doi>" & | |
351 | "Se aude?" & | |
352 | "</EmOpt>\n"; | |
353 | ||
354 | ||
355 | testcase enc_emb_opt() runs on Embedder | |
356 | { | |
357 | var EmOpt testing := c_testing; | |
358 | CHECK_METHOD(bxer_enc_eo, testing, bstr_test6); | |
359 | CHECK_METHOD(exer_enc_eo, testing, estr_test6); | |
360 | ||
361 | testing.sase := omit; | |
362 | testing.embed := { "Doi:", "doi:", "zece:", "Se aude?" }; | |
363 | CHECK_METHOD(bxer_enc_eo, testing, bstr_test10); | |
364 | CHECK_METHOD(exer_enc_eo, testing, estr_test10); | |
365 | ||
366 | testing.zece := omit; | |
367 | testing.doii := omit; | |
368 | testing.embed := { "Doi:", "Se aude?" }; | |
369 | CHECK_METHOD(bxer_enc_eo, testing, bstr_test2); | |
370 | CHECK_METHOD(exer_enc_eo, testing, estr_test2); | |
371 | } | |
372 | ||
373 | testcase dec_emb_opt() runs on Embedder | |
374 | { | |
375 | var EmOpt expected := c_testing; | |
376 | // embed := {"Doi:", "doi:", "zece:", "sase:", "Se aude?" } | |
377 | CHECK_DECODE(bxer_dec_eo, bstr_test6, EmOpt, expected); | |
378 | CHECK_DECODE(exer_dec_eo, estr_test6, EmOpt, expected); | |
379 | ||
380 | expected.sase := omit; | |
381 | expected.embed := {"Doi:", "doi:", "zece:", "Se aude?" }; | |
382 | CHECK_DECODE(bxer_dec_eo, bstr_test10, EmOpt, expected); | |
383 | CHECK_DECODE(exer_dec_eo, estr_test10, EmOpt, expected); | |
384 | ||
385 | expected.zece := omit; | |
386 | expected.doii := omit; | |
387 | expected.embed := {"Doi:", "Se aude?" } | |
388 | CHECK_DECODE(bxer_dec_eo, bstr_test2, EmOpt, expected); | |
389 | CHECK_DECODE(exer_dec_eo, estr_test2, EmOpt, expected); | |
390 | } | |
391 | ||
392 | /********************** Control part **********************/ | |
393 | ||
394 | control { | |
395 | execute(enc_embed()); | |
396 | execute(dec_embed()); | |
397 | ||
398 | execute(enc_ea()); | |
399 | execute(dec_ea()); | |
400 | ||
401 | execute(enc_enil()); | |
402 | execute(dec_enil()); | |
403 | ||
404 | execute(enc_emb_opt()); | |
405 | execute(dec_emb_opt()); | |
406 | } | |
407 | ||
408 | } | |
409 | with { | |
410 | encode "XML" | |
411 | variant "controlNamespace 'foo' prefix 'pix'" | |
412 | } |