Commit | Line | Data |
---|---|---|
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 | ******************************************************************************/ | |
8 | module EmbedValues { | |
9 | modulepar boolean EmbedValues_verbose := false; | |
10 | #define verbose EmbedValues_verbose | |
11 | #include "../macros.ttcnin" | |
12 | ||
13 | type component EMB {} | |
14 | ||
15 | type record EmbProduct { | |
16 | record of universal charstring embed_values, | |
17 | universal charstring companyName, | |
18 | universal charstring productColor, | |
19 | universal charstring productName, | |
20 | octetstring productId | |
21 | } | |
22 | with { | |
23 | variant "embedValues" | |
24 | } | |
25 | ||
26 | ||
27 | DECLARE_XER_ENCODERS(EmbProduct, emb); | |
28 | DECLARE_EXER_ENCODERS(EmbProduct, emb); | |
29 | ||
30 | const EmbProduct embval := { | |
31 | embed_values := {"My Company", "produces", "", "with ID", "which is very popular"}, | |
32 | companyName := "ABC", | |
33 | productColor := "red", | |
34 | productName := "shirt", | |
35 | productId := 'C119B6'O | |
36 | } | |
37 | ||
38 | const universal charstring str_emb_e := | |
39 | "<EmbProduct>My Company<companyName>ABC</companyName>produces<productColor>red</productColor><productName>shirt</productName>with ID<productId>C119B6</productId>which is very popular</EmbProduct>\n"; | |
40 | ||
41 | const universal charstring str_emb_b := | |
42 | "<EmbProduct>\n" & | |
43 | "\t<embed_values>\n" & | |
44 | "\t\t<UNIVERSAL_CHARSTRING>My Company</UNIVERSAL_CHARSTRING>\n" & | |
45 | "\t\t<UNIVERSAL_CHARSTRING>produces</UNIVERSAL_CHARSTRING>\n" & | |
46 | "\t\t<UNIVERSAL_CHARSTRING/>\n" & | |
47 | "\t\t<UNIVERSAL_CHARSTRING>with ID</UNIVERSAL_CHARSTRING>\n" & | |
48 | "\t\t<UNIVERSAL_CHARSTRING>which is very popular</UNIVERSAL_CHARSTRING>\n" & | |
49 | "\t</embed_values>\n" & | |
50 | "\t<companyName>ABC</companyName>\n" & | |
51 | "\t<productColor>red</productColor>\n" & | |
52 | "\t<productName>shirt</productName>\n" & | |
53 | "\t<productId>C119B6</productId>\n" & | |
54 | "</EmbProduct>\n" & | |
55 | "\n"; | |
56 | ||
57 | testcase encode_emb() runs on EMB | |
58 | { | |
59 | CHECK_METHOD(bxer_enc_emb, embval, str_emb_b); | |
60 | CHECK_METHOD(exer_enc_emb, embval, str_emb_e); | |
61 | } | |
62 | ||
63 | testcase decode_emb() runs on EMB | |
64 | { | |
65 | var EmbProduct expected := embval; | |
66 | CHECK_DECODE(bxer_dec_emb, str_emb_b, EmbProduct, expected); | |
67 | CHECK_DECODE(exer_dec_emb, str_emb_e, EmbProduct, expected); | |
68 | } | |
69 | ||
70 | type record EmbedAllTypes { | |
71 | record of universal charstring embed_values, | |
72 | integer i, | |
73 | float f, | |
74 | boolean b, | |
75 | bitstring bs, | |
76 | hexstring hs, | |
77 | octetstring os, | |
78 | charstring cs, | |
79 | universal charstring ucs, | |
80 | enumerated { Big, Small } size, | |
81 | record { | |
82 | universal charstring name, | |
83 | integer phonePrefix | |
84 | } country, | |
85 | record of bitstring bytes, | |
86 | union { | |
87 | universal charstring townName, | |
88 | integer zipCode | |
89 | } location | |
90 | } with { | |
91 | variant "embedValues" | |
92 | } | |
93 | ||
94 | DECLARE_EXER_ENCODERS(EmbedAllTypes, emb_all); | |
95 | ||
96 | const EmbedAllTypes c_emb_all := { | |
97 | { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen" }, | |
98 | 2, | |
99 | 7.1, | |
100 | true, | |
101 | '110101'B, | |
102 | 'ABC12'H, | |
103 | 'C119B6'O, | |
104 | "nothing", | |
105 | "something", | |
106 | Small, | |
107 | { "Hungary", 36 }, | |
108 | { '10011011'B, '11111111'B }, | |
109 | { townName := "London" } | |
110 | }; | |
111 | ||
112 | const universal charstring str_emb_all := | |
113 | "<EmbedAllTypes>one<i>2</i>two<f>7.100000</f>three<b>true</b>four<bs>110101</bs>five<hs>ABC12</hs>six<os>C119B6</os>seven<cs>nothing</cs>eight<ucs>something</ucs>nine<size>Small</size>ten<country><name>Hungary</name><phonePrefix>36</phonePrefix></country>eleven<bytes><BIT_STRING>10011011</BIT_STRING><BIT_STRING>11111111</BIT_STRING></bytes>twelve<location><townName>London</townName></location>thirteen</EmbedAllTypes>\n"; | |
114 | ||
115 | testcase encode_emb_all() runs on EMB | |
116 | { | |
117 | CHECK_METHOD(exer_enc_emb_all, c_emb_all, str_emb_all); | |
118 | } | |
119 | ||
120 | testcase decode_emb_all() runs on EMB | |
121 | { | |
122 | CHECK_DECODE(exer_dec_emb_all, str_emb_all, EmbedAllTypes, c_emb_all); | |
123 | } | |
124 | ||
125 | type record EmbedAnyElem { | |
126 | record of universal charstring embed_values, | |
127 | integer id, | |
128 | universal charstring anyElem, | |
129 | octetstring bytes | |
130 | } with { | |
131 | variant "embedValues"; | |
132 | variant (anyElem) "anyElement"; | |
133 | } | |
134 | ||
135 | DECLARE_EXER_ENCODERS(EmbedAnyElem, emb_any); | |
136 | ||
137 | const EmbedAnyElem c_emb_any := { | |
138 | { "one", "two", "three", "four" }, | |
139 | 2, | |
140 | "<something/>", | |
141 | 'A1'O | |
142 | }; | |
143 | ||
144 | const universal charstring str_emb_any := | |
145 | "<EmbedAnyElem>one<id>2</id>two<something/>three<bytes>A1</bytes>four</EmbedAnyElem>\n"; | |
146 | ||
147 | testcase encode_emb_any() runs on EMB | |
148 | { | |
149 | CHECK_METHOD(exer_enc_emb_any, c_emb_any, str_emb_any); | |
150 | } | |
151 | ||
152 | testcase decode_emb_any() runs on EMB | |
153 | { | |
154 | CHECK_DECODE(exer_dec_emb_any, str_emb_any, EmbedAnyElem, c_emb_any); | |
155 | } | |
156 | ||
af710487 | 157 | // EMBED-VALUES with untagged array |
158 | // the values are also embedded between the array elements, not just the fields of the record | |
159 | type record Inner { | |
160 | integer num, | |
161 | charstring str | |
162 | } | |
163 | ||
164 | type record length (1..infinity) of Inner RoInner; | |
165 | ||
166 | type record Outer { | |
167 | record of universal charstring embed_values, | |
168 | integer attr, | |
169 | octetstring bytes, | |
170 | RoInner stuff | |
171 | } with { | |
172 | variant "embedValues"; | |
173 | variant(attr) "attribute"; | |
174 | variant(bytes) "name as 'Bytes'"; | |
175 | variant(stuff) "untagged"; | |
176 | } | |
177 | ||
178 | DECLARE_EXER_ENCODERS(Outer, emb_outer); | |
179 | ||
180 | const Outer c_emb_array := { | |
181 | embed_values := { "one", "two", "three", "four", "five", "six" }, | |
182 | attr := 48, | |
183 | bytes := 'DEADBEEF'O, | |
184 | stuff := { { 3, "abc" }, { 4, "def" }, { -6, "red" }, { 118, "blue" } } | |
185 | } | |
186 | ||
187 | const Outer c_emb_array_w_holes := { | |
188 | embed_values := { "one", "", "three", "", "five" }, | |
189 | attr := 48, | |
190 | bytes := 'DEADBEEF'O, | |
191 | stuff := { { 3, "abc" }, { 4, "def" }, { -6, "red" }, { 118, "blue" } } | |
192 | } | |
193 | ||
194 | const universal charstring str_emb_array := | |
195 | "<Outer attr='48'>one" & | |
196 | "<Bytes>DEADBEEF</Bytes>two" & | |
197 | "<Inner><num>3</num><str>abc</str></Inner>three" & | |
198 | "<Inner><num>4</num><str>def</str></Inner>four" & | |
199 | "<Inner><num>-6</num><str>red</str></Inner>five" & | |
200 | "<Inner><num>118</num><str>blue</str></Inner>six</Outer>\n"; | |
201 | ||
202 | const universal charstring str_emb_array_w_holes := | |
203 | "<Outer attr='48'>one" & | |
204 | "<Bytes>DEADBEEF</Bytes>" & | |
205 | "<Inner><num>3</num><str>abc</str></Inner>three" & | |
206 | "<Inner><num>4</num><str>def</str></Inner>" & | |
207 | "<Inner><num>-6</num><str>red</str></Inner>five" & | |
208 | "<Inner><num>118</num><str>blue</str></Inner></Outer>\n"; | |
209 | ||
210 | testcase encode_emb_array() runs on EMB | |
211 | { | |
212 | CHECK_METHOD(exer_enc_emb_outer, c_emb_array, str_emb_array); | |
213 | CHECK_METHOD(exer_enc_emb_outer, c_emb_array_w_holes, str_emb_array_w_holes); | |
214 | } | |
215 | ||
216 | testcase decode_emb_array() runs on EMB | |
217 | { | |
218 | CHECK_DECODE(exer_dec_emb_outer, str_emb_array, Outer, c_emb_array); | |
219 | CHECK_DECODE(exer_dec_emb_outer, str_emb_array_w_holes, Outer, c_emb_array_w_holes); | |
220 | } | |
221 | ||
a38c6d4c | 222 | // same as before, but the embedded values are stored in an optimized record-of |
223 | type record Outer2 { | |
224 | record of universal charstring embed_values, | |
225 | integer attr, | |
226 | octetstring bytes, | |
227 | RoInner stuff | |
228 | } with { | |
229 | variant "name as 'Outer'"; | |
230 | extension(embed_values) "optimize:memalloc"; | |
231 | variant "embedValues"; | |
232 | variant(attr) "attribute"; | |
233 | variant(bytes) "name as 'Bytes'"; | |
234 | variant(stuff) "untagged"; | |
235 | } | |
236 | ||
237 | DECLARE_EXER_ENCODERS(Outer2, emb_outer2); | |
238 | ||
239 | const Outer2 c_emb_array2 := { | |
240 | embed_values := { "one", "two", "three", "four", "five", "six" }, | |
241 | attr := 48, | |
242 | bytes := 'DEADBEEF'O, | |
243 | stuff := { { 3, "abc" }, { 4, "def" }, { -6, "red" }, { 118, "blue" } } | |
244 | } | |
245 | ||
246 | const Outer2 c_emb_array_w_holes2 := { | |
247 | embed_values := { "one", "", "three", "", "five" }, | |
248 | attr := 48, | |
249 | bytes := 'DEADBEEF'O, | |
250 | stuff := { { 3, "abc" }, { 4, "def" }, { -6, "red" }, { 118, "blue" } } | |
251 | } | |
252 | ||
253 | testcase encode_emb_array_opt() runs on EMB | |
254 | { | |
255 | CHECK_METHOD(exer_enc_emb_outer2, c_emb_array2, str_emb_array); | |
256 | CHECK_METHOD(exer_enc_emb_outer2, c_emb_array_w_holes2, str_emb_array_w_holes); | |
257 | } | |
258 | ||
259 | testcase decode_emb_array_opt() runs on EMB | |
260 | { | |
261 | CHECK_DECODE(exer_dec_emb_outer2, str_emb_array, Outer2, c_emb_array2); | |
262 | CHECK_DECODE(exer_dec_emb_outer2, str_emb_array_w_holes, Outer2, c_emb_array_w_holes2); | |
263 | } | |
264 | ||
265 | // same as before, but one of the embedded record-ofs is optimized | |
266 | type record length (1..infinity) of Inner RoInner2 with { extension "optimize:memalloc" }; | |
267 | ||
268 | type record Outer3 { | |
269 | record of universal charstring embed_values, | |
270 | integer attr, | |
271 | octetstring bytes, | |
272 | RoInner2 stuff | |
273 | } with { | |
274 | variant "name as 'Outer'"; | |
275 | extension(embed_values) "optimize:memalloc"; | |
276 | variant "embedValues"; | |
277 | variant(attr) "attribute"; | |
278 | variant(bytes) "name as 'Bytes'"; | |
279 | variant(stuff) "untagged"; | |
280 | } | |
281 | ||
282 | DECLARE_EXER_ENCODERS(Outer3, emb_outer3); | |
283 | ||
284 | const Outer3 c_emb_array3 := { | |
285 | embed_values := { "one", "two", "three", "four", "five", "six" }, | |
286 | attr := 48, | |
287 | bytes := 'DEADBEEF'O, | |
288 | stuff := { { 3, "abc" }, { 4, "def" }, { -6, "red" }, { 118, "blue" } } | |
289 | } | |
290 | ||
291 | const Outer3 c_emb_array_w_holes3 := { | |
292 | embed_values := { "one", "", "three", "", "five" }, | |
293 | attr := 48, | |
294 | bytes := 'DEADBEEF'O, | |
295 | stuff := { { 3, "abc" }, { 4, "def" }, { -6, "red" }, { 118, "blue" } } | |
296 | } | |
297 | ||
298 | testcase encode_emb_array_opt2() runs on EMB | |
299 | { | |
300 | CHECK_METHOD(exer_enc_emb_outer3, c_emb_array3, str_emb_array); | |
301 | CHECK_METHOD(exer_enc_emb_outer3, c_emb_array_w_holes3, str_emb_array_w_holes); | |
302 | } | |
303 | ||
304 | testcase decode_emb_array_opt2() runs on EMB | |
305 | { | |
306 | CHECK_DECODE(exer_dec_emb_outer3, str_emb_array, Outer3, c_emb_array3); | |
307 | CHECK_DECODE(exer_dec_emb_outer3, str_emb_array_w_holes, Outer3, c_emb_array_w_holes3); | |
308 | } | |
309 | ||
970ed795 EL |
310 | control { |
311 | execute(encode_emb()); | |
312 | execute(decode_emb()); | |
313 | execute(encode_emb_all()); | |
314 | execute(decode_emb_all()); | |
315 | execute(encode_emb_any()); | |
316 | execute(decode_emb_any()); | |
a38c6d4c | 317 | execute(encode_emb_array()); |
318 | execute(decode_emb_array()); | |
319 | execute(encode_emb_array_opt()); | |
320 | execute(decode_emb_array_opt()); | |
321 | execute(encode_emb_array_opt2()); | |
322 | execute(decode_emb_array_opt2()); | |
970ed795 EL |
323 | } |
324 | ||
325 | } | |
326 | with { | |
327 | encode "XML" | |
328 | } |