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 replacer_SW { //^In TTCN-3 module `replacer_SW':// | |
9 | ||
10 | type component PDTestComponent {}; | |
11 | ||
12 | /* replace on BITSTRING values. Examples from C.34 of ETSI ES 201 873-1 | |
13 | V3.3.1 (2008-02). */ | |
14 | ||
15 | const integer a := 0 | |
16 | const integer b := 1 | |
17 | const bitstring bs_1 := replace('00000110'B, 1, 3, '111'B) // returns '01110110'B | |
18 | const bitstring bs_2 := replace('00000110'B, b + a, b + b + b, '111'B)// returns '01110110'B | |
19 | ||
20 | testcase replace_bitstr() runs on PDTestComponent { //^In testcase definition// | |
21 | if (bs_1 == '01110110'B) { setverdict(pass) } | |
22 | else { setverdict(fail) } //^In else statement// \ | |
23 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
24 | if (bs_1 == bs_2) { setverdict(pass) } | |
25 | else { setverdict(fail) } //^In else statement// \ | |
26 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
27 | } | |
28 | ||
29 | /* replace on HEXSTRING values. */ | |
30 | ||
31 | const hexstring hs_1 := replace('ABCDEF'H, 0, 2, '123'H) // returns '123CDEF'H | |
32 | const hexstring hs_2 := replace('ABCDEF'H, a, b + 1, '123'H)// returns '123CDEF'H | |
33 | ||
34 | testcase replace_hexstr() runs on PDTestComponent { //^In testcase definition// | |
35 | if (hs_1 == '123CDEF'H) { setverdict(pass) } | |
36 | else { setverdict(fail) } //^In else statement// \ | |
37 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
38 | if (hs_1 == hs_2) { setverdict(pass) } | |
39 | else { setverdict(fail) } //^In else statement// \ | |
40 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
41 | } | |
42 | ||
43 | /* replace on OCTETSTRING values. */ | |
44 | ||
45 | const octetstring c := 'FF96'O | |
46 | const octetstring os_0 := '01AB23CD'O | |
47 | const octetstring os_1 := replace('01AB23CD'O, 2, 1, 'FF96'O) // returns '01ABFF96CD'O | |
48 | const octetstring os_2 := replace('01AB23CD'O, a + 2, b, 'FF96'O)// returns '01ABFF96CD'O | |
49 | const octetstring os_3 := replace(os_0, 2, b, c) // returns '01ABFF96CD'O | |
50 | ||
51 | testcase replace_octetstr() runs on PDTestComponent { //^In testcase definition// | |
52 | if (os_1 == '01ABFF96CD'O) { setverdict(pass) } | |
53 | else { setverdict(fail) } //^In else statement// \ | |
54 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
55 | if (os_2 == '01ABFF96CD'O) { setverdict(pass) } | |
56 | else { setverdict(fail) } //^In else statement// \ | |
57 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
58 | if (os_1 == os_2) { setverdict(pass) } | |
59 | else { setverdict(fail) } //^In else statement// \ | |
60 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
61 | if (os_2 == os_3) { setverdict(pass) } | |
62 | else { setverdict(fail) } //^In else statement// \ | |
63 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
64 | } | |
65 | ||
66 | /* replace on CHARSTRING values. */ | |
67 | ||
68 | const charstring x := "x" | |
69 | const charstring cs_0 := "My name is JJ" | |
70 | const charstring cs_1 := replace("My name is JJ", 11, 1, "xx") // returns "My name is xxJ" | |
71 | const charstring cs_2 := replace("My name is JJ", 11, b - 1, "xx")// returns "My name is xxJJ" | |
72 | const charstring cs_3 := replace("My name is JJ", 2, 2, "x") // returns "Myxame is JJ" | |
73 | const charstring cs_4 := replace("My name is JJ", b + 1, b + 1, x)// returns "Myxame is JJ" | |
74 | const charstring cs_5 := replace("My name is JJ", 13, 0, "xx") // returns "My name is JJxx" | |
75 | const charstring cs_6 := replace(cs_0, 13, a, "xx") // returns "My name is JJxx" | |
76 | /* | |
77 | TODO: move to _SE const charstring cs_7 := replace("My name is JJ", 12, 2, "xx") // produces test case error (compile error) | |
78 | -"- const charstring cs_8 := replace("My name is JJ", 13, 2, "xx") // produces test case error (compile error) | |
79 | */ | |
80 | testcase replace_charstr() runs on PDTestComponent { //In testcase definition// | |
81 | if (cs_1 == "My name is xxJ") { setverdict(pass) } | |
82 | else { setverdict(fail) } //^In else statement// \ | |
83 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
84 | if (cs_2 == "My name is xxJJ") { setverdict(pass) } | |
85 | else { setverdict(fail) } //^In else statement// \ | |
86 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
87 | if (cs_3 == "Myxame is JJ") { setverdict(pass) } | |
88 | else { setverdict(fail) } //^In else statement// \ | |
89 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
90 | if (cs_4 == "Myxame is JJ") { setverdict(pass) } | |
91 | else { setverdict(fail) } //^In else statement// \ | |
92 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
93 | if (cs_3 == cs_4) { setverdict(pass) } | |
94 | else { setverdict(fail) } //^In else statement// \ | |
95 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
96 | if (cs_5 == "My name is JJxx") { setverdict(pass) } | |
97 | else { setverdict(fail) } //^In else statement// \ | |
98 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
99 | if (cs_6 == "My name is JJxx") { setverdict(pass) } | |
100 | else { setverdict(fail) } //^In else statement// \ | |
101 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
102 | if (cs_5 == cs_6) { setverdict(pass) } | |
103 | else { setverdict(fail) } //^In else statement// \ | |
104 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
105 | } | |
106 | ||
107 | /* replace on UNIVERSAL_CHARSTRING values. */ | |
108 | ||
109 | const universal charstring u := char(0, 0, 0, 120) & "" | |
110 | const universal charstring us_0 := char(0, 0, 0, 77) & "y name is JJ" | |
111 | const universal charstring us_1 := replace(char(0, 0, 0, 77) & "y name is JJ", 11, 1, char(0, 0, 0, 120) & "x") // returns "My name is xxJ" | |
112 | const universal charstring us_2 := replace(char(0, 0, 0, 77) & "y name is JJ", 11, b - 1, char(0, 0, 0, 120) & "x")// returns "My name is xxJJ" | |
113 | const universal charstring us_3 := replace(char(0, 0, 0, 77) & "y name is JJ", 2, 2, char(0, 0, 0, 120) & "") // returns "Myxame is JJ" | |
114 | const universal charstring us_4 := replace(char(0, 0, 0, 77) & "y name is JJ", b + 1, b + 1, u) // returns "Myxame is JJ" | |
115 | const universal charstring us_5 := replace(char(0, 0, 0, 77) & "y name is JJ", 13, 0, char(0, 0, 0, 120) & "x") // returns "My name is JJxx" | |
116 | const universal charstring us_6 := replace(us_0, 13, a, char(0, 0, 0, 120) & "x") // returns "My name is JJxx" | |
117 | ||
118 | testcase replace_ucharstr() runs on PDTestComponent { //In testcase definition// | |
119 | if (us_1 == char(0, 0, 0, 77) & "y name is xxJ") { setverdict(pass) } | |
120 | else { setverdict(fail) } //^In else statement// \ | |
121 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
122 | if (us_2 == char(0, 0, 0, 77) & "y name is xxJJ") { setverdict(pass) } | |
123 | else { setverdict(fail) } //^In else statement// \ | |
124 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
125 | if (us_3 == char(0, 0, 0, 77) & "yxame is JJ") { setverdict(pass) } | |
126 | else { setverdict(fail) } //^In else statement// \ | |
127 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
128 | if (us_4 == char(0, 0, 0, 77) & "yxame is JJ") { setverdict(pass) } | |
129 | else { setverdict(fail) } //^In else statement// \ | |
130 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
131 | if (us_3 == us_4) { setverdict(pass) } | |
132 | else { setverdict(fail) } //^In else statement// \ | |
133 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
134 | if (us_5 == char(0, 0, 0, 77) & "y name is JJxx") { setverdict(pass) } | |
135 | else { setverdict(fail) } //^In else statement// \ | |
136 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
137 | if (us_6 == char(0, 0, 0, 77) & "y name is JJxx") { setverdict(pass) } | |
138 | else { setverdict(fail) } //^In else statement// \ | |
139 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
140 | if (us_5 == us_6) { setverdict(pass) } | |
141 | else { setverdict(fail) } //^In else statement// \ | |
142 | //^warning\: Control never reaches this code because of previous effective condition\(s\)// | |
143 | } | |
144 | ||
145 | control { | |
146 | execute (replace_bitstr()); | |
147 | execute (replace_hexstr()); | |
148 | execute (replace_octetstr()); | |
149 | execute (replace_charstr()); | |
150 | execute (replace_ucharstr()); | |
151 | } | |
152 | ||
153 | } |