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 UseNilSimple_verbose := false;
10 #define verbose UseNilSimple_verbose
11 #include "../macros.ttcnin"
13 type component Nilus {}
15 const universal charstring nil_attr := "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true'";
18 boolean field optional
24 DECLARE_XER_ENCODERS(unbool, ub);
25 DECLARE_EXER_ENCODERS(unbool, ub);
27 const unbool cub := { true }
28 const unbool cubo:= { omit }
30 const universal charstring bstr_ub :=
32 "\t<field><true/></field>\n" &
35 const universal charstring bstr_ubo :=
38 const universal charstring estr_ub :=
39 "<unbool>true</unbool>\n\n";
41 const universal charstring estr_ubo :=
42 "<unbool " & nil_attr & "/>\n\n";
44 testcase tc_enc_unbool() runs on Nilus
46 CHECK_METHOD(exer_enc_ub, cub, estr_ub);
47 CHECK_METHOD(bxer_enc_ub, cub, bstr_ub);
49 CHECK_METHOD(exer_enc_ub, cubo, estr_ubo);
50 CHECK_METHOD(bxer_enc_ub, cubo, bstr_ubo);
53 testcase tc_dec_unbool() runs on Nilus
55 CHECK_DECODE(exer_dec_ub, estr_ub, unbool, cub);
56 CHECK_DECODE(bxer_dec_ub, bstr_ub, unbool, cub);
58 CHECK_DECODE(exer_dec_ub, estr_ubo, unbool, cubo);
59 CHECK_DECODE(bxer_dec_ub, bstr_ubo, unbool, cubo);
62 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
65 charstring field optional
71 DECLARE_XER_ENCODERS(uncs, ucs);
72 DECLARE_EXER_ENCODERS(uncs, ucs);
74 const uncs cucs := { "Unpossible" }
75 const uncs cucso:= { omit }
77 const universal charstring bstr_ucs :=
79 "\t<field>Unpossible</field>\n" &
82 const universal charstring bstr_ucso :=
85 const universal charstring estr_ucs :=
86 "<uncs>Unpossible</uncs>\n\n";
88 const universal charstring estr_ucso :=
89 "<uncs " & nil_attr & "/>\n\n";
91 testcase tc_enc_uncs() runs on Nilus
93 CHECK_METHOD(exer_enc_ucs, cucs, estr_ucs);
94 CHECK_METHOD(bxer_enc_ucs, cucs, bstr_ucs);
96 CHECK_METHOD(exer_enc_ucs, cucso, estr_ucso);
97 CHECK_METHOD(bxer_enc_ucs, cucso, bstr_ucso);
100 testcase tc_dec_uncs() runs on Nilus
102 CHECK_DECODE(exer_dec_ucs, estr_ucs, uncs, cucs);
103 CHECK_DECODE(bxer_dec_ucs, bstr_ucs, uncs, cucs);
105 CHECK_DECODE(exer_dec_ucs, estr_ucso, uncs, cucso);
106 CHECK_DECODE(bxer_dec_ucs, bstr_ucso, uncs, cucso);
109 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
118 DECLARE_XER_ENCODERS(unf, uf);
119 DECLARE_EXER_ENCODERS(unf, uf);
121 const unf cuf := { 3.141592 }
123 const universal charstring bstr_uf :=
125 "\t<field>3.141592</field>\n" &
128 const universal charstring estr_uf :=
129 "<unf>3.141592</unf>\n\n";
131 testcase tc_enc_unf() runs on Nilus
133 CHECK_METHOD(bxer_enc_uf, cuf, bstr_uf);
134 CHECK_METHOD(exer_enc_uf, cuf, estr_uf);
137 testcase tc_dec_unf() runs on Nilus
139 CHECK_DECODE(bxer_dec_uf, bstr_uf, unf, cuf);
140 CHECK_DECODE(exer_dec_uf, estr_uf, unf, cuf);
143 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
146 integer field optional
152 DECLARE_XER_ENCODERS(uni, ui);
153 DECLARE_EXER_ENCODERS(uni, ui);
155 const uni cui := { 42 }
156 const uni cuia:= { 6022141793000000000000000 } // Avogadro, 6.022 * 10^23
158 const universal charstring bstr_ui :=
160 "\t<field>42</field>\n" &
163 const universal charstring estr_ui :=
166 const universal charstring bstr_uia :=
168 "\t<field>6022141793000000000000000</field>\n" &
171 const universal charstring estr_uia :=
172 "<uni>6022141793000000000000000</uni>\n\n";
174 testcase tc_enc_uni() runs on Nilus
176 CHECK_METHOD(bxer_enc_ui, cui, bstr_ui);
177 CHECK_METHOD(exer_enc_ui, cui, estr_ui);
179 CHECK_METHOD(bxer_enc_ui, cuia, bstr_uia);
180 CHECK_METHOD(exer_enc_ui, cuia, estr_uia);
183 testcase tc_dec_uni() runs on Nilus
185 CHECK_DECODE(bxer_dec_ui, bstr_ui, uni, cui);
186 CHECK_DECODE(exer_dec_ui, estr_ui, uni, cui);
188 CHECK_DECODE(bxer_dec_ui, bstr_uia, uni, cuia);
189 CHECK_DECODE(exer_dec_ui, estr_uia, uni, cuia);
192 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
195 octetstring field optional
199 variant (field) "XSD:base64Binary" // required for octetstring to be "character-encodable"
202 DECLARE_XER_ENCODERS(unos, uos);
203 DECLARE_EXER_ENCODERS(unos, uos);
205 // Text from Thomas Hobbes's Leviathan, quoted in Wikipedia's article about base64
206 const unos cuos := { char2oct("Man is distinguished, not only by his reason, " &
207 "but by this singular passion from other animals, which is a lust of the mind, " &
208 "that by a perseverance of delight in the continued and indefatigable " &
209 "generation of knowledge, exceeds the short vehemence of any carnal pleasure.") }
211 const universal charstring TWFu := // also from Wikipedia
212 "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz" &
213 "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg" &
214 "dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu" &
215 "dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo" &
216 "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=";
218 const universal charstring octets :=
219 "4D616E2069732064697374696E677569736865642C206E6F74206F6E6C792062"&
220 "792068697320726561736F6E2C2062757420627920746869732073696E67756C"&
221 "61722070617373696F6E2066726F6D206F7468657220616E696D616C732C2077"&
222 "686963682069732061206C757374206F6620746865206D696E642C2074686174"&
223 "2062792061207065727365766572616E6365206F662064656C6967687420696E"&
224 "2074686520636F6E74696E75656420616E6420696E6465666174696761626C65"&
225 "2067656E65726174696F6E206F66206B6E6F776C656467652C20657863656564"&
226 "73207468652073686F727420766568656D656E6365206F6620616E7920636172"&
227 "6E616C20706C6561737572652E";
229 const universal charstring bstr_uos :=
231 "\t<field>" & octets & "</field>\n" &
234 const universal charstring estr_uos :=
235 "<unos>" & TWFu & "</unos>\n\n";
237 testcase tc_enc_unos() runs on Nilus
240 CHECK_METHOD(bxer_enc_uos, cuos, bstr_uos);
241 CHECK_METHOD(exer_enc_uos, cuos, estr_uos);
244 testcase tc_dec_unos() runs on Nilus
246 CHECK_DECODE(bxer_dec_uos, bstr_uos, unos, cuos);
247 CHECK_DECODE(exer_dec_uos, estr_uos, unos, cuos);
250 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
253 execute(tc_enc_unbool());
254 execute(tc_dec_unbool());
256 execute(tc_enc_uncs());
257 execute(tc_dec_uncs());
259 execute(tc_enc_unf());
260 execute(tc_dec_unf());
262 execute(tc_enc_uni());
263 execute(tc_dec_uni());
265 execute(tc_enc_unos());
266 execute(tc_dec_unos());
272 variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'"
273 variant "elementFormQualified";
274 variant "attributeFormQualified";