* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
+ * Baranyi, Botond
* Balasko, Jeno
* Kovacs, Ferenc
* Raduly, Csaba
type record templateOctetstr_rec {
octetstring x1,
octetstring x2,
- octetstring x3 optional };
+ octetstring 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 templateOctetstr_rec templateOctetstr_tSpec :={ //specific values
x1:='00AA'O,
x2:='01AA'O,
x1:='00AA'O,
x2:='01AA'O,
x3:='10*'O };
+
+template decmatch_uni decmatch_tUnion := { i := ? };
+
+template decmatch_rec decmatch_tRecord := { i := (0..infinity), s := ? };
+
+template templateOctetstr_rec templateOctetstr_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 templateOctetstr_rec templateOctetstr_tDecmatchSelfRef := { // decoded content match with self-reference
+ x1 := '00AA'O,
+ x2 := decmatch templateOctetstr_tDecmatchSelfRef.x1,
+ x3 := decmatch templateOctetstr_rec: { x1 := templateOctetstr_tDecmatchSelfRef.x1, x2 := ?, x3 := * }
+};
+
testcase templateOctetstrSpec() runs on templateOctetstr_mycomp {
var templateOctetstr_rec x1,x2; //specific value
if (match('BBBAABBA'O, vto1)) { setverdict(pass) } else { setverdict(fail) }
}
+testcase templateOctetstrDecmatch() runs on templateOctetstr_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 octetstring bad_rec_enc, good_rec_enc, bad_list_enc, good_list_enc, bad_uni_enc, good_uni_enc;
+ bad_rec_enc := bit2oct(encvalue(bad_rec));
+ good_rec_enc := bit2oct(encvalue(good_rec));
+ bad_list_enc := bit2oct(encvalue(bad_list));
+ good_list_enc := bit2oct(encvalue(good_list));
+ bad_uni_enc := bit2oct(encvalue(bad_uni));
+ good_uni_enc := bit2oct(encvalue(good_uni));
+ var templateOctetstr_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 := 'FF00'O };
+ // match: all 3 are good
+ if (match(r1, templateOctetstr_tDecmatch)) { setverdict(pass); }
+ else { setverdict(fail, 1); }
+ // no match: decoded list does not match
+ if (not match(r2, templateOctetstr_tDecmatch)) { setverdict(pass); }
+ else { setverdict(fail, 2); }
+ // no match: decoded union does not match
+ if (not match(r3, templateOctetstr_tDecmatch)) { setverdict(pass); }
+ else { setverdict(fail, 3); }
+ // no match: decoded record does not match
+ if (not match(r4, templateOctetstr_tDecmatch)) { setverdict(pass); }
+ else { setverdict(fail, 4); }
+ // no match: x3 is not a valid encoded record value
+ if (not match(r5, templateOctetstr_tDecmatch)) { setverdict(pass); }
+ else { setverdict(fail, 5); }
+ // match r1 with the same template declared as an in-line template
+ if (match(r1, templateOctetstr_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 templateOctetstr_rec.x1 x) return octetstring
+with { extension "prototype(convert) encode(JSON)" }
+
+testcase templateOctetstrDecmatchSelfRef() runs on templateOctetstr_mycomp {
+ // global self-referencing template
+ var templateOctetstr_rec.x1 bad_os, good_os;
+ bad_os := 'AA00'O;
+ good_os := '00AA'O;
+ var templateOctetstr_rec bad_rec, good_rec;
+ bad_rec := { x1 := '00'O, x2 := '01'O, x3 := '02'O };
+ good_rec := { x1 := '00AA'O, x2 := '01'O, x3 := '02'O };
+ var octetstring bad_os_enc, good_os_enc, bad_rec_enc, good_rec_enc;
+ bad_os_enc := ef_enc_rec_x1(bad_os);
+ good_os_enc := ef_enc_rec_x1(good_os);
+ bad_rec_enc := bit2oct(encvalue(bad_rec));
+ good_rec_enc := bit2oct(encvalue(good_rec));
+ var templateOctetstr_rec r1, r2, r3;
+ r1 := { x1 := '00AA'O, x2 := good_os_enc, x3 := good_rec_enc };
+ r2 := { x1 := '00AA'O, x2 := bad_os_enc, x3 := good_rec_enc };
+ r3 := { x1 := '00AA'O, x2 := good_os_enc, x3 := bad_rec_enc };
+ // match: all 2 are good
+ if (match(r1, templateOctetstr_tDecmatchSelfRef)) { setverdict(pass); }
+ else { setverdict(fail, 1); }
+ // no match: decoded octetstring does not match
+ if (not match(r2, templateOctetstr_tDecmatchSelfRef)) { setverdict(pass); }
+ else { setverdict(fail, 2); }
+ // no match: decoded record does not match
+ if (not match(r3, templateOctetstr_tDecmatchSelfRef)) { setverdict(pass); }
+ else { setverdict(fail, 3); }
+
+ // local self-referencing template
+ var template templateOctetstr_rec t := { x1 := '00AA'O, x2 := ?, x3 := ? };
+ t.x1 := decmatch t;
+ var templateOctetstr_rec r4, r5;
+ r4 := { x1 := good_rec_enc, x2 := 'AA'O, x3 := 'AB'O };
+ r5 := { x1 := bad_rec_enc, x2 := 'AA'O, x3 := 'AB'O };
+ if (match(r4, t)) { setverdict(pass); }
+ else { setverdict(fail, 4); }
+ if (not match(r5, t)) { setverdict(pass); }
+ else { setverdict(fail, 5); }
+}
+
+function f_decmatch(in template templateOctetstr_rec par_temp :=
+ { x1 := ?, x2 := ?, x3 := decmatch decmatch_rec: { i := (1, 2, 3), s := ? } })
+{
+ var decmatch_rec bad_rec, good_rec;
+ bad_rec := { i := 11, s := "xyz" };
+ good_rec := { i := 3, s := "abc" };
+ var octetstring bad_rec_enc, good_rec_enc;
+ bad_rec_enc := bit2oct(encvalue(bad_rec));
+ good_rec_enc := bit2oct(encvalue(good_rec));
+ var templateOctetstr_rec r1, r2;
+ r1 := { x1 := '1A'O, x2 := '1B'O, x3 := good_rec_enc };
+ r2 := { x1 := '1A'O, x2 := '1B'O, x3 := bad_rec_enc };
+ if (match(r1, par_temp)) { setverdict(pass); }
+ else { setverdict(fail, 1); }
+ if (not match(r2, par_temp)) { setverdict(pass); }
+ else { setverdict(fail, 2); }
+}
+
+testcase templateOctetstrDecmatchExtra() runs on templateOctetstr_mycomp {
+ // testing decmatch template as parameter default value
+ f_decmatch();
+ // testing logging of decmatch template
+ if (log2str(templateOctetstr_tDecmatch) == "{ " &
+ "x1 := decmatch decmatch_list: { (1 .. 10), (11 .. 20), (21 .. 30) }, " &
+ "x2 := decmatch decmatch_uni: { i := ? }, " &
+ "x3 := decmatch decmatch_rec: { i := (0 .. infinity), s := \"abc\" } }")
+ { setverdict(pass); }
+ else { setverdict(fail, templateOctetstr_tDecmatch); }
+}
+
control {
execute(templateOctetstrSpec());
execute(templateOctetstrList());
execute(templateOctetstrAnyEl());
execute(templateOctetstrAnyorNoneEl());
execute(CR_TR00018474());
+ execute(templateOctetstrDecmatch());
+ execute(templateOctetstrDecmatchSelfRef());
+ execute(templateOctetstrDecmatchExtra());
}
}