Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
d44e3c4f | 2 | * Copyright (c) 2000-2016 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 | |
d44e3c4f | 7 | * |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Raduly, Csaba | |
11 | * | |
970ed795 EL |
12 | ******************************************************************************/ |
13 | module WhitespaceTest { | |
14 | ||
15 | /* Tests for the WHITESPACE encoding instruction. | |
16 | ** WHITESPACE has no effect on the encoder, so only decoding is tested. | |
17 | */ | |
18 | ||
19 | modulepar boolean WhitespaceTest_verbose := false; | |
20 | #define verbose WhitespaceTest_verbose | |
21 | #include "../macros.ttcnin" | |
22 | ||
23 | type component Snow {} | |
24 | ||
25 | type charstring preserver | |
26 | with { variant "whiteSpace preserve" } | |
27 | ||
28 | type charstring replacer | |
29 | with { variant "whiteSpace replace" } | |
30 | ||
31 | type charstring collapser | |
32 | with { variant "whiteSpace collapse" } | |
33 | ||
34 | type universal charstring upreserver | |
35 | with { variant "whiteSpace preserve" } | |
36 | ||
37 | type universal charstring ureplacer | |
38 | with { variant "whiteSpace replace" } | |
39 | ||
40 | type universal charstring ucollapser | |
41 | with { variant "whiteSpace collapse" } | |
42 | ||
43 | ||
44 | const charstring hello := | |
45 | "Say hello. \n" & | |
46 | " \t \t \n" & | |
47 | "\t\t \t\n" & | |
48 | " \t\t \t \t\n" & | |
49 | "\t\t \t \n" & | |
50 | " \t\t \t\t \n" & | |
51 | "\t\t \t\t\n" & | |
52 | " \t\t \t\t \n" & | |
53 | "\t\t \t \n" & | |
54 | " \t\t \t\t\t\t\n" & | |
55 | "\t\t \t \t\n" & | |
56 | " \t \t\t \n" & | |
57 | "\t\t \t\t \n" & | |
58 | " \t \n" & | |
59 | "\t\t \t\t\t\n" & | |
60 | " \t\t\t \t\t\t\n" & | |
61 | "\t\t \t \n" & | |
62 | " \t\t \t\t\t\t\n" & | |
63 | "\t\t \t \t\n" & | |
64 | " \t\t\t \t \n" & | |
65 | "\t\t \t \t \n" & | |
66 | " \t\t \t\t \n" & | |
67 | "\t\t \t \t\t\n" & | |
68 | " \t\t \t \n" & | |
69 | "\t\t \t\t \n" & | |
70 | " \t \n" & | |
71 | "\t\t \t\t \t\n" & | |
72 | " \t\t \t\t\t\t\n" & | |
73 | "\t\t \t\t\t \n" & | |
74 | " \t\t \t\t \n" & | |
75 | "\t\t \t\t\t\t\n" & | |
76 | " \t \n" & | |
77 | "\t\t \t \n" & | |
78 | " \t\t\t \t\t\n" & | |
79 | "\t\t \t \t\n" & | |
80 | " \t\t\t \n" & | |
81 | "\t\t \t \t \n" & | |
82 | " \t\t \t\n" & | |
83 | "\t\t \t \t\t\n" & | |
84 | " \t\t \t\t\n" & | |
85 | "\t\t \t \t \n" & | |
86 | " \t\t \t \t\n" & | |
87 | "\t\t \t \t \t\n" & | |
88 | " \t\t\t \t\t\n" & | |
89 | "\t\t \t \t\t \n" & | |
90 | " \t \t\n" & | |
91 | "\t\t \t \t\t\t\n" & | |
92 | " \n" & | |
93 | "\t\t \n" & | |
94 | "\n" & | |
95 | " \t \t\t\t \t\t\t \t\t\t \t \t\t \t \t \t\t\t \t \t\t \t \t\n" & | |
96 | "\n" & | |
97 | " \t \t\t \t\t\t \t\t \t \t \t\t\t \t\t\t \t\t \t\t \t\t \t \t \t\t \t\t\t \t\t \t \t\n" & | |
98 | "\n" & | |
99 | "\n" & | |
100 | "\n" & | |
101 | "\n" & | |
102 | " \t\t \t \t\t \t \t\t \t \n" & | |
103 | "\t \n" & | |
104 | "\t\n" & | |
105 | "\n" & | |
106 | " \t\t\t \t\t\t \t\t\t \t \t\t \t \t \t\t\t \t \t\t \t \t\n" & | |
107 | " \n" & | |
108 | " \t\t\t \n" & | |
109 | " \n" & | |
110 | "\t \t\t\t \t\t\t \t\t\t \t \t\t \t \t \t\t\t \t \t\t \t \t \t \t\t\t\t\t \t\t \t \t \t\t \t\t\t \t\t \t \n" & | |
111 | "\t\n" & | |
112 | " \t\n" & | |
113 | "\t \n" & | |
114 | " \n" & | |
115 | " \t\t\t \t\t\t \t\t\t \t \t\t \t \t \t\t\t \t \t\t \t \t\n" & | |
116 | "\n" & | |
117 | " \t\t\t \t\t\t \t\t\t \t \t\t \t \t \t\t\t \t \t\t \t \t \t \t\t\t\t\t \t\t \t \t \t\t \t\t\t \t\t \t \n" & | |
118 | " \n" & | |
119 | "\n" & | |
120 | " \n" & | |
121 | "\n" & | |
122 | "\n" & | |
123 | "\t\n" & | |
124 | "\n" & | |
125 | " \t\t\t \t \t\t \t \t \t\t \t \t\t \t \n" & | |
126 | " \n" & | |
127 | " \n" & | |
128 | " \t\n" & | |
129 | "\t \t\t\t \n" & | |
130 | " \t \t \n" & | |
131 | "\t \t\n" & | |
132 | "\t \t\t\t \t \t\t \t \t \t\t \t \t\t \t \t \t\t\t\t\t \t\t \t \t \t\t \t\t\t \t\t \t \n" & | |
133 | " \n" & | |
134 | "\n" & | |
135 | " \t\n" & | |
136 | "\t \n" & | |
137 | " \n" & | |
138 | " \t\t\t \t \t\t \t \t \t\t \t \t\t \t \n" & | |
139 | "\n" & | |
140 | " \t\t\t \t \t\t \t \t \t\t \t \t\t \t \t \t\t\t\t\t \t\t \t \t \t\t \t\t\t \t\t \t \n" & | |
141 | " \n" & | |
142 | "\n" & | |
143 | " \t\n" & | |
144 | "\t \n" & | |
145 | "\t\t \n" & | |
146 | "\t\n" & | |
147 | "\n" & | |
148 | " \t\t \t\t\t \t\t \t \t \t\t\t \t\t\t \t\t \t\t \t\t \t \t \t\t \t\t\t \t\t \t \t\n" & | |
149 | " \t \t \n" & | |
150 | " \t\t \t\n" & | |
151 | "\t\n" & | |
152 | " \t\n" & | |
153 | " \n" & | |
154 | "\t\n"; | |
155 | ||
156 | // hello with tabs and newlines converted to a space | |
157 | const charstring flathello := | |
158 | "Say hello. " & | |
159 | " " & | |
160 | " " & | |
161 | " " & | |
162 | " " & | |
163 | " " & | |
164 | " " & | |
165 | " " & | |
166 | " " & | |
167 | " " & | |
168 | " " & | |
169 | " " & | |
170 | " " & | |
171 | " " & | |
172 | " " & | |
173 | " " & | |
174 | " " & | |
175 | " " & | |
176 | " " & | |
177 | " " & | |
178 | " " & | |
179 | " " & | |
180 | " " & | |
181 | " " & | |
182 | " " & | |
183 | " " & | |
184 | " " & | |
185 | " " & | |
186 | " " & | |
187 | " " & | |
188 | " " & | |
189 | " " & | |
190 | " " & | |
191 | " " & | |
192 | " " & | |
193 | " " & | |
194 | " " & | |
195 | " " & | |
196 | " " & | |
197 | " " & | |
198 | " " & | |
199 | " " & | |
200 | " " & | |
201 | " " & | |
202 | " " & | |
203 | " " & | |
204 | " " & | |
205 | " " & | |
206 | " " & | |
207 | " " & | |
208 | " " & | |
209 | " " & | |
210 | " " & | |
211 | " " & | |
212 | " " & | |
213 | " " & | |
214 | " " & | |
215 | " " & | |
216 | " " & | |
217 | " " & | |
218 | " " & | |
219 | " " & | |
220 | " " & | |
221 | " " & | |
222 | " " & | |
223 | " " & | |
224 | " " & | |
225 | " " & | |
226 | " " & | |
227 | " " & | |
228 | " " & | |
229 | " " & | |
230 | " " & | |
231 | " " & | |
232 | " " & | |
233 | " " & | |
234 | " " & | |
235 | " " & | |
236 | " " & | |
237 | " " & | |
238 | " " & | |
239 | " " & | |
240 | " " & | |
241 | " " & | |
242 | " " & | |
243 | " " & | |
244 | " " & | |
245 | " " & | |
246 | " " & | |
247 | " " & | |
248 | " " & | |
249 | " " & | |
250 | " " & | |
251 | " " & | |
252 | " " & | |
253 | " " & | |
254 | " " & | |
255 | " " & | |
256 | " " & | |
257 | " " & | |
258 | " " & | |
259 | " " & | |
260 | " " & | |
261 | " " & | |
262 | " " & | |
263 | " " & | |
264 | " " & | |
265 | " " & | |
266 | " " & | |
267 | " "; | |
268 | ||
269 | // hello with consecutive spaces and newlines converted to a single space | |
270 | const charstring smallhello := "Say hello."; | |
271 | ||
272 | DECLARE_XER_ENCODERS(preserver, pres) | |
273 | DECLARE_EXER_ENCODERS(preserver, pres) | |
274 | ||
275 | DECLARE_XER_ENCODERS(replacer, rpl) | |
276 | DECLARE_EXER_ENCODERS(replacer, rpl) | |
277 | ||
278 | DECLARE_XER_ENCODERS(collapser, col) | |
279 | DECLARE_EXER_ENCODERS(collapser, col) | |
280 | ||
281 | testcase dec_whitespace_preserve() runs on Snow | |
282 | { | |
283 | var charstring expected := hello; | |
284 | var octetstring tmp := bxer_enc_pres(hello); | |
285 | var universal charstring input := fromUTF8(tmp); | |
286 | ||
287 | // BXER & CXER just give back the input. | |
288 | CHECK_DECODE(bxer_dec_pres, input, preserver, expected); | |
289 | CHECK_DECODE(cxer_dec_pres, input, preserver, expected); | |
290 | ||
291 | // EXER brings WHITESPACE REPLACE to life. | |
292 | expected := hello; | |
293 | CHECK_DECODE(exer_dec_pres, input, preserver, expected); | |
294 | ||
295 | // When the input does not end in whitespace, the behavior is the same. | |
296 | tmp := bxer_enc_pres(hello & "!"); | |
297 | input := fromUTF8(tmp); | |
298 | CHECK_DECODE(bxer_dec_pres, input, preserver, hello & "!"); | |
299 | CHECK_DECODE(cxer_dec_pres, input, preserver, hello & "!"); | |
300 | expected := hello & "!"; | |
301 | CHECK_DECODE(exer_dec_pres, input, preserver, expected); | |
302 | } | |
303 | ||
304 | testcase dec_whitespace_replace() runs on Snow | |
305 | { | |
306 | var charstring expected := hello; | |
307 | // Encode the string to produce the input for the decoder. | |
308 | // (WHITESPACE applies no change on Titan's XER *encoder* ) | |
309 | var octetstring tmp := bxer_enc_rpl(hello); | |
310 | var universal charstring input := fromUTF8(tmp); | |
311 | ||
312 | // BXER & CXER just give back the input. | |
313 | CHECK_DECODE(bxer_dec_rpl, input, replacer, expected); | |
314 | CHECK_DECODE(cxer_dec_rpl, input, replacer, expected); | |
315 | ||
316 | // EXER brings WHITESPACE REPLACE to life. | |
317 | expected := flathello; | |
318 | CHECK_DECODE(exer_dec_rpl, input, replacer, expected); | |
319 | ||
320 | // When the input does not end in whitespace, the behavior is the same. | |
321 | tmp := bxer_enc_rpl(hello & "!"); | |
322 | input := fromUTF8(tmp); | |
323 | CHECK_DECODE(bxer_dec_rpl, input, replacer, hello & "!"); | |
324 | CHECK_DECODE(cxer_dec_rpl, input, replacer, hello & "!"); | |
325 | expected := flathello & "!"; | |
326 | CHECK_DECODE(exer_dec_rpl, input, replacer, expected); | |
327 | } | |
328 | ||
329 | testcase dec_whitespace_collapse() runs on Snow | |
330 | { | |
331 | var charstring expected := hello; | |
332 | // Encode the string to produce the input for the decoder. | |
333 | var octetstring tmp := bxer_enc_col(hello); | |
334 | var universal charstring input := fromUTF8(tmp); | |
335 | ||
336 | // BXER & CXER just give back the input. | |
337 | CHECK_DECODE(bxer_dec_col, input, collapser, expected); | |
338 | CHECK_DECODE(cxer_dec_col, input, collapser, expected); | |
339 | ||
340 | // WHITESPACE COLLAPSE makes all the whitespace at the end disappear. | |
341 | expected := smallhello; | |
342 | CHECK_DECODE(exer_dec_col, input, collapser, expected); | |
343 | ||
344 | input := fromUTF8( bxer_enc_col(hello & "!") ); | |
345 | // Now the input does not end in whitespace. Nothing exciting from BXER/CXER. | |
346 | CHECK_DECODE(bxer_dec_col, input, replacer, hello & "!"); | |
347 | CHECK_DECODE(cxer_dec_col, input, replacer, hello & "!"); | |
348 | // WHITESPACE COLLAPSE transforms whitespace in the middle into a single space. | |
349 | // Note that we append a space before the exclamation mark. | |
350 | // This space is the output from all that whitespace in the input. | |
351 | expected := smallhello & " !"; | |
352 | CHECK_DECODE(exer_dec_col, input, collapser, expected); | |
353 | } | |
354 | ||
355 | ||
356 | DECLARE_XER_ENCODERS(upreserver, upres) | |
357 | DECLARE_EXER_ENCODERS(upreserver, upres) | |
358 | ||
359 | DECLARE_XER_ENCODERS(ureplacer, urpl) | |
360 | DECLARE_EXER_ENCODERS(ureplacer, urpl) | |
361 | ||
362 | DECLARE_XER_ENCODERS(ucollapser, ucol) | |
363 | DECLARE_EXER_ENCODERS(ucollapser, ucol) | |
364 | ||
365 | // These strings check that characters with cell values of 9, 13 or 32 | |
366 | // (but different plane,group,row values) are not accidentally identified | |
367 | // as HORIZONTAL TAB, CARRIAGE RETURN or SPACE. | |
368 | ||
369 | const universal charstring tricky := | |
370 | " \t " & char(0,1,2,9) & char(0,1,2,13) & char(0,1,2,32) & "\t\t\tThe end\t\n\n"; | |
371 | ||
372 | const universal charstring flat_tricky := | |
373 | " " & char(0,1,2,9) & char(0,1,2,13) & char(0,1,2,32) & " The end "; | |
374 | ||
375 | const universal charstring small_tricky := | |
376 | char(0,1,2,9) & char(0,1,2,13) & char(0,1,2,32) & " The end"; | |
377 | ||
378 | testcase dec_whitespace_upreserve() runs on Snow | |
379 | { | |
380 | var universal charstring expected := hello; | |
381 | var universal charstring input := fromUTF8( bxer_enc_upres(hello) ); | |
382 | ||
383 | CHECK_DECODE(bxer_dec_upres, input, upreserver, expected); | |
384 | CHECK_DECODE(cxer_dec_upres, input, upreserver, expected); | |
385 | ||
386 | expected := hello; | |
387 | CHECK_DECODE(exer_dec_upres, input, upreserver, expected); | |
388 | ||
389 | input := fromUTF8( bxer_enc_upres(tricky) ); | |
390 | expected := tricky; | |
391 | CHECK_DECODE(exer_dec_upres, input, upreserver, expected); | |
392 | ||
393 | input := fromUTF8( bxer_enc_upres(tricky & "!") ); | |
394 | expected := tricky & "!"; | |
395 | CHECK_DECODE(exer_dec_upres, input, upreserver, expected); | |
396 | ||
397 | } | |
398 | ||
399 | testcase dec_whitespace_ureplace() runs on Snow | |
400 | { | |
401 | var universal charstring expected := hello; | |
402 | var universal charstring input := fromUTF8( bxer_enc_urpl(hello) ); | |
403 | ||
404 | CHECK_DECODE(bxer_dec_urpl, input, ureplacer, expected); | |
405 | CHECK_DECODE(cxer_dec_urpl, input, ureplacer, expected); | |
406 | ||
407 | expected := flathello; | |
408 | CHECK_DECODE(exer_dec_urpl, input, ureplacer, expected); | |
409 | ||
410 | input := fromUTF8( bxer_enc_urpl(tricky) ); | |
411 | expected := flat_tricky; | |
412 | CHECK_DECODE(exer_dec_urpl, input, ureplacer, expected); | |
413 | ||
414 | input := fromUTF8( bxer_enc_urpl(tricky & "!") ); | |
415 | expected := flat_tricky & "!"; | |
416 | CHECK_DECODE(exer_dec_urpl, input, ureplacer, expected); | |
417 | ||
418 | } | |
419 | ||
420 | testcase dec_whitespace_ucollapse() runs on Snow | |
421 | { | |
422 | var universal charstring expected := hello; | |
423 | var universal charstring input := fromUTF8( bxer_enc_ucol(hello) ); | |
424 | ||
425 | CHECK_DECODE(bxer_dec_ucol, input, ucollapser, expected); | |
426 | CHECK_DECODE(cxer_dec_ucol, input, ucollapser, expected); | |
427 | ||
428 | expected := smallhello; | |
429 | CHECK_DECODE(exer_dec_ucol, input, ucollapser, expected); | |
430 | ||
431 | input := fromUTF8( bxer_enc_ucol(tricky) ); | |
432 | expected := small_tricky; | |
433 | CHECK_DECODE(exer_dec_ucol, input, ucollapser, expected); | |
434 | ||
435 | input := fromUTF8( bxer_enc_ucol(tricky & "!") ); | |
436 | expected := small_tricky & " !"; | |
437 | // whitespace is no longer at the end, it is collapsed instead of being eliminated | |
438 | // Note: a space, then '!' | |
439 | CHECK_DECODE(exer_dec_ucol, input, ucollapser, expected); | |
440 | ||
441 | input := fromUTF8( bxer_enc_ucol("?" & tricky) ); | |
442 | expected := "? " & small_tricky; | |
443 | // whitespace is no longer at the beginning, it is collapsed instead of being eliminated | |
444 | // Note: '?', then a spaec | |
445 | CHECK_DECODE(exer_dec_ucol, input, ucollapser, expected); | |
446 | } | |
447 | ||
448 | ||
449 | control { | |
450 | execute(dec_whitespace_preserve()) | |
451 | execute(dec_whitespace_replace()) | |
452 | execute(dec_whitespace_collapse()) | |
453 | ||
454 | execute(dec_whitespace_upreserve()) | |
455 | execute(dec_whitespace_ureplace()) | |
456 | execute(dec_whitespace_ucollapse()) | |
457 | } | |
458 | ||
459 | } | |
460 | with { | |
461 | encode "XER" | |
462 | } |