Sync with 5.2.0
[deliverable/titan.core.git] / regression_test / json / Functions.ttcn
CommitLineData
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 ******************************************************************************/
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
65
66external function f_enc_roi(in RoI u) return octetstring
67 with { extension "prototype(convert)"; extension "encode(JSON)"; }
68
69external function f_enc_rof(in RoF u) return octetstring
70 with { extension "prototype(convert)"; extension "encode(JSON)"; }
71
72external function f_enc_rocs(in RoCS u) return octetstring
73 with { extension "prototype(convert)"; extension "encode(JSON)"; }
74
75external function f_enc_ints(in IntArr u) return octetstring
76 with { extension "prototype(convert)"; extension "encode(JSON)"; }
77
78external function f_enc_floats(in FloatArr u) return octetstring
79 with { extension "prototype(convert)"; extension "encode(JSON)"; }
80
81external function f_enc_strs(in StrArr u) return octetstring
82 with { extension "prototype(convert)"; extension "encode(JSON)"; }
83
84external function f_enc_profile(in Profile u) return octetstring
85 with { extension "prototype(convert)"; extension "encode(JSON)"; }
86
87external function f_enc_profile_compact(in Profile u) return octetstring
88 with { extension "prototype(convert) encode(JSON) printing(compact)"; }
89
90external function f_enc_profile_compact_p(in Profile u) return octetstring
91 with { extension "encode(JSON) prototype(convert) printing(compact)"; }
92
93external function f_enc_profile_pretty(in Profile u) return octetstring
94 with { extension "prototype(convert) encode(JSON) printing(pretty)"; }
95
96external function f_enc_profile0(in Profile0 u) return octetstring
97 with { extension "prototype(convert)"; extension "encode(JSON)"; }
98
99external function f_enc_cba(in CBA u) return octetstring
100 with { extension "prototype(convert)"; extension "encode(JSON)"; }
101
102external function f_enc_stuff(in Stuff x) return octetstring
103 with { extension "prototype(convert) encode(JSON)" }
104
af710487 105external function f_enc_hpt(in HasPardType x) return octetstring
106 with { extension "prototype(convert) encode(JSON)" }
107
970ed795
EL
108// for ASN.1 types
109external function f_enc_seqofint(in SeqOfInt x) return octetstring
110 with { extension "prototype(convert) encode(JSON)" }
111
112external function f_enc_seqprod(in SeqProduct x) return octetstring
113 with { extension "prototype(convert) encode(JSON)" }
114
115external function f_enc_number(in Number x) return octetstring
116 with { extension "prototype(convert) encode(JSON)" }
117
118external function f_enc_strings(in ManyStrings x) return octetstring
119 with { extension "prototype(convert) encode(JSON)" }
120
121external function f_enc_complex(in ComplexSet x) return octetstring
122 with { extension "prototype(convert) encode(JSON)" }
af710487 123
124external function f_enc_obj(in Object x) return octetstring
125 with { extension "prototype(convert) encode(JSON)" }
126
127external function f_enc_null(in HasNull x) return octetstring
128 with { extension "prototype(convert) encode(JSON)" }
970ed795
EL
129
130//=================== Decoders =====================================
131
132// for TTCN-3 types
133external function f_dec_int(in octetstring x) return integer
134 with { extension "prototype(convert)"; extension "decode(JSON)"; }
135
136external function f_dec_bool(in octetstring x) return boolean
137 with { extension "prototype(convert)"; extension "decode(JSON)"; }
138
139external function f_dec_bit(in octetstring x) return bitstring
140 with { extension "prototype(convert)"; extension "decode(JSON)"; }
141
142external function f_dec_hex(in octetstring x) return hexstring
143 with { extension "prototype(convert)"; extension "decode(JSON)"; }
144
145external function f_dec_f(in octetstring x) return float
146 with { extension "prototype(convert)"; extension "decode(JSON)"; }
147
148external function f_dec_days(in octetstring x) return Days
149 with { extension "prototype(convert)"; extension "decode(JSON)"; }
150
151external function f_dec_os(in octetstring x) return octetstring
152 with { extension "prototype(convert)"; extension "decode(JSON)"; }
153
154external function f_dec_vt(in octetstring x) return verdicttype
155 with { extension "prototype(convert)"; extension "decode(JSON)"; }
156
157external function f_dec_cs(in octetstring x) return charstring
158 with { extension "prototype(convert)"; extension "decode(JSON)"; }
159
160external function f_dec_cs_x(in octetstring x) return charstring
161 with { extension "prototype(convert)"; extension "decode(XER:XER_EXTENDED)"; }
162
163external function f_dec_ucs(in octetstring x) return universal charstring
164 with { extension "prototype(convert)"; extension "decode(JSON)"; }
165
166external function f_dec_ucs_x(in octetstring x) return universal charstring
167with { extension "prototype(convert)"; extension "decode(XER:XER_EXTENDED)"; }
168
169external function f_dec_ints(in octetstring u) return IntArr
170 with { extension "prototype(convert)"; extension "decode(JSON)"; }
171
172external function f_dec_floats(in octetstring u) return FloatArr
173 with { extension "prototype(convert)"; extension "decode(JSON)"; }
174
175external function f_dec_strs(in octetstring u) return StrArr
176 with { extension "prototype(convert)"; extension "decode(JSON)"; }
177
178external function f_dec_R(in octetstring x) return R
179 with { extension "prototype(convert)"; extension "decode(JSON)"; }
180
181external function f_dec_A(in octetstring x) return A
182 with { extension "prototype(convert)"; extension "decode(JSON)"; }
183
184external function f_dec_ER(in octetstring x) return EmptyRec
185 with { extension "prototype(convert)"; extension "decode(JSON)"; }
186
187external function f_dec_roi(in octetstring x) return RoI
188 with { extension "prototype(convert)"; extension "decode(JSON)"; }
189
190external function f_dec_rof(in octetstring x) return RoF
191 with { extension "prototype(convert)"; extension "decode(JSON)"; }
192
193external function f_dec_rocs(in octetstring x) return RoCS
194 with { extension "prototype(convert)"; extension "decode(JSON)"; }
195
196external function f_dec_profile(in octetstring u) return Profile
197 with { extension "prototype(convert)"; extension "decode(JSON)"; }
198
199external function f_dec_profile0(in octetstring u) return Profile0
200 with { extension "prototype(convert)"; extension "decode(JSON)"; }
201
202external function f_dec_cba(in octetstring u) return CBA
203 with { extension "prototype(convert)"; extension "decode(JSON)"; }
204
205external function f_dec_stuff(in octetstring x) return Stuff
206 with { extension "prototype(convert) decode(JSON)" }
207
208external function f_dec_def(in octetstring x) return RecDef
209 with { extension "prototype(convert) decode(JSON)" }
210
af710487 211external function f_dec_hpt(in octetstring x) return HasPardType
212 with { extension "prototype(convert) decode(JSON)" }
213
970ed795
EL
214// for ASN.1 types
215external function f_dec_seqofint(in octetstring x) return SeqOfInt
216 with { extension "prototype(convert) decode(JSON)" }
217
218external function f_dec_seqprod(in octetstring x) return SeqProduct
219 with { extension "prototype(convert) decode(JSON)" }
220
221external function f_dec_number(in octetstring x) return Number
222 with { extension "prototype(convert) decode(JSON)" }
223
224external function f_dec_strings(in octetstring x) return ManyStrings
225 with { extension "prototype(convert) decode(JSON)" }
226
227external function f_dec_complex(in octetstring x) return ComplexSet
228 with { extension "prototype(convert) decode(JSON)" }
af710487 229
230external function f_dec_obj(in octetstring x) return Object
231 with { extension "prototype(convert) decode(JSON)" }
232
233external function f_dec_null(in octetstring x) return HasNull
234 with { extension "prototype(convert) decode(JSON)" }
970ed795
EL
235
236//============== Internal Functions ====================
237
238function f_check_encoding(in octetstring encoded, in octetstring expected) {
239 log("encoded: ",encoded," expected: ",expected)
240 if(encoded == expected) {
241 setverdict(pass);
242 } else {
243 setverdict(fail, "expected:", expected,"received: ", encoded);
244 }
245 } with { extension "transparent"}
246
247
248
249 function f_bool2verdict(in boolean b) {
250 if(b){setverdict(pass)} else {setverdict(fail)}
251 } with { extension "transparent"}
252
253 function f_abs(in float f) return float {
254 if(f < 0.0 ) { f:= -f }
255 return f;
256 }
257
258}
This page took 0.052326 seconds and 5 git commands to generate.