Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / XML / TTCNandXML / WhitespaceTest.ttcnpp
CommitLineData
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 ******************************************************************************/
8module WhitespaceTest {
9
10/* Tests for the WHITESPACE encoding instruction.
11** WHITESPACE has no effect on the encoder, so only decoding is tested.
12*/
13
14modulepar boolean WhitespaceTest_verbose := false;
15#define verbose WhitespaceTest_verbose
16#include "../macros.ttcnin"
17
18type component Snow {}
19
20type charstring preserver
21with { variant "whiteSpace preserve" }
22
23type charstring replacer
24with { variant "whiteSpace replace" }
25
26type charstring collapser
27with { variant "whiteSpace collapse" }
28
29type universal charstring upreserver
30with { variant "whiteSpace preserve" }
31
32type universal charstring ureplacer
33with { variant "whiteSpace replace" }
34
35type universal charstring ucollapser
36with { variant "whiteSpace collapse" }
37
38
39const charstring hello :=
40"Say hello. \n" &
41" \t \t \n" &
42"\t\t \t\n" &
43" \t\t \t \t\n" &
44"\t\t \t \n" &
45" \t\t \t\t \n" &
46"\t\t \t\t\n" &
47" \t\t \t\t \n" &
48"\t\t \t \n" &
49" \t\t \t\t\t\t\n" &
50"\t\t \t \t\n" &
51" \t \t\t \n" &
52"\t\t \t\t \n" &
53" \t \n" &
54"\t\t \t\t\t\n" &
55" \t\t\t \t\t\t\n" &
56"\t\t \t \n" &
57" \t\t \t\t\t\t\n" &
58"\t\t \t \t\n" &
59" \t\t\t \t \n" &
60"\t\t \t \t \n" &
61" \t\t \t\t \n" &
62"\t\t \t \t\t\n" &
63" \t\t \t \n" &
64"\t\t \t\t \n" &
65" \t \n" &
66"\t\t \t\t \t\n" &
67" \t\t \t\t\t\t\n" &
68"\t\t \t\t\t \n" &
69" \t\t \t\t \n" &
70"\t\t \t\t\t\t\n" &
71" \t \n" &
72"\t\t \t \n" &
73" \t\t\t \t\t\n" &
74"\t\t \t \t\n" &
75" \t\t\t \n" &
76"\t\t \t \t \n" &
77" \t\t \t\n" &
78"\t\t \t \t\t\n" &
79" \t\t \t\t\n" &
80"\t\t \t \t \n" &
81" \t\t \t \t\n" &
82"\t\t \t \t \t\n" &
83" \t\t\t \t\t\n" &
84"\t\t \t \t\t \n" &
85" \t \t\n" &
86"\t\t \t \t\t\t\n" &
87" \n" &
88"\t\t \n" &
89"\n" &
90" \t \t\t\t \t\t\t \t\t\t \t \t\t \t \t \t\t\t \t \t\t \t \t\n" &
91"\n" &
92" \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" &
93"\n" &
94"\n" &
95"\n" &
96"\n" &
97" \t\t \t \t\t \t \t\t \t \n" &
98"\t \n" &
99"\t\n" &
100"\n" &
101" \t\t\t \t\t\t \t\t\t \t \t\t \t \t \t\t\t \t \t\t \t \t\n" &
102" \n" &
103" \t\t\t \n" &
104" \n" &
105"\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" &
106"\t\n" &
107" \t\n" &
108"\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\n" &
111"\n" &
112" \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" &
113" \n" &
114"\n" &
115" \n" &
116"\n" &
117"\n" &
118"\t\n" &
119"\n" &
120" \t\t\t \t \t\t \t \t \t\t \t \t\t \t \n" &
121" \n" &
122" \n" &
123" \t\n" &
124"\t \t\t\t \n" &
125" \t \t \n" &
126"\t \t\n" &
127"\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" &
128" \n" &
129"\n" &
130" \t\n" &
131"\t \n" &
132" \n" &
133" \t\t\t \t \t\t \t \t \t\t \t \t\t \t \n" &
134"\n" &
135" \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" &
136" \n" &
137"\n" &
138" \t\n" &
139"\t \n" &
140"\t\t \n" &
141"\t\n" &
142"\n" &
143" \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" &
144" \t \t \n" &
145" \t\t \t\n" &
146"\t\n" &
147" \t\n" &
148" \n" &
149"\t\n";
150
151// hello with tabs and newlines converted to a space
152const charstring flathello :=
153"Say hello. " &
154" " &
155" " &
156" " &
157" " &
158" " &
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// hello with consecutive spaces and newlines converted to a single space
265const charstring smallhello := "Say hello.";
266
267DECLARE_XER_ENCODERS(preserver, pres)
268DECLARE_EXER_ENCODERS(preserver, pres)
269
270DECLARE_XER_ENCODERS(replacer, rpl)
271DECLARE_EXER_ENCODERS(replacer, rpl)
272
273DECLARE_XER_ENCODERS(collapser, col)
274DECLARE_EXER_ENCODERS(collapser, col)
275
276testcase dec_whitespace_preserve() runs on Snow
277{
278 var charstring expected := hello;
279 var octetstring tmp := bxer_enc_pres(hello);
280 var universal charstring input := fromUTF8(tmp);
281
282 // BXER & CXER just give back the input.
283 CHECK_DECODE(bxer_dec_pres, input, preserver, expected);
284 CHECK_DECODE(cxer_dec_pres, input, preserver, expected);
285
286 // EXER brings WHITESPACE REPLACE to life.
287 expected := hello;
288 CHECK_DECODE(exer_dec_pres, input, preserver, expected);
289
290 // When the input does not end in whitespace, the behavior is the same.
291 tmp := bxer_enc_pres(hello & "!");
292 input := fromUTF8(tmp);
293 CHECK_DECODE(bxer_dec_pres, input, preserver, hello & "!");
294 CHECK_DECODE(cxer_dec_pres, input, preserver, hello & "!");
295 expected := hello & "!";
296 CHECK_DECODE(exer_dec_pres, input, preserver, expected);
297}
298
299testcase dec_whitespace_replace() runs on Snow
300{
301 var charstring expected := hello;
302 // Encode the string to produce the input for the decoder.
303 // (WHITESPACE applies no change on Titan's XER *encoder* )
304 var octetstring tmp := bxer_enc_rpl(hello);
305 var universal charstring input := fromUTF8(tmp);
306
307 // BXER & CXER just give back the input.
308 CHECK_DECODE(bxer_dec_rpl, input, replacer, expected);
309 CHECK_DECODE(cxer_dec_rpl, input, replacer, expected);
310
311 // EXER brings WHITESPACE REPLACE to life.
312 expected := flathello;
313 CHECK_DECODE(exer_dec_rpl, input, replacer, expected);
314
315 // When the input does not end in whitespace, the behavior is the same.
316 tmp := bxer_enc_rpl(hello & "!");
317 input := fromUTF8(tmp);
318 CHECK_DECODE(bxer_dec_rpl, input, replacer, hello & "!");
319 CHECK_DECODE(cxer_dec_rpl, input, replacer, hello & "!");
320 expected := flathello & "!";
321 CHECK_DECODE(exer_dec_rpl, input, replacer, expected);
322}
323
324testcase dec_whitespace_collapse() runs on Snow
325{
326 var charstring expected := hello;
327 // Encode the string to produce the input for the decoder.
328 var octetstring tmp := bxer_enc_col(hello);
329 var universal charstring input := fromUTF8(tmp);
330
331 // BXER & CXER just give back the input.
332 CHECK_DECODE(bxer_dec_col, input, collapser, expected);
333 CHECK_DECODE(cxer_dec_col, input, collapser, expected);
334
335 // WHITESPACE COLLAPSE makes all the whitespace at the end disappear.
336 expected := smallhello;
337 CHECK_DECODE(exer_dec_col, input, collapser, expected);
338
339 input := fromUTF8( bxer_enc_col(hello & "!") );
340 // Now the input does not end in whitespace. Nothing exciting from BXER/CXER.
341 CHECK_DECODE(bxer_dec_col, input, replacer, hello & "!");
342 CHECK_DECODE(cxer_dec_col, input, replacer, hello & "!");
343 // WHITESPACE COLLAPSE transforms whitespace in the middle into a single space.
344 // Note that we append a space before the exclamation mark.
345 // This space is the output from all that whitespace in the input.
346 expected := smallhello & " !";
347 CHECK_DECODE(exer_dec_col, input, collapser, expected);
348}
349
350
351DECLARE_XER_ENCODERS(upreserver, upres)
352DECLARE_EXER_ENCODERS(upreserver, upres)
353
354DECLARE_XER_ENCODERS(ureplacer, urpl)
355DECLARE_EXER_ENCODERS(ureplacer, urpl)
356
357DECLARE_XER_ENCODERS(ucollapser, ucol)
358DECLARE_EXER_ENCODERS(ucollapser, ucol)
359
360// These strings check that characters with cell values of 9, 13 or 32
361// (but different plane,group,row values) are not accidentally identified
362// as HORIZONTAL TAB, CARRIAGE RETURN or SPACE.
363
364const universal charstring tricky :=
365" \t " & char(0,1,2,9) & char(0,1,2,13) & char(0,1,2,32) & "\t\t\tThe end\t\n\n";
366
367const universal charstring flat_tricky :=
368" " & char(0,1,2,9) & char(0,1,2,13) & char(0,1,2,32) & " The end ";
369
370const universal charstring small_tricky :=
371char(0,1,2,9) & char(0,1,2,13) & char(0,1,2,32) & " The end";
372
373testcase dec_whitespace_upreserve() runs on Snow
374{
375 var universal charstring expected := hello;
376 var universal charstring input := fromUTF8( bxer_enc_upres(hello) );
377
378 CHECK_DECODE(bxer_dec_upres, input, upreserver, expected);
379 CHECK_DECODE(cxer_dec_upres, input, upreserver, expected);
380
381 expected := hello;
382 CHECK_DECODE(exer_dec_upres, input, upreserver, expected);
383
384 input := fromUTF8( bxer_enc_upres(tricky) );
385 expected := tricky;
386 CHECK_DECODE(exer_dec_upres, input, upreserver, expected);
387
388 input := fromUTF8( bxer_enc_upres(tricky & "!") );
389 expected := tricky & "!";
390 CHECK_DECODE(exer_dec_upres, input, upreserver, expected);
391
392}
393
394testcase dec_whitespace_ureplace() runs on Snow
395{
396 var universal charstring expected := hello;
397 var universal charstring input := fromUTF8( bxer_enc_urpl(hello) );
398
399 CHECK_DECODE(bxer_dec_urpl, input, ureplacer, expected);
400 CHECK_DECODE(cxer_dec_urpl, input, ureplacer, expected);
401
402 expected := flathello;
403 CHECK_DECODE(exer_dec_urpl, input, ureplacer, expected);
404
405 input := fromUTF8( bxer_enc_urpl(tricky) );
406 expected := flat_tricky;
407 CHECK_DECODE(exer_dec_urpl, input, ureplacer, expected);
408
409 input := fromUTF8( bxer_enc_urpl(tricky & "!") );
410 expected := flat_tricky & "!";
411 CHECK_DECODE(exer_dec_urpl, input, ureplacer, expected);
412
413}
414
415testcase dec_whitespace_ucollapse() runs on Snow
416{
417 var universal charstring expected := hello;
418 var universal charstring input := fromUTF8( bxer_enc_ucol(hello) );
419
420 CHECK_DECODE(bxer_dec_ucol, input, ucollapser, expected);
421 CHECK_DECODE(cxer_dec_ucol, input, ucollapser, expected);
422
423 expected := smallhello;
424 CHECK_DECODE(exer_dec_ucol, input, ucollapser, expected);
425
426 input := fromUTF8( bxer_enc_ucol(tricky) );
427 expected := small_tricky;
428 CHECK_DECODE(exer_dec_ucol, input, ucollapser, expected);
429
430 input := fromUTF8( bxer_enc_ucol(tricky & "!") );
431 expected := small_tricky & " !";
432 // whitespace is no longer at the end, it is collapsed instead of being eliminated
433 // Note: a space, then '!'
434 CHECK_DECODE(exer_dec_ucol, input, ucollapser, expected);
435
436 input := fromUTF8( bxer_enc_ucol("?" & tricky) );
437 expected := "? " & small_tricky;
438 // whitespace is no longer at the beginning, it is collapsed instead of being eliminated
439 // Note: '?', then a spaec
440 CHECK_DECODE(exer_dec_ucol, input, ucollapser, expected);
441}
442
443
444control {
445 execute(dec_whitespace_preserve())
446 execute(dec_whitespace_replace())
447 execute(dec_whitespace_collapse())
448
449 execute(dec_whitespace_upreserve())
450 execute(dec_whitespace_ureplace())
451 execute(dec_whitespace_ucollapse())
452}
453
454}
455with {
456encode "XER"
457}
This page took 0.04154 seconds and 5 git commands to generate.