Commit | Line | Data |
---|---|---|
970ed795 EL |
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 | ******************************************************************************/ | |
8 | module Txerstring { | |
9 | ||
10 | modulepar boolean Txerstring_verbose := false; | |
11 | #define verbose Txerstring_verbose | |
12 | ||
13 | #include "../macros.ttcnin" | |
14 | ||
15 | import from AsnValues all; | |
16 | external function flatten(inout universal charstring par) ; | |
17 | ||
18 | DECLARE_XER_ENCODERS( charstring,string); | |
19 | DECLARE_EXER_ENCODERS(charstring,string) | |
20 | DECLARE_XER_ENCODERS( rstring, rstring); | |
21 | DECLARE_EXER_ENCODERS( rstring, rstring); | |
22 | DECLARE_XER_ENCODERS( ustring, ustring); | |
23 | DECLARE_EXER_ENCODERS( ustring, ustring); | |
24 | ||
25 | type component Tstring{} | |
26 | ||
27 | type record rstring { | |
28 | charstring s optional | |
29 | } | |
30 | ||
31 | type union ustring { | |
32 | charstring s | |
33 | } | |
34 | ||
35 | function test_escape(in charstring source, in charstring escaped) | |
36 | { | |
37 | var universal charstring expected := "<CHARSTRING>" & escaped & "</CHARSTRING>\n"; | |
38 | CHECK_METHOD(cxer_enc_string, source, expected); | |
39 | CHECK_METHOD(bxer_enc_string, source, expected & lf); | |
40 | CHECK_METHOD(exer_enc_string, source, expected & lf); | |
41 | } | |
42 | ||
43 | testcase encode_string_plain() runs on Tstring | |
44 | { | |
45 | var charstring plain := "Foo"; | |
46 | var universal charstring expected := "<CHARSTRING>Foo</CHARSTRING>\n"; | |
47 | CHECK_METHOD(cxer_enc_string, plain, expected); | |
48 | CHECK_METHOD(bxer_enc_string, plain, expected & lf); | |
49 | CHECK_METHOD(exer_enc_string, plain, expected & lf); | |
50 | ||
51 | plain := "Vaettir"; // this was meant to use æ | |
52 | expected := "<CHARSTRING>Vaettir</CHARSTRING>\n"; | |
53 | CHECK_METHOD(cxer_enc_string, plain, expected); | |
54 | CHECK_METHOD(bxer_enc_string, plain, expected & lf); | |
55 | CHECK_METHOD(exer_enc_string, plain, expected & lf); | |
56 | } | |
57 | ||
58 | testcase encode_string_escapes() runs on Tstring | |
59 | { | |
60 | var charstring left := "<"; | |
61 | var charstring html_escaped := "<"; | |
62 | test_escape(left, html_escaped); | |
63 | ||
64 | left := "<html"; | |
65 | html_escaped := "<html"; | |
66 | test_escape(left, html_escaped); | |
67 | ||
68 | left := left & ">"; | |
69 | html_escaped := "<html>"; | |
70 | test_escape(left, html_escaped); | |
71 | ||
72 | left := html_escaped; // "double-escaping" | |
73 | html_escaped := "&lt;html&gt;"; | |
74 | test_escape(left, html_escaped); | |
75 | } | |
76 | ||
77 | testcase encode_string_empty() runs on Tstring | |
78 | { | |
79 | var charstring empty := ""; | |
80 | var universal charstring expected := "<CHARSTRING/>\n"; | |
81 | CHECK_METHOD(cxer_enc_string, empty, expected); | |
82 | CHECK_METHOD(bxer_enc_string, empty, expected & lf); | |
83 | CHECK_METHOD(exer_enc_string, empty, expected & lf); | |
84 | ||
85 | var rstring rec; | |
86 | rec.s := omit; | |
87 | ||
88 | expected := "<rstring/>\n\n"; | |
89 | var octetstring bytes; | |
90 | bytes := bxer_enc_rstring(rec); | |
91 | var universal charstring result; | |
92 | var integer rv := o2u("UTF-8", bytes, result); | |
93 | COMPARE(result, expected); | |
94 | ||
95 | bytes := cxer_enc_rstring(rec); | |
96 | rv := o2u("UTF-8", bytes, result); | |
97 | flatten(expected); | |
98 | COMPARE(result, expected & lf); | |
99 | ||
100 | rec.s := "Foo"; | |
101 | expected := "<rstring>\n\t<s>Foo</s>\n</rstring>\n\n"; | |
102 | ||
103 | bytes := bxer_enc_rstring(rec); | |
104 | var universal charstring foo; | |
105 | rv := o2u("UTF-8", bytes, foo); | |
106 | COMPARE(foo, expected); | |
107 | flatten(expected); | |
108 | bytes := cxer_enc_rstring(rec); | |
109 | rv := o2u("UTF-8", bytes, foo); | |
110 | COMPARE(foo, expected & lf); | |
111 | } | |
112 | ||
113 | //testcase encode_string_plain() runs on Tstring | |
114 | //{} | |
115 | ||
116 | const charstring us0 := "<ustring>\n\t<s/>\n</ustring>\n\n"; | |
117 | ||
118 | testcase encode_string_choice() runs on Tstring | |
119 | { | |
120 | var ustring rec := { s := "" } | |
121 | var universal charstring expected; | |
122 | ||
123 | expected := us0; | |
124 | CHECK_METHOD(bxer_enc_ustring, rec, expected); | |
125 | CHECK_METHOD(exer_enc_ustring, rec, expected); | |
126 | flatten(expected); | |
127 | CHECK_METHOD(cxer_enc_ustring, rec, expected & lf); | |
128 | ||
129 | rec.s := "Hello!"; // not omit anymore | |
130 | expected := "<ustring>\n\t<s>Hello!</s>\n</ustring>\n\n"; | |
131 | CHECK_METHOD(bxer_enc_ustring, rec, expected); | |
132 | CHECK_METHOD(exer_enc_ustring, rec, expected); | |
133 | flatten(expected); | |
134 | CHECK_METHOD(cxer_enc_ustring, rec, expected & lf); | |
135 | } | |
136 | ||
137 | ||
138 | ||
139 | control { | |
140 | execute( encode_string_plain() ); | |
141 | execute( encode_string_escapes() ); | |
142 | execute( encode_string_empty() ); | |
143 | execute( encode_string_choice() ); | |
144 | } | |
145 | ||
146 | } | |
147 | with { | |
148 | encode "XML" | |
149 | extension "version R8Z" | |
150 | } |