Commit | Line | Data |
---|---|---|
28352dbd BB |
1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 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 | * Contributors: | |
9 | * Baranyi, Botond – initial implementation | |
10 | * | |
11 | ******************************************************************************/ | |
12 | module TtemplateHexstr { | |
13 | ||
14 | type component templateHexstr_mycomp {}; | |
15 | ||
16 | type record templateHexstr_rec { | |
17 | hexstring x1, | |
18 | hexstring x2, | |
19 | hexstring x3 optional | |
20 | } | |
21 | with { | |
22 | encode "JSON"; | |
23 | variant(x1) "JSON: name as first"; | |
24 | variant(x2) "JSON: name as second"; | |
25 | variant(x3) "JSON: name as third"; | |
26 | } | |
27 | ||
28 | type record decmatch_rec { | |
29 | integer i, | |
30 | charstring s | |
31 | } | |
32 | with { | |
33 | encode "JSON"; | |
34 | } | |
35 | ||
36 | type record of integer decmatch_list | |
37 | with { | |
38 | encode "XML"; | |
39 | variant "list"; | |
40 | } | |
41 | ||
42 | type union decmatch_uni { | |
43 | integer i, | |
44 | charstring s | |
45 | } | |
46 | with { | |
47 | encode "RAW"; | |
48 | variant(i) "FIELDLENGTH(16)"; | |
49 | } | |
50 | ||
51 | template decmatch_uni decmatch_tUnion := { i := ? }; | |
52 | ||
53 | template decmatch_rec decmatch_tRecord := { i := (0..infinity), s := ? }; | |
54 | ||
55 | template templateHexstr_rec templateHexstr_tDecmatch := { // decoded content match | |
56 | x1 := decmatch decmatch_list: { (1..10), (11..20), (21..30) }, | |
57 | x2 := decmatch decmatch_tUnion, | |
58 | x3 := decmatch modifies decmatch_tRecord := { s := "abc" } | |
59 | }; | |
60 | ||
61 | template templateHexstr_rec templateHexstr_tDecmatchSelfRef := { // decoded content match with self-reference | |
62 | x1 := '01A'H, | |
63 | x2 := decmatch templateHexstr_tDecmatchSelfRef.x1, | |
64 | x3 := decmatch templateHexstr_rec: { x1 := templateHexstr_tDecmatchSelfRef.x1, x2 := ?, x3 := * } | |
65 | }; | |
66 | ||
67 | testcase templateHexstrDecmatch() runs on templateHexstr_mycomp { | |
68 | var decmatch_rec bad_rec, good_rec; | |
69 | bad_rec := { i := 11, s := "xyz" }; | |
70 | good_rec := { i := 3, s := "abc" }; | |
71 | var decmatch_list bad_list, good_list; | |
72 | bad_list := { 4, 7, 10 }; | |
73 | good_list := { 2, 15, 28 }; | |
74 | var decmatch_uni bad_uni, good_uni; | |
75 | bad_uni := { s := "five" }; | |
76 | good_uni := { i := 5 }; | |
77 | var hexstring bad_rec_enc, good_rec_enc, bad_list_enc, good_list_enc, bad_uni_enc, good_uni_enc; | |
78 | bad_rec_enc := bit2hex(encvalue(bad_rec)); | |
79 | good_rec_enc := bit2hex(encvalue(good_rec)); | |
80 | bad_list_enc := bit2hex(encvalue(bad_list)); | |
81 | good_list_enc := bit2hex(encvalue(good_list)); | |
82 | bad_uni_enc := bit2hex(encvalue(bad_uni)); | |
83 | good_uni_enc := bit2hex(encvalue(good_uni)); | |
84 | var templateHexstr_rec r1, r2, r3, r4, r5; | |
85 | r1 := { x1 := good_list_enc, x2 := good_uni_enc, x3 := good_rec_enc }; | |
86 | r2 := { x1 := bad_list_enc, x2 := good_uni_enc, x3 := good_rec_enc }; | |
87 | r3 := { x1 := good_list_enc, x2 := bad_uni_enc, x3 := good_rec_enc }; | |
88 | r4 := { x1 := good_list_enc, x2 := good_uni_enc, x3 := bad_rec_enc }; | |
89 | r5 := { x1 := good_list_enc, x2 := good_uni_enc, x3 := '00FF'H }; | |
90 | // match: all 3 are good | |
91 | if (match(r1, templateHexstr_tDecmatch)) { setverdict(pass); } | |
92 | else { setverdict(fail, 1); } | |
93 | // no match: decoded list does not match | |
94 | if (not match(r2, templateHexstr_tDecmatch)) { setverdict(pass); } | |
95 | else { setverdict(fail, 2); } | |
96 | // no match: decoded union does not match | |
97 | if (not match(r3, templateHexstr_tDecmatch)) { setverdict(pass); } | |
98 | else { setverdict(fail, 3); } | |
99 | // no match: decoded record does not match | |
100 | if (not match(r4, templateHexstr_tDecmatch)) { setverdict(pass); } | |
101 | else { setverdict(fail, 4); } | |
102 | // no match: x3 is not a valid encoded record value | |
103 | if (not match(r5, templateHexstr_tDecmatch)) { setverdict(pass); } | |
104 | else { setverdict(fail, 5); } | |
105 | // match r1 with the same template declared as an in-line template | |
106 | if (match(r1, templateHexstr_rec: { | |
107 | x1 := decmatch decmatch_list: { (1..10), (11..20), (21..30) }, | |
108 | x2 := decmatch decmatch_tUnion, | |
109 | x3 := decmatch modifies decmatch_tRecord := { s := "abc" } | |
110 | })) { setverdict(pass); } | |
111 | else { setverdict(fail, 6); } | |
112 | } | |
113 | ||
114 | external function ef_enc_rec_x1(in templateHexstr_rec.x1 x) return octetstring | |
115 | with { extension "prototype(convert) encode(JSON)" } | |
116 | ||
117 | testcase templateHexstrDecmatchSelfRef() runs on templateHexstr_mycomp { | |
118 | // global self-referencing template | |
119 | var templateHexstr_rec.x1 bad_hs, good_hs; | |
120 | bad_hs := 'FE98'H; | |
121 | good_hs := '01A'H; | |
122 | var templateHexstr_rec bad_rec, good_rec; | |
123 | bad_rec := { x1 := 'D01'H, x2 := 'D02'H, x3 := 'D03'H }; | |
124 | good_rec := { x1 := '01A'H, x2 := 'D02'H, x3 := 'D03'H }; | |
125 | var hexstring bad_hs_enc, good_hs_enc, bad_rec_enc, good_rec_enc; | |
126 | bad_hs_enc := oct2hex(ef_enc_rec_x1(bad_hs)); | |
127 | good_hs_enc := oct2hex(ef_enc_rec_x1(good_hs)); | |
128 | bad_rec_enc := bit2hex(encvalue(bad_rec)); | |
129 | good_rec_enc := bit2hex(encvalue(good_rec)); | |
130 | var templateHexstr_rec r1, r2, r3; | |
131 | r1 := { x1 := '01A'H, x2 := good_hs_enc, x3 := good_rec_enc }; | |
132 | r2 := { x1 := '01A'H, x2 := bad_hs_enc, x3 := good_rec_enc }; | |
133 | r3 := { x1 := '01A'H, x2 := good_hs_enc, x3 := bad_rec_enc }; | |
134 | // match: all 2 are good | |
135 | if (match(r1, templateHexstr_tDecmatchSelfRef)) { setverdict(pass); } | |
136 | else { setverdict(fail, 1); } | |
137 | // no match: decoded octetstring does not match | |
138 | if (not match(r2, templateHexstr_tDecmatchSelfRef)) { setverdict(pass); } | |
139 | else { setverdict(fail, 2); } | |
140 | // no match: decoded record does not match | |
141 | if (not match(r3, templateHexstr_tDecmatchSelfRef)) { setverdict(pass); } | |
142 | else { setverdict(fail, 3); } | |
143 | ||
144 | // local self-referencing template | |
145 | var template templateHexstr_rec t := { x1 := '01A'H, x2 := ?, x3 := ? }; | |
146 | t.x1 := decmatch t; | |
147 | var templateHexstr_rec r4, r5; | |
148 | r4 := { x1 := good_rec_enc, x2 := 'A1'H, x3 := 'A2'H }; | |
149 | r5 := { x1 := bad_rec_enc, x2 := 'A1'H, x3 := 'A2'H }; | |
150 | if (match(r4, t)) { setverdict(pass); } | |
151 | else { setverdict(fail, 4); } | |
152 | if (not match(r5, t)) { setverdict(pass); } | |
153 | else { setverdict(fail, 5); } | |
154 | } | |
155 | ||
156 | control { | |
157 | execute(templateHexstrDecmatch()); | |
158 | execute(templateHexstrDecmatchSelfRef()); | |
159 | } | |
160 | ||
161 | } |