X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fe2-interface.git;a=blobdiff_plain;f=e2sim%2Fasn1c%2FBOOLEAN_rfill.c;fp=e2sim%2Fasn1c%2FBOOLEAN_rfill.c;h=5ec628bbf07e5ae65a7ebf05ca403fa8d0cffb44;hp=0000000000000000000000000000000000000000;hb=f5900596513e4359fc839ba361da085674e90b68;hpb=215d350dbe06a4c7ee370815f26128a7f7e160cb diff --git a/e2sim/asn1c/BOOLEAN_rfill.c b/e2sim/asn1c/BOOLEAN_rfill.c new file mode 100644 index 0000000..5ec628b --- /dev/null +++ b/e2sim/asn1c/BOOLEAN_rfill.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#include +#include + +asn_random_fill_result_t +BOOLEAN_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, + const asn_encoding_constraints_t *constraints, + size_t max_length) { + asn_random_fill_result_t result_ok = {ARFILL_OK, 1}; + asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0}; + asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0}; + BOOLEAN_t *st = *sptr; + + if(max_length == 0) return result_skipped; + + if(st == NULL) { + st = (BOOLEAN_t *)(*sptr = CALLOC(1, sizeof(*st))); + if(st == NULL) { + return result_failed; + } + } + +#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) + if(!constraints || !constraints->per_constraints) + constraints = &td->encoding_constraints; + if(constraints->per_constraints) { + const asn_per_constraint_t *pc = &constraints->per_constraints->value; + if(pc->flags & APC_CONSTRAINED) { + *st = asn_random_between(pc->lower_bound, pc->upper_bound); + return result_ok; + } + } +#else + if(!constraints) constraints = &td->encoding_constraints; +#endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ + + /* Simulate booleans that are sloppily set and biased. */ + switch(asn_random_between(0, 7)) { + case 0: + case 1: + case 2: + *st = 0; break; + case 3: *st = -1; break; + case 4: *st = 1; break; + case 5: *st = INT_MIN; break; + case 6: *st = INT_MAX; break; + default: + *st = asn_random_between(INT_MIN, INT_MAX); + break; + } + return result_ok; +}