Commit | Line | Data |
---|---|---|
970ed795 EL |
1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2014 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 | module regex_OK { //^In TTCN-3 module `regex_OK':// | |
9 | ||
10 | type component PDTestComponent {}; | |
11 | ||
12 | ||
13 | /*--- REGEXP_CHARSTRING --------------------------------------------------*/ | |
14 | ||
15 | ||
16 | testcase regexp_char() runs on PDTestComponent{ //In testcase definition// | |
17 | ||
18 | //var charstring reg_char1 := "123abcd _efg\nhhhhx" | |
19 | ||
20 | // POSITIVE TEST CASES | |
21 | var charstring reg[55]; | |
22 | ||
23 | reg[0] := regexp("123hhh" ,"[1-3]#(,)([h-h]#(,))" ,0) | |
24 | reg[1] := regexp("123hhh" ,"[1-3]#(3,)(h#(3,))" ,0) | |
25 | reg[2] := regexp("123hhh" ,"[1-3]#(3,4)(h#(3,4))" ,0) | |
26 | reg[3] := regexp("123hhh" ,"[1-3]#(1,3)(h#(1,3))" ,0) | |
27 | reg[4] := regexp("123hhh" ,"[1-3]#(,3)(h#(,3))" ,0) | |
28 | ||
29 | reg[5] := regexp("333 hhh" ,"[^1-2]#(,) ([^a-g,i-z]#(,))" ,0) | |
30 | reg[6] := regexp("333 hhh" ,"[^1-2,4]#(,) ([^a-g,i]#(,))" ,0) | |
31 | reg[7] := regexp("333 hhh" ,"[^1,2,4]#(,) ([^a,b,i]#(,))" ,0) //In variable assignment// //In operation `regexp\(\)'// //In character string pattern// //Charstring pattern: Duplicate character `.' in the character set//2 | |
32 | reg[8] := regexp("333 hhh" ,"[^1-2]#(,)[3] ([^a-g]#(,))" ,0) | |
33 | reg[9] := regexp("333 hhh" ,"[^1-2]#(,)[33] ([^i-z]#(,))" ,0) //In variable assignment// //In operation `regexp\(\)'// //In character string pattern// //Charstring pattern: Duplicate character `.' in the character set// | |
34 | ||
35 | reg[10] := regexp("333 hhh" ,"[^1-2]#(,)[3,33] ([h,g]#(,))" ,0) //In variable assignment// //In operation `regexp\(\)'// //In character string pattern// //Charstring pattern: Duplicate character `.' in the character set//2 | |
36 | reg[11] := regexp("333 hhh" ,"[^1-2]#(,)[33,3,4] ([h]#(,))" ,0) //In variable assignment// //In operation `regexp\(\)'// //In character string pattern// //Charstring pattern: Duplicate character `.' in the character set//3 | |
37 | reg[12] := regexp("333 hhh" ,"[^1-2]#(,) ([h,hh]h#(,))" ,0) //In variable assignment// //In operation `regexp\(\)'// //In character string pattern// //Charstring pattern: Duplicate character `.' in the character set//2 | |
38 | reg[13] := regexp("333 hhh" ,"[^1-2]#(,) ([h,hh,hhh]#(,))" ,0) //In variable assignment// //In operation `regexp\(\)'// //In character string pattern// //Charstring pattern: Duplicate character `.' in the character set//6 | |
39 | reg[14] := regexp("333 hhh" ,"[^1-2]#(,) ([h,g,hh]#(,))" ,0) //In variable assignment// //In operation `regexp\(\)'// //In character string pattern// //Charstring pattern: Duplicate character `.' in the character set//3 | |
40 | ||
41 | reg[15] := regexp("333 hhh " ,"\d\d\d (\w\w\w) " ,0) //In charstring value// //Unknown escape sequence `\\.' was treated literally//6 | |
42 | reg[16] := regexp("333 hhh " ,"\w#(,) (\w\w#(,2)) " ,0) //In charstring value// //Unknown escape sequence `\\.' was treated literally//3 | |
43 | reg[17] := regexp("333 hhh " ,"\w#(,) (\w#(,2)\w) " ,0) //In charstring value// //Unknown escape sequence `\\.' was treated literally//3 | |
44 | reg[18] := regexp("333 hhh " ,"\w#(3,) (\w?\w) " ,0) //In charstring value// //Unknown escape sequence `\\.' was treated literally//3 | |
45 | reg[19] := regexp("333 hhh " ,"\w\d3 (h\wh) " ,0) //In charstring value// //Unknown escape sequence `\\.' was treated literally//3 | |
46 | ||
47 | reg[20] := regexp("333\thhh " ,"????(???)?" ,0) | |
48 | reg[21] := regexp("333\thhh " ,"3??\t(?h?)?" ,0) | |
49 | reg[22] := regexp("333\thhh " ,"?#(,)\t(?#(,))?" ,0) | |
50 | reg[23] := regexp("333\thhh " ,"?#(,)?(h?\w) " ,0) //In charstring value// //Unknown escape sequence `\\.' was treated literally// | |
51 | reg[24] := regexp("333\thhh " ,"?#(,3)\t(h??#(,2))?" ,0) | |
52 | ||
53 | reg[25] := regexp("333\rhhh " ,"?*\r(*) " ,0) | |
54 | reg[26] := regexp("333\rhhh " ,"*?3\r(h*) " ,0) | |
55 | reg[27] := regexp("333\rhhh " ,"*333\r(***h) " ,0) | |
56 | reg[28] := regexp("333\rhhh " ,"*(h*?h)?" ,0) | |
57 | reg[29] := regexp("333\rhhh " ,"*?(???)?" ,0) | |
58 | ||
59 | reg[30] := regexp("333\rhhh " ,"*???\r(?*h#(2,)) " ,0) | |
60 | reg[31] := regexp("333\rhhh " ,"\w\d*\r(\w?*) " ,0) //In charstring value// //Unknown escape sequence `\\.' was treated literally//3 | |
61 | reg[32] := regexp("333\rhhh " ,"*?(h*h\w) " ,0) //In charstring value// //Unknown escape sequence `\\.' was treated literally// | |
62 | reg[33] := regexp("333\rhhh " ,"*\r(\w\w\w) " ,0) //In charstring value// //Unknown escape sequence `\\.' was treated literally//3 | |
63 | reg[34] := regexp("333\rhhh " ,"*\r(*) " ,0) | |
64 | ||
65 | reg[35] := regexp("333\"hhh " ,"*\"(???)(?)*" ,0) | |
66 | reg[36] := regexp("333\"hhh " ,"*3?(?*??)[ ,1]" ,0) | |
67 | reg[37] := regexp("333\"hhh " ,"*3?(???)[1, ,2]" ,0) //In variable assignment// //In operation `regexp\(\)'// //In character string pattern// //Charstring pattern: Duplicate character `.' in the character set// | |
68 | reg[38] := regexp("333\"hhh " ,"*33?(???)[^a,1]" ,0) | |
69 | reg[39] := regexp("333\"hhh " ,"333\"(???)*" ,0) | |
70 | ||
71 | ||
72 | for (var integer j:=0; j<=39; j:=j+1) { | |
73 | if (reg[j] == "hhh") | |
74 | {setverdict(pass);} | |
75 | else {setverdict(fail);} | |
76 | } | |
77 | ||
78 | ||
79 | reg[40] := regexp("123\rabc" ,"(*)123(*)abc" ,1) | |
80 | reg[41] := regexp("\r123" ,"(*)123(*)" ,0) | |
81 | reg[42] := regexp("\r123\r" ,"(*)123(?)" ,1) | |
82 | reg[43] := regexp("\t\n\r123\r" ,"??(?)123(?)" ,0) | |
83 | reg[44] := regexp("\t\n\r123" ,"(?)(?)(?)(*)" ,2) | |
84 | ||
85 | reg[45] := regexp("(\r)" ,"(\()(?)(\))" ,1) //In charstring value// //Unknown escape sequence `\\.' was treated literally//2 | |
86 | reg[46] := regexp("\"(\r)\"" ,"?(\()(?)(\))?",1) //In charstring value// //Unknown escape sequence `\\.' was treated literally//2 | |
87 | reg[47] := regexp("\r" ,"(?)" ,0) | |
88 | reg[48] := regexp("\r" ,"(*)" ,0) | |
89 | reg[49] := regexp("\r" ,"(**)" ,0) | |
90 | ||
91 | reg[50] := regexp("\r \t \n" ,"(*) (*) (*)" ,0) | |
92 | reg[51] := regexp("\r\r\r\r" ,"(*)(\r#(3))" ,0) | |
93 | reg[52] := regexp("\r" ,"([^\n,\t])" ,0) | |
94 | reg[53] := regexp("\r " ,"(*)(?)(?)" ,1) | |
95 | reg[54] := regexp(" \r " ,"(?)(*?*) " ,1) | |
96 | ||
97 | ||
98 | for (var integer j:=40; j<=54; j:=j+1) { | |
99 | if (reg[j] == "\r") | |
100 | {setverdict(pass);} | |
101 | else {setverdict(fail);} | |
102 | } | |
103 | ||
104 | ||
105 | // NEGATIVE TEST CASES | |
106 | var charstring regn[10]; | |
107 | ||
108 | regn[0] := regexp("\r" ,"(?)(?)" ,1) | |
109 | regn[1] := regexp("\r \n" ,"(?)(\n)" ,1) | |
110 | regn[2] := regexp("12ab" ,"(\d\d\d)(\w)" ,1) //In charstring value// //Unknown escape sequence `\\.' was treated literally//4 | |
111 | regn[3] := regexp("12ab" ,"(\d#(3))(?)" ,1) //In charstring value// //Unknown escape sequence `\\.' was treated literally// | |
112 | regn[4] := regexp("\r" ,"(?)(r*)" ,1) | |
113 | ||
114 | regn[5] := regexp("\r" ,"(*)([\t,\n])" ,1) | |
115 | regn[6] := regexp("\r" ,"(*)([^\r])" ,1) | |
116 | regn[7] := regexp("123 abc" ,"123??(a??)" ,0) | |
117 | regn[8] := regexp("1234" ,"([1-3]#(,))" ,0) | |
118 | regn[9] := regexp("123a" ,"(\d#(,))" ,0) //In charstring value// //Unknown escape sequence `\\.' was treated literally// | |
119 | ||
120 | for (var integer j:=0; j<=9; j:=j+1) { | |
121 | if (regn[j] == "") | |
122 | {setverdict(pass);} | |
123 | else {setverdict(fail);} | |
124 | } | |
125 | ||
126 | } | |
127 | ||
128 | testcase regexp_degen() runs on PDTestComponent { | |
129 | var charstring reg[6]; | |
130 | //These would be errors: | |
131 | //reg[-2] := regexp(strng, "([]+)", 0); | |
132 | //reg[-1] := regexp(strng, "([^]+)", 0); | |
133 | reg[0] := regexp("@@@]]]###", "*([]]#3)(*)", 0); // a right square bracket | |
134 | reg[1] := regexp("]]]!!!]]]", "*([^]]#3)(*)", 0); // not a right square bracket | |
135 | ||
136 | reg[2] := regexp("+++---!!!", "*([-]#3)(*)", 0); // a dash | |
137 | reg[3] := regexp("---???---", "*([^-]#3)(*)", 0); // not a dash | |
138 | ||
139 | reg[4] := regexp("[[[-]-+++", "*([]-]#3)(*)", 0); // a right square bracket or dash | |
140 | reg[5] := regexp("[[[---]]]", "*([^]-]#3)(*)", 0);// not a right square bracket or dash | |
141 | ||
142 | for(var integer i:=0; i<6; i:=i+1) { | |
143 | log(reg[i]); | |
144 | if( lengthof(reg[i])==3 ) | |
145 | {setverdict(pass);} | |
146 | else {setverdict(fail);} | |
147 | } | |
148 | } | |
149 | ||
150 | control { | |
151 | execute (regexp_char()); | |
152 | execute (regexp_degen()); | |
153 | } | |
154 | ||
155 | } |