Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / XML / XER / Txerbinstr.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 Txerbinstr {
9
10modulepar boolean Txerbinstr_verbose := false;
11#define verbose Txerbinstr_verbose
12
13#include "../macros.ttcnin"
14type component Binstr {}
15
16
17type octetstring oct64
18with {
19 variant "XSD:base64Binary"
20}
21
22type record r_ostr {
23 octetstring s
24}
25
26type union u_ostr {
27 octetstring s
28}
29
30type record of oct64 rof_ostr
31
32DECLARE_XER_ENCODERS (oct64, ostr);
33DECLARE_EXER_ENCODERS(oct64, ostr);
34DECLARE_XER_ENCODERS (r_ostr, rostr);
35DECLARE_EXER_ENCODERS(r_ostr, rostr);
36DECLARE_XER_ENCODERS (u_ostr, uostr);
37DECLARE_EXER_ENCODERS(u_ostr, uostr);
38DECLARE_XER_ENCODERS (rof_ostr, rofostr);
39DECLARE_EXER_ENCODERS(rof_ostr, rofostr);
40
41const octetstring babe := 'BABEFACE'O
42const universal charstring xer_babe := "<oct64>BABEFACE</oct64>\n"; // Basic XER ignores Base64
43const universal charstring exer_babe := "<oct64>ur76zg==</oct64>\n"
44const universal charstring plain_babe:= "BABEFACE";
45
46const oct64 rbabe := '040044140084'O
47
48testcase enc_ostr() runs on Binstr
49{
50 CHECK_METHOD(bxer_enc_ostr, babe, xer_babe);
51 CHECK_METHOD(exer_enc_ostr, babe, exer_babe);
52 //boring CHECK_METHOD(bxer_enc_ostr, rbabe, plain_babe);
53 CHECK_METHOD(exer_enc_ostr, rbabe, xer_babe);
54}
55
56testcase dec_ostr() runs on Binstr
57{
58 CHECK_DECODE(bxer_dec_ostr, xer_babe, octetstring, babe);
59 CHECK_DECODE(exer_dec_ostr, exer_babe, octetstring, babe);
60 //CHECK_DECODE(exer_enc_ostr,plain_babe, octetstring, rbabe);
61}
62
63//TODO r_ostr
64//TODO u_ostr
65
66const rof_ostr strings := {
67 char2oct("pleasure."),
68 char2oct("leasure."),
69 char2oct("easure."),
70 char2oct("asure."),
71 char2oct("sure."),
72 char2oct("ure."),
73 char2oct("re."),
74 char2oct("e."),
75 char2oct("."),
76 char2oct("")
77}
78
79const integer numstrings := lengthof(strings)
80
81const universal charstring base64s[numstrings] := {
82 "<oct64>cGxlYXN1cmUu</oct64>\n", // encoded values from the Wikipedia page
83 "<oct64>bGVhc3VyZS4=</oct64>\n", // of Base64
84 "<oct64>ZWFzdXJlLg==</oct64>\n",
85 "<oct64>YXN1cmUu</oct64>\n",
86 "<oct64>c3VyZS4=</oct64>\n",
87 "<oct64>dXJlLg==</oct64>\n",
88 "<oct64>cmUu</oct64>\n",
89 "<oct64>ZS4=</oct64>\n",
90 "<oct64>Lg==</oct64>\n",
91 "<oct64/>\n"
92}
93
94testcase enc_rof_ostr() runs on Binstr
95{
96 var universal charstring everything := "<rof_ostr>\n";
97
98 for (var integer i := 0; i < numstrings; i := i + 1) {
99 //CHECK_METHOD(bxer_enc_ostr, strings[i], base64s[i]);
100
101 CHECK_METHOD(exer_enc_ostr, strings[i], base64s[i]);
102 // test encoding of individual strings
103
104 everything := everything & "\t" & base64s[i];
105 // also prepare the test string for the entire record-of
106 }
107 everything := everything & "</rof_ostr>\n\n";
108
109 CHECK_METHOD(exer_enc_rofostr, strings, everything);
110}
111
112testcase dec_rof_ostr() runs on Binstr
113{
114 var universal charstring everything := "<rof_ostr>\n";
115
116 for (var integer i := 0; i < numstrings; i := i + 1) {
117 //CHECK_METHOD(bxer_enc_ostr, strings[i], base64s[i]);
118
119 CHECK_DECODE(exer_dec_ostr, base64s[i], octetstring, strings[i]);
120 // test encoding of individual strings
121
122 everything := everything & "\t" & base64s[i];
123 // also prepare the test string for the entire record-of
124 }
125 everything := everything & "</rof_ostr>\n\n";
126
127 CHECK_DECODE(exer_dec_rofostr, everything, rof_ostr, strings);
128}
129
130// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
131
132type hexstring hex64
133with {
134 variant "XSD:base64Binary"
135}
136
137type record r_hstr {
138 hexstring h
139}
140
141type union u_hstr {
142 hexstring h
143}
144
145type record of hex64 rof_hstr
146
147DECLARE_XER_ENCODERS (hex64, hstr);
148DECLARE_EXER_ENCODERS(hex64, hstr);
149DECLARE_XER_ENCODERS (r_hstr, rhstr);
150DECLARE_EXER_ENCODERS(r_hstr, rhstr);
151DECLARE_XER_ENCODERS (u_hstr, uhstr);
152DECLARE_EXER_ENCODERS(u_hstr, uhstr);
153DECLARE_XER_ENCODERS (rof_hstr, rofhstr);
154DECLARE_EXER_ENCODERS(rof_hstr, rofhstr);
155
156const hexstring coffee := 'DECAFBAD'H
157const universal charstring xer_coffee := "<hex64>DECAFBAD</hex64>\n";
158const universal charstring exer_coffee := "<hex64>3sr7rQ==</hex64>\n"
159
160testcase enc_hstr() runs on Binstr
161{
162 CHECK_METHOD(bxer_enc_hstr, coffee, xer_coffee);
163 CHECK_METHOD(exer_enc_hstr, coffee, exer_coffee);
164}
165
166testcase dec_hstr() runs on Binstr
167{
168 CHECK_DECODE(bxer_dec_hstr, xer_coffee, hexstring, coffee);
169 CHECK_DECODE(exer_dec_hstr, exer_coffee, hexstring, coffee);
170}
171
172//TODO r_hstr
173//TODO u_hstr
174
175const rof_hstr hstrings := {
176 oct2hex(char2oct("pleasure.")),
177 oct2hex(char2oct("leasure.")),
178 oct2hex(char2oct("easure.")),
179 oct2hex(char2oct("asure.")),
180 oct2hex(char2oct("sure.")),
181 oct2hex(char2oct("ure.")),
182 oct2hex(char2oct("re.")),
183 oct2hex(char2oct("e.")),
184 oct2hex(char2oct(".")),
185 oct2hex(char2oct(""))
186}
187
188const integer numhstrings := lengthof(hstrings)
189
190const universal charstring base64hs[numstrings] := {
191 "<hex64>cGxlYXN1cmUu</hex64>\n", // encoded values from the Wikipedia page
192 "<hex64>bGVhc3VyZS4=</hex64>\n", // of Base64
193 "<hex64>ZWFzdXJlLg==</hex64>\n",
194 "<hex64>YXN1cmUu</hex64>\n",
195 "<hex64>c3VyZS4=</hex64>\n",
196 "<hex64>dXJlLg==</hex64>\n",
197 "<hex64>cmUu</hex64>\n",
198 "<hex64>ZS4=</hex64>\n",
199 "<hex64>Lg==</hex64>\n",
200 "<hex64/>\n"
201}
202
203testcase enc_rof_hstr() runs on Binstr
204{
205 var universal charstring everything := "<rof_hstr>\n";
206
207 for (var integer i := 0; i < numhstrings; i := i + 1) {
208 //CHECK_METHOD(bxer_enc_hstr, strings[i], base64s[i]);
209
210 CHECK_METHOD(exer_enc_hstr, hstrings[i], base64hs[i]);
211 // test encoding of individual strings
212
213 everything := everything & "\t" & base64hs[i];
214 // also prepare the test string for the entire record-of
215 }
216 everything := everything & "</rof_hstr>\n\n";
217
218 CHECK_METHOD(exer_enc_rofhstr, hstrings, everything);
219
220}
221
222testcase dec_rof_hstr() runs on Binstr
223{
224 var universal charstring everything := "<rof_hstr>\n";
225
226 for (var integer i := 0; i < numhstrings; i := i + 1) {
227 //CHECK_METHOD(bxer_enc_hstr, strings[i], base64s[i]);
228
229 CHECK_DECODE(exer_dec_hstr, base64hs[i], hexstring, hstrings[i]);
230 // test encoding of individual strings
231
232 everything := everything & "\t" & base64hs[i];
233 // also prepare the test string for the entire record-of
234 }
235 everything := everything & "</rof_hstr>\n\n";
236
237 CHECK_DECODE(exer_dec_rofhstr, everything, rof_hstr, hstrings);
238}
239
240// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
241
242control
243{
244 execute(enc_ostr());
245 execute(dec_ostr());
246
247 execute(enc_rof_ostr());
248 execute(dec_rof_ostr());
249
250 execute(enc_hstr());
251 execute(dec_hstr());
252
253 execute(enc_rof_hstr());
254 execute(dec_rof_hstr());
255}
256
257
258}
259with {
260 encode "XML"
261 extension "version R99999A";
262}
This page took 0.04778 seconds and 5 git commands to generate.