mirror of https://gerrit.osmocom.org/asn1c
add signed integer tests for test 134
parent
6c52784de1
commit
58b74eb570
|
@ -35,14 +35,16 @@ static void
|
|||
verify(int testNo, T_t *ti) {
|
||||
asn_enc_rval_t er;
|
||||
asn_dec_rval_t rv;
|
||||
unsigned char buf[16];
|
||||
unsigned char buf[20];
|
||||
T_t *to = 0;
|
||||
|
||||
fprintf(stderr, "%d IN: { %lu, %lu }\n", testNo,
|
||||
i2ul(&ti->unsigned33), i2ul(&ti->unsigned42));
|
||||
fprintf(stderr, "%d IN: { %lu, %lu, %ld, %ld }\n", testNo,
|
||||
i2ul(&ti->unsigned33), i2ul(&ti->unsigned42),
|
||||
i2ul(&ti->signed33), ti->signed33ext
|
||||
);
|
||||
|
||||
er = uper_encode_to_buffer(&asn_DEF_T, ti, buf, sizeof buf);
|
||||
assert(er.encoded == 33 + 42);
|
||||
assert(er.encoded >= 33 + 42 + 33 + 1 + 33);
|
||||
|
||||
rv = uper_decode(0, &asn_DEF_T, (void *)&to, buf, sizeof buf, 0, 0);
|
||||
assert(rv.code == RC_OK);
|
||||
|
@ -50,12 +52,16 @@ verify(int testNo, T_t *ti) {
|
|||
fprintf(stderr, "%d ENC: %2x%2x%2x%2x %2x%2x%2x%2x\n", testNo,
|
||||
buf[0], buf[1], buf[2], buf[3],
|
||||
buf[4], buf[5], buf[6], buf[7]);
|
||||
fprintf(stderr, "%d OUT: { %lu, %lu } vs { %lu, %lu }\n",
|
||||
fprintf(stderr, "%d OUT: { %lu, %lu, %ld, %ld } vs { %lu, %lu, %ld, %ld }\n",
|
||||
testNo,
|
||||
i2ul(&ti->unsigned33), i2ul(&ti->unsigned42),
|
||||
i2ul(&to->unsigned33), i2ul(&to->unsigned42));
|
||||
i2ul(&ti->signed33), ti->signed33ext,
|
||||
i2ul(&to->unsigned33), i2ul(&to->unsigned42),
|
||||
i2ul(&to->signed33), to->signed33ext);
|
||||
assert(i2ul(&ti->unsigned33) == i2ul(&to->unsigned33));
|
||||
assert(i2ul(&ti->unsigned42) == i2ul(&to->unsigned42));
|
||||
assert(i2ul(&ti->signed33) == i2ul(&to->signed33));
|
||||
assert(ti->signed33ext == to->signed33ext);
|
||||
|
||||
xer_fprint(stderr, &asn_DEF_T, ti);
|
||||
xer_fprint(stderr, &asn_DEF_T, to);
|
||||
|
@ -77,37 +83,71 @@ int main() {
|
|||
T_t ti;
|
||||
|
||||
memset(&ti, 0, sizeof(ti));
|
||||
ul2i(&ti.unsigned33, 0);
|
||||
ul2i(&ti.unsigned42, 0);
|
||||
ul2i(&ti.unsigned33, 0);
|
||||
ul2i(&ti.unsigned42, 0);
|
||||
ul2i(&ti.signed33, 0);
|
||||
ti.signed33ext = 0;
|
||||
verify(1, &ti);
|
||||
|
||||
ul2i(&ti.unsigned33, 1);
|
||||
ul2i(&ti.unsigned42, 1);
|
||||
ul2i(&ti.unsigned33, 1);
|
||||
ul2i(&ti.unsigned42, 1);
|
||||
ul2i(&ti.signed33, 1);
|
||||
ti.signed33ext = 1;
|
||||
verify(2, &ti);
|
||||
|
||||
ul2i(&ti.unsigned33, 5000000000);
|
||||
ul2i(&ti.unsigned42, 3153600000000);
|
||||
ul2i(&ti.unsigned33, 5000000000);
|
||||
ul2i(&ti.unsigned42, 3153600000000);
|
||||
ul2i(&ti.signed33, 4000000000);
|
||||
ti.signed33ext = 4000000000;
|
||||
verify(3, &ti);
|
||||
|
||||
ul2i(&ti.unsigned33, -1);
|
||||
ul2i(&ti.unsigned42, 0);
|
||||
ul2i(&ti.unsigned42, 0);
|
||||
ul2i(&ti.signed33, 0);
|
||||
ti.signed33ext = 0;
|
||||
NO_encode(4, &ti);
|
||||
|
||||
ul2i(&ti.unsigned33, 0);
|
||||
ul2i(&ti.unsigned33, 0);
|
||||
ul2i(&ti.unsigned42, -1);
|
||||
ul2i(&ti.signed33, 0);
|
||||
ti.signed33ext = 0;
|
||||
NO_encode(5, &ti);
|
||||
|
||||
ul2i(&ti.unsigned33, 5000000000 + 1);
|
||||
ul2i(&ti.unsigned42, 0);
|
||||
ul2i(&ti.unsigned33, 0);
|
||||
ul2i(&ti.unsigned42, 0);
|
||||
ul2i(&ti.signed33, -4000000000-1);
|
||||
ti.signed33ext = 0;
|
||||
NO_encode(6, &ti);
|
||||
|
||||
ul2i(&ti.unsigned33, 0);
|
||||
ul2i(&ti.unsigned42, 3153600000000 + 1);
|
||||
NO_encode(7, &ti);
|
||||
ul2i(&ti.unsigned33, 0);
|
||||
ul2i(&ti.unsigned42, 0);
|
||||
ul2i(&ti.signed33, 0);
|
||||
ti.signed33ext = -4000000000-1;
|
||||
verify(7, &ti); /* signed33ext is extensible */
|
||||
|
||||
ul2i(&ti.unsigned33, 5000000000 - 1);
|
||||
ul2i(&ti.unsigned42, 3153600000000 - 1);
|
||||
verify(8, &ti);
|
||||
ul2i(&ti.unsigned33, 5000000000 + 1);
|
||||
ul2i(&ti.unsigned42, 0);
|
||||
ul2i(&ti.signed33, 0);
|
||||
ti.signed33ext = 0;
|
||||
NO_encode(8, &ti);
|
||||
|
||||
ul2i(&ti.unsigned33, 0);
|
||||
ul2i(&ti.unsigned42, 3153600000000 + 1);
|
||||
ul2i(&ti.signed33, 0);
|
||||
ti.signed33ext = 0;
|
||||
NO_encode(9, &ti);
|
||||
|
||||
ul2i(&ti.unsigned33, 5000000000 - 1);
|
||||
ul2i(&ti.unsigned42, 3153600000000 - 1);
|
||||
ul2i(&ti.signed33, 4000000000 - 1);
|
||||
ti.signed33ext = 4000000000 - 1;
|
||||
verify(10, &ti);
|
||||
|
||||
ul2i(&ti.unsigned33, 0);
|
||||
ul2i(&ti.unsigned42, 0);
|
||||
ul2i(&ti.signed33, 0);
|
||||
ti.signed33ext = 4000000000 + 1;
|
||||
verify(11, &ti);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -733,10 +733,10 @@ INTEGER_encode_uper(asn_TYPE_descriptor_t *td,
|
|||
/* X.691-11/2008, #13.2.2, test if constrained whole number */
|
||||
if(ct && ct->range_bits >= 0) {
|
||||
/* #11.5.6 -> #11.3 */
|
||||
ASN_DEBUG("Encoding integer with range %d bits",
|
||||
ct->range_bits);
|
||||
long v = value - ct->lower_bound;
|
||||
if(uper_put_constrained_whole_number_s(po, v, ct->range_bits))
|
||||
ASN_DEBUG("Encoding integer %ld (%lu) with range %d bits",
|
||||
value, value - ct->lower_bound, ct->range_bits);
|
||||
unsigned long v = value - ct->lower_bound;
|
||||
if(uper_put_constrained_whole_number_u(po, v, ct->range_bits))
|
||||
_ASN_ENCODE_FAILED;
|
||||
_ASN_ENCODED_OK(er);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,9 @@ BEGIN
|
|||
-- Supported only on 64-bit platforms.
|
||||
T ::= SEQUENCE {
|
||||
unsigned33 INTEGER (0..5000000000), -- range 33 bits
|
||||
unsigned42 INTEGER (0..3153600000000) -- range 42 bits
|
||||
unsigned42 INTEGER (0..3153600000000), -- range 42 bits
|
||||
signed33 INTEGER (-4000000000..4000000000), -- 33 bits
|
||||
signed33ext INTEGER (-4000000000..4000000000,...)
|
||||
}
|
||||
|
||||
END
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/*** <<< INCLUDES [T] >>> ***/
|
||||
|
||||
#include <INTEGER.h>
|
||||
#include <NativeInteger.h>
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
/*** <<< TYPE-DECLS [T] >>> ***/
|
||||
|
@ -9,6 +10,8 @@
|
|||
typedef struct T {
|
||||
INTEGER_t unsigned33;
|
||||
INTEGER_t unsigned42;
|
||||
INTEGER_t signed33;
|
||||
long signed33ext;
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
|
@ -82,6 +85,62 @@ memb_unsigned42_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
memb_signed33_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
const INTEGER_t *st = (const INTEGER_t *)sptr;
|
||||
long value;
|
||||
|
||||
if(!sptr) {
|
||||
_ASN_CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(asn_INTEGER2long(st, &value)) {
|
||||
_ASN_CTFAIL(app_key, td, sptr,
|
||||
"%s: value too large (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((value >= -4000000000 && value <= 4000000000)) {
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
} else {
|
||||
_ASN_CTFAIL(app_key, td, sptr,
|
||||
"%s: constraint failed (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
memb_signed33ext_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
|
||||
long value;
|
||||
|
||||
if(!sptr) {
|
||||
_ASN_CTFAIL(app_key, td, sptr,
|
||||
"%s: value not given (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
value = *(const long *)sptr;
|
||||
|
||||
if((value >= -4000000000 && value <= 4000000000)) {
|
||||
/* Constraint check succeeded */
|
||||
return 0;
|
||||
} else {
|
||||
_ASN_CTFAIL(app_key, td, sptr,
|
||||
"%s: constraint failed (%s:%d)",
|
||||
td->name, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*** <<< CTDEFS [T] >>> ***/
|
||||
|
||||
|
@ -95,6 +154,16 @@ static asn_per_constraints_t asn_PER_memb_unsigned42_constr_3 GCC_NOTUSED = {
|
|||
{ APC_UNCONSTRAINED, -1, -1, 0, 0 },
|
||||
0, 0 /* No PER value map */
|
||||
};
|
||||
static asn_per_constraints_t asn_PER_memb_signed33_constr_4 GCC_NOTUSED = {
|
||||
{ APC_CONSTRAINED, 33, -1, -4000000000, 4000000000 } /* (-4000000000..4000000000) */,
|
||||
{ APC_UNCONSTRAINED, -1, -1, 0, 0 },
|
||||
0, 0 /* No PER value map */
|
||||
};
|
||||
static asn_per_constraints_t asn_PER_memb_signed33ext_constr_5 GCC_NOTUSED = {
|
||||
{ APC_CONSTRAINED | APC_EXTENSIBLE, 33, -1, -4000000000, 4000000000 } /* (-4000000000..4000000000,...) */,
|
||||
{ APC_UNCONSTRAINED, -1, -1, 0, 0 },
|
||||
0, 0 /* No PER value map */
|
||||
};
|
||||
|
||||
/*** <<< STAT-DEFS [T] >>> ***/
|
||||
|
||||
|
@ -117,19 +186,39 @@ static asn_TYPE_member_t asn_MBR_T_1[] = {
|
|||
.default_value = 0,
|
||||
.name = "unsigned42"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct T, signed33),
|
||||
.tag = (ASN_TAG_CLASS_CONTEXT | (2 << 2)),
|
||||
.tag_mode = -1, /* IMPLICIT tag at current level */
|
||||
.type = &asn_DEF_INTEGER,
|
||||
.memb_constraints = memb_signed33_constraint_1,
|
||||
.per_constraints = &asn_PER_memb_signed33_constr_4,
|
||||
.default_value = 0,
|
||||
.name = "signed33"
|
||||
},
|
||||
{ ATF_NOFLAGS, 0, offsetof(struct T, signed33ext),
|
||||
.tag = (ASN_TAG_CLASS_CONTEXT | (3 << 2)),
|
||||
.tag_mode = -1, /* IMPLICIT tag at current level */
|
||||
.type = &asn_DEF_NativeInteger,
|
||||
.memb_constraints = memb_signed33ext_constraint_1,
|
||||
.per_constraints = &asn_PER_memb_signed33ext_constr_5,
|
||||
.default_value = 0,
|
||||
.name = "signed33ext"
|
||||
},
|
||||
};
|
||||
static ber_tlv_tag_t asn_DEF_T_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static asn_TYPE_tag2member_t asn_MAP_T_tag2el_1[] = {
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* unsigned33 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* unsigned42 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* unsigned42 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 }, /* signed33 */
|
||||
{ (ASN_TAG_CLASS_CONTEXT | (3 << 2)), 3, 0, 0 } /* signed33ext */
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_T_specs_1 = {
|
||||
sizeof(struct T),
|
||||
offsetof(struct T, _asn_ctx),
|
||||
asn_MAP_T_tag2el_1,
|
||||
2, /* Count of tags in the map */
|
||||
4, /* Count of tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
|
@ -155,7 +244,7 @@ asn_TYPE_descriptor_t asn_DEF_T = {
|
|||
/sizeof(asn_DEF_T_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
asn_MBR_T_1,
|
||||
2, /* Elements count */
|
||||
4, /* Elements count */
|
||||
&asn_SPC_T_specs_1 /* Additional specs */
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue