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 | ||
970ed795 EL |
222 | control { |
223 | execute(encode_emb()); | |
224 | execute(decode_emb()); | |
225 | execute(encode_emb_all()); | |
226 | execute(decode_emb_all()); | |
227 | execute(encode_emb_any()); | |
228 | execute(decode_emb_any()); | |
af710487 | 229 | //execute(encode_emb_array()); - this functionality was temporarily removed in RT1 |
230 | //execute(decode_emb_array()); | |
970ed795 EL |
231 | } |
232 | ||
233 | } | |
234 | with { | |
235 | encode "XML" | |
236 | } |