File: pattern_quadruples.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 (145 lines) | stat: -rw-r--r-- 5,043 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
/******************************************************************************
 * 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:
 *   Balasko, Jeno
 *   Raduly, Csaba
 *   Szabados, Kristof
 *   Zalanyi, Balazs Andor
 *
 ******************************************************************************/
module pattern_quadruples
{
  type component univchar_comp {};

  testcase univ_match() runs on univchar_comp {
    var universal charstring ustr;
    const universal charstring custr := char(1, 21, 0, 122);
    var template universal charstring utmp := pattern "{custr}[a-zA-Z\q{0, 0, 255, 24}-\q{0, 2, 12, 230}]";
    template universal charstring utmp2 := pattern "{utmp}[^0-9]";

    var boolean b := true;
    var integer i;
    const integer l1 := unichar2int(char(0, 0, 255, 24));
    const integer l2 := unichar2int(char(0, 2, 12, 230));
    const integer l := unichar2int(char(0, 2, 12, 255));
    for (i := 0; i <= l and b == true; i := i + 1) {
      ustr := char(1, 21, 0, 122) & int2unichar(i) & "a";
      b:= match(ustr, utmp2);
      if (i < 65 or (i > 90 and i < 97) or (i > 122 and i < l1) or i > l2) {
        b := not b;
      }
    }
    if (b) {
      setverdict(pass);
    } else {
      setverdict(fail);
    }
  }

  testcase univ_match_neg() runs on univchar_comp {
    var universal charstring ustr;
    template universal charstring utmp := pattern "[^\q{0, 1, 123, 12}-\q{0, 2, 203, 255}]";

    var boolean b := true;
    var integer i;
    const integer l1 := unichar2int(char(0, 1, 123, 12));
    const integer l2 := unichar2int(char(0, 2, 203, 255));
    const integer l := unichar2int(char(0, 3, 0, 0));
    for (i := 0; i <= l and b == true; i := i + 1) {
      ustr := int2unichar(i);
      b:= match(ustr, utmp);
      if (i >= l1 and i <= l2) {
        b := not b;
      }
    }
    if (b) {
      setverdict(pass);
    } else {
      setverdict(fail);
    }
  }

  testcase univ_regexp() runs on univchar_comp {
    var universal charstring uinput := "   simple text for a regexp example  ";
    var universal charstring uregexp;

    var universal charstring expected[0..2] := { "   simple ", "text", " for a regexp example  " };

    var charstring ustrpattern := "(?+)(text)(?+)";

    var integer i;
    for (i := 0; i <= 2; i := i + 1) {
      uregexp := regexp(uinput, ustrpattern, i);
      if (uregexp != expected[i]) {
        setverdict(fail, "not equal at ", i);
      }
    }

    setverdict(pass);
  }

  testcase univ_from_charstr_pattern() runs on univchar_comp {
    template           charstring t_cs := pattern "foo.*";
    template universal charstring t_us := t_cs; // not an error anymore

    var           charstring foobar_c := "foo.bar";
    var universal charstring foobar_u := "foo.bar";

    if (not match(foobar_c, t_cs)) { setverdict(fail, "cstr mismatch,", match(foobar_c, t_cs)); }
    if (not match(foobar_u, t_us)) { setverdict(fail, "ustr mismatch,", match(foobar_u, t_us)); }
    setverdict(pass);
  }
  
  const universal charstring c_ucs_val := "AÍ";
  const universal charstring c_ucs_pattern := "([abc][é-ű])";
  
  // case-insensitive regexp
  testcase univ_regexp_nocase() runs on univchar_comp {
    // regexp with constants (calculated at compile-time)
    var universal charstring v_res_const := regexp @nocase (c_ucs_val, c_ucs_pattern, 0);
    if (v_res_const != c_ucs_val) {
      setverdict(fail, "Const regexp failed. Got: ", v_res_const, ", expected: ", c_ucs_val);
    }
    
    // regexp with variables (calculated at runtime)
    var universal charstring v_ucs_val := "aÁű";
    var universal charstring v_ucs_pattern := "(Aá[É-Ű])";
    var universal charstring v_res_var := regexp @nocase (v_ucs_val, v_ucs_pattern, 0);
    if (v_res_var != v_ucs_val) {
      setverdict(fail, "Var regexp failed. Got: ", v_res_var, ", expected: ", v_ucs_val);
    }
    setverdict(pass);
  }
  
  modulepar template universal charstring mpt_ucs;
  
  // case-insensitive pattern
  testcase univ_pattern_nocase() runs on univchar_comp {
    // pattern in template variable
    var template universal charstring vt_ucs := pattern @nocase "A\q{0,0,0,225}[\q{0,0,0,201}-\q{0,0,1,113}]"; // "Aá[É-ű]"
    var universal charstring val := "aÁű";
    if (not match(val, vt_ucs)) {
      setverdict(fail, "Var template pattern failed: ", match(val, vt_ucs));
    }
    
    // pattern in template module parameter
    if (not match(val, mpt_ucs)) {
      setverdict(fail, "Var template pattern failed: ", match(val, mpt_ucs));
    }
    setverdict(pass);
  }

  control {
    execute(univ_match());
    execute(univ_match_neg());
    execute(univ_regexp());
    execute(univ_from_charstr_pattern());
    execute(univ_regexp_nocase());
    execute(univ_pattern_nocase());
  }
}