9ce328c9d4807f87974f64ab4cc489b89c4b0d50
[deliverable/titan.core.git] / regression_test / XML / EXER-whitepaper / EmbedValues.ttcnpp
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
157 control {
158 execute(encode_emb());
159 execute(decode_emb());
160 execute(encode_emb_all());
161 execute(decode_emb_all());
162 execute(encode_emb_any());
163 execute(decode_emb_any());
164 }
165
166 }
167 with {
168 encode "XML"
169 }
This page took 0.044635 seconds and 4 git commands to generate.