Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
58b74eb5
Commit
58b74eb5
authored
Feb 10, 2014
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add signed integer tests for test 134
parent
6c52784d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
162 additions
and
31 deletions
+162
-31
asn1c/tests/check-134.-gen-PER.c
asn1c/tests/check-134.-gen-PER.c
+63
-23
skeletons/INTEGER.c
skeletons/INTEGER.c
+4
-4
tests/134-per-long-OK.asn1
tests/134-per-long-OK.asn1
+3
-1
tests/134-per-long-OK.asn1.-Pgen-PER
tests/134-per-long-OK.asn1.-Pgen-PER
+92
-3
No files found.
asn1c/tests/check-134.-gen-PER.c
View file @
58b74eb5
...
@@ -35,14 +35,16 @@ static void
...
@@ -35,14 +35,16 @@ static void
verify
(
int
testNo
,
T_t
*
ti
)
{
verify
(
int
testNo
,
T_t
*
ti
)
{
asn_enc_rval_t
er
;
asn_enc_rval_t
er
;
asn_dec_rval_t
rv
;
asn_dec_rval_t
rv
;
unsigned
char
buf
[
16
];
unsigned
char
buf
[
20
];
T_t
*
to
=
0
;
T_t
*
to
=
0
;
fprintf
(
stderr
,
"%d IN: { %lu, %lu }
\n
"
,
testNo
,
fprintf
(
stderr
,
"%d IN: { %lu, %lu, %ld, %ld }
\n
"
,
testNo
,
i2ul
(
&
ti
->
unsigned33
),
i2ul
(
&
ti
->
unsigned42
));
i2ul
(
&
ti
->
unsigned33
),
i2ul
(
&
ti
->
unsigned42
),
i2ul
(
&
ti
->
signed33
),
ti
->
signed33ext
);
er
=
uper_encode_to_buffer
(
&
asn_DEF_T
,
ti
,
buf
,
sizeof
buf
);
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
);
rv
=
uper_decode
(
0
,
&
asn_DEF_T
,
(
void
*
)
&
to
,
buf
,
sizeof
buf
,
0
,
0
);
assert
(
rv
.
code
==
RC_OK
);
assert
(
rv
.
code
==
RC_OK
);
...
@@ -50,12 +52,16 @@ verify(int testNo, T_t *ti) {
...
@@ -50,12 +52,16 @@ verify(int testNo, T_t *ti) {
fprintf
(
stderr
,
"%d ENC: %2x%2x%2x%2x %2x%2x%2x%2x
\n
"
,
testNo
,
fprintf
(
stderr
,
"%d ENC: %2x%2x%2x%2x %2x%2x%2x%2x
\n
"
,
testNo
,
buf
[
0
],
buf
[
1
],
buf
[
2
],
buf
[
3
],
buf
[
0
],
buf
[
1
],
buf
[
2
],
buf
[
3
],
buf
[
4
],
buf
[
5
],
buf
[
6
],
buf
[
7
]);
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
,
testNo
,
i2ul
(
&
ti
->
unsigned33
),
i2ul
(
&
ti
->
unsigned42
),
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
->
unsigned33
)
==
i2ul
(
&
to
->
unsigned33
));
assert
(
i2ul
(
&
ti
->
unsigned42
)
==
i2ul
(
&
to
->
unsigned42
));
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
,
ti
);
xer_fprint
(
stderr
,
&
asn_DEF_T
,
to
);
xer_fprint
(
stderr
,
&
asn_DEF_T
,
to
);
...
@@ -79,35 +85,69 @@ int main() {
...
@@ -79,35 +85,69 @@ int main() {
memset
(
&
ti
,
0
,
sizeof
(
ti
));
memset
(
&
ti
,
0
,
sizeof
(
ti
));
ul2i
(
&
ti
.
unsigned33
,
0
);
ul2i
(
&
ti
.
unsigned33
,
0
);
ul2i
(
&
ti
.
unsigned42
,
0
);
ul2i
(
&
ti
.
unsigned42
,
0
);
ul2i
(
&
ti
.
signed33
,
0
);
ti
.
signed33ext
=
0
;
verify
(
1
,
&
ti
);
verify
(
1
,
&
ti
);
ul2i
(
&
ti
.
unsigned33
,
1
);
ul2i
(
&
ti
.
unsigned33
,
1
);
ul2i
(
&
ti
.
unsigned42
,
1
);
ul2i
(
&
ti
.
unsigned42
,
1
);
ul2i
(
&
ti
.
signed33
,
1
);
ti
.
signed33ext
=
1
;
verify
(
2
,
&
ti
);
verify
(
2
,
&
ti
);
ul2i
(
&
ti
.
unsigned33
,
5000000000
);
ul2i
(
&
ti
.
unsigned33
,
5000000000
);
ul2i
(
&
ti
.
unsigned42
,
3153600000000
);
ul2i
(
&
ti
.
unsigned42
,
3153600000000
);
ul2i
(
&
ti
.
signed33
,
4000000000
);
ti
.
signed33ext
=
4000000000
;
verify
(
3
,
&
ti
);
verify
(
3
,
&
ti
);
ul2i
(
&
ti
.
unsigned33
,
-
1
);
ul2i
(
&
ti
.
unsigned33
,
-
1
);
ul2i
(
&
ti
.
unsigned42
,
0
);
ul2i
(
&
ti
.
unsigned42
,
0
);
ul2i
(
&
ti
.
signed33
,
0
);
ti
.
signed33ext
=
0
;
NO_encode
(
4
,
&
ti
);
NO_encode
(
4
,
&
ti
);
ul2i
(
&
ti
.
unsigned33
,
0
);
ul2i
(
&
ti
.
unsigned33
,
0
);
ul2i
(
&
ti
.
unsigned42
,
-
1
);
ul2i
(
&
ti
.
unsigned42
,
-
1
);
ul2i
(
&
ti
.
signed33
,
0
);
ti
.
signed33ext
=
0
;
NO_encode
(
5
,
&
ti
);
NO_encode
(
5
,
&
ti
);
ul2i
(
&
ti
.
unsigned33
,
5000000000
+
1
);
ul2i
(
&
ti
.
unsigned33
,
0
);
ul2i
(
&
ti
.
unsigned42
,
0
);
ul2i
(
&
ti
.
unsigned42
,
0
);
ul2i
(
&
ti
.
signed33
,
-
4000000000
-
1
);
ti
.
signed33ext
=
0
;
NO_encode
(
6
,
&
ti
);
NO_encode
(
6
,
&
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
,
0
);
ul2i
(
&
ti
.
signed33
,
0
);
ti
.
signed33ext
=
0
;
NO_encode
(
8
,
&
ti
);
ul2i
(
&
ti
.
unsigned33
,
0
);
ul2i
(
&
ti
.
unsigned33
,
0
);
ul2i
(
&
ti
.
unsigned42
,
3153600000000
+
1
);
ul2i
(
&
ti
.
unsigned42
,
3153600000000
+
1
);
NO_encode
(
7
,
&
ti
);
ul2i
(
&
ti
.
signed33
,
0
);
ti
.
signed33ext
=
0
;
NO_encode
(
9
,
&
ti
);
ul2i
(
&
ti
.
unsigned33
,
5000000000
-
1
);
ul2i
(
&
ti
.
unsigned33
,
5000000000
-
1
);
ul2i
(
&
ti
.
unsigned42
,
3153600000000
-
1
);
ul2i
(
&
ti
.
unsigned42
,
3153600000000
-
1
);
verify
(
8
,
&
ti
);
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
;
return
0
;
}
}
...
...
skeletons/INTEGER.c
View file @
58b74eb5
...
@@ -733,10 +733,10 @@ INTEGER_encode_uper(asn_TYPE_descriptor_t *td,
...
@@ -733,10 +733,10 @@ INTEGER_encode_uper(asn_TYPE_descriptor_t *td,
/* X.691-11/2008, #13.2.2, test if constrained whole number */
/* X.691-11/2008, #13.2.2, test if constrained whole number */
if
(
ct
&&
ct
->
range_bits
>=
0
)
{
if
(
ct
&&
ct
->
range_bits
>=
0
)
{
/* #11.5.6 -> #11.3 */
/* #11.5.6 -> #11.3 */
ASN_DEBUG
(
"Encoding integer with range %d bits"
,
ASN_DEBUG
(
"Encoding integer
%ld (%lu)
with range %d bits"
,
ct
->
range_bits
);
value
,
value
-
ct
->
lower_bound
,
ct
->
range_bits
);
long
v
=
value
-
ct
->
lower_bound
;
unsigned
long
v
=
value
-
ct
->
lower_bound
;
if
(
uper_put_constrained_whole_number_
s
(
po
,
v
,
ct
->
range_bits
))
if
(
uper_put_constrained_whole_number_
u
(
po
,
v
,
ct
->
range_bits
))
_ASN_ENCODE_FAILED
;
_ASN_ENCODE_FAILED
;
_ASN_ENCODED_OK
(
er
);
_ASN_ENCODED_OK
(
er
);
}
}
...
...
tests/134-per-long-OK.asn1
View file @
58b74eb5
...
@@ -15,7 +15,9 @@ BEGIN
...
@@ -15,7 +15,9 @@ BEGIN
-- Supported only on 64-bit platforms.
-- Supported only on 64-bit platforms.
T ::= SEQUENCE {
T ::= SEQUENCE {
unsigned33 INTEGER (0..5000000000), -- range 33 bits
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
END
tests/134-per-long-OK.asn1.-Pgen-PER
View file @
58b74eb5
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
/*** <<< INCLUDES [T] >>> ***/
/*** <<< INCLUDES [T] >>> ***/
#include <INTEGER.h>
#include <INTEGER.h>
#include <NativeInteger.h>
#include <constr_SEQUENCE.h>
#include <constr_SEQUENCE.h>
/*** <<< TYPE-DECLS [T] >>> ***/
/*** <<< TYPE-DECLS [T] >>> ***/
...
@@ -9,6 +10,8 @@
...
@@ -9,6 +10,8 @@
typedef struct T {
typedef struct T {
INTEGER_t unsigned33;
INTEGER_t unsigned33;
INTEGER_t unsigned42;
INTEGER_t unsigned42;
INTEGER_t signed33;
long signed33ext;
/* Context for parsing across buffer boundaries */
/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
asn_struct_ctx_t _asn_ctx;
...
@@ -82,6 +85,62 @@ memb_unsigned42_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
...
@@ -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] >>> ***/
/*** <<< CTDEFS [T] >>> ***/
...
@@ -95,6 +154,16 @@ static asn_per_constraints_t asn_PER_memb_unsigned42_constr_3 GCC_NOTUSED = {
...
@@ -95,6 +154,16 @@ static asn_per_constraints_t asn_PER_memb_unsigned42_constr_3 GCC_NOTUSED = {
{ APC_UNCONSTRAINED, -1, -1, 0, 0 },
{ APC_UNCONSTRAINED, -1, -1, 0, 0 },
0, 0 /* No PER value map */
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] >>> ***/
/*** <<< STAT-DEFS [T] >>> ***/
...
@@ -117,19 +186,39 @@ static asn_TYPE_member_t asn_MBR_T_1[] = {
...
@@ -117,19 +186,39 @@ static asn_TYPE_member_t asn_MBR_T_1[] = {
.default_value = 0,
.default_value = 0,
.name = "unsigned42"
.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[] = {
static ber_tlv_tag_t asn_DEF_T_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
};
static asn_TYPE_tag2member_t asn_MAP_T_tag2el_1[] = {
static asn_TYPE_tag2member_t asn_MAP_T_tag2el_1[] = {
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* unsigned33 */
{ (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 = {
static asn_SEQUENCE_specifics_t asn_SPC_T_specs_1 = {
sizeof(struct T),
sizeof(struct T),
offsetof(struct T, _asn_ctx),
offsetof(struct T, _asn_ctx),
asn_MAP_T_tag2el_1,
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) */
0, 0, 0, /* Optional elements (not needed) */
-1, /* Start extensions */
-1, /* Start extensions */
-1 /* Stop extensions */
-1 /* Stop extensions */
...
@@ -155,7 +244,7 @@ asn_TYPE_descriptor_t asn_DEF_T = {
...
@@ -155,7 +244,7 @@ asn_TYPE_descriptor_t asn_DEF_T = {
/sizeof(asn_DEF_T_tags_1[0]), /* 1 */
/sizeof(asn_DEF_T_tags_1[0]), /* 1 */
0, /* No PER visible constraints */
0, /* No PER visible constraints */
asn_MBR_T_1,
asn_MBR_T_1,
2
, /* Elements count */
4
, /* Elements count */
&asn_SPC_T_specs_1 /* Additional specs */
&asn_SPC_T_specs_1 /* Additional specs */
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment