2 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #include <asn_internal.h>
7 #include <constr_CHOICE.h>
9 asn_random_fill_result_t
10 CHOICE_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
11 const asn_encoding_constraints_t *constr,
13 const asn_CHOICE_specifics_t *specs =
14 (const asn_CHOICE_specifics_t *)td->specifics;
15 asn_random_fill_result_t res;
16 asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
17 asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
18 const asn_TYPE_member_t *elm;
20 void *memb_ptr; /* Pointer to the member */
21 void **memb_ptr2; /* Pointer to that pointer */
24 if(max_length == 0) return result_skipped;
29 st = CALLOC(1, specs->struct_size);
35 present = asn_random_between(1, td->elements_count);
36 elm = &td->elements[present - 1];
38 if(elm->flags & ATF_POINTER) {
39 /* Member is a pointer to another structure */
40 memb_ptr2 = (void **)((char *)st + elm->memb_offset);
42 memb_ptr = (char *)st + elm->memb_offset;
43 memb_ptr2 = &memb_ptr;
46 res = elm->type->op->random_fill(elm->type, memb_ptr2,
47 &elm->encoding_constraints, max_length);
48 _set_present_idx(st, specs->pres_offset, specs->pres_size, present);
49 if(res.code == ARFILL_OK) {
53 ASN_STRUCT_RESET(*td, st);
55 ASN_STRUCT_FREE(*td, st);