Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / XML / EXER-whitepaper / Name.ttcnpp
1 /******************************************************************************
2 * Copyright (c) 2000-2015 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 Name
9 {
10 modulepar boolean Name_verbose := false;
11 #define verbose Name_verbose
12 #include "../macros.ttcnin"
13
14 type component alias {}
15
16 type record NM {
17 charstring r,
18 charstring blue,
19 charstring black
20 }
21 with {
22 variant (r) "name as 'Red'";
23 variant (blue) "name as uppercased";
24 variant (black) "name as capitalized";
25 }
26
27 DECLARE_XER_ENCODERS(NM, nm)
28 DECLARE_EXER_ENCODERS(NM, nm)
29
30 const NM outfit := { r := "shirt", blue := "trousers", black := "shoes" }
31
32 const universal charstring str_nm_e :=
33 "<NM>\n" &
34 "\t<Red>shirt</Red>\n" &
35 "\t<BLUE>trousers</BLUE>\n" &
36 "\t<Black>shoes</Black>\n" &
37 "</NM>\n\n";
38
39 const universal charstring str_nm_b :=
40 "<NM>\n" &
41 "\t<r>shirt</r>\n" &
42 "\t<blue>trousers</blue>\n" &
43 "\t<black>shoes</black>\n" &
44 "</NM>\n\n";
45
46 testcase enc_name() runs on alias
47 {
48 CHECK_METHOD(bxer_enc_nm, outfit, str_nm_b);
49 CHECK_METHOD(exer_enc_nm, outfit, str_nm_e);
50 }
51
52 testcase dec_name() runs on alias
53 {
54 CHECK_DECODE(bxer_dec_nm, str_nm_b, NM, outfit);
55 CHECK_DECODE(exer_dec_nm, str_nm_e, NM, outfit);
56 }
57
58 /* * * * * * Renaming the embedded type in a record-of * * * * * * * */
59
60 type record ParamType {
61 charstring caller
62 }
63
64 type record Call {
65 record {
66 record of ParamType param_list
67 } params optional
68 }
69 with {
70 variant "name as uncapitalized";
71 variant (params.param_list[-]) "name as 'param'";
72 }
73
74 DECLARE_XER_ENCODERS(Call, c);
75 DECLARE_EXER_ENCODERS(Call, c);
76
77 const Call phone_home := {
78 params := {
79 param_list := {
80 {
81 caller := "E.T."
82 }
83 }
84 }
85 }
86
87 const universal charstring ET := // for EXER
88 "<call>\n" &
89 "\t<params>\n" &
90 "\t\t<param_list>\n" &
91 "\t\t\t<param>\n" &
92 "\t\t\t\t<caller>E.T.</caller>\n" &
93 "\t\t\t</param>\n" &
94 "\t\t</param_list>\n" &
95 "\t</params>\n" &
96 "</call>\n\n";
97
98 const universal charstring BT := // for Basic XER
99 "<Call>\n" &
100 "\t<params>\n" &
101 "\t\t<param_list>\n" &
102 "\t\t\t<ParamType>\n" &
103 "\t\t\t\t<caller>E.T.</caller>\n" &
104 "\t\t\t</ParamType>\n" &
105 "\t\t</param_list>\n" &
106 "\t</params>\n" &
107 "</Call>\n\n";
108
109 testcase enc_name_recof_embed() runs on alias
110 {
111 CHECK_METHOD(bxer_enc_c, phone_home, BT);
112 CHECK_METHOD(exer_enc_c, phone_home, ET);
113 }
114
115 testcase dec_name_recof_embed() runs on alias
116 {
117 CHECK_DECODE(bxer_dec_c, BT, Call, phone_home);
118 CHECK_DECODE(exer_dec_c, ET, Call, phone_home);
119 }
120
121 /* * * * Record of a type with a "name as" (HL14920) * * * */
122
123 group HL14920 {
124
125 // <element name="foo" type="float"/>
126 type float Foo
127 with {
128 variant "name as uncapitalized";
129 variant "element";
130 };
131
132 //<element name="AllData">
133 // <complexType>
134 // <sequence>
135 // <element ref="ns:foo" minOccurs="0" maxOccurs="unbounded"/>
136 // </sequence>
137 // </complexType>
138 //</element>
139 type record AllData {
140 record of Foo foo_list
141 }
142 with {
143 variant "element";
144 variant (foo_list) "untagged";
145 }
146
147 }
148 with {
149 // For HL14920 to fire, AllData.foo_list.<oftype> needs to have
150 // a XER attribute. This variant will propagate to it.
151 variant "namespace as 'urn:trouble' prefix 'trbl'"
152 }
153
154 DECLARE_XER_ENCODERS(AllData, ad);
155 DECLARE_EXER_ENCODERS(AllData, ad);
156
157 const AllData everything := {
158 { 3.1, 4.1, 5.9, 2.6 }
159 }
160
161 const universal charstring bstr_all :=
162 "<AllData>\n" &
163 "\t<foo_list>\n" &
164 "\t\t<Foo>3.100000</Foo>\n" &
165 "\t\t<Foo>4.100000</Foo>\n" &
166 "\t\t<Foo>5.900000</Foo>\n" &
167 "\t\t<Foo>2.600000</Foo>\n" &
168 "\t</foo_list>\n" &
169 "</AllData>\n\n";
170
171 const universal charstring estr_all :=
172 "<trbl:AllData xmlns:trbl='urn:trouble'>\n" &
173 "\t<trbl:foo>3.100000</trbl:foo>\n" &
174 "\t<trbl:foo>4.100000</trbl:foo>\n" &
175 "\t<trbl:foo>5.900000</trbl:foo>\n" &
176 "\t<trbl:foo>2.600000</trbl:foo>\n" &
177 "</trbl:AllData>\n\n";
178
179
180 testcase enc_recof_named() runs on alias
181 {
182 CHECK_METHOD(bxer_enc_ad, everything, bstr_all);
183 CHECK_METHOD(exer_enc_ad, everything, estr_all);
184 }
185
186 testcase dec_recof_named() runs on alias
187 {
188 CHECK_DECODE(bxer_dec_ad, bstr_all, AllData, everything);
189 CHECK_DECODE(exer_dec_ad, estr_all, AllData, everything);
190 }
191
192 control {
193 execute(enc_name());
194 execute(dec_name());
195
196 execute(enc_name_recof_embed());
197 execute(dec_name_recof_embed());
198
199 execute(enc_recof_named());
200 execute(dec_recof_named());
201 }
202
203 }
204 with {
205 encode "XML"
206 }
This page took 0.036509 seconds and 5 git commands to generate.