implemented decmatch (artf724241)
[deliverable/titan.core.git] / regression_test / templateUnicharstr / TtemplateUnicharstr.ttcn
diff --git a/regression_test/templateUnicharstr/TtemplateUnicharstr.ttcn b/regression_test/templateUnicharstr/TtemplateUnicharstr.ttcn
new file mode 100644 (file)
index 0000000..258ee8e
--- /dev/null
@@ -0,0 +1,254 @@
+/******************************************************************************
+ * Copyright (c) 2000-2016 Ericsson Telecom AB
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Baranyi, Botond – initial implementation
+ *
+ ******************************************************************************/
+module TtemplateUnicharstr {
+
+type component templateUnicharstr_mycomp {};
+type record templateUnicharstr_rec {
+ universal charstring x1,
+ universal charstring x2,
+ universal charstring 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)";
+}
+
+type octetstring OS
+with {
+  encode "RAW";
+}
+
+
+template decmatch_uni decmatch_tUnion := { i := ? };
+
+template decmatch_rec decmatch_tRecord := { i := (0..infinity), s := ? };
+
+template templateUnicharstr_rec templateUnicharstr_tDecmatch := { // decoded content match
+  x1 := decmatch decmatch_list: { (1..10), (11..20), (21..30) }, // no format parameter = UTF-8
+  x2 := decmatch decmatch_tUnion,
+  x3 := decmatch modifies decmatch_tRecord := { s := "abc" }
+};
+
+template templateUnicharstr_rec templateUnicharstr_tDecmatchSelfRef := { // decoded content match with self-reference
+  x1 := "a",
+  x2 := decmatch("UTF-8") templateUnicharstr_tDecmatchSelfRef.x1,
+  x3 := decmatch("UTF-8") templateUnicharstr_rec: { x1 := templateUnicharstr_tDecmatchSelfRef.x1, x2 := ?, x3 := * }
+};
+
+template templateUnicharstr_rec templateUnicharstr_tDecmatch16 := { // decoded content match in UTF-16 format
+  x1 := decmatch("UTF-16") OS: 'FEFF'O, // just the BOM
+  x2 := decmatch("UTF-16LE") OS: ? length (4..6), // BOM + 1-2 characters below FFFF or 1 character above FFFF
+  x3 := decmatch("UTF-16BE") OS: ? length (8..infinity) // BOM + 3 or more characters (2 or more if one of them is above FFFF)
+};
+
+template templateUnicharstr_rec templateUnicharstr_tDecmatch32 := { // decoded content match in UTF-32 format
+  x1 := decmatch("UTF-32") OS: '0000FEFF'O, // just the BOM
+  x2 := decmatch("UTF-32LE") OS: ? length (4..8), // BOM + 1 optional character
+  x3 := decmatch("UTF-32BE") OS: ? length (16..infinity) // BOM + 3 or more characters
+};
+
+template charstring templateUnicharstr_tCharDecmatch := decmatch decmatch_rec: { i := 1, s := ? };
+
+
+testcase templateUnicharstrDecmatch() runs on templateUnicharstr_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 universal charstring bad_rec_enc, good_rec_enc, bad_list_enc, good_list_enc, bad_uni_enc, good_uni_enc;
+  bad_rec_enc := oct2unichar(bit2oct(encvalue(bad_rec)), "UTF-8");
+  good_rec_enc := oct2unichar(bit2oct(encvalue(good_rec)), "UTF-8");
+  bad_list_enc := oct2unichar(bit2oct(encvalue(bad_list)), "UTF-8");
+  good_list_enc := oct2unichar(bit2oct(encvalue(good_list)), "UTF-8");
+  bad_uni_enc := oct2unichar(bit2oct(encvalue(bad_uni)), "UTF-8");
+  good_uni_enc := oct2unichar(bit2oct(encvalue(good_uni)), "UTF-8");
+  var templateUnicharstr_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 := "xyz"        };
+  // match: all 3 are good
+  if (match(r1, templateUnicharstr_tDecmatch)) { setverdict(pass); }
+  else { setverdict(fail, 1); }
+  // no match: decoded list does not match
+  if (not match(r2, templateUnicharstr_tDecmatch)) { setverdict(pass); }
+  else { setverdict(fail, 2); }
+  // no match: decoded union does not match
+  if (not match(r3, templateUnicharstr_tDecmatch)) { setverdict(pass); }
+  else { setverdict(fail, 3); }
+  // no match: decoded record does not match
+  if (not match(r4, templateUnicharstr_tDecmatch)) { setverdict(pass); }
+  else { setverdict(fail, 4); }
+  // no match: x3 is not a valid encoded record value
+  if (not match(r5, templateUnicharstr_tDecmatch)) { setverdict(pass); }
+  else { setverdict(fail, 5); }
+  // match r1 with the same template declared as an in-line template
+  if (match(r1, templateUnicharstr_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 templateUnicharstr_rec.x1 x) return octetstring
+with { extension "prototype(convert) encode(JSON)" }
+
+testcase templateUnicharstrDecmatchSelfRef() runs on templateUnicharstr_mycomp {
+  // global self-referencing template
+  var templateUnicharstr_rec.x1 bad_ucs, good_ucs;
+  bad_ucs := char(0, 0, 1, 113);
+  good_ucs := "a";
+  var templateUnicharstr_rec bad_rec, good_rec;
+  bad_rec := { x1 := char(0, 0, 0, 255), x2 := char(0, 0, 1, 0), x3 := char(0, 0, 1, 1) };
+  good_rec := { x1 := "a", x2 := char(0, 0, 1, 0), x3 := char(0, 0, 1, 1) };
+  var universal charstring bad_ucs_enc, good_ucs_enc, bad_rec_enc, good_rec_enc;
+  bad_ucs_enc := oct2unichar(ef_enc_rec_x1(bad_ucs), "UTF-8");
+  good_ucs_enc := oct2unichar(ef_enc_rec_x1(good_ucs), "UTF-8");
+  bad_rec_enc := oct2unichar(bit2oct(encvalue(bad_rec)), "UTF-8");
+  good_rec_enc := oct2unichar(bit2oct(encvalue(good_rec)), "UTF-8");
+  var templateUnicharstr_rec r1, r2, r3;
+  r1 := { x1 := "a", x2 := good_ucs_enc, x3 := good_rec_enc };
+  r2 := { x1 := "a", x2 := bad_ucs_enc,  x3 := good_rec_enc };
+  r3 := { x1 := "a", x2 := good_ucs_enc, x3 := bad_rec_enc  };
+  // match: all 2 are good
+  if (match(r1, templateUnicharstr_tDecmatchSelfRef)) { setverdict(pass); }
+  else { setverdict(fail, 1); }
+  // no match: decoded octetstring does not match
+  if (not match(r2, templateUnicharstr_tDecmatchSelfRef)) { setverdict(pass); }
+  else { setverdict(fail, 2); }
+  // no match: decoded record does not match
+  if (not match(r3, templateUnicharstr_tDecmatchSelfRef)) { setverdict(pass); }
+  else { setverdict(fail, 3); }
+  
+  // local self-referencing template
+  var template templateUnicharstr_rec t := { x1 := "a", x2 := ?, x3 := ? };
+  t.x1 := decmatch t;
+  var templateUnicharstr_rec r4, r5;
+  r4 := { x1 := good_rec_enc, x2 := "x", x3 := "y" };
+  r5 := { x1 := bad_rec_enc,  x2 := "x", x3 := "y" };
+  if (match(r4, t)) { setverdict(pass); }
+  else { setverdict(fail, 4); }
+  if (not match(r5, t)) { setverdict(pass); }
+  else { setverdict(fail, 5); }
+}
+
+testcase templateUnicharstrDecmatch16() runs on templateUnicharstr_mycomp {
+  var universal charstring bad16, good16, bad16le, good16le, bad16be, good16be;
+  bad16 := "abc";
+  good16 := "";
+  bad16le := char(0, 1, 2, 3) & char(0, 4, 5, 6);
+  good16le := char(0, 1, 2, 3);
+  bad16be := char(0, 1, 10, 100);
+  good16be := "ab" & char(0, 1, 10, 100) & "xy";
+  var templateUnicharstr_rec r1, r2, r3, r4;
+  r1 := { x1 := good16, x2 := good16le, x3 := good16be };
+  r2 := { x1 := bad16,  x2 := good16le, x3 := good16be };
+  r3 := { x1 := good16, x2 := bad16le,  x3 := good16be };
+  r4 := { x1 := good16, x2 := good16le, x3 := bad16be  };
+  // match: all 3 are good
+  if (match(r1, templateUnicharstr_tDecmatch16)) { setverdict(pass); }
+  else { setverdict(fail, 1); }
+  // no match: decoded string in UTF-16 format is not empty
+  if (not match(r2, templateUnicharstr_tDecmatch16)) { setverdict(pass); }
+  else { setverdict(fail, 2); }
+  // no match: decoded string in UTF-16LE format is too long
+  if (not match(r3, templateUnicharstr_tDecmatch16)) { setverdict(pass); }
+  else { setverdict(fail, 3); }
+  // no match: decoded string in UTF-16BE format is too short
+  if (not match(r4, templateUnicharstr_tDecmatch16)) { setverdict(pass); }
+  else { setverdict(fail, 4); }
+}
+
+testcase templateUnicharstrDecmatch32() runs on templateUnicharstr_mycomp {
+  var universal charstring bad32, good32, bad32le, good32le, bad32be, good32be;
+  bad32 := "abc";
+  good32 := "";
+  bad32le := char(0, 1, 2, 3) & char(0, 4, 5, 6);
+  good32le := char(0, 1, 2, 3);
+  bad32be := char(0, 1, 10, 100);
+  good32be := "ab" & char(0, 1, 10, 100) & "xy";
+  var templateUnicharstr_rec r1, r2, r3, r4;
+  r1 := { x1 := good32, x2 := good32le, x3 := good32be };
+  r2 := { x1 := bad32,  x2 := good32le, x3 := good32be };
+  r3 := { x1 := good32, x2 := bad32le,  x3 := good32be };
+  r4 := { x1 := good32, x2 := good32le, x3 := bad32be  };
+  // match: all 3 are good
+  if (match(r1, templateUnicharstr_tDecmatch32)) { setverdict(pass); }
+  else { setverdict(fail, 1); }
+  // no match: decoded string in UTF-32 format is not empty
+  if (not match(r2, templateUnicharstr_tDecmatch32)) { setverdict(pass); }
+  else { setverdict(fail, 2); }
+  // no match: decoded string in UTF-32LE format is too long
+  if (not match(r3, templateUnicharstr_tDecmatch32)) { setverdict(pass); }
+  else { setverdict(fail, 3); }
+  // no match: decoded string in UTF-32BE format is too short
+  if (not match(r4, templateUnicharstr_tDecmatch32)) { setverdict(pass); }
+  else { setverdict(fail, 4); }
+}
+
+testcase templateUnicharstrDecmatchCopyCharstr() runs on templateUnicharstr_mycomp {
+  // testing a universal charstring template copied from a
+  // charstring template (with decoded content matching)
+  var template universal charstring t := templateUnicharstr_tCharDecmatch;
+  var decmatch_rec bad_rec, good_rec;
+  bad_rec := { i := 6, s := "xyz" };
+  good_rec := { i := 1, s := "abc" };
+  var universal charstring bad_rec_enc, good_rec_enc;
+  bad_rec_enc := oct2unichar(bit2oct(encvalue(bad_rec)), "UTF-8");
+  good_rec_enc := oct2unichar(bit2oct(encvalue(good_rec)), "UTF-8");
+  if (match(good_rec_enc, t)) { setverdict(pass); }
+  else { setverdict(fail, 1); }
+  if (not match(bad_rec_enc, t)) { setverdict(pass); }
+  else { setverdict(fail, 2); }
+}
+
+control {
+  execute(templateUnicharstrDecmatch());
+  execute(templateUnicharstrDecmatchSelfRef());
+  execute(templateUnicharstrDecmatch16());
+  execute(templateUnicharstrDecmatch32());
+  execute(templateUnicharstrDecmatchCopyCharstr());
+}
+
+}
This page took 0.029155 seconds and 5 git commands to generate.