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