NativeEnumerated.c vars NULL init and check
[com/asn1c.git] / tests / tests-asn1c-compiler / 147-inherit-per-constraints-OK.asn1.-Pgen-PER
1
2 /*** <<< INCLUDES [Short] >>> ***/
3
4 #include <NativeInteger.h>
5
6 /*** <<< TYPE-DECLS [Short] >>> ***/
7
8 typedef long     Short_t;
9
10 /*** <<< FUNC-DECLS [Short] >>> ***/
11
12 extern asn_per_constraints_t asn_PER_type_Short_constr_1;
13 extern asn_TYPE_descriptor_t asn_DEF_Short;
14 asn_struct_free_f Short_free;
15 asn_struct_print_f Short_print;
16 asn_constr_check_f Short_constraint;
17 ber_type_decoder_f Short_decode_ber;
18 der_type_encoder_f Short_encode_der;
19 xer_type_decoder_f Short_decode_xer;
20 xer_type_encoder_f Short_encode_xer;
21 per_type_decoder_f Short_decode_uper;
22 per_type_encoder_f Short_encode_uper;
23 per_type_decoder_f Short_decode_aper;
24 per_type_encoder_f Short_encode_aper;
25
26 /*** <<< CODE [Short] >>> ***/
27
28 int
29 Short_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
30                         asn_app_constraint_failed_f *ctfailcb, void *app_key) {
31         long value;
32         
33         if(!sptr) {
34                 ASN__CTFAIL(app_key, td, sptr,
35                         "%s: value not given (%s:%d)",
36                         td->name, __FILE__, __LINE__);
37                 return -1;
38         }
39         
40         value = *(const long *)sptr;
41         
42         if((value >= 0 && value <= 65535)) {
43                 /* Constraint check succeeded */
44                 return 0;
45         } else {
46                 ASN__CTFAIL(app_key, td, sptr,
47                         "%s: constraint failed (%s:%d)",
48                         td->name, __FILE__, __LINE__);
49                 return -1;
50         }
51 }
52
53 /*
54  * This type is implemented using NativeInteger,
55  * so here we adjust the DEF accordingly.
56  */
57
58 /*** <<< CTDEFS [Short] >>> ***/
59
60 asn_per_constraints_t asn_PER_type_Short_constr_1 CC_NOTUSED = {
61         { APC_CONSTRAINED,       16,  16,  0,  65535 }  /* (0..65535) */,
62         { APC_UNCONSTRAINED,    -1, -1,  0,  0 },
63         0, 0    /* No PER value map */
64 };
65
66 /*** <<< STAT-DEFS [Short] >>> ***/
67
68 static const ber_tlv_tag_t asn_DEF_Short_tags_1[] = {
69         (ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
70 };
71 asn_TYPE_descriptor_t asn_DEF_Short = {
72         "Short",
73         "Short",
74         &asn_OP_NativeInteger,
75         asn_DEF_Short_tags_1,
76         sizeof(asn_DEF_Short_tags_1)
77                 /sizeof(asn_DEF_Short_tags_1[0]), /* 1 */
78         asn_DEF_Short_tags_1,   /* Same as above */
79         sizeof(asn_DEF_Short_tags_1)
80                 /sizeof(asn_DEF_Short_tags_1[0]), /* 1 */
81         { 0, &asn_PER_type_Short_constr_1, Short_constraint },
82         0, 0,   /* No members */
83         0       /* No specifics */
84 };
85
86
87 /*** <<< INCLUDES [Alias] >>> ***/
88
89 #include "Short.h"
90
91 /*** <<< TYPE-DECLS [Alias] >>> ***/
92
93 typedef Short_t  Alias_t;
94
95 /*** <<< FUNC-DECLS [Alias] >>> ***/
96
97 extern asn_per_constraints_t asn_PER_type_Alias_constr_1;
98 extern asn_TYPE_descriptor_t asn_DEF_Alias;
99 asn_struct_free_f Alias_free;
100 asn_struct_print_f Alias_print;
101 asn_constr_check_f Alias_constraint;
102 ber_type_decoder_f Alias_decode_ber;
103 der_type_encoder_f Alias_encode_der;
104 xer_type_decoder_f Alias_decode_xer;
105 xer_type_encoder_f Alias_encode_xer;
106 per_type_decoder_f Alias_decode_uper;
107 per_type_encoder_f Alias_encode_uper;
108 per_type_decoder_f Alias_decode_aper;
109 per_type_encoder_f Alias_encode_aper;
110
111 /*** <<< CODE [Alias] >>> ***/
112
113 int
114 Alias_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
115                         asn_app_constraint_failed_f *ctfailcb, void *app_key) {
116         long value;
117         
118         if(!sptr) {
119                 ASN__CTFAIL(app_key, td, sptr,
120                         "%s: value not given (%s:%d)",
121                         td->name, __FILE__, __LINE__);
122                 return -1;
123         }
124         
125         value = *(const long *)sptr;
126         
127         if((value >= 0 && value <= 65535)) {
128                 /* Constraint check succeeded */
129                 return 0;
130         } else {
131                 ASN__CTFAIL(app_key, td, sptr,
132                         "%s: constraint failed (%s:%d)",
133                         td->name, __FILE__, __LINE__);
134                 return -1;
135         }
136 }
137
138 /*
139  * This type is implemented using Short,
140  * so here we adjust the DEF accordingly.
141  */
142
143 /*** <<< CTDEFS [Alias] >>> ***/
144
145 asn_per_constraints_t asn_PER_type_Alias_constr_1 CC_NOTUSED = {
146         { APC_CONSTRAINED,       16,  16,  0,  65535 }  /* (0..65535) */,
147         { APC_UNCONSTRAINED,    -1, -1,  0,  0 },
148         0, 0    /* No PER value map */
149 };
150
151 /*** <<< STAT-DEFS [Alias] >>> ***/
152
153 static const ber_tlv_tag_t asn_DEF_Alias_tags_1[] = {
154         (ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
155 };
156 asn_TYPE_descriptor_t asn_DEF_Alias = {
157         "Alias",
158         "Alias",
159         &asn_OP_NativeInteger,
160         asn_DEF_Alias_tags_1,
161         sizeof(asn_DEF_Alias_tags_1)
162                 /sizeof(asn_DEF_Alias_tags_1[0]), /* 1 */
163         asn_DEF_Alias_tags_1,   /* Same as above */
164         sizeof(asn_DEF_Alias_tags_1)
165                 /sizeof(asn_DEF_Alias_tags_1[0]), /* 1 */
166         { 0, &asn_PER_type_Alias_constr_1, Alias_constraint },
167         0, 0,   /* No members */
168         0       /* No specifics */
169 };
170
171
172 /*** <<< INCLUDES [Soo] >>> ***/
173
174 #include <NativeInteger.h>
175 #include "Short.h"
176 #include "Alias.h"
177 #include <constr_SEQUENCE.h>
178
179 /*** <<< TYPE-DECLS [Soo] >>> ***/
180
181 typedef struct Soo {
182         long     foo;
183         Short_t  bar;
184         Alias_t  baz;
185         
186         /* Context for parsing across buffer boundaries */
187         asn_struct_ctx_t _asn_ctx;
188 } Soo_t;
189
190 /*** <<< FUNC-DECLS [Soo] >>> ***/
191
192 extern asn_TYPE_descriptor_t asn_DEF_Soo;
193
194 /*** <<< CODE [Soo] >>> ***/
195
196 static int
197 memb_foo_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr,
198                         asn_app_constraint_failed_f *ctfailcb, void *app_key) {
199         long value;
200         
201         if(!sptr) {
202                 ASN__CTFAIL(app_key, td, sptr,
203                         "%s: value not given (%s:%d)",
204                         td->name, __FILE__, __LINE__);
205                 return -1;
206         }
207         
208         value = *(const long *)sptr;
209         
210         if((value >= 0 && value <= 65535)) {
211                 /* Constraint check succeeded */
212                 return 0;
213         } else {
214                 ASN__CTFAIL(app_key, td, sptr,
215                         "%s: constraint failed (%s:%d)",
216                         td->name, __FILE__, __LINE__);
217                 return -1;
218         }
219 }
220
221
222 /*** <<< CTDEFS [Soo] >>> ***/
223
224 static asn_per_constraints_t asn_PER_memb_foo_constr_2 CC_NOTUSED = {
225         { APC_CONSTRAINED,       16,  16,  0,  65535 }  /* (0..65535) */,
226         { APC_UNCONSTRAINED,    -1, -1,  0,  0 },
227         0, 0    /* No PER value map */
228 };
229
230 /*** <<< STAT-DEFS [Soo] >>> ***/
231
232 static asn_TYPE_member_t asn_MBR_Soo_1[] = {
233         { ATF_NOFLAGS, 0, offsetof(struct Soo, foo),
234                 .tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)),
235                 .tag_mode = 0,
236                 .type = &asn_DEF_NativeInteger,
237                 .type_selector = 0,
238                 { .oer_constraints = 0, .per_constraints = &asn_PER_memb_foo_constr_2, .general_constraints =  memb_foo_constraint_1 },
239                 0, 0, /* No default value */
240                 .name = "foo"
241                 },
242         { ATF_NOFLAGS, 0, offsetof(struct Soo, bar),
243                 .tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)),
244                 .tag_mode = 0,
245                 .type = &asn_DEF_Short,
246                 .type_selector = 0,
247                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
248                 0, 0, /* No default value */
249                 .name = "bar"
250                 },
251         { ATF_NOFLAGS, 0, offsetof(struct Soo, baz),
252                 .tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)),
253                 .tag_mode = 0,
254                 .type = &asn_DEF_Alias,
255                 .type_selector = 0,
256                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
257                 0, 0, /* No default value */
258                 .name = "baz"
259                 },
260 };
261 static const ber_tlv_tag_t asn_DEF_Soo_tags_1[] = {
262         (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
263 };
264 static const asn_TYPE_tag2member_t asn_MAP_Soo_tag2el_1[] = {
265     { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 2 }, /* foo */
266     { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 1, -1, 1 }, /* bar */
267     { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 2, -2, 0 } /* baz */
268 };
269 static asn_SEQUENCE_specifics_t asn_SPC_Soo_specs_1 = {
270         sizeof(struct Soo),
271         offsetof(struct Soo, _asn_ctx),
272         .tag2el = asn_MAP_Soo_tag2el_1,
273         .tag2el_count = 3,      /* Count of tags in the map */
274         0, 0, 0,        /* Optional elements (not needed) */
275         -1,     /* First extension addition */
276 };
277 asn_TYPE_descriptor_t asn_DEF_Soo = {
278         "Soo",
279         "Soo",
280         &asn_OP_SEQUENCE,
281         asn_DEF_Soo_tags_1,
282         sizeof(asn_DEF_Soo_tags_1)
283                 /sizeof(asn_DEF_Soo_tags_1[0]), /* 1 */
284         asn_DEF_Soo_tags_1,     /* Same as above */
285         sizeof(asn_DEF_Soo_tags_1)
286                 /sizeof(asn_DEF_Soo_tags_1[0]), /* 1 */
287         { 0, 0, SEQUENCE_constraint },
288         asn_MBR_Soo_1,
289         3,      /* Elements count */
290         &asn_SPC_Soo_specs_1    /* Additional specs */
291 };
292