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 ******************************************************************************/
9 modulepar boolean EmbedValues_verbose := false;
10 #define verbose EmbedValues_verbose
11 #include "../macros.ttcnin"
15 type record EmbProduct {
16 record of universal charstring embed_values,
17 universal charstring companyName,
18 universal charstring productColor,
19 universal charstring productName,
27 DECLARE_XER_ENCODERS(EmbProduct, emb);
28 DECLARE_EXER_ENCODERS(EmbProduct, emb);
30 const EmbProduct embval := {
31 embed_values := {"My Company", "produces", "", "with ID", "which is very popular"},
33 productColor := "red",
34 productName := "shirt",
35 productId := 'C119B6'O
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";
41 const universal charstring str_emb_b :=
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" &
57 testcase encode_emb() runs on EMB
59 CHECK_METHOD(bxer_enc_emb, embval, str_emb_b);
60 CHECK_METHOD(exer_enc_emb, embval, str_emb_e);
63 testcase decode_emb() runs on EMB
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);
70 type record EmbedAllTypes {
71 record of universal charstring embed_values,
79 universal charstring ucs,
80 enumerated { Big, Small } size,
82 universal charstring name,
85 record of bitstring bytes,
87 universal charstring townName,
94 DECLARE_EXER_ENCODERS(EmbedAllTypes, emb_all);
96 const EmbedAllTypes c_emb_all := {
97 { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen" },
108 { '10011011'B, '11111111'B },
109 { townName := "London" }
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";
115 testcase encode_emb_all() runs on EMB
117 CHECK_METHOD(exer_enc_emb_all, c_emb_all, str_emb_all);
120 testcase decode_emb_all() runs on EMB
122 CHECK_DECODE(exer_dec_emb_all, str_emb_all, EmbedAllTypes, c_emb_all);
125 type record EmbedAnyElem {
126 record of universal charstring embed_values,
128 universal charstring anyElem,
131 variant "embedValues";
132 variant (anyElem) "anyElement";
135 DECLARE_EXER_ENCODERS(EmbedAnyElem, emb_any);
137 const EmbedAnyElem c_emb_any := {
138 { "one", "two", "three", "four" },
144 const universal charstring str_emb_any :=
145 "<EmbedAnyElem>one<id>2</id>two<something/>three<bytes>A1</bytes>four</EmbedAnyElem>\n";
147 testcase encode_emb_any() runs on EMB
149 CHECK_METHOD(exer_enc_emb_any, c_emb_any, str_emb_any);
152 testcase decode_emb_any() runs on EMB
154 CHECK_DECODE(exer_dec_emb_any, str_emb_any, EmbedAnyElem, c_emb_any);
157 // EMBED-VALUES with untagged array
158 // the values are also embedded between the array elements, not just the fields of the record
164 type record length (1..infinity) of Inner RoInner;
167 record of universal charstring embed_values,
172 variant "embedValues";
173 variant(attr) "attribute";
174 variant(bytes) "name as 'Bytes'";
175 variant(stuff) "untagged";
178 DECLARE_EXER_ENCODERS(Outer, emb_outer);
180 const Outer c_emb_array := {
181 embed_values := { "one", "two", "three", "four", "five", "six" },
183 bytes := 'DEADBEEF'O,
184 stuff := { { 3, "abc" }, { 4, "def" }, { -6, "red" }, { 118, "blue" } }
187 const Outer c_emb_array_w_holes := {
188 embed_values := { "one", "", "three", "", "five" },
190 bytes := 'DEADBEEF'O,
191 stuff := { { 3, "abc" }, { 4, "def" }, { -6, "red" }, { 118, "blue" } }
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";
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";
210 testcase encode_emb_array() runs on EMB
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);
216 testcase decode_emb_array() runs on EMB
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);
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());
229 //execute(encode_emb_array()); - this functionality was temporarily removed in RT1
230 //execute(decode_emb_array());