implemented decmatch (artf724241)
[deliverable/titan.core.git] / regression_test / templateUnicharstr / TtemplateUnicharstr.ttcn
1 /******************************************************************************
2 * Copyright (c) 2000-2016 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 * Contributors:
9 * Baranyi, Botond – initial implementation
10 *
11 ******************************************************************************/
12 module TtemplateUnicharstr {
13
14 type component templateUnicharstr_mycomp {};
15 type record templateUnicharstr_rec {
16 universal charstring x1,
17 universal charstring x2,
18 universal charstring x3 optional
19 }
20 with {
21 encode "JSON";
22 variant(x1) "JSON: name as first";
23 variant(x2) "JSON: name as second";
24 variant(x3) "JSON: name as third";
25 }
26
27 type record decmatch_rec {
28 integer i,
29 charstring s
30 }
31 with {
32 encode "JSON";
33 }
34
35 type record of integer decmatch_list
36 with {
37 encode "XML";
38 variant "list";
39 }
40
41 type union decmatch_uni {
42 integer i,
43 charstring s
44 }
45 with {
46 encode "RAW";
47 variant(i) "FIELDLENGTH(16)";
48 }
49
50 type octetstring OS
51 with {
52 encode "RAW";
53 }
54
55
56 template decmatch_uni decmatch_tUnion := { i := ? };
57
58 template decmatch_rec decmatch_tRecord := { i := (0..infinity), s := ? };
59
60 template templateUnicharstr_rec templateUnicharstr_tDecmatch := { // decoded content match
61 x1 := decmatch decmatch_list: { (1..10), (11..20), (21..30) }, // no format parameter = UTF-8
62 x2 := decmatch decmatch_tUnion,
63 x3 := decmatch modifies decmatch_tRecord := { s := "abc" }
64 };
65
66 template templateUnicharstr_rec templateUnicharstr_tDecmatchSelfRef := { // decoded content match with self-reference
67 x1 := "a",
68 x2 := decmatch("UTF-8") templateUnicharstr_tDecmatchSelfRef.x1,
69 x3 := decmatch("UTF-8") templateUnicharstr_rec: { x1 := templateUnicharstr_tDecmatchSelfRef.x1, x2 := ?, x3 := * }
70 };
71
72 template templateUnicharstr_rec templateUnicharstr_tDecmatch16 := { // decoded content match in UTF-16 format
73 x1 := decmatch("UTF-16") OS: 'FEFF'O, // just the BOM
74 x2 := decmatch("UTF-16LE") OS: ? length (4..6), // BOM + 1-2 characters below FFFF or 1 character above FFFF
75 x3 := decmatch("UTF-16BE") OS: ? length (8..infinity) // BOM + 3 or more characters (2 or more if one of them is above FFFF)
76 };
77
78 template templateUnicharstr_rec templateUnicharstr_tDecmatch32 := { // decoded content match in UTF-32 format
79 x1 := decmatch("UTF-32") OS: '0000FEFF'O, // just the BOM
80 x2 := decmatch("UTF-32LE") OS: ? length (4..8), // BOM + 1 optional character
81 x3 := decmatch("UTF-32BE") OS: ? length (16..infinity) // BOM + 3 or more characters
82 };
83
84 template charstring templateUnicharstr_tCharDecmatch := decmatch decmatch_rec: { i := 1, s := ? };
85
86
87 testcase templateUnicharstrDecmatch() runs on templateUnicharstr_mycomp {
88 var decmatch_rec bad_rec, good_rec;
89 bad_rec := { i := 11, s := "xyz" };
90 good_rec := { i := 3, s := "abc" };
91 var decmatch_list bad_list, good_list;
92 bad_list := { 4, 7, 10 };
93 good_list := { 2, 15, 28 };
94 var decmatch_uni bad_uni, good_uni;
95 bad_uni := { s := "five" };
96 good_uni := { i := 5 };
97 var universal charstring bad_rec_enc, good_rec_enc, bad_list_enc, good_list_enc, bad_uni_enc, good_uni_enc;
98 bad_rec_enc := oct2unichar(bit2oct(encvalue(bad_rec)), "UTF-8");
99 good_rec_enc := oct2unichar(bit2oct(encvalue(good_rec)), "UTF-8");
100 bad_list_enc := oct2unichar(bit2oct(encvalue(bad_list)), "UTF-8");
101 good_list_enc := oct2unichar(bit2oct(encvalue(good_list)), "UTF-8");
102 bad_uni_enc := oct2unichar(bit2oct(encvalue(bad_uni)), "UTF-8");
103 good_uni_enc := oct2unichar(bit2oct(encvalue(good_uni)), "UTF-8");
104 var templateUnicharstr_rec r1, r2, r3, r4, r5;
105 r1 := { x1 := good_list_enc, x2 := good_uni_enc, x3 := good_rec_enc };
106 r2 := { x1 := bad_list_enc, x2 := good_uni_enc, x3 := good_rec_enc };
107 r3 := { x1 := good_list_enc, x2 := bad_uni_enc, x3 := good_rec_enc };
108 r4 := { x1 := good_list_enc, x2 := good_uni_enc, x3 := bad_rec_enc };
109 r5 := { x1 := good_list_enc, x2 := good_uni_enc, x3 := "xyz" };
110 // match: all 3 are good
111 if (match(r1, templateUnicharstr_tDecmatch)) { setverdict(pass); }
112 else { setverdict(fail, 1); }
113 // no match: decoded list does not match
114 if (not match(r2, templateUnicharstr_tDecmatch)) { setverdict(pass); }
115 else { setverdict(fail, 2); }
116 // no match: decoded union does not match
117 if (not match(r3, templateUnicharstr_tDecmatch)) { setverdict(pass); }
118 else { setverdict(fail, 3); }
119 // no match: decoded record does not match
120 if (not match(r4, templateUnicharstr_tDecmatch)) { setverdict(pass); }
121 else { setverdict(fail, 4); }
122 // no match: x3 is not a valid encoded record value
123 if (not match(r5, templateUnicharstr_tDecmatch)) { setverdict(pass); }
124 else { setverdict(fail, 5); }
125 // match r1 with the same template declared as an in-line template
126 if (match(r1, templateUnicharstr_rec: {
127 x1 := decmatch decmatch_list: { (1..10), (11..20), (21..30) },
128 x2 := decmatch decmatch_tUnion,
129 x3 := decmatch modifies decmatch_tRecord := { s := "abc" }
130 })) { setverdict(pass); }
131 else { setverdict(fail, 6); }
132 }
133
134 external function ef_enc_rec_x1(in templateUnicharstr_rec.x1 x) return octetstring
135 with { extension "prototype(convert) encode(JSON)" }
136
137 testcase templateUnicharstrDecmatchSelfRef() runs on templateUnicharstr_mycomp {
138 // global self-referencing template
139 var templateUnicharstr_rec.x1 bad_ucs, good_ucs;
140 bad_ucs := char(0, 0, 1, 113);
141 good_ucs := "a";
142 var templateUnicharstr_rec bad_rec, good_rec;
143 bad_rec := { x1 := char(0, 0, 0, 255), x2 := char(0, 0, 1, 0), x3 := char(0, 0, 1, 1) };
144 good_rec := { x1 := "a", x2 := char(0, 0, 1, 0), x3 := char(0, 0, 1, 1) };
145 var universal charstring bad_ucs_enc, good_ucs_enc, bad_rec_enc, good_rec_enc;
146 bad_ucs_enc := oct2unichar(ef_enc_rec_x1(bad_ucs), "UTF-8");
147 good_ucs_enc := oct2unichar(ef_enc_rec_x1(good_ucs), "UTF-8");
148 bad_rec_enc := oct2unichar(bit2oct(encvalue(bad_rec)), "UTF-8");
149 good_rec_enc := oct2unichar(bit2oct(encvalue(good_rec)), "UTF-8");
150 var templateUnicharstr_rec r1, r2, r3;
151 r1 := { x1 := "a", x2 := good_ucs_enc, x3 := good_rec_enc };
152 r2 := { x1 := "a", x2 := bad_ucs_enc, x3 := good_rec_enc };
153 r3 := { x1 := "a", x2 := good_ucs_enc, x3 := bad_rec_enc };
154 // match: all 2 are good
155 if (match(r1, templateUnicharstr_tDecmatchSelfRef)) { setverdict(pass); }
156 else { setverdict(fail, 1); }
157 // no match: decoded octetstring does not match
158 if (not match(r2, templateUnicharstr_tDecmatchSelfRef)) { setverdict(pass); }
159 else { setverdict(fail, 2); }
160 // no match: decoded record does not match
161 if (not match(r3, templateUnicharstr_tDecmatchSelfRef)) { setverdict(pass); }
162 else { setverdict(fail, 3); }
163
164 // local self-referencing template
165 var template templateUnicharstr_rec t := { x1 := "a", x2 := ?, x3 := ? };
166 t.x1 := decmatch t;
167 var templateUnicharstr_rec r4, r5;
168 r4 := { x1 := good_rec_enc, x2 := "x", x3 := "y" };
169 r5 := { x1 := bad_rec_enc, x2 := "x", x3 := "y" };
170 if (match(r4, t)) { setverdict(pass); }
171 else { setverdict(fail, 4); }
172 if (not match(r5, t)) { setverdict(pass); }
173 else { setverdict(fail, 5); }
174 }
175
176 testcase templateUnicharstrDecmatch16() runs on templateUnicharstr_mycomp {
177 var universal charstring bad16, good16, bad16le, good16le, bad16be, good16be;
178 bad16 := "abc";
179 good16 := "";
180 bad16le := char(0, 1, 2, 3) & char(0, 4, 5, 6);
181 good16le := char(0, 1, 2, 3);
182 bad16be := char(0, 1, 10, 100);
183 good16be := "ab" & char(0, 1, 10, 100) & "xy";
184 var templateUnicharstr_rec r1, r2, r3, r4;
185 r1 := { x1 := good16, x2 := good16le, x3 := good16be };
186 r2 := { x1 := bad16, x2 := good16le, x3 := good16be };
187 r3 := { x1 := good16, x2 := bad16le, x3 := good16be };
188 r4 := { x1 := good16, x2 := good16le, x3 := bad16be };
189 // match: all 3 are good
190 if (match(r1, templateUnicharstr_tDecmatch16)) { setverdict(pass); }
191 else { setverdict(fail, 1); }
192 // no match: decoded string in UTF-16 format is not empty
193 if (not match(r2, templateUnicharstr_tDecmatch16)) { setverdict(pass); }
194 else { setverdict(fail, 2); }
195 // no match: decoded string in UTF-16LE format is too long
196 if (not match(r3, templateUnicharstr_tDecmatch16)) { setverdict(pass); }
197 else { setverdict(fail, 3); }
198 // no match: decoded string in UTF-16BE format is too short
199 if (not match(r4, templateUnicharstr_tDecmatch16)) { setverdict(pass); }
200 else { setverdict(fail, 4); }
201 }
202
203 testcase templateUnicharstrDecmatch32() runs on templateUnicharstr_mycomp {
204 var universal charstring bad32, good32, bad32le, good32le, bad32be, good32be;
205 bad32 := "abc";
206 good32 := "";
207 bad32le := char(0, 1, 2, 3) & char(0, 4, 5, 6);
208 good32le := char(0, 1, 2, 3);
209 bad32be := char(0, 1, 10, 100);
210 good32be := "ab" & char(0, 1, 10, 100) & "xy";
211 var templateUnicharstr_rec r1, r2, r3, r4;
212 r1 := { x1 := good32, x2 := good32le, x3 := good32be };
213 r2 := { x1 := bad32, x2 := good32le, x3 := good32be };
214 r3 := { x1 := good32, x2 := bad32le, x3 := good32be };
215 r4 := { x1 := good32, x2 := good32le, x3 := bad32be };
216 // match: all 3 are good
217 if (match(r1, templateUnicharstr_tDecmatch32)) { setverdict(pass); }
218 else { setverdict(fail, 1); }
219 // no match: decoded string in UTF-32 format is not empty
220 if (not match(r2, templateUnicharstr_tDecmatch32)) { setverdict(pass); }
221 else { setverdict(fail, 2); }
222 // no match: decoded string in UTF-32LE format is too long
223 if (not match(r3, templateUnicharstr_tDecmatch32)) { setverdict(pass); }
224 else { setverdict(fail, 3); }
225 // no match: decoded string in UTF-32BE format is too short
226 if (not match(r4, templateUnicharstr_tDecmatch32)) { setverdict(pass); }
227 else { setverdict(fail, 4); }
228 }
229
230 testcase templateUnicharstrDecmatchCopyCharstr() runs on templateUnicharstr_mycomp {
231 // testing a universal charstring template copied from a
232 // charstring template (with decoded content matching)
233 var template universal charstring t := templateUnicharstr_tCharDecmatch;
234 var decmatch_rec bad_rec, good_rec;
235 bad_rec := { i := 6, s := "xyz" };
236 good_rec := { i := 1, s := "abc" };
237 var universal charstring bad_rec_enc, good_rec_enc;
238 bad_rec_enc := oct2unichar(bit2oct(encvalue(bad_rec)), "UTF-8");
239 good_rec_enc := oct2unichar(bit2oct(encvalue(good_rec)), "UTF-8");
240 if (match(good_rec_enc, t)) { setverdict(pass); }
241 else { setverdict(fail, 1); }
242 if (not match(bad_rec_enc, t)) { setverdict(pass); }
243 else { setverdict(fail, 2); }
244 }
245
246 control {
247 execute(templateUnicharstrDecmatch());
248 execute(templateUnicharstrDecmatchSelfRef());
249 execute(templateUnicharstrDecmatch16());
250 execute(templateUnicharstrDecmatch32());
251 execute(templateUnicharstrDecmatchCopyCharstr());
252 }
253
254 }
This page took 0.035829 seconds and 5 git commands to generate.