Commit d2a73606 authored by Lev Walkin's avatar Lev Walkin

bound the size of SEQUENCE OF and SET OF random generator

parent 62155df0
...@@ -981,7 +981,7 @@ asn_TYPE_operation_t asn_OP_SET_OF = { ...@@ -981,7 +981,7 @@ asn_TYPE_operation_t asn_OP_SET_OF = {
asn_random_fill_result_t asn_random_fill_result_t
SET_OF_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, SET_OF_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
const asn_encoding_constraints_t *constr, const asn_encoding_constraints_t *constraints,
size_t max_length) { size_t max_length) {
const asn_SET_OF_specifics_t *specs = const asn_SET_OF_specifics_t *specs =
(const asn_SET_OF_specifics_t *)td->specifics; (const asn_SET_OF_specifics_t *)td->specifics;
...@@ -990,12 +990,12 @@ SET_OF_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, ...@@ -990,12 +990,12 @@ SET_OF_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0}; asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
const asn_TYPE_member_t *elm = td->elements; const asn_TYPE_member_t *elm = td->elements;
void *st = *sptr; void *st = *sptr;
long slb = 0; /* Lower size bound */
long sub = 5; /* Upper size bound */
size_t rnd_len; size_t rnd_len;
if(max_length == 0) return result_skipped; if(max_length == 0) return result_skipped;
(void)constr;
if(st == NULL) { if(st == NULL) {
st = (*sptr = CALLOC(1, specs->struct_size)); st = (*sptr = CALLOC(1, specs->struct_size));
if(st == NULL) { if(st == NULL) {
...@@ -1003,13 +1003,28 @@ SET_OF_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, ...@@ -1003,13 +1003,28 @@ SET_OF_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
} }
} }
rnd_len = asn_random_between(0, 5); if(!constraints || !constraints->per_constraints)
constraints = &td->encoding_constraints;
if(constraints->per_constraints) {
const asn_per_constraint_t *pc = &constraints->per_constraints->size;
if(pc->flags & APC_SEMI_CONSTRAINED) {
slb = pc->lower_bound;
sub = pc->lower_bound + 5;
} else if(pc->flags & APC_CONSTRAINED) {
slb = pc->lower_bound;
sub = pc->upper_bound;
if(sub - slb > 5) sub = slb + 5;
}
}
rnd_len = asn_random_between(slb, sub);
for(; rnd_len > 0; rnd_len--) { for(; rnd_len > 0; rnd_len--) {
asn_anonymous_set_ *list = _A_SET_FROM_VOID(st); asn_anonymous_set_ *list = _A_SET_FROM_VOID(st);
void *ptr = 0; void *ptr = 0;
asn_random_fill_result_t tmpres = elm->type->op->random_fill( asn_random_fill_result_t tmpres = elm->type->op->random_fill(
elm->type, &ptr, &elm->encoding_constraints, elm->type, &ptr, &elm->encoding_constraints,
max_length > res_ok.length ? max_length - res_ok.length : 0); (max_length > res_ok.length ? max_length - res_ok.length : 0)
/ rnd_len);
switch(tmpres.code) { switch(tmpres.code) {
case ARFILL_OK: case ARFILL_OK:
ASN_SET_ADD(list, ptr); ASN_SET_ADD(list, ptr);
......
...@@ -41,6 +41,7 @@ TESTS += bundles/13-UTCTime-bundle.txt ...@@ -41,6 +41,7 @@ TESTS += bundles/13-UTCTime-bundle.txt
TESTS += bundles/14-GeneralizedTime-bundle.txt TESTS += bundles/14-GeneralizedTime-bundle.txt
TESTS += bundles/15-CHOICE-bundle.txt TESTS += bundles/15-CHOICE-bundle.txt
TESTS += bundles/16-SEQUENCE-bundle.txt TESTS += bundles/16-SEQUENCE-bundle.txt
TESTS += bundles/17-SEQUENCE-OF-bundle.txt
EXTRA_DIST = \ EXTRA_DIST = \
random-test-driver.c \ random-test-driver.c \
......
SEQUENCE OF NULL
SEQUENCE (SIZE(0)) OF NULL
SEQUENCE (SIZE(1)) OF NULL
SEQUENCE (SIZE(0..2)) OF NULL
SEQUENCE (SIZE(1..2)) OF NULL
SEQUENCE (SIZE(1..MAX)) OF NULL
SEQUENCE OF BOOLEAN
SEQUENCE (SIZE(0)) OF BOOLEAN
SEQUENCE (SIZE(1)) OF BOOLEAN
SEQUENCE (SIZE(0..2)) OF BOOLEAN
SEQUENCE (SIZE(1..2)) OF BOOLEAN
SEQUENCE (SIZE(1..MAX)) OF BOOLEAN
SEQUENCE OF PrintableString (SIZE(1))
SEQUENCE (SIZE(0)) OF PrintableString (SIZE(1))
SEQUENCE (SIZE(1)) OF PrintableString (SIZE(1))
SEQUENCE (SIZE(0..2)) OF PrintableString (SIZE(1))
SEQUENCE (SIZE(1..2)) OF PrintableString (SIZE(1))
SEQUENCE (SIZE(1..MAX)) OF PrintableString (SIZE(1))
SEQUENCE OF PrintableString (FROM("A".."Z"))
SEQUENCE (SIZE(0)) OF PrintableString (FROM("A".."Z"))
SEQUENCE (SIZE(1)) OF PrintableString (FROM("A".."Z"))
SEQUENCE (SIZE(0..2)) OF PrintableString (FROM("A".."Z"))
SEQUENCE (SIZE(1..2)) OF PrintableString (FROM("A".."Z"))
SEQUENCE (SIZE(1..MAX)) OF PrintableString (FROM("A".."Z"))
SEQUENCE OF PrintableString (FROM("A".."Z"))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment