Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / json / Functions.ttcn
CommitLineData
970ed795 1/******************************************************************************
3abe9331 2 * Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
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 ******************************************************************************/
8module Functions
9{
10
11import from Types all;
12import from JsonData language "ASN.1" all;
13
14//=================== Encoders =====================================
15
16// for TTCN-3 types
17external function f_enc_int(in integer x) return octetstring
18 with { extension "prototype(convert)"; extension "encode(JSON)"; }
19
20external function f_enc_bool(in boolean x) return octetstring
21 with { extension "prototype(convert)"; extension "encode(JSON)"; }
22
23external function f_enc_cs(in charstring x) return octetstring
24 with { extension "prototype(convert)"; extension "encode(JSON)"; }
25
26external function f_enc_cs_x(in charstring x) return octetstring
27 with { extension "prototype(convert)"; extension "encode(XER:XER_EXTENDED)"; }
28
29external function f_enc_ucs_x(in universal charstring x) return octetstring
30 with { extension "prototype(convert)"; extension "encode(XER:XER_EXTENDED)"; }
31
32external function f_enc_os(in octetstring x) return octetstring
33 with { extension "prototype(convert)"; extension "encode(JSON)"; }
34
35external function f_enc_hex(in hexstring x) return octetstring
36 with { extension "prototype(convert)"; extension "encode(JSON)"; }
37
38external function f_enc_bit(in bitstring x) return octetstring
39 with { extension "prototype(convert)"; extension "encode(JSON)"; }
40
41external function f_enc_vt(in verdicttype x) return octetstring
42 with { extension "prototype(convert)"; extension "encode(JSON)"; }
43
44external function f_enc_ucs(in universal charstring x) return octetstring
45 with { extension "prototype(convert)"; extension "encode(JSON)"; }
46
47external function f_enc_f(in float x) return octetstring
48 with { extension "prototype(convert)"; extension "encode(JSON)"; }
49
50external function f_enc_f_x(in float x) return octetstring
51 with { extension "prototype(convert)"; extension "encode(XER:XER_EXTENDED)"; }
52
53external function f_enc_days(in Days x) return octetstring
54 with { extension "prototype(convert)"; extension "encode(JSON)"; }
55
56external function f_enc_R(in R rec) return octetstring
57 with { extension "prototype(convert)"; extension "encode(JSON)"; }
58
59external function f_enc_A(in A u) return octetstring
60 with { extension "prototype(convert)"; extension "encode(JSON)"; }
61
62external function f_enc_ER(in EmptyRec u) return octetstring
63 with { extension "prototype(convert)"; extension "encode(JSON)"; }
64
970ed795
EL
65external function f_enc_roi(in RoI u) return octetstring
66 with { extension "prototype(convert)"; extension "encode(JSON)"; }
67
68external function f_enc_rof(in RoF u) return octetstring
69 with { extension "prototype(convert)"; extension "encode(JSON)"; }
70
71external function f_enc_rocs(in RoCS u) return octetstring
72 with { extension "prototype(convert)"; extension "encode(JSON)"; }
73
74external function f_enc_ints(in IntArr u) return octetstring
75 with { extension "prototype(convert)"; extension "encode(JSON)"; }
76
77external function f_enc_floats(in FloatArr u) return octetstring
78 with { extension "prototype(convert)"; extension "encode(JSON)"; }
79
80external function f_enc_strs(in StrArr u) return octetstring
81 with { extension "prototype(convert)"; extension "encode(JSON)"; }
82
83external function f_enc_profile(in Profile u) return octetstring
84 with { extension "prototype(convert)"; extension "encode(JSON)"; }
85
86external function f_enc_profile_compact(in Profile u) return octetstring
87 with { extension "prototype(convert) encode(JSON) printing(compact)"; }
88
89external function f_enc_profile_compact_p(in Profile u) return octetstring
90 with { extension "encode(JSON) prototype(convert) printing(compact)"; }
91
92external function f_enc_profile_pretty(in Profile u) return octetstring
93 with { extension "prototype(convert) encode(JSON) printing(pretty)"; }
94
95external function f_enc_profile0(in Profile0 u) return octetstring
96 with { extension "prototype(convert)"; extension "encode(JSON)"; }
97
98external function f_enc_cba(in CBA u) return octetstring
99 with { extension "prototype(convert)"; extension "encode(JSON)"; }
100
101external function f_enc_stuff(in Stuff x) return octetstring
102 with { extension "prototype(convert) encode(JSON)" }
103
af710487 104external function f_enc_hpt(in HasPardType x) return octetstring
105 with { extension "prototype(convert) encode(JSON)" }
106
3abe9331 107external function f_enc_asn_stuff(in AsnStuff x) return octetstring
108 with { extension "prototype(convert) encode(JSON)" }
109
110external function f_enc_opt_uni(in OptionalUnions x) return octetstring
111 with { extension "prototype(convert) encode(JSON)" }
112
113external function f_enc_meta_rec(in MetainfoRecord x) return octetstring
114 with { extension "prototype(convert) encode(JSON)" }
115
116external function f_enc_meta_set(in MetainfoSet x) return octetstring
117 with { extension "prototype(convert) encode(JSON)" }
118
970ed795
EL
119// for ASN.1 types
120external function f_enc_seqofint(in SeqOfInt x) return octetstring
121 with { extension "prototype(convert) encode(JSON)" }
122
123external function f_enc_seqprod(in SeqProduct x) return octetstring
124 with { extension "prototype(convert) encode(JSON)" }
125
126external function f_enc_number(in Number x) return octetstring
127 with { extension "prototype(convert) encode(JSON)" }
128
129external function f_enc_strings(in ManyStrings x) return octetstring
130 with { extension "prototype(convert) encode(JSON)" }
131
132external function f_enc_complex(in ComplexSet x) return octetstring
133 with { extension "prototype(convert) encode(JSON)" }
af710487 134
135external function f_enc_obj(in Object x) return octetstring
136 with { extension "prototype(convert) encode(JSON)" }
137
138external function f_enc_null(in HasNull x) return octetstring
139 with { extension "prototype(convert) encode(JSON)" }
970ed795
EL
140
141//=================== Decoders =====================================
142
143// for TTCN-3 types
144external function f_dec_int(in octetstring x) return integer
145 with { extension "prototype(convert)"; extension "decode(JSON)"; }
146
147external function f_dec_bool(in octetstring x) return boolean
148 with { extension "prototype(convert)"; extension "decode(JSON)"; }
149
150external function f_dec_bit(in octetstring x) return bitstring
151 with { extension "prototype(convert)"; extension "decode(JSON)"; }
152
153external function f_dec_hex(in octetstring x) return hexstring
154 with { extension "prototype(convert)"; extension "decode(JSON)"; }
155
156external function f_dec_f(in octetstring x) return float
157 with { extension "prototype(convert)"; extension "decode(JSON)"; }
158
159external function f_dec_days(in octetstring x) return Days
160 with { extension "prototype(convert)"; extension "decode(JSON)"; }
161
162external function f_dec_os(in octetstring x) return octetstring
163 with { extension "prototype(convert)"; extension "decode(JSON)"; }
164
165external function f_dec_vt(in octetstring x) return verdicttype
166 with { extension "prototype(convert)"; extension "decode(JSON)"; }
167
168external function f_dec_cs(in octetstring x) return charstring
169 with { extension "prototype(convert)"; extension "decode(JSON)"; }
170
171external function f_dec_cs_x(in octetstring x) return charstring
172 with { extension "prototype(convert)"; extension "decode(XER:XER_EXTENDED)"; }
173
174external function f_dec_ucs(in octetstring x) return universal charstring
175 with { extension "prototype(convert)"; extension "decode(JSON)"; }
176
177external function f_dec_ucs_x(in octetstring x) return universal charstring
178with { extension "prototype(convert)"; extension "decode(XER:XER_EXTENDED)"; }
179
180external function f_dec_ints(in octetstring u) return IntArr
181 with { extension "prototype(convert)"; extension "decode(JSON)"; }
182
183external function f_dec_floats(in octetstring u) return FloatArr
184 with { extension "prototype(convert)"; extension "decode(JSON)"; }
185
186external function f_dec_strs(in octetstring u) return StrArr
187 with { extension "prototype(convert)"; extension "decode(JSON)"; }
188
189external function f_dec_R(in octetstring x) return R
190 with { extension "prototype(convert)"; extension "decode(JSON)"; }
191
192external function f_dec_A(in octetstring x) return A
193 with { extension "prototype(convert)"; extension "decode(JSON)"; }
194
195external function f_dec_ER(in octetstring x) return EmptyRec
196 with { extension "prototype(convert)"; extension "decode(JSON)"; }
197
198external function f_dec_roi(in octetstring x) return RoI
199 with { extension "prototype(convert)"; extension "decode(JSON)"; }
200
201external function f_dec_rof(in octetstring x) return RoF
202 with { extension "prototype(convert)"; extension "decode(JSON)"; }
203
204external function f_dec_rocs(in octetstring x) return RoCS
205 with { extension "prototype(convert)"; extension "decode(JSON)"; }
206
207external function f_dec_profile(in octetstring u) return Profile
208 with { extension "prototype(convert)"; extension "decode(JSON)"; }
209
210external function f_dec_profile0(in octetstring u) return Profile0
211 with { extension "prototype(convert)"; extension "decode(JSON)"; }
212
213external function f_dec_cba(in octetstring u) return CBA
214 with { extension "prototype(convert)"; extension "decode(JSON)"; }
215
216external function f_dec_stuff(in octetstring x) return Stuff
217 with { extension "prototype(convert) decode(JSON)" }
218
219external function f_dec_def(in octetstring x) return RecDef
220 with { extension "prototype(convert) decode(JSON)" }
221
af710487 222external function f_dec_hpt(in octetstring x) return HasPardType
223 with { extension "prototype(convert) decode(JSON)" }
224
3abe9331 225external function f_dec_asn_stuff(in octetstring x) return AsnStuff
226 with { extension "prototype(convert) decode(JSON)" }
227
228external function f_dec_opt_uni(in octetstring x) return OptionalUnions
229 with { extension "prototype(convert) decode(JSON)" }
230
231external function f_dec_meta_rec(in octetstring x) return MetainfoRecord
232 with { extension "prototype(convert) decode(JSON)" }
233
234external function f_dec_meta_set(in octetstring x) return MetainfoSet
235 with { extension "prototype(convert) decode(JSON)" }
236
970ed795
EL
237// for ASN.1 types
238external function f_dec_seqofint(in octetstring x) return SeqOfInt
239 with { extension "prototype(convert) decode(JSON)" }
240
241external function f_dec_seqprod(in octetstring x) return SeqProduct
242 with { extension "prototype(convert) decode(JSON)" }
243
244external function f_dec_number(in octetstring x) return Number
245 with { extension "prototype(convert) decode(JSON)" }
246
247external function f_dec_strings(in octetstring x) return ManyStrings
248 with { extension "prototype(convert) decode(JSON)" }
249
250external function f_dec_complex(in octetstring x) return ComplexSet
251 with { extension "prototype(convert) decode(JSON)" }
af710487 252
253external function f_dec_obj(in octetstring x) return Object
254 with { extension "prototype(convert) decode(JSON)" }
255
256external function f_dec_null(in octetstring x) return HasNull
257 with { extension "prototype(convert) decode(JSON)" }
970ed795
EL
258
259//============== Internal Functions ====================
260
261function f_check_encoding(in octetstring encoded, in octetstring expected) {
262 log("encoded: ",encoded," expected: ",expected)
263 if(encoded == expected) {
264 setverdict(pass);
265 } else {
266 setverdict(fail, "expected:", expected,"received: ", encoded);
267 }
268 } with { extension "transparent"}
269
270
271
272 function f_bool2verdict(in boolean b) {
273 if(b){setverdict(pass)} else {setverdict(fail)}
274 } with { extension "transparent"}
275
276 function f_abs(in float f) return float {
277 if(f < 0.0 ) { f:= -f }
278 return f;
279 }
280
281}
This page took 0.036793 seconds and 5 git commands to generate.