File: TtemplateBitstr.ttcn

package info (click to toggle)
eclipse-titan 8.2.0-1
  • links: PTS
  • area: main
  • in suites: bookworm, sid
  • size: 103,544 kB
  • sloc: cpp: 271,008; ansic: 33,683; yacc: 23,419; makefile: 15,483; lex: 9,204; java: 4,848; perl: 4,555; sh: 2,242; xml: 1,378; javascript: 85; awk: 48; php: 32; python: 13
file content (540 lines) | stat: -rw-r--r-- 19,446 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
/******************************************************************************
 * Copyright (c) 2000-2021 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
 *
 * Contributors:
 *   Baranyi, Botond
 *   Balasko, Jeno
 *   Kovacs, Ferenc
 *   Raduly, Csaba
 *   Szabados, Kristof
 *   Szabo, Janos Zoltan – initial implementation
 *
 ******************************************************************************/
module TtemplateBitstr {
type component templateBitstr_mycomp {};
type record templateBitstr_rec {
 bitstring x1,
 bitstring x2,
 bitstring x3 optional
}
with {
  encode "JSON";
  variant(x1) "JSON: name as first";
  variant(x2) "JSON: name as second";
  variant(x3) "JSON: name as third";
}

type record decmatch_rec {
  integer i,
  charstring s
}
with {
  encode "JSON";
}

type record of integer decmatch_list
with {
  encode "XML";
  variant "list";
}

type union decmatch_uni {
  integer i,
  charstring s
}
with {
  encode "RAW";
  variant(i) "FIELDLENGTH(16)";
}


template templateBitstr_rec templateBitstr_tSpec :={ //specific values
 x1:='001'B,
 x2:='010'B,
 x3:='100'B };
template templateBitstr_rec templateBitstr_tList :={ //specific value and value list
 x1:='001'B,
 x2:=('010'B,'011'B,'1100'B),
 x3:='100'B };
template templateBitstr_rec templateBitstr_tComp :={ //specific value and compl. list
 x1:='001'B,
 x2:=complement ('11'B,'00'B,'1000'B),
 x3:='100'B };
template templateBitstr_rec templateBitstr_tOmit :={ //omitting values
 x1:='001'B,
 x2:='010'B,
 x3:=omit } ;
template templateBitstr_rec templateBitstr_tAny :={ //specific and any value
 x1:='001'B,
 x2:='010'B,
 x3:=? } ;
template templateBitstr_rec templateBitstr_tAnyorNone :={ //specific and AnyorNone value
 x1:='001'B,
 x2:='010'B,
 x3:=* };
template templateBitstr_rec templateBitstr_tLength1 :={ //specific value and fix length
 x1:='001'B,
 x2:='010'B,
 x3:=* length(3) };
template templateBitstr_rec templateBitstr_tLength2 :={ //specific value and length (range)
 x1:='001'B,
 x2:='010'B,
 x3:=? length(2..4) };
template templateBitstr_rec templateBitstr_tLength3 :={ //specific value and length (range, infinity)
 x1:='001'B,
 x2:='010'B,
 x3:=? length(2..infinity) };
template templateBitstr_rec templateBitstr_tIfpresent :={ //specific value and ifpresent
 x1:='001'B,
 x2:='010'B,
 x3:='100'B ifpresent };
template templateBitstr_rec templateBitstr_tLengthIfp :={ //specific value and fix length and ifpresent
 x1:='001'B,
 x2:='010'B,
 x3:= ? length(3) ifpresent};
template templateBitstr_rec templateBitstr_tAnyEl :={ //specific value and any element inside value
 x1:='001'B,
 x2:='010'B,
 x3:='10?'B } ;
template templateBitstr_rec templateBitstr_tAnyorNoneEl :={ //specific value and Any number of elements or none inside value
 x1:='001'B,
 x2:='010'B,
 x3:='10*'B };

 template bitstring t_param1(templateBitstr_rec par) := substr(par.x1, 0, 1); // parameterised template
 
template decmatch_uni decmatch_tUnion := { i := ? };

template decmatch_rec decmatch_tRecord := { i := (0..infinity), s := ? };

template templateBitstr_rec templateBitstr_tDecmatch := { // decoded content match
  x1 := decmatch decmatch_list: { (1..10), (11..20), (21..30) },
  x2 := decmatch decmatch_tUnion,
  x3 := decmatch modifies decmatch_tRecord := { s := "abc" }
};

template templateBitstr_rec templateBitstr_tDecmatchSelfRef := { // decoded content match with self-reference
  x1 := '1011'B,
  x2 := decmatch templateBitstr_tDecmatchSelfRef.x1,
  x3 := decmatch templateBitstr_rec: { x1 := templateBitstr_tDecmatchSelfRef.x1, x2 := ?, x3 := * }
};

testcase templateBitstrSpec() runs on templateBitstr_mycomp {
var templateBitstr_rec x1,x2;		//specific value
x1:={ x1:='001'B,  x2:='010'B,  x3:='100'B };
x2:={ x1:='00'B,  x2:='010'B,  x3:='100'B };
//match
if (match(x1,templateBitstr_tSpec)) {setverdict(pass);}
 else {setverdict(fail);}
//no match
if (not(match(x2,templateBitstr_tSpec))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBitstrList() runs on templateBitstr_mycomp {
var templateBitstr_rec x1,x2,x3;		//value list
x1:={ x1:='001'B,  x2:='010'B,  x3:='100'B };
x2:={ x1:='001'B,  x2:='00'B,  x3:='100'B };
x3:={ x1:='1'B,  x2:='010'B,  x3:='100'B };
//match
if (match(x1,templateBitstr_tList)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: out of list
if (not(match(x2,templateBitstr_tList))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateBitstr_tList))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBitstrComp() runs on templateBitstr_mycomp {
var templateBitstr_rec x1,x2,x3;		//complemented list
x1:={ x1:='001'B,  x2:='010'B,  x3:='100'B };
x2:={ x1:='001'B,  x2:='11'B,  x3:='100'B };
x3:={ x1:='11'B,  x2:='010'B,  x3:='100'B };
//match
if (match(x1,templateBitstr_tComp)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: in the list
if (not(match(x2,templateBitstr_tComp))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateBitstr_tComp))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBitstrOmit() runs on templateBitstr_mycomp {
var templateBitstr_rec x1,x2,x3;		//omitting value
x1:={ x1:='001'B,  x2:='010'B,  x3:=omit };
x2:={ x1:='001'B,  x2:='010'B,  x3:='000'B };
x3:={ x1:='00'B,  x2:='010'B,  x3:=omit };
//match
if (match(x1,templateBitstr_tOmit)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: not omitted
if (not(match(x2,templateBitstr_tOmit))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateBitstr_tOmit))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBitstrAny() runs on templateBitstr_mycomp {
var templateBitstr_rec x1,x2,x3;		//any value
x1:={ x1:='001'B,  x2:='010'B,  x3:='111'B };
x2:={ x1:='001'B,  x2:='010'B,  x3:=omit };
x3:={ x1:='0'B,  x2:='010'B,  x3:='10'B };
//match
if (match(x1,templateBitstr_tAny)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: field omitted
if (not(match(x2,templateBitstr_tAny))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateBitstr_tAny))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBitstrAnyorNone() runs on templateBitstr_mycomp {
var templateBitstr_rec x1,x2,x3;		//AnyorNone value
x1:={ x1:='001'B,  x2:='010'B,  x3:=omit };
x2:={ x1:='001'B,  x2:='010'B,  x3:='100'B };
x3:={ x1:='1'B,  x2:='010'B,  x3:=omit };
//match: omitted
if (match(x1,templateBitstr_tAnyorNone)) {setverdict(pass);}
 else {setverdict(fail);}
//match: value
if (match(x2,templateBitstr_tAnyorNone)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateBitstr_tAnyorNone))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBitstrLength1() runs on templateBitstr_mycomp {
var templateBitstr_rec x1,x2,x3,x4;		//length (fix)
x1:={ x1:='001'B,  x2:='010'B,  x3:='111'B };
x2:={ x1:='001'B,  x2:='010'B,  x3:=omit };
x3:={ x1:='001'B,  x2:='010'B,  x3:='10'B };
x4:={ x1:='0010'B,  x2:='010'B,  x3:='111'B };
//match: proper length
if (match(x1,templateBitstr_tLength1)) {setverdict(pass);}
 else {setverdict(fail);}
//match: omitted
if (match(x2,templateBitstr_tLength1)) {setverdict(pass);}
 else {setverdict(fail);}
// no match: not proper length
if (not(match(x3,templateBitstr_tLength1))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x4,templateBitstr_tLength1))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBitstrLength2() runs on templateBitstr_mycomp {
var templateBitstr_rec x1,x2,x3;		//length (range)
x1:={ x1:='001'B,  x2:='010'B,  x3:='111'B };
x2:={ x1:='001'B,  x2:='010'B,  x3:='1'B };
x3:={ x1:='0010'B,  x2:='010'B,  x3:='111'B };
//match
if (match(x1,templateBitstr_tLength2)) {setverdict(pass);}
 else {setverdict(fail);}
// no match: not proper length
if (not(match(x2,templateBitstr_tLength2))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateBitstr_tLength2))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBitstrLength3() runs on templateBitstr_mycomp {
var templateBitstr_rec x1,x2,x3;		//length (range, infinity)
x1:={ x1:='001'B,  x2:='010'B,  x3:='111'B };
x2:={ x1:='001'B,  x2:='010'B,  x3:='1'B };
x3:={ x1:='0010'B,  x2:='010'B,  x3:='111'B };
//match
if (match(x1,templateBitstr_tLength3)) {setverdict(pass);}
 else {setverdict(fail);}
// no match: not proper length
if (not(match(x2,templateBitstr_tLength3))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateBitstr_tLength3))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBitstrIfpresent() runs on templateBitstr_mycomp {
var templateBitstr_rec x1,x2,x3,x4;		//ifpresent
x1:={ x1:='001'B,  x2:='010'B,  x3:='100'B };
x2:={ x1:='001'B,  x2:='010'B,  x3:=omit };
x3:={ x1:='001'B,  x2:='010'B,  x3:='000'B };
x4:={ x1:='00'B,  x2:='010'B,  x3:=omit };
//match: present and match
if (match(x1,templateBitstr_tIfpresent)) {setverdict(pass);}
 else {setverdict(fail);}
//match: not present
if (match(x2,templateBitstr_tIfpresent)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: present and not match
if (not(match(x3,templateBitstr_tIfpresent))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x4,templateBitstr_tIfpresent))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBitstrLengthIfp() runs on templateBitstr_mycomp {
var templateBitstr_rec x1,x2,x3,x4;	      //length (fix), ifpresent
x1:={ x1:='001'B,  x2:='010'B,  x3:='111'B };
x2:={ x1:='001'B,  x2:='010'B,  x3:=omit };
x3:={ x1:='001'B,  x2:='010'B,  x3:='10'B };
x4:={ x1:='0010'B,  x2:='010'B,  x3:='111'B };
//match: proper length
if (match(x1,templateBitstr_tLengthIfp)) {setverdict(pass);}
 else {setverdict(fail);}
//match: omitted
if (match(x2,templateBitstr_tLengthIfp)) {setverdict(pass);}
 else {setverdict(fail);}
// no match: not proper length
if (not(match(x3,templateBitstr_tLengthIfp))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x4,templateBitstr_tLengthIfp))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBitstrAnyEl() runs on templateBitstr_mycomp {
var templateBitstr_rec x1,x2,x3,x4,x5;  	      //any element
x1:={ x1:='001'B,  x2:='010'B,  x3:='101'B };
x2:={ x1:='001'B,  x2:='010'B,  x3:='10'B };
x3:={ x1:='001'B,  x2:='010'B,  x3:='1000'B };
x4:={ x1:='001'B,  x2:='010'B,  x3:='001'B };
x5:={ x1:='0'B,  x2:='010'B,  x3:='101'B };
//match
if (match(x1,templateBitstr_tAnyEl)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: no element
if (not(match(x2,templateBitstr_tAnyEl))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: two element
if (not(match(x3,templateBitstr_tAnyEl))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: wrong element
if (not(match(x4,templateBitstr_tAnyEl))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x5,templateBitstr_tAnyEl))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase templateBitstrAnyorNoneEl() runs on templateBitstr_mycomp {
var templateBitstr_rec x1,x2,x3,x4,x5;  	      //Any number of elements or none
x1:={ x1:='001'B,  x2:='010'B,  x3:='10'B };
x2:={ x1:='001'B,  x2:='010'B,  x3:='100'B };
x3:={ x1:='001'B,  x2:='010'B,  x3:='1011'B };
x4:={ x1:='001'B,  x2:='010'B,  x3:='110'B };
x5:={ x1:='1'B,  x2:='010'B,  x3:='100'B };
//match: no element
if (match(x1,templateBitstr_tAnyorNoneEl)) {setverdict(pass);}
 else {setverdict(fail);}
//match: one element
if (match(x2,templateBitstr_tAnyorNoneEl)) {setverdict(pass);}
 else {setverdict(fail);}
//match: two element
if (match(x3,templateBitstr_tAnyorNoneEl)) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other element
if (not(match(x4,templateBitstr_tAnyorNoneEl))) {setverdict(pass);}
 else {setverdict(fail);}
//no match: other field
if (not(match(x5,templateBitstr_tAnyorNoneEl))) {setverdict(pass);}
 else {setverdict(fail);}
}

testcase CR_TR00018474() runs on templateBitstr_mycomp {
  // Indexing of string template variables.
  var template bitstring vtb1 := '0011110000'B
  var template bitstring vtb2 := '0*?1'B  // It's a pattern, cannot be indexed, runtime error.
  vtb1[0] := '1'B
  if (match('1011110000'B, vtb1)) { setverdict(pass) } else { setverdict(fail) }
  vtb1[0] := '1'B  // Indexed assignment notation cannot be used here.
  vtb1[1] := '0'B  // Still works, nothing special.
  if (match('1011110000'B, vtb1)) { setverdict(pass) } else { setverdict(fail) }
}

testcase templateBitstrDecmatch() runs on templateBitstr_mycomp {
  var decmatch_rec bad_rec, good_rec;
  bad_rec := { i := 11, s := "xyz" };
  good_rec := { i := 3, s := "abc" };
  var decmatch_list bad_list, good_list;
  bad_list := { 4, 7, 10 };
  good_list := { 2, 15, 28 };
  var decmatch_uni bad_uni, good_uni;
  bad_uni := { s := "five" };
  good_uni := { i := 5 };
  var bitstring bad_rec_enc, good_rec_enc, bad_list_enc, good_list_enc, bad_uni_enc, good_uni_enc;
  bad_rec_enc := encvalue(bad_rec);
  good_rec_enc := encvalue(good_rec);
  bad_list_enc := encvalue(bad_list);
  good_list_enc := encvalue(good_list);
  bad_uni_enc := encvalue(bad_uni);
  good_uni_enc := encvalue(good_uni);
  var templateBitstr_rec r1, r2, r3, r4, r5;
  r1 := { x1 := good_list_enc, x2 := good_uni_enc, x3 := good_rec_enc };
  r2 := { x1 := bad_list_enc,  x2 := good_uni_enc, x3 := good_rec_enc };
  r3 := { x1 := good_list_enc, x2 := bad_uni_enc,  x3 := good_rec_enc };
  r4 := { x1 := good_list_enc, x2 := good_uni_enc, x3 := bad_rec_enc  };
  r5 := { x1 := good_list_enc, x2 := good_uni_enc, x3 := '11110011'B  };
  // match: all 3 are good
  if (match(r1, templateBitstr_tDecmatch)) { setverdict(pass); }
  else { setverdict(fail, 1); }
  // no match: decoded list does not match
  if (not match(r2, templateBitstr_tDecmatch)) { setverdict(pass); }
  else { setverdict(fail, 2); }
  // no match: decoded union does not match
  if (not match(r3, templateBitstr_tDecmatch)) { setverdict(pass); }
  else { setverdict(fail, 3); }
  // no match: decoded record does not match
  if (not match(r4, templateBitstr_tDecmatch)) { setverdict(pass); }
  else { setverdict(fail, 4); }
  // no match: x3 is not a valid encoded record value
  if (not match(r5, templateBitstr_tDecmatch)) { setverdict(pass); }
  else { setverdict(fail, 5); }
  // match r1 with the same template declared as an in-line template
  if (match(r1, templateBitstr_rec: {
    x1 := decmatch decmatch_list: { (1..10), (11..20), (21..30) },
    x2 := decmatch decmatch_tUnion,
    x3 := decmatch modifies decmatch_tRecord := { s := "abc" }
  })) { setverdict(pass); }
  else { setverdict(fail, 6); }
}

external function ef_enc_rec_x1(in templateBitstr_rec.x1 x) return octetstring
with { extension "prototype(convert) encode(JSON)" }

testcase templateBitstrDecmatchSelfRef() runs on templateBitstr_mycomp {
  // global self-referencing template
  var templateBitstr_rec.x1 bad_bs, good_bs;
  bad_bs := '11'B;
  good_bs := '1011'B;
  var templateBitstr_rec bad_rec, good_rec;
  bad_rec := { x1 := '01'B, x2 := '10'B, x3 := '11'B };
  good_rec := { x1 := '1011'B, x2 := '10'B, x3 := '11'B };
  var bitstring bad_bs_enc, good_bs_enc, bad_rec_enc, good_rec_enc;
  bad_bs_enc := oct2bit(ef_enc_rec_x1(bad_bs));
  good_bs_enc := oct2bit(ef_enc_rec_x1(good_bs));
  bad_rec_enc := encvalue(bad_rec);
  good_rec_enc := encvalue(good_rec);
  var templateBitstr_rec r1, r2, r3;
  r1 := { x1 := '1011'B, x2 := good_bs_enc, x3 := good_rec_enc };
  r2 := { x1 := '1011'B, x2 := bad_bs_enc,  x3 := good_rec_enc };
  r3 := { x1 := '1011'B, x2 := good_bs_enc, x3 := bad_rec_enc  };
  // match: all 2 are good
  if (match(r1, templateBitstr_tDecmatchSelfRef)) { setverdict(pass); }
  else { setverdict(fail, 1); }
  // no match: decoded octetstring does not match
  if (not match(r2, templateBitstr_tDecmatchSelfRef)) { setverdict(pass); }
  else { setverdict(fail, 2); }
  // no match: decoded record does not match
  if (not match(r3, templateBitstr_tDecmatchSelfRef)) { setverdict(pass); }
  else { setverdict(fail, 3); }
  
  // local self-referencing template
  var template templateBitstr_rec t := { x1 := '1011'B, x2 := ?, x3 := ? };
  t.x1 := decmatch t;
  var templateBitstr_rec r4, r5;
  r4 := { x1 := good_rec_enc, x2 := '10'B, x3 := '11'B };
  r5 := { x1 := bad_rec_enc,  x2 := '10'B, x3 := '11'B };
  if (match(r4, t)) { setverdict(pass); }
  else { setverdict(fail, 4); }
  if (not match(r5, t)) { setverdict(pass); }
  else { setverdict(fail, 5); }
}

function f_is_negative(bitstring p_par) return boolean {
  // assume the first bit of the first byte is the sign bit
  if (lengthof(p_par) mod 8 != 0) {
    // the sign bit is one of the zero before the start of the bitstring
    return false;
  }
  return p_par[0] == '1'B;
}

template bitstring t_conjunction := conjunct(? length(1..8), @dynamic f_is_negative);

template bitstring t_implication := '*1010'B implies @dynamic f_is_negative;

// matches if the number of ones in the bitstring matches the template parameter
template bitstring t_dynamic(template integer pt_ones) := @dynamic {
  var integer v_num_ones := 0;
  for (var integer i := 0; i < lengthof(value); i := i + 1) {
    if (value[i] == '1'B) {
      v_num_ones := v_num_ones + 1;
    }
  }
  return match(v_num_ones, pt_ones);
}

testcase templateBitstrConjunction() runs on templateBitstr_mycomp {
  var bitstring v1 := '10000000'B, v2 := '11111'B;
  if (not match(v1, t_conjunction)) {
    setverdict(fail, match(v1, t_conjunction));
  }
  if (match(v2, t_conjunction)) {
    setverdict(fail, match(v2, t_conjunction));
  }
  setverdict(pass);
}

testcase templateBitstrImplication() runs on templateBitstr_mycomp {
  var bitstring v1 := '110011'B, v2 := '01101010'B, v3 := '11111010'B;
  if (not match(v1, t_implication)) {
    setverdict(fail, match(v1, t_implication));
  }
  if (match(v2, t_implication)) {
    setverdict(fail, match(v2, t_implication));
  }
  if (not match(v3, t_implication)) {
    setverdict(fail, match(v3, t_implication));
  }
  setverdict(pass);
}

testcase templateBitstrDynamic() runs on templateBitstr_mycomp {
  var bitstring v1 := '100101'B, v2 := '10010'B;
  var template integer vt1 := 3, vt2 := (3..4);
  if (not match(v1, t_dynamic(vt1))) {
    setverdict(fail, match(v1, t_dynamic(vt1)));
  }
  if (match(v2, t_dynamic(vt2))) {
    setverdict(fail, match(v2, t_dynamic(vt2)));
  }
  setverdict(pass);
}

control {
 execute(templateBitstrSpec());
 execute(templateBitstrList());
 execute(templateBitstrComp());
 execute(templateBitstrOmit());
 execute(templateBitstrAny());
 execute(templateBitstrAnyorNone());
 execute(templateBitstrLength1());
 execute(templateBitstrLength2());
 execute(templateBitstrLength3());
 execute(templateBitstrIfpresent());
 execute(templateBitstrLengthIfp());
 execute(templateBitstrAnyEl());
 execute(templateBitstrAnyorNoneEl());
 execute(CR_TR00018474());
 execute(templateBitstrDecmatch());
 execute(templateBitstrDecmatchSelfRef());
 execute(templateBitstrConjunction());
 execute(templateBitstrImplication());
 execute(templateBitstrDynamic());
}
}