Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
3abe9331 | 2 | * Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
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 UseNilSimple { | |
9 | modulepar boolean UseNilSimple_verbose := false; | |
10 | #define verbose UseNilSimple_verbose | |
11 | #include "../macros.ttcnin" | |
12 | ||
13 | type component Nilus {} | |
14 | ||
15 | const universal charstring nil_attr := "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true'"; | |
16 | ||
17 | type record unbool { | |
18 | boolean field optional | |
19 | } | |
20 | with { | |
21 | variant "useNil"; | |
22 | } | |
23 | ||
24 | DECLARE_XER_ENCODERS(unbool, ub); | |
25 | DECLARE_EXER_ENCODERS(unbool, ub); | |
26 | ||
27 | const unbool cub := { true } | |
28 | const unbool cubo:= { omit } | |
29 | ||
30 | const universal charstring bstr_ub := | |
31 | "<unbool>\n" & | |
32 | "\t<field><true/></field>\n" & | |
33 | "</unbool>\n\n"; | |
34 | ||
35 | const universal charstring bstr_ubo := | |
36 | "<unbool/>\n\n"; | |
37 | ||
38 | const universal charstring estr_ub := | |
39 | "<unbool>true</unbool>\n\n"; | |
40 | ||
41 | const universal charstring estr_ubo := | |
42 | "<unbool " & nil_attr & "/>\n\n"; | |
43 | ||
44 | testcase tc_enc_unbool() runs on Nilus | |
45 | { | |
46 | CHECK_METHOD(exer_enc_ub, cub, estr_ub); | |
47 | CHECK_METHOD(bxer_enc_ub, cub, bstr_ub); | |
48 | ||
49 | CHECK_METHOD(exer_enc_ub, cubo, estr_ubo); | |
50 | CHECK_METHOD(bxer_enc_ub, cubo, bstr_ubo); | |
51 | } | |
52 | ||
53 | testcase tc_dec_unbool() runs on Nilus | |
54 | { | |
55 | CHECK_DECODE(exer_dec_ub, estr_ub, unbool, cub); | |
56 | CHECK_DECODE(bxer_dec_ub, bstr_ub, unbool, cub); | |
57 | ||
58 | CHECK_DECODE(exer_dec_ub, estr_ubo, unbool, cubo); | |
59 | CHECK_DECODE(bxer_dec_ub, bstr_ubo, unbool, cubo); | |
60 | } | |
61 | ||
62 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
63 | ||
64 | type record uncs { | |
65 | charstring field optional | |
66 | } | |
67 | with { | |
68 | variant "useNil"; | |
69 | } | |
70 | ||
71 | DECLARE_XER_ENCODERS(uncs, ucs); | |
72 | DECLARE_EXER_ENCODERS(uncs, ucs); | |
73 | ||
74 | const uncs cucs := { "Unpossible" } | |
75 | const uncs cucso:= { omit } | |
76 | ||
77 | const universal charstring bstr_ucs := | |
78 | "<uncs>\n" & | |
79 | "\t<field>Unpossible</field>\n" & | |
80 | "</uncs>\n\n"; | |
81 | ||
82 | const universal charstring bstr_ucso := | |
83 | "<uncs/>\n\n"; | |
84 | ||
85 | const universal charstring estr_ucs := | |
86 | "<uncs>Unpossible</uncs>\n\n"; | |
87 | ||
88 | const universal charstring estr_ucso := | |
89 | "<uncs " & nil_attr & "/>\n\n"; | |
90 | ||
91 | testcase tc_enc_uncs() runs on Nilus | |
92 | { | |
93 | CHECK_METHOD(exer_enc_ucs, cucs, estr_ucs); | |
94 | CHECK_METHOD(bxer_enc_ucs, cucs, bstr_ucs); | |
95 | ||
96 | CHECK_METHOD(exer_enc_ucs, cucso, estr_ucso); | |
97 | CHECK_METHOD(bxer_enc_ucs, cucso, bstr_ucso); | |
98 | } | |
99 | ||
100 | testcase tc_dec_uncs() runs on Nilus | |
101 | { | |
102 | CHECK_DECODE(exer_dec_ucs, estr_ucs, uncs, cucs); | |
103 | CHECK_DECODE(bxer_dec_ucs, bstr_ucs, uncs, cucs); | |
104 | ||
105 | CHECK_DECODE(exer_dec_ucs, estr_ucso, uncs, cucso); | |
106 | CHECK_DECODE(bxer_dec_ucs, bstr_ucso, uncs, cucso); | |
107 | } | |
108 | ||
109 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
110 | ||
111 | type record unf { | |
112 | float field optional | |
113 | } | |
114 | with { | |
115 | variant "useNil"; | |
116 | } | |
117 | ||
118 | DECLARE_XER_ENCODERS(unf, uf); | |
119 | DECLARE_EXER_ENCODERS(unf, uf); | |
120 | ||
121 | const unf cuf := { 3.141592 } | |
122 | ||
123 | const universal charstring bstr_uf := | |
124 | "<unf>\n" & | |
125 | "\t<field>3.141592</field>\n" & | |
126 | "</unf>\n\n"; | |
127 | ||
128 | const universal charstring estr_uf := | |
129 | "<unf>3.141592</unf>\n\n"; | |
130 | ||
131 | testcase tc_enc_unf() runs on Nilus | |
132 | { | |
133 | CHECK_METHOD(bxer_enc_uf, cuf, bstr_uf); | |
134 | CHECK_METHOD(exer_enc_uf, cuf, estr_uf); | |
135 | } | |
136 | ||
137 | testcase tc_dec_unf() runs on Nilus | |
138 | { | |
139 | CHECK_DECODE(bxer_dec_uf, bstr_uf, unf, cuf); | |
140 | CHECK_DECODE(exer_dec_uf, estr_uf, unf, cuf); | |
141 | } | |
142 | ||
143 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
144 | ||
145 | type record uni { | |
146 | integer field optional | |
147 | } | |
148 | with { | |
149 | variant "useNil"; | |
150 | } | |
151 | ||
152 | DECLARE_XER_ENCODERS(uni, ui); | |
153 | DECLARE_EXER_ENCODERS(uni, ui); | |
154 | ||
155 | const uni cui := { 42 } | |
156 | const uni cuia:= { 6022141793000000000000000 } // Avogadro, 6.022 * 10^23 | |
157 | ||
158 | const universal charstring bstr_ui := | |
159 | "<uni>\n" & | |
160 | "\t<field>42</field>\n" & | |
161 | "</uni>\n\n"; | |
162 | ||
163 | const universal charstring estr_ui := | |
164 | "<uni>42</uni>\n\n"; | |
165 | ||
166 | const universal charstring bstr_uia := | |
167 | "<uni>\n" & | |
168 | "\t<field>6022141793000000000000000</field>\n" & | |
169 | "</uni>\n\n"; | |
170 | ||
171 | const universal charstring estr_uia := | |
172 | "<uni>6022141793000000000000000</uni>\n\n"; | |
173 | ||
174 | testcase tc_enc_uni() runs on Nilus | |
175 | { | |
176 | CHECK_METHOD(bxer_enc_ui, cui, bstr_ui); | |
177 | CHECK_METHOD(exer_enc_ui, cui, estr_ui); | |
178 | ||
179 | CHECK_METHOD(bxer_enc_ui, cuia, bstr_uia); | |
180 | CHECK_METHOD(exer_enc_ui, cuia, estr_uia); | |
181 | } | |
182 | ||
183 | testcase tc_dec_uni() runs on Nilus | |
184 | { | |
185 | CHECK_DECODE(bxer_dec_ui, bstr_ui, uni, cui); | |
186 | CHECK_DECODE(exer_dec_ui, estr_ui, uni, cui); | |
187 | ||
188 | CHECK_DECODE(bxer_dec_ui, bstr_uia, uni, cuia); | |
189 | CHECK_DECODE(exer_dec_ui, estr_uia, uni, cuia); | |
190 | } | |
191 | ||
192 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
193 | ||
194 | type record unos { | |
195 | octetstring field optional | |
196 | } | |
197 | with { | |
198 | variant "useNil"; | |
199 | variant (field) "XSD:base64Binary" // required for octetstring to be "character-encodable" | |
200 | } | |
201 | ||
202 | DECLARE_XER_ENCODERS(unos, uos); | |
203 | DECLARE_EXER_ENCODERS(unos, uos); | |
204 | ||
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.") } | |
210 | ||
211 | const universal charstring TWFu := // also from Wikipedia | |
212 | "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz" & | |
213 | "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg" & | |
214 | "dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu" & | |
215 | "dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo" & | |
216 | "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="; | |
217 | ||
218 | const universal charstring octets := | |
219 | "4D616E2069732064697374696E677569736865642C206E6F74206F6E6C792062"& | |
220 | "792068697320726561736F6E2C2062757420627920746869732073696E67756C"& | |
221 | "61722070617373696F6E2066726F6D206F7468657220616E696D616C732C2077"& | |
222 | "686963682069732061206C757374206F6620746865206D696E642C2074686174"& | |
223 | "2062792061207065727365766572616E6365206F662064656C6967687420696E"& | |
224 | "2074686520636F6E74696E75656420616E6420696E6465666174696761626C65"& | |
225 | "2067656E65726174696F6E206F66206B6E6F776C656467652C20657863656564"& | |
226 | "73207468652073686F727420766568656D656E6365206F6620616E7920636172"& | |
227 | "6E616C20706C6561737572652E"; | |
228 | ||
229 | const universal charstring bstr_uos := | |
230 | "<unos>\n" & | |
231 | "\t<field>" & octets & "</field>\n" & | |
232 | "</unos>\n\n"; | |
233 | ||
234 | const universal charstring estr_uos := | |
235 | "<unos>" & TWFu & "</unos>\n\n"; | |
236 | ||
237 | testcase tc_enc_unos() runs on Nilus | |
238 | { | |
239 | //log(cuos); | |
240 | CHECK_METHOD(bxer_enc_uos, cuos, bstr_uos); | |
241 | CHECK_METHOD(exer_enc_uos, cuos, estr_uos); | |
242 | } | |
243 | ||
244 | testcase tc_dec_unos() runs on Nilus | |
245 | { | |
246 | CHECK_DECODE(bxer_dec_uos, bstr_uos, unos, cuos); | |
247 | CHECK_DECODE(exer_dec_uos, estr_uos, unos, cuos); | |
248 | } | |
249 | ||
250 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
251 | ||
252 | control { | |
253 | execute(tc_enc_unbool()); | |
254 | execute(tc_dec_unbool()); | |
255 | ||
256 | execute(tc_enc_uncs()); | |
257 | execute(tc_dec_uncs()); | |
258 | ||
259 | execute(tc_enc_unf()); | |
260 | execute(tc_dec_unf()); | |
261 | ||
262 | execute(tc_enc_uni()); | |
263 | execute(tc_dec_uni()); | |
264 | ||
265 | execute(tc_enc_unos()); | |
266 | execute(tc_dec_unos()); | |
267 | } | |
268 | ||
269 | } | |
270 | with { | |
271 | encode "XML"; | |
272 | variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'" | |
273 | variant "elementFormQualified"; | |
274 | variant "attributeFormQualified"; | |
275 | } |