1 /******************************************************************************
2 * Copyright (c) 2000-2015 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 ******************************************************************************/
10 modulepar boolean Txerstring_verbose := false;
11 #define verbose Txerstring_verbose
13 #include "../macros.ttcnin"
15 import from AsnValues all;
16 external function flatten(inout universal charstring par) ;
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);
25 type component Tstring{}
35 function test_escape(in charstring source, in charstring escaped)
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);
43 testcase encode_string_plain() runs on Tstring
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);
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);
58 testcase encode_string_escapes() runs on Tstring
60 var charstring left := "<";
61 var charstring html_escaped := "<";
62 test_escape(left, html_escaped);
65 html_escaped := "<html";
66 test_escape(left, html_escaped);
69 html_escaped := "<html>";
70 test_escape(left, html_escaped);
72 left := html_escaped; // "double-escaping"
73 html_escaped := "&lt;html&gt;";
74 test_escape(left, html_escaped);
77 testcase encode_string_empty() runs on Tstring
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);
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);
95 bytes := cxer_enc_rstring(rec);
96 rv := o2u("UTF-8", bytes, result);
98 COMPARE(result, expected & lf);
101 expected := "<rstring>\n\t<s>Foo</s>\n</rstring>\n\n";
103 bytes := bxer_enc_rstring(rec);
104 var universal charstring foo;
105 rv := o2u("UTF-8", bytes, foo);
106 COMPARE(foo, expected);
108 bytes := cxer_enc_rstring(rec);
109 rv := o2u("UTF-8", bytes, foo);
110 COMPARE(foo, expected & lf);
113 //testcase encode_string_plain() runs on Tstring
116 const charstring us0 := "<ustring>\n\t<s/>\n</ustring>\n\n";
118 testcase encode_string_choice() runs on Tstring
120 var ustring rec := { s := "" }
121 var universal charstring expected;
124 CHECK_METHOD(bxer_enc_ustring, rec, expected);
125 CHECK_METHOD(exer_enc_ustring, rec, expected);
127 CHECK_METHOD(cxer_enc_ustring, rec, expected & lf);
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);
134 CHECK_METHOD(cxer_enc_ustring, rec, expected & lf);
140 execute( encode_string_plain() );
141 execute( encode_string_escapes() );
142 execute( encode_string_empty() );
143 execute( encode_string_choice() );
149 extension "version R8Z"